system-controller: only override dst rectangle for apps.
[profile/ivi/murphy.git] / src / common / debug.h
1 /*
2  * Copyright (c) 2012, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *  * Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *  * Neither the name of Intel Corporation nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __MURPHY_DEBUG_H__
31 #define __MURPHY_DEBUG_H__
32
33 #include <stdio.h>
34
35 #include <murphy/common/macros.h>
36 #include <murphy/common/debug-info.h>
37
38 MRP_CDECL_BEGIN
39
40 /** Log a debug message if the invoking debug site is enabled. */
41 #define mrp_debug(fmt, args...)        do {                               \
42         static int __site_stamp = -1;                                     \
43         static int __site_enabled;                                        \
44                                                                           \
45         if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) {              \
46             __site_enabled = mrp_debug_check(__FUNCTION__,                \
47                                              __FILE__, __LINE__);         \
48             __site_stamp   = mrp_debug_stamp;                             \
49         }                                                                 \
50                                                                           \
51         if (MRP_UNLIKELY(__site_enabled))                                 \
52             mrp_debug_msg(__LOC__, fmt, ## args);                         \
53     } while (0)
54
55
56 /** mrp_debug variant with explicitly passed site info. */
57 #define mrp_debug_at(_file, _line, _func, fmt, args...)        do {       \
58         static int __site_stamp = -1;                                     \
59         static int __site_enabled;                                        \
60                                                                           \
61         if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) {              \
62             __site_enabled = mrp_debug_check(_func, _file, _line);        \
63             __site_stamp   = mrp_debug_stamp;                             \
64         }                                                                 \
65                                                                           \
66         if (MRP_UNLIKELY(__site_enabled))                                 \
67             mrp_debug_msg(_file, _line, _func, fmt, ## args);             \
68     } while (0)
69
70
71 /** Run a block of code if the invoking debug site is enabled. */
72 #define mrp_debug_code(...)         do {                                  \
73         static int __site_stamp = -1;                                     \
74         static int __site_enabled;                                        \
75                                                                           \
76         if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) {              \
77             __site_enabled = mrp_debug_check(__FUNCTION__,                \
78                                              __FILE__, __LINE__);         \
79             __site_stamp   = mrp_debug_stamp;                             \
80         }                                                                 \
81                                                                           \
82         if (MRP_UNLIKELY(__site_enabled)) {                               \
83             __VA_ARGS__;                                                  \
84         }                                                                 \
85     } while (0)
86
87 /** Global debug configuration stamp, exported for minimum-overhead checking. */
88 extern int mrp_debug_stamp;
89
90 /** Enable/disable debug messages globally. */
91 int mrp_debug_enable(int enabled);
92
93 /** Reset all debug configuration to the defaults. */
94 void mrp_debug_reset(void);
95
96 /** Apply the debug configuration settings given in cmd. */
97 int mrp_debug_set_config(const char *cmd);
98
99 /** Dump the active debug configuration. */
100 int mrp_debug_dump_config(FILE *fp);
101
102 /** Low-level log wrapper for debug messages. */
103 void mrp_debug_msg(const char *file, int line, const char *func,
104                    const char *format, ...) MRP_PRINTF_LIKE(4, 5);
105
106 /** Check if the given debug site is enabled. */
107 int mrp_debug_check(const char *func, const char *file, int line);
108
109 MRP_CDECL_END
110
111 #endif /* __MURPHY_DEBUG_H__ */