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