From 87936e5249b2c22eefac0acfc21696e209ee6d35 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Mon, 28 Jul 2014 13:33:23 +0200 Subject: New Callback function in DLT library, called when log level of context is changed Signed-off-by: Alexander Wenzel --- include/dlt/dlt_user.h | 21 ++++++++++++++ include/dlt/dlt_user_macros.h | 8 ++++++ src/examples/dlt-example-user.c | 12 ++++++++ src/lib/dlt_user.c | 62 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 7d41896..44d1ca1 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -186,6 +186,14 @@ typedef struct int (*injection_callback)(uint32_t service_id, void *data, uint32_t length); } DltUserInjectionCallback; +typedef struct +{ + char contextID[DLT_ID_SIZE]; /**< Context ID */ + int8_t log_level; /**< Log level */ + int8_t trace_status; /**< Trace status */ + void (*log_level_changed_callback) (char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status); +} DltUserLogLevelChangedCallback; + /** * This structure is used in a table managing all contexts and the corresponding log levels in an application. */ @@ -199,6 +207,10 @@ typedef struct char *context_description; /**< description of context */ DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */ uint32_t nrcallbacks; + + // Log Level changed callback + void (*log_level_changed_callback) (char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status); + } dlt_ll_ts_type; /** @@ -536,6 +548,15 @@ int dlt_get_log_state(); int dlt_register_injection_callback(DltContext *handle, uint32_t service_id, int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); +/** + * Register callback function called when log level of context was changed + * @param handle pointer to an object containing information about one special logging context + * @param (*dlt_log_level_changed_callback) function pointer to callback function + * @return negative value if there was an error + */ +int 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)); + /** * Switch to verbose mode * diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h index 37a8ccf..8a186ae 100644 --- a/include/dlt/dlt_user_macros.h +++ b/include/dlt/dlt_user_macros.h @@ -148,6 +148,14 @@ extern DltContext CONTEXT; #define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do{\ dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK);} while(0) +/** + * Register callback function called when log level of context was changed + * @param CONTEXT object containing information about one special logging context + * @param CALLBACK function pointer to callback function + */ +#define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) do{\ + dlt_register_log_level_changed_callback(&(CONTEXT),CALLBACK);} while(0) + /** * Send log message with variable list of messages (intended for verbose mode) * @param CONTEXT object containing information about one special logging context diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index 25d3110..a01ea44 100755 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -74,6 +74,7 @@ #include "dlt_common.h" /* for dlt_get_version() */ int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length); +void dlt_user_log_level_changed_callback(char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status); DLT_DECLARE_CONTEXT(mycontext); @@ -244,6 +245,7 @@ int main(int argc, char* argv[]) DLT_REGISTER_CONTEXT(mycontext,"TEST","Test Context for Logging"); DLT_REGISTER_INJECTION_CALLBACK(mycontext, 0x1000, dlt_user_injection_callback); + DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(mycontext, dlt_user_log_level_changed_callback); text = message; @@ -376,3 +378,13 @@ int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length return 0; } +void dlt_user_log_level_changed_callback(char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status) +{ + char text[5]; + text[4]=0; + + memcpy(text,context_id,DLT_ID_SIZE); + + printf("Log level changed of context %s, LogLevel=%u, TraceState=%u \n",text,log_level,trace_status); +} + diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index a721f1c..bf63ed7 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -586,6 +586,7 @@ int dlt_free(void) 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; } free(dlt_user.dlt_ll_ts); @@ -814,6 +815,8 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const 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; + } } else @@ -858,6 +861,7 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const 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; } } } @@ -1036,6 +1040,7 @@ int dlt_unregister_context(DltContext *handle) } 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; } DLT_SEM_FREE(); @@ -2002,6 +2007,48 @@ int dlt_register_injection_callback(DltContext *handle, uint32_t service_id, return 0; } +int 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)) +{ + DltContextData log; + uint32_t i; + + if (handle==0) + { + return -1; + } + + if (dlt_user_log_init(handle, &log)==-1) + { + return -1; + } + + /* This function doesn't make sense storing to local file is choosen; + so terminate this function */ + if (dlt_user.dlt_is_file) + { + return 0; + } + + DLT_SEM_LOCK(); + + if (dlt_user.dlt_ll_ts==0) + { + DLT_SEM_FREE(); + return 0; + } + + /* Insert callback in corresponding table */ + i=handle->log_level_pos; + + /* Store new callback function */ + dlt_user.dlt_ll_ts[i].log_level_changed_callback = dlt_log_level_changed_callback; + + DLT_SEM_FREE(); + + return 0; +} + /** * NW Trace related */ @@ -3570,12 +3617,14 @@ int dlt_user_log_check_user_message(void) /* For delayed calling of injection callback, to avoid deadlock */ DltUserInjectionCallback delayed_injection_callback; + DltUserLogLevelChangedCallback delayed_log_level_changed_callback; 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; delayed_injection_callback.service_id = 0; + delayed_log_level_changed_callback.log_level_changed_callback = 0; if (dlt_user.dlt_user_handle!=DLT_FD_INIT) { @@ -3653,12 +3702,25 @@ int dlt_user_log_check_user_message(void) *(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; } } DLT_SEM_FREE(); } + /* 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); + } + /* keep not read data in buffer */ if (dlt_receiver_remove(receiver,sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogLevel))==-1) { -- cgit v1.2.1