From b2ce65d9947849160e04e751075c7fe4b5dcd158 Mon Sep 17 00:00:00 2001 From: ManikandanC Date: Mon, 22 May 2017 10:57:21 +0530 Subject: Dynamic allocation of msg buffer It is possible to change the default buffer size for log message creation via environment variable: export DLT_LOG_MSG_BUF_LEN= Instead of using a static buffer with size of 1390 bytes, the buffer is allocated dynamically with the specified value.The max size is restricted to approx 65k. Signed-off-by: Christoph Lipka Signed-off-by: ManikandanC --- include/dlt/dlt_common.h | 31 ++++++++++++++++++++++--------- include/dlt/dlt_user.h | 10 ++++++++-- include/dlt/dlt_user_macros.h | 30 ++++++++++++------------------ 3 files changed, 42 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index f939329..4803663 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -381,6 +381,16 @@ enum { #else #define DLT_STATIC #endif + +/** + * Type to specify whether received data is from socket or file/fifo + */ +typedef enum +{ + DLT_RECEIVE_SOCKET, + DLT_RECEIVE_FD +} DltReceiverType; + /** * The definition of the serial header containing the characters "DLS" + 0x01. */ @@ -753,6 +763,7 @@ typedef struct int32_t totalBytesRcvd; /**< total number of received bytes */ char *buffer; /**< pointer to receiver buffer */ char *buf; /**< pointer to position within receiver buffer */ + char *backup_buf; /** pointer to the buffer with partial messages if any **/ int fd; /**< connection handle */ int32_t buffersize; /**< size of receiver buffer */ } DltReceiver; @@ -1150,24 +1161,26 @@ extern "C" */ DltReturnValue dlt_receiver_free(DltReceiver *receiver); /** - * Receive data from socket using the dlt receiver structure + * Initialising a dlt receiver structure * @param receiver pointer to dlt receiver structure - * @return number of received bytes or negative value if there was an error + * @param fd handle to file/socket/fifo, fram which the data should be received + * @param buffer data buffer for storing the received data + * @return negative value if there was an error and zero if success */ - int dlt_receiver_receive_socket(DltReceiver *receiver); + DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer); /** - * Receive data from file/fifo using the dlt receiver structure + * De-Initialize a dlt receiver structure * @param receiver pointer to dlt receiver structure - * @return number of received bytes or negative value if there was an error + * @return negative value if there was an error and zero if success */ - int dlt_receiver_receive_fd(DltReceiver *receiver); + DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver); /** - * Receive data from file/fifo/socket, calls corresponding function based on - * CMake configuration. + * Receive data from socket or file/fifo using the dlt receiver structure * @param receiver pointer to dlt receiver structure + * @param from_src specify whether received data is from socket or file/fifo * @return number of received bytes or negative value if there was an error */ - int dlt_receiver_receive(DltReceiver *receiver); + int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src); /** * Remove a specific size of bytes from the received data * @param receiver pointer to dlt receiver structure diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 82e5e31..8e676c6 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -115,7 +115,7 @@ typedef struct typedef struct { DltContext *handle; /**< pointer to DltContext */ - unsigned char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/ + unsigned char *buffer; /**< buffer for building log message*/ int32_t size; /**< payload size */ int32_t log_level; /**< log level */ int32_t trace_status; /**< trace status */ @@ -222,7 +222,7 @@ typedef struct DltBuffer startup_buffer; /**< Ring-buffer for buffering messages during startup and missing connection */ /* Buffer used for resending, locked by DLT semaphore */ - uint8_t resend_buffer[DLT_USER_RESENDBUF_MAX_SIZE]; + uint8_t *resend_buffer; uint32_t timeout_at_exit_handler; /**< timeout used in dlt_user_atexit_blow_out_user_buffer, in 0.1 milliseconds */ dlt_env_ll_set initial_ll_set; @@ -236,6 +236,7 @@ typedef struct int16_t corrupt_message_size_size; #endif DltUserConnectionState connection_state; + uint16_t log_buf_len; /**< length of message buffer, by default: DLT_USER_BUF_MAX_SIZE */ } DltUser; /************************************************************************************************** @@ -795,6 +796,11 @@ DltReturnValue dlt_user_log_resend_buffer(void); */ static inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle,DltLogLevelType loglevel) { + if (loglevel < DLT_LOG_OFF || loglevel >= DLT_LOG_MAX) + { + return DLT_RETURN_WRONG_PARAMETER; + } + if (handle == NULL || handle->log_level_ptr == NULL) { return DLT_RETURN_WRONG_PARAMETER; diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index d50b335..e1b1267 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -187,16 +187,13 @@ #else #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \ do { \ - if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start(&CONTEXT,&log_local,LOGLEVEL); \ + if (dlt_local == DLT_RETURN_TRUE) \ { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start(&CONTEXT,&log_local,LOGLEVEL); \ - if (dlt_local > 0) \ - { \ - ARGS; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ + ARGS; \ + (void)dlt_user_log_write_finish(&log_local); \ } \ } while(0) #endif @@ -219,16 +216,13 @@ #else #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \ do { \ - if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \ + DltContextData log_local; \ + int dlt_local; \ + dlt_local = dlt_user_log_write_start_id(&CONTEXT,&log_local,LOGLEVEL,MSGID); \ + if (dlt_local == DLT_RETURN_TRUE) \ { \ - DltContextData log_local; \ - int dlt_local; \ - dlt_local = dlt_user_log_write_start_id(&CONTEXT,&log_local,LOGLEVEL,MSGID); \ - if (dlt_local > 0) \ - { \ - ARGS; \ - (void)dlt_user_log_write_finish(&log_local); \ - } \ + ARGS; \ + (void)dlt_user_log_write_finish(&log_local); \ } \ } while(0) #endif -- cgit v1.2.1