* [GAM-11] remove dependency from DLT in DLTWrapper if WITH_DLT is undefined
authorFrank Herchet <frank.fh.herchet@bmw.de>
Tue, 28 Feb 2012 14:45:50 +0000 (15:45 +0100)
committerFrank Herchet <frank.fh.herchet@bmw.de>
Tue, 28 Feb 2012 14:45:50 +0000 (15:45 +0100)
* [GAM-11] add some structs and enums to be compatible to DLT-interface

AudioManagerDaemon/src/DLTWrapper.cpp
includes/DLTWrapper.h

index a5b51ac..cdb1a1e 100644 (file)
 
 
 #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)
index 7d72836..3a9482a 100644 (file)
@@ -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;