Update changed code
[apps/home/smartsearch.git] / include / ps_debug_util.h
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
19
20
21
22 #ifndef __DEF_PS_DEBUG_UTIL_H__
23 #define __DEF_PS_DEBUG_UTIL_H__
24
25 #ifdef __ENABLE_DEBUG_UTIL
26
27 #include <assert.h>
28
29 #ifdef __ENABLE_PLATFORM_DEBUG
30
31 #include <dlog.h>
32
33 #ifdef LOG_TAG
34 #undef LOG_TAG
35 #endif
36 #define LOG_TAG "SEARCH"
37
38 #define SEARCH_FUNC_START \
39                         do {\
40                                 LOGD("[%s() START ----->]\n", __FUNCTION__);\
41                         }while(0)
42
43 #define SEARCH_FUNC_END \
44                         do {\
45                                 LOGD("[%s() <----- END]\n", __FUNCTION__);\
46                         }while(0)
47
48 #define SEARCH_FUNC_LINE \
49                         do {\
50                                 LOGD("[%s() \t%s:%d]\n", __FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
51                         }while(0)
52
53 #define SEARCH_DEBUG_LOG(fmt, arg...) \
54                         do {\
55                                 LOGD("\x1b[32m[SEARCH][D][" fmt "]\x1b[0m\n", ##arg);\
56                         }while(0)
57
58 #define SEARCH_DEBUG_WARNING(fmt, arg...) \
59                         do {\
60                                 LOGW("\x1b[33m[SEARCH][W][" fmt "]\x1b[0m\n", ##arg);\
61                         }while(0)
62
63 #define SEARCH_DEBUG_ERROR(fmt, arg...) \
64                         do {\
65                                 LOGE("\x1b[31m[SEARCH][E][" fmt "]\x1b[0m\n", ##arg);\
66                         }while(0)
67
68 #define SEARCH_ASSERT_IF(cond) \
69                         do {\
70                                 if(cond) {\
71                                         LOGE("\x1b[31m[%s() \t%s:%d][ASSERT]\x1b[0m",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
72                                         assert(0);\
73                                 }\
74                         }while(0)
75
76 #define SEARCH_RETV_IF(cond,ret) \
77                         do {\
78                                 if(cond) {\
79                                         LOGW("\x1b[33m[%s() \t%s:%d][RET_IF]\x1b[0m",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
80                                         return ret;\
81                                 }\
82                         }while(0)
83
84 #define SEARCH_RET_IF(cond) \
85                         do {\
86                                 if(cond) {\
87                                         LOGW("\x1b[33m[%s() \t%s:%d][RET_IF]\x1b[0m",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
88                                         return;\
89                                 }\
90                         }while(0)
91
92 #define SEARCH_RET_IF_STR_INVALID(str,ret) \
93                         do {\
94                                 if((str == NULL) || strlen(str) == 0) {\
95                                         LOGW("\x1b[33m[%s() \t%s:%d][RET_STR_IF]\x1b[0m",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
96                                         return ret;\
97                                 }\
98                         }while(0)
99
100 #else
101
102 #include <stdio.h>
103
104 #define SEARCH_FUNC_START \
105                         do {\
106                                 fprintf(stderr, "[SEARCH][%s() START ----->]\n", __FUNCTION__);\
107                         }while(0)
108
109 #define SEARCH_FUNC_END \
110                         do {\
111                                 fprintf("[SEARCH][%s() <----- END]\n", __FUNCTION__);\
112                         }while(0)
113
114 #define SEARCH_FUNC_LINE \
115                         do {\
116                                 fprintf("[SEARCH][%s() \t%s:%d]\n", __FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
117                         }while(0)
118
119 #define SEARCH_DEBUG_LOG(fmt, arg...) \
120                         do {\
121                                 fprintf(stderr, "[SEARCH][D][" fmt "\n", ##arg);\
122                         }while(0)
123
124 #define SEARCH_DEBUG_WARNING(fmt, arg...) \
125                         do {\
126                                 fprintf(stderr, "[SEARCH][W][" fmt "\n", ##arg);\
127                         }while(0)
128
129 #define SEARCH_DEBUG_ERROR(fmt, arg...) \
130                         do {\
131                                 fprintf(stderr, "[SEARCH][E][" fmt "\n", ##arg);\
132                         }while(0)
133
134 #define SEARCH_ASSERT_IF(cond) \
135                         do {\
136                                 if(cond) {\
137                                         fprintf(stderr, "[%s() \t%s:%d][ASSERT]",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
138                                         assert(0);\
139                                 }\
140                         }while(0)
141
142 #define SEARCH_RETV_IF(cond,ret) \
143                         do {\
144                                 if(cond) {\
145                                         fprintf(stderr, "[%s() \t%s:%d][RET_IF]",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
146                                         return ret;\
147                                 }\
148                         }while(0)
149
150 #define SEARCH_RET_IF(cond) \
151                         do {\
152                                 if(cond) {\
153                                         fprintf(stderr, "[%s() \t%s:%d][RET_IF]",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
154                                         return;\
155                                 }\
156                         }while(0)
157
158 #define SEARCH_RET_IF_STR_INVALID(str,ret) \
159                         do {\
160                                 if((str == NULL) || strlen(str) == 0) {\
161                                         fprintf("\x1b[33m[%s() \t%s:%d][RET_STR_IF]\x1b[0m",__FUNCTION__, strrchr(__FILE__, '/')+1, __LINE__);\
162                                         return ret;\
163                                 }\
164                         }while(0)
165
166 #endif
167
168 #else
169
170 #define SEARCH_FUNC_START
171 #define SEARCH_FUNC_END
172 #define SEARCH_FUNC_LINE
173 #define SEARCH_DEBUG_LOG(fmt, arg...)
174 #define SEARCH_DEBUG_WARNING(fmt, arg...)
175 #define SEARCH_DEBUG_ERROR(fmt, arg...)
176 #define SEARCH_ASSERT_IF(cond)
177 #define SEARCH_RETV_IF(cond,ret)
178 #define SEARCH_RET_IF(cond)
179 #define SEARCH_RET_IF_STR_INVALID(str,ret)
180
181 #endif                          // __ENABLE_DEBUG_UTIL
182
183 #endif                          // __DEF_PS_DEBUG_UTIL_H__