Add backend function for vendor supported tiled format.
[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_NEVER_GET_HERE() TBM_WRN("** NEVER GET HERE **")
99 #define TBM_DEPRECATED(str) \
100         do { \
101                 if (str) \
102                         TBM_WRN("** DEPRECATED: %s **", str); \
103                 else \
104                         TBM_WRN("** DEPRECATED **"); \
105         } while(0)
106
107 /* check condition */
108 #define TBM_RETURN_IF_FAIL(cond) {\
109         if (!(cond)) {\
110                 TBM_ERR("'%s' failed.\n", #cond);\
111                 return;\
112         } \
113 }
114 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
115         if (!(cond)) {\
116                 TBM_ERR("'%s' failed.\n", #cond);\
117                 return val;\
118         } \
119 }
120 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
121         if (!(cond)) {\
122                 TBM_ERR("'%s' failed.\n", #cond);\
123                 goto val;\
124         } \
125 }
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif /* _TBM_LOG_H_ */