sensord: clean up sf_common.h/sensor_common.h/sensor_logs.h
[platform/core/system/sensord.git] / src / shared / sensor_logs.h
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 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_LOGS_H_
21 #define _SENSOR_LOGS_H_
22
23 #include <dlog.h>
24 #include <sys/types.h>
25
26 #define EVENT_TYPE_SHIFT 16
27 #define SENSOR_TYPE_SHIFT 32
28
29 #define MICROSECONDS(tv)        ((tv.tv_sec * 1000000ll) + tv.tv_usec)
30
31 #ifdef LOG_TAG
32         #undef LOG_TAG
33 #endif
34 #define LOG_TAG "SENSOR"
35
36 #ifdef _DEBUG
37 #define DBG SLOGD
38 #else
39 #define DBG(...) do{} while(0)
40 #endif
41
42 #define ERR SLOGE
43 #define WARN SLOGW
44 #define INFO SLOGI
45 #define _E ERR
46 #define _W WARN
47 #define _I INFO
48 #define _D DBG
49
50 #if defined(_DEBUG)
51 #  define warn_if(expr, fmt, arg...) do { \
52                 if(expr) { \
53                         DBG("(%s) -> " fmt, #expr, ##arg); \
54                 } \
55         } while (0)
56 #  define ret_if(expr) do { \
57                 if(expr) { \
58                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
59                         return; \
60                 } \
61         } while (0)
62 #  define retv_if(expr, val) do { \
63                 if(expr) { \
64                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
65                         return (val); \
66                 } \
67         } while (0)
68 #  define retm_if(expr, fmt, arg...) do { \
69                 if(expr) { \
70                         ERR(fmt, ##arg); \
71                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
72                         return; \
73                 } \
74         } while (0)
75 #  define retvm_if(expr, val, fmt, arg...) do { \
76                 if(expr) { \
77                         ERR(fmt, ##arg); \
78                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
79                         return (val); \
80                 } \
81         } while (0)
82
83 #else
84 #  define warn_if(expr, fmt, arg...) do { \
85                 if(expr) { \
86                         ERR(fmt, ##arg); \
87                 } \
88         } while (0)
89 #  define ret_if(expr) do { \
90                 if(expr) { \
91                         return; \
92                 } \
93         } while (0)
94 #  define retv_if(expr, val) do { \
95                 if(expr) { \
96                         return (val); \
97                 } \
98         } while (0)
99 #  define retm_if(expr, fmt, arg...) do { \
100                 if(expr) { \
101                         ERR(fmt, ##arg); \
102                         return; \
103                 } \
104         } while (0)
105 #  define retvm_if(expr, val, fmt, arg...) do { \
106                 if(expr) { \
107                         ERR(fmt, ##arg); \
108                         return (val); \
109                 } \
110         } while (0)
111
112 #endif
113
114 #ifdef __cplusplus
115 extern "C"
116 {
117 #endif
118
119 const char* get_client_name(void);
120 bool get_proc_name(pid_t pid, char *process_name);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif /* _SENSOR_LOGS_H_ */