summaryrefslogtreecommitdiff
path: root/src/system/dlt-system-logfile.c
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@de.adit-jv.com>2018-12-20 14:58:19 +0100
committerChristoph Lipka <clipka@de.adit-jv.com>2018-12-21 10:23:41 +0100
commitdca8ab254aa0a687c32009079d85e4d8f960b213 (patch)
treee63b6a552fd9f61873892110a56a89ef354864cd /src/system/dlt-system-logfile.c
parent0d0c74640c8b792db37cb9f884f89f7561ea551f (diff)
downloadDLT-daemon-dca8ab254aa0a687c32009079d85e4d8f960b213.tar.gz
Code beautification using uncrustify
Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
Diffstat (limited to 'src/system/dlt-system-logfile.c')
-rw-r--r--src/system/dlt-system-logfile.c152
1 files changed, 75 insertions, 77 deletions
diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c
index 687d739..dae557f 100644
--- a/src/system/dlt-system-logfile.c
+++ b/src/system/dlt-system-logfile.c
@@ -50,7 +50,7 @@
#include <unistd.h>
#include "dlt-system.h"
-// Modes of sending
+/* Modes of sending */
#define SEND_MODE_OFF 0
#define SEND_MODE_ONCE 1
#define SEND_MODE_ON 2
@@ -62,98 +62,96 @@ DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX];
void send_file(LogFileOptions const *fileopt, int n)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, sending file."));
- FILE * pFile;
- DltContext context = logfileContext[n];
- char buffer[1024];
- int bytes;
- int seq = 1;
-
- pFile = fopen((*fileopt).Filename[n],"r");
-
- if(pFile != NULL)
- {
- while (!feof(pFile)) {
- bytes = fread(buffer,1,sizeof(buffer)-1,pFile);
- if(bytes>=0)
- buffer[bytes] = 0;
- else
- buffer[0] = 0;
-
- if(feof(pFile)) {
- DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq*-1), DLT_STRING(buffer));
- break;
- }
- else {
- DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer));
- }
- }
- fclose(pFile);
- }
- else
- {
- DLT_LOG(dltsystem, DLT_LOG_ERROR,
- DLT_STRING("dlt-system-logfile, failed to open file."),
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, sending file."));
+ FILE *pFile;
+ DltContext context = logfileContext[n];
+ char buffer[1024];
+ int bytes;
+ int seq = 1;
+
+ pFile = fopen((*fileopt).Filename[n], "r");
+
+ if (pFile != NULL) {
+ while (!feof(pFile)) {
+ bytes = fread(buffer, 1, sizeof(buffer) - 1, pFile);
+
+ if (bytes >= 0)
+ buffer[bytes] = 0;
+ else
+ buffer[0] = 0;
+
+ if (feof(pFile)) {
+ DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq * -1), DLT_STRING(buffer));
+ break;
+ }
+ else {
+ DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer));
+ }
+ }
+
+ fclose(pFile);
+ }
+ else {
+ DLT_LOG(dltsystem, DLT_LOG_ERROR,
+ DLT_STRING("dlt-system-logfile, failed to open file."),
DLT_STRING((*fileopt).Filename[n]));
- }
+ }
}
void register_contexts(LogFileOptions const *fileopts)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, registering file contexts."));
- int i;
- for(i = 0;i < (*fileopts).Count;i++)
- {
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, registering file contexts."));
+ int i;
+
+ for (i = 0; i < (*fileopts).Count; i++)
DLT_REGISTER_CONTEXT(logfileContext[i], (*fileopts).ContextId[i],
- (*fileopts).Filename[i]);
- }
+ (*fileopts).Filename[i]);
}
void logfile_thread(void *v_conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, in thread."));
- DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, in thread."));
+ DltSystemConfiguration *conf = (DltSystemConfiguration *)v_conf;
register_contexts(&(conf->LogFile));
- int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
- int i;
- for(i = 0;i < conf->LogFile.Count;i++)
- logfile_delays[i] = conf->LogFile.TimeDelay[i];
-
- while(!threads.shutdown)
- {
- sleep(1);
- for(i = 0;i < conf->LogFile.Count;i++)
- {
- if(conf->LogFile.Mode[i] == SEND_MODE_OFF)
- continue;
-
- if(logfile_delays[i] <= 0)
- {
+ int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
+ int i;
+
+ for (i = 0; i < conf->LogFile.Count; i++)
+ logfile_delays[i] = conf->LogFile.TimeDelay[i];
+
+ while (!threads.shutdown) {
+ sleep(1);
+
+ for (i = 0; i < conf->LogFile.Count; i++) {
+ if (conf->LogFile.Mode[i] == SEND_MODE_OFF)
+ continue;
+
+ if (logfile_delays[i] <= 0) {
send_file(&(conf->LogFile), i);
- logfile_delays[i] = conf->LogFile.TimeDelay[i];
- if(conf->LogFile.Mode[i] == SEND_MODE_ONCE)
- conf->LogFile.Mode[i] = SEND_MODE_OFF;
- }
- else
- {
- logfile_delays[i]--;
- }
- }
- }
+ logfile_delays[i] = conf->LogFile.TimeDelay[i];
+
+ if (conf->LogFile.Mode[i] == SEND_MODE_ONCE)
+ conf->LogFile.Mode[i] = SEND_MODE_OFF;
+ }
+ else {
+ logfile_delays[i]--;
+ }
+ }
+ }
}
void start_logfile(DltSystemConfiguration *conf)
{
- DLT_LOG(dltsystem, DLT_LOG_DEBUG,
- DLT_STRING("dlt-system-logfile, starting."));
- DLT_LOG(dltsystem,DLT_LOG_DEBUG,DLT_STRING("Starting thread for logfile"));
- static pthread_attr_t t_attr;
- static pthread_t pt;
- pthread_create(&pt, &t_attr, (void *)logfile_thread, conf);
- threads.threads[threads.count++] = pt;
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG,
+ DLT_STRING("dlt-system-logfile, starting."));
+ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("Starting thread for logfile"));
+ static pthread_attr_t t_attr;
+ static pthread_t pt;
+ pthread_create(&pt, &t_attr, (void *)logfile_thread, conf);
+ threads.threads[threads.count++] = pt;
}