Fix coverity issue
[platform/core/multimedia/libmm-fileinfo.git] / include / mm_file_debug.h
1 /*
2  * libmm-fileinfo
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef _MMFILE_DEBUG_H_
23 #define _MMFILE_DEBUG_H_
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <dlog.h>
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34
35 #define LOG_TAG "MM_FILEINFO"
36 #define RELEASE 0
37 #define DEBUG 1
38
39 #ifdef __MMFILE_TEST_MODE__
40 #define DEBUG_MODE 1
41 #else
42 #define DEBUG_MODE 0
43 #endif
44
45 /*#define LOG_COLOR */
46
47 #ifdef LOG_COLOR
48 #define FONT_COLOR_RESET    "\033[0m"
49 #define FONT_COLOR_RED      "\033[31m"
50 #define FONT_COLOR_GREEN    "\033[32m"
51 #define FONT_COLOR_YELLOW   "\033[33m"
52 #define FONT_COLOR_BLUE     "\033[34m"
53 #define FONT_COLOR_PURPLE   "\033[35m"
54 #define FONT_COLOR_CYAN     "\033[36m"
55 #define FONT_COLOR_GRAY     "\033[37m"
56
57 #define debug_log(mode, fmt, arg...) do { \
58                         if (mode == DEBUG) {    \
59                                 LOGD(FONT_COLOR_RESET fmt, ##arg); \
60                         } else if (mode == RELEASE) {   \
61                                 if (DEBUG_MODE == 1)    \
62                                         LOGD(FONT_COLOR_RESET fmt, ##arg); \
63                         }       \
64                 } while (0)
65
66 #define debug_msg(mode, fmt, arg...) do { \
67                         if (mode == DEBUG) {    \
68                                 LOGD(FONT_COLOR_RESET fmt, ##arg); \
69                         } else if (mode == RELEASE) {   \
70                                 if (DEBUG_MODE == 1)    \
71                                         LOGD(FONT_COLOR_RESET fmt, ##arg); \
72                         }       \
73                 } while (0)
74
75 #define debug_warning(mode, fmt, arg...) do { \
76                         if (mode == DEBUG) {    \
77                                 LOGW(FONT_COLOR_GREEN fmt, ##arg); \
78                         } else if (mode == RELEASE) {   \
79                                 if (DEBUG_MODE == 1)    \
80                                         LOGW(FONT_COLOR_GREEN fmt, ##arg); \
81                         }       \
82                 } while (0)
83
84 #define debug_error(mode, fmt, arg...) do { \
85                         if (mode == DEBUG) {    \
86                                 LOGE(FONT_COLOR_RED fmt, ##arg); \
87                         } else if (mode == RELEASE) {   \
88                                 if (DEBUG_MODE == 1)    \
89                                         LOGE(FONT_COLOR_RED fmt, ##arg); \
90                         }       \
91                 } while (0)
92
93 #define debug_fenter(mode) do { \
94                         if (mode == DEBUG) {    \
95                                 LOGE(FONT_COLOR_RESET "<ENTER> \n");     \
96                         } else if (mode == RELEASE) {   \
97                                 if (DEBUG_MODE == 1)    \
98                                         LOGE(FONT_COLOR_RESET "<ENTER> \n");     \
99                         }       \
100                 } while (0)
101
102 #define debug_fleave(mode) do { \
103                         if (mode == DEBUG) {    \
104                                 LOGE(FONT_COLOR_RESET "<LEAVE> \n");     \
105                         } else if (mode == RELEASE) {   \
106                                 if (DEBUG_MODE == 1)    \
107                                         LOGE(FONT_COLOR_RESET "<LEAVE> \n");     \
108                         }       \
109                 } while (0)
110
111 #else
112
113 #define debug_log(mode, fmt, arg...) do { \
114                         if (mode == DEBUG) {    \
115                                 LOGD(" "fmt"", ##arg);     \
116                         } else if (mode == RELEASE) {   \
117                                 if (DEBUG_MODE == 1)    \
118                                         LOGD(" "fmt"", ##arg);     \
119                         }       \
120                 } while (0)
121
122 #define debug_msg(mode, fmt, arg...) do { \
123                         if (mode == DEBUG) {    \
124                                 LOGD(" "fmt"", ##arg);     \
125                         } else if (mode == RELEASE) {   \
126                                 if (DEBUG_MODE == 1)    \
127                                         LOGD(" "fmt"", ##arg);     \
128                         }       \
129                 } while (0)
130
131 #define debug_warning(mode, fmt, arg...) do { \
132                         if (mode == DEBUG) {    \
133                                 LOGW(" "fmt"", ##arg);     \
134                         } else if (mode == RELEASE) {   \
135                                 if (DEBUG_MODE == 1)    \
136                                         LOGW(" "fmt"", ##arg);     \
137                         }       \
138                 } while (0)
139
140 #define debug_error(mode, fmt, arg...) do { \
141                         if (mode == DEBUG) {    \
142                                 LOGE(" "fmt"", ##arg);     \
143                         } else if (mode == RELEASE) {   \
144                                 if (DEBUG_MODE == 1)    \
145                                         LOGE(" "fmt"", ##arg);  \
146                         }       \
147                 } while (0)
148
149 #define debug_fenter(mode) do { \
150                         if (mode == DEBUG) {    \
151                                 LOGE("<ENTER> \n");     \
152                         } else if (mode == RELEASE) {   \
153                                 if (DEBUG_MODE == 1)    \
154                                         LOGE("<ENTER> \n");     \
155                         }       \
156                 } while (0)
157
158 #define debug_fleave(mode) do { \
159                         if (mode == DEBUG) {    \
160                                 LOGE("<LEAVE> \n");     \
161                         } else if (mode == RELEASE) {   \
162                                 if (DEBUG_MODE == 1)    \
163                                         LOGE("<LEAVE> \n");     \
164                         }       \
165                 } while (0)
166 #endif
167
168 #define mm_file_retv_if_fails(expr, val) do { \
169                         if (!(expr)) { \
170                                 return (val); \
171                         } \
172                 } while (0)
173
174 #define mm_file_retvm_if_fails(mode, expr, val) do { \
175                                 if (!(expr)) { \
176                                         debug_error(mode, "ERROR [%s]", #expr);  \
177                                         return (val); \
178                                 } \
179                         } while (0)
180
181 #ifdef __cplusplus
182 }
183 #endif
184
185 #endif /* _MMFILE_DEBUG_H_ */