automotive-dlt
dlt_daemon_connection.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/types.h>
#include "dlt_daemon_connection_types.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_event_handler_types.h"
#include "dlt_daemon_event_handler.h"
#include "dlt-daemon.h"
#include "dlt-daemon_cfg.h"
#include "dlt_daemon_common.h"
#include "dlt_common.h"
#include "dlt_gateway.h"
#include "dlt_daemon_socket.h"
Include dependency graph for dlt_daemon_connection.c:

Go to the source code of this file.

Functions

STATIC int dlt_connection_send (DltConnection *conn, void *msg, size_t msg_size)
 Generic sending function. More...
 
int dlt_connection_send_multiple (DltConnection *con, void *data1, int size1, void *data2, int size2, int sendserialheader)
 Send up to two messages through a connection. More...
 
DltConnectiondlt_connection_get_next (DltConnection *current, int type_mask)
 Get the next connection filtered with a type mask. More...
 
STATIC void dlt_connection_destroy_receiver (DltConnection *con)
 
STATIC DltReceiverdlt_connection_get_receiver (DltDaemonLocal *daemon_local, DltConnectionType type, int fd)
 Get the receiver structure associated to a connection. More...
 
void * dlt_connection_get_callback (DltConnection *con)
 Get the callback from a specific connection. More...
 
void dlt_connection_destroy (DltConnection *to_destroy)
 Destroys a connection. More...
 
int dlt_connection_create (DltDaemonLocal *daemon_local, DltEventHandler *evh, int fd, int mask, DltConnectionType type)
 Creates a connection and registers it to the DltEventHandler. More...
 

Variables

static DltConnectionId connectionId
 

Detailed Description

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

Definition in file dlt_daemon_connection.c.

Function Documentation

int dlt_connection_create ( DltDaemonLocal daemon_local,
DltEventHandler evh,
int  fd,
int  mask,
DltConnectionType  type 
)

Creates a connection and registers it to the DltEventHandler.

The function will allocate memory for the connection, and give the pointer to the DltEventHandler in order to register it for incoming events. The connection is then destroyed later on, once it's not needed anymore or it the event handler is destroyed.

Parameters
daemon_localStructure were some needed information is.
evhDltEventHandler to register the connection to.
fdFile descriptor of the connection.
maskEvent list bit mask.
typeConnection type.
Returns
0 On success, -1 otherwise.

Definition at line 346 of file dlt_daemon_connection.c.

References ACTIVE, connectionId, dlt_connection_get_receiver(), DLT_DAEMON_TEXTBUFSIZE, dlt_event_handler_find_connection(), dlt_event_handler_register_connection(), dlt_log(), DltConnection::id, NULL, DltConnection::receiver, DltConnection::status, and DltConnection::type.

Referenced by create_timer_fd(), dlt_daemon_init_fifo(), dlt_daemon_init_serial(), dlt_daemon_local_connection_init(), dlt_daemon_process_client_connect(), dlt_daemon_process_control_connect(), dlt_gateway_establish_connections(), and dlt_gateway_process_on_demand_request().

void dlt_connection_destroy ( DltConnection to_destroy)

Destroys a connection.

This function closes and frees the corresponding connection. This is expected to be called by the connection owner: the DltEventHandler. Ownership of the connection is given during the registration to the DltEventHandler.

Parameters
to_destroyConnection to be destroyed.

Definition at line 320 of file dlt_daemon_connection.c.

References dlt_connection_destroy_receiver(), DLT_CONNECTION_TYPE_MAX, DltReceiver::fd, DltConnection::id, DltConnection::receiver, and DltConnection::type.

Referenced by dlt_daemon_remove_connection().

STATIC void dlt_connection_destroy_receiver ( DltConnection con)
void* dlt_connection_get_callback ( DltConnection con)

Get the callback from a specific connection.

The callback retrieved that way is used to handle event for this connection. It as been chosen to proceed that way instead of having the callback directly in the structure in order to have some way to check that the structure is still valid, or at least gracefully handle errors instead of crashing.

Parameters
conThe connection to retrieve the callback from.
Returns
Function pointer or NULL.

Definition at line 257 of file dlt_daemon_connection.c.

References DLT_CONNECTION_APP_MSG, DLT_CONNECTION_CLIENT_CONNECT, DLT_CONNECTION_CLIENT_MSG_SERIAL, DLT_CONNECTION_CLIENT_MSG_TCP, DLT_CONNECTION_CONTROL_CONNECT, DLT_CONNECTION_CONTROL_MSG, DLT_CONNECTION_GATEWAY, DLT_CONNECTION_GATEWAY_TIMER, DLT_CONNECTION_ONE_S_TIMER, DLT_CONNECTION_SIXTY_S_TIMER, DLT_CONNECTION_SYSTEMD_TIMER, DLT_CONNECTION_TYPE_MAX, dlt_daemon_process_client_connect(), dlt_daemon_process_client_messages(), dlt_daemon_process_client_messages_serial(), dlt_daemon_process_control_connect(), dlt_daemon_process_control_messages(), dlt_daemon_process_one_s_timer(), dlt_daemon_process_sixty_s_timer(), dlt_daemon_process_systemd_timer(), dlt_daemon_process_user_messages(), dlt_gateway_process_gateway_timer(), dlt_gateway_process_passive_node_messages(), NULL, and DltConnection::type.

