summaryrefslogtreecommitdiff
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
parentc7ef1ef0126023ca8a377f00ae9aebb81bc34d37 (diff)
downloadaudiomanager-024ffad4978da6e3e1ab7dfd67f2e9ed8b3758ee.tar.gz
reworked DltWrapper. fixed gtest and gmock.pc files
-rw-r--r--AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp7
-rw-r--r--AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h2
-rw-r--r--AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp6
-rw-r--r--AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp6
-rw-r--r--AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp6
-rw-r--r--AudioManagerCore/test/AmRouterTest/CMakeLists.txt2
-rw-r--r--AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp6
-rwxr-xr-xAudioManagerDaemon/src/main.cpp21
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h258
-rw-r--r--AudioManagerUtilities/src/CAmDltWrapper.cpp732
-rw-r--r--AudioManagerUtilities/test/AmSocketHandlerTest/CMakeLists.txt3
-rw-r--r--cmake/gmock.pc.in2
-rw-r--r--cmake/gtest.pc.in2
13 files changed, 680 insertions, 373 deletions
diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp
index 9008ce6..0836229 100644
--- a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp
+++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp
@@ -32,7 +32,7 @@ using namespace am;
using namespace testing;
DLT_DECLARE_CONTEXT(AudioManager)
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
+TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default on",true);
ACTION(returnResyncConnection)
{
@@ -659,13 +659,12 @@ int main(int argc, char **argv)
try
{
TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true));
- cmd->add(enableNoDLTDebug);
+ cmd->add(enableDebug);
}
catch (TCLAP::ArgException &e) // catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
CAmCommandLineSingleton::instance()->preparse(argc,argv);
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
- CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context");
+ CAmDltWrapper::instanctiateOnce("ATEST","AudioManagerControlInterface Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON);
logInfo("RoutingSendInterface Test started");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h
index b7fa27a..3e645fb 100644
--- a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h
+++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h
@@ -42,6 +42,8 @@
#include "../MockIAmControlSend.h"
#include "CAmSocketHandler.h"
+DLT_DECLARE_CONTEXT(textContext)
+
namespace am
{
diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
index 337ecb7..dd61b7c 100644
--- a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
+++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
@@ -43,7 +43,7 @@ int16_t const TEST_MAX_CONNECTION_ID = 20;
int16_t const TEST_MAX_MAINCONNECTION_ID = 20;
int16_t const TEST_MAX_SINK_ID = 40;
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
+TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
CAmMapBasicTest::CAmMapBasicTest() :
@@ -3262,12 +3262,12 @@ int main(int argc, char **argv)
try
{
TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true));
- cmd->add(enableNoDLTDebug);
+ cmd->add(enableDebug);
}
catch (TCLAP::ArgException &e) // catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
CAmCommandLineSingleton::instance()->preparse(argc,argv);
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("databse", "databasetest");
+ CAmDltWrapper::instanctiateOnce("DTEST","Database Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON);
logInfo("Database Test started ");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp
index f95a24a..e662b4b 100644
--- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp
+++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp
@@ -27,7 +27,7 @@
#include "CAmDltWrapper.h"
#include "CAmCommandLineSingleton.h"
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
+TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
using namespace am;
@@ -3170,12 +3170,12 @@ int main(int argc, char **argv)
try
{
TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true));
- cmd->add(enableNoDLTDebug);
+ cmd->add(enableDebug);
}
catch (TCLAP::ArgException &e) // catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
CAmCommandLineSingleton::instance()->preparse(argc,argv);
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterMapTest");
+ CAmDltWrapper::instanctiateOnce("rTEST","RouterMap Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON);
logInfo("Routing Test started ");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp
index a64979e..5f59777 100644
--- a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp
+++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp
@@ -28,7 +28,7 @@
using namespace am;
using namespace testing;
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
+TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
CAmRouterTest::CAmRouterTest() :
plistRoutingPluginDirs(), //
@@ -1954,12 +1954,12 @@ int main(int argc, char **argv)
try
{
TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true));
- cmd->add(enableNoDLTDebug);
+ cmd->add(enableDebug);
}
catch (TCLAP::ArgException &e) // catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
CAmCommandLineSingleton::instance()->preparse(argc,argv);
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest");
+ CAmDltWrapper::instanctiateOnce("RTEST","Router Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON);
logInfo("Routing Test started ");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
diff --git a/AudioManagerCore/test/AmRouterTest/CMakeLists.txt b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt
index db05911..d1c0635 100644
--- a/AudioManagerCore/test/AmRouterTest/CMakeLists.txt
+++ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt
@@ -34,7 +34,7 @@ ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX})
TARGET_LINK_LIBRARIES(AmRouterTest
${GTEST_LIBRARIES}
- ${GMOCK_LIBRARIES}
+ ${GMOCK_LIBRARIES}
AudioManagerCore
)
diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp
index 5978b6d..916ff77 100644
--- a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp
+++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp
@@ -27,7 +27,7 @@
using namespace am;
using namespace testing;
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
+TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false);
CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() :
plistRoutingPluginDirs(), //
@@ -371,12 +371,12 @@ int main(int argc, char **argv)
try
{
TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true));
- cmd->add(enableNoDLTDebug);
+ cmd->add(enableDebug);
}
catch (TCLAP::ArgException &e) // catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; }
CAmCommandLineSingleton::instance()->preparse(argc,argv);
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest");
+ CAmDltWrapper::instanctiateOnce("RTEST","RoutingInterface Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index d71c02b..29cb4c9 100755
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -84,11 +84,12 @@ TCLAP::ValueArg<std::string> additionalCommandPluginDirs("L","additionalCommandP
TCLAP::ValueArg<std::string> additionalRoutingPluginDirs("R","additionalRoutingPluginDirs","additional path for looking for routing plugins, can be used after -r option ",false," ","string");
TCLAP::ValueArg<std::string> routingPluginDir("r","RoutingPluginDir","path for looking for routing plugins",false," ","string");
TCLAP::ValueArg<std::string> commandPluginDir("l","CommandPluginDir","path for looking for command plugins",false," ","string");
-TCLAP::ValueArg<std::string> databasePath ("p","databasePath","path for sqlite database (default is in memory)",false,":memory:","string");
+TCLAP::ValueArg<std::string> dltLogFilename("F","dltLogFilename","the name of the logfile, absolute path. Only if logging is et to file",false," ","string");
+TCLAP::ValueArg<unsigned int> dltOutput ("O","dltOutput","defines where logs are written. 0=dlt-daemon(default), 1=command line, 2=file ",false,0,"int");
TCLAP::ValueArg<unsigned int> telnetPort ("t","telnetport","The port that is used for telnet",false,DEFAULT_TELNETPORT,"int");
TCLAP::ValueArg<unsigned int> maxConnections ("m","maxConnections","Maximal number of connections for telnet",false,MAX_TELNETCONNECTIONS,"int");
+TCLAP::SwitchArg dltEnable ("e","dltEnable","Enables or disables dlt logging. Default = enabled",true);
TCLAP::SwitchArg dbusWrapperTypeBool ("T","dbusType","DbusType to be used by CAmDbusWrapper: if option is selected, DBUS_SYSTEM is used otherwise DBUS_SESSION",false);
-TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon, default on",true);
TCLAP::SwitchArg currentSettings("i","currentSettings","print current settings and exit",false);
TCLAP::SwitchArg daemonizeAM("d","daemonize","daemonize Audiomanager. Better use systemd...",false);
@@ -168,9 +169,6 @@ void printCmdInformation()
printf("\tTelnet portNumber:\t\t\t%i\n", telnetPort.getValue());
printf("\tTelnet maxConnections:\t\t\t%i\n", maxConnections.getValue());
#endif
-#ifndef WITH_DLT
- printf("\tDlt Command Line Output: \t\t%s\n", enableNoDLTDebug.getValue()?"enabled":"not enabled");
-#endif
printf("\tControllerPlugin: \t\t\t%s\n", controllerPlugin.getValue().c_str());
printf("\tDirectories of CommandPlugins: \t\t\n");
std::vector<std::string>::const_iterator dirIter = listCommandPluginDirs.begin();
@@ -206,7 +204,7 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context)
switch (sig)
{
/*ctl +c lets call direct controllerRundown, because we might be blocked at the moment.
- But there is the risk of interrupting something important */
+ But there is the risk of interrupting something important */https://asc.bmwgroup.net/wiki/display/MGUROTO/Lastest+and+greatest
case SIGINT:
CAmControlSender::CallsetControllerRundown(sig);
break;
@@ -244,7 +242,9 @@ void mainProgram(int argc, char *argv[])
cmd->add(routingPluginDir);
cmd->add(currentSettings);
cmd->add(daemonizeAM);
- cmd->add(enableNoDLTDebug);
+ cmd->add(dltEnable);
+ cmd->add(dltLogFilename);
+ cmd->add(dltOutput);
#ifdef WITH_DBUS_WRAPPER
cmd->add(dbusWrapperTypeBool);
#endif
@@ -267,7 +267,7 @@ void mainProgram(int argc, char *argv[])
daemonize();
}
- CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("AudioManagerDeamon", "AudioManagerDeamon");
+ CAmDltWrapper::instanctiateOnce("AUDI", "AudioManager",dltEnable.getValue(),static_cast<am::CAmDltWrapper::logDestination>(dltOutput.getValue()),dltLogFilename.getValue());
//Instantiate all classes. Keep in same order !
CAmSocketHandler iSocketHandler;
@@ -423,11 +423,6 @@ int main(int argc, char *argv[], char** envp)
close(fd0);
close(fd1);
close(fd2);
-
- //deinit the DLT
- CAmDltWrapper* inst(getWrapper());
- inst->deinit();
-
exit(0);
}
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"
diff --git a/cmake/gmock.pc.in b/cmake/gmock.pc.in
index 76d5c0c..eb292f0 100644
--- a/cmake/gmock.pc.in
+++ b/cmake/gmock.pc.in
@@ -5,5 +5,5 @@ Description: Google's framework for writing C++ tests on a variety of platforms
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/include
libdir=${prefix}/lib
-Cflags:-I${includedir}/gmock
+Cflags:-I${includedir}
Libs: -L${libdir} -lgmock
diff --git a/cmake/gtest.pc.in b/cmake/gtest.pc.in
index 37b8209..ee14e01 100644
--- a/cmake/gtest.pc.in
+++ b/cmake/gtest.pc.in
@@ -5,5 +5,5 @@ Description: Google's framework for writing C++ tests on a variety of platforms
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/include
libdir=${prefix}/lib
-Cflags:-I${includedir}/gtest
+Cflags:-I${includedir}
Libs: -L${libdir} -lgtest