automotive-dlt
dlt_offline_logstorage_behavior.c File Reference
#include <syslog.h>
#include <limits.h>
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include "dlt_offline_logstorage.h"
#include "dlt_offline_logstorage_behavior.h"
Include dependency graph for dlt_offline_logstorage_behavior.c:

Go to the source code of this file.

Functions

void dlt_logstorage_log_file_name (char *log_file_name, DltLogStorageUserConfig *file_config, char *name, int idx)
 
void dlt_logstorage_sort_file_name (DltLogStorageFileList **head)
 
void dlt_logstorage_rearrange_file_name (DltLogStorageFileList **head)
 
unsigned int dlt_logstorage_get_idx_of_log_file (DltLogStorageUserConfig *file_config, char *file)
 
int dlt_logstorage_storage_dir_info (DltLogStorageUserConfig *file_config, char *path, DltLogStorageConfigData *config)
 
int dlt_logstorage_open_log_file (DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int msg_size)
 
int dlt_logstorage_prepare_on_msg (DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int log_msg_size)
 
int dlt_logstorage_write_on_msg (DltLogStorageConfigData *config, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
 
int dlt_logstorage_sync_on_msg (DltLogStorageConfigData *config, int status)
 
int dlt_logstorage_prepare_msg_cache (DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int log_msg_size)
 
int dlt_logstorage_write_msg_cache (DltLogStorageConfigData *config, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
 
int dlt_logstorage_sync_msg_cache (DltLogStorageConfigData *config, int status)
 

Detailed Description

app begin@ Copyright (C) 2015 Advanced Driver Information Technology. This code is developed by Advanced Driver Information Technology. Copyright of Advanced Driver Information Technology, Bosch and DENSO.

DLT offline log storage functionality source file.

Author
Christoph Lipka clipk.nosp@m.a@jp.nosp@m..adit.nosp@m.-jv..nosp@m.com ADIT 2015
Syed Hameed shame.nosp@m.ed@j.nosp@m.p.adi.nosp@m.t-jv.nosp@m..com ADIT 2015

For further information see http://www.genivi.org/. end@

Definition in file dlt_offline_logstorage_behavior.c.

Function Documentation

unsigned int dlt_logstorage_get_idx_of_log_file ( DltLogStorageUserConfig file_config,
char *  file 
)

dlt_logstorage_get_idx_of_log_file

Extract index of log file name passed as input argument

Parameters
filefile name to extract the index from
file_configUser configurations for log file
Returns
index on success, -1 if no index is found

Definition at line 203 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN, DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN, DltLogStorageUserConfig::logfile_delimiter, DltLogStorageUserConfig::logfile_timestamp, and NULL.

Referenced by dlt_logstorage_open_log_file(), and dlt_logstorage_storage_dir_info().

void dlt_logstorage_log_file_name ( char *  log_file_name,
DltLogStorageUserConfig file_config,
char *  name,
int  idx 
)

dlt_logstorage_log_file_name

Create log file name in the form configured by the user <filename><delimiter><index><delimiter><timestamp>.dlt

filename: given in configuration file delimiter: Punctuation characters (configured in dlt.conf) timestamp: yyyy-mm-dd-hh-mm-ss (enabled/disabled in dlt.conf) index: Index len depends on wrap around value in dlt.conf ex: wrap around = 99, index will 01..99

Parameters
log_file_namecontains complete logfile name
file_configUser configurations for log file
namefile name given in configuration file
idxcontinous index of log files @ return None

Definition at line 53 of file dlt_offline_logstorage_behavior.c.

References DLT_MOUNT_PATH_MAX, DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN, DltLogStorageUserConfig::logfile_counteridxlen, DltLogStorageUserConfig::logfile_delimiter, DltLogStorageUserConfig::logfile_maxcounter, DltLogStorageUserConfig::logfile_timestamp, and NULL.

Referenced by dlt_logstorage_open_log_file().

int dlt_logstorage_open_log_file ( DltLogStorageConfigData config,
DltLogStorageUserConfig file_config,
char *  dev_path,
int  msg_size 
)

dlt_logstorage_open_log_file

Open a log file. Check storage directory for already created files and open the oldest if there is enough space to store at least msg_size. Otherwise create a new file, but take configured max number of files into account and remove the oldest file if needed.

Parameters
configDltLogStorageConfigData
file_configUser configurations for log file
dev_pathStorage device path
msg_sizeSize of incoming message
Returns
0 on succes, -1 on error

Definition at line 371 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), dlt_logstorage_get_idx_of_log_file(), dlt_logstorage_log_file_name(), dlt_logstorage_storage_dir_info(), DLT_MOUNT_PATH_MAX, DLT_OFFLINE_LOGSTORAGE_CONFIG_DIR_PATH_LEN, DltLogStorageConfigData::file_name, DltLogStorageConfigData::file_size, DltLogStorageConfigData::log, DltLogStorageUserConfig::logfile_maxcounter, DltLogStorageFileList::next, NULL, DltLogStorageConfigData::num_files, and DltLogStorageConfigData::records.

Referenced by dlt_logstorage_prepare_on_msg().

int dlt_logstorage_prepare_msg_cache ( DltLogStorageConfigData config,
DltLogStorageUserConfig file_config,
char *  dev_path,
int  log_msg_size 
)

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. Create a memory area to cache data.

Parameters
configDltLogStorageConfigData
file_configUser configurations for log file
dev_pathStorage device path
log_msg_sizeSize of log message
Returns
0 on success, -1 on error

Definition at line 680 of file dlt_offline_logstorage_behavior.c.

References DltLogStorageConfigData::cache, dlt_log(), dlt_logstorage_prepare_on_msg(), DltLogStorageConfigData::file_size, g_logstorage_cache_max, g_logstorage_cache_size, DltLogStorageConfigData::log, and NULL.

Referenced by dlt_logstorage_filter_set_strategy().

int dlt_logstorage_prepare_on_msg ( DltLogStorageConfigData config,
DltLogStorageUserConfig file_config,
char *  dev_path,
int  log_msg_size 
)

dlt_logstorage_prepare_on_msg

Prepare the log file for a certain filer. If log file not open or log files max size reached, open a new file.

Parameters
configDltLogStorageConfigData
file_configUser configurations for log file
dev_pathStorage device path
log_msg_sizeSize of log message
Returns
0 on success, -1 on error

Definition at line 539 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), dlt_logstorage_open_log_file(), DltLogStorageConfigData::file_size, DltLogStorageConfigData::log, and NULL.

