tbm_module: make tbm_module_bufmgr_bind_native_display
[platform/core/uifw/libtbm.git] / include / tbm_log.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@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 #ifndef _TBM_LOG_H_
33 #define _TBM_LOG_H_
34
35 #include <unistd.h>
36 #include <sys/syscall.h>
37 #include <time.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44  * @file tbm_log.h
45  * @brief The header file to print logs in frontend and backend modules
46  * @details
47  */
48
49 enum {
50         TBM_LOG_LEVEL_NONE,
51         TBM_LOG_LEVEL_ERR,
52         TBM_LOG_LEVEL_WRN,
53         TBM_LOG_LEVEL_INFO,
54         TBM_LOG_LEVEL_DBG,
55 };
56
57 void tbm_log_enable_color(unsigned int enable);
58 void tbm_log_enable_dlog(unsigned int enable);
59 void tbm_log_set_debug_level(int level);
60 void tbm_log_set_assert_level(int level);
61 void tbm_log_set_path(const char *path);
62 void tbm_log_print(int level, const char *fmt, ...);
63 void tbm_log_print_stdout(int level, const char *fmt, ...);
64
65 #define TBM_DBG(fmt, args...) \
66         do { \
67                 struct timespec ts; \
68                 clock_gettime(CLOCK_MONOTONIC, &ts); \
69                 tbm_log_print(TBM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
70                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
71                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
72         } while (0)
73 #define TBM_INFO(fmt, args...) \
74         do { \
75                 struct timespec ts; \
76                 clock_gettime(CLOCK_MONOTONIC, &ts); \
77                 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
78                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
79                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
80         } while (0)
81 #define TBM_WRN(fmt, args...) \
82         do { \
83                 struct timespec ts; \
84                 clock_gettime(CLOCK_MONOTONIC, &ts); \
85                 tbm_log_print(TBM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
86                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
87                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
88         } while (0)
89 #define TBM_ERR(fmt, args...) \
90         do { \
91                 struct timespec ts; \
92                 clock_gettime(CLOCK_MONOTONIC, &ts); \
93                 tbm_log_print(TBM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
94                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
95                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
96         } while (0)
97
98 #define TBM_STDOUT_INFO(fmt, args...) \
99         do { \
100                 struct timespec ts; \
101                 clock_gettime(CLOCK_MONOTONIC, &ts); \
102                 tbm_log_print_stdout(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
103                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
104                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
105         } while (0)
106
107 #define TBM_NEVER_GET_HERE() TBM_WRN("** NEVER GET HERE **")
108 #define TBM_DEPRECATED(str) \
109         do { \
110                 if (str) \
111                         TBM_WRN("** DEPRECATED: %s **", str); \
112                 else \
113                         TBM_WRN("** DEPRECATED **"); \
114         } while(0)
115
116 /* check condition */
117 #define TBM_RETURN_IF_FAIL(cond) {\
118         if (!(cond)) {\
119                 TBM_ERR("'%s' failed.\n", #cond);\
120                 return;\
121         } \
122 }
123 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
124         if (!(cond)) {\
125                 TBM_ERR("'%s' failed.\n", #cond);\
126                 return val;\
127         } \
128 }
129 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
130         if (!(cond)) {\
131                 TBM_ERR("'%s' failed.\n", #cond);\
132                 goto val;\
133         } \
134 }
135
136 #define TBM_RETURN_SET_ERR_IF_FAIL(cond, error, error_type) {\
137         if (!(cond)) {\
138                 TBM_ERR("'%s' failed.\n", #cond);\
139                 error = error_type;\
140                 return;\
141         } \
142 }
143
144 #define TBM_RETURN_VAL_SET_ERR_IF_FAIL(cond, val, error, error_type) {\
145         if (!(cond)) {\
146                 TBM_ERR("'%s' failed.\n", #cond);\
147                 error = error_type;\
148                 return val;\
149         } \
150 }
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 #endif /* _TBM_LOG_H_ */