2 * Copyright (C) 2012, BMW AG
4 * This file is part of GENIVI Project AudioManager.
6 * Contributions are licensed to the GENIVI Alliance under one or more
7 * Contribution License Agreements.
10 * This Source Code Form is subject to the terms of the
11 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
12 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
17 * \file CAmDltWrapper.cpp
18 * For further information see http://www.genivi.org/.
23 #include "shared/CAmDltWrapper.h"
32 CAmDltWrapper* CAmDltWrapper::mpDLTWrapper = NULL;
33 pthread_mutex_t CAmDltWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER;
35 CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug)
38 mpDLTWrapper = new CAmDltWrapper(enableNoDLTDebug);
41 mpDLTWrapper->enableNoDLTDebug(true);
43 return (mpDLTWrapper);
46 void CAmDltWrapper::unregisterContext(DltContext & handle)
49 dlt_unregister_context(&handle);
55 void CAmDltWrapper::deinit()
58 unregisterContext(mDltContext);
62 CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) :
64 mEnableNoDLTDebug(enableNoDLTDebug),
69 (void) enableNoDLTDebug;
71 std::cout << "\e[0;34m[DLT]\e[0;30m\tRunning without DLT-support" << std::endl;
75 void CAmDltWrapper::registerApp(const char *appid, const char *description)
78 dlt_register_app(appid, description);
79 //register a default context
80 dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass");
87 void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description)
90 dlt_register_context(&handle, contextid, description);
92 strncpy(handle.contextID,contextid,4);
94 // store only the first contextID
95 if(0 == strlen(mDltContext.contextID))
97 memcpy(&mDltContext.contextID,contextid,4);
98 const size_t str_len = strlen(description);
101 mDltContextData.context_description = new char[str_len + 1];
102 (void) strcpy(mDltContextData.context_description,description);
106 std::cout << "\e[0;34m[DLT]\e[0;30m\tRegistering Context " << contextid << " , " << description << std::endl;
111 void CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context)
114 pthread_mutex_lock(&mMutex);
116 context = &mDltContext;
118 dlt_user_log_write_start(context, &mDltContextData, loglevel);
120 if(mEnableNoDLTDebug)
121 std::cout << "\e[0;34m[" << context->contextID << "]\e[0;30m\t";
126 void CAmDltWrapper::send()
129 dlt_user_log_write_finish(&mDltContextData);
131 if(mEnableNoDLTDebug)
132 std::cout << mDltContextData.buffer.str().c_str() << std::endl;
134 mDltContextData.buffer.str("");
135 mDltContextData.buffer.clear();
137 pthread_mutex_unlock(&mMutex);
140 void CAmDltWrapper::append(const int8_t value)
143 dlt_user_log_write_int8(&mDltContextData, value);
149 void CAmDltWrapper::append(const uint8_t value)
152 dlt_user_log_write_uint8(&mDltContextData, value);
158 void CAmDltWrapper::append(const int16_t value)
161 dlt_user_log_write_int16(&mDltContextData, value);
167 void CAmDltWrapper::append(const uint16_t value)
170 dlt_user_log_write_uint16(&mDltContextData, value);
176 void CAmDltWrapper::append(const int32_t value)
179 dlt_user_log_write_int32(&mDltContextData, value);
185 void CAmDltWrapper::append(const uint32_t value)
188 dlt_user_log_write_uint32(&mDltContextData, value);
194 void CAmDltWrapper::append(const char*& value)
197 dlt_user_log_write_string(&mDltContextData, value);
199 mDltContextData.buffer << value;
203 void CAmDltWrapper::append(const std::string& value)
206 dlt_user_log_write_string(&mDltContextData, value.c_str());
208 mDltContextData.buffer << value;
212 void CAmDltWrapper::append(const bool value)
215 dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
221 void CAmDltWrapper::append(const int64_t value)
224 dlt_user_log_write_int64(&mDltContextData, value);
230 void CAmDltWrapper::append(const uint64_t value)
233 dlt_user_log_write_uint64(&mDltContextData, value);
239 void CAmDltWrapper::append(am_Error_e value)
244 case am_Error_e::E_OK:
247 case am_Error_e::E_ABORTED:
250 case am_Error_e::E_ALREADY_EXISTS:
251 txt="E_ALREADY_EXISTS";
253 case am_Error_e::E_DATABASE_ERROR:
254 txt="E_DATABASE_ERROR";
256 case am_Error_e::E_NON_EXISTENT:
257 txt="E_NON_EXISTENT";
259 case am_Error_e::E_NOT_POSSIBLE:
260 txt="E_NOT_POSSIBLE";
262 case am_Error_e::E_NOT_USED:
265 case am_Error_e::E_NO_CHANGE:
268 case am_Error_e::E_OUT_OF_RANGE:
269 txt="E_OUT_OF_RANGE";
271 case am_Error_e::E_UNKNOWN:
280 dlt_user_log_write_string(&mDltContextData, txt.c_str());
282 mDltContextData.buffer << txt;
287 template<class T> void CAmDltWrapper::appendNoDLT(T value)
289 mDltContextData.buffer << value;
292 void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug)
294 mEnableNoDLTDebug = enableNoDLTDebug;
298 CAmDltWrapper::~CAmDltWrapper()
302 mpDLTWrapper->unregisterContext(mDltContext);