Merge branch 'master' of github.com:otcshare/murphy
[profile/ivi/murphy.git] / src / common / debug.h
1 #ifndef __MURPHY_DEBUG_H__
2 #define __MURPHY_DEBUG_H__
3
4 #include <stdio.h>
5
6 #include <murphy/common/macros.h>
7
8 MRP_CDECL_BEGIN
9
10 /** Macro to generate a debug site string. */
11 #define MRP_DEBUG_SITE(file, line, func)        \
12     "__DEBUG_SITE_"file":"MRP_STRINGIFY(line)
13
14 /** Log a debug message if the invoking debug site is enabled. */
15 #define mrp_debug(fmt, args...) do {                                    \
16         static const char *__site =                                     \
17             MRP_DEBUG_SITE(__FILE__, __LINE__, __FUNCTION__);           \
18         static int __site_stamp = -1;                                   \
19         static int __site_enabled;                                      \
20                                                                         \
21         if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) {            \
22             __site_enabled = mrp_debug_check(__FUNCTION__,              \
23                                              __FILE__, __LINE__);       \
24             __site_stamp   = mrp_debug_stamp;                           \
25         }                                                               \
26                                                                         \
27         if (MRP_UNLIKELY(__site_enabled))                               \
28             mrp_debug_msg(__site, __LOC__, fmt, ## args);               \
29     } while (0)
30
31 /** Global debug configuration stamp, exported for minimum-overhead checking. */
32 extern int mrp_debug_stamp;
33
34 /** Enable/disable debug messages globally. */
35 int mrp_debug_enable(int enabled);
36
37 /** Reset all debug configuration to the defaults. */
38 void mrp_debug_reset(void);
39
40 /** Apply the debug configuration settings given in cmd. */
41 int mrp_debug_set_config(const char *cmd);
42
43 /** Dump the active debug configuration. */
44 int mrp_debug_dump_config(FILE *fp);
45
46 /** Low-level log wrapper for debug messages. */
47 void mrp_debug_msg(const char *site, const char *file, int line,
48                    const char *func, const char *format, ...);
49
50 /** Check if the given debug site is enabled. */
51 int mrp_debug_check(const char *func, const char *file, int line);
52
53 MRP_CDECL_END
54
55 #endif /* __MURPHY_DEBUG_H__ */