summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Lorenz <jlorenz@de.adit-jv.com>2015-09-10 14:48:34 +0200
committerChristian Linke <christian.linke@bmw.de>2015-09-16 08:14:01 +0100
commit3315426039419a1ad5b5c80f5481080cc77a8a16 (patch)
tree560b1f641d87667f8ba3db8e2f404ff443e1bc83
parent1423d7d9f4f0f67c3c354f8a334a1485734b7f24 (diff)
downloadaudiomanager-3315426039419a1ad5b5c80f5481080cc77a8a16.tar.gz
Utility: DLT: New registerContext allows to set log level and trace status from application
Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h17
-rw-r--r--AudioManagerUtilities/src/CAmDltWrapper.cpp39
2 files changed, 51 insertions, 5 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index ac57343..6d52bf1 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -40,6 +40,7 @@ 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;
/**
@@ -58,6 +59,17 @@ typedef enum
} 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
@@ -71,6 +83,9 @@ typedef struct
char* context_description; /**< description of context */
} DltContextData;
+#define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
+
+
#define DLT_DECLARE_CONTEXT(CONTEXT) \
DltContext CONTEXT;
@@ -92,6 +107,8 @@ public:
static CAmDltWrapper* instance(const bool enableNoDLTDebug = false);
void registerApp(const char *appid, const char * description);
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 unregisterContext(DltContext& handle);
bool init(DltLogLevelType loglevel, DltContext* context = NULL);
diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp
index 6a6d8dd..149edcd 100644
--- a/AudioManagerUtilities/src/CAmDltWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp
@@ -104,8 +104,35 @@ void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, c
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::registerContext(DltContext& handle, const char *contextid, const char * description,
+ const DltLogLevelType level, const DltTraceStatusType status)
+{
+#ifdef WITH_DLT
+ 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
@@ -119,13 +146,15 @@ bool CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context)
context = &mDltContext;
#ifdef WITH_DLT
if (dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0)
+#else
+ if((mEnableNoDLTDebug == false) || (loglevel > context->log_level_user))
+#endif
{
- pthread_mutex_unlock(&mMutex);
- return false;
+ pthread_mutex_unlock(&mMutex);
+ return false;
}
-#else
- if(mEnableNoDLTDebug)
- std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t";
+#ifndef WITH_DLT
+ std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t";
#endif
return true;
}