Referenced by dlt_logstorage_filter_set_strategy(), and dlt_logstorage_prepare_msg_cache().

void dlt_logstorage_rearrange_file_name ( DltLogStorageFileList **  head)

dlt_logstorage_rearrange_file_name

Rearrange the filenames in the order of latest and oldest

Parameters
headLog filename list @ return None

Definition at line 159 of file dlt_offline_logstorage_behavior.c.

References DltLogStorageFileList::idx, DltLogStorageFileList::next, and NULL.

Referenced by dlt_logstorage_storage_dir_info().

void dlt_logstorage_sort_file_name ( DltLogStorageFileList **  head)

dlt_logstorage_sort_file_name

Sort the filenames with index based ascending order (bubble sort)

Parameters
headLog filename list @ return None

Definition at line 116 of file dlt_offline_logstorage_behavior.c.

References DltLogStorageFileList::idx, DltLogStorageFileList::next, and NULL.

Referenced by dlt_logstorage_storage_dir_info().

int dlt_logstorage_storage_dir_info ( DltLogStorageUserConfig file_config,
char *  path,
DltLogStorageConfigData config 
)

dlt_logstorage_storage_dir_info

Read file names of storage directory. Update the file list, arrange it in order of latest and oldest

Parameters
file_configUser configurations for log file
pathPath to storage directory
configDltLogStorageConfigData
Returns
0 on success, -1 on error

Definition at line 268 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), dlt_logstorage_get_idx_of_log_file(), dlt_logstorage_rearrange_file_name(), dlt_logstorage_sort_file_name(), DltLogStorageConfigData::file_name, DltLogStorageUserConfig::logfile_delimiter, DltLogStorageFileList::next, NULL, and DltLogStorageConfigData::records.

Referenced by dlt_logstorage_open_log_file().

int dlt_logstorage_sync_msg_cache ( DltLogStorageConfigData config,
int  status 
)
int dlt_logstorage_sync_on_msg ( DltLogStorageConfigData config,
int  status 
)

dlt_logstorage_sync_on_msg

sync data to disk.

Parameters
configDltLogStorageConfigData
statusStrategy flag
Returns
0 on success, -1 on error

Definition at line 645 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), DLT_LOGSTORAGE_SYNC_ON_MSG, DltLogStorageConfigData::log, and NULL.

Referenced by dlt_logstorage_filter_set_strategy().

int dlt_logstorage_write_msg_cache ( DltLogStorageConfigData config,
unsigned char *  data1,
int  size1,
unsigned char *  data2,
int  size2,
unsigned char *  data3,
int  size3 
)

dlt_logstorage_write_msg_cache

Write the log message.

Parameters
configDltLogStorageConfigData
data1header
size1header size
data2storage header
size2storage header size
data3payload
size3payload size
Returns
0 on success, -1 on error

Definition at line 752 of file dlt_offline_logstorage_behavior.c.

References DltLogStorageConfigData::cache, dlt_log(), DltLogStorageConfigData::file_size, NULL, DltLogStorageCacheFooter::offset, and DltLogStorageCacheFooter::wrap_around_cnt.

Referenced by dlt_logstorage_filter_set_strategy().

int dlt_logstorage_write_on_msg ( DltLogStorageConfigData config,
unsigned char *  data1,
int  size1,
unsigned char *  data2,
int  size2,
unsigned char *  data3,
int  size3 
)

dlt_logstorage_write_on_msg

Write the log message.

Parameters
configDltLogStorageConfigData
data1header
size1header size
data2storage header
size2storage header size
data3payload
size3payload size
Returns
0 on success, -1 on error

Definition at line 602 of file dlt_offline_logstorage_behavior.c.

References dlt_log(), DltLogStorageConfigData::log, and NULL.

Referenced by dlt_logstorage_filter_set_strategy().