automotive-dlt
dlt_offline_logstorage.h
Go to the documentation of this file.
1 
23 /*******************************************************************************
24 ** **
25 ** SRC-MODULE: dlt_offline_logstorage.h **
26 ** **
27 ** TARGET : linux **
28 ** **
29 ** PROJECT : DLT **
30 ** **
31 ** AUTHOR : Syed Hameed shameed@jp.adit-jv.com **
32 ** Christoph Lipka clipka@jp.adit-jv.com **
33 ** PURPOSE : **
34 ** **
35 ** REMARKS : **
36 ** **
37 ** PLATFORM DEPENDANT [yes/no]: yes **
38 ** **
39 ** TO BE CHANGED BY USER [yes/no]: no **
40 ** **
41 *******************************************************************************/
42 
43 /*******************************************************************************
44 ** Author Identity **
45 ********************************************************************************
46 ** **
47 ** Initials Name Company **
48 ** -------- ------------------------- ---------------------------------- **
49 ** sh Syed Hameed ADIT **
50 ** cl Christoph Lipka ADIT **
51 *******************************************************************************/
52 
53 #ifndef DLT_OFFLINE_LOGSTORAGE_H
54 #define DLT_OFFLINE_LOGSTORAGE_H
55 
56 #include <search.h>
57 #include "dlt_common.h"
58 #include "dlt-daemon_cfg.h"
59 
60 #define DLT_OFFLINE_LOGSTORAGE_MAXFILTERS 100 /* Maximum entries in hashmap */
61 
62 #define DLT_OFFLINE_LOGSTORAGE_INIT_DONE 1 /* For device configuration status */
63 #define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED 1
64 #define DLT_OFFLINE_LOGSTORAGE_FREE 0
65 #define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED 0
66 #define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE 1
67 
68 #define DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES 2 /* sync logstorage caches */
69 
70 #define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN 10 /* Maximum size for key */
71 #define DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN 50 /* Maximum file name length of the log file */
72 
73 #define DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN 4
74 #define DLT_OFFLINE_LOGSTORAGE_INDEX_LEN 3
75 #define DLT_OFFLINE_LOGSTORAGE_MAX_INDEX 999
76 #define DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN 16
77 #define DLT_OFFLINE_LOGSTORAGE_INDEX_OFFSET (DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + \
78  DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + \
79  DLT_OFFLINE_LOGSTORAGE_INDEX_LEN)
80 #define DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN (DLT_OFFLINE_LOGSTORAGE_MAX_FILE_NAME_LEN + \
81  DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + \
82  DLT_OFFLINE_LOGSTORAGE_INDEX_LEN + \
83  DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + 1)
84 
85 #define DLT_OFFLINE_LOGSTORAGE_FILTER_UNINIT 0
86 #define DLT_OFFLINE_LOGSTORAGE_ECUID (1<<8)
87 #define DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT (1<<7)
88 #define DLT_OFFLINE_LOGSTORAGE_APP_INIT (1<<6)
89 #define DLT_OFFLINE_LOGSTORAGE_CTX_INIT (1<<5)
90 #define DLT_OFFLINE_LOGSTORAGE_LOG_LVL_INIT (1<<4)
91 #define DLT_OFFLINE_LOGSTORAGE_NAME_INIT (1<<3)
92 #define DLT_OFFLINE_LOGSTORAGE_SIZE_INIT (1<<2)
93 #define DLT_OFFLINE_LOGSTORAGE_SYNC_BEHAVIOR (1<<1)
94 #define DLT_OFFLINE_LOGSTORAGE_NUM_INIT 1
95 /* Sync behavior and ECUid are optional */
96 #define DLT_OFFLINE_LOGSTORAGE_FILTER_INIT 0xFD
97 
98 #define DLT_OFFLINE_LOGSTORAGE_FILTER_INITIALIZED(A) ((A) >= DLT_OFFLINE_LOGSTORAGE_FILTER_INIT)
99 
100 #define DLT_OFFLINE_LOGSTORAGE_IS_FILTER_PRESENT(A) ((A) & DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT)
101 
102 #define DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN 50
103 #define DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME "dlt_logstorage.conf"
104 
105 /* +3 because of device number and \0 */
106 #define DLT_OFFLINE_LOGSTORAGE_MAX_PATH_LEN (DLT_OFFLINE_LOGSTORAGE_MAX_LOG_FILE_LEN + \
107  DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN + 3)
108 
109 #define DLT_OFFLINE_LOGSTORAGE_MAX(A, B) ((A) > (B) ? (A) : (B))
110 #define DLT_OFFLINE_LOGSTORAGE_MIN(A, B) ((A) < (B) ? (A) : (B))
111 
112 #define DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS 5
113 #define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM 8
114 
115 #define DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION "FILTER"
116 #define DLT_OFFLINE_LOGSTORAGE_GENERAL_CONFIG_SECTION "GENERAL"
117 
118 /* Offline Logstorage sync strategies */
119 #define DLT_LOGSTORAGE_SYNC_ON_ERROR -1 /* error case */
120 #define DLT_LOGSTORAGE_SYNC_ON_MSG 1 /* default, on message sync */
121 #define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT (1<<1) /* sync on daemon exit */
122 #define DLT_LOGSTORAGE_SYNC_ON_DEMAND (1<<2) /* sync on demand */
123 #define DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT (1<<3) /* sync on device disconnect*/
124 
125 #define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S) & (s))
126 
127 /* logstorage max cache */
129 /* current logstorage cache size */
131 
132 typedef struct
133 {
134  int offset; /* current write offset */
135  unsigned int wrap_around_cnt; /* wrap around counter */
137 
138 typedef struct
139 {
140  /* File name user configurations */
141  int logfile_timestamp; /* Timestamp set/reset */
142  char logfile_delimiter; /* Choice of delimiter */
143  unsigned int logfile_maxcounter; /* Maximum file index counter */
144  unsigned int logfile_counteridxlen; /* File index counter length */
146 
147 typedef struct DltLogStorageFileList
148 {
149  /* List for filenames */
150  char *name; /* Filename */
151  unsigned int idx; /* File index */
154 
156 
158 {
159  /* filter section */
160  int log_level; /* Log level number configured for filter */
161  char *file_name; /* File name for log storage configured for filter */
162  unsigned int file_size; /* MAX File size of storage file configured for filter */
163  unsigned int num_files; /* MAX number of storage files configured for filters */
164  int sync; /* Sync strategy */
165  char *ecuid; /* ECU identifier */
166  /* callback function for filter configurations */
167  int (*dlt_logstorage_prepare)(DltLogStorageConfigData *config,
168  DltLogStorageUserConfig *file_config,
169  char *dev_path,
170  int log_msg_size);
172  unsigned char *data1,
173  int size1,
174  unsigned char *data2,
175  int size2,
176  unsigned char *data3,
177  int size3);
178  /* status is strategy, e.g. DLT_LOGSTORAGE_SYNC_ON_MSG is used when callback
179  * is called on message received */
180  int (*dlt_logstorage_sync)(DltLogStorageConfigData *config, int status);
181  FILE *log; /* current open log file */
182  void *cache; /* log data cache */
183  DltLogStorageFileList *records; /* File name list */
184 };
185 
186 
187 typedef struct
188 {
189  char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN]; /* Keys stored in hash table */
190  DltLogStorageConfigData data; /* Data stored in hash table */
192 
193 
194 typedef struct
195 {
196  struct hsearch_data config_htab; /* Hash table object declaration used by hsearch_r()*/
197  DltLogStorageConfig *config_data; /* Configuration data */
198  char *filter_keys; /* List of all keys stored in config_htab */
199  int num_filter_keys; /* Number of keys */
200  char device_mount_point[DLT_MOUNT_PATH_MAX]; /* Device mount path */
201  unsigned int connection_type; /* Type of connection */
202  unsigned int config_status; /* Status of configuration */
203  int write_errors; /* number of write errors */
205 
216 extern int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point);
217 
226 extern int dlt_logstorage_load_config(DltLogStorage *handle);
235 extern int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason);
250 extern DltLogStorageConfigData **dlt_logstorage_get_config(DltLogStorage *handle, char *apid, char *ctid, int *num_config);
262 extern int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key);
263 
278 extern int dlt_logstorage_write(DltLogStorage *handle,
279  DltLogStorageUserConfig *uconfig,
280  unsigned char *data1,
281  int size1,
282  unsigned char *data2,
283  int size2,
284  unsigned char *data3,
285  int size3);
286 
295 extern int dlt_logstorage_sync_caches(DltLogStorage *handle);
296 
297 #endif /* DLT_OFFLINE_LOGSTORAGE_H */
unsigned int g_logstorage_cache_size
DltKpiConfig config
Definition: dlt-kpi.c:37
DltLogStorageConfigData ** dlt_logstorage_get_config(DltLogStorage *handle, char *apid, char *ctid, int *num_config)
int dlt_logstorage_sync_caches(DltLogStorage *handle)
unsigned int connection_type
DltLogStorageConfig * config_data
int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
DltLogStorageFileList * records
#define DLT_MOUNT_PATH_MAX
Definition: dlt_common.h:332
int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason)
int dlt_logstorage_write(DltLogStorage *handle, DltLogStorageUserConfig *uconfig, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
int dlt_logstorage_load_config(DltLogStorage *handle)
int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key)
unsigned int config_status
DltLogStorageConfigData data
#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN
unsigned int g_logstorage_cache_max
struct DltLogStorageFileList * next
struct DltLogStorageFileList DltLogStorageFileList