summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities
diff options
context:
space:
mode:
authorChristian Linke <Christian.Linke@bmw.de>2016-02-17 14:41:04 +0100
committerChristian Linke <Christian.Linke@bmw.de>2016-02-17 14:41:04 +0100
commit024ffad4978da6e3e1ab7dfd67f2e9ed8b3758ee (patch)
tree38ee4e5da832e6c31e137dfcd2055907b98b916c /AudioManagerUtilities
parentc7ef1ef0126023ca8a377f00ae9aebb81bc34d37 (diff)
downloadaudiomanager-024ffad4978da6e3e1ab7dfd67f2e9ed8b3758ee.tar.gz
reworked DltWrapper. fixed gtest and gmock.pc files
Diffstat (limited to 'AudioManagerUtilities')
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h258
-rw-r--r--AudioManagerUtilities/src/CAmDltWrapper.cpp732
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt3
3 files changed, 652 insertions, 341 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index d227929..009b1e6 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -21,80 +21,80 @@
#include <string>
#include <pthread.h>
#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <map>
#include <audiomanagerconfig.h>
#include "audiomanagertypes.h"
#ifdef WITH_DLT
-#include <dlt/dlt.h>
-namespace am
-{
+ #include <dlt/dlt.h>
#else
-#include <stdint.h>
-#include <sstream>
+ #include <stdint.h>
+ #include <sstream>
-#define DLT_USER_BUF_MAX_SIZE 2048
+ #define DLT_USER_BUF_MAX_SIZE 2048
-/**
- * This structure is used for every context used in an application.
- */
-typedef struct
-{
- char contextID[4]; /**< context id */
- int32_t log_level_pos; /**< offset in user-application context field */
- int32_t log_level_user; /** any message above this log level is not logged */
-} DltContext;
+ /**
+ * This structure is used for every context used in an application.
+ */
+ typedef struct
+ {
+ char contextID[4]; /**< context id */
+ int32_t log_level_pos; /**< offset in user-application context field */
+ int32_t log_level_user; /** any message above this log level is not logged */
+ } DltContext;
+
+ /**
+ * Definition of DLT trace status
+ */
+ typedef enum
+ {
+ DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
+ DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
+ DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
+ } 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
-{
- DLT_LOG_DEFAULT = -1, /**< Default log level */
- DLT_LOG_OFF = 0x00, /**< Log level off */
- DLT_LOG_FATAL = 0x01, /**< fatal system error */
- DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
- DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
- DLT_LOG_INFO = 0x04, /**< informational */
- DLT_LOG_DEBUG = 0x05, /**< debug */
- DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
-} DltLogLevelType;
+ /**
+ * Definitions of DLT log level
+ */
+ typedef enum
+ {
+ DLT_LOG_DEFAULT = -1, /**< Default log level */
+ DLT_LOG_OFF = 0x00, /**< Log level off */
+ DLT_LOG_FATAL = 0x01, /**< fatal system error */
+ DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
+ DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
+ DLT_LOG_INFO = 0x04, /**< informational */
+ DLT_LOG_DEBUG = 0x05, /**< debug */
+ DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
+ } DltLogLevelType;
-/**
- * Definition of DLT trace status
- */
-typedef enum
-{
- DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
- DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
- DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
-} 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;
-
-#define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
+ #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
+ #define DLT_DECLARE_CONTEXT(CONTEXT) \
+ DltContext CONTEXT;
+ #define DLT_IMPORT_CONTEXT(CONTEXT) \
+ extern DltContext CONTEXT;
-#define DLT_DECLARE_CONTEXT(CONTEXT) \
-DltContext CONTEXT;
+#endif // WITH_DLT
-#define DLT_IMPORT_CONTEXT(CONTEXT) \
-extern DltContext CONTEXT;
namespace am
{
-#endif // WITH_DLT
/**
* Wraps around the dlt. This class is instantiated as a singleton and offers a default
@@ -105,13 +105,57 @@ namespace am
class CAmDltWrapper
{
public:
- static CAmDltWrapper* instance(const bool enableNoDLTDebug = false);
- void registerApp(const char *appid, const char * description);
+
+ /**
+ * 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
+ */
+ enum logDestination
+ {
+ DAEMON=0, //!< logging with the DLT daemon
+ COMMAND_LINE=1, //!< logging with commandline
+ FILE_OUT =2 //!< logging into a file
+ };
+
+ /**
+ * Instanciate the Dlt Wrapper
+ * @param appid The AppID
+ * @param description A description of the Application
+ * @param debugEnabled if set to true, debug outputs will be generated, default = true
+ * @param logDest the destination, the log should be written
+ * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT
+ * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false
+ */
+ static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false);
+
+ /**
+ * get the Wrapper Instance
+ */
+ static CAmDltWrapper* instance();
+
+ /**
+ * 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, const DltLogLevelType level, const DltTraceStatusType status);
void unregisterContext(DltContext& handle);
-
+ bool getEnabled();
+ ~CAmDltWrapper();
+
+
bool init(DltLogLevelType loglevel, DltContext* context = NULL);
void deinit();
void send();
@@ -126,19 +170,29 @@ public:
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(mEnableNoDLTDebug)
- {
- dlt_user_log_write_string(&mDltContextData, value);
- }
- #else
- mDltContextData.buffer << value;
- #endif
- }
+ #ifdef WITH_DLT
+ if (mlogDestination == logDestination::DAEMON)
+ {
+ dlt_user_log_write_string(&mDltContextData, value);
+ }
+ else
+ {
+ mNoDltContextData.buffer << std::string(value);
+ }
+ #else
+ mNoDltContextData.buffer << std::string(value);
+ #endif //WITH_DLT
+
+ }
// specialization for const am_Error_e
template<typename T = const am_Error_e> void append(const am_Error_e value)
@@ -156,8 +210,7 @@ public:
"E_ABORTED",
"E_WRONG_FORMAT"
};
- if(mEnableNoDLTDebug)
- append(str_error[value]);
+ append(str_error[value]);
}
// Template to print unknown pointer types with their address
@@ -184,33 +237,28 @@ public:
this->append(args...);
}
-#ifndef WITH_DLT
- void enableNoDLTDebug(const bool enableNoDLTDebug = true);
-#endif
- ~CAmDltWrapper();
private:
- CAmDltWrapper(const bool enableNoDLTDebug); //is private because of singleton pattern
-#ifndef WITH_DLT
- template<class T> void appendNoDLT(T value);
-#endif
+ /**
+ * 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();
DltContext mDltContext; //!< the default context
DltContextData mDltContextData; //!< contextdata
- bool mEnableNoDLTDebug;
+ NoDltContextData mNoDltContextData; //!<contextdata for std out logging
+ 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;
};
/**
- * returns the instance of the CAmDltWrapper
- * @return
- */
-inline CAmDltWrapper* getWrapper()
-{
- return (CAmDltWrapper::instance());
-}
-
-/**
* logs given values with a given context (register first!) and given loglevel
* @param context
* @param loglevel
@@ -220,10 +268,15 @@ inline CAmDltWrapper* getWrapper()
template<typename T, typename... TArgs>
void log(DltContext* const context, DltLogLevelType loglevel, T value, TArgs... args)
{
- CAmDltWrapper* inst(getWrapper());
-
+ CAmDltWrapper* inst(CAmDltWrapper::instance());
+ if (!inst->getEnabled())
+ {
+ return;
+ }
if (!inst->init(loglevel, context))
- return;
+ {
+ return;
+ }
inst->append(value);
inst->append(args...);
inst->send();
@@ -262,6 +315,17 @@ 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...);
+}
+
}
#endif /* DLTWRAPPER_H_ */
diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp
index 3b10ef4..b116e53 100644
--- a/AudioManagerUtilities/src/CAmDltWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp
@@ -27,314 +27,562 @@
#include <string>
#include <iostream>
#include <string.h>
+#include <chrono>
+#include <ctime>
namespace am
{
-
CAmDltWrapper* CAmDltWrapper::mpDLTWrapper = NULL;
pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER;
-CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug)
+std::string CAmDltWrapper::now()
{
- if (!mpDLTWrapper)
- mpDLTWrapper = new CAmDltWrapper(enableNoDLTDebug);
-#ifndef WITH_DLT
- if(enableNoDLTDebug)
- mpDLTWrapper->enableNoDLTDebug(true);
-#endif
- return (mpDLTWrapper);
+ 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));
}
-void CAmDltWrapper::unregisterContext(DltContext & handle)
+CAmDltWrapper* CAmDltWrapper::instanctiateOnce(const char *appid, const char * description, const bool debugEnabled, const logDestination logDest, const std::string Filename,bool onlyError)
{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
- {
- dlt_unregister_context(&handle);
- }
-#else
- (void) handle;
-#endif
+ if (!mpDLTWrapper)
+ {
+ mpDLTWrapper = new CAmDltWrapper(appid,description,debugEnabled,logDest,Filename,onlyError);
+ }
+ return (mpDLTWrapper);
}
-void CAmDltWrapper::deinit()
+CAmDltWrapper* CAmDltWrapper::instance()
{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
- {
- unregisterContext(mDltContext);
- }
-#endif
+ return mpDLTWrapper;
}
-CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug=true) :
- mDltContext(), //
- mDltContextData(), //
- mEnableNoDLTDebug(enableNoDLTDebug)
+bool CAmDltWrapper::getEnabled()
{
- (void) enableNoDLTDebug;
-#ifndef WITH_DLT
- std::cout << "\e[0;34m[DLT]\e[0;30m\tRunning without DLT-support" << std::endl;
-#endif
+ return (mDebugEnabled);
}
-void CAmDltWrapper::registerApp(const char *appid, const char *description)
+bool CAmDltWrapper::initNoDlt(DltLogLevelType loglevel, DltContext* context)
{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ if (mlogDestination==logDestination::COMMAND_LINE)
{
- dlt_register_app(appid, description);
- //register a default context
- dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass");
+ 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;
}
-#else
- (void) appid;
- (void) description;
-#endif
}
+
+#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)
+ {
+ if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
+ {
+ dlt_register_app(appid, description);
+ //register a default context
+ dlt_register_context(&mDltContext, "DEF", "Default Context registered by DLTWrapper Class");
+ }
+ 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;
+ }
+ }
+ }
+
+ CAmDltWrapper::~CAmDltWrapper()
+ {
+ if (mpDLTWrapper && mDebugEnabled && mlogDestination==logDestination::DAEMON)
+ {
+ mpDLTWrapper->unregisterContext(mDltContext);
+ delete mpDLTWrapper;
+ }
+ else if (mpDLTWrapper && mDebugEnabled && mlogDestination==logDestination::COMMAND_LINE)
+ {
+ mFilename.close();
+ }
+ }
-void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
- {
- dlt_register_context(&handle, contextid, description);
- }
-#else
- strncpy(handle.contextID,contextid,4);
-
- // store only the first contextID
- if(0 == strlen(mDltContext.contextID))
- {
- memcpy(&mDltContext.contextID,contextid,4);
- const size_t str_len = strlen(description);
- if(str_len < 2000)
- {
- mDltContextData.context_description = new char[str_len + 1];
- (void) strcpy(mDltContextData.context_description,description);
- }
- mDltContext.log_level_user = DLT_DEFAULT_LOG_LEVEL;
- }
- handle.log_level_user = DLT_DEFAULT_LOG_LEVEL;
- std::cout << "\e[0;34m[DLT]\e[0;30m\tRegistering Context " << contextid << " , " << description << std::endl;
-
-#endif
-}
+ void CAmDltWrapper::unregisterContext(DltContext & handle)
+ {
+ if (mDebugEnabled && mlogDestination==logDestination::DAEMON)
+ {
+ dlt_unregister_context(&handle);
+ }
+ }
-void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char * description,
- const DltLogLevelType level, const DltTraceStatusType status)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
- {
- dlt_register_context_ll_ts(&handle, contextid, description, level, status);
- }
-#else
- strncpy(handle.contextID,contextid,4);
-
- // store only the first contextID
- if(0 == strlen(mDltContext.contextID))
- {
- memcpy(&mDltContext.contextID,contextid,4);
- const size_t str_len = strlen(description);
- if(str_len < 2000)
- {
- mDltContextData.context_description = new char[str_len + 1];
- (void) strcpy(mDltContextData.context_description,description);
- }
- mDltContext.log_level_user = level;
- }
- handle.log_level_user = level;
- std::cout << "\e[0;34m[DLT]\e[0;30m\tRegistering Context " << contextid << " , " << description << std::endl;
-
-#endif
-}
+ void CAmDltWrapper::deinit()
+ {
+ if (mDebugEnabled)
+ {
+ unregisterContext(mDltContext);
+ }
+ }
+
+ 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)
+ {
+ 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)
+ {
+ pthread_mutex_lock(&mMutex);
+ if (mlogDestination==logDestination::DAEMON)
+ {
+ if (!context)
+ context = &mDltContext;
+
+ if(dlt_user_log_write_start(context, &mDltContextData, loglevel) < 0)
+ {
+ pthread_mutex_unlock(&mMutex);
+ return false;
+ }
+ }
+ else
+ {
+ initNoDlt(loglevel,context);
+ }
+ return true;
+ }
-bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context)
-{
- (void) loglevel;
- pthread_mutex_lock(&mMutex);
- if (!context)
- context = &mDltContext;
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
- if(dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0)
-#else
- if((mEnableNoDLTDebug == false) || (loglevel > context->log_level_user))
-#endif
+ void CAmDltWrapper::send()
+ {
+ if (mlogDestination==logDestination::DAEMON)
{
- pthread_mutex_unlock(&mMutex);
- return false;
+ dlt_user_log_write_finish(&mDltContextData);
}
-#ifndef WITH_DLT
- std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t";
-#endif
- return true;
-}
+ 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::send()
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const uint8_t value)
{
- dlt_user_log_write_finish(&mDltContextData);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_uint8(&mDltContextData, value);
+ else
+ appendNoDLT(value);
}
-#else
- if(mEnableNoDLTDebug)
- std::cout << mDltContextData.buffer.str().c_str() << std::endl;
- mDltContextData.buffer.str("");
- mDltContextData.buffer.clear();
-#endif
- pthread_mutex_unlock(&mMutex);
-}
+ 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 int8_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const uint16_t value)
{
- dlt_user_log_write_int8(&mDltContextData, value);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_uint16(&mDltContextData, value);
+ else
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const uint8_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const int32_t value)
{
- dlt_user_log_write_uint8(&mDltContextData, value);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_int32(&mDltContextData, value);
+ else
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const int16_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const uint32_t value)
{
- dlt_user_log_write_int16(&mDltContextData, value);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_uint32(&mDltContextData, value);
+ else
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const uint16_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const std::string& value)
{
- dlt_user_log_write_uint16(&mDltContextData, value);
+ append(value.c_str());
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const int32_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const bool value)
{
- dlt_user_log_write_int32(&mDltContextData, value);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
+ else
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const uint32_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const int64_t value)
{
- dlt_user_log_write_uint32(&mDltContextData, value);
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_int64(&mDltContextData, value);
+ else
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const std::string& value)
-{
- if (mEnableNoDLTDebug)
- append(value.c_str());
-}
+ 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 bool value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const std::vector<uint8_t> & data)
{
- dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
+ if (mlogDestination==logDestination::DAEMON)
+ dlt_user_log_write_raw(&mDltContextData,(void*)data.data(),data.size());
+ else
+ mNoDltContextData.buffer << data.data();
}
-#else
- appendNoDLT(value);
-#endif
}
-void CAmDltWrapper::append(const int64_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+#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()
{
- dlt_user_log_write_int64(&mDltContextData, value);
+ 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)
+ {
+ 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)
+ {
+ 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)
+ {
+ pthread_mutex_lock(&mMutex);
+ initNoDlt(loglevel,context);
+ }
+
+ void CAmDltWrapper::send()
+ {
+ 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)
+ {
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const uint64_t value)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const uint8_t value)
{
- dlt_user_log_write_uint64(&mDltContextData, value);
+ appendNoDLT(value);
}
-#else
- appendNoDLT(value);
-#endif
-}
-void CAmDltWrapper::append(const std::vector<uint8_t> & data)
-{
-#ifdef WITH_DLT
- if (mEnableNoDLTDebug)
+ void CAmDltWrapper::append(const int16_t value)
{
- dlt_user_log_write_raw(&mDltContextData,(void*)data.data(),data.size());
+ appendNoDLT(value);
}
-#else
- mDltContextData.buffer << data.data();
-#endif
-}
-#ifndef WITH_DLT
-template<class T> void CAmDltWrapper::appendNoDLT(T value)
-{
- mDltContextData.buffer << value;
-}
+ void CAmDltWrapper::append(const uint16_t value)
+ {
+ appendNoDLT(value);
+ }
-void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug)
-{
- mEnableNoDLTDebug = enableNoDLTDebug;
-}
-#endif
+ void CAmDltWrapper::append(const int32_t value)
+ {
+ appendNoDLT(value);
+ }
-CAmDltWrapper::~CAmDltWrapper()
-{
- if (mpDLTWrapper && mEnableNoDLTDebug)
- {
- mpDLTWrapper->unregisterContext(mDltContext);
- delete mpDLTWrapper;
- }
-}
+ 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();
+ }
}
+#endif //WITH_DLT
diff --git a/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt b/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt
index 2a3b9d8..012aa73 100644
--- a/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt
+++ b/AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt
@@ -22,8 +22,7 @@ project(AmSocketHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION})
INCLUDE_DIRECTORIES(
${AUDIOMANAGER_UTILITIES_INCLUDE}
${GMOCK_INCLUDE_DIRS}
-)
-
+ ${GTEST_INCLUDE_DIRS})
file(GLOB Socket_SRCS_CXX
"*.cpp"