diff options
author | Lassi Marttala <lassi.lm.marttala@partner.bmw.de> | 2012-05-16 10:10:12 +0200 |
---|---|---|
committer | Christian Muck <christian.muck@bmw.de> | 2012-06-13 23:50:08 +0200 |
commit | f8f80a07afd45d60c2975bfd7e4b859fb8c10a96 (patch) | |
tree | 832f4103d0c8c1662c58ec9645fe20f510ace49c /src/system/dlt-system-logfile.c | |
parent | 9141005cf22f379059c27aa4a82111a13e760883 (diff) | |
download | DLT-daemon-f8f80a07afd45d60c2975bfd7e4b859fb8c10a96.tar.gz |
[GDLT-67] dlt-system v2.0, check full commit message for rebase details
[GDLT-67] Prepare build system.
[GDLT-67] Config parsing, structure for thread handling
[GDLT-67] Finalize configuration reading.
[GDLT-67] Reimplementation of syslog, logfile, logprocess, shell.
[GDLT-67] First complete version of the new dlt-system.
[GDLT-67] Fixed header comments. authors, file names.
[GDLT-67] Final touches.
[GDLT-67] Fixed a problem with thread creation in optimized release binary.
[GDLT-67] New configuration file.
[GDLT-67] Added dlt debug output
Signed-off-by: Christian Muck <christian.muck@bmw.de>
Diffstat (limited to 'src/system/dlt-system-logfile.c')
-rw-r--r-- | src/system/dlt-system-logfile.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c new file mode 100644 index 0000000..8872d20 --- /dev/null +++ b/src/system/dlt-system-logfile.c @@ -0,0 +1,148 @@ +/** + * @licence app begin@ + * Copyright (C) 2012 BMW AG + * + * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Lassi Marttala <lassi.lm.marttala@partner.bmw.de> BMW 2012 + * + * \file dlt-system-logfile.c + * For further information see http://www.genivi.org/. + * @licence end@ + */ + +/******************************************************************************* +** ** +** SRC-MODULE: dlt-system-logfile.c ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Lassi Marttala <lassi.lm.marttala@partner.bmw.de> ** +** Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + + +#include <pthread.h> +#include <unistd.h> +#include "dlt-system.h" + +// Modes of sending +#define SEND_MODE_OFF 0 +#define SEND_MODE_ONCE 1 +#define SEND_MODE_ON 2 + +DLT_IMPORT_CONTEXT(dltsystem); + +extern DltSystemThreads threads; +DltContext logfileContext[DLT_SYSTEM_LOG_FILE_MAX]; + +void send_file(LogFileOptions 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>0) + { + 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)); + } + else { + DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer)); + } + } + fclose(pFile); + } +} + +void register_contexts(LogFileOptions 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_REGISTER_CONTEXT(logfileContext[i], fileopts.ContextId[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; + + 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) + { + 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]--; + } + } + } +} + +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; +} |