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