[GSW-138] API Extension to resend the log messages in the user buffer fixed.
authorChristian Muck <christian.muck@bmw.de>
Fri, 13 Jan 2012 08:12:22 +0000 (09:12 +0100)
committerChristian Muck <christian.muck@bmw.de>
Fri, 13 Jan 2012 08:12:22 +0000 (09:12 +0100)
include/dlt/dlt_user.h
src/lib/dlt_user.c
src/lib/dlt_user_cfg.h

index b128244..ac889c7 100755 (executable)
@@ -596,6 +596,14 @@ int dlt_forward_msg(void *msgdata,size_t size);
  */
 int dlt_user_check_buffer(int *total_size, int *used_size);
 
+/**
+ * Try to resend log message in the user buffer. Stops if the dlt_uptime is bigger than
+ * dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT. A pause between the resending
+ * attempts can be defined with DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP
+ * @return number of messages in the user buffer
+ */
+int dlt_user_atexit_blow_out_user_buffer(void);
+
 #ifdef __cplusplus
 }
 #endif
index 8c82dd3..594fe39 100755 (executable)
@@ -331,6 +331,16 @@ int dlt_init_common(void)
 
 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){
+               char tmp[256];
+               sprintf(&tmp,"Lost log messages in user buffer when exiting: %i\n",count);
+               dlt_log(LOG_ERR, tmp);
+       }
+
     /* Unregister app (this also unregisters all contexts in daemon) */
     /* Ignore return value */
     dlt_unregister_app();
@@ -340,6 +350,31 @@ void dlt_user_atexit_handler(void)
     dlt_free();
 }
 
+int dlt_user_atexit_blow_out_user_buffer(void){
+
+       int count,ret;
+
+       uint32_t exitTime = dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT;
+
+       while(dlt_uptime() < exitTime ){
+
+               ret = dlt_user_log_resend_buffer();
+
+               if(ret == 0)
+               {
+                               return 0;
+               }
+
+               usleep(DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP);
+       }
+
+       DLT_SEM_LOCK();
+       count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer));
+       DLT_SEM_FREE();
+
+       return count;
+}
+
 int dlt_free(void)
 {
     int i;
index e3bb8a3..46e8c52 100755 (executable)
 /* Name of environment variable for local print mode */\r
 #define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE"\r
 \r
+/* Timeout offset for resending user buffer at exit in usec (1000 usec = 1ms)*/\r
+#define DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT 100000\r
+\r
+/* Sleeps between resending user buffer at exit in usec (1000 usec = 1ms)*/\r
+#define DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP 1000\r
+\r
+\r
 /************************/\r
 /* Don't change please! */\r
 /************************/\r