1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
* libsf-common
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: JuHyun Kim <jh8212.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#if !defined(_COMMON_H_)
#define _COMMON_H_
#ifdef __cplusplus
extern "C"
{
#endif
enum sf_log_type {
SF_LOG_PRINT_FILE = 1,
SF_LOG_SYSLOG = 2,
SF_LOG_DLOG = 3,
};
enum sf_priority_type {
SF_LOG_ERR = 1,
SF_LOG_DBG = 2,
SF_LOG_INFO = 3,
};
void sf_log(int type , int priority , const char *tag , const char *fmt , ...);
#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
#ifndef __MODULE__
#include <string.h>
#define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
//for new log system - dlog
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "SENSOR_FW"
//
#if defined(_DEBUG) || defined(USE_FILE_DEBUG)
#define DbgPrint(fmt, arg...) do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG , "[SF_MSG_PRT][%s:%d] "fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
#endif
#if defined(USE_SYSLOG_DEBUG)
#define ERR(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define INFO(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define DBG(fmt, arg...) do { sf_log(SF_LOG_SYSLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#elif defined(_DEBUG) || defined(USE_DLOG_DEBUG)
#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define INFO(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define DBG(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_DBG, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#elif defined(USE_FILE_DEBUG)
#define ERR(fmt, arg...) do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_ERR][%s:%d] "fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
#define DBG(fmt, arg...) do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_DBG][%s:%d] "fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
#define INFO(fmt, arg...) do { sf_log(SF_LOG_PRINT_FILE, 0, LOG_TAG ,"[SF_MSG_INFO][%s:%d] "fmt"\n",__MODULE__, __LINE__, ##arg); } while(0)
#elif defined(USE_DLOG_LOG)
#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define INFO(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_INFO, LOG_TAG, "%s:%s(%d)> "fmt, __MODULE__, __func__, __LINE__, ##arg); } while(0)
#define DBG(...)
#define DbgPrint(...)
#else
#define ERR(fmt, arg...) do { sf_log(SF_LOG_DLOG, SF_LOG_ERR, LOG_TAG, fmt , ##arg); } while(0)
#define DbgPrint(...)
#define DBG(...)
#define INFO(...)
#endif
#if defined(_DEBUG)
# define warn_if(expr, fmt, arg...) do { \
if(expr) { \
DBG("(%s) -> "fmt, #expr, ##arg); \
} \
} while (0)
# define ret_if(expr) do { \
if(expr) { \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return; \
} \
} while (0)
# define retv_if(expr, val) do { \
if(expr) { \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return (val); \
} \
} while (0)
# define retm_if(expr, fmt, arg...) do { \
if(expr) { \
ERR(fmt, ##arg); \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return; \
} \
} while (0)
# define retvm_if(expr, val, fmt, arg...) do { \
if(expr) { \
ERR(fmt, ##arg); \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return (val); \
} \
} while (0)
#else
# define warn_if(expr, fmt, arg...) do { \
if(expr) { \
ERR(fmt, ##arg); \
} \
} while (0)
# define ret_if(expr) do { \
if(expr) { \
return; \
} \
} while (0)
# define retv_if(expr, val) do { \
if(expr) { \
return (val); \
} \
} while (0)
# define retm_if(expr, fmt, arg...) do { \
if(expr) { \
ERR(fmt, ##arg); \
return; \
} \
} while (0)
# define retvm_if(expr, val, fmt, arg...) do { \
if(expr) { \
ERR(fmt, ##arg); \
return (val); \
} \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
//! End of a file
|