sensor-hal: re-organize build procedure
[platform/adaptation/tm1/sensor-hal-tm1.git] / src / 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_LOG_H_
21 #define _SENSOR_LOG_H_
22
23 #include <dlog.h>
24
25 #if !defined(NAME_MAX)
26 #define NAME_MAX 256
27 #endif
28
29 #define SENSOR_TYPE_SHIFT 16
30
31 enum sf_log_type {
32         SF_LOG_PRINT_FILE               = 1,
33         SF_LOG_SYSLOG                   = 2,
34         SF_LOG_DLOG                     = 3,
35 };
36
37 enum sf_priority_type {
38         SF_LOG_ERR                      = 1,
39         SF_LOG_DBG                      = 2,
40         SF_LOG_INFO                     = 3,
41         SF_LOG_WARN                     = 4,
42 };
43
44 #define MICROSECONDS(tv)        ((tv.tv_sec * 1000000ll) + tv.tv_usec)
45
46 //for new log system - dlog
47 #ifdef LOG_TAG
48         #undef LOG_TAG
49 #endif
50 #define LOG_TAG "SENSOR"
51
52 #ifdef _DEBUG
53 #define DBG SLOGD
54 #else
55 #define DBG(...) do{} while(0)
56 #endif
57
58 #define ERR SLOGE
59 #define WARN SLOGW
60 #define INFO SLOGI
61 #define _E ERR
62 #define _W WARN
63 #define _I INFO
64 #define _D DBG
65
66 #if defined(_DEBUG)
67 #  define warn_if(expr, fmt, arg...) do { \
68                 if(expr) { \
69                         DBG("(%s) -> " fmt, #expr, ##arg); \
70                 } \
71         } while (0)
72 #  define ret_if(expr) do { \
73                 if(expr) { \
74                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
75                         return; \
76                 } \
77         } while (0)
78 #  define retv_if(expr, val) do { \
79                 if(expr) { \
80                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
81                         return (val); \
82                 } \
83         } while (0)
84 #  define retm_if(expr, fmt, arg...) do { \
85                 if(expr) { \
86                         ERR(fmt, ##arg); \
87                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
88                         return; \
89                 } \
90         } while (0)
91 #  define retvm_if(expr, val, fmt, arg...) do { \
92                 if(expr) { \
93                         ERR(fmt, ##arg); \
94                         DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
95                         return (val); \
96                 } \
97         } while (0)
98
99 #else
100 #  define warn_if(expr, fmt, arg...) do { \
101                 if(expr) { \
102                         ERR(fmt, ##arg); \
103                 } \
104         } while (0)
105 #  define ret_if(expr) do { \
106                 if(expr) { \
107                         return; \
108                 } \
109         } while (0)
110 #  define retv_if(expr, val) do { \
111                 if(expr) { \
112                         return (val); \
113                 } \
114         } while (0)
115 #  define retm_if(expr, fmt, arg...) do { \
116                 if(expr) { \
117                         ERR(fmt, ##arg); \
118                         return; \
119                 } \
120         } while (0)
121 #  define retvm_if(expr, val, fmt, arg...) do { \
122                 if(expr) { \
123                         ERR(fmt, ##arg); \
124                         return (val); \
125                 } \
126         } while (0)
127
128 #endif
129
130 #endif /* _SENSOR_LOG_H_ */