automotive-dlt
|
#include <sys/epoll.h>
#include "dlt_daemon_connection_types.h"
#include "dlt_daemon_event_handler_types.h"
#include "dlt-daemon.h"
Go to the source code of this file.
Definition in file dlt_daemon_event_handler.h.
int dlt_connection_check_activate | ( | DltEventHandler * | evhdl, |
DltConnection * | con, | ||
int | activation_type | ||
) |
Check for connection activation.
If the connection is active and it's not allowed anymore or it the user ask for deactivation, the connection will be deactivated. If the connection is inactive, the user asks for activation and it's allowed for it to be activated, the connection will be activated.
evhdl | The event handler structure. |
con | The connection to act on |
activation_type | The type of activation requested ((DE)ACTIVATE) |
Definition at line 335 of file dlt_daemon_event_handler.c.
References ACTIVATE, ACTIVE, DEACTIVATE, DLT_DAEMON_TEXTBUFSIZE, dlt_log(), DltEventHandler::epfd, DltConnection::ev_mask, DltReceiver::fd, DltConnection::id, INACTIVE, NULL, DltConnection::receiver, DltConnection::status, and DltConnection::type.
Referenced by dlt_event_handler_register_connection(), and dlt_event_handler_unregister_connection().
int dlt_daemon_handle_event | ( | DltEventHandler * | pEvent, |
DltDaemon * | daemon, | ||
DltDaemonLocal * | daemon_local | ||
) |
Catch and process incoming events.
This function waits for events on all connections. Once an event raise, the callback for the specific connection is called, or the connection is destroyed if a hangup occurs.
daemon | Structure to be passed to the callback. |
daemon_local | Structure containing needed information. |
pEvent | Event handler structure. |
Definition at line 91 of file dlt_daemon_event_handler.c.
References dlt_connection_get_callback(), DLT_CONNECTION_TYPE_MAX, DLT_DAEMON_TEXTBUFSIZE, DLT_EPOLL_MAX_EVENTS, DLT_EPOLL_TIMEOUT_MSEC, dlt_event_handler_find_connection_by_id(), dlt_event_handler_unregister_connection(), dlt_log(), DLT_RETURN_ERROR, DltEventHandler::epfd, DltEventHandler::events, DltDaemonLocal::flags, NULL, str, and DltDaemonFlags::vflag.
Referenced by main().
int dlt_daemon_prepare_event_handling | ( | DltEventHandler * | ev | ) |
Prepare the event handler.
This will create the epoll file descriptor.
ev | The event handler to prepare. |
Definition at line 62 of file dlt_daemon_event_handler.c.
References DLT_EPOLL_MAX_EVENTS, dlt_log(), DLT_RETURN_ERROR, DltEventHandler::epfd, and NULL.
Referenced by main().
void dlt_event_handler_cleanup_connections | ( | DltEventHandler * | ev | ) |
Destroy the connection list.
This function runs through the connection list and destroy them one by one.
ev | Pointer to the event handler structure. |
Definition at line 287 of file dlt_daemon_event_handler.c.
References DltEventHandler::connections, dlt_daemon_remove_connection(), and NULL.
Referenced by dlt_daemon_local_cleanup().
DltConnection* dlt_event_handler_find_connection | ( | DltEventHandler * | ev, |
int | fd | ||
) |
Find connection with a specific fd in the connection list.
There can be only one event per fd. We can then find a specific connection based on this fd. That allows to check if a specific fd has already been registered.
ev | The event handler structure where the list of connection is. |
fd | The file descriptor of the connection to be found. |
Definition at line 201 of file dlt_daemon_event_handler.c.
References DltEventHandler::connections, DltReceiver::fd, DltConnection::next, NULL, and DltConnection::receiver.
Referenced by dlt_connection_create(), and dlt_event_handler_unregister_connection().
DltConnection* dlt_event_handler_find_connection_by_id | ( | DltEventHandler * | ev, |
DltConnectionId | id | ||
) |
Find connection with a specific id in the connection list.
There can be only one event per fd. We can then find a specific connection based on this fd. That allows to check if a specific fd has already been registered.
ev | The event handler structure where the list of connection is. |
id | The identifier of the connection to be found. |
Definition at line 226 of file dlt_daemon_event_handler.c.
References DltEventHandler::connections, DltConnection::id, DltConnection::next, and NULL.
Referenced by dlt_daemon_handle_event().
int dlt_event_handler_register_connection | ( | DltEventHandler * | evhdl, |
DltDaemonLocal * | daemon_local, | ||
DltConnection * | connection, | ||
int | mask | ||
) |
Registers a connection for event handling and takes its ownership.
As we add the connection to the list of connection, we take its ownership. That's the only place where the connection pointer is stored. The connection is then used to create a new event trigger. If the connection is of type DLT_CONNECTION_CLIENT_MSG_TCP, we increase the daemon_local->client_connections counter. TODO: Move this counter inside the event handler structure.
evhdl | The event handler structure where the connection list is. |
daemon_local | Structure containing needed information. |
connection | The connection to be registered. |
mask | The bit mask of event to be registered. |
Definition at line 429 of file dlt_daemon_event_handler.c.
References ACTIVATE, DltDaemonLocal::client_connections, dlt_connection_check_activate(), DLT_CONNECTION_CLIENT_MSG_SERIAL, DLT_CONNECTION_CLIENT_MSG_TCP, dlt_daemon_add_connection(), dlt_log(), DltConnection::ev_mask, INACTIVE, DltConnection::next, NULL, DltConnection::receiver, DltConnection::status, and DltConnection::type.
Referenced by dlt_connection_create().
int dlt_event_handler_unregister_connection | ( | DltEventHandler * | evhdl, |
DltDaemonLocal * | daemon_local, | ||
int | fd | ||
) |
Unregisters a connection from the event handler and destroys it.
We first look for the connection to be unregistered, delete the event corresponding and then destroy the connection. If the connection is of type DLT_CONNECTION_CLIENT_MSG_TCP, we decrease the daemon_local->client_connections counter. TODO: Move this counter inside the event handler structure.
evhdl | The event handler structure where the connection list is. |
daemon_local | Structure containing needed information. |
fd | The file descriptor of the connection to be unregistered. |
Definition at line 472 of file dlt_daemon_event_handler.c.
References DltDaemonLocal::client_connections, DEACTIVATE, dlt_connection_check_activate(), DLT_CONNECTION_CLIENT_MSG_SERIAL, DLT_CONNECTION_CLIENT_MSG_TCP, dlt_daemon_remove_connection(), dlt_event_handler_find_connection(), dlt_log(), DLT_RETURN_ERROR, NULL, and DltConnection::type.
Referenced by dlt_daemon_close_socket(), dlt_daemon_handle_event(), dlt_gateway_process_on_demand_request(), and dlt_gateway_process_passive_node_messages().