* [GAM-11] make project compilable without DLT
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / DLTWrapper.cpp
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * GeniviAudioMananger AudioManagerDaemon
5  *
6  * \file DLTWrapper.cpp
7  *
8  * \date 20-Oct-2011 3:42:04 PM
9  * \author Christian Mueller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
12  * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13  * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
14  *
15  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19  * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20  * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21  * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
22  *
23  */
24
25
26 #include "DLTWrapper.h"
27 #include <cassert>
28
29 DLTWrapper* DLTWrapper::mDLTWrapper = NULL;
30
31 DLTWrapper *DLTWrapper::instance()
32 {
33     if (!mDLTWrapper)
34         mDLTWrapper = new DLTWrapper;
35     return mDLTWrapper;
36 }
37
38 void DLTWrapper::unregisterContext(DltContext & handle)
39 {
40 #ifdef WITH_DLT
41     dlt_unregister_context(&handle);
42 #endif
43 }
44
45 DLTWrapper::DLTWrapper() :
46         mDltContext(), //
47         mDltContextData()
48 {
49 }
50
51 void DLTWrapper::registerApp(const char *appid, const char *description)
52 {
53 #ifdef WITH_DLT
54     dlt_register_app(appid, description);
55     //register a default context
56     dlt_register_context(&mDltContext, "def", "default Context registered by DLTWrapper CLass");
57 #endif
58 }
59
60 void DLTWrapper::registerContext(DltContext& handle, const char *contextid, const char *description)
61 {
62 #ifdef WITH_DLT
63     dlt_register_context(&handle, contextid, description);
64 #endif
65 }
66
67 void DLTWrapper::init(DltLogLevelType loglevel, DltContext* context)
68 {
69     if (!context)
70         context = &mDltContext;
71 #ifdef WITH_DLT
72     dlt_user_log_write_start(context, &mDltContextData, loglevel);
73 #endif
74
75 }
76
77 void DLTWrapper::send()
78 {
79 #ifdef WITH_DLT
80     dlt_user_log_write_finish(&mDltContextData);
81 #endif
82 }
83
84 void DLTWrapper::append(const int8_t value)
85 {
86 #ifdef WITH_DLT
87     dlt_user_log_write_int8(&mDltContextData, value);
88 #endif
89 }
90
91 void DLTWrapper::append(const uint8_t value)
92 {
93 #ifdef WITH_DLT
94     dlt_user_log_write_uint8(&mDltContextData, value);
95 #endif
96 }
97
98 void DLTWrapper::append(const int16_t value)
99 {
100 #ifdef WITH_DLT
101     dlt_user_log_write_int16(&mDltContextData, value);
102 #endif
103 }
104
105 void DLTWrapper::append(const uint16_t value)
106 {
107 #ifdef WITH_DLT
108     dlt_user_log_write_uint16(&mDltContextData, value);
109 #endif
110 }
111
112 void DLTWrapper::append(const int32_t value)
113 {
114 #ifdef WITH_DLT
115     dlt_user_log_write_int32(&mDltContextData, value);
116 #endif
117 }
118
119 void DLTWrapper::append(const uint32_t value)
120 {
121 #ifdef WITH_DLT
122     dlt_user_log_write_uint32(&mDltContextData, value);
123 #endif
124 }
125
126 void DLTWrapper::append(const char*& value)
127 {
128 #ifdef WITH_DLT
129     dlt_user_log_write_string(&mDltContextData, value);
130 #endif
131 }
132
133 void DLTWrapper::append(const std::string& value)
134 {
135 #ifdef WITH_DLT
136     dlt_user_log_write_string(&mDltContextData, value.c_str());
137 #endif
138 }
139
140 void DLTWrapper::append(const bool value)
141 {
142 #ifdef WITH_DLT
143     dlt_user_log_write_bool(&mDltContextData, static_cast<uint8_t>(value));
144 #endif
145 }
146
147 DLTWrapper::~DLTWrapper()
148 {
149     if (mDLTWrapper)
150         delete mDLTWrapper;
151 }
152