Bug 84 - Adding utf8 support to dlt-daemon, dlt-viewer. Modified patch, originally...
[profile/ivi/dlt-daemon.git] / include / dlt / dlt_user_macros.h
1 /**
2  * @licence app begin@
3  * Copyright (C) 2012  BMW AG
4  *
5  * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
6  *
7  * Contributions are licensed to the GENIVI Alliance under one or more
8  * Contribution License Agreements.
9  *
10  * \copyright
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/.
14  *
15  *
16  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
17  *
18  * \file dlt_user_macros.h
19  * For further information see http://www.genivi.org/.
20  * @licence end@
21  */
22
23 /*******************************************************************************
24  **                                                                            **
25  **  SRC-MODULE: dlt_user_macros.h                                             **
26  **                                                                            **
27  **  TARGET    : linux                                                         **
28  **                                                                            **
29  **  PROJECT   : DLT                                                           **
30  **                                                                            **
31  **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
32  **              Markus Klein                                                  **
33  **                                                                            **
34  **  PURPOSE   :                                                               **
35  **                                                                            **
36  **  REMARKS   :                                                               **
37  **                                                                            **
38  **  PLATFORM DEPENDANT [yes/no]: yes                                          **
39  **                                                                            **
40  **  TO BE CHANGED BY USER [yes/no]: no                                        **
41  **                                                                            **
42  *******************************************************************************/
43
44 /*******************************************************************************
45  **                      Author Identity                                       **
46  ********************************************************************************
47  **                                                                            **
48  ** Initials     Name                       Company                            **
49  ** --------     -------------------------  ---------------------------------- **
50  **  aw          Alexander Wenzel           BMW                                **
51  **  mk          Markus Klein               Fraunhofer ESK                     **
52  *******************************************************************************/
53
54 /*******************************************************************************
55  **                      Revision Control History                              **
56  *******************************************************************************/
57
58 /*
59  * $LastChangedRevision: 1515 $
60  * $LastChangedDate: 2010-12-13 09:18:54 +0100 (Mon, 13 Dec 2010) $
61  * $LastChangedBy$
62  Initials    Date         Comment
63  aw          13.01.2010   initial
64  */
65
66 #ifndef DLT_USER_MACROS_H
67 #define DLT_USER_MACORS_H
68
69 #include "dlt_version.h"
70
71 /**
72  \defgroup userapi DLT User API
73  \addtogroup userapi
74  \{
75  */
76
77 /**************************************************************************************************
78  * The folowing macros define a macro interface for DLT
79  **************************************************************************************************/
80
81 /**
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
85  */
86 #define DLT_DECLARE_CONTEXT(CONTEXT) \
87 DltContext CONTEXT;
88
89 /**
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
93  */
94 #define DLT_IMPORT_CONTEXT(CONTEXT) \
95 extern DltContext CONTEXT;
96
97 /**
98  * Register application.
99  * @param APPID application id with maximal four characters
100  * @param DESCRIPTION ASCII string containing description
101  */
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)
105
106
107 /**
108  * Unregister application.
109  */
110 #define DLT_UNREGISTER_APP() do{\
111         dlt_unregister_app();} while(0)
112
113 /**
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
118  */
119 #define DLT_REGISTER_CONTEXT(CONTEXT,CONTEXTID,DESCRIPTION) do{\
120         dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION);} while(0)
121
122 /**
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)
131  */
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)
134
135 /**
136  * Unregister context.
137  * @param CONTEXT object containing information about one special logging context
138  */
139 #define DLT_UNREGISTER_CONTEXT(CONTEXT) do{\
140         dlt_unregister_context(&(CONTEXT));} while(0)
141
142 /**
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
147  */
148 #define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) do{\
149         dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK);} while(0)
150
151 /**
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
156  */
157 #ifdef _MSC_VER
158 /* DLT_LOG is not supported by MS Visual C++ */
159 /* use function interface instead            */
160 #else
161 #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
162         do { \
163                 DltContextData log; \
164                 if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0) \
165                 { \
166             ARGS; \
167             dlt_user_log_write_finish(&log); \
168                 } \
169         } while(0)
170 #endif
171
172 /**
173  * Send log message with variable list of messages (intended for non-verbose mode)
174  * @param CONTEXT object containing information about one special logging context
175  * @param LOGLEVEL the log level of the log message
176  * @param MSGID the message id of log message
177  * @param ARGS variable list of arguments: 
178  calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(),
179  DLT_INT(), DLT_UINT(), DLT_RAW()
180  */
181 #ifdef _MSC_VER
182 /* DLT_LOG_ID is not supported by MS Visual C++ */
183 /* use function interface instead               */
184 #else
185 #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
186         do { \
187                 DltContextData log; \
188                 if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)>0) \
189                 { \
190             ARGS; \
191             dlt_user_log_write_finish(&log); \
192                 } \
193         } while(0)
194 #endif
195
196 /**
197  * Add string parameter to the log messsage.
198  * @param TEXT ASCII string
199  */
200 #define DLT_STRING(TEXT) ({ \
201         dlt_user_log_write_string(&log,TEXT); \
202         })
203
204 /**
205  * Add utf8-encoded string parameter to the log messsage.
206  * @param TEXT UTF8-encoded string
207  */
208 #define DLT_UTF8(TEXT) ({ \
209         dlt_user_log_write_utf8_string(&log,TEXT); \
210   })
211
212 /**
213  * Add boolean parameter to the log messsage.
214  * @param BOOL_VAR Boolean value (mapped to uint8)
215  */
216 #define DLT_BOOL(BOOL_VAR) ({ \
217         dlt_user_log_write_bool(&log,BOOL_VAR); \
218         })
219
220 /**
221  * Add float32 parameter to the log messsage.
222  * @param FLOAT32_VAR Float32 value (mapped to float)
223  */
224 #define DLT_FLOAT32(FLOAT32_VAR) ({ \
225         dlt_user_log_write_float32(&log,FLOAT32_VAR); \
226         })
227
228 /**
229  * Add float64 parameter to the log messsage.
230  * @param FLOAT64_VAR Float64 value (mapped to double)
231  */
232 #define DLT_FLOAT64(FLOAT64_VAR) ({ \
233         dlt_user_log_write_float64(&log,FLOAT64_VAR); \
234         })
235
236 /**
237  * Add integer parameter to the log messsage.
238  * @param INT_VAR integer value
239  */
240 #define DLT_INT(INT_VAR) ({ \
241         dlt_user_log_write_int(&log,INT_VAR); \
242         })
243 #define DLT_INT8(INT_VAR) ({ \
244         dlt_user_log_write_int8(&log,INT_VAR); \
245         })
246 #define DLT_INT16(INT_VAR) ({ \
247         dlt_user_log_write_int16(&log,INT_VAR); \
248         })
249 #define DLT_INT32(INT_VAR) ({ \
250         dlt_user_log_write_int32(&log,INT_VAR); \
251         })
252 #define DLT_INT64(INT_VAR) ({ \
253         dlt_user_log_write_int64(&log,INT_VAR); \
254         })
255
256 /**
257  * Add unsigned integer parameter to the log messsage.
258  * @param UINT_VAR unsigned integer value
259  */
260 #define DLT_UINT(UINT_VAR) ({ \
261         dlt_user_log_write_uint(&log,UINT_VAR); \
262         })
263 #define DLT_UINT8(UINT_VAR) ({ \
264         dlt_user_log_write_uint8(&log,UINT_VAR); \
265         })
266 #define DLT_UINT16(UINT_VAR) ({ \
267         dlt_user_log_write_uint16(&log,UINT_VAR); \
268         })
269 #define DLT_UINT32(UINT_VAR) ({ \
270         dlt_user_log_write_uint32(&log,UINT_VAR); \
271         })
272 #define DLT_UINT64(UINT_VAR) ({ \
273         dlt_user_log_write_uint64(&log,UINT_VAR); \
274         })
275
276 /**
277  * Add binary memory block to the log messages.
278  * @param BUF pointer to memory block
279  * @param LEN length of memory block
280  */
281 #define DLT_RAW(BUF,LEN) ({ \
282         dlt_user_log_write_raw(&log,BUF,LEN); \
283         })
284
285 /**
286  * Trace network message
287  * @param CONTEXT object containing information about one special logging context
288  * @param TYPE type of network trace message
289  * @param HEADERLEN length of network message header
290  * @param HEADER pointer to network message header
291  * @param PAYLOADLEN length of network message payload
292  * @param PAYLOAD pointer to network message payload
293  */
294 #define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
295     do { \
296         dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
297     }while(0)
298
299 /**
300  * Trace network message, allow truncation
301  * @param CONTEXT object containing information about one special logging context
302  * @param TYPE type of network trace message
303  * @param HEADERLEN length of network message header
304  * @param HEADER pointer to network message header
305  * @param PAYLOADLEN length of network message payload
306  * @param PAYLOAD pointer to network message payload
307  */
308 #define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
309     do { \
310         dlt_user_trace_network_truncated(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD, 1); \
311     }while(0)
312
313 /**
314  * Trace network message, segment large messages
315  * @param CONTEXT object containing information about one special logging context
316  * @param TYPE type of network trace message
317  * @param HEADERLEN length of network message header
318  * @param HEADER pointer to network message header
319  * @param PAYLOADLEN length of network message payload
320  * @param PAYLOAD pointer to network message payload
321  */
322 #define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
323     do { \
324         dlt_user_trace_network_segmented(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
325     }while(0)
326
327 /**
328  * Send log message with string parameter.
329  * @param CONTEXT object containing information about one special logging context
330  * @param LOGLEVEL the log level of the log message
331  * @param TEXT ASCII string
332  */
333 #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \
334     do { \
335         dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
336     } while(0)
337
338 /**
339  * Send log message with string parameter and integer parameter.
340  * @param CONTEXT object containing information about one special logging context
341  * @param LOGLEVEL the log level of the log messages
342  * @param TEXT ASCII string
343  * @param INT_VAR integer value
344  */
345 #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \
346         do { \
347         dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
348         } while(0)
349
350 /**
351  * Send log message with string parameter and unsigned integer parameter.
352  * @param CONTEXT object containing information about one special logging context
353  * @param LOGLEVEL the log level of the log message
354  * @param TEXT ASCII string
355  * @param UINT_VAR unsigned integer value
356  */
357 #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \
358         do { \
359                 dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
360         } while(0)
361
362 /**
363  * Send log message with unsigned integer parameter.
364  * @param CONTEXT object containing information about one special logging context
365  * @param LOGLEVEL the log level of the log message
366  * @param UINT_VAR unsigned integer value
367  */
368 #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \
369         do { \
370                 dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
371         } while(0)
372
373 /**
374  * Send log message with integer parameter.
375  * @param CONTEXT object containing information about one special logging context
376  * @param LOGLEVEL the log level of the log message
377  * @param INT_VAR integer value
378  */
379 #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \
380         do { \
381                 dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
382         } while(0)
383
384 /**
385  * Send log message with binary memory block.
386  * @param CONTEXT object containing information about one special logging context
387  * @param LOGLEVEL the log level of the log message
388  * @param BUF pointer to memory block
389  * @param LEN length of memory block
390  */
391 #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \
392         do { \
393                 dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
394         } while(0)
395
396 /**
397  * Switch to verbose mode
398  *
399  */
400 #define DLT_VERBOSE_MODE() do { \
401         dlt_verbose_mode();} while(0)
402
403 /**
404  * Switch to non-verbose mode
405  *
406  */
407 #define DLT_NONVERBOSE_MODE() do {\
408         dlt_nonverbose_mode();} while(0)
409
410 /**
411  * Set maximum logged log level and trace status of application
412  *
413  * @param LOGLEVEL This is the log level to be set for the whole application
414  * @param TRACESTATUS This is the trace status to be set for the whole application
415  */
416 #define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) do {\
417     dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS);} while(0)
418
419 /**
420  * Enable local printing of messages
421  *
422  */
423 #define DLT_ENABLE_LOCAL_PRINT() do {\
424         dlt_enable_local_print();} while(0)
425
426 /**
427  * Disable local printing of messages
428  *
429  */
430 #define DLT_DISABLE_LOCAL_PRINT() do {\
431         dlt_disable_local_print();} while(0)
432
433 /**
434  \}
435  */
436
437 #endif /* DLT_USER_MACROS_H */