summaryrefslogtreecommitdiff
path: root/common/include/debug.h
blob: daa8583dc6b6a920ee50206a441a7248439706c3 (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
 *
 * 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.
 */

#ifndef __ELM_MYPHOTOCAM_DEBUG_H__
#define __ELM_MYPHOTOCAM_DEBUG_H__

#include <assert.h>


/*
	Category :
		FATAL
		ERROR
		WARN
		HIGH
		MED
		LOW
		DEBUG
*/


enum
{
	DBG_MSG_LOW    	= 0,
	DBG_MSG_MED 		= 1,
	DBG_MSG_HIGH		= 2,

	DBG_MSG_WARN		= 3,
	DBG_MSG_ERROR		= 4,
	DBG_MSG_FATAL		= 5,

	DBG_MSG_CUST5		= 6,
	DBG_MSG_CUST6		= 7,
	DBG_MSG_CUST7		= 8,
	DBG_MSG_CUST8		= 9,
	DBG_MSG_CUST9		= 10,
	DBG_MSG_CUST10	= 11,
	DBG_MSG_CUST11	= 12,
	DBG_MSG_CUST12	= 13,
	DBG_MSG_CUST13	= 14,
};


// level
enum
{
	DBG_MSG_BIT_LOW 		= (1<<DBG_MSG_LOW),
	DBG_MSG_BIT_MED 		= (1<<DBG_MSG_MED),
	DBG_MSG_BIT_HIGH		= (1<<DBG_MSG_HIGH),
	DBG_MSG_BIT_WARN		= (1<<DBG_MSG_WARN),
	DBG_MSG_BIT_ERROR		= (1<<DBG_MSG_ERROR),
	DBG_MSG_BIT_FATAL		= (1<<DBG_MSG_FATAL),

	DBG_MSG_BIT_CUST5		= (1<<DBG_MSG_CUST5),
	DBG_MSG_BIT_CUST6		= (1<<DBG_MSG_CUST6),
	DBG_MSG_BIT_CUST7		= (1<<DBG_MSG_CUST7),
	DBG_MSG_BIT_CUST8		= (1<<DBG_MSG_CUST8),
	DBG_MSG_BIT_CUST9		= (1<<DBG_MSG_CUST9),
	DBG_MSG_BIT_CUST10	= (1<<DBG_MSG_CUST10),
	DBG_MSG_BIT_CUST11	= (1<<DBG_MSG_CUST11),
	DBG_MSG_BIT_CUST12	= (1<<DBG_MSG_CUST12),
	DBG_MSG_BIT_CUST13	= (1<<DBG_MSG_CUST13),
};

#define DBG_MSG_LVL_DEBUG 		(DBG_MSG_BIT_CUST13)

#define DBG_MSG_LVL_ALL			(DBG_MSG_LVL_LOW)

#define DBG_MSG_LVL_FATAL		(DBG_MSG_BIT_FATAL)
#define DBG_MSG_LVL_ERROR		(DBG_MSG_LVL_FATAL	| DBG_MSG_BIT_ERROR)
#define DBG_MSG_LVL_WARN		(DBG_MSG_LVL_ERROR	| DBG_MSG_BIT_WARN)
#define DBG_MSG_LVL_HIGH		(DBG_MSG_LVL_WARN	| DBG_MSG_BIT_HIGH)
#define DBG_MSG_LVL_MED		(DBG_MSG_LVL_HIGH	| DBG_MSG_BIT_MED)
#define DBG_MSG_LVL_LOW		(DBG_MSG_LVL_MED	| DBG_MSG_BIT_LOW)
#define DBG_MSG_LVL_NONE		(0)


// Get time of day
#include <sys/time.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

#undef DISABLE_LOG

// Time analyzer
#define DEFINE_PERFORM_TIME(aa) long aa = 0; struct timeval tv

#define BEGIN_PERFORM_TIME(aa) \
	{ \
		gettimeofday(&tv, NULL); \
		aa = tv.tv_sec * 1000 + tv.tv_usec / 1000; \
	} while(0)

#define END_PERFORM_TIME(aa) \
	{  \
		gettimeofday(&tv, NULL);  \
		aa = ( tv.tv_sec * 1000 + tv.tv_usec / 1000 ) - aa; \
	} while(0)

// TODO : Need align(1)
typedef struct {
	const char *fname;
	int nline;
	const char *szcategory;
	int msg_level;
	const char *szlevel;
	unsigned long time;
} debug_msg_type;

void __custom_debug_msg(debug_msg_type *debug_msg, const char *msg, ...);

#ifdef DISABLE_LOG

#define __MSG_FATAL(level, szCat,  ...)
#define __MSG_ERROR(level, szCat,  ...)
#define __MSG_WARN(level, szCat, ...)
#define __MSG_HIGH(level, szCat, ...)
#define __MSG_MED(level, szCat,  ...)
#define __MSG_LOW(level, szCat,  ...)
#define __MSG_DEBUG(level, szCat,  ...)

#else		// DISABLE_LOG

/* coverity[+kill] */
#define __MSG_FATAL(level, szCat,  ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_FATAL) \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,								\
				DBG_MSG_FATAL,					\
				"FATAL", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)

#define __MSG_ERROR(level, szCat,  ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_ERROR)  \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,								\
				DBG_MSG_ERROR,					\
				"ERROR", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)


#define __MSG_WARN(level, szCat, ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_WARN)  \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,							\
				DBG_MSG_WARN,					\
				"WARN", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)

#define __MSG_HIGH(level, szCat, ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_HIGH) \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,							\
				DBG_MSG_HIGH,					\
				"HIGH", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)

#define __MSG_MED(level, szCat,  ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_MED) \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,							\
				DBG_MSG_MED,					\
				"MED", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)


#define __MSG_LOW(level, szCat,  ...)	\
	do { \
		if ((level) & DBG_MSG_BIT_LOW) \
		{ \
			static debug_msg_type msg______unique______name___ = {		\
				__FILE__,							\
				__LINE__,							\
				szCat,								\
				DBG_MSG_LOW,					\
				"LOW", \
			};									\
			__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
		} \
	} while(0)

#define __MSG_DBG(level, szCat,  ...)	\
			do { \
				if ((level) & DBG_MSG_BIT_CUST13) \
				{ \
					static debug_msg_type msg______unique______name___ = {		\
						__FILE__,							\
						__LINE__,							\
						szCat,								\
						DBG_MSG_BIT_CUST13,					\
						"DBG", \
					};									\
					__custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
				} \
			} while(0)


#endif 		// DISABLE_LOG

#define ASSERT(level, szCat, expr) \
	do { \
		if( !(expr) )					\
		{							\
			__MSG_FATAL(level, szCat, "[%s] ASSERT : " #expr , __func__ );	\
		} \
	} while(0)

#define NEVER_GET_HERE(level, szCat) \
	do { \
		__MSG_FATAL(level, szCat, "NeverGetHere : %s(%d)", __func__, __LINE__);	\
	} while(0)

#ifdef __cplusplus
}
#endif


#endif 		// __ELM_MYPHOTOCAM_DEBUG_H__