Package version up to 3.0.3
[platform/adaptation/spreadtrum/libtbm-sprd.git] / src / libhal-backend-tbm-sprd / tbm_backend_log.h
1 /**************************************************************************
2
3 libtbm_sprd
4
5 Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 #ifndef __TBM_BACKEND_LOG_H__
32 #define __TBM_BACKEND_LOG_H__
33
34 #include <sys/syscall.h>
35 #include <time.h>
36 #include <dlog.h>
37
38 enum {
39         TBM_BACKEND_LOG_LEVEL_NONE,
40         TBM_BACKEND_LOG_LEVEL_ERR,
41         TBM_BACKEND_LOG_LEVEL_WRN,
42         TBM_BACKEND_LOG_LEVEL_INFO,
43         TBM_BACKEND_LOG_LEVEL_DBG,
44 };
45
46 /* log level */
47 void tbm_backend_log_print(int level, const char *fmt, ...);
48
49 #define TBM_BACKEND_DBG(fmt, args...) \
50         do { \
51                 struct timespec ts; \
52                 clock_gettime(CLOCK_MONOTONIC, &ts); \
53                 tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
54                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
55                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
56         } while (0)
57
58 #define TBM_BACKEND_INFO(fmt, args...) \
59         do { \
60                 struct timespec ts; \
61                 clock_gettime(CLOCK_MONOTONIC, &ts); \
62                 tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
63                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
64                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
65         } while (0)
66
67 #define TBM_BACKEND_WRN(fmt, args...) \
68         do { \
69                 struct timespec ts; \
70                 clock_gettime(CLOCK_MONOTONIC, &ts); \
71                 tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
72                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
73                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
74         } while (0)
75
76 #define TBM_BACKEND_ERR(fmt, args...) \
77         do { \
78                 struct timespec ts; \
79                 clock_gettime(CLOCK_MONOTONIC, &ts); \
80                 tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
81                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
82                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
83         } while (0)
84
85 #define TBM_BACKEND_RETURN_IF_FAIL(cond) {\
86         if (!(cond)) {\
87                 TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
88                 return;\
89         } \
90 }
91 #define TBM_BACKEND_RETURN_VAL_IF_FAIL(cond, val) {\
92         if (!(cond)) {\
93                 TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
94                 return val;\
95         } \
96 }
97 #define TBM_BACKEND_GOTO_VAL_IF_FAIL(cond, val) {\
98         if (!(cond)) {\
99                 TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
100                 goto val;\
101         } \
102 }
103
104 #endif  /* __TBM_BACKEND_LOG_H__ */