Init of dlt daemon
[profile/ivi/dlt-daemon.git] / include / dlt / dlt_user_macros.h
1 /*
2  * Dlt- Diagnostic Log and Trace console apps
3  * @licence app begin@
4  *
5  * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
6  * 
7  * This program is free software; you can redistribute it and/or modify it under the terms of the 
8  * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 
11  * Public License, version 2.1, for more details.
12  * 
13  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along 
14  * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
15  * 
16  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may 
17  * also be applicable to programs even in cases in which the program is not a library in the technical sense.
18  * 
19  * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may 
20  * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to 
21  * license your linked modules under the GNU Lesser General Public License, version 2.1, you 
22  * may use the program under the following exception.
23  * 
24  * As a special exception, the copyright holders of DLT give you permission to combine DLT 
25  * with software programs or libraries that are released under any license unless such a combination is not
26  * permitted by the license of such a software program or library. You may copy and distribute such a 
27  * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28  * special exception, for DLT and the licenses of the other code concerned.
29  * 
30  * Note that people who make modified versions of DLT are not obligated to grant this special exception 
31  * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, 
32  * version 2.1, gives permission to release a modified version without this exception; this exception 
33  * also makes it possible to release a modified version which carries forward this exception.
34  *
35  * @licence end@
36  */
37
38
39 /*******************************************************************************
40 **                                                                            **
41 **  SRC-MODULE: dlt_user_macros.h                                             **
42 **                                                                            **
43 **  TARGET    : linux                                                         **
44 **                                                                            **
45 **  PROJECT   : DLT                                                           **
46 **                                                                            **
47 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
48 **              Markus Klein                                                  **
49 **                                                                            **
50 **  PURPOSE   :                                                               **
51 **                                                                            **
52 **  REMARKS   :                                                               **
53 **                                                                            **
54 **  PLATFORM DEPENDANT [yes/no]: yes                                          **
55 **                                                                            **
56 **  TO BE CHANGED BY USER [yes/no]: no                                        **
57 **                                                                            **
58 *******************************************************************************/
59
60 /*******************************************************************************
61 **                      Author Identity                                       **
62 ********************************************************************************
63 **                                                                            **
64 ** Initials     Name                       Company                            **
65 ** --------     -------------------------  ---------------------------------- **
66 **  aw          Alexander Wenzel           BMW                                **
67 **  mk          Markus Klein               Fraunhofer ESK                     **
68 *******************************************************************************/
69
70 /*******************************************************************************
71 **                      Revision Control History                              **
72 *******************************************************************************/
73
74 /*
75  * $LastChangedRevision: 1515 $
76  * $LastChangedDate: 2010-12-13 09:18:54 +0100 (Mon, 13 Dec 2010) $
77  * $LastChangedBy$
78  Initials    Date         Comment
79  aw          13.01.2010   initial
80  */
81
82 #ifndef DLT_USER_MACROS_H
83 #define DLT_USER_MACORS_H
84
85 /**
86   \defgroup userapi DLT User API
87   \addtogroup userapi
88   \{
89 */
90
91 /**************************************************************************************************
92 * The folowing macros define a macro interface for DLT
93 **************************************************************************************************/
94
95 /**
96  * Create an object for a new context.
97  * This macro has to be called first for every.
98  * @param CONTEXT object containing information about one special logging context
99  */
100 #define DLT_DECLARE_CONTEXT(CONTEXT) \
101 DltContext CONTEXT;
102
103 /**
104  * Use an object of a new context created in another module.
105  * This macro has to be called first for every.
106  * @param CONTEXT object containing information about one special logging context
107  */
108 #define DLT_IMPORT_CONTEXT(CONTEXT) \
109 extern DltContext CONTEXT;
110
111 /**
112  * Register application.
113  * @param APPID application id with maximal four characters
114  * @param DESCRIPTION ASCII string containing description
115  */
116 #define DLT_REGISTER_APP(APPID,DESCRIPTION) \
117     dlt_register_app( APPID, DESCRIPTION);
118
119 /**
120  * Unregister application.
121  */
122 #define DLT_UNREGISTER_APP() \
123         dlt_unregister_app();
124
125 /**
126  * Register context (with default log level and default trace status)
127  * @param CONTEXT object containing information about one special logging context
128  * @param CONTEXTID context id with maximal four characters
129  * @param DESCRIPTION ASCII string containing description
130  */
131 #define DLT_REGISTER_CONTEXT(CONTEXT,CONTEXTID,DESCRIPTION) \
132         dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION);
133
134 /**
135  * Register context with pre-defined log level and pre-defined trace status.
136  * @param CONTEXT object containing information about one special logging context
137  * @param CONTEXTID context id with maximal four characters
138  * @param DESCRIPTION ASCII string containing description
139  * @param LOGLEVEL log level to be pre-set for this context
140           (DLT_LOG_DEFAULT is not allowed here)
141  * @param TRACESTATUS trace status to be pre-set for this context
142                   (DLT_TRACE_STATUS_DEFAULT is not allowed here)
143  */
144 #define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT,CONTEXTID,DESCRIPTION,LOGLEVEL,TRACESTATUS) \
145         dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS);
146
147 /**
148  * Unregister context.
149  * @param CONTEXT object containing information about one special logging context
150  */
151 #define DLT_UNREGISTER_CONTEXT(CONTEXT) \
152         dlt_unregister_context(&(CONTEXT));
153
154 /**
155  * Register callback function called when injection message was received
156  * @param CONTEXT object containing information about one special logging context
157  * @param SERVICEID service id of the injection message
158  * @param CALLBACK function pointer to callback function
159  */
160 #define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) \
161         dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK);
162
163 /**
164  * Send log message with variable list of messages (intended for verbose mode)
165  * @param CONTEXT object containing information about one special logging context
166  * @param LOGLEVEL the log level of the log message
167  * @param ARGS variable list of arguments
168  */
169 #ifdef _MSC_VER
170   /* DLT_LOG is not supported by MS Visual C++ */
171   /* use function interface instead            */
172 #else
173 #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
174         { \
175                 DltContextData log; \
176                 if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)) \
177                 { \
178             ARGS; \
179             dlt_user_log_write_finish(&log); \
180                 } \
181         }
182 #endif
183
184 /**
185  * Send log message with variable list of messages (intended for non-verbose mode)
186  * @param CONTEXT object containing information about one special logging context
187  * @param LOGLEVEL the log level of the log message
188  * @param MSGID the message id of log message
189  * @param ARGS variable list of arguments: 
190           calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(),
191           DLT_INT(), DLT_UINT(), DLT_RAW()
192  */
193 #ifdef _MSC_VER
194   /* DLT_LOG_ID is not supported by MS Visual C++ */
195   /* use function interface instead               */
196 #else
197 #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
198         { \
199                 DltContextData log; \
200                 if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)) \
201                 { \
202             ARGS; \
203             dlt_user_log_write_finish(&log); \
204                 } \
205         }
206 #endif
207
208 /**
209  * Add string parameter to the log messsage.
210  * @param TEXT ASCII string
211  */
212 #define DLT_STRING(TEXT) ({ \
213         dlt_user_log_write_string(&log,TEXT); \
214         })
215
216 /**
217  * Add boolean parameter to the log messsage.
218  * @param BOOL_VAR Boolean value (mapped to uint8)
219  */
220 #define DLT_BOOL(BOOL_VAR) ({ \
221         dlt_user_log_write_bool(&log,BOOL_VAR); \
222         })
223
224 /**
225  * Add float32 parameter to the log messsage.
226  * @param FLOAT32_VAR Float32 value (mapped to float)
227  */
228 #define DLT_FLOAT32(FLOAT32_VAR) ({ \
229         dlt_user_log_write_float32(&log,FLOAT32_VAR); \
230         })
231
232 /**
233  * Add float64 parameter to the log messsage.
234  * @param FLOAT64_VAR Float64 value (mapped to double)
235  */
236 #define DLT_FLOAT64(FLOAT64_VAR) ({ \
237         dlt_user_log_write_float64(&log,FLOAT64_VAR); \
238         })
239
240 /**
241  * Add integer parameter to the log messsage.
242  * @param INT_VAR integer value
243  */
244 #define DLT_INT(INT_VAR) ({ \
245         dlt_user_log_write_int(&log,INT_VAR); \
246         })
247 #define DLT_INT8(INT_VAR) ({ \
248         dlt_user_log_write_int8(&log,INT_VAR); \
249         })
250 #define DLT_INT16(INT_VAR) ({ \
251         dlt_user_log_write_int16(&log,INT_VAR); \
252         })
253 #define DLT_INT32(INT_VAR) ({ \
254         dlt_user_log_write_int32(&log,INT_VAR); \
255         })
256 #define DLT_INT64(INT_VAR) ({ \
257         dlt_user_log_write_int64(&log,INT_VAR); \
258         })
259
260 /**
261  * Add unsigned integer parameter to the log messsage.
262  * @param UINT_VAR unsigned integer value
263  */
264 #define DLT_UINT(UINT_VAR) ({ \
265         dlt_user_log_write_uint(&log,UINT_VAR); \
266         })
267 #define DLT_UINT8(UINT_VAR) ({ \
268         dlt_user_log_write_uint8(&log,UINT_VAR); \
269         })
270 #define DLT_UINT16(UINT_VAR) ({ \
271         dlt_user_log_write_uint16(&log,UINT_VAR); \
272         })
273 #define DLT_UINT32(UINT_VAR) ({ \
274         dlt_user_log_write_uint32(&log,UINT_VAR); \
275         })
276 #define DLT_UINT64(UINT_VAR) ({ \
277         dlt_user_log_write_uint64(&log,UINT_VAR); \
278         })
279
280 /**
281  * Add binary memory block to the log messages.
282  * @param BUF pointer to memory block
283  * @param LEN length of memory block
284  */
285 #define DLT_RAW(BUF,LEN) ({ \
286         dlt_user_log_write_raw(&log,BUF,LEN); \
287         })
288
289 /**
290  * Trace network message
291  * @param CONTEXT object containing information about one special logging context
292  * @param TYPE type of network trace message
293  * @param HEADERLEN length of network message header
294  * @param HEADER pointer to network message header
295  * @param PAYLOADLEN length of network message payload
296  * @param PAYLOAD pointer to network message payload
297  */
298 #define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
299     { \
300         dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
301     }
302
303 /**
304  * Send log message with string parameter.
305  * @param CONTEXT object containing information about one special logging context
306  * @param LOGLEVEL the log level of the log message
307  * @param TEXT ASCII string
308  */
309 #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \
310     { \
311         dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
312     }
313
314
315 /**
316  * Send log message with string parameter and integer parameter.
317  * @param CONTEXT object containing information about one special logging context
318  * @param LOGLEVEL the log level of the log messages
319  * @param TEXT ASCII string
320  * @param INT_VAR integer value
321  */
322 #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \
323         { \
324         dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
325         }
326
327 /**
328  * Send log message with string parameter and unsigned integer 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  * @param UINT_VAR unsigned integer value
333  */
334 #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \
335         { \
336                 dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
337         }
338
339 /**
340  * Send log message with unsigned integer parameter.
341  * @param CONTEXT object containing information about one special logging context
342  * @param LOGLEVEL the log level of the log message
343  * @param UINT_VAR unsigned integer value
344  */
345 #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \
346         { \
347                 dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
348         }
349
350 /**
351  * Send log message with 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 INT_VAR integer value
355  */
356 #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \
357         { \
358                 dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
359         }
360
361 /**
362  * Send log message with binary memory block.
363  * @param CONTEXT object containing information about one special logging context
364  * @param LOGLEVEL the log level of the log message
365  * @param BUF pointer to memory block
366  * @param LEN length of memory block
367  */
368 #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \
369         { \
370                 dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
371         }
372
373 /**
374  * Switch to verbose mode
375  *
376  */
377 #define DLT_VERBOSE_MODE() \
378         dlt_verbose_mode();
379
380 /**
381  * Switch to non-verbose mode
382  *
383  */
384 #define DLT_NONVERBOSE_MODE() \
385         dlt_nonverbose_mode();
386
387 /**
388  * Set maximum logged log level and trace status of application
389  *
390  * @param LOGLEVEL This is the log level to be set for the whole application
391  * @param TRACESTATUS This is the trace status to be set for the whole application
392  */
393 #define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) \
394     dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS);
395
396 /**
397  * Enable local printing of messages
398  *
399  */
400 #define DLT_ENABLE_LOCAL_PRINT() \
401         dlt_enable_local_print();
402
403 /**
404  * Disable local printing of messages
405  *
406  */
407 #define DLT_DISABLE_LOCAL_PRINT() \
408         dlt_disable_local_print();
409
410 /**
411   \}
412 */
413
414 #endif /* DLT_USER_MACROS_H */