Referenced by dlt_daemon_handle_event().

DltConnection* dlt_connection_get_next ( DltConnection current,
int  type_mask 
)

Get the next connection filtered with a type mask.

In some cases we need the next connection available of a specific type or specific different types. This function returns the next available connection that is of one of the types included in the mask. The current connection can be returned.

Parameters
currentThe current connection pointer.
type_maskA bit mask representing the connection types to be filtered.
Returns
The next available connection of the considered types or NULL.

Definition at line 151 of file dlt_daemon_connection.c.

References DltConnection::next, and DltConnection::type.

Referenced by dlt_daemon_client_send_all_multiple().

STATIC DltReceiver* dlt_connection_get_receiver ( DltDaemonLocal daemon_local,
DltConnectionType  type,
int  fd 
)

Get the receiver structure associated to a connection.

The receiver structure is sometimes needed while handling the event. This behavior is mainly due to the fact that it's not intended to modify the whole design of the daemon while implementing the new event handling. Based on the connection type provided, this function returns the pointer to the DltReceiver structure corresponding.

Parameters
dameon_localStructure where to take the DltReceiver pointer from.
typeType of the connection.
fdFile descriptor
Returns
DltReceiver structure or NULL if none corresponds to the type.

Definition at line 193 of file dlt_daemon_connection.c.

References DLT_CONNECTION_APP_MSG, DLT_CONNECTION_CLIENT_CONNECT, DLT_CONNECTION_CLIENT_MSG_SERIAL, DLT_CONNECTION_CLIENT_MSG_TCP, DLT_CONNECTION_CONTROL_CONNECT, DLT_CONNECTION_CONTROL_MSG, DLT_CONNECTION_GATEWAY, DLT_CONNECTION_GATEWAY_TIMER, DLT_CONNECTION_ONE_S_TIMER, DLT_CONNECTION_SIXTY_S_TIMER, DLT_CONNECTION_SYSTEMD_TIMER, DLT_DAEMON_RCVBUFSIZE, DLT_DAEMON_RCVBUFSIZESERIAL, DLT_DAEMON_RCVBUFSIZESOCK, dlt_gateway_get_connection_receiver(), dlt_receiver_init(), NULL, and DltDaemonLocal::pGateway.

Referenced by dlt_connection_create().

STATIC int dlt_connection_send ( DltConnection conn,
void *  msg,
size_t  msg_size 
)

Generic sending function.

We manage different type of connection which have similar send/write functions. We can then abstract the data transfer using this function, moreover as we often transfer data to different kind of connection within the same loop.

Parameters
connThe connection structure.
msgThe message buffer to be sent
msg_sizeThe length of the message to be sent
Returns
The amount of bytes send on success, -1 otherwise. errno is appropriately set.

Definition at line 67 of file dlt_daemon_connection.c.

References DLT_CONNECTION_CLIENT_MSG_SERIAL, DLT_CONNECTION_CLIENT_MSG_TCP, DLT_CONNECTION_TYPE_MAX, DLT_DAEMON_ERROR_OK, DLT_DAEMON_ERROR_UNKNOWN, dlt_daemon_socket_sendreliable(), DltReceiver::fd, NULL, DltConnection::receiver, and DltConnection::type.

Referenced by dlt_connection_send_multiple().

int dlt_connection_send_multiple ( DltConnection con,
void *  data1,
int  size1,
void *  data2,
int  size2,
int  sendserialheader 
)

Send up to two messages through a connection.

We often need to send 2 messages through a specific connection, plus the serial header. This function groups these different calls.

Parameters
conThe connection to send the messages through.
data1The first message to be sent.
size1The size of the first message.
data2The second message to be send.
size2The second message size.
sendserialheaderWhether we need or not to send the serial header.
Returns
DLT_DAEMON_ERROR_OK on success, -1 otherwise. errno is properly set.

Definition at line 105 of file dlt_daemon_connection.c.

References dlt_connection_send(), DLT_DAEMON_ERROR_UNKNOWN, DLT_RETURN_OK, dltSerialHeader, and NULL.

Referenced by dlt_daemon_client_send_all_multiple().

Variable Documentation

DltConnectionId connectionId
static

Definition at line 51 of file dlt_daemon_connection.c.

Referenced by dlt_connection_create().