summaryrefslogtreecommitdiff
path: root/src/offlinelogstorage
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2016-03-16 16:05:53 +0900
committerGernot Wirschal <gernot.wirschal@bmw.de>2016-04-25 14:34:34 +0200
commitbc09757d465d4ee5728157dce4fed0f71841daa7 (patch)
treec65dbe20fe43dc36e480ca85b74b41aa812e5de2 /src/offlinelogstorage
parentab443bc109f1d6a957fc5a85cd0efc566299bd4d (diff)
downloadDLT-daemon-bc09757d465d4ee5728157dce4fed0f71841daa7.tar.gz
Offline logstorage: On Demand triggering for syncing Logstorage cache and support long options
Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com> Change-Id: I2bac5e48a5d210b544a96fe96dc322f28ac472fe
Diffstat (limited to 'src/offlinelogstorage')
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.c92
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage.h24
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c59
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.h30
4 files changed, 142 insertions, 63 deletions
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c
index 6905b05..40dc285 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage.c
@@ -335,20 +335,34 @@ int dlt_logstorage_set_sync_strategy(int *strategy, char *value)
return -1;
}
- if (strncasecmp(value, "ON_MSG", strlen(value)) == 0)
+ if (strcasestr(value, "ON_MSG") != NULL)
{
*strategy = DLT_LOGSTORAGE_SYNC_ON_MSG;
+ dlt_log(LOG_DEBUG, "ON_MSG found, ignore other if added\n");
}
- else if (strncasecmp(value, "ON_DAEMON_EXIT", strlen(value)) == 0)
+ else /* ON_MSG not set, combination of cache based strategies possible */
{
- *strategy = DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT;
- }
- else
- {
- dlt_log(LOG_WARNING, "Unknown sync strategy. Set default ON_MSG\n");
- *strategy = DLT_LOGSTORAGE_SYNC_ON_MSG;
- }
+ if (strcasestr(value, "ON_DAEMON_EXIT") != NULL)
+ {
+ *strategy |= DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT;
+ }
+
+ if (strcasestr(value, "ON_DEMAND") != NULL)
+ {
+ *strategy |= DLT_LOGSTORAGE_SYNC_ON_DEMAND;
+ }
+ if (strcasestr(value, "ON_DEVICE_DISCONNECT") != NULL)
+ {
+ *strategy |= DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT;
+ }
+
+ if (*strategy == 0)
+ {
+ dlt_log(LOG_WARNING, "Unknown sync strategies. Set default ON_MSG\n");
+ *strategy = DLT_LOGSTORAGE_SYNC_ON_MSG;
+ }
+ }
return 0;
}
@@ -557,7 +571,9 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
dlt_log(LOG_ERR, "dlt_logstorage_device_connected Error : Device already connected, \n");
dlt_log(LOG_ERR, "Send disconnect, connect request \n");
- dlt_logstorage_device_disconnected(handle);
+ dlt_logstorage_device_disconnected(
+ handle,
+ DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
}
strncpy(handle->device_mount_point,mount_point,DLT_MOUNT_PATH_MAX);
@@ -578,9 +594,10 @@ int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
* Free all allocated memory used in log storage handle
*
* @param handle DLT Logstorage handle
+ * @param reason Reason for freeing the device
*
*/
-void dlt_logstorage_free(DltLogStorage *handle)
+void dlt_logstorage_free(DltLogStorage *handle, int reason)
{
int i=0;
@@ -592,7 +609,7 @@ void dlt_logstorage_free(DltLogStorage *handle)
/* ignore return value */
handle->config_data[i].data.dlt_logstorage_sync(
&(handle->config_data[i].data),
- DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT);
+ reason);
free(handle->config_data[i].data.file_name);
@@ -635,10 +652,11 @@ void dlt_logstorage_free(DltLogStorage *handle)
* De-Initializes DLT Offline Logstorage with respect to device status
*
* @param handle DLT Logstorage handle
+ * @param reason Reason for disconnect
* @return 0 on success, -1 on error
*
*/
-int dlt_logstorage_device_disconnected(DltLogStorage *handle)
+int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason)
{
if (handle == NULL)
return -1;
@@ -646,7 +664,7 @@ int dlt_logstorage_device_disconnected(DltLogStorage *handle)
/* If configuration loading was done, free it */
if (handle->config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
{
- dlt_logstorage_free(handle);
+ dlt_logstorage_free(handle, reason);
}
/* Reset all device status */
@@ -727,7 +745,7 @@ int dlt_logstorage_prepare_table(DltLogStorage *handle, char *appid, char *ctxid
{
dlt_log(LOG_ERR, "Adding to hash table failed, returning failure\n");
- dlt_logstorage_free(handle);
+ dlt_logstorage_free(handle, DLT_LOGSTORAGE_SYNC_ON_ERROR);
free(keys);
return -1;
@@ -876,19 +894,18 @@ void dlt_logstorage_filter_set_strategy(DltLogStorageConfigData *config,
return;
}
- switch(strategy)
+ if (strategy == DLT_LOGSTORAGE_SYNC_ON_MSG) /* file based */
{
- case DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT:
- config->dlt_logstorage_prepare = &dlt_logstorage_prepare_on_daemon_exit;
- config->dlt_logstorage_write = &dlt_logstorage_write_on_daemon_exit;
- config->dlt_logstorage_sync = &dlt_logstorage_sync_on_daemon_exit;
- break;
- case DLT_LOGSTORAGE_SYNC_ON_MSG: /* ON_MSG is the default strategy */
- default:
config->dlt_logstorage_prepare = &dlt_logstorage_prepare_on_msg;
config->dlt_logstorage_write = &dlt_logstorage_write_on_msg;
config->dlt_logstorage_sync = &dlt_logstorage_sync_on_msg;
}
+ else /* cache based */
+ {
+ config->dlt_logstorage_prepare = &dlt_logstorage_prepare_msg_cache;
+ config->dlt_logstorage_write = &dlt_logstorage_write_msg_cache;
+ config->dlt_logstorage_sync = &dlt_logstorage_sync_msg_cache;
+ }
}
/*Return :
@@ -959,7 +976,7 @@ int dlt_daemon_setup_filter_properties(DltLogStorage *handle, DltConfigFile *con
}
else
{
- if (tmp_data.sync != DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT)
+ if (tmp_data.sync <= DLT_LOGSTORAGE_SYNC_ON_MSG)
{
dlt_log(LOG_INFO,
"Sync strategy not given. Use default ON_MSG\n");
@@ -1432,3 +1449,30 @@ int dlt_logstorage_write(DltLogStorage *handle,
return err;
}
+
+int dlt_logstorage_sync_caches(DltLogStorage *handle)
+{
+ int i = 0;
+
+ if (handle == NULL)
+ {
+ return -1;
+ }
+
+ for (i=0; i<handle->num_filter_keys; i++)
+ {
+ /* sync data if necessary */
+ /* ignore return value */
+ if (handle->config_data[i].data.dlt_logstorage_sync(
+ &(handle->config_data[i].data),
+ DLT_LOGSTORAGE_SYNC_ON_DEMAND) != 0)
+ {
+
+ dlt_log(LOG_ERR,
+ "dlt_logstorage_sync_caches: Sync failed."
+ " Continue with next cache.\n");
+ }
+ }
+
+ return 0;
+}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h
index 843fef2..df232b7 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage.h
@@ -65,6 +65,8 @@
#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0
#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1
+#define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */
+
#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 10 /* Maximum size for key */
#define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN 50 /* Maximum file name length of the log file */
@@ -114,9 +116,13 @@
#define DLT_OFFLINE_LOGSTORAGE_GENERAL_CONFIG_SECTION "GENERAL"
/* Offline Logstorage sync strategies */
-#define DLT_LOGSTORAGE_SYNC_ON_MSG 0x00 /* default, on message sync */
-#define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT 0x01 /* sync on daemon exit */
+#define DLT_LOGSTORAGE_SYNC_ON_ERROR -1 /* error case */
+#define DLT_LOGSTORAGE_SYNC_ON_MSG 1 /* default, on message sync */
+#define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT (1<<1) /* sync on daemon exit */
+#define DLT_LOGSTORAGE_SYNC_ON_DEMAND (1<<2) /* sync on demand */
+#define DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT (1<<3) /* sync on device disconnect*/
+#define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S) & (s))
/* logstorage max cache */
unsigned int g_logstorage_cache_max;
@@ -223,9 +229,10 @@ extern int dlt_logstorage_load_config(DltLogStorage *handle);
* De-Initializes DLT Offline Logstorage with respect to device status
*
* @param handle DLT Logstorage handle
+ * @param reason Reason for device disconnection
* @return 0 on success, -1 on error
*/
-extern int dlt_logstorage_device_disconnected(DltLogStorage *handle);
+extern int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason);
/**
* dlt_logstorage_get_config
*
@@ -276,4 +283,15 @@ extern int dlt_logstorage_write(DltLogStorage *handle,
int size2,
unsigned char *data3,
int size3);
+
+/**
+ * dlt_logstorage_sync_caches
+ *
+ * Sync all caches inside the specified logstorage device.
+ *
+ * @param handle DltLogStorage handle
+ * @return 0 on success, -1 otherwise
+ */
+extern int dlt_logstorage_sync_caches(DltLogStorage *handle);
+
#endif /* DLT_OFFLINE_LOGSTORAGE_H */
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index 43c4d68..125e083 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -660,7 +660,7 @@ int dlt_logstorage_sync_on_msg(DltLogStorageConfigData *config, int status)
}
/**
- * dlt_logstorage_prepare_on_daemon_exit
+ * dlt_logstorage_prepare_msg_cache
*
* Prepare the log file for a certain filer. If log file not open or log
* files max size reached, open a new file.
@@ -672,10 +672,10 @@ int dlt_logstorage_sync_on_msg(DltLogStorageConfigData *config, int status)
* @param log_msg_size Size of log message
* @return 0 on success, -1 on error
*/
-int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
- DltLogStorageUserConfig *file_config,
- char *dev_path,
- int log_msg_size)
+int dlt_logstorage_prepare_msg_cache(DltLogStorageConfigData *config,
+ DltLogStorageUserConfig *file_config,
+ char *dev_path,
+ int log_msg_size)
{
if (config == NULL || file_config == NULL || dev_path == NULL)
{
@@ -684,8 +684,8 @@ int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
log_msg_size = log_msg_size; /* satisfy compiler */
- /* open log file */
- if (config->cache == NULL)
+ /* create file to sync cache into later */
+ if (config->log == NULL)
{
/* get always a new file */
if (dlt_logstorage_prepare_on_msg(config,
@@ -697,7 +697,11 @@ int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
"Cannot prepare log file for ON_DAEMON_EXIT sync\n");
return -1;
}
+ }
+ /* create cache */
+ if (config->cache == NULL)
+ {
/* check total logstorage cache size */
if ((g_logstorage_cache_size +
config->file_size +
@@ -727,7 +731,7 @@ int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
}
/**
- * dlt_logstorage_write_on_daemon_exit
+ * dlt_logstorage_write_msg_cache
*
* Write the log message.
*
@@ -740,13 +744,13 @@ int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
* @param size3 payload size
* @return 0 on success, -1 on error
*/
-int dlt_logstorage_write_on_daemon_exit(DltLogStorageConfigData *config,
- unsigned char *data1,
- int size1,
- unsigned char *data2,
- int size2,
- unsigned char *data3,
- int size3)
+int dlt_logstorage_write_msg_cache(DltLogStorageConfigData *config,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3)
{
DltLogStorageCacheFooter *footer = NULL;
int msg_size;
@@ -805,7 +809,7 @@ int dlt_logstorage_write_on_daemon_exit(DltLogStorageConfigData *config,
}
/**
- * dlt_logstorage_sync_on_daemon_exit
+ * dlt_logstorage_sync_msg_cache
*
* sync data to disk.
*
@@ -813,8 +817,8 @@ int dlt_logstorage_write_on_daemon_exit(DltLogStorageConfigData *config,
* @param status Strategy flag
* @return 0 on success, -1 on error
*/
-int dlt_logstorage_sync_on_daemon_exit(DltLogStorageConfigData *config,
- int status)
+int dlt_logstorage_sync_msg_cache(DltLogStorageConfigData *config,
+ int status)
{
int ret = 0;
DltLogStorageCacheFooter *footer = NULL;
@@ -824,7 +828,8 @@ int dlt_logstorage_sync_on_daemon_exit(DltLogStorageConfigData *config,
return -1;
}
- if (status == config->sync) /* only sync on exit */
+ /* sync only, if given strategy is set */
+ if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(config->sync, status) > 0)
{
if (config->log == NULL || config->cache == NULL)
{
@@ -863,7 +868,21 @@ int dlt_logstorage_sync_on_daemon_exit(DltLogStorageConfigData *config,
dlt_log(LOG_ERR, "Failed to sync log file\n");
}
}
+
+ /* do not reinitialize in case of ON_DAEMON_EXIT */
+ if (status != DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT)
+ {
+ /* clean ring buffer and reset footer information */
+ memset(config->cache,
+ 0,
+ config->file_size + sizeof(DltLogStorageCacheFooter));
+
+ /* close the file, a new one will be created when prepare is
+ * called again */
+ fclose(config->log);
+ config->log = NULL;
+ }
}
- return ret;
+ return 0;
}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.h b/src/offlinelogstorage/dlt_offline_logstorage_behavior.h
index 16394be..f26ce69 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.h
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.h
@@ -69,23 +69,21 @@ int dlt_logstorage_write_on_msg(DltLogStorageConfigData *config,
* is called on message received */
int dlt_logstorage_sync_on_msg(DltLogStorageConfigData *config, int status);
-/* ON_DAEMON_EXIT behavior */
-int dlt_logstorage_prepare_on_daemon_exit(DltLogStorageConfigData *config,
- DltLogStorageUserConfig *file_config,
- char *dev_path,
- int log_msg_size);
+/* Logstorage cache functionality */
+int dlt_logstorage_prepare_msg_cache(DltLogStorageConfigData *config,
+ DltLogStorageUserConfig *file_config,
+ char *dev_path,
+ int log_msg_size);
-int dlt_logstorage_write_on_daemon_exit(DltLogStorageConfigData *config,
- unsigned char *data1,
- int size1,
- unsigned char *data2,
- int size2,
- unsigned char *data3,
- int size3);
+int dlt_logstorage_write_msg_cache(DltLogStorageConfigData *config,
+ unsigned char *data1,
+ int size1,
+ unsigned char *data2,
+ int size2,
+ unsigned char *data3,
+ int size3);
-/* status is strategy, e.g. DLT_LOGSTORAGE_SYNC_ON_MSG is used when callback
- * is called on message received */
-int dlt_logstorage_sync_on_daemon_exit(DltLogStorageConfigData *config,
- int status);
+int dlt_logstorage_sync_msg_cache(DltLogStorageConfigData *config,
+ int status);
#endif /* DLT_OFFLINELOGSTORAGE_DLT_OFFLINE_LOGSTORAGE_BEHAVIOR_H_ */