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;
34 CAmDltWrapper *CAmDltWrapper::instance(const bool enableNoDLTDebug)
37 mpDLTWrapper = new CAmDltWrapper(enableNoDLTDebug);
40 mpDLTWrapper->enableNoDLTDebug(true);
42 return (mpDLTWrapper);
45 void CAmDltWrapper::unregisterContext(DltContext & handle)
48 dlt_unregister_context(&handle);
54 CAmDltWrapper::CAmDltWrapper(const bool enableNoDLTDebug) :
56 mEnableNoDLTDebug(enableNoDLTDebug),
61 (void) enableNoDLTDebug;
63 std::cout << "[DLT] Running without DLT-support" << std::endl;
67 void CAmDltWrapper::registerApp(const char *appid, const char *description)
70 dlt_register_app(appid, description);
71 //register a default context
72 dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass");
79 void CAmDltWrapper::registerContext(DltContext& handle, const char *contextid, const char *description)
82 dlt_register_context(&handle, contextid, description);
85 memcpy(&mDltContext.contextID,contextid,4);
86 const size_t str_len = strlen(description);
89 mDltContextData.context_description = new char[str_len + 1];
90 (void) strcpy(mDltContextData.context_description,description);
95 void CAmDltWrapper::init(DltLogLevelType loglevel, DltContext* context)
99 context = &mDltContext;
101 dlt_user_log_write_start(context, &mDltContextData, loglevel);
106 void CAmDltWrapper::send()
109 dlt_user_log_write_finish(&mDltContextData);
111 if(mEnableNoDLTDebug)
112 std::cout << "[" << mDltContext.contextID << "] " << mDltContextData.buffer.str().c_str() << std::endl;
114 mDltContextData.buffer.str("");
115 mDltContextData.buffer.clear();
119 void CAmDltWrapper::append(const int8_t value)
122 dlt_user_log_write_int8(&mDltContextData, value);
128 void CAmDltWrapper::append(const uint8_t value)
131 dlt_user_log_write_uint8(&mDltContextData, value);
137 void CAmDltWrapper::append(const int16_t value)
140 dlt_user_log_write_int16(&mDltContextData, value);
146 void CAmDltWrapper::append(const uint16_t value)
149 dlt_user_log_write_uint16(&mDltContextData, value);
155 void CAmDltWrapper::append(const int32_t value)
158 dlt_user_log_write_int32(&mDltContextData, value);
164 void CAmDltWrapper::append(const uint32_t value)
167 dlt_user_log_write_uint32(&mDltContextData, value);
173 void CAmDltWrapper::append(const char*& value)
176 dlt_user_log_write_string(&mDltContextData, value);
178 mDltContextData.buffer << value;
182 void CAmDltWrapper::append(const std::string& value)
185 dlt_user_log_write_string(&mDltContextData, value.c_str());
187 mDltContextData.buffer << value;
191 void CAmDltWrapper::append(const bool value)
194 dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
201 template<class T> void CAmDltWrapper::appendNoDLT(T value)
203 mDltContextData.buffer << value;
206 void CAmDltWrapper::enableNoDLTDebug(const bool enableNoDLTDebug)
208 mEnableNoDLTDebug = enableNoDLTDebug;
212 CAmDltWrapper::~CAmDltWrapper()