automotive-dlt
|
#include <errno.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "dlt_common.h"
#include "dlt_protocol.h"
#include "dlt_client.h"
#include "dlt-control-common.h"
Go to the source code of this file.
Macros | |
#define | pr_fmt(fmt) "Common control: "fmt |
#define | DLT_CTRL_APID "DLTC" |
#define | DLT_CTRL_CTID "DLTC" |
#define | DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock" |
#define | DLT_RECEIVE_TEXTBUFSIZE 1024 |
Functions | |
int | get_verbosity (void) |
void | set_verbosity (int v) |
char * | get_ecuid (void) |
void | set_ecuid (char *ecuid) |
long | get_timeout (void) |
void | set_timeout (long t) |
int | dlt_parse_config_param (char *config_id, char **config_data) |
static int | dlt_control_send_message_to_socket (int sock, DltMessage *msg) |
Send a message to the daemon through the socket. More... | |
static int | prepare_extra_headers (DltMessage *msg, uint8_t *header) |
Prepare the extra headers of a DLT message. More... | |
static int | prepare_headers (DltMessage *msg, uint8_t *header) |
Prepare the headers of a DLT message. More... | |
static DltMessage * | dlt_control_prepare_message (DltControlMsgBody *data) |
Prepare a DLT message. More... | |
static int | dlt_control_init_connection (DltClient *client, void *cb) |
Initialize the connection with the daemon. More... | |
static void * | dlt_control_listen_to_daemon (void *data) |
Daemon listener function. More... | |
static int | dlt_control_callback (DltMessage *message, void *data) |
Internal callback for DLT response. More... | |
int | dlt_control_send_message (DltControlMsgBody *body, int timeout) |
Send a message to the daemon and wait for the asynchronous answer. More... | |
int | dlt_control_init (int(*response_analyzer)(char *, void *, int), char *ecuid, int verbosity) |
Control communication initialization. More... | |
int | dlt_control_deinit (void) |
Control communication clean-up. More... | |
Variables | |
static int(* | response_analyzer_cb )(char *, void *, int) |
Analyze the daemon answer. More... | |
static pthread_t | daemon_connect_thread |
static DltClient | client |
static int | callback_return = -1 |
static pthread_mutex_t | answer_lock = PTHREAD_MUTEX_INITIALIZER |
static pthread_cond_t | answer_cond = PTHREAD_COND_INITIALIZER |
static int | local_verbose |
static char | local_ecuid [DLT_CTRL_ECUID_LEN] |
static long | local_timeout |
app begin@ Copyright (C) 2015 Advanced Driver Information Technology. This code is developed by Advanced Driver Information Technology. Copyright of Advanced Driver Information Technology, Bosch and DENSO.
This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
For further information see http://www.genivi.org/. end@
Definition in file dlt-control-common.c.
#define DLT_CTRL_APID "DLTC" |
Definition at line 69 of file dlt-control-common.c.
Referenced by prepare_extra_headers().
#define DLT_CTRL_CTID "DLTC" |
Definition at line 70 of file dlt-control-common.c.
Referenced by prepare_extra_headers().
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock" |
Definition at line 71 of file dlt-control-common.c.
Referenced by dlt_control_init_connection(), and option_file_parser().
#define DLT_RECEIVE_TEXTBUFSIZE 1024 |
Definition at line 72 of file dlt-control-common.c.
Referenced by dlt_control_callback(), and dlt_parse_config_param().
#define pr_fmt | ( | fmt | ) | "Common control: "fmt |
Definition at line 52 of file dlt-control-common.c.
|
static |
Internal callback for DLT response.
This function is called by the dlt_client_main_loop once a response is read from the DLT socket. After some basic checks, the user's response analyzer is called. The return value of the analyzer is then provided back to the dlt_control_send_message function to be given back as a return value. As this function is called in a dedicated thread, the return value is provided using a global variable. Access to this variable is controlled through a dedicated mutex. New values are signaled using a dedicated condition variable.
message | The DLT answer Unused |
Definition at line 526 of file dlt-control-common.c.
References answer_cond, answer_lock, callback_return, sDltMessage::databuffer, sDltMessage::datasize, DLT_IS_HTYP_WEID, dlt_message_header(), dlt_message_payload(), DLT_OUTPUT_ASCII, DLT_RECEIVE_TEXTBUFSIZE, dlt_set_storageheader(), get_verbosity(), sDltMessage::headerextra, NULL, pr_error, response_analyzer_cb, sDltMessage::standardheader, and sDltMessage::storageheader.
Referenced by dlt_control_init().
int dlt_control_deinit | ( | void | ) |
Control communication clean-up.
Cancels the listener thread and clean=up the dlt client structure.
Definition at line 688 of file dlt-control-common.c.
References daemon_connect_thread, dlt_client_cleanup(), and get_verbosity().
Referenced by dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), and dlt_passive_node_ctrl_single_request().
int dlt_control_init | ( | int(*)(char *, void *, int) | response_analyzer, |
char * | ecuid, | ||
int | verbosity | ||
) |
Control communication initialization.
This will prepare the DLT connection and the thread dedicated to the response listening.
response_analyzer | User defined function used to analyze the response |
ecuid | The ECUID to provide to the daemon |
verbosity | The verbosity level |
Definition at line 648 of file dlt-control-common.c.
References daemon_connect_thread, dlt_client_cleanup(), dlt_control_callback(), dlt_control_init_connection(), dlt_control_listen_to_daemon(), get_verbosity(), NULL, pr_error, response_analyzer_cb, set_ecuid(), and set_verbosity().
Referenced by dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), and dlt_passive_node_ctrl_single_request().
|
static |
Initialize the connection with the daemon.
The connection is initialized using an internal callback. The user's response analyzer will be finally executed by this callback. The client pointer is used to established the connection.
client | A pointer to a valid client structure |
cb | The internal callback to be executed while receiving a new message |
Definition at line 459 of file dlt-control-common.c.
References data, dlt_client_connect(), dlt_client_init(), DLT_CLIENT_MODE_UNIX, dlt_client_register_message_callback(), dlt_client_set_socket_path(), DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH, dlt_parse_config_param(), get_verbosity(), DltClient::mode, NULL, pr_error, pr_verbose, and DltClient::socketPath.
Referenced by dlt_control_init().
|
static |
Daemon listener function.
This function will continuously read on the DLT socket, until an error occurs or the thread executing this function is canceled.
data | Thread parameter |
Definition at line 502 of file dlt-control-common.c.
References data, dlt_client_main_loop(), get_verbosity(), NULL, and pr_verbose.
Referenced by dlt_control_init().
|
static |
Prepare a DLT message.
The DLT message is built using the data given by the user. The data is basically composed of a buffer and a size.
data | The message body to be used to build the DLT message. |
Definition at line 386 of file dlt-control-common.c.
References DltControlMsgBody::data, sDltMessage::databuffer, sDltMessage::databuffersize, sDltMessage::datasize, dlt_message_free(), dlt_message_init(), get_verbosity(), sDltMessage::headerbuffer, NULL, pr_error, pr_verbose, prepare_extra_headers(), prepare_headers(), and DltControlMsgBody::size.
Referenced by dlt_control_send_message().
int dlt_control_send_message | ( | DltControlMsgBody * | body, |
int | timeout | ||
) |
Send a message to the daemon and wait for the asynchronous answer.
The answer is received and analyzed by a dedicated thread. Thus we need to wait for the signal from this thread and then read the return value to be provided to the user. In case of timeout, this function fails. The message provided by the user is formated in DLT format before sending.
body | The message provided by the user |
timeout | The time to wait before considering that no answer will come |
Definition at line 581 of file dlt-control-common.c.
References answer_cond, answer_lock, callback_return, dlt_control_prepare_message(), dlt_control_send_message_to_socket(), dlt_message_free(), get_verbosity(), NULL, pr_error, and DltClient::sock.
Referenced by dlt_logstorage_send_event(), and dlt_passive_node_ctrl_single_request().
|
static |
Send a message to the daemon through the socket.
The socket as to be opened and active before sending.
sock | The socket to send the message through |
msg | The message to be send in DLT format. |
Definition at line 248 of file dlt-control-common.c.
References sDltMessage::databuffer, sDltMessage::datasize, sDltMessage::headerbuffer, sDltMessage::headersize, and pr_error.
Referenced by dlt_control_send_message().
int dlt_parse_config_param | ( | char * | config_id, |
char ** | config_data | ||
) |
Definition at line 161 of file dlt-control-common.c.
References DLT_DAEMON_FLAG_MAX, DLT_RECEIVE_TEXTBUFSIZE, and NULL.
Referenced by dlt_control_init_connection(), main(), and set_ecuid().
char* get_ecuid | ( | void | ) |
Definition at line 106 of file dlt-control-common.c.
References local_ecuid.
Referenced by dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), dlt_passive_node_ctrl_single_request(), and prepare_extra_headers().
long get_timeout | ( | void | ) |
Definition at line 141 of file dlt-control-common.c.
References local_timeout.
Referenced by dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), dlt_logstorage_send_event(), and dlt_passive_node_ctrl_single_request().
int get_verbosity | ( | void | ) |
Definition at line 96 of file dlt-control-common.c.
References local_verbose.
Referenced by dlt_control_callback(), dlt_control_deinit(), dlt_control_init(), dlt_control_init_connection(), dlt_control_listen_to_daemon(), dlt_control_prepare_message(), dlt_control_send_message(), dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), dlt_passive_node_ctrl_single_request(), prepare_extra_headers(), and usage().
|
static |
Prepare the extra headers of a DLT message.
Modifies the extra headers of the message so that it can be sent.
msg | The message to be prepared |
header | The base header to be used. |
Definition at line 276 of file dlt-control-common.c.
References DLT_CTRL_APID, DLT_CTRL_CTID, dlt_message_set_extraparameters(), DLT_MSIN_CONTROL_REQUEST, dlt_set_id(), DLT_STANDARD_HEADER_EXTRA_SIZE, dlt_uptime(), sDltMessage::extendedheader, get_ecuid(), get_verbosity(), sDltMessage::headerextra, pr_error, pr_verbose, and sDltMessage::standardheader.
Referenced by dlt_control_prepare_message().
|
static |
Prepare the headers of a DLT message.
Modifies the headers of the message so that it can be sent.
msg | The message to be prepared |
header | The base header to be used. |
Definition at line 326 of file dlt-control-common.c.
References sDltMessage::datasize, DLT_HTOBE_16, DLT_HTYP_MSBF, DLT_HTYP_PROTOCOL_VERSION1, DLT_HTYP_UEH, DLT_HTYP_WEID, DLT_HTYP_WTMS, dlt_set_storageheader(), DLT_STANDARD_HEADER_EXTRA_SIZE, sDltMessage::headersize, pr_error, pr_verbose, sDltMessage::standardheader, and sDltMessage::storageheader.
Referenced by dlt_control_prepare_message().
void set_ecuid | ( | char * | ecuid | ) |
Definition at line 111 of file dlt-control-common.c.
References DLT_CTRL_ECUID_LEN, dlt_parse_config_param(), local_ecuid, NULL, and pr_error.
Referenced by dlt_control_init(), main(), and parse_args().
void set_timeout | ( | long | t | ) |
Definition at line 146 of file dlt-control-common.c.
References DLT_CTRL_TIMEOUT, local_timeout, and pr_error.
Referenced by main(), and parse_args().
void set_verbosity | ( | int | v | ) |
Definition at line 101 of file dlt-control-common.c.
References local_verbose.
Referenced by dlt_control_init(), and parse_args().
|
static |
Definition at line 90 of file dlt-control-common.c.
Referenced by dlt_control_callback(), and dlt_control_send_message().
|
static |
Definition at line 89 of file dlt-control-common.c.
Referenced by dlt_control_callback(), and dlt_control_send_message().
|
static |
Definition at line 88 of file dlt-control-common.c.
Referenced by dlt_control_callback(), and dlt_control_send_message().
|
static |
Definition at line 87 of file dlt-control-common.c.
Referenced by main().
|
static |
Definition at line 86 of file dlt-control-common.c.
Referenced by dlt_control_deinit(), and dlt_control_init().
|
static |
Definition at line 93 of file dlt-control-common.c.
Referenced by get_ecuid(), and set_ecuid().
|
static |
Definition at line 94 of file dlt-control-common.c.
Referenced by get_timeout(), and set_timeout().
|
static |
Definition at line 92 of file dlt-control-common.c.
Referenced by get_verbosity(), and set_verbosity().
|
static |
Analyze the daemon answer.
This function as to be provided by the user of the connection.
answer | The textual answer of the daemon |
payload | The daemons answer payload |
length | The daemons answer payload length |
Definition at line 84 of file dlt-control-common.c.
Referenced by dlt_control_callback(), and dlt_control_init().