summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Koch <mkoch@de.adit-jv.com>2020-01-13 11:31:48 +0100
committerMartin Koch <mkoch@de.adit-jv.com>2020-01-14 15:25:58 +0100
commit522a451d6b5f6e67a87310effac47bcd6490cde2 (patch)
treea08f4722d7574b3ca59a5e80c6c1527286bebcdc
parent06bbfdafdef58891799c70d115c82a670488b09b (diff)
downloadaudiomanager-522a451d6b5f6e67a87310effac47bcd6490cde2.tar.gz
AM_Utils: reduce CAmDltWrapper to legacy wrapper around new logging architecture
Signed-off-by: Martin Koch <mkoch@de.adit-jv.com>
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h358
-rwxr-xr-xAudioManagerUtilities/include/IAmLogger.h3
-rw-r--r--AudioManagerUtilities/src/CAmDltWrapper.cpp750
3 files changed, 90 insertions, 1021 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index a86b4dc..1b65ec1 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -5,6 +5,7 @@
*
* \author Christian Linke, christian.linke@bmw.de BMW 2011,2012
* \author Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2014
+ * \author Martin Koch, mkoch@de.adit-jv.com ADIT 2020
*
* \copyright
* This Source Code Form is subject to the terms of the
@@ -12,6 +13,11 @@
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* \file CAmDltWrapper.h
+ * This file is reduced to a legacy wrapper around the new logging architecture
+ * to establish compatibility with plugins and applications developed for audio-manager
+ * versions before 7.7.0.\n
+ * For new development use CAmLogWrapper instead.
+ *
* For further information see http://www.genivi.org/.
*/
@@ -19,14 +25,12 @@
#define DLTWRAPPER_H_
#include <string>
-#include <pthread.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <map>
-#include <vector>
-#include <audiomanagerconfig.h>
-#include "audiomanagertypes.h"
+
+#include "CAmLogWrapper.h"
#ifdef WITH_DLT
# include <dlt.h>
@@ -34,6 +38,7 @@
# include <stdint.h>
# include <sstream>
+# define DLT_ID_SIZE 4
# define DLT_USER_BUF_MAX_SIZE 2048
/**
@@ -57,20 +62,6 @@ typedef enum
} DltTraceStatusType;
/**
- * This structure is used for context data used in an application.
- */
-typedef struct
-{
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char *context_description; /**< description of context */
-} DltContextData;
-
-/**
* Definitions of DLT log level
*/
typedef enum
@@ -106,21 +97,6 @@ namespace am
class CAmDltWrapper
{
public:
-
- /**
- * This structure is used for context data used in an application.
- */
- typedef struct
- {
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char *context_description; /**< description of context */
- } NoDltContextData;
-
/*
* The eunum gives the logtype
*/
@@ -151,7 +127,7 @@ public:
* register a context
*/
void registerContext(DltContext &handle, const char *contextid, const char *description);
- void registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status);
+ void registerContext(DltContext &handle, const char *contextid, const char *description, DltLogLevelType level, DltTraceStatusType status);
void unregisterContext(DltContext &handle);
bool getEnabled();
@@ -161,335 +137,63 @@ public:
bool checkLogLevel(DltLogLevelType logLevel)
{
-#ifdef WITH_DLT
-# ifdef DLT_IS_LOG_LEVEL_ENABLED
- return (dlt_user_is_logLevel_enabled(&mDltContext, logLevel) == DLT_RETURN_TRUE);
-# else
- (void)logLevel;
- return true;
-# endif
-#else // ifdef WITH_DLT
- return (logLevel <= mDltContext.log_level_user);
-#endif // ifdef WITH_DLT
- }
-
- void deinit();
- void send();
- void append(const int8_t value);
- void append(const uint8_t value);
- void append(const int16_t value);
- void append(const uint16_t value);
- void append(const int32_t value);
- void append(const uint32_t value);
- void append(const uint64_t value);
- void append(const int64_t value);
- void append(const std::string &value);
- void append(const bool value);
- void append(const std::vector<uint8_t> &data);
-
- template<class T>
- void appendNoDLT(T value)
- {
- mNoDltContextData.buffer << value << " ";
- }
-
- // specialization for const char*
- template<typename T = const char *>
- void append(const char *value)
- {
-#ifdef WITH_DLT
- if (mlogDestination == logDestination::DAEMON)
+ if (mpCurrentContext)
{
- dlt_user_log_write_string(&mDltContextData, value);
+ return mpCurrentContext->checkLogLevel(static_cast<am_LogLevel_e>(logLevel));
}
else
{
- mNoDltContextData.buffer << std::string(value);
- }
-#else // ifdef WITH_DLT
- mNoDltContextData.buffer << std::string(value);
-#endif // WITH_DLT
-
- }
-
-private:
- static const std::vector<const char *> mStr_error;
- static const std::vector<const char *> mStr_sourceState;
- static const std::vector<const char *> mStr_MuteState;
- static const std::vector<const char *> mStr_DomainState;
- static const std::vector<const char *> mStr_ConnectionState;
- static const std::vector<const char *> mStr_Availability;
- static const std::vector<const char *> mStr_Interrupt;
- static const std::vector<const char *> mStr_Handle;
- static const std::vector<const char *> mStr_NotificationStatus;
-
-public:
-
- // specialization for const am_Error_e
- template<typename T = const am_Error_e>
- void append(const am_Error_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_error.size())
- {
- std::ostringstream ss;
- ss << "value for am_Error_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_error[value]);
- }
-
- // specialization for const am_Error_e
- template<typename T = const am_SourceState_e>
- void append(const am_SourceState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_sourceState.size())
- {
- std::ostringstream ss;
- ss << "value for am_SourceState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_sourceState[value]);
- }
-
- template<typename T = const am_MuteState_e>
- void append(const am_MuteState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_MuteState.size())
- {
- std::ostringstream ss;
- ss << "value for am_MuteState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_MuteState[value]);
- }
-
- template<typename T = const am_DomainState_e>
- void append(const am_DomainState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_DomainState.size())
- {
- std::ostringstream ss;
- ss << "value for am_DomainState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
-
- return;
- }
-
- append(mStr_DomainState[value]);
- }
-
- template<typename T = const am_ConnectionState_e>
- void append(const am_ConnectionState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_ConnectionState.size())
- {
- std::ostringstream ss;
- ss << "value for am_ConnectionState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_ConnectionState[value]);
- }
-
- template<typename T = const am_Availability_e>
- void append(const am_Availability_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Availability.size())
- {
- std::ostringstream ss;
- ss << "value for am_Availability_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_Availability[value]);
- }
-
- template<typename T = const am_InterruptState_e>
- void append(const am_InterruptState_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Interrupt.size())
- {
- std::ostringstream ss;
- ss << "value for am_InterruptState_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
- }
-
- append(mStr_Interrupt[value]);
- }
-
- template<typename T = const am_Handle_e>
- void append(const am_Handle_e value)
- {
- if (static_cast<std::size_t>(value) >= mStr_Handle.size())
- {
- std::ostringstream ss;
- ss << "value for am_Handle_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
+ return getLogger()->importContext().checkLogLevel(static_cast<am_LogLevel_e>(logLevel));
}
-
- append(mStr_Handle[value]);
}
- template<typename T = const am_Handle_s>
- void append(const am_Handle_s value)
- {
- append(value.handleType);
- append(value.handle);
- }
+ void deinit();
+ void send();
- template<typename T = const am_NotificationStatus_e>
- void append(const am_NotificationStatus_e value)
+ template<typename... TArgs>
+ void append(TArgs... args)
{
- if (static_cast<std::size_t>(value) >= mStr_NotificationStatus.size())
+ if (mpCurrentContext)
{
- std::ostringstream ss;
- ss << "value for am_NotificationStatus_e out of bounds! " << std::dec << (size_t)value;
- append(ss.str().c_str());
- return;
+ mpCurrentContext->append(args...);
}
-
- append(mStr_NotificationStatus[value]);
}
- // Template to print unknown pointer types with their address
- template<typename T>
- void append(T *value)
- {
- std::ostringstream ss;
- ss << "0x" << std::hex << (uint64_t)value;
- append(ss.str().c_str());
- }
-
- // Template to print unknown types
- template<typename T>
- void append(T value)
- {
- std::ostringstream ss;
- ss << std::dec << static_cast<int>(value);
- append(ss.str().c_str());
- }
-
- // Template parameter pack to generate recursive code
- void append(void) {}
- template<typename T, typename... TArgs>
- void append(T value, TArgs... args)
- {
- this->append(value);
- this->append(args...);
- }
private:
/**
* private contructor
*/
- CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename = "", bool onlyError = false); // is private because of singleton pattern
- bool initNoDlt(DltLogLevelType loglevel, DltContext *context);
- std::string now();
+ CAmDltWrapper(IAmLogger *pLogger, bool debugEnabled, bool onlyError = false); // is private because of singleton pattern
- DltContext mDltContext; //!< the default context
- DltContextData mDltContextData; //!< contextdata
- NoDltContextData mNoDltContextData; //!< contextdata for std out logging
+ IAmLogger *mpLogger; //!< pointer to underlying logger instance
+ IAmLogContext *mpCurrentContext; //!< context for direct init(), append(...) and send() operations
std::map<DltContext *, std::string> mMapContext; //!< a Map for all registered context
bool mDebugEnabled; //!< debug Enabled or not
- logDestination mlogDestination; //!< The log destination
- std::ofstream mFilename; //!< Filename for logging
bool mOnlyError; //!< Only if Log Level is above Error
- bool mLogOn; //!< Used to keep track if currently logging is on
static CAmDltWrapper *mpDLTWrapper; //!< pointer to the wrapper instance
- static pthread_mutex_t mMutex;
-
};
/**
* logs given values with a given context (register first!) and given loglevel
* @param context
* @param loglevel
- * @param value
- * @param ...
+ * @param ... args
*/
-template<typename T, typename... TArgs>
-void log(DltContext *const context, DltLogLevelType loglevel, T value, TArgs... args)
+template<typename... TArgs>
+void log(DltContext *const context, DltLogLevelType loglevel, TArgs... args)
{
- CAmDltWrapper *inst(CAmDltWrapper::instance());
- if (!inst->getEnabled())
- {
- return;
- }
-
- if (!inst->init(loglevel, context))
+ std::string contextID;
+ if (context)
{
- return;
+ contextID = std::string(context->contextID, DLT_ID_SIZE);
}
- inst->append(value);
- inst->append(args...);
- inst->send();
-}
-
-/**
- * logs given values with debuglevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logDebug(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_DEBUG, value, args...);
-}
-
-/**
- * logs given values with infolevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logInfo(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_INFO, value, args...);
+ // delegate to dedicated logging context
+ getLogger()->importContext(contextID.c_str())
+ .log(static_cast<am_LogLevel_e>(loglevel), args...);
}
-/**
- * logs given values with errorlevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logError(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_ERROR, value, args...);
-}
-
-/**
- * logs given values with warninglevel with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logWarning(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_WARN, value, args...);
-}
-
-/**
- * logs given values with verbose with the default context
- * @param value
- * @param ...
- */
-template<typename T, typename... TArgs>
-void logVerbose(T value, TArgs... args)
-{
- log(NULL, DLT_LOG_VERBOSE, value, args...);
-}
}
diff --git a/AudioManagerUtilities/include/IAmLogger.h b/AudioManagerUtilities/include/IAmLogger.h
index 95af6b9..4517657 100755
--- a/AudioManagerUtilities/include/IAmLogger.h
+++ b/AudioManagerUtilities/include/IAmLogger.h
@@ -65,6 +65,9 @@ enum am_LogStatus_e
class IAmLogContext
{
+ // enable cooperation with legacy class CAmDltWrapper
+ friend class CAmDltWrapper;
+
public:
virtual ~IAmLogContext() {}
diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp
index fff4a57..9a57242 100644
--- a/AudioManagerUtilities/src/CAmDltWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp
@@ -22,134 +22,26 @@
*
*/
-#include <string>
-#include <iostream>
#include <string.h>
-#include <chrono>
-#include <ctime>
-#include <sys/types.h>
#include <unistd.h>
#include "CAmDltWrapper.h"
-namespace am
-{
-CAmDltWrapper *CAmDltWrapper::mpDLTWrapper = NULL;
-pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER;
+using namespace std;
-const std::vector<const char *> CAmDltWrapper::mStr_error =
-{
- "E_OK",
- "E_UNKNOWN",
- "E_OUT_OF_RANGE",
- "E_NOT_USED",
- "E_DATABASE_ERROR",
- "E_ALREADY_EXISTS",
- "E_NO_CHANGE",
- "E_NOT_POSSIBLE",
- "E_NON_EXISTENT",
- "E_ABORTED",
- "E_WRONG_FORMAT",
- "E_COMMUNICATION",
- "E_MAX"
-};
-const std::vector<const char *> CAmDltWrapper::mStr_sourceState =
-{
- "SS_UNKNNOWN",
- "SS_ON",
- "SS_OFF",
- "SS_PAUSED",
- "SS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_MuteState =
-{
- "MS_UNKNOWN",
- "MS_MUTED",
- "MS_UNMUTED",
- "MS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_DomainState =
-{
- "DS_UNKNOWN",
- "DS_CONTROLLED",
- "DS_INDEPENDENT_STARTUP",
- "DS_INDEPENDENT_RUNDOWN",
- "DS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_ConnectionState =
-{
- "CS_UNKNOWN",
- "CS_CONNECTING",
- "CS_CONNECTED",
- "CS_DISCONNECTING",
- "CS_DISCONNECTED",
- "CS_SUSPENDED",
- "CS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Availability =
-{
- "A_UNKNOWN",
- "A_AVAILABLE",
- "A_UNAVAILABLE",
- "A_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Interrupt =
-{
- "IS_UNKNOWN",
- "IS_OFF",
- "IS_INTERRUPTED",
- "IS_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_Handle =
-{
- "H_UNKNOWN",
- "H_CONNECT",
- "H_DISCONNECT",
- "H_SETSOURCESTATE",
- "H_SETSINKVOLUME",
- "H_SETSOURCEVOLUME",
- "H_SETSINKSOUNDPROPERTY",
- "H_SETSOURCESOUNDPROPERTY",
- "H_SETSINKSOUNDPROPERTIES",
- "H_SETSOURCESOUNDPROPERTIES",
- "H_CROSSFADE",
- "H_SETVOLUMES",
- "H_SETSINKNOTIFICATION",
- "H_SETSOURCENOTIFICATION",
- "H_MAX"
-};
-
-const std::vector<const char *> CAmDltWrapper::mStr_NotificationStatus =
+namespace am
{
- "NS_UNKNOWN",
- "NS_OFF",
- "NS_PERIODIC",
- "NS_MINIMUM",
- "NS_MAXIMUM",
- "NS_CHANGE",
- "NS_MAX"
-};
+CAmDltWrapper *CAmDltWrapper::mpDLTWrapper = NULL;
-std::string CAmDltWrapper::now()
-{
- std::time_t t(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
- struct tm *timeinfo(localtime(&t));
- char buffer[80];
- std::strftime(buffer, 80, "%D %T ", timeinfo);
- return (std::string(buffer));
-}
CAmDltWrapper *CAmDltWrapper::instanctiateOnce(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
{
if (!mpDLTWrapper)
{
- mpDLTWrapper = new CAmDltWrapper(appid, description, debugEnabled, logDest, Filename, onlyError);
+ IAmLogger *pLogger = CAmLogWrapper::instantiateOnce(appid, description
+ , (debugEnabled ? LS_ON : LS_OFF), static_cast<am_LogService_e>(logDest)
+ , Filename, onlyError);
+ mpDLTWrapper = new CAmDltWrapper(pLogger, debugEnabled, onlyError);
}
return (mpDLTWrapper);
@@ -162,8 +54,8 @@ CAmDltWrapper *CAmDltWrapper::instance()
// an application seems not to use our CAmDltWrapper class therefore create default
std::ostringstream description;
description << "PID=" << getpid() << " _=" << getenv("_");
- mpDLTWrapper = new CAmDltWrapper("AMDL", description.str().c_str());
- std::cerr << "Application doesn't call CAmDltWrapper::instanciateOnce!!!" << std::endl;
+ mpDLTWrapper = instanctiateOnce("AMDL", description.str().c_str());
+ std::cerr << "Application doesn't call CAmDltWrapper::instanctiateOnce!!!" << std::endl;
std::cerr << "-> CAmDltWrapper::instance registers DLT application [ AMDL | " << description.str() << " ]" << std::endl;
}
@@ -175,639 +67,109 @@ bool CAmDltWrapper::getEnabled()
return (mDebugEnabled);
}
-bool CAmDltWrapper::initNoDlt(DltLogLevelType loglevel, DltContext *context)
+CAmDltWrapper::CAmDltWrapper(IAmLogger *pLogger, bool debugEnabled, bool onlyError)
+ : mpLogger(pLogger)
+ , mpCurrentContext(NULL)
+ , mDebugEnabled(debugEnabled)
+ , mOnlyError(onlyError)
{
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- if (!context)
- {
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "\033[0;31m" << "[DEF] [Erro] \033[0m";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;33m" << "[DEF] [Warn] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;36m" << "[DEF] [Info] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;32m" << "[DEF] [Defa] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
- else
- {
- std::string con(mMapContext.at(context));
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "\033[0;31m[" << con << "] [Erro] \033[0m";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;33m[" << con << "] [Warn] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;36m[" << con << "] [Info] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "\033[0;32m[" << con << "] [Defa] \033[0m";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
-
- return true;
- }
- else
- {
- if (!context)
- {
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "[DEF] [Erro] ";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Warn] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Info] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[DEF] [Defa] ";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
- else
- {
- std::string con(mMapContext.at(context));
- switch (loglevel)
- {
- case DLT_LOG_OFF:
- case DLT_LOG_FATAL:
- case DLT_LOG_ERROR:
- mNoDltContextData.buffer << "[" << con << "] [Erro] ";
- mLogOn = true;
- break;
- case DLT_LOG_WARN:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Warn] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- case DLT_LOG_INFO:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Info] ";
- }
- else
- {
- mLogOn = false;
- }
-
- break;
- default:
- if (!mOnlyError)
- {
- mNoDltContextData.buffer << "[" << con << "] [Defa] ";
- }
- else
- {
- mLogOn = false;
- }
- }
- }
-
- return true;
- }
}
-#ifdef WITH_DLT
-CAmDltWrapper::CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
- : mDebugEnabled(debugEnabled)
- , //
- mlogDestination(logDest)
- , //
- mFilename(NULL)
- , //
- mOnlyError(onlyError)
- , //
- mLogOn(true)
+CAmDltWrapper::~CAmDltWrapper()
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
+ for (auto context : mMapContext)
{
- dlt_register_app(appid, description);
- // register a default context
- dlt_register_context(&mDltContext, "DEF", "Default Context registered by DLTWrapper Class");
+ unregisterContext(*(context.first));
}
- else if (mDebugEnabled)
- {
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering AppID " << appid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
- if (!mFilename.is_open())
- {
- throw std::runtime_error("Cannot open file for logging");
- }
- mFilename << now() << "[DLT] Registering AppID " << appid << " , " << description << std::endl;
- }
- }
-}
+ delete mpLogger;
+ mpLogger = NULL;
-CAmDltWrapper::~CAmDltWrapper()
-{
- if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- mpDLTWrapper->unregisterContext(mDltContext);
- delete mpDLTWrapper;
- }
- else if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::COMMAND_LINE)
- {
- mFilename.close();
- }
+ mpDLTWrapper = NULL;
}
void CAmDltWrapper::unregisterContext(DltContext &handle)
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
+ if (mpLogger)
{
- dlt_unregister_context(&handle);
+ string ctxID(handle.contextID, DLT_ID_SIZE);
+ mpLogger->unregisterContext(ctxID.c_str());
+ mMapContext.erase(&handle);
}
}
void CAmDltWrapper::deinit()
{
- if (mDebugEnabled)
+ if (mpCurrentContext)
{
- unregisterContext(mDltContext);
+ mpCurrentContext->configure(mOnlyError ? LL_ERROR : LL_INFO);
}
+ mpCurrentContext = NULL;
}
void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description)
{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- dlt_register_context(&handle, contextid, description);
- }
- else if (mDebugEnabled)
- {
- mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << "[DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
- }
-}
-
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status)
-{
- if (mDebugEnabled && mlogDestination == logDestination::DAEMON)
- {
- dlt_register_context_ll_ts(&handle, contextid, description, level, status);
- }
- else if (mDebugEnabled)
+ if (mpLogger)
{
+ mpLogger->registerContext(contextid, description);
+ size_t len = min(DLT_ID_SIZE, 1 + (int)strlen(contextid));
+ strncpy(handle.contextID, contextid, len);
mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << " [DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
}
}
-bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
+void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description
+ , DltLogLevelType level, DltTraceStatusType status)
{
- pthread_mutex_lock(&mMutex);
- if (mlogDestination == logDestination::DAEMON)
+ if (mpLogger)
{
- if (!context)
+ if (level == DLT_LOG_DEFAULT)
{
- context = &mDltContext;
+ logWarning("CAmDltWrapper::registerContext - understanding DLT_LOG_DEFAULT as DLT_LOG_INFO");
+ level = DLT_LOG_INFO;
}
-
- if (dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0)
+ if (status == DLT_TRACE_STATUS_DEFAULT)
{
- pthread_mutex_unlock(&mMutex);
- return false;
+ logError("CAmDltWrapper::registerContext - understanding DLT_TRACE_STATUS_DEFAULT as DLT_TRACE_STATUS_ON");
+ status = DLT_TRACE_STATUS_ON;
}
- }
- else
- {
- initNoDlt(loglevel, context);
- }
-
- return true;
-}
-void CAmDltWrapper::send()
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_finish(&mDltContextData);
- }
- else
- {
- if (mlogDestination == logDestination::COMMAND_LINE && mLogOn)
- {
- std::cout << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
- else if (mLogOn)
- {
- mFilename << now() << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
-
- mNoDltContextData.buffer.str("");
- mNoDltContextData.buffer.clear();
- }
-
- pthread_mutex_unlock(&mMutex);
-}
-
-void CAmDltWrapper::append(const int8_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int8(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint8_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint8(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int16_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int16(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint16_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint16(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int32_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int32(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint32_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint32(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const std::string &value)
-{
- append(value.c_str());
-}
-
-void CAmDltWrapper::append(const bool value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const int64_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_int64(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const uint64_t value)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_uint64(&mDltContextData, value);
- }
- else
- {
- appendNoDLT(value);
- }
-}
-
-void CAmDltWrapper::append(const std::vector<uint8_t> &data)
-{
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_raw(&mDltContextData, (void *)data.data(), data.size());
- }
- else
- {
- mNoDltContextData.buffer << data.data();
- }
-}
-
-}
-#else // ------------------------------------------------------------------------------------------------- no DLT !
-CAmDltWrapper::CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled, const logDestination logDest, const std::string Filename, bool onlyError)
- : mDebugEnabled(debugEnabled)
- , //
- mlogDestination(logDest)
- , //
- mFilename(NULL)
- , //
- mOnlyError(onlyError)
- , //
- mLogOn(true)
-{
- if (logDest == logDestination::DAEMON)
- {
- std::cout << "\033[0;31m[DLT] Cannot Use Daemon Logging, active in CMAKE! Using CommandLine\033[0m" << std::endl;
- mlogDestination = logDestination::COMMAND_LINE;
- }
-
- if (mDebugEnabled)
- {
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering AppID " << appid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename.open(Filename, std::ofstream::out | std::ofstream::trunc);
- if (!mFilename.is_open())
- {
- throw std::runtime_error("Cannot open file for logging");
- }
-
- mFilename << now() << "[DLT] Registering AppID " << appid << " , " << description << std::endl;
- }
- }
-}
-
-CAmDltWrapper::~CAmDltWrapper()
-{
- if (mpDLTWrapper && mDebugEnabled && mlogDestination == logDestination::COMMAND_LINE)
- {
- mFilename.close();
- }
-}
-
-void CAmDltWrapper::unregisterContext(DltContext &handle)
-{
-}
-
-void CAmDltWrapper::deinit()
-{
-}
-
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description)
-{
- if (mDebugEnabled)
- {
+ size_t len = min(DLT_ID_SIZE, 1 + (int)strlen(contextid));
+ mpLogger->registerContext(contextid, description
+ , static_cast<am_LogLevel_e>(level), static_cast<am_LogStatus_e>(status));
+ strncpy(handle.contextID, contextid, len);
mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
- {
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
- }
- else
- {
- mFilename << now() << "[DLT] Registering Context " << contextid << " , " << description << std::endl;
- }
}
}
-void CAmDltWrapper::registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status)
+
+bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
{
- if (mDebugEnabled)
+ if (mpLogger)
{
- mMapContext.emplace(&handle, std::string(contextid));
-
- if (mlogDestination == logDestination::COMMAND_LINE)
+ if (context)
{
- std::cout << "\033[0;36m[DLT] Registering Context " << contextid << " , " << description << "\033[0m" << std::endl;
+ string mCurrentContextID(context->contextID, DLT_ID_SIZE);
+ mpCurrentContext = &(mpLogger->importContext(mCurrentContextID.c_str()));
}
else
{
- mFilename << now() << " [DLT] Registering Context " << contextid << " , " << description << std::endl;
+ mpCurrentContext = &(mpLogger->importContext());
}
+ mpCurrentContext->configure(static_cast<am_LogLevel_e>(loglevel));
}
-}
-bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext *context)
-{
- pthread_mutex_lock(&mMutex);
- return initNoDlt(loglevel, context);
+ return true;
}
void CAmDltWrapper::send()
{
- if (mlogDestination == logDestination::COMMAND_LINE && mLogOn)
+ if (mpCurrentContext)
{
- std::cout << mNoDltContextData.buffer.str().c_str() << std::endl;
+ mpCurrentContext->send();
}
- else if (mLogOn)
- {
- mFilename << now() << mNoDltContextData.buffer.str().c_str() << std::endl;
- }
-
- mNoDltContextData.buffer.str("");
- mNoDltContextData.buffer.clear();
- pthread_mutex_unlock(&mMutex);
-}
-
-void CAmDltWrapper::append(const int8_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint8_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int16_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint16_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int32_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint32_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const std::string &value)
-{
- append(value.c_str());
-}
-
-void CAmDltWrapper::append(const bool value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const int64_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const uint64_t value)
-{
- appendNoDLT(value);
-}
-
-void CAmDltWrapper::append(const std::vector<uint8_t> &data)
-{
- mNoDltContextData.buffer << data.data();
+ mpCurrentContext = NULL;
}
}
-#endif // WITH_DLT