automotive-dlt
dlt_daemon_event_handler.h File Reference
#include <sys/epoll.h>
#include "dlt_daemon_connection_types.h"
#include "dlt_daemon_event_handler_types.h"
#include "dlt-daemon.h"
Include dependency graph for dlt_daemon_event_handler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int dlt_daemon_prepare_event_handling (DltEventHandler *)
 Prepare the event handler. More...
 
int dlt_daemon_handle_event (DltEventHandler *, DltDaemon *, DltDaemonLocal *)
 Catch and process incoming events. More...
 
DltConnectiondlt_event_handler_find_connection_by_id (DltEventHandler *, DltConnectionId)
 Find connection with a specific id in the connection list. More...
 
DltConnectiondlt_event_handler_find_connection (DltEventHandler *, int)
 Find connection with a specific fd in the connection list. More...
 
void dlt_event_handler_cleanup_connections (DltEventHandler *)
 Destroy the connection list. More...
 
int dlt_event_handler_register_connection (DltEventHandler *, DltDaemonLocal *, DltConnection *, int)
 Registers a connection for event handling and takes its ownership. More...
 
int dlt_event_handler_unregister_connection (DltEventHandler *, DltDaemonLocal *, int)
 Unregisters a connection from the event handler and destroys it. More...
 
int dlt_connection_check_activate (DltEventHandler *, DltConnection *, int)
 Check for connection activation. More...
 

Detailed Description

Author
Frederic Berat fbera.nosp@m.t@de.nosp@m..adit.nosp@m.-jv..nosp@m.com

Definition in file dlt_daemon_event_handler.h.

Function Documentation

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.

Parameters
evhdlThe event handler structure.
conThe connection to act on
activation_typeThe type of activation requested ((DE)ACTIVATE)
Returns
0 on success, -1 otherwise

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.

Parameters
daemonStructure to be passed to the callback.
daemon_localStructure containing needed information.
pEventEvent handler structure.
Returns
0 on success, -1 otherwise. May be interrupted.

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.

Parameters
evThe event handler to prepare.
Returns
0 on success, -1 otherwise.

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.

Parameters
evPointer 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.

Parameters
evThe event handler structure where the list of connection is.
fdThe file descriptor of the connection to be found.
Returns
The found connection pointer, NULL otherwise.

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.

Parameters
evThe event handler structure where the list of connection is.
idThe identifier of the connection to be found.
Returns
The found connection pointer, NULL otherwise.

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.

Parameters
evhdlThe event handler structure where the connection list is.
daemon_localStructure containing needed information.
connectionThe connection to be registered.
maskThe bit mask of event to be registered.
Returns
0 on success, -1 otherwise.

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.

Parameters
evhdlThe event handler structure where the connection list is.
daemon_localStructure containing needed information.
fdThe file descriptor of the connection to be unregistered.
Returns
0 on success, -1 otherwise.

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().