Use macro instead
[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 SAFE_STRLCPY(dst, src, n)       g_strlcpy(dst, src, n);
46 #define SAFE_STRLCAT(dst, src, n)       g_strlcat(dst, src, n);
47
48 /*#define LOG_COLOR */
49
50 #ifdef LOG_COLOR
51 #define FONT_COLOR_RESET    "\033[0m"
52 #define FONT_COLOR_RED      "\033[31m"
53 #define FONT_COLOR_GREEN    "\033[32m"
54 #define FONT_COLOR_YELLOW   "\033[33m"
55 #define FONT_COLOR_BLUE     "\033[34m"
56 #define FONT_COLOR_PURPLE   "\033[35m"
57 #define FONT_COLOR_CYAN     "\033[36m"
58 #define FONT_COLOR_GRAY     "\033[37m"
59
60 #define debug_log(mode, fmt, arg...) do { \
61                         if (mode == DEBUG) {    \
62                                 LOGD(FONT_COLOR_RESET fmt, ##arg); \
63                         } else if (mode == RELEASE) {   \
64                                 if (DEBUG_MODE == 1)    \
65                                         LOGD(FONT_COLOR_RESET fmt, ##arg); \
66                         }       \
67                 } while (0)
68
69 #define debug_msg(mode, fmt, arg...) do { \
70                         if (mode == DEBUG) {    \
71                                 LOGD(FONT_COLOR_RESET fmt, ##arg); \
72                         } else if (mode == RELEASE) {   \
73                                 if (DEBUG_MODE == 1)    \
74                                         LOGD(FONT_COLOR_RESET fmt, ##arg); \
75                         }       \
76                 } while (0)
77
78 #define debug_warning(mode, fmt, arg...) do { \
79                         if (mode == DEBUG) {    \
80                                 LOGW(FONT_COLOR_GREEN fmt, ##arg); \
81                         } else if (mode == RELEASE) {   \
82                                 if (DEBUG_MODE == 1)    \
83                                         LOGW(FONT_COLOR_GREEN fmt, ##arg); \
84                         }       \
85                 } while (0)
86
87 #define debug_error(mode, fmt, arg...) do { \
88                         if (mode == DEBUG) {    \
89                                 LOGE(FONT_COLOR_RED fmt, ##arg); \
90                         } else if (mode == RELEASE) {   \
91                                 if (DEBUG_MODE == 1)    \
92                                         LOGE(FONT_COLOR_RED fmt, ##arg); \
93                         }       \
94                 } while (0)
95
96 #define debug_fenter(mode) do { \
97                         if (mode == DEBUG) {    \
98                                 LOGE(FONT_COLOR_RESET "<ENTER> \n");     \
99                         } else if (mode == RELEASE) {   \
100                                 if (DEBUG_MODE == 1)    \
101                                         LOGE(FONT_COLOR_RESET "<ENTER> \n");     \
102                         }       \
103                 } while (0)
104
105 #define debug_fleave(mode) do { \
106                         if (mode == DEBUG) {    \
107                                 LOGE(FONT_COLOR_RESET "<LEAVE> \n");     \
108                         } else if (mode == RELEASE) {   \
109                                 if (DEBUG_MODE == 1)    \
110                                         LOGE(FONT_COLOR_RESET "<LEAVE> \n");     \
111                         }       \
112                 } while (0)
113
114 #else
115
116 #define debug_log(mode, fmt, arg...) do { \
117                         if (mode == DEBUG) {    \
118                                 LOGD(" "fmt"", ##arg);     \
119                         } else if (mode == RELEASE) {   \
120                                 if (DEBUG_MODE == 1)    \
121                                         LOGD(" "fmt"", ##arg);     \
122                         }       \
123                 } while (0)
124
125 #define debug_msg(mode, fmt, arg...) do { \
126                         if (mode == DEBUG) {    \
127                                 LOGD(" "fmt"", ##arg);     \
128                         } else if (mode == RELEASE) {   \
129                                 if (DEBUG_MODE == 1)    \
130                                         LOGD(" "fmt"", ##arg);     \
131                         }       \
132                 } while (0)
133
134 #define debug_warning(mode, fmt, arg...) do { \
135                         if (mode == DEBUG) {    \
136                                 LOGW(" "fmt"", ##arg);     \
137                         } else if (mode == RELEASE) {   \
138                                 if (DEBUG_MODE == 1)    \
139                                         LOGW(" "fmt"", ##arg);     \
140                         }       \
141                 } while (0)
142
143 #define debug_error(mode, fmt, arg...) do { \
144                         if (mode == DEBUG) {    \
145                                 LOGE(" "fmt"", ##arg);     \
146                         } else if (mode == RELEASE) {   \
147                                 if (DEBUG_MODE == 1)    \
148                                         LOGE(" "fmt"", ##arg);  \
149                         }       \
150                 } while (0)
151
152 #define debug_fenter(mode) do { \
153                         if (mode == DEBUG) {    \
154                                 LOGE("<ENTER> \n");     \
155                         } else if (mode == RELEASE) {   \
156                                 if (DEBUG_MODE == 1)    \
157                                         LOGE("<ENTER> \n");     \
158                         }       \
159                 } while (0)
160
161 #define debug_fleave(mode) do { \
162                         if (mode == DEBUG) {    \
163                                 LOGE("<LEAVE> \n");     \
164                         } else if (mode == RELEASE) {   \
165                                 if (DEBUG_MODE == 1)    \
166                                         LOGE("<LEAVE> \n");     \
167                         }       \
168                 } while (0)
169 #endif
170
171 #define mm_file_retv_if_fails(expr, val) do { \
172                         if (!(expr)) { \
173                                 return (val); \
174                         } \
175                 } while (0)
176
177 #define mm_file_retvm_if_fails(mode, expr, val) do { \
178                                 if (!(expr)) { \
179                                         debug_error(mode, "ERROR [%s]", #expr);  \
180                                         return (val); \
181                                 } \
182                         } while (0)
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif /* _MMFILE_DEBUG_H_ */
189