tizen 2.4 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / lib / xdbg_log.h
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #if defined(XDBG_CLIENT)
33 #error "This header is not for client."
34 #endif
35
36 #ifndef __XDBG_LOG_H__
37 #define __XDBG_LOG_H__
38
39 #include <errno.h>
40 #include <stdlib.h>
41 #include <xorg-server.h>
42 #include <os.h>
43 #include <xdbg_log_secure.h>
44
45 unsigned int xDbgLogGetModule (char *name);
46 Bool         xDbgGetLogEnableDlog ();
47
48 #define _C(b,s)             (((b) >> (s)) & 0xFF)
49 #define _B(c,s)             ((((unsigned int)(c)) & 0xff) << (s))
50 #define XDBG_M(a,b,c,d)     (_B(d,24)|_B(c,16)|_B(b,8)|_B(a,0))
51
52 /* debug module for XDBG */
53 #define MXDBG    XDBG_M('X','D','B','G')
54
55 // Masks
56 #define XLOG_MASK_LOGLEVEL   0x000000FF
57 #define XLOG_MASK_OPTIONS    0xFFFFFF00
58
59 // LogLevels
60 enum
61 {
62     XLOG_LEVEL_0,
63     XLOG_LEVEL_1,
64     XLOG_LEVEL_2,
65     XLOG_LEVEL_3,
66     XLOG_LEVEL_4,
67     XLOG_LEVEL_MAX,
68     XLOG_LEVEL_DEFAULT = XLOG_LEVEL_MAX,
69 };
70
71 #define XDBG_ALL_MODULE  0xFFFFFFFF
72
73 #define XLOG_LEVEL_DEBUG    XLOG_LEVEL_0    /* console */
74 #define XLOG_LEVEL_TRACE    XLOG_LEVEL_1    /* console */
75 #define XLOG_LEVEL_INFO     XLOG_LEVEL_2    /* Xorg.0.log or dlog */
76 #define XLOG_LEVEL_WARNING  XLOG_LEVEL_3    /* Xorg.0.log and dlog */
77 #define XLOG_LEVEL_ERROR    XLOG_LEVEL_4    /* Xorg.0.log and dlog */
78
79 #define XLOG_OPTION_KLOG        (1 << 8)    /* LV:WARNING and /dev/kmsg */
80 #define XLOG_OPTION_SECURE      (1 << 12)   /* LV:INFO. Disable when released */
81
82 typedef enum
83 {
84     MODE_NAME_ONLY,
85     MODE_WITH_STATUS
86 } LOG_ENUM_MODE;
87
88 int   xDbgLogEnumModules (LOG_ENUM_MODE mode, char *buf, int *remain);
89 int   xDbgLogSetLevel    (unsigned int module, int level);
90 void  xDbgLogEnableDlog  (Bool enable);
91 void* xDbgLog            (unsigned int module, int logoption, const char *file, int line, const char *f, ...);
92
93 // defines
94 #define XLOG_DEBUG(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_DEBUG, __FILE__, __LINE__, ##ARG)
95 #define XLOG_TRACE(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_TRACE, __FILE__, __LINE__, ##ARG)
96 #define XLOG_INFO(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_INFO, __FILE__, __LINE__, ##ARG)
97 #define XLOG_WARNING(mod, ARG...)  xDbgLog(mod, XLOG_LEVEL_WARNING, __FILE__, __LINE__, ##ARG)
98 #define XLOG_ERROR(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_ERROR, __FILE__, __LINE__, ##ARG)
99 #define XLOG_KLOG(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_WARNING|XLOG_OPTION_KLOG, __FILE__, __LINE__, ##ARG)
100 #define XLOG_SECURE(mod, ARG...)   xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_SECURE, __FILE__, __LINE__, ##ARG)
101
102 #define XDBG_DEBUG(mod, fmt, ARG...)      XLOG_DEBUG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
103 #define XDBG_TRACE(mod, fmt, ARG...)      XLOG_TRACE(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
104 #define XDBG_INFO(mod, fmt, ARG...)       XLOG_INFO(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
105 #define XDBG_WARNING(mod, fmt, ARG...)    XLOG_WARNING(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
106 #define XDBG_ERROR(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
107 #define XDBG_ERRNO(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s](err=%s(%d)) "fmt, __FUNCTION__, strerror(errno), errno, ##ARG)
108 #define XDBG_KLOG(mod, fmt, ARG...)       XLOG_KLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
109
110 #if TIZEN_ENGINEER_MODE
111 #define XDBG_SECURE(mod, fmt, ARG...)     XLOG_SECURE(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
112 #else
113 #if USE_NORMAL_LOG
114 #define XDBG_SECURE(mod, fmt, ARG...)     XLOG_INFO(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
115 #else
116 #define XDBG_SECURE(mod, fmt, ARG...)     do { } while(0)
117 #endif
118 #endif
119
120 #define XDBG_NEVER_GET_HERE(mod)          XLOG_ERROR(mod, "[%s:%d] ** NEVER GET HERE **\n", __FUNCTION__,__LINE__)
121
122 #define XDBG_WARNING_IF_FAIL(cond)         {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond);}}
123 #define XDBG_RETURN_IF_FAIL(cond)          {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); return; }}
124 #define XDBG_RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); return val; }}
125 #define XDBG_RETURN_VAL_IF_ERRNO(cond, val, errno)       {if (!(cond)) { XDBG_ERRNO (MXDBG, "'%s' failed.\n", #cond); return val; }}
126 #define XDBG_GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); goto dst; }}
127 #define XDBG_GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { XDBG_ERRNO (MXDBG, "'%s' failed.\n", #cond); goto dst; }}
128
129 #define XDBG_REPLY(fmt, ARG...)  \
130     do { \
131         if (reply && len && *len > 0) \
132         { \
133             int s = snprintf (reply, *len, fmt, ##ARG); \
134             reply += s; \
135             *len -= s; \
136         } \
137     } while (0)
138
139 #endif  /* __XDBG_LOG_H__ */