3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
11 * This Source Code Form is subject to the terms of the
12 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
13 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
18 * \file dlt_user_macros.h
19 * For further information see http://www.genivi.org/.
23 /*******************************************************************************
25 ** SRC-MODULE: dlt_user_macros.h **
31 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
38 ** PLATFORM DEPENDANT [yes/no]: yes **
40 ** TO BE CHANGED BY USER [yes/no]: no **
42 *******************************************************************************/
44 /*******************************************************************************
46 ********************************************************************************
48 ** Initials Name Company **
49 ** -------- ------------------------- ---------------------------------- **
50 ** aw Alexander Wenzel BMW **
51 ** mk Markus Klein Fraunhofer ESK **
52 *******************************************************************************/
54 /*******************************************************************************
55 ** Revision Control History **
56 *******************************************************************************/
59 * $LastChangedRevision: 1515 $
60 * $LastChangedDate: 2010-12-13 09:18:54 +0100 (Mon, 13 Dec 2010) $
66 #ifndef DLT_USER_MACROS_H
67 #define DLT_USER_MACORS_H
69 #include "dlt_version.h"
72 \defgroup userapi DLT User API
77 /**************************************************************************************************
78 * The folowing macros define a macro interface for DLT
79 **************************************************************************************************/
82 * Create an object for a new context.
83 * This macro has to be called first for every.
84 * @param CONTEXT object containing information about one special logging context
86 #define DLT_DECLARE_CONTEXT(CONTEXT) \
90 * Use an object of a new context created in another module.
91 * This macro has to be called first for every.
92 * @param CONTEXT object containing information about one special logging context
94 #define DLT_IMPORT_CONTEXT(CONTEXT) \
95 extern DltContext CONTEXT;
98 * Register application.
99 * @param APPID application id with maximal four characters
100 * @param DESCRIPTION ASCII string containing description
102 #define DLT_REGISTER_APP(APPID,DESCRIPTION) do {\
103 dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION ); \
104 dlt_register_app( APPID, DESCRIPTION);} while(0)
108 * Unregister application.
110 #define DLT_UNREGISTER_APP() do{\
111 dlt_unregister_app();} while(0)
114 * Register context (with default log level and default trace status)
115 * @param CONTEXT object containing information about one special logging context
116 * @param CONTEXTID context id with maximal four characters
117 * @param DESCRIPTION ASCII string containing description
119 #define DLT_REGISTER_CONTEXT(CONTEXT,CONTEXTID,DESCRIPTION) do{\
120 dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION);} while(0)
123 * Register context with pre-defined log level and pre-defined trace status.
124 * @param CONTEXT object containing information about one special logging context
125 * @param CONTEXTID context id with maximal four characters
126 * @param DESCRIPTION ASCII string containing description
127 * @param LOGLEVEL log level to be pre-set for this context
128 (DLT_LOG_DEFAULT is not allowed here)
129 * @param TRACESTATUS trace status to be pre-set for this context
130 (DLT_TRACE_STATUS_DEFAULT is not allowed here)
132 #define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT,CONTEXTID,DESCRIPTION,LOGLEVEL,TRACESTATUS) do{\
133 dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS);} while(0)
136 * Unregister context.
137 * @param CONTEXT object containing information about one special logging context
139 #define DLT_UNREGISTER_CONTEXT(CONTEXT) do{\
140 dlt_unregister_context(&(CONTEXT));} while(0)
143 * Register callback function called when injection message was received
144 * @param CONTEXT object containing information about one special logging context
145 * @param SERVICEID service id of the injection message
146 * @param CALLBACK function pointer to callback function
148 #define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do{\
149 dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK);} while(0)
152 * Send log message with variable list of messages (intended for verbose mode)
153 * @param CONTEXT object containing information about one special logging context
154 * @param LOGLEVEL the log level of the log message
155 * @param ARGS variable list of arguments
158 /* DLT_LOG is not supported by MS Visual C++ */
159 /* use function interface instead */
161 #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
163 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
165 DltContextData log; \
166 if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0) \
169 dlt_user_log_write_finish(&log); \
176 * Send log message with variable list of messages (intended for non-verbose mode)
177 * @param CONTEXT object containing information about one special logging context
178 * @param LOGLEVEL the log level of the log message
179 * @param MSGID the message id of log message
180 * @param ARGS variable list of arguments:
181 calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(),
182 DLT_INT(), DLT_UINT(), DLT_RAW()
185 /* DLT_LOG_ID is not supported by MS Visual C++ */
186 /* use function interface instead */
188 #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
190 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
192 DltContextData log; \
193 if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)>0) \
196 dlt_user_log_write_finish(&log); \
203 * Add string parameter to the log messsage.
204 * @param TEXT ASCII string
206 #define DLT_STRING(TEXT) \
207 dlt_user_log_write_string(&log,TEXT)
210 * Add constant string parameter to the log messsage.
211 * @param TEXT Constant ASCII string
213 #define DLT_CSTRING(TEXT) \
214 dlt_user_log_write_constant_string(&log,TEXT)
217 * Add utf8-encoded string parameter to the log messsage.
218 * @param TEXT UTF8-encoded string
220 #define DLT_UTF8(TEXT) \
221 dlt_user_log_write_utf8_string(&log,TEXT)
224 * Add boolean parameter to the log messsage.
225 * @param BOOL_VAR Boolean value (mapped to uint8)
227 #define DLT_BOOL(BOOL_VAR) \
228 dlt_user_log_write_bool(&log,BOOL_VAR)
231 * Add float32 parameter to the log messsage.
232 * @param FLOAT32_VAR Float32 value (mapped to float)
234 #define DLT_FLOAT32(FLOAT32_VAR) \
235 dlt_user_log_write_float32(&log,FLOAT32_VAR)
238 * Add float64 parameter to the log messsage.
239 * @param FLOAT64_VAR Float64 value (mapped to double)
241 #define DLT_FLOAT64(FLOAT64_VAR) \
242 dlt_user_log_write_float64(&log,FLOAT64_VAR)
245 * Add integer parameter to the log messsage.
246 * @param INT_VAR integer value
248 #define DLT_INT(INT_VAR) \
249 dlt_user_log_write_int(&log,INT_VAR)
251 #define DLT_INT8(INT_VAR) \
252 dlt_user_log_write_int8(&log,INT_VAR)
254 #define DLT_INT16(INT_VAR) \
255 dlt_user_log_write_int16(&log,INT_VAR)
257 #define DLT_INT32(INT_VAR) \
258 dlt_user_log_write_int32(&log,INT_VAR)
260 #define DLT_INT64(INT_VAR) \
261 dlt_user_log_write_int64(&log,INT_VAR)
264 * Add unsigned integer parameter to the log messsage.
265 * @param UINT_VAR unsigned integer value
267 #define DLT_UINT(UINT_VAR) \
268 dlt_user_log_write_uint(&log,UINT_VAR)
270 #define DLT_UINT8(UINT_VAR) \
271 dlt_user_log_write_uint8(&log,UINT_VAR)
273 #define DLT_UINT16(UINT_VAR) \
274 dlt_user_log_write_uint16(&log,UINT_VAR)
276 #define DLT_UINT32(UINT_VAR) \
277 dlt_user_log_write_uint32(&log,UINT_VAR)
279 #define DLT_UINT64(UINT_VAR) \
280 dlt_user_log_write_uint64(&log,UINT_VAR)
283 * Add binary memory block to the log messages.
284 * @param BUF pointer to memory block
285 * @param LEN length of memory block
287 #define DLT_RAW(BUF,LEN) \
288 dlt_user_log_write_raw(&log,BUF,LEN)
291 * Trace network message
292 * @param CONTEXT object containing information about one special logging context
293 * @param TYPE type of network trace message
294 * @param HEADERLEN length of network message header
295 * @param HEADER pointer to network message header
296 * @param PAYLOADLEN length of network message payload
297 * @param PAYLOAD pointer to network message payload
299 #define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
301 if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
303 dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
308 * Trace network message, allow truncation
309 * @param CONTEXT object containing information about one special logging context
310 * @param TYPE type of network trace message
311 * @param HEADERLEN length of network message header
312 * @param HEADER pointer to network message header
313 * @param PAYLOADLEN length of network message payload
314 * @param PAYLOAD pointer to network message payload
316 #define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
318 if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
320 dlt_user_trace_network_truncated(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD, 1); \
325 * Trace network message, segment large messages
326 * @param CONTEXT object containing information about one special logging context
327 * @param TYPE type of network trace message
328 * @param HEADERLEN length of network message header
329 * @param HEADER pointer to network message header
330 * @param PAYLOADLEN length of network message payload
331 * @param PAYLOAD pointer to network message payload
333 #define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
335 if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
337 dlt_user_trace_network_segmented(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
342 * Send log message with string parameter.
343 * @param CONTEXT object containing information about one special logging context
344 * @param LOGLEVEL the log level of the log message
345 * @param TEXT ASCII string
347 #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \
349 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
351 dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
356 * Send log message with string parameter and integer parameter.
357 * @param CONTEXT object containing information about one special logging context
358 * @param LOGLEVEL the log level of the log messages
359 * @param TEXT ASCII string
360 * @param INT_VAR integer value
362 #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \
364 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
366 dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
371 * Send log message with string parameter and unsigned integer parameter.
372 * @param CONTEXT object containing information about one special logging context
373 * @param LOGLEVEL the log level of the log message
374 * @param TEXT ASCII string
375 * @param UINT_VAR unsigned integer value
377 #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \
379 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
381 dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
386 * Send log message with unsigned integer parameter.
387 * @param CONTEXT object containing information about one special logging context
388 * @param LOGLEVEL the log level of the log message
389 * @param UINT_VAR unsigned integer value
391 #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \
393 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
395 dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
400 * Send log message with integer parameter.
401 * @param CONTEXT object containing information about one special logging context
402 * @param LOGLEVEL the log level of the log message
403 * @param INT_VAR integer value
405 #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \
407 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
409 dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
414 * Send log message with binary memory block.
415 * @param CONTEXT object containing information about one special logging context
416 * @param LOGLEVEL the log level of the log message
417 * @param BUF pointer to memory block
418 * @param LEN length of memory block
420 #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \
422 if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
424 dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
429 * Switch to verbose mode
432 #define DLT_VERBOSE_MODE() do { \
433 dlt_verbose_mode();} while(0)
436 * Switch to non-verbose mode
439 #define DLT_NONVERBOSE_MODE() do {\
440 dlt_nonverbose_mode();} while(0)
443 * Set maximum logged log level and trace status of application
445 * @param LOGLEVEL This is the log level to be set for the whole application
446 * @param TRACESTATUS This is the trace status to be set for the whole application
448 #define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) do {\
449 dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS);} while(0)
452 * Enable local printing of messages
455 #define DLT_ENABLE_LOCAL_PRINT() do {\
456 dlt_enable_local_print();} while(0)
459 * Disable local printing of messages
462 #define DLT_DISABLE_LOCAL_PRINT() do {\
463 dlt_disable_local_print();} while(0)
469 #endif /* DLT_USER_MACROS_H */