automotive-dlt
dlt_user_macros.h
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 /*******************************************************************************
28  ** **
29  ** SRC-MODULE: dlt_user_macros.h **
30  ** **
31  ** TARGET : linux **
32  ** **
33  ** PROJECT : DLT **
34  ** **
35  ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
36  ** Markus Klein **
37  ** **
38  ** PURPOSE : **
39  ** **
40  ** REMARKS : **
41  ** **
42  ** PLATFORM DEPENDANT [yes/no]: yes **
43  ** **
44  ** TO BE CHANGED BY USER [yes/no]: no **
45  ** **
46  *******************************************************************************/
47 
48 /*******************************************************************************
49  ** Author Identity **
50  ********************************************************************************
51  ** **
52  ** Initials Name Company **
53  ** -------- ------------------------- ---------------------------------- **
54  ** aw Alexander Wenzel BMW **
55  ** mk Markus Klein Fraunhofer ESK **
56  *******************************************************************************/
57 
58 /*******************************************************************************
59  ** Revision Control History **
60  *******************************************************************************/
61 
62 /*
63  * $LastChangedRevision: 1515 $
64  * $LastChangedDate: 2010-12-13 09:18:54 +0100 (Mon, 13 Dec 2010) $
65  * $LastChangedBy$
66  Initials Date Comment
67  aw 13.01.2010 initial
68  */
69 
70 #ifndef DLT_USER_MACROS_H
71 #define DLT_USER_MACROS_H
72 
73 #include "dlt_version.h"
74 
81 /**************************************************************************************************
82  * The folowing macros define a macro interface for DLT
83  **************************************************************************************************/
84 
93 #define DLT_DECLARE_CONTEXT(CONTEXT) \
94  DltContext CONTEXT;
95 
104 #define DLT_IMPORT_CONTEXT(CONTEXT) \
105  extern DltContext CONTEXT;
106 
112 #define DLT_REGISTER_APP(APPID,DESCRIPTION) do {\
113  (void)dlt_check_library_version(_DLT_PACKAGE_MAJOR_VERSION, _DLT_PACKAGE_MINOR_VERSION ); \
114  (void)dlt_register_app( APPID, DESCRIPTION);} while(0)
115 
116 
120 #define DLT_UNREGISTER_APP() do{\
121  (void)dlt_unregister_app();} while(0)
122 
129 #define DLT_REGISTER_CONTEXT(CONTEXT,CONTEXTID,DESCRIPTION) do{\
130  (void)dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION);} while(0)
131 
142 #define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT,CONTEXTID,DESCRIPTION,LOGLEVEL,TRACESTATUS) do{\
143  (void)dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS);} while(0)
144 
149 #define DLT_UNREGISTER_CONTEXT(CONTEXT) do{\
150  (void)dlt_unregister_context(&(CONTEXT));} while(0)
151 
158 #define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do{\
159  (void)dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK);} while(0)
160 
166 #define DLT_REGISTER_LOG_LEVEL_CHANGED_CALLBACK(CONTEXT, CALLBACK) do{\
167  (void)dlt_register_log_level_changed_callback(&(CONTEXT),CALLBACK);} while(0)
168 
178 #ifdef _MSC_VER
179 /* DLT_LOG is not supported by MS Visual C++ */
180 /* use function interface instead */
181 #else
182 #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
183  do { \
184  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
185  { \
186  DltContextData log_local; \
187  int dlt_local; \
188  dlt_local = dlt_user_log_write_start(&CONTEXT,&log_local,LOGLEVEL); \
189  if (dlt_local > 0) \
190  { \
191  ARGS; \
192  (void)dlt_user_log_write_finish(&log_local); \
193  } \
194  } \
195  } while(0)
196 #endif
197 
210 #ifdef _MSC_VER
211 /* DLT_LOG_ID is not supported by MS Visual C++ */
212 /* use function interface instead */
213 #else
214 #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
215  do { \
216  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
217  { \
218  DltContextData log_local; \
219  int dlt_local; \
220  dlt_local = dlt_user_log_write_start_id(&CONTEXT,&log_local,LOGLEVEL,MSGID); \
221  if (dlt_local > 0) \
222  { \
223  ARGS; \
224  (void)dlt_user_log_write_finish(&log_local); \
225  } \
226  } \
227  } while(0)
228 #endif
229 
234 #define DLT_STRING(TEXT) \
235  (void)dlt_user_log_write_string(&log_local,TEXT)
236 
241 #define DLT_CSTRING(TEXT) \
242  (void)dlt_user_log_write_constant_string(&log_local,TEXT)
243 
248 #define DLT_UTF8(TEXT) \
249  (void)dlt_user_log_write_utf8_string(&log_local,TEXT)
250 
255 #define DLT_BOOL(BOOL_VAR) \
256  (void)dlt_user_log_write_bool(&log_local,BOOL_VAR)
257 
262 #define DLT_FLOAT32(FLOAT32_VAR) \
263  (void)dlt_user_log_write_float32(&log_local,FLOAT32_VAR)
264 
269 #define DLT_FLOAT64(FLOAT64_VAR) \
270  (void)dlt_user_log_write_float64(&log_local,FLOAT64_VAR)
271 
276 #define DLT_INT(INT_VAR) \
277  (void)dlt_user_log_write_int(&log_local,INT_VAR)
278 
279 #define DLT_INT8(INT_VAR) \
280  (void)dlt_user_log_write_int8(&log_local,INT_VAR)
281 
282 #define DLT_INT16(INT_VAR) \
283  (void)dlt_user_log_write_int16(&log_local,INT_VAR)
284 
285 #define DLT_INT32(INT_VAR) \
286  (void)dlt_user_log_write_int32(&log_local,INT_VAR)
287 
288 #define DLT_INT64(INT_VAR) \
289  (void)dlt_user_log_write_int64(&log_local,INT_VAR)
290 
295 #define DLT_UINT(UINT_VAR) \
296  (void)dlt_user_log_write_uint(&log_local,UINT_VAR)
297 
298 #define DLT_UINT8(UINT_VAR) \
299  (void)dlt_user_log_write_uint8(&log_local,UINT_VAR)
300 
301 #define DLT_UINT16(UINT_VAR) \
302  (void)dlt_user_log_write_uint16(&log_local,UINT_VAR)
303 
304 #define DLT_UINT32(UINT_VAR) \
305  (void)dlt_user_log_write_uint32(&log_local,UINT_VAR)
306 
307 #define DLT_UINT64(UINT_VAR) \
308  (void)dlt_user_log_write_uint64(&log_local,UINT_VAR)
309 
315 #define DLT_RAW(BUF,LEN) \
316  (void)dlt_user_log_write_raw(&log_local,BUF,LEN)
317 #define DLT_HEX8(UINT_VAR) \
318  (void)dlt_user_log_write_uint8_formatted(&log_local,UINT_VAR,DLT_FORMAT_HEX8)
319 #define DLT_HEX16(UINT_VAR) \
320  (void)dlt_user_log_write_uint16_formatted(&log_local,UINT_VAR,DLT_FORMAT_HEX16)
321 #define DLT_HEX32(UINT_VAR) \
322  (void)dlt_user_log_write_uint32_formatted(&log_local,UINT_VAR,DLT_FORMAT_HEX32)
323 #define DLT_HEX64(UINT_VAR) \
324  (void)dlt_user_log_write_uint64_formatted(&log_local,UINT_VAR,DLT_FORMAT_HEX64)
325 #define DLT_BIN8(UINT_VAR) \
326  (void)dlt_user_log_write_uint8_formatted(&log_local,UINT_VAR,DLT_FORMAT_BIN8)
327 #define DLT_BIN16(UINT_VAR) \
328  (void)dlt_user_log_write_uint16_formatted(&log_local,UINT_VAR,DLT_FORMAT_BIN16)
329 
333 #define DLT_PTR(PTR_VAR) \
334  (void)dlt_user_log_write_ptr(&log_local, PTR_VAR)
335 
345 #define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
346  do { \
347  if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
348  { \
349  (void)dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
350  } \
351  }while(0)
352 
362 #define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
363  do { \
364  if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
365  { \
366  (void)dlt_user_trace_network_truncated(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD, 1); \
367  } \
368  }while(0)
369 
379 #define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
380  do { \
381  if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
382  { \
383  (void)dlt_user_trace_network_segmented(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
384  } \
385  }while(0)
386 
393 #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \
394  do { \
395  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
396  { \
397  (void)dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
398  } \
399  } while(0)
400 
408 #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \
409  do { \
410  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
411  { \
412  (void)dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
413  } \
414  } while(0)
415 
423 #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \
424  do { \
425  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
426  { \
427  (void)dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
428  } \
429  } while(0)
430 
437 #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \
438  do { \
439  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
440  { \
441  (void)dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
442  } \
443  } while(0)
444 
451 #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \
452  do { \
453  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
454  { \
455  (void)dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
456  } \
457  } while(0)
458 
466 #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \
467  do { \
468  if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
469  { \
470  (void)dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
471  } \
472  } while(0)
473 
477 #define DLT_LOG_MARKER() \
478  do { \
479  (void)dlt_log_marker(); \
480  } while(0)
481 
486 #define DLT_VERBOSE_MODE() do { \
487  (void)dlt_verbose_mode();} while(0)
488 
493 #define DLT_NONVERBOSE_MODE() do {\
494  (void)dlt_nonverbose_mode();} while(0)
495 
502 #define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) do {\
503  (void)dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS);} while(0)
504 
509 #define DLT_ENABLE_LOCAL_PRINT() do {\
510  (void)dlt_enable_local_print();} while(0)
511 
516 #define DLT_DISABLE_LOCAL_PRINT() do {\
517  (void)dlt_disable_local_print();} while(0)
518 
525 #define DLT_IS_LOG_LEVEL_ENABLED(CONTEXT,LOGLEVEL) \
526  (dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL) == DLT_RETURN_TRUE)
527 
532 #endif /* DLT_USER_MACROS_H */