diff options
author | ManikandanC <Manikandan.Chockalingam@in.bosch.com> | 2017-05-22 10:57:21 +0530 |
---|---|---|
committer | Christoph Lipka <clipka@users.noreply.github.com> | 2018-12-10 15:40:58 +0100 |
commit | b2ce65d9947849160e04e751075c7fe4b5dcd158 (patch) | |
tree | 17bd0227f0d26d3557deecb83b026284975019a1 /include | |
parent | ea836f6de185f32c14404950f5cfb2ebf084e1ca (diff) | |
download | DLT-daemon-b2ce65d9947849160e04e751075c7fe4b5dcd158.tar.gz |
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=<value>
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 <clipka@de.adit-jv.com>
Signed-off-by: ManikandanC <Manikandan.Chockalingam@in.bosch.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/dlt/dlt_common.h | 31 | ||||
-rw-r--r-- | include/dlt/dlt_user.h | 10 | ||||
-rw-r--r-- | include/dlt/dlt_user_macros.h | 30 |
3 files changed, 42 insertions, 29 deletions
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 |