summaryrefslogtreecommitdiff
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
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
-rw-r--r--src/console/logstorage/dlt-logstorage-common.c8
-rw-r--r--src/console/logstorage/dlt-logstorage-common.h1
-rw-r--r--src/console/logstorage/dlt-logstorage-ctrl.c84
-rw-r--r--src/daemon/dlt_daemon_client.c29
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c95
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.h30
-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
10 files changed, 364 insertions, 88 deletions
diff --git a/src/console/logstorage/dlt-logstorage-common.c b/src/console/logstorage/dlt-logstorage-common.c
index 592da25..9f472d2 100644
--- a/src/console/logstorage/dlt-logstorage-common.c
+++ b/src/console/logstorage/dlt-logstorage-common.c
@@ -108,7 +108,7 @@ int get_default_event_type(void)
void set_default_event_type(long type)
{
- g_options.event_type = !!type;
+ g_options.event_type = type;
}
char *get_default_path(void)
@@ -119,7 +119,11 @@ char *get_default_path(void)
void set_default_path(char *path)
{
memset(g_options.device_path, 0, DLT_MOUNT_PATH_MAX);
- strncpy(g_options.device_path, path, DLT_MOUNT_PATH_MAX - 1);
+
+ if (path != NULL)
+ {
+ strncpy(g_options.device_path, path, DLT_MOUNT_PATH_MAX - 1);
+ }
}
/* Used by the handlers */
diff --git a/src/console/logstorage/dlt-logstorage-common.h b/src/console/logstorage/dlt-logstorage-common.h
index a1c0994..eaf5bd9 100644
--- a/src/console/logstorage/dlt-logstorage-common.h
+++ b/src/console/logstorage/dlt-logstorage-common.h
@@ -29,6 +29,7 @@
#define EVENT_UNMOUNTING 0
#define EVENT_MOUNTED 1
+#define EVENT_SYNC_CACHE 2
typedef enum
{
diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c
index b213501..1e255b7 100644
--- a/src/console/logstorage/dlt-logstorage-ctrl.c
+++ b/src/console/logstorage/dlt-logstorage-ctrl.c
@@ -61,6 +61,7 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
+#include <getopt.h>
#include <sys/epoll.h>
@@ -365,19 +366,24 @@ static int dlt_logstorage_ctrl_setup_event_loop(void)
static int dlt_logstorage_ctrl_single_request()
{
int ret = 0;
- /* Check if a 'CONF_NAME' file is present at the given path */
- if (!dlt_logstorage_check_config_file(get_default_path()))
- {
- pr_error("No '%s' file available at: %s\n",
- CONF_NAME,
- get_default_path());
- return -1;
- }
- if (!dlt_logstorage_check_directory_permission(get_default_path()))
+ /* in case sync all caches, an empty path is given */
+ if (get_default_event_type() != EVENT_SYNC_CACHE)
{
- pr_error("'%s' is not writable\n", get_default_path());
- return -1;
+ /* Check if a 'CONF_NAME' file is present at the given path */
+ if (!dlt_logstorage_check_config_file(get_default_path()))
+ {
+ pr_error("No '%s' file available at: %s\n",
+ CONF_NAME,
+ get_default_path());
+ return -1;
+ }
+
+ if (!dlt_logstorage_check_directory_permission(get_default_path()))
+ {
+ pr_error("'%s' is not writable\n", get_default_path());
+ return -1;
+ }
}
/* Initializing the communication with the daemon */
@@ -410,17 +416,32 @@ static void usage(void)
"a certain logstorage device\n");
printf("\n");
printf("Options:\n");
- printf(" -c Connection type: connect = 1, disconnect = 0\n");
- printf(" -d[prop] Run as daemon: prop = use proprietary handler\n");
- printf(" 'prop' may be replaced by any meaningful word\n");
- printf(" -e Set ECU ID (Default: %s)\n", DLT_CTRL_DEFAULT_ECUID);
- printf(" -h Usage\n");
- printf(" -p Mount point path\n");
- printf(" -t Specify connection timeout (Default: %ds)\n",
+ printf(" -c --command Connection type: connect = 1, disconnect = 0\n");
+ printf(" -d[prop] --daemonize=prop Run as daemon: prop = use proprietary handler\n");
+ printf(" 'prop' may be replaced by any meaningful word\n");
+ printf(" If prop is not specified, udev will be used\n");
+ printf(" -e --ecuid Set ECU ID (Default: %s)\n", DLT_CTRL_DEFAULT_ECUID);
+ printf(" -h --help Usage\n");
+ printf(" -p --path Mount point path\n");
+ printf(" -s[path] --snapshot=path Sync Logstorage cache\n");
+ printf(" Don't use -s together with -d and -c\n");
+ printf(" -t Specify connection timeout (Default: %ds)\n",
DLT_CTRL_TIMEOUT);
- printf(" -v Set verbose flag (Default:%d)\n", get_verbosity());
+ printf(" -v --verbose Set verbose flag (Default:%d)\n", get_verbosity());
}
+static struct option long_options[] = {
+ {"command", required_argument, 0, 'c'},
+ {"daemonize", optional_argument, 0, 'd'},
+ {"ecuid", required_argument, 0, 'e'},
+ {"help", no_argument, 0, 'h'},
+ {"path", required_argument, 0, 'p'},
+ {"snapshot", optional_argument, 0, 's'},
+ {"timeout", required_argument, 0, 't'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+};
+
/** @brief Parses the application arguments
*
* The arguments are parsed and saved in static structure for future use.
@@ -433,11 +454,27 @@ static void usage(void)
static int parse_args(int argc, char *argv[])
{
int c = -1;
+ int long_index = 0;
- while ((c = getopt(argc, argv, ":t:he:p:d::c:v")) != -1)
+ while ((c = getopt_long(argc,
+ argv,
+ ":s::t:he:p:d::c:v",
+ long_options,
+ &long_index)) != -1)
{
switch (c)
{
+ case 's':
+ set_default_event_type(EVENT_SYNC_CACHE);
+
+ if (optarg != NULL && strlen(optarg) >= DLT_MOUNT_PATH_MAX)
+ {
+ pr_error("Mount path '%s' too long\n", optarg);
+ return -1;
+ }
+
+ set_default_path(optarg);
+ break;
case 't':
set_timeout(strtol(optarg, NULL, 10));
break;
@@ -492,6 +529,13 @@ static int parse_args(int argc, char *argv[])
}
}
+ if (get_default_event_type() == EVENT_SYNC_CACHE &&
+ get_handler_type() != CTRL_NOHANDLER)
+ {
+ pr_error("Sync caches not available in daemon mode\n");
+ return -1;
+ }
+
return 0;
}
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index c92601e..55413c5 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -2050,10 +2050,37 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo
/* Check if log level of running application needs to be reset */
dlt_daemon_logstorage_reset_application_loglevel(daemon, device_index, daemon_local->flags.offlineLogstorageMaxDevices, verbose);
- dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]));
+ dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]),
++ DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose);
}
+ /* Check for cache synchronization request from log storage ctrl app */
+ else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES)
+ {
+ /* trigger logstorage to sync caches */
+ if (dlt_daemon_logstorage_sync_cache(daemon,
+ daemon_local,
+ req->mount_point,
+ verbose) == 0)
+ {
+ dlt_daemon_control_service_response(sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
+ DLT_SERVICE_RESPONSE_OK,
+ verbose);
+ }
+ else
+ {
+ dlt_daemon_control_service_response(sock,
+ daemon,
+ daemon_local,
+ DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
+ DLT_SERVICE_RESPONSE_ERROR,
+ verbose);
+ }
+ }
else
{
dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index a6d799e..6e245eb 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -521,7 +521,9 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon,
"Disable storage device\n");
/* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened,
* therefore remove logstorage device */
- dlt_logstorage_device_disconnected(&(daemon->storage_handle[i]));
+ dlt_logstorage_device_disconnected(
+ &(daemon->storage_handle[i]),
+ DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
}
}
}
@@ -593,9 +595,98 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
if (daemon->storage_handle[i].connection_type ==
DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
{
- dlt_logstorage_device_disconnected(&daemon->storage_handle[i]);
+ dlt_logstorage_device_disconnected(
+ &daemon->storage_handle[i],
+ DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT);
}
}
return 0;
}
+
+int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *mnt_point,
+ int verbose)
+{
+ int i = 0;
+ DltLogStorage *handle = NULL;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL || mnt_point == NULL)
+ {
+ return -1;
+ }
+
+ if (strlen(mnt_point) > 0) /* mount point is given */
+ {
+ handle = dlt_daemon_logstorage_get_device(daemon,
+ daemon_local,
+ mnt_point,
+ verbose);
+ if (handle == NULL)
+ {
+ return -1;
+ }
+ else
+ {
+ if (dlt_logstorage_sync_caches(handle) != 0)
+ {
+ return -1;
+ }
+ }
+ }
+ else /* sync caches for all connected logstorage devices */
+ {
+ for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ if (daemon->storage_handle[i].connection_type ==
+ DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
+ {
+ if (dlt_logstorage_sync_caches(&daemon->storage_handle[i]) != 0)
+ {
+ return -1;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *mnt_point,
+ int verbose)
+{
+ int i = 0;
+ int len1 = 0;
+ int len2 = 0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL || daemon_local == NULL || mnt_point == NULL)
+ {
+ return NULL;
+ }
+
+ len1 = strlen(mnt_point);
+
+ for(i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ len2 = strlen(daemon->storage_handle[i].device_mount_point);
+
+ /* Check if the requested device path is already used as log storage
+ * device. Check for strlen first, to avoid comparison errors when
+ * final '/' is given or not */
+ if (strncmp(daemon->storage_handle[i].device_mount_point,
+ mnt_point,
+ len1 > len2 ? len2 : len1) == 0)
+ {
+ return &daemon->storage_handle[i];
+ }
+ }
+
+ return NULL;
+}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h
index 148abd0..3ab092a 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.h
+++ b/src/daemon/dlt_daemon_offline_logstorage.h
@@ -150,4 +150,34 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
int verbose);
+/**
+ * Sync logstorage caches
+ *
+ * @param daemon Pointer to Dlt Daemon structure
+ * @param daemon_local Pointer to Dlt Daemon Local structure
+ * @param mount_point Logstorage device mount point
+ * @param verbose If set to true verbose information is printed out
+ * @return 0 on success, -1 otherwise
+ */
+int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *mnt_point,
+ int verbose);
+
+/**
+ * dlt_logstorage_get_device
+ *
+ * Get a Logstorage device handle for given the mount point.
+ *
+ * @param daemon Pointer to Dlt Daemon structure
+ * @param daemon_local Pointer to Dlt Daemon Local structure
+ * @param mount_point Logstorage device mount point
+ * @param verbose If set to true verbose information is printed out
+ * @return handle to Logstorage device on success, NULL otherwise
+ */
+DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ char *mnt_point,
+ int verbose);
+
#endif /* DLT_DAEMON_OFFLINE_LOGSTORAGE_H */
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_ */