diff options
author | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-20 14:58:19 +0100 |
---|---|---|
committer | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-21 10:23:41 +0100 |
commit | dca8ab254aa0a687c32009079d85e4d8f960b213 (patch) | |
tree | e63b6a552fd9f61873892110a56a89ef354864cd /src/lib | |
parent | 0d0c74640c8b792db37cb9f884f89f7561ea551f (diff) | |
download | DLT-daemon-dca8ab254aa0a687c32009079d85e4d8f960b213.tar.gz |
Code beautification using uncrustify
Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dlt_client.c | 630 | ||||
-rw-r--r-- | src/lib/dlt_client_cfg.h | 4 | ||||
-rw-r--r-- | src/lib/dlt_env_ll.c | 573 | ||||
-rw-r--r-- | src/lib/dlt_filetransfer.c | 555 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 3092 | ||||
-rw-r--r-- | src/lib/dlt_user_cfg.h | 2 |
6 files changed, 2162 insertions, 2694 deletions
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c index 4723e00..745aa4f 100644 --- a/src/lib/dlt_client.c +++ b/src/lib/dlt_client.c @@ -63,28 +63,28 @@ * $LastChangedRevision$ * $LastChangedDate$ * $LastChangedBy$ - Initials Date Comment - aw 12.07.2010 initial + * Initials Date Comment + * aw 12.07.2010 initial */ #include <stdio.h> #if defined (__WIN32__) || defined (_MSC_VER) -#pragma warning(disable : 4996) /* Switch off C4996 warnings */ -#include <winsock2.h> /* for socket(), connect(), send(), and recv() */ +# pragma warning(disable : 4996) /* Switch off C4996 warnings */ +# include <winsock2.h> /* for socket(), connect(), send(), and recv() */ #else -#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */ -#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ -#include <netdb.h> -#include <sys/stat.h> -#include <sys/un.h> +# include <sys/socket.h> /* for socket(), connect(), send(), and recv() */ +# include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ +# include <netdb.h> +# include <sys/stat.h> +# include <sys/un.h> #endif #if defined(_MSC_VER) -#include <io.h> +# include <io.h> #else -#include <unistd.h> -#include <syslog.h> +# include <unistd.h> +# include <syslog.h> #endif #include <fcntl.h> @@ -98,34 +98,31 @@ #include "dlt_client.h" #include "dlt_client_cfg.h" -static int (*message_callback_function) (DltMessage *message, void *data) = NULL; +static int (*message_callback_function)(DltMessage *message, void *data) = NULL; static char str[DLT_CLIENT_TEXTBUFSIZE]; -void dlt_client_register_message_callback(int (*registerd_callback) (DltMessage *message, void *data)){ +void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage *message, void *data)) +{ message_callback_function = registerd_callback; } DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose) { - if (verbose && port != DLT_DAEMON_TCP_PORT) - { + if (verbose && (port != DLT_DAEMON_TCP_PORT)) dlt_vlog(LOG_INFO, "Init dlt client struct with port %d\n", port); - } if (client == NULL) - { return DLT_RETURN_ERROR; - } - client->sock=-1; - client->servIP=0; - client->serialDevice=0; - client->baudrate=DLT_CLIENT_INITIAL_BAUDRATE; + client->sock = -1; + client->servIP = 0; + client->serialDevice = 0; + client->baudrate = DLT_CLIENT_INITIAL_BAUDRATE; client->port = port; client->socketPath = 0; - client->mode=DLT_CLIENT_MODE_TCP; - client->receiver.buffer=0; + client->mode = DLT_CLIENT_MODE_TCP; + client->receiver.buffer = 0; return DLT_RETURN_OK; } @@ -139,28 +136,25 @@ DltReturnValue dlt_client_init(DltClient *client, int verbose) /* the port may be specified by an environment variable */ env_daemon_port = getenv(DLT_CLIENT_ENV_DAEMON_TCP_PORT); - if (env_daemon_port != NULL) - { + + if (env_daemon_port != NULL) { tmp_port = atoi(env_daemon_port); - if ((tmp_port < IPPORT_RESERVED) || (tmp_port > USHRT_MAX)) - { + + if ((tmp_port < IPPORT_RESERVED) || (tmp_port > USHRT_MAX)) { dlt_vlog(LOG_ERR, "Specified port is out of possible range: %d.\n", tmp_port); return DLT_RETURN_ERROR; } - else - { + else { servPort = tmp_port; } } if (verbose) - { dlt_vlog(LOG_INFO, "Init dlt client struct with default port: %hu.\n", servPort); - } return dlt_client_init_port(client, servPort, verbose); } @@ -174,21 +168,19 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; - if (client==0) - { + if (client == 0) return DLT_RETURN_ERROR; - } - switch (client->mode) - { + switch (client->mode) { case DLT_CLIENT_MODE_TCP: snprintf(portnumbuffer, 32, "%d", client->port); + if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return DLT_RETURN_ERROR; } - for(p = servinfo; p != NULL; p = p->ai_next) { + for (p = servinfo; p != NULL; p = p->ai_next) { if ((client->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) { snprintf(str, DLT_CLIENT_TEXTBUFSIZE, "socket() failed! %s\n", @@ -196,6 +188,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) dlt_log(LOG_WARNING, str); continue; } + if (connect(client->sock, p->ai_addr, p->ai_addrlen) < 0) { snprintf(str, DLT_CLIENT_TEXTBUFSIZE, "connect() failed! %s\n", @@ -216,81 +209,79 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) } if (verbose) - { - printf("Connected to DLT daemon (%s)\n",client->servIP); - } + printf("Connected to DLT daemon (%s)\n", client->servIP); + break; case DLT_CLIENT_MODE_SERIAL: /* open serial connection */ - client->sock=open(client->serialDevice,O_RDWR); - if (client->sock<0) - { - fprintf(stderr,"ERROR: Failed to open device %s\n", client->serialDevice); + client->sock = open(client->serialDevice, O_RDWR); + + if (client->sock < 0) { + fprintf(stderr, "ERROR: Failed to open device %s\n", client->serialDevice); return DLT_RETURN_ERROR; } - if (isatty(client->sock)) - { + if (isatty(client->sock)) { #if !defined (__WIN32__) - if (dlt_setup_serial(client->sock,client->baudrate) < DLT_RETURN_OK) - { - fprintf(stderr,"ERROR: Failed to configure serial device %s (%s) \n", client->serialDevice, strerror(errno)); + + if (dlt_setup_serial(client->sock, client->baudrate) < DLT_RETURN_OK) { + fprintf(stderr, "ERROR: Failed to configure serial device %s (%s) \n", client->serialDevice, + strerror(errno)); return DLT_RETURN_ERROR; } + #else - return DLT_RETURN_ERROR; + return DLT_RETURN_ERROR; #endif } - else - { + else { if (verbose) - { - fprintf(stderr,"ERROR: Device is not a serial device, device = %s (%s) \n", client->serialDevice, strerror(errno)); - } + fprintf(stderr, + "ERROR: Device is not a serial device, device = %s (%s) \n", + client->serialDevice, + strerror(errno)); + return DLT_RETURN_ERROR; } if (verbose) - { printf("Connected to %s\n", client->serialDevice); - } + break; case DLT_CLIENT_MODE_UNIX: - if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) - { + + if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { fprintf(stderr, "ERROR: (unix) socket error: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - memcpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path)-1); + memcpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path) - 1); if (connect(client->sock, (struct sockaddr_un *)&addr, - sizeof(addr)) == -1) - { + sizeof(addr)) == -1) { fprintf(stderr, "ERROR: (unix) connect error: %s\n", strerror(errno)); return DLT_RETURN_ERROR; } - if (client->sock < 0) - { - fprintf(stderr,"ERROR: Failed to open device %s\n", + if (client->sock < 0) { + fprintf(stderr, "ERROR: Failed to open device %s\n", client->socketPath); return DLT_RETURN_ERROR; } + break; default: + if (verbose) - { fprintf(stderr, "ERROR: Mode not supported: %d\n", client->mode); - } + return DLT_RETURN_ERROR; } - if (dlt_receiver_init(&(client->receiver), client->sock, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) - { + if (dlt_receiver_init(&(client->receiver), client->sock, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) { fprintf(stderr, "ERROR initializing receiver\n"); return DLT_RETURN_ERROR; } @@ -303,37 +294,30 @@ DltReturnValue dlt_client_cleanup(DltClient *client, int verbose) int ret = DLT_RETURN_OK; if (verbose) - { printf("Cleanup dlt client\n"); - } if (client == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (client->sock!=-1) - { + if (client->sock != -1) close(client->sock); - } - if (dlt_receiver_free(&(client->receiver)) != DLT_RETURN_OK) - { + if (dlt_receiver_free(&(client->receiver)) != DLT_RETURN_OK) { dlt_vlog(LOG_WARNING, "Failed to free receiver\n"); ret = DLT_RETURN_ERROR; } - if (client->serialDevice) - { + + if (client->serialDevice) { free(client->serialDevice); client->serialDevice = NULL; } - if (client->servIP) - { + + if (client->servIP) { free(client->servIP); client->servIP = NULL; } - if (client->socketPath) - { + + if (client->socketPath) { free(client->socketPath); client->socketPath = NULL; } @@ -346,72 +330,58 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) DltMessage msg; int ret; - if (client==0) - { + if (client == 0) return DLT_RETURN_ERROR; - } - if (dlt_message_init(&msg,verbose) == DLT_RETURN_ERROR) - { + if (dlt_message_init(&msg, verbose) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } - while (1) - { + while (1) { /* wait for data from socket or serial connection */ ret = dlt_receiver_receive(&(client->receiver), client->mode); - if (ret<=0) - { + if (ret <= 0) { /* No more data to be received */ - if (dlt_message_free(&msg,verbose) == DLT_RETURN_ERROR) - { + if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } return DLT_RETURN_TRUE; } - while (dlt_message_read(&msg,(unsigned char*)(client->receiver.buf),client->receiver.bytesRcvd,0,verbose) == DLT_MESSAGE_ERROR_OK) - { + while (dlt_message_read(&msg, (unsigned char *)(client->receiver.buf), client->receiver.bytesRcvd, 0, + verbose) == DLT_MESSAGE_ERROR_OK) { /* Call callback function */ if (message_callback_function) - { - (*message_callback_function)(&msg,data); - } + (*message_callback_function)(&msg, data); - if (msg.found_serialheader) - { - if (dlt_receiver_remove(&(client->receiver),msg.headersize+msg.datasize-sizeof(DltStorageHeader)+sizeof(dltSerialHeader)) == DLT_RETURN_ERROR) - { + if (msg.found_serialheader) { + if (dlt_receiver_remove(&(client->receiver), + msg.headersize + msg.datasize - sizeof(DltStorageHeader) + + sizeof(dltSerialHeader)) == + DLT_RETURN_ERROR) { /* Return value ignored */ - dlt_message_free(&msg,verbose); + dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } } - else - { - if (dlt_receiver_remove(&(client->receiver),msg.headersize+msg.datasize-sizeof(DltStorageHeader)) == DLT_RETURN_ERROR) - { - /* Return value ignored */ - dlt_message_free(&msg,verbose); - return DLT_RETURN_ERROR; - } + else if (dlt_receiver_remove(&(client->receiver), + msg.headersize + msg.datasize - sizeof(DltStorageHeader)) == + DLT_RETURN_ERROR) { + /* Return value ignored */ + dlt_message_free(&msg, verbose); + return DLT_RETURN_ERROR; } } - if (dlt_receiver_move_to_begin(&(client->receiver)) == DLT_RETURN_ERROR) - { + if (dlt_receiver_move_to_begin(&(client->receiver)) == DLT_RETURN_ERROR) { /* Return value ignored */ - dlt_message_free(&msg,verbose); + dlt_message_free(&msg, verbose); return DLT_RETURN_ERROR; } } - if (dlt_message_free(&msg,verbose) == DLT_RETURN_ERROR) - { + if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } @@ -425,92 +395,87 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti uint32_t id_tmp; uint32_t id; - if ((client==0) || (client->sock<0) || (apid==0) || (ctid==0)) - { + if ((client == 0) || (client->sock < 0) || (apid == 0) || (ctid == 0)) return DLT_RETURN_ERROR; - } /* initialise new message */ - if (dlt_message_init(&msg,0) == DLT_RETURN_ERROR) - { + if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } /* prepare payload of data */ msg.datasize = size; - if (msg.databuffer && (msg.databuffersize < msg.datasize)) - { + + if (msg.databuffer && (msg.databuffersize < msg.datasize)) { free(msg.databuffer); - msg.databuffer=0; + msg.databuffer = 0; } - if (msg.databuffer == 0){ - msg.databuffer = (uint8_t *) malloc(msg.datasize); + + if (msg.databuffer == 0) { + msg.databuffer = (uint8_t *)malloc(msg.datasize); msg.databuffersize = msg.datasize; } - if(msg.databuffer == 0) - { - dlt_message_free(&msg,0); + + if (msg.databuffer == 0) { + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } /* copy data */ - memcpy(msg.databuffer,payload,size); + memcpy(msg.databuffer, payload, size); /* prepare storage header */ - msg.storageheader = (DltStorageHeader*)msg.headerbuffer; + msg.storageheader = (DltStorageHeader *)msg.headerbuffer; - if (dlt_set_storageheader(msg.storageheader,"") == DLT_RETURN_ERROR) - { - dlt_message_free(&msg,0); + if (dlt_set_storageheader(msg.storageheader, "") == DLT_RETURN_ERROR) { + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } /* prepare standard header */ - msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); - msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ; + msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1; - #if (BYTE_ORDER==BIG_ENDIAN) - msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF); + #if (BYTE_ORDER == BIG_ENDIAN) + msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF); #endif msg.standardheader->mcnt = 0; /* Set header extra parameters */ - dlt_set_id(msg.headerextra.ecu,client->ecuid); - //msg.headerextra.seid = 0; + dlt_set_id(msg.headerextra.ecu, client->ecuid); + /*msg.headerextra.seid = 0; */ msg.headerextra.tmsp = dlt_uptime(); /* Copy header extra parameters to headerbuffer */ - if (dlt_message_set_extraparameters(&msg,0) == DLT_RETURN_ERROR) - { - dlt_message_free(&msg,0); + if (dlt_message_set_extraparameters(&msg, 0) == DLT_RETURN_ERROR) { + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } /* prepare extended header */ - msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + - sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) ); + msg.extendedheader = (DltExtendedHeader *)(msg.headerbuffer + + sizeof(DltStorageHeader) + + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); msg.extendedheader->msin = DLT_MSIN_CONTROL_REQUEST; msg.extendedheader->noar = 1; /* number of arguments */ - dlt_set_id(msg.extendedheader->apid,(apid[0]=='\0')?DLT_CLIENT_DUMMY_APP_ID:apid); - dlt_set_id(msg.extendedheader->ctid,(ctid[0]=='\0')?DLT_CLIENT_DUMMY_CON_ID:ctid); + dlt_set_id(msg.extendedheader->apid, (apid[0] == '\0') ? DLT_CLIENT_DUMMY_APP_ID : apid); + dlt_set_id(msg.extendedheader->ctid, (ctid[0] == '\0') ? DLT_CLIENT_DUMMY_CON_ID : ctid); /* prepare length information */ msg.headersize = sizeof(DltStorageHeader) + - sizeof(DltStandardHeader) + - sizeof(DltExtendedHeader) + - DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); + sizeof(DltStandardHeader) + + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); - len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize; - if (len>UINT16_MAX) - { - fprintf(stderr,"Critical: Huge injection message discarded!\n"); - dlt_message_free(&msg,0); + len = msg.headersize - sizeof(DltStorageHeader) + msg.datasize; + + if (len > UINT16_MAX) { + fprintf(stderr, "Critical: Huge injection message discarded!\n"); + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } @@ -518,69 +483,71 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti msg.standardheader->len = DLT_HTOBE_16(len); /* Send data (without storage header) */ - if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) - { + if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) { /* via FileDescriptor */ - ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader)); - if (0 > ret) - { + ret = + write(client->sock, msg.headerbuffer + sizeof(DltStorageHeader), msg.headersize - sizeof(DltStorageHeader)); + + if (0 > ret) { dlt_log(LOG_ERR, "Sending message failed\n"); - dlt_message_free(&msg,0); + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } - ret=write(client->sock, msg.databuffer,msg.datasize); - if (0 > ret){ + ret = write(client->sock, msg.databuffer, msg.datasize); + + if (0 > ret) { dlt_log(LOG_ERR, "Sending message failed\n"); - dlt_message_free(&msg,0); + dlt_message_free(&msg, 0); return DLT_RETURN_ERROR; } - id_tmp = *((uint32_t*)(msg.databuffer)); + id_tmp = *((uint32_t *)(msg.databuffer)); id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp); dlt_vlog(LOG_INFO, "Control message forwarded : %s\n", dlt_get_service_name(id)); } - else - { + else { /* via Socket */ - send(client->sock, (const char *)(msg.headerbuffer+sizeof(DltStorageHeader)),msg.headersize-sizeof(DltStorageHeader),0); - send(client->sock, (const char *)msg.databuffer,msg.datasize,0); + send(client->sock, (const char *)(msg.headerbuffer + sizeof(DltStorageHeader)), + msg.headersize - sizeof(DltStorageHeader), 0); + send(client->sock, (const char *)msg.databuffer, msg.datasize, 0); } /* free message */ - if (dlt_message_free(&msg,0) == DLT_RETURN_ERROR) - { + if (dlt_message_free(&msg, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } -DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *ctid, uint32_t serviceID, uint8_t *buffer, uint32_t size) +DltReturnValue dlt_client_send_inject_msg(DltClient *client, + char *apid, + char *ctid, + uint32_t serviceID, + uint8_t *buffer, + uint32_t size) { uint8_t *payload; int offset; - payload = (uint8_t *) malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); + payload = (uint8_t *)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size); - if(payload==0) - { + if (payload == 0) return DLT_RETURN_ERROR; - } offset = 0; - memcpy(payload , &serviceID,sizeof(serviceID)); - offset+=sizeof(uint32_t); - memcpy(payload+offset, &size, sizeof(size)); - offset+=sizeof(uint32_t); - memcpy(payload+offset, buffer, size); + memcpy(payload, &serviceID, sizeof(serviceID)); + offset += sizeof(uint32_t); + memcpy(payload + offset, &size, sizeof(size)); + offset += sizeof(uint32_t); + memcpy(payload + offset, buffer, size); /* free message */ - if (dlt_client_send_ctrl_msg(client,apid,ctid,payload,sizeof(uint32_t) + sizeof(uint32_t) + size) == DLT_RETURN_ERROR) - { + if (dlt_client_send_ctrl_msg(client, apid, ctid, payload, + sizeof(uint32_t) + sizeof(uint32_t) + size) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -597,28 +564,25 @@ DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ct int ret = DLT_RETURN_ERROR; if (client == NULL) - { return ret; - } + req = (DltServiceSetLogLevel *)malloc(sizeof(DltServiceSetLogLevel)); - req = (DltServiceSetLogLevel *) malloc(sizeof(DltServiceSetLogLevel)); if (req == NULL) - { return ret; - } + memset(req, 0, sizeof(DltServiceSetLogLevel)); req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL; - dlt_set_id(req->apid,apid); - dlt_set_id(req->ctid,ctid); - req->log_level=logLevel; - dlt_set_id(req->com,"remo"); + dlt_set_id(req->apid, apid); + dlt_set_id(req->ctid, ctid); + req->log_level = logLevel; + dlt_set_id(req->com, "remo"); - /* free message */ + /* free message */ ret = dlt_client_send_ctrl_msg(client, "APP", "CON", - (uint8_t*) req, + (uint8_t *)req, sizeof(DltServiceSetLogLevel)); @@ -633,16 +597,12 @@ DltReturnValue dlt_client_get_log_info(DltClient *client) int ret = DLT_RETURN_ERROR; if (client == NULL) - { return ret; - } - req = (DltServiceGetLogInfoRequest *) malloc(sizeof(DltServiceGetLogInfoRequest)); + req = (DltServiceGetLogInfoRequest *)malloc(sizeof(DltServiceGetLogInfoRequest)); if (req == NULL) - { return ret; - } req->service_id = DLT_SERVICE_ID_GET_LOG_INFO; req->options = 7; @@ -654,7 +614,7 @@ DltReturnValue dlt_client_get_log_info(DltClient *client) ret = dlt_client_send_ctrl_msg(client, "", "", - (uint8_t *) req, + (uint8_t *)req, sizeof(DltServiceGetLogInfoRequest)); free(req); @@ -668,17 +628,13 @@ DltReturnValue dlt_client_get_default_log_level(DltClient *client) int ret = DLT_RETURN_ERROR; if (client == NULL) - { return ret; - } req = (DltServiceGetDefaultLogLevelRequest *) - malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); + malloc(sizeof(DltServiceGetDefaultLogLevelRequest)); if (req == NULL) - { return ret; - } req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL; @@ -686,7 +642,7 @@ DltReturnValue dlt_client_get_default_log_level(DltClient *client) ret = dlt_client_send_ctrl_msg(client, "", "", - (uint8_t *) req, + (uint8_t *)req, sizeof(DltServiceGetDefaultLogLevelRequest)); free(req); @@ -700,11 +656,9 @@ DltReturnValue dlt_client_get_software_version(DltClient *client) int ret = DLT_RETURN_ERROR; if (client == NULL) - { return ret; - } - req = (DltServiceGetSoftwareVersion *) malloc(sizeof(DltServiceGetSoftwareVersion)); + req = (DltServiceGetSoftwareVersion *)malloc(sizeof(DltServiceGetSoftwareVersion)); req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; @@ -712,7 +666,7 @@ DltReturnValue dlt_client_get_software_version(DltClient *client) ret = dlt_client_send_ctrl_msg(client, "", "", - (uint8_t *) req, + (uint8_t *)req, sizeof(DltServiceGetSoftwareVersion)); free(req); @@ -725,24 +679,21 @@ DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char DltServiceSetLogLevel *req; uint8_t *payload; - payload = (uint8_t *) malloc(sizeof(DltServiceSetLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetLogLevel)); - if(payload==0) - { + if (payload == 0) return DLT_RETURN_ERROR; - } - req = (DltServiceSetLogLevel *) payload; + req = (DltServiceSetLogLevel *)payload; memset(req, 0, sizeof(DltServiceSetLogLevel)); req->service_id = DLT_SERVICE_ID_SET_TRACE_STATUS; - dlt_set_id(req->apid,apid); - dlt_set_id(req->ctid,ctid); - req->log_level=traceStatus; - dlt_set_id(req->com,"remo"); - - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR) - { + dlt_set_id(req->apid, apid); + dlt_set_id(req->ctid, ctid); + req->log_level = traceStatus; + dlt_set_id(req->com, "remo"); + + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -757,22 +708,20 @@ DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defa DltServiceSetDefaultLogLevel *req; uint8_t *payload; - payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if(payload==0) - { + if (payload == 0) return DLT_RETURN_ERROR; - } - req = (DltServiceSetDefaultLogLevel *) payload; + req = (DltServiceSetDefaultLogLevel *)payload; req->service_id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL; - req->log_level=defaultLogLevel; - dlt_set_id(req->com,"remo"); + req->log_level = defaultLogLevel; + dlt_set_id(req->com, "remo"); - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) - { + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, + sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -787,22 +736,19 @@ DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel DltServiceSetDefaultLogLevel *req; uint8_t *payload; - payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); if (payload == 0) - { return DLT_RETURN_ERROR; - } - req = (DltServiceSetDefaultLogLevel *) payload; + req = (DltServiceSetDefaultLogLevel *)payload; req->service_id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL; req->log_level = LogLevel; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) - { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) { free(payload); return DLT_RETURN_ERROR; } @@ -817,22 +763,20 @@ DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t d DltServiceSetDefaultLogLevel *req; uint8_t *payload; - payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if(payload==0) - { + if (payload == 0) return DLT_RETURN_ERROR; - } - req = (DltServiceSetDefaultLogLevel *) payload; + req = (DltServiceSetDefaultLogLevel *)payload; req->service_id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS; - req->log_level=defaultTraceStatus; - dlt_set_id(req->com,"remo"); + req->log_level = defaultTraceStatus; + dlt_set_id(req->com, "remo"); - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) - { + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, + sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -847,29 +791,26 @@ DltReturnValue dlt_client_send_all_trace_status(DltClient *client, uint8_t trace DltServiceSetDefaultLogLevel *req; uint8_t *payload; - if (client == NULL) - { + if (client == NULL) { dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__); return DLT_RETURN_ERROR; } - payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetDefaultLogLevel)); - if (payload == 0) - { + if (payload == 0) { dlt_vlog(LOG_ERR, "%s: Could not allocate memory %d\n", __func__, sizeof(DltServiceSetDefaultLogLevel)); return DLT_RETURN_ERROR; } - req = (DltServiceSetDefaultLogLevel *) payload; + req = (DltServiceSetDefaultLogLevel *)payload; req->service_id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS; req->log_level = traceStatus; dlt_set_id(req->com, "remo"); /* free message */ - if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) - { + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1) { free(payload); return DLT_RETURN_ERROR; } @@ -884,21 +825,18 @@ DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPa DltServiceSetVerboseMode *req; uint8_t *payload; - payload = (uint8_t *) malloc(sizeof(DltServiceSetVerboseMode)); + payload = (uint8_t *)malloc(sizeof(DltServiceSetVerboseMode)); - if(payload==0) - { + if (payload == 0) return DLT_RETURN_ERROR; - } - req = (DltServiceSetVerboseMode *) payload; + req = (DltServiceSetVerboseMode *)payload; req->service_id = DLT_SERVICE_ID_SET_TIMING_PACKETS; - req->new_status=timingPakets; + req->new_status = timingPakets; - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) - { + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR) { free(payload); return DLT_RETURN_ERROR; } @@ -914,11 +852,9 @@ DltReturnValue dlt_client_send_store_config(DltClient *client) service_id = DLT_SERVICE_ID_STORE_CONFIG; - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",(uint8_t*)&service_id,sizeof(uint32_t)) == DLT_RETURN_ERROR) - { + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } @@ -929,21 +865,17 @@ DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client) service_id = DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT; - /* free message */ - if (dlt_client_send_ctrl_msg(client,"APP","CON",(uint8_t*)&service_id,sizeof(uint32_t)) == DLT_RETURN_ERROR) - { + /* free message */ + if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t *)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } return DLT_RETURN_OK; } DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate) { - if (client==0) - { + if (client == 0) return DLT_RETURN_ERROR; - } client->baudrate = dlt_convert_serial_speed(baudrate); @@ -953,33 +885,36 @@ DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate) int dlt_client_set_server_ip(DltClient *client, char *ipaddr) { client->servIP = strdup(ipaddr); - if (client->servIP == NULL) - { + + if (client->servIP == NULL) { dlt_log(LOG_ERR, "ERROR: failed to duplicate server IP\n"); return DLT_RETURN_ERROR; } + return DLT_RETURN_OK; } int dlt_client_set_serial_device(DltClient *client, char *serial_device) { client->serialDevice = strdup(serial_device); - if (client->serialDevice == NULL) - { + + if (client->serialDevice == NULL) { dlt_log(LOG_ERR, "ERROR: failed to duplicate serial device\n"); return DLT_RETURN_ERROR; } + return DLT_RETURN_OK; } int dlt_client_set_socket_path(DltClient *client, char *socket_path) { client->socketPath = strdup(socket_path); - if (client->socketPath == NULL) - { + + if (client->socketPath == NULL) { dlt_log(LOG_ERR, "ERROR: failed to duplicate socket path\n"); return DLT_RETURN_ERROR; } + return DLT_RETURN_OK; } /** @@ -989,19 +924,17 @@ int dlt_client_set_socket_path(DltClient *client, char *socket_path) * @param count_app_ids number of app_ids which needs to be freed */ DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse *resp, - int count_app_ids) + int count_app_ids) { AppIDsType *app = NULL; ContextIDsInfoType *con = NULL; int i = 0; int j = 0; - for (i = 0; i < count_app_ids; i++) - { + for (i = 0; i < count_app_ids; i++) { app = &(resp->log_info_type.app_ids[i]); - for (j = 0; j < app->count_context_ids; j++) - { + for (j = 0; j < app->count_context_ids; j++) { con = &(app->context_id_info[j]); free(con->context_description); @@ -1022,7 +955,7 @@ DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoR } DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse *resp, - char *resp_text) + char *resp_text) { AppIDsType *app = NULL; ContextIDsInfoType *con = NULL; @@ -1032,56 +965,48 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo int rp_count = 0; if ((resp == NULL) || (resp_text == NULL)) - { return DLT_RETURN_WRONG_PARAMETER; - } /* ------------------------------------------------------ - get_log_info data structure(all data is ascii) - - get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. - ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. - jj jj kk kk kk .. .. - ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ - aa : get mode (fix value at 0x07) - bb bb : list num of apid (little endian) - cc cc cc cc: apid - dd dd : list num of ctid (little endian) - ee ee ee ee: ctid - ff : log level - gg : trace status - hh hh : description length of ctid - ii ii .. : description text of ctid - jj jj : description length of apid - kk kk .. : description text of apid - ------------------------------------------------------ */ + * get_log_info data structure(all data is ascii) + * + * get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. + * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. .. + * jj jj kk kk kk .. .. + * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~ + * aa : get mode (fix value at 0x07) + * bb bb : list num of apid (little endian) + * cc cc cc cc: apid + * dd dd : list num of ctid (little endian) + * ee ee ee ee: ctid + * ff : log level + * gg : trace status + * hh hh : description length of ctid + * ii ii .. : description text of ctid + * jj jj : description length of apid + * kk kk .. : description text of apid + * ------------------------------------------------------ */ rp = resp_text + DLT_GET_LOG_INFO_HEADER; rp_count = 0; /* check if status is acceptable */ if ((resp->status < GET_LOG_INFO_STATUS_MIN) || - (resp->status > GET_LOG_INFO_STATUS_MAX)) - { + (resp->status > GET_LOG_INFO_STATUS_MAX)) { if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX) - { dlt_vlog(LOG_WARNING, "The status(%d) is invalid: NO matching Context IDs\n", resp->status); - } else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW) - { dlt_vlog(LOG_WARNING, "The status(%d) is invalid: Response data over flow\n", resp->status); - } else - { dlt_vlog(LOG_WARNING, "The status(%d) is invalid\n", resp->status); - } + return DLT_RETURN_ERROR; } @@ -1090,17 +1015,15 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo &rp_count); resp->log_info_type.app_ids = (AppIDsType *)calloc - (resp->log_info_type.count_app_ids, sizeof(AppIDsType)); + (resp->log_info_type.count_app_ids, sizeof(AppIDsType)); - if (resp->log_info_type.app_ids == NULL) - { + if (resp->log_info_type.app_ids == NULL) { dlt_vlog(LOG_ERR, "calloc failed for app_ids\n"); dlt_client_free_calloc_failed_get_log_info(resp, 0); return DLT_RETURN_ERROR; } - for (i = 0; i < resp->log_info_type.count_app_ids; i++) - { + for (i = 0; i < resp->log_info_type.count_app_ids; i++) { app = &(resp->log_info_type.app_ids[i]); /* get app id */ dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE); @@ -1110,18 +1033,16 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo &rp_count); app->context_id_info = (ContextIDsInfoType *)calloc - (app->count_context_ids, sizeof(ContextIDsInfoType)); + (app->count_context_ids, sizeof(ContextIDsInfoType)); - if (app->context_id_info == NULL) - { + if (app->context_id_info == NULL) { dlt_vlog(LOG_ERR, "calloc failed for context_id_info\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } - for (j = 0; j < app->count_context_ids; j++) - { + for (j = 0; j < app->count_context_ids; j++) { con = &(app->context_id_info[j]); /* get con id */ dlt_getloginfo_conv_ascii_to_id(rp, @@ -1131,30 +1052,27 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo /* log_level */ if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7)) - { con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); - } /* trace status */ if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7)) - { con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count); - } /* context desc */ - if (resp->status == 7){ + if (resp->status == 7) { con->len_context_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); con->context_description = (char *)calloc - (con->len_context_description + 1, sizeof(char)); - if (con->context_description == 0) - { + (con->len_context_description + 1, sizeof(char)); + + if (con->context_description == 0) { dlt_log(LOG_ERR, "calloc failed for context description\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_description, @@ -1163,18 +1081,18 @@ DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoRespo } /* application desc */ - if (resp->status == 7) - { + if (resp->status == 7) { app->len_app_description = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count); app->app_description = (char *)calloc - (app->len_app_description + 1, sizeof(char)); - if (app->app_description == 0) - { + (app->len_app_description + 1, sizeof(char)); + + if (app->app_description == 0) { dlt_log(LOG_ERR, "calloc failed for application description\n"); dlt_client_free_calloc_failed_get_log_info(resp, i); return DLT_RETURN_ERROR; } + dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_description, @@ -1192,16 +1110,12 @@ int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse *resp) int j = 0; if (resp == NULL) - { return DLT_RETURN_OK; - } - for (i = 0; i < resp->log_info_type.count_app_ids; i++) - { + for (i = 0; i < resp->log_info_type.count_app_ids; i++) { app = resp->log_info_type.app_ids[i]; - for (j = 0; j < app.count_context_ids; j++) - { + for (j = 0; j < app.count_context_ids; j++) { free(app.context_id_info[j].context_description); app.context_id_info[j].context_description = NULL; } diff --git a/src/lib/dlt_client_cfg.h b/src/lib/dlt_client_cfg.h index bfa4d96..7ff473f 100644 --- a/src/lib/dlt_client_cfg.h +++ b/src/lib/dlt_client_cfg.h @@ -84,9 +84,9 @@ /* Initial baudrate */ #if !defined (__WIN32__) && !defined(_MSC_VER) -#define DLT_CLIENT_INITIAL_BAUDRATE B115200 +# define DLT_CLIENT_INITIAL_BAUDRATE B115200 #else -#define DLT_CLIENT_INITIAL_BAUDRATE 0 +# define DLT_CLIENT_INITIAL_BAUDRATE 0 #endif /* Name of environment variable for specifying the daemon port */ diff --git a/src/lib/dlt_env_ll.c b/src/lib/dlt_env_ll.c index 8972747..85d2250 100644 --- a/src/lib/dlt_env_ll.c +++ b/src/lib/dlt_env_ll.c @@ -22,7 +22,7 @@ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_env_ll.c -*/ + */ #include "dlt_user.h" #include <string.h> @@ -55,33 +55,26 @@ * * @return 0 if successful, -1 else */ -int dlt_env_extract_id(char ** const env, char * id) +int dlt_env_extract_id(char **const env, char *id) { - int i; - if (!env || !id) - { - return -1; - } + int i; - if (!(*env)) - { - return -1; - } + if (!env || !id) + return -1; - memset(id, 0, 4); + if (!(*env)) + return -1; - for (i = 0; (i<4) && (**env != ':') && (**env != 0); ++i) - { - *id++ = *((*env)++); - } + memset(id, 0, 4); - /* the next/last character must be ':' */ - if ((0 != **env) && (':' == **env)) - { - return 0; - } + for (i = 0; (i < 4) && (**env != ':') && (**env != 0); ++i) + *id++ = *((*env)++); - return -1; + /* the next/last character must be ':' */ + if ((0 != **env) && (':' == **env)) + return 0; + + return -1; } @@ -90,112 +83,77 @@ int dlt_env_extract_id(char ** const env, char * id) * * Stops end of string or if ';' is detected */ -int dlt_env_helper_to_lower(char ** const env, char *result, int const res_len) +int dlt_env_helper_to_lower(char **const env, char *result, int const res_len) { - int count = 0; - char ch = *(*env); + int count = 0; + char ch = *(*env); - if (!env || !result) - { - return -1; - } + if (!env || !result) + return -1; - if (!(*env)) - { - return -1; - } - - count = 0; - ch = *(*env); - while (ch && (count < res_len-1) && (ch != ';')) - { - if (ch >= 'A' && ch <= 'Z') - { - result[count] = ch + 'a' - 'A'; - } - else - { - result[count] = ch; + if (!(*env)) + return -1; + + count = 0; + ch = *(*env); + + while (ch && (count < res_len - 1) && (ch != ';')) { + if ((ch >= 'A') && (ch <= 'Z')) + result[count] = ch + 'a' - 'A'; + else + result[count] = ch; + + ch = *(++(*env)); + ++count; } - ch = *(++(*env)); - ++count; - } - result[count] = 0; - if (!ch || (ch == ';')) /* full input was parsed */ - { - return 0; - } - else - { - return -1; - } + result[count] = 0; + + if (!ch || (ch == ';')) /* full input was parsed */ + return 0; + else + return -1; } -int dlt_env_extract_symbolic_ll(char ** const env, int8_t * ll) +int dlt_env_extract_symbolic_ll(char **const env, int8_t *ll) { - char result[strlen("verbose")+1]; - if (!env || !ll) - { - return -1; - } + char result[strlen("verbose") + 1]; - if (!(*env)) - { - return -1; - } + if (!env || !ll) + return -1; - if (dlt_env_helper_to_lower(env, &result[0], sizeof(result)) == 0) - { - if (strncmp("default", result, sizeof(result)) == 0) - { - *ll = -1; - } - else if (strncmp("off", result, sizeof(result)) == 0) - { - *ll = 0; - } - else if (strncmp("fatal", result, sizeof(result)) == 0) - { - *ll = 1; - } - else if (strncmp("error", result, sizeof(result)) == 0) - { - *ll = 2; - } - else if (strncmp("warning", result, sizeof(result)) == 0) - { - *ll = 3; - } - else if (strncmp("info", result, sizeof(result)) == 0) - { - *ll = 4; - } - else if (strncmp("debug", result, sizeof(result)) == 0) - { - *ll = 5; - } - else if (strncmp("verbose", result, sizeof(result)) == 0) - { - *ll = 6; - } - else - { - return -1; - } + if (!(*env)) + return -1; - if (**env != 0) - { - (*env)++; + if (dlt_env_helper_to_lower(env, &result[0], sizeof(result)) == 0) { + if (strncmp("default", result, sizeof(result)) == 0) + *ll = -1; + else if (strncmp("off", result, sizeof(result)) == 0) + *ll = 0; + else if (strncmp("fatal", result, sizeof(result)) == 0) + *ll = 1; + else if (strncmp("error", result, sizeof(result)) == 0) + *ll = 2; + else if (strncmp("warning", result, sizeof(result)) == 0) + *ll = 3; + else if (strncmp("info", result, sizeof(result)) == 0) + *ll = 4; + else if (strncmp("debug", result, sizeof(result)) == 0) + *ll = 5; + else if (strncmp("verbose", result, sizeof(result)) == 0) + *ll = 6; + else + return -1; + + if (**env != 0) + (*env)++; + + return 0; + } + else { + return -1; } - return 0; - } - else - { - return -1; - } - } @@ -225,51 +183,37 @@ int dlt_env_extract_symbolic_ll(char ** const env, int8_t * ll) * * @return 0 if successful, -1 else */ -int dlt_env_extract_ll(char ** const env, int8_t * ll) +int dlt_env_extract_ll(char **const env, int8_t *ll) { - if (!env || !ll) - { - return -1; - } + if (!env || !ll) + return -1; - if (!(*env)) - { - return -1; - } + if (!(*env)) + return -1; - /* extract number */ - if (**env == '-') - { - (*env)++; - if (**env == '1') - { - *ll = -1; - (*env)++; + /* extract number */ + if (**env == '-') { + (*env)++; + + if (**env == '1') { + *ll = -1; + (*env)++; + } } - } - else - { - if ((**env >= '0') && (**env < '7')) - { - *ll = **env - '0'; - (*env)++; + else { + if ((**env >= '0') && (**env < '7')) { + *ll = **env - '0'; + (*env)++; + } + else if (dlt_env_extract_symbolic_ll(env, ll) != 0) + return -1; } - else - { - if (dlt_env_extract_symbolic_ll(env, ll) != 0) - { - return -1; - } - } - } - /* check end, either next char is NULL or ';' */ - if ((**env == ';') || (**env == 0)) - { - return 0; - } + /* check end, either next char is NULL or ';' */ + if ((**env == ';') || (**env == 0)) + return 0; - return -1; + return -1; } @@ -278,41 +222,35 @@ int dlt_env_extract_ll(char ** const env, int8_t * ll) * * @return 0 if successful, -1 else */ -int dlt_env_extract_ll_item(char ** const env, dlt_env_ll_item * const item) +int dlt_env_extract_ll_item(char **const env, dlt_env_ll_item *const item) { - int ret = -1; - if (!env || !item) - { - return -1; - } + int ret = -1; - if (!(*env)) - { - return -1; - } + if (!env || !item) + return -1; - memset(item, 0, sizeof(dlt_env_ll_item)); - ret = dlt_env_extract_id(env, item->appId); - if (ret == -1) - { - return -1; - } + if (!(*env)) + return -1; - (*env)++; - ret = dlt_env_extract_id(env, item->ctxId); - if (ret == -1) - { - return -1; - } + memset(item, 0, sizeof(dlt_env_ll_item)); + ret = dlt_env_extract_id(env, item->appId); - (*env)++; - ret = dlt_env_extract_ll(env, &item->ll); - if (ret == -1) - { - return -1; - } + if (ret == -1) + return -1; + + (*env)++; + ret = dlt_env_extract_id(env, item->ctxId); + + if (ret == -1) + return -1; + + (*env)++; + ret = dlt_env_extract_ll(env, &item->ll); - return 0; + if (ret == -1) + return -1; + + return 0; } @@ -324,43 +262,40 @@ int dlt_env_extract_ll_item(char ** const env, dlt_env_ll_item * const item) * @return -1 if memory could not be allocated * @return 0 on success */ -int dlt_env_init_ll_set(dlt_env_ll_set * const ll_set) +int dlt_env_init_ll_set(dlt_env_ll_set *const ll_set) { - if (!ll_set) - { - return -1; - } - - ll_set->array_size = DLT_ENV_LL_SET_INCREASE; - ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); - if (!ll_set->item) - { - /* should trigger a warning: no memory left */ - ll_set->array_size = 0; - return -1; - } - ll_set->num_elem = 0u; - return 0; + if (!ll_set) + return -1; + + ll_set->array_size = DLT_ENV_LL_SET_INCREASE; + ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); + + if (!ll_set->item) { + /* should trigger a warning: no memory left */ + ll_set->array_size = 0; + return -1; + } + + ll_set->num_elem = 0u; + return 0; } /** * @brief release ll_set */ -void dlt_env_free_ll_set(dlt_env_ll_set * const ll_set) +void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set) { - if (!ll_set) - { - return; - } - - if (ll_set->item != NULL) - { - free(ll_set->item); - ll_set->item = NULL; - } - ll_set->array_size = 0u; - ll_set->num_elem = 0u; + if (!ll_set) + return; + + if (ll_set->item != NULL) { + free(ll_set->item); + ll_set->item = NULL; + } + + ll_set->array_size = 0u; + ll_set->num_elem = 0u; } @@ -370,33 +305,30 @@ void dlt_env_free_ll_set(dlt_env_ll_set * const ll_set) * @return -1 if memory could not be allocated * @return 0 on success */ -int dlt_env_increase_ll_set(dlt_env_ll_set * const ll_set) +int dlt_env_increase_ll_set(dlt_env_ll_set *const ll_set) { - dlt_env_ll_item * old_set; - size_t old_size; + dlt_env_ll_item *old_set; + size_t old_size; - if (!ll_set) - { - return -1; - } + if (!ll_set) + return -1; - old_set = ll_set->item; - old_size = ll_set->array_size; + old_set = ll_set->item; + old_size = ll_set->array_size; - ll_set->array_size += DLT_ENV_LL_SET_INCREASE; - ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); - if (!ll_set->item) - { - /* should trigger a warning: no memory left */ - ll_set->array_size -= DLT_ENV_LL_SET_INCREASE; - return -1; - } - else - { - memcpy(ll_set->item, old_set, sizeof(dlt_env_ll_item)*old_size); - free(old_set); - return 0; - } + ll_set->array_size += DLT_ENV_LL_SET_INCREASE; + ll_set->item = (dlt_env_ll_item *)malloc(sizeof(dlt_env_ll_item) * ll_set->array_size); + + if (!ll_set->item) { + /* should trigger a warning: no memory left */ + ll_set->array_size -= DLT_ENV_LL_SET_INCREASE; + return -1; + } + else { + memcpy(ll_set->item, old_set, sizeof(dlt_env_ll_item) * old_size); + free(old_set); + return 0; + } } @@ -408,44 +340,31 @@ int dlt_env_increase_ll_set(dlt_env_ll_set * const ll_set) * * @return 0 if successful, -1 else */ -int dlt_env_extract_ll_set(char ** const env, dlt_env_ll_set * const ll_set) +int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set) { - if (!env || !ll_set) - { - return -1; - } + if (!env || !ll_set) + return -1; - if (!(*env)) - { - return -1; - } + if (!(*env)) + return -1; - if (dlt_env_init_ll_set(ll_set) == -1) - { - return -1; - } - - do - { - if (ll_set->num_elem == ll_set->array_size) - { - if (dlt_env_increase_ll_set(ll_set) == -1) - { + if (dlt_env_init_ll_set(ll_set) == -1) return -1; - } - } - if (dlt_env_extract_ll_item(env, &ll_set->item[ll_set->num_elem++]) == -1) - { - return -1; - } - if (**env == ';') - { - (*env)++; - } - } while (**env != 0); + do { + if (ll_set->num_elem == ll_set->array_size) { + if (dlt_env_increase_ll_set(ll_set) == -1) + return -1; + } + + if (dlt_env_extract_ll_item(env, &ll_set->item[ll_set->num_elem++]) == -1) + return -1; + + if (**env == ';') + (*env)++; + } while (**env != 0); - return 0; + return 0; } @@ -454,26 +373,21 @@ int dlt_env_extract_ll_set(char ** const env, dlt_env_ll_set * const ll_set) * * @return 1 if matching, 0 if not */ -int dlt_env_ids_match(char const * const a, char const * const b) +int dlt_env_ids_match(char const *const a, char const *const b) { - if (a[0] != b[0]) - { - return 0; - } - if (a[1] != b[1]) - { - return 0; - } - if (a[2] != b[2]) - { - return 0; - } - if (a[3] != b[3]) - { - return 0; - } + if (a[0] != b[0]) + return 0; + + if (a[1] != b[1]) + return 0; + + if (a[2] != b[2]) + return 0; - return 1; + if (a[3] != b[3]) + return 0; + + return 1; } @@ -488,43 +402,26 @@ int dlt_env_ids_match(char const * const a, char const * const b) * * In case of error, -1 is returned. */ -int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const * const item, char const * const apid, char const * const ctid) +int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const *const item, char const *const apid, char const *const ctid) { - if ((!item) || (!apid) || (!ctid)) - { - return -1; - } + if ((!item) || (!apid) || (!ctid)) + return -1; - if (item->appId[0] == 0) - { - if (item->ctxId[0] == 0) - { - return 1; + if (item->appId[0] == 0) { + if (item->ctxId[0] == 0) { + return 1; + } + else if (dlt_env_ids_match(item->ctxId, ctid)) + return 2; } - else - { - if (dlt_env_ids_match(item->ctxId, ctid)) - { - return 2; - } - } - } - else - { - if (dlt_env_ids_match(item->appId, apid)) - { - if (item->ctxId[0] == 0) - { - return 3; - } - else if (dlt_env_ids_match(item->ctxId, ctid)) - { - return 4; - } + else if (dlt_env_ids_match(item->appId, apid)) { + if (item->ctxId[0] == 0) + return 3; + else if (dlt_env_ids_match(item->ctxId, ctid)) + return 4; } - } - return 0; + return 0; } @@ -537,31 +434,31 @@ int dlt_env_ll_item_get_matching_prio(dlt_env_ll_item const * const item, char c * * If no item matches or in case of error, the original log-level (\param ll) is returned */ -int dlt_env_adjust_ll_from_env(dlt_env_ll_set const * const ll_set, char const * const apid, char const * const ctid, int const ll) +int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, + char const *const apid, + char const *const ctid, + int const ll) { - if ((!ll_set) || (!apid) || (!ctid)) - { - return ll; - } - - int res = ll; - int prio = 0; /* no match so far */ - size_t i; - for (i = 0; i<ll_set->num_elem; ++i) - { - int p = dlt_env_ll_item_get_matching_prio(&ll_set->item[i], apid, ctid); - if (p > prio) - { - prio = p; - res = ll_set->item[i].ll; - if (p == 4) /* maximum reached, immediate return */ - { - return res; - } + if ((!ll_set) || (!apid) || (!ctid)) + return ll; + + int res = ll; + int prio = 0; /* no match so far */ + size_t i; + + for (i = 0; i < ll_set->num_elem; ++i) { + int p = dlt_env_ll_item_get_matching_prio(&ll_set->item[i], apid, ctid); + + if (p > prio) { + prio = p; + res = ll_set->item[i].ll; + + if (p == 4) /* maximum reached, immediate return */ + return res; + } } - } - return res; + return res; } diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 1038e0a..7844de2 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -59,34 +59,35 @@ #include "dlt_filetransfer.h" #include "dlt_common.h" -//!Defines the buffer size of a single file package which will be logged to dlt +/*!Defines the buffer size of a single file package which will be logged to dlt */ #define BUFFER_SIZE 1024 -//!Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many logs in a short period of time. +/*!Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many logs in a short period of time. */ #define MIN_TIMEOUT 20 #define DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES INT_MAX -//!Buffer for dlt file transfer. The size is defined by BUFFER_SIZE +/*!Buffer for dlt file transfer. The size is defined by BUFFER_SIZE */ unsigned char buffer[BUFFER_SIZE]; -//!Get some information about the file size of a file +/*!Get some information about the file size of a file */ /**See stat(2) for more informations. * @param file Absolute file path * @return Returns the size of the file (if it is a regular file or a symbolic link) in bytes. */ -uint32_t getFilesize(const char* file, int *ok){ +uint32_t getFilesize(const char *file, int *ok) +{ struct stat st; - if ( -1 == stat(file, &st)) - { - //we can only return 0, as the value is unsigned + if (-1 == stat(file, &st)) { + /*we can only return 0, as the value is unsigned */ *ok = 0; return 0; } + *ok = 1; return (uint32_t)st.st_size; } @@ -96,95 +97,98 @@ uint32_t getFilesize(const char* file, int *ok){ * @param hash start and result value for hash computation * */ -void stringHash(const char* str, uint32_t *hash ) +void stringHash(const char *str, uint32_t *hash) { if (!str || !hash) return; - unsigned int len = strlen(str); - unsigned int i = 0; - if (len <= 0){ - return; - } + unsigned int len = strlen(str); - for(i = 0; i < len; i++) - { - *hash = 53 * *hash + str[i]; - } + unsigned int i = 0; + + if (len <= 0) + return; + for (i = 0; i < len; i++) + *hash = 53 * *hash + str[i]; } -//!Get some information about the file serial number of a file +/*!Get some information about the file serial number of a file */ /** See stat(2) for more informations. * @param file Absolute file path * @param value *ok == 0 -> error; *ok == 1 -> ok * @return Returns a unique number associated with each filename */ -uint32_t getFileSerialNumber(const char* file, int *ok){ +uint32_t getFileSerialNumber(const char *file, int *ok) +{ struct stat st; uint32_t ret; - if ( -1 == stat(file, &st)) - { + + if (-1 == stat(file, &st)) { *ok = 0; ret = 0; } - else - { + else { *ok = 1; ret = st.st_ino; - ret = ret << (sizeof(ret)*8)/2; + ret = ret << (sizeof(ret) * 8) / 2; ret |= st.st_size; ret ^= st.st_ctime; stringHash(file, &ret); } + return ret; } -//!Returns the creation date of a file +/*!Returns the creation date of a file */ /** See stat(2) for more informations. * @param file Absolute file path * @return Returns the creation date of a file -*/ -time_t getFileCreationDate(const char* file,int *ok){ + */ +time_t getFileCreationDate(const char *file, int *ok) +{ struct stat st; - if (-1 == stat(file, &st)) - { + + if (-1 == stat(file, &st)) { *ok = 0; return 0; } + *ok = 1; return st.st_ctime; } -//!Returns the creation date of a file +/*!Returns the creation date of a file */ /** Format of the creation date is Day Mon dd hh:mm:ss yyyy * @param file Absolute file path * @return Returns the creation date of a file -*/ -char* getFileCreationDate2(const char* file,int *ok){ + */ +char *getFileCreationDate2(const char *file, int *ok) +{ struct stat st; - if (-1 == stat(file, &st)) - { + + if (-1 == stat(file, &st)) { *ok = 0; return 0; } + *ok = 1; - struct tm *ts= localtime(&st.st_ctime); + struct tm *ts = localtime(&st.st_ctime); return asctime(ts); } -//!Checks if the file exists +/*!Checks if the file exists */ /**@param file Absolute file path * @return Returns 1 if the file exists, 0 if the file does not exist */ -int isFile (const char* file) +int isFile (const char *file) { - struct stat st; - return (stat (file, &st) == 0); + struct stat st; + return stat (file, &st) == 0; } -//!Waits a period of time +/*!Waits a period of time */ /**Waits a period of time. The minimal time to wait is MIN_TIMEOUT. This makes sure that the FIFO of dlt is not flooded. * @param timeout Timeout to in ms but can not be smaller as MIN_TIMEOUT */ @@ -193,7 +197,7 @@ void doTimeout(int timeout) usleep(timeout * 1000); } -//!Checks free space of the user buffer +/*!Checks free space of the user buffer */ /** * @param returns -1 if more than 50% space in the user buffer is free. Otherwise 1 will be returned. */ @@ -203,106 +207,132 @@ int checkUserBufferForFreeSpace() dlt_user_check_buffer(&total_size, &used_size); - if((total_size - used_size) < (total_size/2)) - { + if ((total_size - used_size) < (total_size / 2)) return -1; - } + return 1; } -//!Deletes the given file +/*!Deletes the given file */ /** * @param filename Absolute file path * @return If the file is successfully deleted, a zero value is returned.If the file can not be deleted a nonzero value is returned. */ -int doRemoveFile(const char*filename){ - return remove( filename); +int doRemoveFile(const char *filename) +{ + return remove(filename); } -void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filename, int errorCode){ +void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filename, int errorCode) +{ - if(errno != ENOENT) - { + if (errno != ENOENT) { int ok = 0; - uint32_t fserial = getFileSerialNumber(filename,&ok); + uint32_t fserial = getFileSerialNumber(filename, &ok); + if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "),DLT_STRING(filename)); - uint32_t fsize = getFilesize(filename,&ok); + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "), + DLT_STRING(filename)); + + uint32_t fsize = getFilesize(filename, &ok); + if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "),DLT_STRING(filename)); - char *fcreationdate = getFileCreationDate2(filename,&ok); + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), + DLT_STRING(filename)); + + char *fcreationdate = getFileCreationDate2(filename, &ok); + if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "),DLT_STRING(filename)); - - int package_count = dlt_user_log_file_packagesCount(fileContext,filename); - - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(errorCode), - DLT_INT(-errno), - DLT_UINT(fserial), - DLT_STRING(filename), - DLT_UINT(fsize), - DLT_STRING(fcreationdate), - DLT_INT(package_count), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLER") - ); - } else { - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("FLER"), - DLT_INT(errorCode), - DLT_INT(-errno), - DLT_STRING(filename), - DLT_STRING("FLER") - ); + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), + DLT_STRING(filename)); + + int package_count = dlt_user_log_file_packagesCount(fileContext, filename); + + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("FLER"), + DLT_INT(errorCode), + DLT_INT(-errno), + DLT_UINT(fserial), + DLT_STRING(filename), + DLT_UINT(fsize), + DLT_STRING(fcreationdate), + DLT_INT(package_count), + DLT_UINT(BUFFER_SIZE), + DLT_STRING("FLER") + ); + } + else { + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("FLER"), + DLT_INT(errorCode), + DLT_INT(-errno), + DLT_STRING(filename), + DLT_STRING("FLER") + ); } } -//!Logs specific file inforamtions to dlt +/*!Logs specific file inforamtions to dlt */ /**The filename, file size, file serial number and the number of packages will be logged to dlt. * @param fileContext Specific context * @param filename Absolute file path * @return Returns 0 if everything was okey.If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename){ +int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) +{ - if(isFile(filename)) - { + if (isFile(filename)) { int ok; - uint32_t fsize = getFilesize(filename,&ok); + uint32_t fsize = getFilesize(filename, &ok); + if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"),DLT_STRING(filename)); + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"), + DLT_STRING(filename)); + + uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - uint32_t fserialnumber = getFileSerialNumber(filename,&ok); if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"),DLT_STRING(filename)); + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"), + DLT_STRING(filename)); + char *creationdate = getFileCreationDate2(filename, &ok); - char *creationdate = getFileCreationDate2(filename,&ok); if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"),DLT_STRING(filename)); - - DLT_LOG(*fileContext,DLT_LOG_INFO, - DLT_STRING("FLIF"), - DLT_STRING("file serialnumber"),DLT_UINT(fserialnumber), - DLT_STRING("filename"),DLT_STRING(filename), - DLT_STRING("file size in bytes"),DLT_UINT(fsize), - DLT_STRING("file creation date"),DLT_STRING(creationdate), - DLT_STRING("number of packages"),DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), - DLT_STRING("FLIF") - ); + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"), + DLT_STRING(filename)); + + DLT_LOG(*fileContext, DLT_LOG_INFO, + DLT_STRING("FLIF"), + DLT_STRING("file serialnumber"), DLT_UINT(fserialnumber), + DLT_STRING("filename"), DLT_STRING(filename), + DLT_STRING("file size in bytes"), DLT_UINT(fsize), + DLT_STRING("file creation date"), DLT_STRING(creationdate), + DLT_STRING("number of packages"), DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), + DLT_STRING("FLIF") + ); return 0; - } else { - dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_INFO_ABOUT); + } + else { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_INFO_ABOUT); return DLT_FILETRANSFER_ERROR_INFO_ABOUT; } } -//!Transfer the complete file as several dlt logs. +/*!Transfer the complete file as several dlt logs. */ /**This method transfer the complete file as several dlt logs. At first it will be checked that the file exist. * In the next step some generic informations about the file will be logged to dlt. * Now the header will be logged to dlt. See the method dlt_user_log_file_header for more informations. @@ -316,31 +346,24 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename){ */ int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, int timeout) { - if(!isFile(filename)) - { - dlt_user_log_file_errorMessage(fileContext,filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); + if (!isFile(filename)) { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); return DLT_FILETRANSFER_ERROR_FILE_COMPLETE; } - if(dlt_user_log_file_header(fileContext,filename) != 0) - { + if (dlt_user_log_file_header(fileContext, filename) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE1; - } - if(dlt_user_log_file_data(fileContext, filename,DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES,timeout) != 0) - { + if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, timeout) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE2; - } - if(dlt_user_log_file_end(fileContext,filename, deleteFlag) != 0) - { + if (dlt_user_log_file_end(fileContext, filename, deleteFlag) != 0) return DLT_FILETRANSFER_ERROR_FILE_COMPLETE3; - } return 0; } -//!This method gives information about the number of packages the file have +/*!This method gives information about the number of packages the file have */ /**Every file will be divided into several packages. Every package will be logged as a single dlt log. * The number of packages depends on the BUFFER_SIZE. * At first it will be checked if the file exist. Then the file will be divided into @@ -349,43 +372,48 @@ int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, in * @param filename Absolute file path * @return Returns the number of packages if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filename){ +int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filename) +{ int packages; uint32_t filesize; - if(isFile(filename)) - { + if (isFile(filename)) { packages = 1; int ok; - filesize = getFilesize(filename,&ok); - if (!ok){ - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("Error in: dlt_user_log_file_packagesCount, isFile"),DLT_STRING(filename),DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); + filesize = getFilesize(filename, &ok); + + if (!ok) { + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("Error in: dlt_user_log_file_packagesCount, isFile"), + DLT_STRING(filename), + DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); return -1; } - if(filesize < BUFFER_SIZE) - { + + if (filesize < BUFFER_SIZE) { return packages; } - else - { - packages = filesize/BUFFER_SIZE; + else { + packages = filesize / BUFFER_SIZE; - if(filesize%BUFFER_SIZE == 0) - { + if (filesize % BUFFER_SIZE == 0) return packages; - } else - { - return packages+1; - } + return packages + 1; } - } else { - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"),DLT_STRING(filename),DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); + } + else { + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"), + DLT_STRING(filename), + DLT_INT(DLT_FILETRANSFER_ERROR_PACKAGE_COUNT)); return -1; } } -//!Transfer the head of the file as a dlt logs. +/*!Transfer the head of the file as a dlt logs. */ /**The head of the file must be logged to dlt because the head contains inforamtion about the file serial number, * the file name, the file size, package number the file have and the buffer size. * All these informations are needed from the plugin of the dlt viewer. @@ -395,47 +423,52 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam * @param alias Alias for the file. An alternative name to show in the receiving end * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_header_alias(DltContext *fileContext,const char *filename, const char *alias){ +int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename, const char *alias) +{ - if(isFile(filename)) - { + if (isFile(filename)) { int ok; - uint32_t fserialnumber = getFileSerialNumber(filename,&ok); - if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header_alias, Error getting serial number of file:"),DLT_STRING(filename)); + uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - uint32_t fsize = getFilesize(filename,&ok); if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header_alias, Error getting size of file:"),DLT_STRING(filename)); + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header_alias, Error getting serial number of file:"), + DLT_STRING(filename)); + + uint32_t fsize = getFilesize(filename, &ok); - char *fcreationdate = getFileCreationDate2(filename,&ok); if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header_alias, Error getting creation date of file:"),DLT_STRING(filename)); + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header_alias, Error getting size of file:"), DLT_STRING(filename)); + char *fcreationdate = getFileCreationDate2(filename, &ok); + if (!ok) + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header_alias, Error getting creation date of file:"), + DLT_STRING(filename)); - DLT_LOG(*fileContext,DLT_LOG_INFO, + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), DLT_UINT(fserialnumber), DLT_STRING(alias), DLT_UINT(fsize), DLT_STRING(fcreationdate); - DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), + DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), DLT_UINT(BUFFER_SIZE), DLT_STRING("FLST") ); return 0; } - else - { - dlt_user_log_file_errorMessage(fileContext,filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); + else { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } } -//!Transfer the head of the file as a dlt logs. +/*!Transfer the head of the file as a dlt logs. */ /**The head of the file must be logged to dlt because the head contains inforamtion about the file serial number, * the file name, the file size, package number the file have and the buffer size. * All these informations are needed from the plugin of the dlt viewer. @@ -444,48 +477,52 @@ int dlt_user_log_file_header_alias(DltContext *fileContext,const char *filename, * @param filename Absolute file path * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_header(DltContext *fileContext,const char *filename){ +int dlt_user_log_file_header(DltContext *fileContext, const char *filename) +{ - if(isFile(filename)) - { + if (isFile(filename)) { int ok; - uint32_t fserialnumber = getFileSerialNumber(filename,&ok); - if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header, Error getting serial number of file:"),DLT_STRING(filename)); + uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - uint32_t fsize = getFilesize(filename,&ok); if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header, Error getting size of file:"),DLT_STRING(filename)); + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header, Error getting serial number of file:"), DLT_STRING(filename)); - char *fcreationdate = getFileCreationDate2(filename,&ok); - if (!ok) - DLT_LOG(*fileContext,DLT_LOG_ERROR,DLT_STRING("dlt_user_log_file_header, Error getting creation date of file:"),DLT_STRING(filename)); + uint32_t fsize = getFilesize(filename, &ok); + if (!ok) + DLT_LOG(*fileContext, + DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header, Error getting size of file:"), + DLT_STRING(filename)); + char *fcreationdate = getFileCreationDate2(filename, &ok); + if (!ok) + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("dlt_user_log_file_header, Error getting creation date of file:"), DLT_STRING(filename)); - DLT_LOG(*fileContext,DLT_LOG_INFO, - DLT_STRING("FLST"), - DLT_UINT(fserialnumber), - DLT_STRING(filename), - DLT_UINT(fsize), - DLT_STRING(fcreationdate); - DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLST") + DLT_LOG(*fileContext, DLT_LOG_INFO, + DLT_STRING("FLST"), + DLT_UINT(fserialnumber), + DLT_STRING(filename), + DLT_UINT(fsize), + DLT_STRING(fcreationdate); + DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), + DLT_UINT(BUFFER_SIZE), + DLT_STRING("FLST") ); return 0; } - else - { - dlt_user_log_file_errorMessage(fileContext,filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); + else { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } } -//!Transfer the content data of a file. +/*!Transfer the content data of a file. */ /**See the Mainpages.c for more informations. * @param fileContext Specific context to log the file to dlt * @param filename Absolute file path @@ -493,108 +530,105 @@ int dlt_user_log_file_header(DltContext *fileContext,const char *filename){ * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int packageToTransfer, int timeout){ +int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, int timeout) +{ FILE *file; int pkgNumber; uint32_t readBytes; - if(isFile(filename)) - { + if (isFile(filename)) { + + file = fopen (filename, "rb"); - file = fopen (filename,"rb"); - if (file == NULL) - { - dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_FILE_DATA); + if (file == NULL) { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_DATA); return DLT_FILETRANSFER_ERROR_FILE_DATA; } - if( (packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES && packageToTransfer > dlt_user_log_file_packagesCount(fileContext,filename)) || packageToTransfer <= 0) - { - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), - DLT_STRING("packageToTransfer:"), - DLT_UINT(packageToTransfer), - DLT_STRING("numberOfMaximalPackages:"), - DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), - DLT_STRING("for File:"), - DLT_STRING(filename) - ); + if (((packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) && + (packageToTransfer > + dlt_user_log_file_packagesCount(fileContext, filename))) || (packageToTransfer <= 0)) { + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), + DLT_STRING("packageToTransfer:"), + DLT_UINT(packageToTransfer), + DLT_STRING("numberOfMaximalPackages:"), + DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), + DLT_STRING("for File:"), + DLT_STRING(filename) + ); fclose(file); return DLT_FILETRANSFER_ERROR_FILE_DATA; } readBytes = 0; - if(packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) - { -// If a single package should be transferred. The user has to check that the free space in the user buffer > 50% -// if(checkUserBufferForFreeSpace()<0) -// return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; + if (packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) { +/* If a single package should be transferred. The user has to check that the free space in the user buffer > 50% */ +/* if(checkUserBufferForFreeSpace()<0) */ +/* return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; */ - if ( 0 != fseek ( file , (packageToTransfer-1)*BUFFER_SIZE , SEEK_SET ) ) - { - DLT_LOG(*fileContext,DLT_LOG_ERROR, + if (0 != fseek (file, (packageToTransfer - 1) * BUFFER_SIZE, SEEK_SET)) { + DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to fseek in file: "), DLT_STRING(filename), DLT_STRING("ferror:"), DLT_INT(ferror(file)) - ); + ); - fclose (file); - return -1; + fclose (file); + return -1; - } - readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); - int ok; + } - uint32_t fserial = getFileSerialNumber(filename,&ok); + readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); + int ok; - if (1 != ok) - { - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); - } + uint32_t fserial = getFileSerialNumber(filename, &ok); - DLT_LOG(*fileContext,DLT_LOG_INFO, - DLT_STRING("FLDA"), - DLT_UINT(fserial), - DLT_UINT(packageToTransfer), - DLT_RAW(buffer,readBytes), - DLT_STRING("FLDA") - ); + if (1 != ok) + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("failed to get FileSerialNumber for: "), + DLT_STRING(filename)); - doTimeout(timeout); + DLT_LOG(*fileContext, DLT_LOG_INFO, + DLT_STRING("FLDA"), + DLT_UINT(fserial), + DLT_UINT(packageToTransfer), + DLT_RAW(buffer, readBytes), + DLT_STRING("FLDA") + ); + + doTimeout(timeout); - } else { + } + else { pkgNumber = 0; - while( !feof( file ) ) - { -// If the complete file should be transferred, the user buffer will be checked. -// If free space < 50% the package won't be transferred. - if(checkUserBufferForFreeSpace()>0) - { + + while (!feof(file)) { +/* If the complete file should be transferred, the user buffer will be checked. */ +/* If free space < 50% the package won't be transferred. */ + if (checkUserBufferForFreeSpace() > 0) { pkgNumber++; readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); int ok; - uint32_t fserial = getFileSerialNumber(filename,&ok); + uint32_t fserial = getFileSerialNumber(filename, &ok); if (1 != ok) - { - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); - } + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("failed to get FileSerialNumber for: "), + DLT_STRING(filename)); - DLT_LOG(*fileContext,DLT_LOG_INFO, + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), DLT_UINT(fserial), DLT_UINT(pkgNumber), - DLT_RAW(buffer,readBytes), + DLT_RAW(buffer, readBytes), DLT_STRING("FLDA") - ); + ); } + doTimeout(timeout); } } @@ -603,13 +637,13 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac return 0; - } else { - dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_FILE_DATA); + } + else { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_DATA); return DLT_FILETRANSFER_ERROR_FILE_DATA; } - } -//!Transfer the end of the file as a dlt logs. +/*!Transfer the end of the file as a dlt logs. */ /**The end of the file must be logged to dlt because the end contains inforamtion about the file serial number. * This informations is needed from the plugin of the dlt viewer. * See the Mainpages.c for more informations. @@ -618,37 +652,36 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac * @param deleteFlag Flag to delete the file after the whole file is transferred (logged to dlt).1->delete,0->NotDelete * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_end(DltContext *fileContext,const char *filename,int deleteFlag){ +int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int deleteFlag) +{ - if(isFile(filename)) - { + if (isFile(filename)) { int ok; - uint32_t fserial = getFileSerialNumber(filename,&ok); + uint32_t fserial = getFileSerialNumber(filename, &ok); if (1 != ok) - { - DLT_LOG(*fileContext,DLT_LOG_ERROR, - DLT_STRING("failed to get FileSerialNumber for: "), - DLT_STRING(filename)); - } + DLT_LOG(*fileContext, DLT_LOG_ERROR, + DLT_STRING("failed to get FileSerialNumber for: "), + DLT_STRING(filename)); - DLT_LOG(*fileContext,DLT_LOG_INFO, + DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLFI"), DLT_UINT(fserial), DLT_STRING("FLFI") - ); + ); - if(deleteFlag){ - if( doRemoveFile(filename) != 0 ){ - dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_FILE_END); - return -1; - } + if (deleteFlag) { + if (doRemoveFile(filename) != 0) { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); + return -1; + } } return 0; - }else{ - dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_FILE_END); + } + else { + dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); return DLT_FILETRANSFER_ERROR_FILE_END; } } diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 418e1cf..d45bb91 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -32,9 +32,9 @@ #include <signal.h> /* for signal(), SIGPIPE, SIG_IGN */ #if !defined (__WIN32__) -#include <syslog.h> /* for LOG_... */ -#include <semaphore.h> -#include <pthread.h> /* POSIX Threads */ +# include <syslog.h> /* for LOG_... */ +# include <semaphore.h> +# include <pthread.h> /* POSIX Threads */ #endif #include <sys/time.h> @@ -48,7 +48,7 @@ #include <limits.h> #ifdef linux -#include <sys/prctl.h> +# include <sys/prctl.h> #endif #include <sys/types.h> /* needed for getpid() */ @@ -56,8 +56,8 @@ #include <stdbool.h> #ifdef DLT_USE_UNIX_SOCKET_IPC -#include <sys/un.h> -#include <sys/socket.h> +# include <sys/un.h> +# include <sys/socket.h> #endif #include "dlt_user.h" @@ -67,15 +67,15 @@ #include "dlt_user_cfg.h" #ifdef DLT_FATAL_LOG_RESET_ENABLE -#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) \ +# define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) \ do { \ if (LOGLEVEL == DLT_LOG_FATAL) { \ int *p = NULL; \ *p = 0; \ } \ - } while(0) + } while (0) #else /* DLT_FATAL_LOG_RESET_ENABLE */ -#define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) +# define DLT_LOG_FATAL_RESET_TRAP(LOGLEVEL) #endif /* DLT_FATAL_LOG_RESET_ENABLE */ static DltUser dlt_user; @@ -92,11 +92,11 @@ static char str[DLT_USER_BUFFER_LENGTH]; static sem_t dlt_mutex; static pthread_t dlt_receiverthread_handle; -// calling dlt_user_atexit_handler() second time fails with error message -static int atexit_registered = 0; +/* calling dlt_user_atexit_handler() second time fails with error message */ +static int atexit_registered = 0; -// calling atfork_handler() only once -static int atfork_registered = 0; +/* calling atfork_handler() only once */ +static int atfork_registered = 0; /* Segmented Network Trace */ @@ -106,19 +106,23 @@ static int atfork_registered = 0; /* Mutex to wait on while message queue is not initialized */ pthread_mutex_t mq_mutex; -pthread_cond_t mq_init_condition; +pthread_cond_t mq_init_condition; void dlt_lock_mutex(pthread_mutex_t *mutex) { int32_t lock_mutex_result = pthread_mutex_lock(mutex); - if (lock_mutex_result == EOWNERDEAD) - { + + if (lock_mutex_result == EOWNERDEAD) { pthread_mutex_consistent(mutex); lock_mutex_result = 0; } - else if ( lock_mutex_result != 0 ) + else if (lock_mutex_result != 0) { - snprintf(str,DLT_USER_BUFFER_LENGTH, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result); + snprintf(str, + DLT_USER_BUFFER_LENGTH, + "Mutex lock failed unexpected pid=%i with result %i!\n", + getpid(), + lock_mutex_result); dlt_log(LOG_ERR, str); } } @@ -131,13 +135,13 @@ void dlt_unlock_mutex(pthread_mutex_t *mutex) /* Structure to pass data to segmented thread */ typedef struct { - DltContext *handle; - uint32_t id; - DltNetworkTraceType nw_trace_type; - uint32_t header_len; - void *header; - uint32_t payload_len; - void *payload; + DltContext *handle; + uint32_t id; + DltNetworkTraceType nw_trace_type; + uint32_t header_len; + void *header; + uint32_t payload_len; + void *payload; } s_segmented_data; /* Function prototypes for internally used functions */ @@ -149,7 +153,9 @@ static DltReturnValue dlt_user_log_send_register_application(void); static DltReturnValue dlt_user_log_send_unregister_application(void); static DltReturnValue dlt_user_log_send_register_context(DltContextData *log); static DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log); -static DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType loglevel, DltTraceStatusType tracestatus); +static DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, + DltLogLevelType loglevel, + DltTraceStatusType tracestatus); static DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode); static DltReturnValue dlt_user_log_send_marker(); static DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log); @@ -159,7 +165,12 @@ static DltReturnValue dlt_user_log_send_overflow(void); static void dlt_user_trace_network_segmented_thread(void *unused); static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data); static DltReturnValue dlt_user_queue_resend(void); -static DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void* ptr2, size_t len2, void *ptr3, size_t len3); +static DltReturnValue dlt_user_log_out_error_handling(void *ptr1, + size_t len1, + void *ptr2, + size_t len2, + void *ptr3, + size_t len3); static int dlt_start_threads(); static void dlt_stop_threads(); @@ -168,22 +179,22 @@ static void dlt_fork_parent_fork_handler(); static void dlt_fork_child_fork_handler(); -DltReturnValue dlt_user_check_library_version(const char *user_major_version,const char *user_minor_version) +DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version) { - char lib_major_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; - char lib_minor_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; + char lib_major_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; + char lib_minor_version[DLT_USER_MAX_LIB_VERSION_LENGTH]; - dlt_get_major_version( lib_major_version,DLT_USER_MAX_LIB_VERSION_LENGTH); - dlt_get_minor_version( lib_minor_version,DLT_USER_MAX_LIB_VERSION_LENGTH); + dlt_get_major_version(lib_major_version, DLT_USER_MAX_LIB_VERSION_LENGTH); + dlt_get_minor_version(lib_minor_version, DLT_USER_MAX_LIB_VERSION_LENGTH); - if( (strcmp(lib_major_version,user_major_version) != 0) || (strcmp(lib_minor_version,user_minor_version) != 0)) - { - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, - "DLT Library version check failed! Installed DLT library version is %s.%s - Application using DLT library version %s.%s\n", - lib_major_version, - lib_minor_version, - user_major_version, - user_minor_version); + if ((strcmp(lib_major_version, user_major_version) != 0) || (strcmp(lib_minor_version, user_minor_version) != 0)) { + dlt_vnlog(LOG_WARNING, + DLT_USER_BUFFER_LENGTH, + "DLT Library version check failed! Installed DLT library version is %s.%s - Application using DLT library version %s.%s\n", + lib_major_version, + lib_minor_version, + user_major_version, + user_minor_version); return DLT_RETURN_ERROR; } @@ -202,19 +213,18 @@ static DltReturnValue dlt_initialize_socket_connection(void) DLT_SEM_LOCK(); int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd == DLT_FD_INIT) - { + if (sockfd == DLT_FD_INIT) { dlt_log(LOG_CRIT, "Failed to create socket\n"); - DLT_SEM_FREE(); + DLT_SEM_FREE(); return DLT_RETURN_ERROR; } status = fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); - if (status == -1) - { + + if (status == -1) { dlt_vlog(LOG_INFO, - "Socket %s/dlt cannot be changed to NON BLOCK\n", - DLT_USER_IPC_PATH); + "Socket %s/dlt cannot be changed to NON BLOCK\n", + DLT_USER_IPC_PATH); return DLT_RETURN_ERROR; } @@ -223,45 +233,38 @@ static DltReturnValue dlt_initialize_socket_connection(void) l_opt.l_linger = 10; if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &l_opt, sizeof l_opt) < 0) - { dlt_log(LOG_WARNING, "Failed to set linger option\n"); - } remote.sun_family = AF_UNIX; snprintf(dltSockBaseDir, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH); strncpy(remote.sun_path, dltSockBaseDir, sizeof(dltSockBaseDir)); if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX) - { dlt_vlog(LOG_INFO, "Provided path too long...trimming it to path[%s]\n", dltSockBaseDir); - } - if (connect(sockfd, (struct sockaddr*) &remote, sizeof(remote)) == -1) - { - if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) - { + if (connect(sockfd, (struct sockaddr *)&remote, sizeof(remote)) == -1) { + if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { dlt_vlog(LOG_INFO, "Socket %s cannot be opened. Retrying later...\n", dltSockBaseDir); dlt_user.connection_state = DLT_USER_RETRY_CONNECT; } } - else - { + else { dlt_user.dlt_log_handle = sockfd; dlt_user.connection_state = DLT_USER_CONNECTED; if (dlt_receiver_init(&(dlt_user.receiver), sockfd, - DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) - { + DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { dlt_user_initialised = false; DLT_SEM_FREE(); return DLT_RETURN_ERROR; } } + DLT_SEM_FREE(); return DLT_RETURN_OK; @@ -274,68 +277,69 @@ static DltReturnValue dlt_initialize_fifo_connection(void) snprintf(dlt_user_dir, NAME_MAX, "%s/dltpipes", dltFifoBaseDir); snprintf(dlt_daemon_fifo, NAME_MAX, "%s/dlt", dltFifoBaseDir); - ret=mkdir(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX ); - if (ret==-1 && errno != EEXIST) - { + ret = mkdir(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX); + + if ((ret == -1) && (errno != EEXIST)) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "FIFO user dir %s cannot be created!\n", dlt_user_dir); return DLT_RETURN_ERROR; } /* if dlt pipes directory is created by the application also chmod the directory */ - if(ret == 0) - { - // S_ISGID cannot be set by mkdir, let's reassign right bits - ret=chmod(dlt_user_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX ); - if (ret==-1) - { + if (ret == 0) { + /* S_ISGID cannot be set by mkdir, let's reassign right bits */ + ret = chmod(dlt_user_dir, + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | + S_ISVTX); + + if (ret == -1) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "FIFO user dir %s cannot be chmoded!\n", dlt_user_dir); return DLT_RETURN_ERROR; } } /* create and open DLT user FIFO */ - snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",dlt_user_dir,getpid()); + snprintf(filename, DLT_USER_MAX_FILENAME_LENGTH, "%s/dlt%d", dlt_user_dir, getpid()); /* Try to delete existing pipe, ignore result of unlink */ unlink(filename); - ret=mkfifo(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP ); - if (ret==-1) - { + ret = mkfifo(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP); + + if (ret == -1) dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Loging disabled, FIFO user %s cannot be created!\n", filename); /* return DLT_RETURN_OK; */ /* removed to prevent error, when FIFO already exists */ - } - // S_IWGRP cannot be set by mkfifo (???), let's reassign right bits - ret=chmod(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP ); - if (ret==-1) - { + /* S_IWGRP cannot be set by mkfifo (???), let's reassign right bits */ + ret = chmod(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP); + + if (ret == -1) { dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "FIFO user %s cannot be chmoded!\n", dlt_user_dir); return DLT_RETURN_ERROR; } dlt_user.dlt_user_handle = open(filename, O_RDWR | O_CLOEXEC); - if (dlt_user.dlt_user_handle == DLT_FD_INIT) - { + + if (dlt_user.dlt_user_handle == DLT_FD_INIT) { dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Logging disabled, FIFO user %s cannot be opened!\n", filename); unlink(filename); return DLT_RETURN_OK; } /* open DLT output FIFO */ - dlt_user.dlt_log_handle = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK | O_CLOEXEC ); - if (dlt_user.dlt_log_handle==-1) - { - - if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) - { + dlt_user.dlt_log_handle = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK | O_CLOEXEC); + + if (dlt_user.dlt_log_handle == -1) { + + if (dlt_user.connection_state != DLT_USER_RETRY_CONNECT) { /* This is a normal usecase. It is OK that the daemon (and thus the FIFO /tmp/dlt) - starts later and some DLT users have already been started before. - Thus it is OK if the FIFO can't be opened. */ - dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n",dlt_daemon_fifo); + * starts later and some DLT users have already been started before. + * Thus it is OK if the FIFO can't be opened. */ + dlt_vnlog(LOG_INFO, DLT_USER_BUFFER_LENGTH, "FIFO %s cannot be opened. Retrying later...\n", + dlt_daemon_fifo); dlt_user.connection_state = DLT_USER_RETRY_CONNECT; } - //return DLT_RETURN_OK; + + /*return DLT_RETURN_OK; */ } return DLT_RETURN_OK; @@ -344,23 +348,21 @@ static DltReturnValue dlt_initialize_fifo_connection(void) DltReturnValue dlt_init(void) { - // process is exiting. Do not allocate new resources. + /* process is exiting. Do not allocate new resources. */ if (dlt_user_freeing != 0) - { - // return negative value, to stop the current log + /* return negative value, to stop the current log */ return DLT_RETURN_ERROR; - } - // WARNING: multithread unsafe ! - // Another thread will check that dlt_user_initialised != 0, but the lib is not initialised ! + /* WARNING: multithread unsafe ! */ + /* Another thread will check that dlt_user_initialised != 0, but the lib is not initialised ! */ dlt_user_initialised = true; /* Initialize common part of dlt_init()/dlt_init_file() */ - if (dlt_init_common() == DLT_RETURN_ERROR) - { + if (dlt_init_common() == DLT_RETURN_ERROR) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } + strncpy(dltFifoBaseDir, DLT_USER_IPC_PATH, sizeof(DLT_USER_IPC_PATH)); /* check environment variables */ dlt_check_envvar(); @@ -369,33 +371,36 @@ DltReturnValue dlt_init(void) dlt_user.overflow = 0; dlt_user.overflow_counter = 0; #ifdef DLT_SHM_ENABLE - memset(&(dlt_user.dlt_shm),0,sizeof(DltShm)); + memset(&(dlt_user.dlt_shm), 0, sizeof(DltShm)); + /* init shared memory */ - if (dlt_shm_init_client(&(dlt_user.dlt_shm),DLT_SHM_KEY) < 0) - { - snprintf(str,DLT_USER_BUFFER_LENGTH,"Logging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY); + if (dlt_shm_init_client(&(dlt_user.dlt_shm), DLT_SHM_KEY) < 0) { + snprintf(str, DLT_USER_BUFFER_LENGTH, "Logging disabled, Shared memory %d cannot be created!\n", DLT_SHM_KEY); dlt_log(LOG_WARNING, str); - //return 0; + /*return 0; */ } + #elif defined DLT_USE_UNIX_SOCKET_IPC + if (dlt_initialize_socket_connection() != DLT_RETURN_OK) - { - // We could connect to the pipe, but not to the socket, which is normally - // open before by the DLT daemon => bad failure => return error code - // in case application is started before daemon, it is expected behaviour + /* We could connect to the pipe, but not to the socket, which is normally */ + /* open before by the DLT daemon => bad failure => return error code */ + /* in case application is started before daemon, it is expected behaviour */ return DLT_RETURN_ERROR; - } + #else /* FIFO connection */ + if (dlt_initialize_fifo_connection() != DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } + dlt_user.connection_state = DLT_USER_CONNECTED; - if (dlt_receiver_init(&(dlt_user.receiver),dlt_user.dlt_user_handle, DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) - { + + if (dlt_receiver_init(&(dlt_user.receiver), dlt_user.dlt_user_handle, + DLT_USER_RCVBUF_MAX_SIZE) == DLT_RETURN_ERROR) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } + #endif /* These will be lazy initialized only when needed */ @@ -404,14 +409,14 @@ DltReturnValue dlt_init(void) /* Wait mutext for segmented thread */ pthread_mutexattr_t attr; - if (pthread_mutexattr_init(&attr) != 0) - { + + if (pthread_mutexattr_init(&attr) != 0) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } + /* make mutex robust to prevent from deadlock when the segmented thread was cancelled, but held the mutex */ - if ( pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) != 0 ) - { + if (pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) != 0) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } @@ -420,17 +425,15 @@ DltReturnValue dlt_init(void) pthread_mutexattr_destroy(&attr); pthread_cond_init(&mq_init_condition, NULL); - if (dlt_start_threads() < 0) - { + if (dlt_start_threads() < 0) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } - // prepare for fork() call - if (atfork_registered == 0) - { - atfork_registered = 1; - pthread_atfork(&dlt_fork_pre_fork_handler, &dlt_fork_parent_fork_handler, &dlt_fork_child_fork_handler); + /* prepare for fork() call */ + if (atfork_registered == 0) { + atfork_registered = 1; + pthread_atfork(&dlt_fork_pre_fork_handler, &dlt_fork_parent_fork_handler, &dlt_fork_child_fork_handler); } return DLT_RETURN_OK; @@ -438,15 +441,14 @@ DltReturnValue dlt_init(void) DltReturnValue dlt_init_file(const char *name) { - // check null pointer - if(!name) + /* check null pointer */ + if (!name) return DLT_RETURN_WRONG_PARAMETER; dlt_user_initialised = true; /* Initialize common part of dlt_init()/dlt_init_file() */ - if (dlt_init_common() == DLT_RETURN_ERROR) - { + if (dlt_init_common() == DLT_RETURN_ERROR) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } @@ -454,9 +456,9 @@ DltReturnValue dlt_init_file(const char *name) dlt_user.dlt_is_file = 1; /* open DLT output file */ - dlt_user.dlt_log_handle = open(name,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ - if (dlt_user.dlt_log_handle == -1) - { + dlt_user.dlt_log_handle = open(name, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */ + + if (dlt_user.dlt_log_handle == -1) { dlt_vnlog(LOG_ERR, DLT_USER_BUFFER_LENGTH, "Log file %s cannot be opened!\n", name); return DLT_RETURN_ERROR; } @@ -466,62 +468,62 @@ DltReturnValue dlt_init_file(const char *name) DltReturnValue dlt_init_message_queue(void) { - dlt_lock_mutex(&mq_mutex); - if(dlt_user.dlt_segmented_queue_read_handle >= 0 && - dlt_user.dlt_segmented_queue_write_handle >= 0) - { - // Already intialized - dlt_unlock_mutex(&mq_mutex); - return DLT_RETURN_OK; - } + dlt_lock_mutex(&mq_mutex); + + if ((dlt_user.dlt_segmented_queue_read_handle >= 0) && + (dlt_user.dlt_segmented_queue_write_handle >= 0)) { + /* Already intialized */ + dlt_unlock_mutex(&mq_mutex); + return DLT_RETURN_OK; + } /* Generate per process name for queue */ char queue_name[NAME_MAX]; - snprintf(queue_name,NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); + snprintf(queue_name, NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); /* Maximum queue size is 10, limit to size of pointers */ struct mq_attr mqatr; - mqatr.mq_flags = 0; - mqatr.mq_maxmsg = 10; - mqatr.mq_msgsize = sizeof(s_segmented_data *); - mqatr.mq_curmsgs = 0; + mqatr.mq_flags = 0; + mqatr.mq_maxmsg = 10; + mqatr.mq_msgsize = sizeof(s_segmented_data *); + mqatr.mq_curmsgs = 0; /** * Create the message queue. It must be newly created * if old one was left by a crashing process. * */ - dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT| O_RDONLY | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, &mqatr); - if(dlt_user.dlt_segmented_queue_read_handle < 0) - { - if(errno == EEXIST) - { - dlt_log(LOG_WARNING, "Old message queue exists, trying to delete.\n"); - if(mq_unlink(queue_name) < 0) - { + dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT | O_RDONLY | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, + &mqatr); + + if (dlt_user.dlt_segmented_queue_read_handle < 0) { + if (errno == EEXIST) { + dlt_log(LOG_WARNING, "Old message queue exists, trying to delete.\n"); + + if (mq_unlink(queue_name) < 0) dlt_vnlog(LOG_CRIT, 256, "Could not delete existing message queue!: %s \n", strerror(errno)); - } - else // Retry - { - dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT| O_RDONLY | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, &mqatr); - } - } - if(dlt_user.dlt_segmented_queue_read_handle < 0) - { + else /* Retry */ + + dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, + O_CREAT | O_RDONLY | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, + &mqatr); + } + + if (dlt_user.dlt_segmented_queue_read_handle < 0) { dlt_vnlog(LOG_CRIT, 256, "Can't create message queue read handle!: %s \n", strerror(errno)); dlt_unlock_mutex(&mq_mutex); return DLT_RETURN_ERROR; - } + } } - dlt_user.dlt_segmented_queue_write_handle = mq_open(queue_name, O_WRONLY|O_NONBLOCK); - if(dlt_user.dlt_segmented_queue_write_handle < 0) - { + dlt_user.dlt_segmented_queue_write_handle = mq_open(queue_name, O_WRONLY | O_NONBLOCK); + + if (dlt_user.dlt_segmented_queue_write_handle < 0) { dlt_vnlog(LOG_CRIT, 256, "Can't open message queue write handle!: %s \n", strerror(errno)); - dlt_unlock_mutex(&mq_mutex); - return DLT_RETURN_ERROR; + dlt_unlock_mutex(&mq_mutex); + return DLT_RETURN_ERROR; } pthread_cond_signal(&mq_init_condition); @@ -532,7 +534,7 @@ DltReturnValue dlt_init_message_queue(void) DltReturnValue dlt_init_common(void) { char *env_local_print; - char * env_initial_log_level; + char *env_initial_log_level; char *env_buffer_min; uint32_t buffer_min = DLT_USER_RINGBUFFER_MIN_SIZE; char *env_buffer_max; @@ -543,8 +545,7 @@ DltReturnValue dlt_init_common(void) uint32_t buffer_max_configured = 0; /* Binary semaphore for threads */ - if (sem_init(&dlt_mutex, 0, 1)==-1) - { + if (sem_init(&dlt_mutex, 0, 1) == -1) { dlt_user_initialised = false; return DLT_RETURN_ERROR; } @@ -552,11 +553,11 @@ DltReturnValue dlt_init_common(void) /* set to unknown state of connected client */ dlt_user.log_state = -1; - dlt_user.dlt_log_handle=-1; - dlt_user.dlt_user_handle=DLT_FD_INIT; + dlt_user.dlt_log_handle = -1; + dlt_user.dlt_user_handle = DLT_FD_INIT; - dlt_set_id(dlt_user.ecuID,DLT_USER_DEFAULT_ECU_ID); - dlt_set_id(dlt_user.appID,""); + dlt_set_id(dlt_user.ecuID, DLT_USER_DEFAULT_ECU_ID); + dlt_set_id(dlt_user.appID, ""); dlt_user.application_description = NULL; @@ -570,10 +571,10 @@ DltReturnValue dlt_init_common(void) dlt_user.with_session_id = DLT_USER_WITH_SESSION_ID; /* With timestamp is enabled by default */ - dlt_user.with_timestamp= DLT_USER_WITH_TIMESTAMP; + dlt_user.with_timestamp = DLT_USER_WITH_TIMESTAMP; /* With timestamp is enabled by default */ - dlt_user.with_ecu_id= DLT_USER_WITH_ECU_ID; + dlt_user.with_ecu_id = DLT_USER_WITH_ECU_ID; /* Local print is disabled by default */ dlt_user.enable_local_print = 0; @@ -583,28 +584,24 @@ DltReturnValue dlt_init_common(void) dlt_user.timeout_at_exit_handler = DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT; env_local_print = getenv(DLT_USER_ENV_LOCAL_PRINT_MODE); - if (env_local_print) - { - if (strcmp(env_local_print,"AUTOMATIC")==0) - { + + if (env_local_print) { + if (strcmp(env_local_print, "AUTOMATIC") == 0) dlt_user.local_print_mode = DLT_PM_AUTOMATIC; - } - else if (strcmp(env_local_print,"FORCE_ON")==0) - { + else if (strcmp(env_local_print, "FORCE_ON") == 0) dlt_user.local_print_mode = DLT_PM_FORCE_ON; - } - else if (strcmp(env_local_print,"FORCE_OFF")==0) - { + else if (strcmp(env_local_print, "FORCE_OFF") == 0) dlt_user.local_print_mode = DLT_PM_FORCE_OFF; - } } env_initial_log_level = getenv("DLT_INITIAL_LOG_LEVEL"); - if( env_initial_log_level != NULL ) - { - if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0) - { - snprintf(str, DLT_USER_BUFFER_LENGTH, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", getenv("DLT_INITIAL_LOG_LEVEL")); + + if (env_initial_log_level != NULL) { + if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0) { + snprintf(str, + DLT_USER_BUFFER_LENGTH, + "Unable to parse initial set of log-levels from environment! Env:\n%s\n", + getenv("DLT_INITIAL_LOG_LEVEL")); dlt_log(LOG_WARNING, str); } } @@ -620,11 +617,10 @@ DltReturnValue dlt_init_common(void) env_buffer_max = getenv(DLT_USER_ENV_BUFFER_MAX_SIZE); env_buffer_step = getenv(DLT_USER_ENV_BUFFER_STEP_SIZE); - if (env_buffer_min != NULL) - { - buffer_min = (uint32_t) strtol(env_buffer_min, NULL, 10); - if (errno == EINVAL || errno == ERANGE) - { + if (env_buffer_min != NULL) { + buffer_min = (uint32_t)strtol(env_buffer_min, NULL, 10); + + if ((errno == EINVAL) || (errno == ERANGE)) { dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_MIN_SIZE); @@ -632,11 +628,10 @@ DltReturnValue dlt_init_common(void) } } - if (env_buffer_max != NULL) - { - buffer_max = (uint32_t) strtol(env_buffer_max, NULL, 10); - if (errno == EINVAL || errno == ERANGE) - { + if (env_buffer_max != NULL) { + buffer_max = (uint32_t)strtol(env_buffer_max, NULL, 10); + + if ((errno == EINVAL) || (errno == ERANGE)) { dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_MAX_SIZE); @@ -644,11 +639,10 @@ DltReturnValue dlt_init_common(void) } } - if (env_buffer_step != NULL) - { - buffer_step = (uint32_t) strtol(env_buffer_step, NULL, 10); - if (errno == EINVAL || errno == ERANGE) - { + if (env_buffer_step != NULL) { + buffer_step = (uint32_t)strtol(env_buffer_step, NULL, 10); + + if ((errno == EINVAL) || (errno == ERANGE)) { dlt_vlog(LOG_ERR, "Wrong value specified for %s. Using default\n", DLT_USER_ENV_BUFFER_STEP_SIZE); @@ -660,50 +654,47 @@ DltReturnValue dlt_init_common(void) dlt_user.log_buf_len = DLT_USER_BUF_MAX_SIZE; env_log_buffer_len = getenv(DLT_USER_ENV_LOG_MSG_BUF_LEN); - if (env_log_buffer_len != NULL) - { - buffer_max_configured = (uint32_t) strtol(env_log_buffer_len, NULL, 10); + if (env_log_buffer_len != NULL) { + buffer_max_configured = (uint32_t)strtol(env_log_buffer_len, NULL, 10); - if (buffer_max_configured > DLT_LOG_MSG_BUF_MAX_SIZE) - { + if (buffer_max_configured > DLT_LOG_MSG_BUF_MAX_SIZE) { dlt_user.log_buf_len = DLT_LOG_MSG_BUF_MAX_SIZE; dlt_vlog(LOG_WARNING, "Configured size exceeds maximum allowed size,restricting to max [65535 bytes]\n"); } - else - { + else { dlt_user.log_buf_len = buffer_max_configured; dlt_vlog(LOG_INFO, "Configured buffer size to [%d bytes]\n", buffer_max_configured); } } - if (dlt_user.resend_buffer == NULL) - { + + if (dlt_user.resend_buffer == NULL) { dlt_user.resend_buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (dlt_user.resend_buffer == NULL) - { + + if (dlt_user.resend_buffer == NULL) { dlt_user_initialised = false; DLT_SEM_FREE(); dlt_vlog(LOG_ERR, "cannot allocate memory for resend buffer\n"); return DLT_RETURN_ERROR; } } + if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), buffer_min, buffer_max, - buffer_step) == DLT_RETURN_ERROR) - { + buffer_step) == DLT_RETURN_ERROR) { dlt_user_initialised = false; DLT_SEM_FREE(); return DLT_RETURN_ERROR; } + DLT_SEM_FREE(); - signal(SIGPIPE,SIG_IGN); /* ignore pipe signals */ + signal(SIGPIPE, SIG_IGN); /* ignore pipe signals */ - if (atexit_registered == 0) - { + if (atexit_registered == 0) { atexit_registered = 1; atexit(dlt_user_atexit_handler); } @@ -719,10 +710,9 @@ DltReturnValue dlt_init_common(void) void dlt_user_atexit_handler(void) { - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); - // close file + /* close file */ dlt_log_free(); return; } @@ -730,7 +720,7 @@ void dlt_user_atexit_handler(void) /* Try to resend potential log messages in the user buffer */ int count = dlt_user_atexit_blow_out_user_buffer(); - if(count != 0) + if (count != 0) dlt_vnlog(LOG_WARNING, 128, "Lost log messages in user buffer when exiting: %i\n", count); /* Unregister app (this also unregisters all contexts in daemon) */ @@ -742,42 +732,39 @@ void dlt_user_atexit_handler(void) dlt_free(); } -int dlt_user_atexit_blow_out_user_buffer(void){ +int dlt_user_atexit_blow_out_user_buffer(void) +{ - int count,ret; + int count, ret; - uint32_t exitTime = dlt_uptime() + dlt_user.timeout_at_exit_handler; + uint32_t exitTime = dlt_uptime() + dlt_user.timeout_at_exit_handler; /* Send content of ringbuffer */ DLT_SEM_LOCK(); count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); DLT_SEM_FREE(); - if (count > 0) - { - while(dlt_uptime() < exitTime ) - { - if (dlt_user.dlt_log_handle == -1) - { + if (count > 0) { + while (dlt_uptime() < exitTime) { + if (dlt_user.dlt_log_handle == -1) { /* Reattach to daemon if neccesary */ dlt_user_log_reattach_to_daemon(); - if ((dlt_user.dlt_log_handle != -1) && (dlt_user.overflow_counter)) - { - if (dlt_user_log_send_overflow()==0) - { - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "%u messages discarded!\n", dlt_user.overflow_counter); - dlt_user.overflow_counter=0; + if ((dlt_user.dlt_log_handle != -1) && (dlt_user.overflow_counter)) { + if (dlt_user_log_send_overflow() == 0) { + dlt_vnlog(LOG_WARNING, + DLT_USER_BUFFER_LENGTH, + "%u messages discarded!\n", + dlt_user.overflow_counter); + dlt_user.overflow_counter = 0; } } } - if (dlt_user.dlt_log_handle != -1) - { + if (dlt_user.dlt_log_handle != -1) { ret = dlt_user_log_resend_buffer(); - if(ret == 0) - { + if (ret == 0) { DLT_SEM_LOCK(); count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); DLT_SEM_FREE(); @@ -799,8 +786,7 @@ int dlt_user_atexit_blow_out_user_buffer(void){ static void dlt_user_free_buffer(unsigned char **buffer) { - if (*buffer) - { + if (*buffer) { free(*buffer); *buffer = NULL; } @@ -814,30 +800,31 @@ DltReturnValue dlt_free(void) char filename[DLT_USER_MAX_FILENAME_LENGTH]; #endif - if( dlt_user_freeing != 0 ) - // resources are already being freed. Do nothing and return. + if (dlt_user_freeing != 0) + /* resources are already being freed. Do nothing and return. */ return DLT_RETURN_ERROR; - // library is freeing its resources. Avoid to allocate it in dlt_init() + /* library is freeing its resources. Avoid to allocate it in dlt_init() */ dlt_user_freeing = 1; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_user_freeing = 0; return DLT_RETURN_ERROR; } + dlt_user_initialised = false; dlt_stop_threads(); #ifndef DLT_USE_UNIX_SOCKET_IPC - if (dlt_user.dlt_user_handle!=DLT_FD_INIT) - { + + if (dlt_user.dlt_user_handle != DLT_FD_INIT) { close(dlt_user.dlt_user_handle); - dlt_user.dlt_user_handle=DLT_FD_INIT; - snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",dlt_user_dir,getpid()); + dlt_user.dlt_user_handle = DLT_FD_INIT; + snprintf(filename, DLT_USER_MAX_FILENAME_LENGTH, "%s/dlt%d", dlt_user_dir, getpid()); unlink(filename); } + #endif #ifdef DLT_SHM_ENABLE @@ -845,41 +832,38 @@ DltReturnValue dlt_free(void) dlt_shm_free_client(&dlt_user.dlt_shm); #endif - if (dlt_user.dlt_log_handle!=-1) - { + if (dlt_user.dlt_log_handle != -1) { /* close log file/output fifo to daemon */ #ifdef DLT_USE_UNIX_SOCKET_IPC ret = shutdown(dlt_user.dlt_log_handle, SHUT_WR); - if (ret < 0) - { + + if (ret < 0) { dlt_vlog(LOG_WARNING, "%s: shutdown failed: %s\n", __func__, strerror(errno)); } - else - { - while (1) - { + else { + while (1) { ssize_t bytes_read; bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len); - if (bytes_read < 0) - { + + if (bytes_read < 0) { dlt_vlog(LOG_DEBUG, "%s - %d: Reading...\n", __func__, __LINE__); break; } - else - { + else { dlt_vlog(LOG_DEBUG, "%s - %d: %d bytes read from resend buffer\n", __func__, __LINE__); + if (!bytes_read) break; } } } + #endif ret = close(dlt_user.dlt_log_handle); + if (ret < 0) - { dlt_vlog(LOG_WARNING, "%s: close failed: %s\n", __func__, strerror(errno)); - } dlt_user.dlt_log_handle = -1; } @@ -896,34 +880,30 @@ DltReturnValue dlt_free(void) DLT_SEM_FREE(); DLT_SEM_LOCK(); - if (dlt_user.dlt_ll_ts) - { - for (i=0;i<dlt_user.dlt_ll_ts_max_num_entries;i++) - { - if( dlt_user.dlt_ll_ts[i].context_description != NULL) - { + + if (dlt_user.dlt_ll_ts) { + for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { + if (dlt_user.dlt_ll_ts[i].context_description != NULL) { free (dlt_user.dlt_ll_ts[i].context_description); dlt_user.dlt_ll_ts[i].context_description = NULL; } - if (dlt_user.dlt_ll_ts[i].log_level_ptr != NULL) - { + if (dlt_user.dlt_ll_ts[i].log_level_ptr != NULL) { free(dlt_user.dlt_ll_ts[i].log_level_ptr); dlt_user.dlt_ll_ts[i].log_level_ptr = NULL; } - if (dlt_user.dlt_ll_ts[i].trace_status_ptr != NULL) - { + if (dlt_user.dlt_ll_ts[i].trace_status_ptr != NULL) { free(dlt_user.dlt_ll_ts[i].trace_status_ptr); dlt_user.dlt_ll_ts[i].trace_status_ptr = NULL; } - if (dlt_user.dlt_ll_ts[i].injection_table != NULL) - { + if (dlt_user.dlt_ll_ts[i].injection_table != NULL) { free(dlt_user.dlt_ll_ts[i].injection_table); dlt_user.dlt_ll_ts[i].injection_table = NULL; } - dlt_user.dlt_ll_ts[i].nrcallbacks = 0; + + dlt_user.dlt_ll_ts[i].nrcallbacks = 0; dlt_user.dlt_ll_ts[i].log_level_changed_callback = 0; } @@ -937,7 +917,7 @@ DltReturnValue dlt_free(void) DLT_SEM_FREE(); char queue_name[NAME_MAX]; - snprintf(queue_name,NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); + snprintf(queue_name, NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid()); /** * Ignore errors from these, to not to spam user if dlt_free @@ -953,27 +933,25 @@ DltReturnValue dlt_free(void) pthread_mutex_destroy(&mq_mutex); sem_destroy(&dlt_mutex); - // allow the user app to do dlt_init() again. - // The flag is unset only to keep almost the same behaviour as before, on EntryNav - // This should be removed for other projects (see documentation of dlt_free() + /* allow the user app to do dlt_init() again. */ + /* The flag is unset only to keep almost the same behaviour as before, on EntryNav */ + /* This should be removed for other projects (see documentation of dlt_free() */ dlt_user_freeing = 0; return DLT_RETURN_OK; } -DltReturnValue dlt_check_library_version(const char * user_major_version,const char * user_minor_version) +DltReturnValue dlt_check_library_version(const char *user_major_version, const char *user_minor_version) { return dlt_user_check_library_version(user_major_version, user_minor_version); } -DltReturnValue dlt_register_app(const char *appid, const char * description) +DltReturnValue dlt_register_app(const char *appid, const char *description) { DltReturnValue ret = DLT_RETURN_OK; - if (!dlt_user_initialised) - { - if (dlt_init() < 0) - { + if (!dlt_user_initialised) { + if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -984,32 +962,28 @@ DltReturnValue dlt_register_app(const char *appid, const char * description) /* check if application already registered */ /* if yes do not register again */ - if (appid[1] == 0) - { + if (appid[1] == 0) { if (appid[0] == dlt_user.appID[0]) return DLT_RETURN_OK; } else if (appid[2] == 0) { - if (appid[0] == dlt_user.appID[0] && - appid[1] == dlt_user.appID[1]) + if ((appid[0] == dlt_user.appID[0]) && + (appid[1] == dlt_user.appID[1])) return DLT_RETURN_OK; } else if (appid[3] == 0) { - if (appid[0] == dlt_user.appID[0] && - appid[1] == dlt_user.appID[1] && - appid[2] == dlt_user.appID[2]) - return DLT_RETURN_OK; - } - else - { - if (appid[0] == dlt_user.appID[0] && - appid[1] == dlt_user.appID[1] && - appid[2] == dlt_user.appID[2] && - appid[3] == dlt_user.appID[3]) + if ((appid[0] == dlt_user.appID[0]) && + (appid[1] == dlt_user.appID[1]) && + (appid[2] == dlt_user.appID[2])) return DLT_RETURN_OK; } + else if ((appid[0] == dlt_user.appID[0]) && + (appid[1] == dlt_user.appID[1]) && + (appid[2] == dlt_user.appID[2]) && + (appid[3] == dlt_user.appID[3])) + return DLT_RETURN_OK; DLT_SEM_LOCK(); @@ -1021,17 +995,15 @@ DltReturnValue dlt_register_app(const char *appid, const char * description) dlt_user.application_description = NULL; - if (description != NULL) - { + if (description != NULL) { size_t desc_len = strlen(description); dlt_user.application_description = malloc(desc_len + 1); - if (dlt_user.application_description) - { + + if (dlt_user.application_description) { strncpy(dlt_user.application_description, description, desc_len); dlt_user.application_description[desc_len] = '\0'; } - else - { + else { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -1041,40 +1013,38 @@ DltReturnValue dlt_register_app(const char *appid, const char * description) ret = dlt_user_log_send_register_application(); - if (( ret == DLT_RETURN_OK ) && (dlt_user.dlt_log_handle!=-1)) - { + if ((ret == DLT_RETURN_OK) && (dlt_user.dlt_log_handle != -1)) ret = dlt_user_log_resend_buffer(); - } return ret; } -DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char * description) +DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char *description) { - // check nullpointer - if(handle == NULL) + /* check nullpointer */ + if (handle == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { - if (dlt_init() < 0) - { + if (!dlt_user_initialised) { + if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } } if ((contextid == NULL) || (contextid[0] == '\0')) - { return DLT_RETURN_WRONG_PARAMETER; - } - return dlt_register_context_ll_ts(handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET); + return dlt_register_context_ll_ts(handle, + contextid, + description, + DLT_USER_LOG_LEVEL_NOT_SET, + DLT_USER_TRACE_STATUS_NOT_SET); } DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, const char *contextid, - const char * description, + const char *description, int loglevel, int tracestatus, void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], @@ -1085,29 +1055,22 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, uint32_t i; int envLogLevel = DLT_USER_LOG_LEVEL_NOT_SET; - //check nullpointer - if ((handle ==NULL) || (contextid == NULL) || (contextid[0] == '\0')) - { + /*check nullpointer */ + if ((handle == NULL) || (contextid == NULL) || (contextid[0] == '\0')) return DLT_RETURN_WRONG_PARAMETER; - } - if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX) - { + if ((loglevel < DLT_USER_LOG_LEVEL_NOT_SET) || (loglevel >= DLT_LOG_MAX)) { dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel); return DLT_RETURN_WRONG_PARAMETER; } - if (tracestatus < DLT_USER_TRACE_STATUS_NOT_SET || tracestatus >= DLT_TRACE_STATUS_MAX) - { + if ((tracestatus < DLT_USER_TRACE_STATUS_NOT_SET) || (tracestatus >= DLT_TRACE_STATUS_MAX)) { dlt_vlog(LOG_ERR, "Tracestatus %d is outside valid range", tracestatus); return DLT_RETURN_WRONG_PARAMETER; } - if (dlt_user_log_init(handle, &log) == -1) - { return DLT_RETURN_ERROR; - } /* Reset message counter */ handle->mcnt = 0; @@ -1121,11 +1084,10 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, /* Double registration is already checked by daemon */ /* Allocate or expand context array */ - if (dlt_user.dlt_ll_ts == 0) - { - dlt_user.dlt_ll_ts = (dlt_ll_ts_type*) malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); - if (dlt_user.dlt_ll_ts == 0) - { + if (dlt_user.dlt_ll_ts == 0) { + dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * DLT_USER_CONTEXT_ALLOC_SIZE); + + if (dlt_user.dlt_ll_ts == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -1133,71 +1095,65 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, dlt_user.dlt_ll_ts_max_num_entries = DLT_USER_CONTEXT_ALLOC_SIZE; /* Initialize new entries */ - for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) - { + for (i = 0; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { dlt_set_id(dlt_user.dlt_ll_ts[i].contextID, ""); /* At startup, logging and tracing is locally enabled */ /* the correct log level/status is set after received from daemon */ - dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL; + dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL; dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS; - dlt_user.dlt_ll_ts[i].log_level_ptr = 0; + dlt_user.dlt_ll_ts[i].log_level_ptr = 0; dlt_user.dlt_ll_ts[i].trace_status_ptr = 0; dlt_user.dlt_ll_ts[i].context_description = 0; dlt_user.dlt_ll_ts[i].injection_table = 0; - dlt_user.dlt_ll_ts[i].nrcallbacks = 0; + dlt_user.dlt_ll_ts[i].nrcallbacks = 0; dlt_user.dlt_ll_ts[i].log_level_changed_callback = 0; } } - else - { - if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) - { - /* allocate memory in steps of DLT_USER_CONTEXT_ALLOC_SIZE, e.g. 500 */ - dlt_ll_ts_type *old_ll_ts; - uint32_t old_max_entries; - - old_ll_ts = dlt_user.dlt_ll_ts; - old_max_entries = dlt_user.dlt_ll_ts_max_num_entries; - - dlt_user.dlt_ll_ts_max_num_entries = ((dlt_user.dlt_ll_ts_num_entries - / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) - * DLT_USER_CONTEXT_ALLOC_SIZE; - dlt_user.dlt_ll_ts = (dlt_ll_ts_type*) malloc(sizeof(dlt_ll_ts_type)* - dlt_user.dlt_ll_ts_max_num_entries); - if (dlt_user.dlt_ll_ts == 0) - { - dlt_user.dlt_ll_ts = old_ll_ts; - dlt_user.dlt_ll_ts_max_num_entries = old_max_entries; - DLT_SEM_FREE(); - return DLT_RETURN_ERROR; - } + else if ((dlt_user.dlt_ll_ts_num_entries % DLT_USER_CONTEXT_ALLOC_SIZE) == 0) { + /* allocate memory in steps of DLT_USER_CONTEXT_ALLOC_SIZE, e.g. 500 */ + dlt_ll_ts_type *old_ll_ts; + uint32_t old_max_entries; - memcpy(dlt_user.dlt_ll_ts, old_ll_ts, sizeof(dlt_ll_ts_type) * dlt_user.dlt_ll_ts_num_entries); - free(old_ll_ts); + old_ll_ts = dlt_user.dlt_ll_ts; + old_max_entries = dlt_user.dlt_ll_ts_max_num_entries; - /* Initialize new entries */ - for (i = dlt_user.dlt_ll_ts_num_entries; i < dlt_user.dlt_ll_ts_max_num_entries; i++) - { - dlt_set_id(dlt_user.dlt_ll_ts[i].contextID, ""); + dlt_user.dlt_ll_ts_max_num_entries = ((dlt_user.dlt_ll_ts_num_entries + / DLT_USER_CONTEXT_ALLOC_SIZE) + 1) + * DLT_USER_CONTEXT_ALLOC_SIZE; + dlt_user.dlt_ll_ts = (dlt_ll_ts_type *)malloc(sizeof(dlt_ll_ts_type) * + dlt_user.dlt_ll_ts_max_num_entries); - /* At startup, logging and tracing is locally enabled */ - /* the correct log level/status is set after received from daemon */ - dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL; - dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS; + if (dlt_user.dlt_ll_ts == 0) { + dlt_user.dlt_ll_ts = old_ll_ts; + dlt_user.dlt_ll_ts_max_num_entries = old_max_entries; + DLT_SEM_FREE(); + return DLT_RETURN_ERROR; + } - dlt_user.dlt_ll_ts[i].log_level_ptr = 0; - dlt_user.dlt_ll_ts[i].trace_status_ptr = 0; + memcpy(dlt_user.dlt_ll_ts, old_ll_ts, sizeof(dlt_ll_ts_type) * dlt_user.dlt_ll_ts_num_entries); + free(old_ll_ts); - dlt_user.dlt_ll_ts[i].context_description = 0; + /* Initialize new entries */ + for (i = dlt_user.dlt_ll_ts_num_entries; i < dlt_user.dlt_ll_ts_max_num_entries; i++) { + dlt_set_id(dlt_user.dlt_ll_ts[i].contextID, ""); - dlt_user.dlt_ll_ts[i].injection_table = 0; - dlt_user.dlt_ll_ts[i].nrcallbacks = 0; - dlt_user.dlt_ll_ts[i].log_level_changed_callback = 0; - } + /* At startup, logging and tracing is locally enabled */ + /* the correct log level/status is set after received from daemon */ + dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL; + dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS; + + dlt_user.dlt_ll_ts[i].log_level_ptr = 0; + dlt_user.dlt_ll_ts[i].trace_status_ptr = 0; + + dlt_user.dlt_ll_ts[i].context_description = 0; + + dlt_user.dlt_ll_ts[i].injection_table = 0; + dlt_user.dlt_ll_ts[i].nrcallbacks = 0; + dlt_user.dlt_ll_ts[i].log_level_changed_callback = 0; } } @@ -1205,18 +1161,15 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, dlt_set_id(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].contextID, contextid); if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description != 0) - { free(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description); - } dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = 0; - if (description != 0) - { + if (description != 0) { size_t desc_len = strlen(description); dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(desc_len + 1); - if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description == 0) - { + + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } @@ -1225,41 +1178,41 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len] = '\0'; } - if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) - { + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) { dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t)); - if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) - { + + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } } - if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) - { + + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) { dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t)); - if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) - { + + if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } } /* check if the log level is set in the environement */ - envLogLevel = dlt_env_adjust_ll_from_env(&dlt_user.initial_ll_set, dlt_user.appID, contextid, DLT_USER_LOG_LEVEL_NOT_SET); - if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) - { + envLogLevel = dlt_env_adjust_ll_from_env(&dlt_user.initial_ll_set, + dlt_user.appID, + contextid, + DLT_USER_LOG_LEVEL_NOT_SET); + + if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) { dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = envLogLevel; loglevel = envLogLevel; } else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET) { - dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel; + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel; } if (tracestatus != DLT_USER_TRACE_STATUS_NOT_SET) - { dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus; - } /* Prepare transfer struct */ dlt_set_id(handle->contextID, contextid); @@ -1270,12 +1223,14 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description; - *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level; - *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus; + *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level; + *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = + dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus; dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_changed_callback = dlt_log_level_changed_callback; log.log_level = loglevel; - log.trace_status = tracestatus; + log.trace_status = tracestatus; dlt_user.dlt_ll_ts_num_entries++; @@ -1286,8 +1241,8 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle, DltReturnValue dlt_register_context_ll_ts(DltContext *handle, const char *contextid, - const char * description, - int loglevel, + const char *description, + int loglevel, int tracestatus) { return dlt_register_context_ll_ts_llccb(handle, @@ -1301,20 +1256,16 @@ DltReturnValue dlt_register_context_ll_ts(DltContext *handle, DltReturnValue dlt_register_context_llccb(DltContext *handle, const char *contextid, - const char * description, + const char *description, void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status)) { if ((handle == NULL) || (contextid == NULL) || (contextid[0] == '\0')) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (!dlt_user_initialised) - { - if (dlt_init() < 0) - { + if (!dlt_user_initialised) { + if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -1332,8 +1283,7 @@ DltReturnValue dlt_unregister_app(void) { DltReturnValue ret = DLT_RETURN_OK; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -1347,9 +1297,7 @@ DltReturnValue dlt_unregister_app(void) dlt_set_id(dlt_user.appID, ""); if (dlt_user.application_description != NULL) - { free(dlt_user.application_description); - } dlt_user.application_description = NULL; @@ -1362,18 +1310,15 @@ DltReturnValue dlt_unregister_app_flush_buffered_logs(void) { DltReturnValue ret = DLT_RETURN_OK; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_ERR, "%s dlt_user_initialised false\n", __func__); return DLT_RETURN_ERROR; } - if (dlt_user.dlt_log_handle != -1) - { + if (dlt_user.dlt_log_handle != -1) { do - { ret = dlt_user_log_resend_buffer(); - }while ((ret != DLT_RETURN_OK) && (dlt_user.dlt_log_handle != -1)); + while ((ret != DLT_RETURN_OK) && (dlt_user.dlt_log_handle != -1)); } return dlt_unregister_app(); @@ -1386,6 +1331,7 @@ DltReturnValue dlt_unregister_context(DltContext *handle) log.handle = NULL; log.context_description = NULL; + if (dlt_user_log_init(handle, &log) <= DLT_RETURN_ERROR) return DLT_RETURN_ERROR; @@ -1394,8 +1340,7 @@ DltReturnValue dlt_unregister_context(DltContext *handle) handle->log_level_ptr = NULL; handle->trace_status_ptr = NULL; - if (dlt_user.dlt_ll_ts != NULL) - { + if (dlt_user.dlt_ll_ts != NULL) { /* Clear and free local stored context information */ dlt_set_id(dlt_user.dlt_ll_ts[handle->log_level_pos].contextID, ""); @@ -1403,31 +1348,26 @@ DltReturnValue dlt_unregister_context(DltContext *handle) dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status = DLT_USER_INITIAL_TRACE_STATUS; if (dlt_user.dlt_ll_ts[handle->log_level_pos].context_description != NULL) - { free(dlt_user.dlt_ll_ts[handle->log_level_pos].context_description); - } - if (dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr != NULL) - { + if (dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr != NULL) { free(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr); dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr = NULL; } - if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr != NULL) - { + if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr != NULL) { free(dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr); dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr = NULL; } dlt_user.dlt_ll_ts[handle->log_level_pos].context_description = NULL; - if (dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table != NULL) - { + if (dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table != NULL) { free(dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table); dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table = NULL; } - dlt_user.dlt_ll_ts[handle->log_level_pos].nrcallbacks = 0; + dlt_user.dlt_ll_ts[handle->log_level_pos].nrcallbacks = 0; dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_changed_callback = 0; } @@ -1443,61 +1383,58 @@ DltReturnValue dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTrac { uint32_t i; - if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX) - { + if ((loglevel < DLT_USER_LOG_LEVEL_NOT_SET) || (loglevel >= DLT_LOG_MAX)) { dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel); return DLT_RETURN_WRONG_PARAMETER; } - if (tracestatus < DLT_USER_TRACE_STATUS_NOT_SET || tracestatus >= DLT_TRACE_STATUS_MAX) - { + if ((tracestatus < DLT_USER_TRACE_STATUS_NOT_SET) || (tracestatus >= DLT_TRACE_STATUS_MAX)) { dlt_vlog(LOG_ERR, "Tracestatus %d is outside valid range", tracestatus); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { - if (dlt_init() < 0) - { + if (!dlt_user_initialised) { + if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } } /* Removed because of DltLogLevelType and DltTraceStatusType - - if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE)) - { - return DLT_RETURN_ERROR; - } - - if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON)) - { - return DLT_RETURN_ERROR; - } - - if (dlt_user.dlt_ll_ts==0) - { - return DLT_RETURN_ERROR; - } - - */ + * + * if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE)) + * { + * return DLT_RETURN_ERROR; + * } + * + * if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON)) + * { + * return DLT_RETURN_ERROR; + * } + * + * if (dlt_user.dlt_ll_ts==0) + * { + * return DLT_RETURN_ERROR; + * } + * + */ DLT_SEM_LOCK(); - if (dlt_user.dlt_ll_ts == NULL) - { + + if (dlt_user.dlt_ll_ts == NULL) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } /* Update local structures */ - for (i=0; i<dlt_user.dlt_ll_ts_num_entries;i++) - { + for (i = 0; i < dlt_user.dlt_ll_ts_num_entries; i++) { dlt_user.dlt_ll_ts[i].log_level = loglevel; dlt_user.dlt_ll_ts[i].trace_status = tracestatus; - if(dlt_user.dlt_ll_ts[i].log_level_ptr) + + if (dlt_user.dlt_ll_ts[i].log_level_ptr) *(dlt_user.dlt_ll_ts[i].log_level_ptr) = loglevel; - if(dlt_user.dlt_ll_ts[i].trace_status_ptr) + + if (dlt_user.dlt_ll_ts[i].trace_status_ptr) *(dlt_user.dlt_ll_ts[i].trace_status_ptr) = tracestatus; } @@ -1514,16 +1451,13 @@ int dlt_get_log_state() DltReturnValue dlt_set_log_mode(DltUserLogMode mode) { - if (mode < DLT_USER_MODE_UNDEFINED || mode >= DLT_USER_MODE_MAX) - { + if ((mode < DLT_USER_MODE_UNDEFINED) || (mode >= DLT_USER_MODE_MAX)) { dlt_vlog(LOG_ERR, "User log mode %d is outside valid range", mode); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { - if (dlt_init() < 0) - { + if (!dlt_user_initialised) { + if (dlt_init() < 0) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -1534,50 +1468,43 @@ DltReturnValue dlt_set_log_mode(DltUserLogMode mode) int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds) { - if (dlt_user_initialised==0) - { - if (dlt_init()<0) - { - return -1; + if (dlt_user_initialised == 0) { + if (dlt_init() < 0) + return -1; } - } - dlt_user.timeout_at_exit_handler = timeout_in_milliseconds * 10; - return 0; + + dlt_user.timeout_at_exit_handler = timeout_in_milliseconds * 10; + return 0; } -DltReturnValue dlt_forward_msg(void *msgdata,size_t size) +DltReturnValue dlt_forward_msg(void *msgdata, size_t size) { DltUserHeader userheader; DltReturnValue ret; if ((msgdata == NULL) || (size == 0)) - { return DLT_RETURN_WRONG_PARAMETER; - } if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG) < DLT_RETURN_OK) - { /* Type of internal user message; same value for Trace messages */ return DLT_RETURN_ERROR; - } - if (dlt_user.dlt_is_file) - { + if (dlt_user.dlt_is_file) { /* log to file */ return dlt_user_log_out2(dlt_user.dlt_log_handle, msgdata, size, 0, 0); } - else - { + else { /* Reattach to daemon if neccesary */ dlt_user_log_reattach_to_daemon(); - if (dlt_user.overflow_counter) - { - if (dlt_user_log_send_overflow()==0) - { - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Buffer full! %u messages discarded!\n", dlt_user.overflow_counter); - dlt_user.overflow_counter=0; + if (dlt_user.overflow_counter) { + if (dlt_user_log_send_overflow() == 0) { + dlt_vnlog(LOG_WARNING, + DLT_USER_BUFFER_LENGTH, + "Buffer full! %u messages discarded!\n", + dlt_user.overflow_counter); + dlt_user.overflow_counter = 0; } } @@ -1586,77 +1513,66 @@ DltReturnValue dlt_forward_msg(void *msgdata,size_t size) msgdata, size, 0, 0); /* store message in ringbuffer, if an error has occured */ - if (ret < DLT_RETURN_OK) - { + if (ret < DLT_RETURN_OK) { DLT_SEM_LOCK(); - - if (ret == DLT_RETURN_PIPE_ERROR) - { + + if (ret == DLT_RETURN_PIPE_ERROR) { /* handle not open or pipe error */ - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; } if (dlt_buffer_push3(&(dlt_user.startup_buffer), - (unsigned char *)&(userheader), sizeof(DltUserHeader), - msgdata, size, 0, 0) == DLT_RETURN_ERROR) - { - if(dlt_user.overflow_counter==0) - { - dlt_log(LOG_WARNING,"Buffer full! First message discarded!\n"); - } + (unsigned char *)&(userheader), sizeof(DltUserHeader), + msgdata, size, 0, 0) == DLT_RETURN_ERROR) { + if (dlt_user.overflow_counter == 0) + dlt_log(LOG_WARNING, "Buffer full! First message discarded!\n"); ret = DLT_RETURN_BUFFER_FULL; } DLT_SEM_FREE(); - - if(dlt_user_queue_resend() < DLT_RETURN_OK && dlt_user.dlt_log_handle >= 0) - { - ;//dlt_log(LOG_WARNING, "dlt_forward_msg: Failed to queue resending.\n"); - } } - switch (ret) + switch (ret) { + case DLT_RETURN_WRONG_PARAMETER: { - case DLT_RETURN_WRONG_PARAMETER: - { - /* wrong parameters */ - return DLT_RETURN_WRONG_PARAMETER; - } - case DLT_RETURN_BUFFER_FULL: - { - /* Buffer full */ - dlt_user.overflow_counter += 1; - return DLT_RETURN_ERROR; - } - case DLT_RETURN_PIPE_FULL: - { - /* data could not be written */ - return DLT_RETURN_ERROR; - } - case DLT_RETURN_PIPE_ERROR: - { - /* handle not open or pipe error */ - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; + /* wrong parameters */ + return DLT_RETURN_WRONG_PARAMETER; + } + case DLT_RETURN_BUFFER_FULL: + { + /* Buffer full */ + dlt_user.overflow_counter += 1; + return DLT_RETURN_ERROR; + } + case DLT_RETURN_PIPE_FULL: + { + /* data could not be written */ + return DLT_RETURN_ERROR; + } + case DLT_RETURN_PIPE_ERROR: + { + /* handle not open or pipe error */ + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; - return DLT_RETURN_ERROR; - } - case DLT_RETURN_ERROR: - { - /* other error condition */ - return DLT_RETURN_ERROR; - } - case DLT_RETURN_OK: - { - return DLT_RETURN_OK; - } - default: - { - /* This case should not occur */ - return DLT_RETURN_ERROR; - } + return DLT_RETURN_ERROR; + } + case DLT_RETURN_ERROR: + { + /* other error condition */ + return DLT_RETURN_ERROR; + } + case DLT_RETURN_OK: + { + return DLT_RETURN_OK; + } + default: + { + /* This case should not occur */ + return DLT_RETURN_ERROR; + } } } @@ -1665,39 +1581,42 @@ DltReturnValue dlt_forward_msg(void *msgdata,size_t size) /* ********************************************************************************************* */ -inline DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log,DltLogLevelType loglevel) +inline DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel) { - return dlt_user_log_write_start_id(handle,log,loglevel,DLT_USER_DEFAULT_MSGID); + return dlt_user_log_write_start_id(handle, log, loglevel, DLT_USER_DEFAULT_MSGID); } -DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid) +DltReturnValue dlt_user_log_write_start_id(DltContext *handle, + DltContextData *log, + DltLogLevelType loglevel, + uint32_t messageid) { DLT_LOG_FATAL_RESET_TRAP(loglevel); DltReturnValue ret = DLT_RETURN_OK; - // check nullpointer - if (handle == NULL || log == NULL) + /* check nullpointer */ + if ((handle == NULL) || (log == NULL)) return DLT_RETURN_WRONG_PARAMETER; /* check log levels */ ret = dlt_user_is_logLevel_enabled(handle, loglevel); + if (ret == DLT_RETURN_WRONG_PARAMETER) return DLT_RETURN_WRONG_PARAMETER; else if (ret == DLT_RETURN_LOGGING_DISABLED) return DLT_RETURN_OK; else - /* Do nothing */ + /* Do nothing */ /* initialize values */ - if (dlt_user_log_init(handle, log) < DLT_RETURN_OK || dlt_user.dlt_ll_ts == NULL) + if ((dlt_user_log_init(handle, log) < DLT_RETURN_OK) || (dlt_user.dlt_ll_ts == NULL)) return DLT_RETURN_ERROR; /* initialize values */ - if (log->buffer == NULL) - { + if (log->buffer == NULL) { log->buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (log->buffer == NULL) - { + + if (log->buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } @@ -1708,8 +1627,7 @@ DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *l log->size = 0; /* In non-verbose mode, insert message id */ - if (dlt_user.verbose_mode == 0) - { + if (dlt_user.verbose_mode == 0) { if ((sizeof(uint32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; @@ -1718,7 +1636,7 @@ DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *l log->size = sizeof(uint32_t); /* as the message id is part of each message in non-verbose mode, - it doesn't increment the argument counter in extended header (if used) */ + * it doesn't increment the argument counter in extended header (if used) */ } return DLT_RETURN_TRUE; @@ -1746,21 +1664,19 @@ DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type) { size_t new_log_size = 0; - uint32_t type_info = 0; + uint32_t type_info = 0; - // check nullpointer - if (log == NULL || (data == NULL && length!=0)) + /* check nullpointer */ + if ((log == NULL) || ((data == NULL) && (length != 0))) return DLT_RETURN_WRONG_PARAMETER; - // Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning - if ((int16_t)type < DLT_FORMAT_DEFAULT || type >= DLT_FORMAT_MAX) - { + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -1770,23 +1686,20 @@ DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { + if (dlt_user.verbose_mode) { new_log_size = log->size + length + sizeof(uint32_t) + sizeof(uint16_t); if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - /* Transmit type information */ type_info = DLT_TYPE_INFO_RAWD; - if (type >= DLT_FORMAT_HEX8 && type <= DLT_FORMAT_HEX64) - { + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) { type_info |= DLT_SCOD_HEX; type_info += type; } - else if (type >= DLT_FORMAT_BIN8 && type <= DLT_FORMAT_BIN16) + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) { type_info |= DLT_SCOD_BIN; type_info += type - DLT_FORMAT_BIN8 + 1; @@ -1815,35 +1728,31 @@ DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if (sizeof(float32_t)!=4) - { + if (sizeof(float32_t) != 4) return DLT_RETURN_ERROR; - } - if ((log->size+sizeof(float32_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(float32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(float32_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(float32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data, sizeof(float32_t)); + memcpy((log->buffer) + log->size, &data, sizeof(float32_t)); log->size += sizeof(float32_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -1855,52 +1764,46 @@ DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if (sizeof(float64_t)!=8) - { + if (sizeof(float64_t) != 8) return DLT_RETURN_ERROR; - } - if ((log->size+sizeof(float64_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(float64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(float64_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(float64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data, sizeof(float64_t)); + memcpy((log->buffer) + log->size, &data, sizeof(float64_t)); log->size += sizeof(float64_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } -DltReturnValue dlt_user_log_write_uint( DltContextData *log, unsigned int data) +DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data) { if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - switch (sizeof(unsigned int)) - { + switch (sizeof(unsigned int)) { case 1: { return dlt_user_log_write_uint8(log, (uint8_t)data); @@ -1938,30 +1841,28 @@ DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint8_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint8_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); log->size += sizeof(uint8_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -1973,30 +1874,28 @@ DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint16_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint16_t)); log->size += sizeof(uint16_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2008,30 +1907,28 @@ DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint32_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint32_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data, sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint32_t)); log->size += sizeof(uint32_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2043,30 +1940,28 @@ DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint64_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint64_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); - log->size +=sizeof(uint32_t); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); + log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint64_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint64_t)); log->size += sizeof(uint64_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2078,47 +1973,40 @@ DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t d if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - // Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning - if ((int16_t)type < DLT_FORMAT_DEFAULT || type >= DLT_FORMAT_MAX) - { + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT; - if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64) - { + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) type_info |= DLT_SCOD_HEX; - } - else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16) - { + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) type_info |= DLT_SCOD_BIN; - } - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint8_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); log->size += sizeof(uint8_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2130,47 +2018,40 @@ DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - // Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning - if ((int16_t)type < DLT_FORMAT_DEFAULT || type >= DLT_FORMAT_MAX) - { + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT; - if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64) - { + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) type_info |= DLT_SCOD_HEX; - } - else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16) - { + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) type_info |= DLT_SCOD_BIN; - } - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint16_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint16_t)); log->size += sizeof(uint16_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2182,47 +2063,40 @@ DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - // Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning - if ((int16_t)type < DLT_FORMAT_DEFAULT || type >= DLT_FORMAT_MAX) - { + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT; - if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64) - { + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) type_info |= DLT_SCOD_HEX; - } - else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16) - { + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) type_info |= DLT_SCOD_BIN; - } - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint32_t)); log->size += sizeof(uint32_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2234,47 +2108,40 @@ DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - // Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning - if ((int16_t)type < DLT_FORMAT_DEFAULT || type >= DLT_FORMAT_MAX) - { + /* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */ + if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) { dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type); return DLT_RETURN_WRONG_PARAMETER; } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT; - if(type>=DLT_FORMAT_HEX8 && type<=DLT_FORMAT_HEX64) - { + if ((type >= DLT_FORMAT_HEX8) && (type <= DLT_FORMAT_HEX64)) type_info |= DLT_SCOD_HEX; - } - else if(type>=DLT_FORMAT_BIN8 && type<=DLT_FORMAT_BIN16) - { + else if ((type >= DLT_FORMAT_BIN8) && (type <= DLT_FORMAT_BIN16)) type_info |= DLT_SCOD_BIN; - } - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint64_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint64_t)); log->size += sizeof(uint64_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2282,30 +2149,26 @@ DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data) { if (log == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - switch(sizeof(void *)) - { - case 4: - return dlt_user_log_write_uint32_formatted(log, - (uintptr_t)data, - DLT_FORMAT_HEX32); - break; - case 8: - return dlt_user_log_write_uint64_formatted(log, - (uintptr_t)data, - DLT_FORMAT_HEX64); - break; - default: - ; /* skip */ + switch (sizeof(void *)) { + case 4: + return dlt_user_log_write_uint32_formatted(log, + (uintptr_t)data, + DLT_FORMAT_HEX32); + break; + case 8: + return dlt_user_log_write_uint64_formatted(log, + (uintptr_t)data, + DLT_FORMAT_HEX64); + break; + default: + ; /* skip */ } return DLT_RETURN_OK; @@ -2316,14 +2179,12 @@ DltReturnValue dlt_user_log_write_int(DltContextData *log, int data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - switch (sizeof(int)) - { + switch (sizeof(int)) { case 1: { return dlt_user_log_write_int8(log, (int8_t)data); @@ -2361,30 +2222,28 @@ DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(int8_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(int8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(int8_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(int8_t)); + memcpy((log->buffer) + log->size, &data, sizeof(int8_t)); log->size += sizeof(int8_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2396,30 +2255,28 @@ DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(int16_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(int16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(int16_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int16_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(int16_t)); + memcpy((log->buffer) + log->size, &data, sizeof(int16_t)); log->size += sizeof(int16_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2431,30 +2288,28 @@ DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(int32_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(int32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(int32_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int32_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data, sizeof(int32_t)); + memcpy((log->buffer) + log->size, &data, sizeof(int32_t)); log->size += sizeof(int32_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2466,30 +2321,28 @@ DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(int64_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(int64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(int64_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(int64_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(int64_t)); + memcpy((log->buffer) + log->size, &data, sizeof(int64_t)); log->size += sizeof(int64_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2501,30 +2354,28 @@ DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data) if (log == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if ((log->size+sizeof(uint8_t))>dlt_user.log_buf_len) + if ((log->size + sizeof(uint8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { - if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>dlt_user.log_buf_len) + if (dlt_user.verbose_mode) { + if ((log->size + sizeof(uint32_t) + sizeof(uint8_t)) > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; type_info = DLT_TYPE_INFO_BOOL; - memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t)); + memcpy((log->buffer) + log->size, &(type_info), sizeof(uint32_t)); log->size += sizeof(uint32_t); } - memcpy((log->buffer)+log->size,&data,sizeof(uint8_t)); + memcpy((log->buffer) + log->size, &data, sizeof(uint8_t)); log->size += sizeof(uint8_t); - log->args_num ++; + log->args_num++; return DLT_RETURN_OK; } @@ -2535,11 +2386,10 @@ DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text) uint32_t type_info = 0; size_t new_log_size = 0; - if (log == NULL || text == NULL) + if ((log == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -2551,8 +2401,7 @@ DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text) if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { + if (dlt_user.verbose_mode) { new_log_size = log->size + arg_size + sizeof(uint32_t) + sizeof(uint16_t); if (new_log_size > dlt_user.log_buf_len) @@ -2587,11 +2436,10 @@ DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *t uint32_t type_info; size_t new_log_size = 0; - if (log == NULL || text == NULL) + if ((log == NULL) || (text == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_WARNING, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -2602,8 +2450,7 @@ DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *t if (new_log_size > dlt_user.log_buf_len) return DLT_RETURN_USER_BUFFER_FULL; - if (dlt_user.verbose_mode) - { + if (dlt_user.verbose_mode) { new_log_size = log->size + arg_size + sizeof(uint32_t) + sizeof(uint16_t); if (new_log_size > dlt_user.log_buf_len) @@ -2627,10 +2474,10 @@ DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *t } DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint32_t service_id, - dlt_injection_callback_id dlt_injection_cbk, void *priv) + dlt_injection_callback_id dlt_injection_cbk, void *priv) { DltContextData log; - uint32_t i,j,k; + uint32_t i, j, k; int found = 0; DltUserInjectionCallback *old; @@ -2638,65 +2485,62 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (service_id<DLT_USER_INJECTION_MIN) + if (service_id < DLT_USER_INJECTION_MIN) return DLT_RETURN_WRONG_PARAMETER; /* This function doesn't make sense storing to local file is choosen; - so terminate this function */ + * so terminate this function */ if (dlt_user.dlt_is_file) return DLT_RETURN_OK; DLT_SEM_LOCK(); - if (dlt_user.dlt_ll_ts == NULL) - { + if (dlt_user.dlt_ll_ts == NULL) { DLT_SEM_FREE(); return DLT_RETURN_OK; } /* Insert callback in corresponding table */ - i=handle->log_level_pos; + i = handle->log_level_pos; /* Insert each service_id only once */ - for (k=0;k<dlt_user.dlt_ll_ts[i].nrcallbacks;k++) - { + for (k = 0; k < dlt_user.dlt_ll_ts[i].nrcallbacks; k++) if ((dlt_user.dlt_ll_ts[i].injection_table) && - (dlt_user.dlt_ll_ts[i].injection_table[k].service_id == service_id)) - { + (dlt_user.dlt_ll_ts[i].injection_table[k].service_id == service_id)) { found = 1; break; } - } - if (found) - { + + + if (found) { j = k; } - else - { - j=dlt_user.dlt_ll_ts[i].nrcallbacks; + else { + j = dlt_user.dlt_ll_ts[i].nrcallbacks; /* Allocate or expand injection table */ - if (dlt_user.dlt_ll_ts[i].injection_table == NULL) - { - dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback*) malloc(sizeof(DltUserInjectionCallback)); - if(dlt_user.dlt_ll_ts[i].injection_table == NULL) - { + if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { + dlt_user.dlt_ll_ts[i].injection_table = + (DltUserInjectionCallback *)malloc(sizeof(DltUserInjectionCallback)); + + if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { DLT_SEM_FREE(); return DLT_RETURN_ERROR; } } - else - { + else { old = dlt_user.dlt_ll_ts[i].injection_table; - dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback*) malloc(sizeof(DltUserInjectionCallback)*(j+1)); - if(dlt_user.dlt_ll_ts[i].injection_table == NULL) - { + dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback *)malloc( + sizeof(DltUserInjectionCallback) * (j + 1)); + + if (dlt_user.dlt_ll_ts[i].injection_table == NULL) { dlt_user.dlt_ll_ts[i].injection_table = old; DLT_SEM_FREE(); return DLT_RETURN_ERROR; } - memcpy(dlt_user.dlt_ll_ts[i].injection_table,old,sizeof(DltUserInjectionCallback)*j); + + memcpy(dlt_user.dlt_ll_ts[i].injection_table, old, sizeof(DltUserInjectionCallback) * j); free(old); } @@ -2705,14 +2549,13 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 /* Store service_id and corresponding function pointer for callback function */ dlt_user.dlt_ll_ts[i].injection_table[j].service_id = service_id; - if (priv == NULL) - { + + if (priv == NULL) { dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = (dlt_injection_callback)dlt_injection_cbk; dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = NULL; dlt_user.dlt_ll_ts[i].injection_table[j].data = NULL; } - else - { + else { dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = NULL; dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = dlt_injection_cbk; dlt_user.dlt_ll_ts[i].injection_table[j].data = priv; @@ -2724,7 +2567,9 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3 } DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t service_id, - int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)) + int (*dlt_injection_callback)(uint32_t service_id, + void *data, + uint32_t length)) { return dlt_register_injection_callback_with_id(handle, service_id, @@ -2733,9 +2578,10 @@ DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t serv } DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, - void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], - uint8_t log_level, - uint8_t trace_status)) + void (*dlt_log_level_changed_callback)( + char context_id[DLT_ID_SIZE], + uint8_t log_level, + uint8_t trace_status)) { DltContextData log; uint32_t i; @@ -2744,20 +2590,19 @@ DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, return DLT_RETURN_ERROR; /* This function doesn't make sense storing to local file is choosen; - so terminate this function */ + * so terminate this function */ if (dlt_user.dlt_is_file) return DLT_RETURN_OK; DLT_SEM_LOCK(); - if (dlt_user.dlt_ll_ts == NULL) - { + if (dlt_user.dlt_ll_ts == NULL) { DLT_SEM_FREE(); return DLT_RETURN_OK; } /* Insert callback in corresponding table */ - i=handle->log_level_pos; + i = handle->log_level_pos; /* Store new callback function */ dlt_user.dlt_ll_ts[i].log_level_changed_callback = dlt_log_level_changed_callback; @@ -2784,17 +2629,22 @@ int check_buffer(void) * Send the start of a segment chain. * Returns DLT_RETURN_ERROR on failure */ -DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len) +DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, + DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len) { DltContextData log; struct timeval tv; int ret = DLT_RETURN_ERROR; - // check null pointer - if(id == NULL) + + /* check null pointer */ + if (id == NULL) return DLT_RETURN_WRONG_PARAMETER; - if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX) - { + if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -2802,16 +2652,15 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext * if (dlt_user.dlt_ll_ts == NULL) return DLT_RETURN_ERROR; - if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON) - { + if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { /* initialize values */ if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - if (log.buffer == NULL) - { + + if (log.buffer == NULL) { log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (log.buffer == NULL) - { + + if (log.buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } @@ -2825,59 +2674,47 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext * *id = tv.tv_usec; /* Write identifier */ - if(dlt_user_log_write_string(&log, "NWST") < 0) - { + if (dlt_user_log_write_string(&log, "NWST") < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write stream handle */ - if(dlt_user_log_write_uint32(&log, *id) < 0) - { + if (dlt_user_log_write_uint32(&log, *id) < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write header */ - if(dlt_user_log_write_raw(&log, header, header_len) < 0) - { + if (dlt_user_log_write_raw(&log, header, header_len) < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write size of payload */ - if(dlt_user_log_write_uint32(&log, payload_len) < 0) - { + if (dlt_user_log_write_uint32(&log, payload_len) < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write expected segment count */ - uint16_t segment_count = payload_len/DLT_MAX_TRACE_SEGMENT_SIZE+1; + uint16_t segment_count = payload_len / DLT_MAX_TRACE_SEGMENT_SIZE + 1; /* If segments align perfectly with segment size, avoid sending empty segment */ - if((payload_len % DLT_MAX_TRACE_SEGMENT_SIZE) == 0) + if ((payload_len % DLT_MAX_TRACE_SEGMENT_SIZE) == 0) segment_count--; - if(dlt_user_log_write_uint16(&log, segment_count) < 0) - { + if (dlt_user_log_write_uint16(&log, segment_count) < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write length of one segment */ - if(dlt_user_log_write_uint16(&log, DLT_MAX_TRACE_SEGMENT_SIZE) < 0) - { + if (dlt_user_log_write_uint16(&log, DLT_MAX_TRACE_SEGMENT_SIZE) < 0) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Send log */ ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE); @@ -2889,35 +2726,39 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext * return DLT_RETURN_OK; } -DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext *handle, DltNetworkTraceType nw_trace_type, int sequence, uint16_t payload_len, void *payload) +DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, + DltContext *handle, + DltNetworkTraceType nw_trace_type, + int sequence, + uint16_t payload_len, + void *payload) { int ret = DLT_RETURN_ERROR; - if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX) - { + + if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } - while(check_buffer() < 0) - { - usleep(1000*50); // Wait 50ms + while (check_buffer() < 0) { + usleep(1000 * 50); /* Wait 50ms */ dlt_user_log_resend_buffer(); } if (dlt_user.dlt_ll_ts == NULL) return DLT_RETURN_ERROR; - if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON) - { + if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { DltContextData log; + if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; + /* initialize values */ - if (log.buffer == NULL) - { + if (log.buffer == NULL) { log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (log.buffer == NULL) - { + + if (log.buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } @@ -2928,35 +2769,29 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext log.size = 0; /* Write identifier */ - if(dlt_user_log_write_string(&log, "NWCH") < DLT_RETURN_OK) - { + if (dlt_user_log_write_string(&log, "NWCH") < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } + /* Write stream handle */ - if(dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK) - { + if (dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write segment sequence number */ - if(dlt_user_log_write_uint16(&log, sequence) < DLT_RETURN_OK) - { + if (dlt_user_log_write_uint16(&log, sequence) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write data */ - if(dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE); /* Send log */ @@ -2975,8 +2810,7 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han DltContextData log; int ret = DLT_RETURN_ERROR; - if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX) - { + if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } @@ -2984,42 +2818,37 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han if (dlt_user.dlt_ll_ts == NULL) return DLT_RETURN_ERROR; - if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON) - { + if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { /* initialize values */ if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK) return DLT_RETURN_ERROR; - /* initialize values */ - if (log.buffer == NULL) - { + /* initialize values */ + if (log.buffer == NULL) { log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (log.buffer == NULL) - { + + if (log.buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } } + log.args_num = 0; log.trace_status = nw_trace_type; log.size = 0; /* Write identifier */ - if(dlt_user_log_write_string(&log, "NWEN") < DLT_RETURN_OK) - { + if (dlt_user_log_write_string(&log, "NWEN") < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write stream handle */ - if(dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK) - { + if (dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE); /* Send log */ @@ -3036,231 +2865,239 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han void dlt_user_trace_network_segmented_thread(void *unused) { /* Unused on purpose. */ - (void) unused; + (void)unused; #ifdef linux prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0); #endif s_segmented_data *data; - while(1) - { - // Wait until message queue is initialized - dlt_lock_mutex(&mq_mutex); - if(dlt_user.dlt_segmented_queue_read_handle < 0) - { - pthread_cond_wait(&mq_init_condition, &mq_mutex); - } - dlt_unlock_mutex(&mq_mutex); + while (1) { + /* Wait until message queue is initialized */ + dlt_lock_mutex(&mq_mutex); - ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data, - sizeof(s_segmented_data * ), NULL); - if (read < 0) - { - if (errno != EINTR) - { - dlt_vlog(LOG_WARNING, "NWTSegmented: Error while reading queue: %s\n", strerror(errno)); - usleep(DLT_USER_MQ_ERROR_RETRY_INTERVAL); - } - continue; - } + if (dlt_user.dlt_segmented_queue_read_handle < 0) + pthread_cond_wait(&mq_init_condition, &mq_mutex); - if(read != sizeof(s_segmented_data *)) - { - // This case will not happen. - // When this thread is interrupted by signal, mq_receive() will not return - // partial read length and will return -1. And also no data is removed from mq. - dlt_vlog(LOG_WARNING, "NWTSegmented: Could not read data fully from queue: %d\n", read); - continue; - } + dlt_unlock_mutex(&mq_mutex); - /* Indicator just to try to flush the buffer */ - if(data->payload_len == DLT_DELAYED_RESEND_INDICATOR_PATTERN) - { - // Sleep 100ms, to allow other process to read FIFO - usleep(100*1000); - if(dlt_user_log_resend_buffer() < 0) - { - // Requeue if still not empty - if ( dlt_user_queue_resend() < 0 ) - { - //dlt_log(LOG_WARNING, "Failed to queue resending in dlt_user_trace_network_segmented_thread.\n"); - } - } - free(data); - continue; - } + ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data, + sizeof(s_segmented_data *), NULL); - dlt_user_trace_network_segmented_thread_segmenter(data); + if (read < 0) { + if (errno != EINTR) { + dlt_vlog(LOG_WARNING, "NWTSegmented: Error while reading queue: %s\n", strerror(errno)); + usleep(DLT_USER_MQ_ERROR_RETRY_INTERVAL); + } - /* Send the end message */ - DltReturnValue err = dlt_user_trace_network_segmented_end(data->id, data->handle, data->nw_trace_type); - if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR) - { - dlt_log(LOG_WARNING,"NWTSegmented: Could not send end segment.\n"); + continue; + } + + if (read != sizeof(s_segmented_data *)) { + /* This case will not happen. */ + /* When this thread is interrupted by signal, mq_receive() will not return */ + /* partial read length and will return -1. And also no data is removed from mq. */ + dlt_vlog(LOG_WARNING, "NWTSegmented: Could not read data fully from queue: %d\n", read); + continue; + } + + /* Indicator just to try to flush the buffer */ + if (data->payload_len == DLT_DELAYED_RESEND_INDICATOR_PATTERN) { + /* Sleep 100ms, to allow other process to read FIFO */ + usleep(100 * 1000); + + if (dlt_user_log_resend_buffer() < 0) { + /* Requeue if still not empty */ + if (dlt_user_queue_resend() < 0) { + /*dlt_log(LOG_WARNING, "Failed to queue resending in dlt_user_trace_network_segmented_thread.\n"); */ } + } - /* Free resources */ - free(data->header); - free(data->payload); - free(data); + free(data); + continue; } + + dlt_user_trace_network_segmented_thread_segmenter(data); + + /* Send the end message */ + DltReturnValue err = dlt_user_trace_network_segmented_end(data->id, data->handle, data->nw_trace_type); + + if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) + dlt_log(LOG_WARNING, "NWTSegmented: Could not send end segment.\n"); + + /* Free resources */ + free(data->header); + free(data->payload); + free(data); + } } void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data) { - /* Segment the data and send the chunks */ - void *ptr = NULL; - uint32_t offset = 0; - uint16_t sequence = 0; - do - { - uint16_t len = 0; - if(offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len) - { - len = data->payload_len - offset; - } - else - { - len = DLT_MAX_TRACE_SEGMENT_SIZE; - } - /* If payload size aligns perfectly with segment size, avoid sending empty segment */ - if(len == 0) - { - break; - } + /* Segment the data and send the chunks */ + void *ptr = NULL; + uint32_t offset = 0; + uint16_t sequence = 0; - ptr = data->payload + offset; - DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, data->handle, data->nw_trace_type, sequence++, len, ptr); - if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR) - { - dlt_log(LOG_ERR,"NWTSegmented: Could not send segment. Aborting.\n"); - break; // loop - } - offset += len; - }while(ptr < data->payload + data->payload_len); + do { + uint16_t len = 0; + + if (offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len) + len = data->payload_len - offset; + else + len = DLT_MAX_TRACE_SEGMENT_SIZE; + + /* If payload size aligns perfectly with segment size, avoid sending empty segment */ + if (len == 0) + break; + + ptr = data->payload + offset; + DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, + data->handle, + data->nw_trace_type, + sequence++, + len, + ptr); + + if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) { + dlt_log(LOG_ERR, "NWTSegmented: Could not send segment. Aborting.\n"); + break; /* loop */ + } + + offset += len; + } while (ptr < data->payload + data->payload_len); } -DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload) +DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload) { - /* Send as normal trace if possible */ - if(header_len+payload_len+sizeof(uint16_t) < dlt_user.log_buf_len) { - return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload); - } - - /* Allocate Memory */ - s_segmented_data *thread_data = malloc(sizeof(s_segmented_data)); - if(thread_data == NULL) - { - return DLT_RETURN_ERROR; - } - thread_data->header = malloc(header_len); - if(thread_data->header == NULL) - { - free(thread_data); - return DLT_RETURN_ERROR; - } - thread_data->payload = malloc(payload_len); - if(thread_data->payload == NULL) - { - free(thread_data->header); - free(thread_data); - return DLT_RETURN_ERROR; - } - - /* Copy data */ - thread_data->handle = handle; - thread_data->nw_trace_type = nw_trace_type; - thread_data->header_len = header_len; - memcpy(thread_data->header, header, header_len); - thread_data->payload_len = payload_len; - memcpy(thread_data->payload, payload, payload_len); - - /* Send start message */ - DltReturnValue err = dlt_user_trace_network_segmented_start(&(thread_data->id), - thread_data->handle, thread_data->nw_trace_type, - thread_data->header_len, thread_data->header, - thread_data->payload_len); - if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR) - { - dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\n"); - free(thread_data->header); - free(thread_data->payload); - free(thread_data); - return DLT_RETURN_ERROR; - } - - /* Open queue if it is not open */ - if(dlt_init_message_queue() < 0) - { - dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n"); - free(thread_data->header); - free(thread_data->payload); - free(thread_data); - - return DLT_RETURN_ERROR; - } - - /* Add to queue */ - if(mq_send(dlt_user.dlt_segmented_queue_write_handle, - (char *)&thread_data, sizeof(s_segmented_data *), 1) < 0) - { - if(errno == EAGAIN) - { - dlt_log(LOG_WARNING, "NWTSegmented: Queue full. Message discarded.\n"); - } - free(thread_data->header); - free(thread_data->payload); - free(thread_data); - dlt_vnlog(LOG_WARNING, 256,"NWTSegmented: Could not write into queue: %s \n",strerror(errno)); - return DLT_RETURN_ERROR; - } - - //thread_data will be freed by the receiver function - //coverity[leaked_storage] - return DLT_RETURN_OK; + /* Send as normal trace if possible */ + if (header_len + payload_len + sizeof(uint16_t) < dlt_user.log_buf_len) + return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload); + + /* Allocate Memory */ + s_segmented_data *thread_data = malloc(sizeof(s_segmented_data)); + + if (thread_data == NULL) + return DLT_RETURN_ERROR; + + thread_data->header = malloc(header_len); + + if (thread_data->header == NULL) { + free(thread_data); + return DLT_RETURN_ERROR; + } + + thread_data->payload = malloc(payload_len); + + if (thread_data->payload == NULL) { + free(thread_data->header); + free(thread_data); + return DLT_RETURN_ERROR; + } + + /* Copy data */ + thread_data->handle = handle; + thread_data->nw_trace_type = nw_trace_type; + thread_data->header_len = header_len; + memcpy(thread_data->header, header, header_len); + thread_data->payload_len = payload_len; + memcpy(thread_data->payload, payload, payload_len); + + /* Send start message */ + DltReturnValue err = dlt_user_trace_network_segmented_start(&(thread_data->id), + thread_data->handle, thread_data->nw_trace_type, + thread_data->header_len, thread_data->header, + thread_data->payload_len); + + if ((err == DLT_RETURN_BUFFER_FULL) || (err == DLT_RETURN_ERROR)) { + dlt_log(LOG_ERR, "NWTSegmented: Could not send start segment. Aborting.\n"); + free(thread_data->header); + free(thread_data->payload); + free(thread_data); + return DLT_RETURN_ERROR; + } + + /* Open queue if it is not open */ + if (dlt_init_message_queue() < 0) { + dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n"); + free(thread_data->header); + free(thread_data->payload); + free(thread_data); + + return DLT_RETURN_ERROR; + } + + /* Add to queue */ + if (mq_send(dlt_user.dlt_segmented_queue_write_handle, + (char *)&thread_data, sizeof(s_segmented_data *), 1) < 0) { + if (errno == EAGAIN) + dlt_log(LOG_WARNING, "NWTSegmented: Queue full. Message discarded.\n"); + + free(thread_data->header); + free(thread_data->payload); + free(thread_data); + dlt_vnlog(LOG_WARNING, 256, "NWTSegmented: Could not write into queue: %s \n", strerror(errno)); + return DLT_RETURN_ERROR; + } + + /*thread_data will be freed by the receiver function */ + /*coverity[leaked_storage] */ + return DLT_RETURN_OK; } -DltReturnValue dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload) +DltReturnValue dlt_user_trace_network(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload) { return dlt_user_trace_network_truncated(handle, nw_trace_type, header_len, header, payload_len, payload, 1); } -DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate) +DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, + DltNetworkTraceType nw_trace_type, + uint16_t header_len, + void *header, + uint16_t payload_len, + void *payload, + int allow_truncate) { int ret = DLT_RETURN_ERROR; - if(payload == NULL && payload_len > 0) + + if ((payload == NULL) && (payload_len > 0)) return DLT_RETURN_WRONG_PARAMETER; DltContextData log; - if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX) - { + if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); return DLT_RETURN_WRONG_PARAMETER; } - if (dlt_user.dlt_ll_ts==0) - { + if (dlt_user.dlt_ll_ts == 0) return DLT_RETURN_ERROR; - } - if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON) - { + if (handle->trace_status_ptr && (*(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)) { if ((dlt_user_log_init(handle, &log) < DLT_RETURN_OK) || (dlt_user.dlt_ll_ts == NULL)) return DLT_RETURN_ERROR; /* initialize values */ - if (log.buffer == NULL) - { + if (log.buffer == NULL) { log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len); - if (log.buffer == NULL) - { + + if (log.buffer == NULL) { dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n"); return DLT_RETURN_ERROR; } } + log.args_num = 0; log.trace_status = nw_trace_type; log.size = 0; @@ -3269,32 +3106,25 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr header_len = 0; /* If truncation is allowed, check if we must do it */ - if(allow_truncate > 0 && (header_len+payload_len+sizeof(uint16_t))>dlt_user.log_buf_len) - { + if ((allow_truncate > 0) && ((header_len + payload_len + sizeof(uint16_t)) > dlt_user.log_buf_len)) { /* Identify as truncated */ - if(dlt_user_log_write_string(&log, "NWTR") < DLT_RETURN_OK) - { + if (dlt_user_log_write_string(&log, "NWTR") < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write header and its length */ - if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /* Write original size of payload */ - if(dlt_user_log_write_uint32(&log, payload_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_uint32(&log, payload_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - /** * Calculate maximum available space in sending buffer after headers. */ @@ -3302,34 +3132,29 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr int truncated_payload_len = dlt_user.log_buf_len - log.size - sizeof(uint16_t) - sizeof(uint32_t); /* Write truncated payload */ - if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - } - else /* Truncation not allowed or data short enough */ - { + else { /* Truncation not allowed or data short enough */ + /* Write header and its length */ - if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - if (payload == NULL) payload_len = 0; /* Write payload and its length */ - if (dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK) - { + if (dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK) { dlt_user_free_buffer(&(log.buffer)); return DLT_RETURN_ERROR; } - } + ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE); dlt_user_free_buffer(&(log.buffer)); @@ -3346,24 +3171,17 @@ DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, cons DltReturnValue ret = DLT_RETURN_OK; DltContextData log; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if ((handle == NULL) || (text == NULL)) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) - { + if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { ret = DLT_RETURN_ERROR; - } } return ret; @@ -3374,25 +3192,18 @@ DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, DltReturnValue ret = DLT_RETURN_OK; DltContextData log; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if ((handle == NULL) || (text == NULL)) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) - { + if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); dlt_user_log_write_int(&log, data); if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { ret = DLT_RETURN_ERROR; - } } return ret; @@ -3403,25 +3214,18 @@ DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, DltReturnValue ret = DLT_RETURN_OK; DltContextData log; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if ((handle == NULL) || (text == NULL)) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) - { + if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { ret = dlt_user_log_write_string(&log, text); dlt_user_log_write_uint(&log, data); if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { ret = DLT_RETURN_ERROR; - } } return ret; @@ -3431,24 +3235,17 @@ DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int dat { DltContextData log; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if (handle == NULL) - { return DLT_RETURN_ERROR; - } - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) - { + if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { dlt_user_log_write_int(&log, data); if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } } return DLT_RETURN_OK; @@ -3458,24 +3255,17 @@ DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsign { DltContextData log; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if (handle == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) - { + if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE) { dlt_user_log_write_uint(&log, data); if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } } return DLT_RETURN_OK; @@ -3486,26 +3276,18 @@ DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *d DltContextData log; DltReturnValue ret = DLT_RETURN_OK; - if (dlt_user.verbose_mode==0) - { + if (dlt_user.verbose_mode == 0) return DLT_RETURN_ERROR; - } if (handle == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } - if (dlt_user_log_write_start(handle,&log,loglevel) > 0) - { - if ( (ret = dlt_user_log_write_raw(&log,data,length)) < DLT_RETURN_OK) - { + if (dlt_user_log_write_start(handle, &log, loglevel) > 0) { + if ((ret = dlt_user_log_write_raw(&log, data, length)) < DLT_RETURN_OK) return ret; - } + if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } } return DLT_RETURN_OK; @@ -3513,10 +3295,8 @@ DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *d DltReturnValue dlt_log_marker() { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3527,10 +3307,8 @@ DltReturnValue dlt_log_marker() DltReturnValue dlt_verbose_mode(void) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3544,10 +3322,8 @@ DltReturnValue dlt_verbose_mode(void) DltReturnValue dlt_nonverbose_mode(void) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3561,10 +3337,8 @@ DltReturnValue dlt_nonverbose_mode(void) DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3578,10 +3352,8 @@ DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header DltReturnValue dlt_with_session_id(int8_t with_session_id) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3595,10 +3367,8 @@ DltReturnValue dlt_with_session_id(int8_t with_session_id) DltReturnValue dlt_with_timestamp(int8_t with_timestamp) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3612,10 +3382,8 @@ DltReturnValue dlt_with_timestamp(int8_t with_timestamp) DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3629,10 +3397,8 @@ DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id) DltReturnValue dlt_enable_local_print(void) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3645,10 +3411,8 @@ DltReturnValue dlt_enable_local_print(void) DltReturnValue dlt_disable_local_print(void) { - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3664,14 +3428,12 @@ void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) #ifdef linux prctl(PR_SET_NAME, "dlt_receiver", 0, 0, 0); #endif - while (1) - { + + while (1) { /* Check for new messages from DLT daemon */ if (dlt_user_log_check_user_message() < DLT_RETURN_OK) - { /* Critical error */ - dlt_log(LOG_CRIT,"Receiver thread encountered error condition\n"); - } + dlt_log(LOG_CRIT, "Receiver thread encountered error condition\n"); usleep(DLT_USER_RECEIVE_DELAY); /* delay */ } @@ -3681,13 +3443,11 @@ void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log) { - if (handle == NULL || log == NULL) + if ((handle == NULL) || (log == NULL)) return DLT_RETURN_WRONG_PARAMETER; - if (!dlt_user_initialised) - { - if (dlt_init() < DLT_RETURN_OK) - { + if (!dlt_user_initialised) { + if (dlt_init() < DLT_RETURN_OK) { dlt_vlog(LOG_ERR, "%s Failed to initialise dlt", __FUNCTION__); return DLT_RETURN_ERROR; } @@ -3703,11 +3463,10 @@ DltReturnValue dlt_user_queue_resend(void) { static unsigned char dlt_user_queue_resend_error_counter = 0; - if(dlt_user.dlt_log_handle < 0) - { - // Fail silenty. FIFO is not open yet + if (dlt_user.dlt_log_handle < 0) + /* Fail silenty. FIFO is not open yet */ return DLT_RETURN_ERROR; - } + /** * Ask segmented thread to try emptying the buffer soon. * This will be freed in dlt_user_trace_network_segmented_thread @@ -3715,34 +3474,26 @@ DltReturnValue dlt_user_queue_resend(void) s_segmented_data *resend_data = malloc(sizeof(s_segmented_data)); if (resend_data == NULL) - { return DLT_RETURN_ERROR; - } resend_data->payload_len = DLT_DELAYED_RESEND_INDICATOR_PATTERN; - - /* Open queue if it is not open */ - if(dlt_init_message_queue() < DLT_RETURN_OK) - { - if(!dlt_user_queue_resend_error_counter) - { - // log error only when problem occurred first time + if (dlt_init_message_queue() < DLT_RETURN_OK) { + if (!dlt_user_queue_resend_error_counter) + /* log error only when problem occurred first time */ dlt_log(LOG_WARNING, "NWTSegmented: Could not open queue.\n"); - } + dlt_user_queue_resend_error_counter = 1; free(resend_data); return DLT_RETURN_ERROR; } - if(mq_send(dlt_user.dlt_segmented_queue_write_handle, (char *)&resend_data, sizeof(s_segmented_data *), 1) < 0) - { - if(!dlt_user_queue_resend_error_counter) - { - // log error only when problem occurred first time - dlt_vnlog(LOG_DEBUG, 256,"Could not request resending.: %s \n",strerror(errno)); - } + if (mq_send(dlt_user.dlt_segmented_queue_write_handle, (char *)&resend_data, sizeof(s_segmented_data *), 1) < 0) { + if (!dlt_user_queue_resend_error_counter) + /* log error only when problem occurred first time */ + dlt_vnlog(LOG_DEBUG, 256, "Could not request resending.: %s \n", strerror(errno)); + dlt_user_queue_resend_error_counter = 1; free(resend_data); return DLT_RETURN_ERROR; @@ -3750,8 +3501,8 @@ DltReturnValue dlt_user_queue_resend(void) dlt_user_queue_resend_error_counter = 0; - //thread_data will be freed by the receiver function - //coverity[leaked_storage] + /*thread_data will be freed by the receiver function */ + /*coverity[leaked_storage] */ return DLT_RETURN_OK; } @@ -3763,114 +3514,100 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype) DltReturnValue ret = DLT_RETURN_OK; - if (!dlt_user_initialised) - { + if (!dlt_user_initialised) { dlt_vlog(LOG_ERR, "%s dlt_user_initialised false\n", __FUNCTION__); return DLT_RETURN_ERROR; } - if (log == NULL || - log->handle == NULL || - log->handle->contextID[0] == '\0' || + if ((log == NULL) || + (log->handle == NULL) || + (log->handle->contextID[0] == '\0') || (mtype < DLT_TYPE_LOG) || (mtype > DLT_TYPE_CONTROL) ) - { return DLT_RETURN_WRONG_PARAMETER; - } /* also for Trace messages */ #ifdef DLT_SHM_ENABLE + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_SHM) < DLT_RETURN_OK) #else + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG) < DLT_RETURN_OK) #endif - { + return DLT_RETURN_ERROR; - } if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) - { return DLT_RETURN_ERROR; - } - msg.storageheader = (DltStorageHeader*)msg.headerbuffer; + msg.storageheader = (DltStorageHeader *)msg.headerbuffer; - if (dlt_set_storageheader(msg.storageheader,dlt_user.ecuID) == DLT_RETURN_ERROR) - { + if (dlt_set_storageheader(msg.storageheader, dlt_user.ecuID) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } - msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); - msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1 ; + msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1; /* send ecu id */ - if(dlt_user.with_ecu_id) - { + if (dlt_user.with_ecu_id) msg.standardheader->htyp |= DLT_HTYP_WEID; - } /* send timestamp */ - if(dlt_user.with_timestamp) - { + if (dlt_user.with_timestamp) msg.standardheader->htyp |= DLT_HTYP_WTMS; - } /* send session id */ - if(dlt_user.with_session_id) - { + if (dlt_user.with_session_id) { msg.standardheader->htyp |= DLT_HTYP_WSID; msg.headerextra.seid = getpid(); } if (dlt_user.verbose_mode) - { /* In verbose mode, send extended header */ - msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH ); - } + msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH); else - { /* In non-verbose, send extended header if desired */ - if(dlt_user.use_extende_header_for_non_verbose) - msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH ); - } + if (dlt_user.use_extende_header_for_non_verbose) + msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH); + -#if (BYTE_ORDER==BIG_ENDIAN) +#if (BYTE_ORDER == BIG_ENDIAN) msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF); #endif msg.standardheader->mcnt = log->handle->mcnt++; /* Set header extra parameters */ - dlt_set_id(msg.headerextra.ecu,dlt_user.ecuID); - //msg.headerextra.seid = 0; + dlt_set_id(msg.headerextra.ecu, dlt_user.ecuID); + /*msg.headerextra.seid = 0; */ msg.headerextra.tmsp = dlt_uptime(); if (dlt_message_set_extraparameters(&msg, 0) == DLT_RETURN_ERROR) - { return DLT_RETURN_ERROR; - } /* Fill out extended header, if extended header should be provided */ - if (DLT_IS_HTYP_UEH(msg.standardheader->htyp)) - { + if (DLT_IS_HTYP_UEH(msg.standardheader->htyp)) { /* with extended header */ - msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) ); + msg.extendedheader = + (DltExtendedHeader *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); - switch (mtype) - { + switch (mtype) { case DLT_TYPE_LOG: { - msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) ; /* messsage info */ + msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | + ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN); /* messsage info */ break; } case DLT_TYPE_NW_TRACE: { - msg.extendedheader->msin = (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT) | ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) ; /* messsage info */ + msg.extendedheader->msin = (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT) | + ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN); /* messsage info */ break; } default: { - /* This case should not occur */ + /* This case should not occur */ return DLT_RETURN_ERROR; break; } @@ -3878,26 +3615,25 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype) /* If in verbose mode, set flag in header for verbose mode */ if (dlt_user.verbose_mode) - { msg.extendedheader->msin |= DLT_MSIN_VERB; - } msg.extendedheader->noar = log->args_num; /* number of arguments */ - dlt_set_id(msg.extendedheader->apid,dlt_user.appID); /* application id */ - dlt_set_id(msg.extendedheader->ctid,log->handle->contextID); /* context id */ + dlt_set_id(msg.extendedheader->apid, dlt_user.appID); /* application id */ + dlt_set_id(msg.extendedheader->ctid, log->handle->contextID); /* context id */ - msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); } - else - { + else { /* without extended header */ - msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); + msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE( + msg.standardheader->htyp); } - len=msg.headersize - sizeof(DltStorageHeader) +log->size; - if (len>UINT16_MAX) - { - dlt_log(LOG_WARNING,"Huge message discarded!\n"); + len = msg.headersize - sizeof(DltStorageHeader) + log->size; + + if (len > UINT16_MAX) { + dlt_log(LOG_WARNING, "Huge message discarded!\n"); return DLT_RETURN_ERROR; } @@ -3905,132 +3641,123 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype) /* print to std out, if enabled */ if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && - (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) - { - if ((dlt_user.enable_local_print) || (dlt_user.local_print_mode == DLT_PM_FORCE_ON)) - { + (dlt_user.local_print_mode != DLT_PM_AUTOMATIC)) { + if ((dlt_user.enable_local_print) || (dlt_user.local_print_mode == DLT_PM_FORCE_ON)) { if (dlt_user_print_msg(&msg, log) == DLT_RETURN_ERROR) - { return DLT_RETURN_ERROR; - } } } - if (dlt_user.dlt_is_file) - { + if (dlt_user.dlt_is_file) { /* log to file */ - ret=dlt_user_log_out2(dlt_user.dlt_log_handle, msg.headerbuffer, msg.headersize, log->buffer, log->size); + ret = dlt_user_log_out2(dlt_user.dlt_log_handle, msg.headerbuffer, msg.headersize, log->buffer, log->size); return ret; } - else - { + else { /* Reattach to daemon if neccesary */ dlt_user_log_reattach_to_daemon(); - if (dlt_user.overflow_counter) - { - if (dlt_user_log_send_overflow() == DLT_RETURN_OK) - { + if (dlt_user.overflow_counter) { + if (dlt_user_log_send_overflow() == DLT_RETURN_OK) { dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "%u messages discarded!\n", dlt_user.overflow_counter); dlt_user.overflow_counter = 0; } } - /* try to resent old data first */ - ret = DLT_RETURN_OK; - if((dlt_user.dlt_log_handle!=-1) && (dlt_user.appID[0]!='\0')) - { - ret = dlt_user_log_resend_buffer(); - } - if((ret == DLT_RETURN_OK) && (dlt_user.appID[0] != '\0')) - { - /* resend ok or nothing to resent */ + /* try to resent old data first */ + ret = DLT_RETURN_OK; + + if ((dlt_user.dlt_log_handle != -1) && (dlt_user.appID[0] != '\0')) + ret = dlt_user_log_resend_buffer(); + + if ((ret == DLT_RETURN_OK) && (dlt_user.appID[0] != '\0')) { + /* resend ok or nothing to resent */ #ifdef DLT_SHM_ENABLE - if(dlt_user.dlt_log_handle!=-1) - dlt_shm_push(&dlt_user.dlt_shm,msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), - log->buffer, log->size, 0, 0); + + if (dlt_user.dlt_log_handle != -1) + dlt_shm_push(&dlt_user.dlt_shm, msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), + log->buffer, log->size, 0, 0); ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), 0, 0, 0, 0); #else -#ifdef DLT_TEST_ENABLE - if(dlt_user.corrupt_user_header) { - userheader.pattern[0]=0xff; - userheader.pattern[1]=0xff; - userheader.pattern[2]=0xff; - userheader.pattern[3]=0xff; +# ifdef DLT_TEST_ENABLE + + if (dlt_user.corrupt_user_header) { + userheader.pattern[0] = 0xff; + userheader.pattern[1] = 0xff; + userheader.pattern[2] = 0xff; + userheader.pattern[3] = 0xff; } - if(dlt_user.corrupt_message_size) { + + if (dlt_user.corrupt_message_size) msg.standardheader->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size); - } -#endif + +# endif ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), - msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), log->buffer, log->size); #endif } /* store message in ringbuffer, if an error has occured */ - if ((ret!=DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) - { + if ((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) ret = dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), - msg.headerbuffer+sizeof(DltStorageHeader), - msg.headersize-sizeof(DltStorageHeader), + msg.headerbuffer + sizeof(DltStorageHeader), + msg.headersize - sizeof(DltStorageHeader), log->buffer, log->size); - } - switch (ret) + switch (ret) { + case DLT_RETURN_BUFFER_FULL: { - case DLT_RETURN_BUFFER_FULL: - { - /* Buffer full */ - dlt_user.overflow_counter += 1; - return DLT_RETURN_BUFFER_FULL; - } - case DLT_RETURN_PIPE_FULL: - { - /* data could not be written */ - return DLT_RETURN_PIPE_FULL; - } - case DLT_RETURN_PIPE_ERROR: - { - /* handle not open or pipe error */ - close(dlt_user.dlt_log_handle); - dlt_user.dlt_log_handle = -1; - dlt_user.connection_state = DLT_USER_RETRY_CONNECT; + /* Buffer full */ + dlt_user.overflow_counter += 1; + return DLT_RETURN_BUFFER_FULL; + } + case DLT_RETURN_PIPE_FULL: + { + /* data could not be written */ + return DLT_RETURN_PIPE_FULL; + } + case DLT_RETURN_PIPE_ERROR: + { + /* handle not open or pipe error */ + close(dlt_user.dlt_log_handle); + dlt_user.dlt_log_handle = -1; + dlt_user.connection_state = DLT_USER_RETRY_CONNECT; #ifdef DLT_SHM_ENABLE - /* free shared memory */ - dlt_shm_free_client(&dlt_user.dlt_shm); + /* free shared memory */ + dlt_shm_free_client(&dlt_user.dlt_shm); #endif - if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC) - { - dlt_user_print_msg(&msg, log); - } + if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC) + dlt_user_print_msg(&msg, log); - return DLT_RETURN_PIPE_ERROR; - } - case DLT_RETURN_ERROR: - { - /* other error condition */ - return DLT_RETURN_ERROR; - } - case DLT_RETURN_OK: - { - return DLT_RETURN_OK; - } - default: - { - /* This case should never occur. */ - return DLT_RETURN_ERROR; - } + return DLT_RETURN_PIPE_ERROR; + } + case DLT_RETURN_ERROR: + { + /* other error condition */ + return DLT_RETURN_ERROR; + } + case DLT_RETURN_OK: + { + return DLT_RETURN_OK; + } + default: + { + /* This case should never occur. */ + return DLT_RETURN_ERROR; + } } } @@ -4044,50 +3771,38 @@ DltReturnValue dlt_user_log_send_register_application(void) DltReturnValue ret; - if (dlt_user.appID[0]=='\0') - { + if (dlt_user.appID[0] == '\0') return DLT_RETURN_ERROR; - } /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_REGISTER_APPLICATION) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set usercontext */ - dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ usercontext.pid = getpid(); if (dlt_user.application_description != NULL) - { usercontext.description_length = strlen(dlt_user.application_description); - } else - { usercontext.description_length = 0; - } if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } ret = dlt_user_log_out3(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(usercontext), sizeof(DltUserControlMsgRegisterApplication), - dlt_user.application_description, usercontext.description_length); + &(userheader), sizeof(DltUserHeader), + &(usercontext), sizeof(DltUserControlMsgRegisterApplication), + dlt_user.application_description, usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterApplication), dlt_user.application_description, usercontext.description_length); - } return DLT_RETURN_OK; } @@ -4098,25 +3813,19 @@ DltReturnValue dlt_user_log_send_unregister_application(void) DltUserControlMsgUnregisterApplication usercontext; DltReturnValue ret = DLT_RETURN_OK; - if (dlt_user.appID[0]=='\0') - { + if (dlt_user.appID[0] == '\0') return DLT_RETURN_ERROR; - } /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_UNREGISTER_APPLICATION) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set usercontext */ - dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ usercontext.pid = getpid(); if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } ret = dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), @@ -4124,14 +3833,12 @@ DltReturnValue dlt_user_log_send_unregister_application(void) /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterApplication), NULL, 0); - } return DLT_RETURN_OK; } @@ -4143,29 +3850,21 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log) DltReturnValue ret = DLT_RETURN_ERROR; if (log == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } if (log->handle == NULL) - { return DLT_RETURN_ERROR; - } if (log->handle->contextID[0] == '\0') - { return DLT_RETURN_ERROR; - } /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_REGISTER_CONTEXT) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set usercontext */ - dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */ - dlt_set_id(usercontext.ctid,log->handle->contextID); /* context id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ usercontext.log_level_pos = log->handle->log_level_pos; usercontext.pid = getpid(); @@ -4173,35 +3872,31 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log) usercontext.trace_status = (int8_t)log->trace_status; if (log->context_description != NULL) - { usercontext.description_length = strlen(log->context_description); - } else - { usercontext.description_length = 0; - } if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } - - if (dlt_user.appID[0]!='\0') - { - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length); - } + if (dlt_user.appID[0] != '\0') + ret = + dlt_user_log_out3(dlt_user.dlt_log_handle, + &(userheader), + sizeof(DltUserHeader), + &(usercontext), + sizeof(DltUserControlMsgRegisterContext), + log->context_description, + usercontext.description_length); /* store message in ringbuffer, if an error has occured */ if ((ret != DLT_RETURN_OK) || (dlt_user.appID[0] == '\0')) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext), log->context_description, usercontext.description_length); - } return DLT_RETURN_OK; @@ -4214,35 +3909,25 @@ DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log) DltReturnValue ret; if (log == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } if (log->handle == NULL) - { return DLT_RETURN_WRONG_PARAMETER; - } if (log->handle->contextID[0] == '\0') - { - return DLT_RETURN_ERROR; - } + return DLT_RETURN_ERROR; /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_UNREGISTER_CONTEXT) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set usercontext */ - dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */ - dlt_set_id(usercontext.ctid,log->handle->contextID); /* context id */ + dlt_set_id(usercontext.apid, dlt_user.appID); /* application id */ + dlt_set_id(usercontext.ctid, log->handle->contextID); /* context id */ usercontext.pid = getpid(); if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } ret = dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), @@ -4252,14 +3937,12 @@ DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log) /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterContext), NULL, 0); - } return DLT_RETURN_OK; } @@ -4270,52 +3953,44 @@ DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType logle DltUserControlMsgAppLogLevelTraceStatus usercontext; DltReturnValue ret; - if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX) - { + if ((loglevel < DLT_USER_LOG_LEVEL_NOT_SET) || (loglevel >= DLT_LOG_MAX)) { dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel); return DLT_RETURN_ERROR; } - if (tracestatus < DLT_USER_TRACE_STATUS_NOT_SET || tracestatus >= DLT_TRACE_STATUS_MAX) - { + if ((tracestatus < DLT_USER_TRACE_STATUS_NOT_SET) || (tracestatus >= DLT_TRACE_STATUS_MAX)) { dlt_vlog(LOG_ERR, "Tracestatus %d is outside valid range", tracestatus); return DLT_RETURN_ERROR; } - if ((appid == NULL) || (appid[0]=='\0')) - { + if ((appid == NULL) || (appid[0] == '\0')) return DLT_RETURN_ERROR; - } /* Removed because of DltLogLevelType and DltTraceStatusType - - if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE)) - { - return DLT_RETURN_ERROR; - } - - if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON)) - { - return DLT_RETURN_ERROR; - } - - */ + * + * if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE)) + * { + * return DLT_RETURN_ERROR; + * } + * + * if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON)) + * { + * return DLT_RETURN_ERROR; + * } + * + */ /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_APP_LL_TS) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set usercontext */ - dlt_set_id(usercontext.apid,appid); /* application id */ + dlt_set_id(usercontext.apid, appid); /* application id */ usercontext.log_level = loglevel; usercontext.trace_status = tracestatus; if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } ret = dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), @@ -4323,14 +3998,12 @@ DltReturnValue dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType logle /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus), NULL, 0); - } return DLT_RETURN_OK; } @@ -4341,40 +4014,33 @@ DltReturnValue dlt_user_log_send_log_mode(DltUserLogMode mode) DltUserControlMsgLogMode logmode; DltReturnValue ret; - if (mode < DLT_USER_MODE_UNDEFINED || mode >= DLT_USER_MODE_MAX) - { + if ((mode < DLT_USER_MODE_UNDEFINED) || (mode >= DLT_USER_MODE_MAX)) { dlt_vlog(LOG_ERR, "User log mode %d is outside valid range", mode); return DLT_RETURN_WRONG_PARAMETER; } /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_MODE) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } /* set data */ - logmode.log_mode = (unsigned char) mode; + logmode.log_mode = (unsigned char)mode; if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(logmode), sizeof(DltUserControlMsgLogMode)); + &(userheader), sizeof(DltUserHeader), + &(logmode), sizeof(DltUserControlMsgLogMode)); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), &(logmode), sizeof(DltUserControlMsgLogMode), NULL, 0); - } return DLT_RETURN_OK; } @@ -4386,29 +4052,23 @@ DltReturnValue dlt_user_log_send_marker() /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_MARKER) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } /* log to FIFO */ ret = dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), 0, 0); + &(userheader), sizeof(DltUserHeader), 0, 0); /* store message in ringbuffer, if an error has occured */ if (ret < DLT_RETURN_OK) - { return dlt_user_log_out_error_handling(&(userheader), sizeof(DltUserHeader), NULL, 0, NULL, 0); - } return DLT_RETURN_OK; } @@ -4421,9 +4081,7 @@ DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) static char text[DLT_USER_TEXT_LENGTH]; if ((msg == NULL) || (log == NULL)) - { return DLT_RETURN_WRONG_PARAMETER; - } /* Save variables before print */ databuffer_tmp = msg->databuffer; @@ -4439,15 +4097,13 @@ DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) msg->databuffersize = log->size; /* Print message as ASCII */ - if (dlt_message_print_ascii(msg,text,DLT_USER_TEXT_LENGTH, 0) == DLT_RETURN_ERROR) - { + if (dlt_message_print_ascii(msg, text, DLT_USER_TEXT_LENGTH, 0) == DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } /* Restore variables and set len to BE*/ msg->databuffer = databuffer_tmp; msg->databuffersize = databuffersize_tmp; - msg->datasize = datasize_tmp; + msg->datasize = datasize_tmp; msg->standardheader->len = DLT_HTOBE_16(msg->standardheader->len); @@ -4456,8 +4112,8 @@ DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log) DltReturnValue dlt_user_log_check_user_message(void) { - int offset=0; - int leave_while=0; + int offset = 0; + int leave_while = 0; uint32_t i; int fd; @@ -4471,10 +4127,10 @@ DltReturnValue dlt_user_log_check_user_message(void) unsigned char *userbuffer; /* For delayed calling of injection callback, to avoid deadlock */ - DltUserInjectionCallback delayed_injection_callback; + DltUserInjectionCallback delayed_injection_callback; DltUserLogLevelChangedCallback delayed_log_level_changed_callback; - unsigned char *delayed_inject_buffer = 0; - uint32_t delayed_inject_data_length = 0; + unsigned char *delayed_inject_buffer = 0; + uint32_t delayed_inject_data_length = 0; /* Ensure that callback is null before searching for it */ delayed_injection_callback.injection_callback = 0; @@ -4487,86 +4143,76 @@ DltReturnValue dlt_user_log_check_user_message(void) fd = dlt_user.dlt_user_handle; #endif - if (fd != DLT_FD_INIT) - { - while (1) - { - if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD)<=0) - { + if (fd != DLT_FD_INIT) { + while (1) { + if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD) <= 0) /* No new message available */ return DLT_RETURN_OK; - } /* look through buffer as long as data is in there */ - while (1) - { + while (1) { if (receiver->bytesRcvd < (int32_t)sizeof(DltUserHeader)) - { break; - } /* resync if necessary */ - offset=0; - do - { - userheader = (DltUserHeader*) (receiver->buf+offset); + offset = 0; + + do { + userheader = (DltUserHeader *)(receiver->buf + offset); /* Check for user header pattern */ if (dlt_user_check_userheader(userheader)) - { break; - } + offset++; - } - while ((int32_t)(sizeof(DltUserHeader)+offset)<=receiver->bytesRcvd); + } while ((int32_t)(sizeof(DltUserHeader) + offset) <= receiver->bytesRcvd); /* Check for user header pattern */ - if (dlt_user_check_userheader(userheader)<0 || - dlt_user_check_userheader(userheader)==0) - { + if ((dlt_user_check_userheader(userheader) < 0) || + (dlt_user_check_userheader(userheader) == 0)) break; - } /* Set new start offset */ - if (offset>0) - { - receiver->buf+=offset; - receiver->bytesRcvd-=offset; + if (offset > 0) { + receiver->buf += offset; + receiver->bytesRcvd -= offset; } - switch (userheader->message) - { + switch (userheader->message) { case DLT_USER_MESSAGE_LOG_LEVEL: { - if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogLevel))) - { - leave_while=1; + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel))) { + leave_while = 1; break; } - usercontextll = (DltUserControlMsgLogLevel*) (receiver->buf+sizeof(DltUserHeader)); + usercontextll = (DltUserControlMsgLogLevel *)(receiver->buf + sizeof(DltUserHeader)); /* Update log level and trace status */ - if (usercontextll != NULL) - { + if (usercontextll != NULL) { DLT_SEM_LOCK(); if ((usercontextll->log_level_pos >= 0) && - (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries)) - { - // printf("Store ll, ts\n"); - if (dlt_user.dlt_ll_ts) - { + (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries)) { + /* printf("Store ll, ts\n"); */ + if (dlt_user.dlt_ll_ts) { dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = usercontextll->log_level; - dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = usercontextll->trace_status; - if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) - *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = usercontextll->log_level; - if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) - *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = usercontextll->trace_status; - - delayed_log_level_changed_callback.log_level_changed_callback = dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_changed_callback; - memcpy(delayed_log_level_changed_callback.contextID,dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID,DLT_ID_SIZE); + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = + usercontextll->trace_status; + + if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) + *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = + usercontextll->log_level; + + if (dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) + *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = + usercontextll->trace_status; + + delayed_log_level_changed_callback.log_level_changed_callback = + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_changed_callback; + memcpy(delayed_log_level_changed_callback.contextID, + dlt_user.dlt_ll_ts[usercontextll->log_level_pos].contextID, DLT_ID_SIZE); delayed_log_level_changed_callback.log_level = usercontextll->log_level; delayed_log_level_changed_callback.trace_status = usercontextll->trace_status; } @@ -4576,89 +4222,87 @@ DltReturnValue dlt_user_log_check_user_message(void) } /* call callback outside of semaphore */ - if(delayed_log_level_changed_callback.log_level_changed_callback!=0) - { - delayed_log_level_changed_callback.log_level_changed_callback(delayed_log_level_changed_callback.contextID, - delayed_log_level_changed_callback.log_level, - delayed_log_level_changed_callback.trace_status); - } + if (delayed_log_level_changed_callback.log_level_changed_callback != 0) + delayed_log_level_changed_callback.log_level_changed_callback( + delayed_log_level_changed_callback.contextID, + delayed_log_level_changed_callback.log_level, + delayed_log_level_changed_callback.trace_status); /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver,sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogLevel)) == DLT_RETURN_ERROR) - { + if (dlt_receiver_remove(receiver, + sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogLevel)) == + DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } } - break; + break; case DLT_USER_MESSAGE_INJECTION: { /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection))) - { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection))) { leave_while = 1; break; } - usercontextinj = (DltUserControlMsgInjection*) (receiver->buf+sizeof(DltUserHeader)); - userbuffer = (unsigned char*) (receiver->buf+sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection)); + usercontextinj = (DltUserControlMsgInjection *)(receiver->buf + sizeof(DltUserHeader)); + userbuffer = + (unsigned char *)(receiver->buf + sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection)); - if (userbuffer != NULL) - { + if (userbuffer != NULL) { - if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection)+usercontextinj->data_length_inject)) - { + if (receiver->bytesRcvd < + (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + + usercontextinj->data_length_inject)) { leave_while = 1; break; } DLT_SEM_LOCK(); - if ((usercontextinj->data_length_inject > 0) && (dlt_user.dlt_ll_ts)) - { + if ((usercontextinj->data_length_inject > 0) && (dlt_user.dlt_ll_ts)) { /* Check if injection callback is registered for this context */ for (i = 0; i < dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].nrcallbacks; i++) - { if ((dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table) && - (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].service_id == usercontextinj->service_id)) - { + (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].service_id == + usercontextinj->service_id)) { /* Prepare delayed injection callback call */ - if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback != NULL) - { + if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. + injection_callback != NULL) { delayed_injection_callback.injection_callback = - dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback; + dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. + injection_callback; } - else if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback_with_id != NULL) + else if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. + injection_callback_with_id != NULL) { delayed_injection_callback.injection_callback_with_id = - dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback_with_id; + dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i]. + injection_callback_with_id; delayed_injection_callback.data = dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].data; } + delayed_injection_callback.service_id = usercontextinj->service_id; delayed_inject_data_length = usercontextinj->data_length_inject; delayed_inject_buffer = malloc(delayed_inject_data_length); - if (delayed_inject_buffer != NULL) - { + if (delayed_inject_buffer != NULL) { memcpy(delayed_inject_buffer, userbuffer, delayed_inject_data_length); } - else - { + else { DLT_SEM_FREE(); - dlt_log(LOG_WARNING,"malloc failed!\n"); + dlt_log(LOG_WARNING, "malloc failed!\n"); return DLT_RETURN_ERROR; } + break; } - } } DLT_SEM_FREE(); /* Delayed injection callback call */ if ((delayed_inject_buffer != NULL) && - (delayed_injection_callback.injection_callback != NULL)) - { + (delayed_injection_callback.injection_callback != NULL)) { delayed_injection_callback.injection_callback(delayed_injection_callback.service_id, delayed_inject_buffer, delayed_inject_data_length); @@ -4673,6 +4317,7 @@ DltReturnValue dlt_user_log_check_user_message(void) delayed_injection_callback.data); delayed_injection_callback.injection_callback_with_id = NULL; } + free(delayed_inject_buffer); delayed_inject_buffer = NULL; @@ -4681,54 +4326,48 @@ DltReturnValue dlt_user_log_check_user_message(void) (sizeof(DltUserHeader) + sizeof(DltUserControlMsgInjection) + usercontextinj->data_length_inject)) != DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } } } break; case DLT_USER_MESSAGE_LOG_STATE: { /* At least, user header, user context, and service id and data_length of injected message is available */ - if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogState))) - { + if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) { leave_while = 1; break; } - userlogstate = (DltUserControlMsgLogState*) (receiver->buf+sizeof(DltUserHeader)); + userlogstate = (DltUserControlMsgLogState *)(receiver->buf + sizeof(DltUserHeader)); dlt_user.log_state = userlogstate->log_state; /* keep not read data in buffer */ - if (dlt_receiver_remove(receiver,(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogState))) == DLT_RETURN_ERROR) - { + if (dlt_receiver_remove(receiver, + (sizeof(DltUserHeader) + sizeof(DltUserControlMsgLogState))) == + DLT_RETURN_ERROR) return DLT_RETURN_ERROR; - } } - break; + break; default: { - dlt_log(LOG_WARNING,"Invalid user message type received!\n"); + dlt_log(LOG_WARNING, "Invalid user message type received!\n"); /* Ignore result */ - dlt_receiver_remove(receiver,sizeof(DltUserHeader)); + dlt_receiver_remove(receiver, sizeof(DltUserHeader)); /* In next invocation of while loop, a resync will be triggered if additional data was received */ } break; } /* switch() */ - if (leave_while==1) - { - leave_while=0; + if (leave_while == 1) { + leave_while = 0; break; } - } /* while buffer*/ if (dlt_receiver_move_to_begin(receiver) == DLT_RETURN_ERROR) - { return DLT_RETURN_ERROR; - } } /* while receive */ + } /* if */ return DLT_RETURN_OK; @@ -4736,13 +4375,13 @@ DltReturnValue dlt_user_log_check_user_message(void) DltReturnValue dlt_user_log_resend_buffer(void) { - int num,count; + int num, count; int size; DltReturnValue ret; DLT_SEM_LOCK(); - if (dlt_user.appID[0]=='\0') - { + + if (dlt_user.appID[0] == '\0') { DLT_SEM_FREE(); return 0; } @@ -4751,72 +4390,77 @@ DltReturnValue dlt_user_log_resend_buffer(void) count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer)); DLT_SEM_FREE(); - for (num=0;num<count;num++) - { + for (num = 0; num < count; num++) { DLT_SEM_LOCK(); - size = dlt_buffer_copy(&(dlt_user.startup_buffer),dlt_user.resend_buffer,dlt_user.log_buf_len); - - if (size>0) - { - DltUserHeader *userheader = (DltUserHeader*) (dlt_user.resend_buffer); - /* Add application id to the messages of needed*/ - if (dlt_user_check_userheader(userheader)) - { - switch (userheader->message) + size = dlt_buffer_copy(&(dlt_user.startup_buffer), dlt_user.resend_buffer, dlt_user.log_buf_len); + + if (size > 0) { + DltUserHeader *userheader = (DltUserHeader *)(dlt_user.resend_buffer); + + /* Add application id to the messages of needed*/ + if (dlt_user_check_userheader(userheader)) { + switch (userheader->message) { + case DLT_USER_MESSAGE_REGISTER_CONTEXT: { - case DLT_USER_MESSAGE_REGISTER_CONTEXT: - { - DltUserControlMsgRegisterContext *usercontext = (DltUserControlMsgRegisterContext*) (dlt_user.resend_buffer+sizeof(DltUserHeader)); - if ((usercontext != 0) && (usercontext->apid[0]=='\0')) - { - dlt_set_id(usercontext->apid,dlt_user.appID); - } - break; - } - case DLT_USER_MESSAGE_LOG: - { - DltExtendedHeader * extendedHeader = (DltExtendedHeader *)(dlt_user.resend_buffer+sizeof(DltUserHeader)+ - sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)); - if ((extendedHeader) != 0 && (extendedHeader->apid[0]=='\0')) - { // if application id is empty, add it - dlt_set_id(extendedHeader->apid,dlt_user.appID); - } - break; - } - default: - { - break; - } + DltUserControlMsgRegisterContext *usercontext = + (DltUserControlMsgRegisterContext *)(dlt_user.resend_buffer + sizeof(DltUserHeader)); + + if ((usercontext != 0) && (usercontext->apid[0] == '\0')) + dlt_set_id(usercontext->apid, dlt_user.appID); + + break; + } + case DLT_USER_MESSAGE_LOG: + { + DltExtendedHeader *extendedHeader = + (DltExtendedHeader *)(dlt_user.resend_buffer + sizeof(DltUserHeader) + + sizeof(DltStandardHeader) + + sizeof(DltStandardHeaderExtra)); + + if (((extendedHeader) != 0) && (extendedHeader->apid[0] == '\0')) /* if application id is empty, add it */ + dlt_set_id(extendedHeader->apid, dlt_user.appID); + + break; + } + default: + { + break; + } } } #ifdef DLT_SHM_ENABLE - dlt_shm_push(&dlt_user.dlt_shm, dlt_user.resend_buffer+sizeof(DltUserHeader), size-sizeof(DltUserHeader), 0, 0, 0, 0); - - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,sizeof(DltUserHeader), 0, 0, 0, 0); + dlt_shm_push(&dlt_user.dlt_shm, + dlt_user.resend_buffer + sizeof(DltUserHeader), + size - sizeof(DltUserHeader), + 0, + 0, + 0, + 0); + + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, sizeof(DltUserHeader), 0, 0, 0, 0); #else - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,size, 0, 0, 0, 0); + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer, size, 0, 0, 0, 0); #endif /* in case of error, keep message in ringbuffer */ - if (ret == DLT_RETURN_OK) - { + if (ret == DLT_RETURN_OK) { dlt_buffer_remove(&(dlt_user.startup_buffer)); } - else - { - if (ret == DLT_RETURN_PIPE_ERROR) - { + else { + if (ret == DLT_RETURN_PIPE_ERROR) { /* handle not open or pipe error */ close(dlt_user.dlt_log_handle); dlt_user.dlt_log_handle = -1; } + /* keep message in ringbuffer */ DLT_SEM_FREE(); return ret; } } + DLT_SEM_FREE(); } @@ -4829,92 +4473,81 @@ void dlt_user_log_reattach_to_daemon(void) DltContext handle; DltContextData log_new; - if (dlt_user.dlt_log_handle<0) - { - dlt_user.dlt_log_handle=-1; + if (dlt_user.dlt_log_handle < 0) { + dlt_user.dlt_log_handle = -1; #ifdef DLT_USE_UNIX_SOCKET_IPC /* try to open connection to dlt daemon */ dlt_initialize_socket_connection(); + if (dlt_user.connection_state != DLT_USER_CONNECTED) - { /* return if not connected */ return; - } #else /* try to open pipe to dlt daemon */ int fd = open(dlt_daemon_fifo, O_WRONLY | O_NONBLOCK); if (fd < 0) - { return; - } dlt_user.dlt_log_handle = fd; #endif - if (dlt_user_log_init(&handle,&log_new) < DLT_RETURN_OK) - { + + if (dlt_user_log_init(&handle, &log_new) < DLT_RETURN_OK) return; - } #ifdef DLT_SHM_ENABLE + /* init shared memory */ - if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0) - { - dlt_vnlog(LOG_WARNING, DLT_USER_BUFFER_LENGTH, "Loging disabled, Shared memory %d cannot be created!\n", DLT_SHM_KEY); - //return DLT_RETURN_OK; - } + if (dlt_shm_init_client(&dlt_user.dlt_shm, DLT_SHM_KEY) < 0) + dlt_vnlog(LOG_WARNING, + DLT_USER_BUFFER_LENGTH, + "Loging disabled, Shared memory %d cannot be created!\n", + DLT_SHM_KEY); + /*return DLT_RETURN_OK; */ + #endif dlt_log(LOG_NOTICE, "Logging (re-)enabled!\n"); /* Re-register application */ if (dlt_user_log_send_register_application() < DLT_RETURN_ERROR) - { return; - } DLT_SEM_LOCK(); /* Re-register all stored contexts */ - for (num=0; num<dlt_user.dlt_ll_ts_num_entries; num++) - { + for (num = 0; num < dlt_user.dlt_ll_ts_num_entries; num++) /* Re-register stored context */ - if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0')) - { - //dlt_set_id(log_new.appID, dlt_user.appID); + if ((dlt_user.appID[0] != '\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0] != '\0')) { + /*dlt_set_id(log_new.appID, dlt_user.appID); */ dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID); handle.log_level_pos = num; log_new.context_description = dlt_user.dlt_ll_ts[num].context_description; - // Release the mutex for sending context registration: - // function dlt_user_log_send_register_context() can take the mutex to write to the DLT buffer. => dead lock + /* Release the mutex for sending context registration: */ + /* function dlt_user_log_send_register_context() can take the mutex to write to the DLT buffer. => dead lock */ DLT_SEM_FREE(); log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET; log_new.trace_status = DLT_USER_TRACE_STATUS_NOT_SET; if (dlt_user_log_send_register_context(&log_new) < DLT_RETURN_ERROR) - { return; - } - reregistered=1; + reregistered = 1; - // Lock again the mutex - // it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section. + /* Lock again the mutex */ + /* it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section. */ DLT_SEM_LOCK(); } - } DLT_SEM_FREE(); - if (reregistered==1) - { + if (reregistered == 1) dlt_user_log_resend_buffer(); - } } } @@ -4925,27 +4558,23 @@ DltReturnValue dlt_user_log_send_overflow(void) /* set userheader */ if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_OVERFLOW) < DLT_RETURN_OK) - { return DLT_RETURN_ERROR; - } if (dlt_user.dlt_is_file) - { return DLT_RETURN_OK; - } /* set user message parameters */ userpayload.overflow_counter = dlt_user.overflow_counter; - dlt_set_id(userpayload.apid,dlt_user.appID); + dlt_set_id(userpayload.apid, dlt_user.appID); return dlt_user_log_out2(dlt_user.dlt_log_handle, - &(userheader), sizeof(DltUserHeader), - &(userpayload), sizeof(DltUserControlMsgBufferOverflow)); + &(userheader), sizeof(DltUserHeader), + &(userpayload), sizeof(DltUserControlMsgBufferOverflow)); } DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size) { - if(total_size == NULL || used_size == NULL) + if ((total_size == NULL) || (used_size == NULL)) return DLT_RETURN_WRONG_PARAMETER; DLT_SEM_LOCK(); @@ -4967,7 +4596,7 @@ void dlt_user_test_corrupt_user_header(int enable) { dlt_user.corrupt_user_header = enable; } -void dlt_user_test_corrupt_message_size(int enable,int16_t size) +void dlt_user_test_corrupt_message_size(int enable, int16_t size) { dlt_user.corrupt_message_size = enable; dlt_user.corrupt_message_size_size = size; @@ -4979,18 +4608,16 @@ int dlt_start_threads() { /* Start receiver thread */ if (pthread_create(&(dlt_receiverthread_handle), - 0, - (void *) &dlt_user_receiverthread_function, - 0) != 0) - { + 0, + (void *)&dlt_user_receiverthread_function, + 0) != 0) { dlt_log(LOG_CRIT, "Can't create receiver thread!\n"); return -1; } /* Start the segmented thread */ if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, - (void *) dlt_user_trace_network_segmented_thread, NULL)) - { + (void *)dlt_user_trace_network_segmented_thread, NULL)) { dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); return -1; } @@ -5002,55 +4629,54 @@ void dlt_stop_threads() { int dlt_receiverthread_result = 0; int dlt_segmented_nwt_result = 0; - if (dlt_receiverthread_handle) - { + + if (dlt_receiverthread_handle) { /* do not ignore return value */ dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle); - if (dlt_receiverthread_result != 0) - { + + if (dlt_receiverthread_result != 0) { snprintf(str, DLT_USER_BUFFER_LENGTH, - "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", - strerror(errno)); + "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", + strerror(errno)); dlt_log(LOG_ERR, str); } } - if (dlt_user.dlt_segmented_nwt_handle) - { + if (dlt_user.dlt_segmented_nwt_handle) { dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle); - if (dlt_segmented_nwt_result != 0) - { + + if (dlt_segmented_nwt_result != 0) { snprintf(str, DLT_USER_BUFFER_LENGTH, - "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", - strerror(errno)); + "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", + strerror(errno)); dlt_log(LOG_ERR, str); } } /* make sure that the threads really finished working */ - if ((dlt_receiverthread_result == 0) && dlt_receiverthread_handle) - { + if ((dlt_receiverthread_result == 0) && dlt_receiverthread_handle) { int joined = pthread_join(dlt_receiverthread_handle, NULL); - if (joined < 0) - { + + if (joined < 0) { snprintf(str, DLT_USER_BUFFER_LENGTH, - "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", - strerror(errno)); + "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", + strerror(errno)); dlt_log(LOG_ERR, str); } + dlt_receiverthread_handle = 0; /* set to invalid */ } - if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) - { + if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) { int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); - if (joined < 0) - { + + if (joined < 0) { snprintf(str, DLT_USER_BUFFER_LENGTH, - "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", - strerror(errno)); + "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", + strerror(errno)); dlt_log(LOG_ERR, str); } + dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ } } @@ -5062,13 +4688,11 @@ static void dlt_fork_pre_fork_handler() static void dlt_fork_parent_fork_handler() { - if (dlt_user_initialised) - { - if (dlt_start_threads() < 0) - { + if (dlt_user_initialised) { + if (dlt_start_threads() < 0) { snprintf(str, DLT_USER_BUFFER_LENGTH, - "Logging disabled, failed re-start thread after fork(pid=%i)!\n", - getpid()); + "Logging disabled, failed re-start thread after fork(pid=%i)!\n", + getpid()); dlt_log(LOG_WARNING, str); /* cleanup is the only thing we can do here */ dlt_log_free(); @@ -5079,17 +4703,17 @@ static void dlt_fork_parent_fork_handler() static void dlt_fork_child_fork_handler() { - if (dlt_user_initialised) - { - /* don't start anything else but cleanup everything and avoid blow-out of buffers*/ - dlt_user.dlt_log_handle = -1; - dlt_log_free(); - dlt_free(); - /* the only thing that remains is the atexit-handler */ - } + if (dlt_user_initialised) { + /* don't start anything else but cleanup everything and avoid blow-out of buffers*/ + dlt_user.dlt_log_handle = -1; + dlt_log_free(); + dlt_free(); + /* the only thing that remains is the atexit-handler */ + } } -DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void* ptr2, size_t len2, void *ptr3, size_t len3) +DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, + size_t len3) { int ret = DLT_RETURN_ERROR; int msg_size = len1 + len2 + len3; @@ -5099,17 +4723,17 @@ DltReturnValue dlt_user_log_out_error_handling(void *ptr1, size_t len1, void* pt DLT_SEM_FREE(); DLT_SEM_LOCK(); + if (dlt_buffer_push3(&(dlt_user.startup_buffer), ptr1, len1, ptr2, len2, - ptr3, len3) == DLT_RETURN_ERROR) - { - if(dlt_user.overflow_counter == 0) - { - dlt_log(LOG_WARNING,"Buffer full! Messages will be discarded.\n"); - } + ptr3, len3) == DLT_RETURN_ERROR) { + if (dlt_user.overflow_counter == 0) + dlt_log(LOG_WARNING, "Buffer full! Messages will be discarded.\n"); + ret = DLT_RETURN_BUFFER_FULL; } + DLT_SEM_FREE(); return ret; diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 83fa157..5e43ee0 100644 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -89,7 +89,7 @@ #define DLT_USER_BUFFER_LENGTH 255 /* Number of context entries, which will be allocated, - if no more context entries are available */ + * if no more context entries are available */ #define DLT_USER_CONTEXT_ALLOC_SIZE 500 /* Maximu length of a filename string */ |