Fixing build error with new dlog format
[platform/adaptation/emulator/sensor-hal-emulator.git] / src / sensor_log.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #ifndef _SENSOR_LOG_H_
19 #define _SENSOR_LOG_H_
20
21 #include <dlog.h>
22
23 #ifndef NAME_MAX
24 #define NAME_MAX 256
25 #endif
26
27 #ifdef LOG_TAG
28         #undef LOG_TAG
29 #endif
30 #define LOG_TAG "SENSOR"
31
32 #define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
33
34 #ifdef _DEBUG
35 #define DBG SLOGD
36 #else
37 #define DBG(...) do { } while (0)
38 #endif
39
40 #define ERR SLOGE
41 #define WARN SLOGW
42 #define INFO SLOGI
43 #define _E ERR
44 #define _W WARN
45 #define _I INFO
46 #define _D DBG
47
48 #define _ERRNO(errno, tag, fmt, arg...) do { \
49                 char buf[1024]; \
50                 char *error = strerror_r(errno, buf, 1024); \
51                 if (!error) { \
52                         _E("Failed to strerror_r()"); \
53                         break; \
54                 } \
55                 tag(fmt" (%s[%d])", ##arg, error, errno); \
56         } while (0)
57
58 #ifdef _DEBUG
59 #define warn_if(expr, fmt, arg...) do { \
60                 if(expr) { \
61                         _D("(%s) -> " fmt, #expr, ##arg); \
62                 } \
63         } while (0)
64 #define ret_if(expr) do { \
65                 if(expr) { \
66                         _D("(%s) -> %s() return", #expr, __FUNCTION__); \
67                         return; \
68                 } \
69         } while (0)
70 #define retv_if(expr, val) do { \
71                 if(expr) { \
72                         _D("(%s) -> %s() return", #expr, __FUNCTION__); \
73                         return (val); \
74                 } \
75         } while (0)
76 #define retm_if(expr, fmt, arg...) do { \
77                 if(expr) { \
78                         _E(fmt, ##arg); \
79                         _D("(%s) -> %s() return", #expr, __FUNCTION__); \
80                         return; \
81                 } \
82         } while (0)
83 #define retvm_if(expr, val, fmt, arg...) do { \
84                 if(expr) { \
85                         _E(fmt, ##arg); \
86                         _D("(%s) -> %s() return", #expr, __FUNCTION__); \
87                         return (val); \
88                 } \
89         } while (0)
90
91 #else
92 #define warn_if(expr, fmt, arg...) do { \
93                 if(expr) { \
94                         _E(fmt, ##arg); \
95                 } \
96         } while (0)
97 #define ret_if(expr) do { \
98                 if(expr) { \
99                         return; \
100                 } \
101         } while (0)
102 #define retv_if(expr, val) do { \
103                 if(expr) { \
104                         return (val); \
105                 } \
106         } while (0)
107 #define retm_if(expr, fmt, arg...) do { \
108                 if(expr) { \
109                         _E(fmt, ##arg); \
110                         return; \
111                 } \
112         } while (0)
113 #define retvm_if(expr, val, fmt, arg...) do { \
114                 if(expr) { \
115                         _E(fmt, ##arg); \
116                         return (val); \
117                 } \
118         } while (0)
119
120 #endif
121
122 #endif /* _SENSOR_LOG_H_ */