summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Herchet <frank.fh.herchet@bmw.de>2012-02-28 15:45:50 +0100
committerFrank Herchet <frank.fh.herchet@bmw.de>2012-02-28 15:45:50 +0100
commit7abe8302898461aaa342224de2d00ce1c80eb8c2 (patch)
tree5124dfd2f83e903bd651737b71f4beb054ecb48a
parentc05c98fe354cfa8172deb1daff0f0240a740a552 (diff)
downloadaudiomanager-7abe8302898461aaa342224de2d00ce1c80eb8c2.tar.gz
* [GAM-11] remove dependency from DLT in DLTWrapper if WITH_DLT is undefined
* [GAM-11] add some structs and enums to be compatible to DLT-interface
-rw-r--r--AudioManagerDaemon/src/DLTWrapper.cpp68
-rw-r--r--includes/DLTWrapper.h13
2 files changed, 74 insertions, 7 deletions
diff --git a/AudioManagerDaemon/src/DLTWrapper.cpp b/AudioManagerDaemon/src/DLTWrapper.cpp
index a5b51ac..cdb1a1e 100644
--- a/AudioManagerDaemon/src/DLTWrapper.cpp
+++ b/AudioManagerDaemon/src/DLTWrapper.cpp
@@ -24,14 +24,18 @@
#include "DLTWrapper.h"
-#include <cassert>
+#include <string.h>
+#include <sstream>
+#include <iostream>
DLTWrapper* DLTWrapper::mDLTWrapper = NULL;
-DLTWrapper *DLTWrapper::instance()
+DLTWrapper *DLTWrapper::instance(const bool enableNoDLTDebug)
{
if (!mDLTWrapper)
- mDLTWrapper = new DLTWrapper;
+ mDLTWrapper = new DLTWrapper(enableNoDLTDebug);
+ if(enableNoDLTDebug)
+ mDLTWrapper->enableNoDLTDebug(true);
return mDLTWrapper;
}
@@ -42,10 +46,16 @@ void DLTWrapper::unregisterContext(DltContext & handle)
#endif
}
-DLTWrapper::DLTWrapper() :
+DLTWrapper::DLTWrapper(const bool enableNoDLTDebug) :
+#ifndef WITH_DLT
+ mEnableNoDLTDebug(enableNoDLTDebug),
+#endif
mDltContext(), //
mDltContextData()
{
+#ifndef WITH_DLT
+ std::cout << "[DLT] Running without DLT-support" << std::endl;
+#endif
}
void DLTWrapper::registerApp(const char *appid, const char *description)
@@ -61,6 +71,15 @@ void DLTWrapper::registerContext(DltContext& handle, const char *contextid, cons
{
#ifdef WITH_DLT
dlt_register_context(&handle, contextid, description);
+#else
+ memcpy(&mDltContext.contextID,contextid,4);
+ strlen(description);
+ 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);
+ }
#endif
}
@@ -78,6 +97,11 @@ void DLTWrapper::send()
{
#ifdef WITH_DLT
dlt_user_log_write_finish(&mDltContextData);
+#else
+ if(mEnableNoDLTDebug)
+ std::cout << "[" << mDltContext.contextID << "] " << std::string(mDltContextData.buffer) << std::endl;
+
+ mDltContextData.size = 0;
#endif
}
@@ -85,6 +109,8 @@ void DLTWrapper::append(const int8_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_int8(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -92,6 +118,8 @@ void DLTWrapper::append(const uint8_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_uint8(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -99,6 +127,8 @@ void DLTWrapper::append(const int16_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_int16(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -106,6 +136,8 @@ void DLTWrapper::append(const uint16_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_uint16(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -113,6 +145,8 @@ void DLTWrapper::append(const int32_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_int32(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -120,6 +154,8 @@ void DLTWrapper::append(const uint32_t value)
{
#ifdef WITH_DLT
dlt_user_log_write_uint32(&mDltContextData, value);
+#else
+ appendNoDLT(value);
#endif
}
@@ -127,6 +163,9 @@ void DLTWrapper::append(const char*& value)
{
#ifdef WITH_DLT
dlt_user_log_write_string(&mDltContextData, value);
+#else
+ memcpy((mDltContextData.buffer+mDltContextData.size),value,strlen(value));
+ mDltContextData.size += strlen(value);
#endif
}
@@ -134,6 +173,9 @@ void DLTWrapper::append(const std::string& value)
{
#ifdef WITH_DLT
dlt_user_log_write_string(&mDltContextData, value.c_str());
+#else
+ memcpy((mDltContextData.buffer+mDltContextData.size),value.c_str(),value.size());
+ mDltContextData.size += value.size();
#endif
}
@@ -141,9 +183,27 @@ void DLTWrapper::append(const bool value)
{
#ifdef WITH_DLT
dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
+#else
+ appendNoDLT(value);
#endif
}
+#ifndef WITH_DLT
+template<class T> void DLTWrapper::appendNoDLT(T value)
+{
+ if((mDltContextData.size + sizeof(value)) < DLT_USER_BUF_MAX_SIZE)
+ {
+ memcpy((mDltContextData.buffer+mDltContextData.size),&(value),sizeof(value));
+ mDltContextData.size += sizeof(value);
+ }
+}
+
+void DLTWrapper::enableNoDLTDebug(const bool enableNoDLTDebug)
+{
+ mEnableNoDLTDebug = enableNoDLTDebug;
+}
+#endif
+
DLTWrapper::~DLTWrapper()
{
if (mDLTWrapper)
diff --git a/includes/DLTWrapper.h b/includes/DLTWrapper.h
index 7d72836..3a9482a 100644
--- a/includes/DLTWrapper.h
+++ b/includes/DLTWrapper.h
@@ -65,7 +65,7 @@ typedef enum
typedef struct
{
DltContext *handle; /**< pointer to DltContext */
- unsigned char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/
+ char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/
int32_t size; /**< payload size */
int32_t log_level; /**< log level */
int32_t trace_status; /**< trace status */
@@ -88,7 +88,7 @@ extern DltContext CONTEXT;
class DLTWrapper
{
public:
- static DLTWrapper* instance();
+ static DLTWrapper* instance(const bool enableNoDLTDebug = false);
void registerApp(const char *appid, const char * description);
void registerContext(DltContext& handle, const char *contextid, const char * description);
void unregisterContext(DltContext& handle);
@@ -103,9 +103,16 @@ public:
void append(const char*& value);
void append(const std::string& value);
void append(const bool value);
+#ifndef WITH_DLT
+ void enableNoDLTDebug(const bool enableNoDLTDebug = true);
+#endif
~DLTWrapper();
private:
- DLTWrapper(); //is private because of singleton pattern
+ DLTWrapper(const bool enableNoDLTDebug); //is private because of singleton pattern
+#ifndef WITH_DLT
+ template<class T> void appendNoDLT(T value);
+ bool mEnableNoDLTDebug;
+#endif
DltContext mDltContext;
DltContextData mDltContextData;
static DLTWrapper* mDLTWrapper;