diff options
author | Stefan Vacek <stefan.vacek@intel.com> | 2015-08-31 09:29:07 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2015-10-07 10:38:19 +0200 |
commit | 0d330db31f5df337cbb5780a0f6621a7b2cb6396 (patch) | |
tree | 7463ff88ee504cdeaf12f0627c53a05ad2250b70 | |
parent | ed412acac8e9f8a5745e55adeed9652b34b9ee4f (diff) | |
download | DLT-daemon-0d330db31f5df337cbb5780a0f6621a7b2cb6396.tar.gz |
Make timeout on exit configurable
- make timeout in at_exit handler configurable (was hardcoded to 10s), new api:
int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds);
- add option -t to dlt-adaptor-stdin to set timeout in at_exit_handler
- add option -t to dlt-example-user to set timeout in at_exit_handler
Signed-off-by: Stefan Vacek <stefan.vacek@intel.com>
-rw-r--r-- | include/dlt/dlt_user.h | 18 | ||||
-rw-r--r-- | src/adaptor/dlt-adaptor-stdin.c | 19 | ||||
-rw-r--r-- | src/examples/dlt-example-user.c | 20 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 18 |
4 files changed, 61 insertions, 14 deletions
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index 05bd6b9..df41259 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -300,6 +300,7 @@ typedef struct // Buffer used for resending, locked by DLT semaphore uint8_t resend_buffer[DLT_USER_RESENDBUF_MAX_SIZE]; + 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; #ifdef DLT_SHM_ENABLE @@ -313,11 +314,11 @@ typedef struct } DltUser; /************************************************************************************************** -* The folowing API functions define a low level function interface for DLT +* The following API functions define a low level function interface for DLT **************************************************************************************************/ /** - * Initialise the generation of a DLT log message (intended for usage in non-verbose mode) + * Initialize the generation of a DLT log message (intended for usage in non-verbose mode) * This function has to be called first, when an application wants to send a new log messages. * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, * when return value is bigger than zero. @@ -329,7 +330,7 @@ typedef struct int dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); /** - * Initialise the generation of a DLT log message (intended for usage in verbose mode) + * Initialize the generation of a DLT log message (intended for usage in verbose mode) * This function has to be called first, when an application wants to send a new log messages. * Following functions like dlt_user_log_write_string and dlt_user_log_write_finish must only be called, * when return value is bigger than zero. @@ -519,14 +520,14 @@ int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_ **************************************************************************************************/ /** - * Initialise the user lib communication with daemon. + * Initialize the user lib communication with daemon. * This function has to be called first, before using any DLT user lib functions. * @return negative value if there was an error */ int dlt_init(); /** - * Initialise the user lib writing only to file. + * Initialize the user lib writing only to file. * This function has to be called first, before using any DLT user lib functions. * @param name name of an optional log file * @return negative value if there was an error @@ -595,6 +596,13 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const */ int dlt_unregister_context(DltContext *handle); + +/** + * Set maximum timeout for re-sending at exit + * @param timeout_in_milliseconds maximum time to wait until giving up re-sending, default 10000 (equals to 10 seconds) + */ +int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds); + /** * Set the logging mode used by the daemon. * The logging mode is stored persistantly by the daemon. diff --git a/src/adaptor/dlt-adaptor-stdin.c b/src/adaptor/dlt-adaptor-stdin.c index 2ad0ca5..33ab8a2 100644 --- a/src/adaptor/dlt-adaptor-stdin.c +++ b/src/adaptor/dlt-adaptor-stdin.c @@ -90,11 +90,12 @@ int main(int argc, char* argv[]) char apid[DLT_ID_SIZE]; char ctid[DLT_ID_SIZE]; char version[255]; + int timeout = -1; dlt_set_id(apid, PS_DLT_APP); dlt_set_id(ctid, PS_DLT_CONTEXT); - while ((opt = getopt(argc, argv, "a:c:h")) != -1) + while ((opt = getopt(argc, argv, "a:c:ht:")) != -1) { switch (opt) { @@ -108,6 +109,11 @@ int main(int argc, char* argv[]) dlt_set_id(ctid,optarg); break; } + case 't': + { + timeout = atoi(optarg); + break; + } case 'h': { dlt_get_version(version,255); @@ -116,9 +122,10 @@ int main(int argc, char* argv[]) printf("Adaptor for forwarding input from stdin to DLT daemon.\n"); printf("%s \n", version); printf("Options:\n"); - printf("-a apid - Set application id to apid (default: SINA)\n"); - printf("-c ctid - Set context id to ctid (default: SINC)\n"); - printf("-h - This help\n"); + printf(" -a apid - Set application id to apid (default: SINA)\n"); + printf(" -c ctid - Set context id to ctid (default: SINC)\n"); + printf(" -t timeout - Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n"); + printf(" -h - This help\n"); return 0; break; } @@ -132,6 +139,10 @@ int main(int argc, char* argv[]) DLT_REGISTER_APP(apid,PS_DLT_APP_DESC); DLT_REGISTER_CONTEXT(mycontext, ctid, PS_DLT_CONTEXT_DESC); + if (timeout > -1) + { + dlt_set_resend_timeout_atexit(timeout); + } while (fgets(str, MAXSTRLEN, stdin)) { diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index 61550fc..5822fde 100644 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -102,8 +102,9 @@ void usage() printf(" -k Send marker message\n"); printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n"); printf(" -l level Set log level to <level>, level=-1..6\n"); + printf(" -t timeout Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n"); #ifdef DLT_TEST_ENABLE - printf(" -c Corrupt user header\n"); + printf(" -c Corrupt user header\n"); printf(" -s size Corrupt message size\n"); printf(" -z size Size of message\n"); #endif /* DLT_TEST_ENABLE */ @@ -128,6 +129,7 @@ int main(int argc, char* argv[]) char *mvalue = 0; char *message = 0; int lvalue = DLT_LOG_WARN; + char *tvalue = 0; int index; int c; @@ -140,9 +142,9 @@ int main(int argc, char* argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:s:l:")) != -1) + while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:s:l:t:")) != -1) #else - while ((c = getopt (argc, argv, "vgakd:f:n:m:l:")) != -1) + while ((c = getopt (argc, argv, "vgakd:f:n:m:l:t:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) @@ -204,9 +206,14 @@ int main(int argc, char* argv[]) lvalue = atoi(optarg); break; } + case 't': + { + tvalue = optarg; + break; + } case '?': { - if (optopt == 'd' || optopt == 'f' || optopt == 'n'|| optopt == 'l') + if (optopt == 'd' || optopt == 'f' || optopt == 'n'|| optopt == 'l' || optopt == 't') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } @@ -306,6 +313,11 @@ int main(int argc, char* argv[]) delay = 500 * 1000; } + if (tvalue) + { + dlt_set_resend_timeout_atexit(atoi(tvalue)); + } + if (gflag) { /* DLT messages to test Fibex non-verbose description: dlt-example-non-verbose.xml */ diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index f961bb5..2164768 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -465,6 +465,8 @@ int dlt_init_common(void) dlt_user.local_print_mode = DLT_PM_UNSET; + 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) { @@ -555,7 +557,7 @@ int dlt_user_atexit_blow_out_user_buffer(void){ int count,ret; - uint32_t exitTime = dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT; + uint32_t exitTime = dlt_uptime() + dlt_user.timeout_at_exit_handler; /* Send content of ringbuffer */ DLT_SEM_LOCK(); @@ -1202,6 +1204,20 @@ int dlt_set_log_mode(DltUserLogMode mode) return dlt_user_log_send_log_mode(mode); } +int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds) +{ + if (dlt_user_initialised==0) + { + if (dlt_init()<0) + { + return -1; + } + } + dlt_user.timeout_at_exit_handler = timeout_in_milliseconds * 10; + return 0; +} + + int dlt_forward_msg(void *msgdata,size_t size) { DltUserHeader userheader; |