Tizen 2.1 base
[apps/home/libslp-alarm.git] / include / db-dlog.h
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://floralicense.org/license/
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 #ifndef __DB_DLOG_H__
19 #define __DB_DLOG_H__
20
21 #include <stdio.h>
22 #include <assert.h>
23 #include <dlog.h>
24 /**********************************************************************
25 ******************define, struct ,typedef, union, enum, global val *************************************
26 ***********************************************************************/
27 #define DB_FUN_BEG()   DB_INFO("====>>>>fun=%s, BEGIN====>>>>", __FUNCTION__);
28 #define DB_FUN_END()   DB_INFO("====>>>>fun=%s, END====>>>>",  __FUNCTION__);
29 #define DB_INFO(fmt, arg...) LOGD("[%s:%d] "fmt, __FILE__, __LINE__, ##arg);
30 #define DB_ERR(fmt, arg...) LOGE(FONT_COLOR_RED"[%s:%d] "fmt FONT_COLOR_RESET, __FILE__, __LINE__, ##arg);
31
32 #define DB_FUN_DEBUG_BEG()      //DB_INFO("====>>>>fun=%s, BEGIN====>>>>",__FUNCTION__);
33 #define DB_FUN_DEBUG_END()      //DB_INFO("====>>>>fun=%s, END====>>>>",  __FUNCTION__);
34 #define DB_DEBUG_INFO(fmt, arg...)      //DB_INFO(fmt, ##arg)
35 #define DB_DEBUG_INFO(fmt, arg...)      //DB_ERR(fmt,##arg)
36
37 #define DB_RET_IF(expr) \
38     do { \
39                 if (expr) {\
40                     nErr = FAILED;\
41                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
42                     goto End; \
43                 } \
44         } \
45     } while (1);
46 #define DB_RETV_IF(expr, val) \
47         do { \
48                 if (expr) { \
49                     nErr = FAILED;\
50                     ret = val;\
51                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
52                     goto End; \
53                 } \
54         } while (0);
55 #define DB_RETE_IF(expr, errorId) \
56     do { \
57                 if (expr) { \
58                     nErr = errorId;\
59                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
60                     goto End; \
61         } \
62     } while (0);
63 #define DB_RETEM_IF(expr, errorId, fmt, arg...) \
64     do { \
65                 if (expr) { \
66                     nErr = errorId;\
67                 DB_INFO_RED(fmt, ##arg); \
68                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
69                     goto End; \
70                 } \
71     } while (0);
72 #define DB_RETVE_IF(expr, val, errorId) \
73     do { \
74                 if (expr) { \
75                     nErr = errorId;\
76                     ret = val;\
77                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
78                     goto End; \
79                 } \
80     } while (0);
81 #define DB_RETM_IF(expr, fmt, arg...) \
82     do { \
83                 if (expr) { \
84                     nErr = FAILED;\
85                     DB_INFO_RED(fmt, ##arg); \
86                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
87                     goto End; \
88                 } \
89     } while (0);
90 #define DB_RETVM_IF(expr, val, fmt, arg...) \
91     do { \
92                 if (expr) { \
93                     nErr = FAILED;\
94                     ret = val;\
95                     DB_INFO_RED(fmt, ##arg); \
96                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
97                     goto End; \
98                 } \
99     } while (0);
100 #define DB_RETVME_IF(expr, val, errorId, fmt, arg...) \
101     do { \
102                 if (expr) { \
103                     nErr = errorId;\
104                     ret = val;\
105                     DB_INFO_RED(fmt, ##arg); \
106                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
107                     goto End; \
108                 } \
109     } while (0);
110 /* anci c color type */
111 #define FONT_COLOR_RESET    "\033[0m"
112 #define FONT_COLOR_RED      "\033[31m"
113 #define FONT_COLOR_GREEN    "\033[32m"
114 #define FONT_COLOR_YELLOW   "\033[33m"
115 #define FONT_COLOR_BLUE     "\033[34m"
116 #define FONT_COLOR_PURPLE   "\033[35m"
117 #define FONT_COLOR_CYAN     "\033[36m"
118 #define FONT_COLOR_GRAY     "\033[37m"
119
120 #define DB_INFO_RED(fmt, arg...) DB_INFO(FONT_COLOR_RED fmt FONT_COLOR_RESET, ##arg)
121 #define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
122 #define DB_INFO_YELLOW(fmt, arg...) DB_INFO(FONT_COLOR_YELLOW fmt FONT_COLOR_RESET, ##arg)
123 #define DB_INFO_BLUE(fmt, arg...) DB_INFO(FONT_COLOR_BLUE fmt FONT_COLOR_RESET, ##arg)
124 #define DB_INFO_PURPLE(fmt, arg...) DB_INFO(FONT_COLOR_PURPLE fmt FONT_COLOR_RESET, ##arg)
125 #define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
126 #define DB_INFO_CYAN(fmt, arg...) DB_INFO(FONT_COLOR_CYAN fmt FONT_COLOR_RESET, ##arg)
127 #define DB_INFO_GRAY(fmt, arg...) DB_INFO(FONT_COLOR_GRAY fmt FONT_COLOR_RESET, ##arg)
128
129 #define DB_INFO_WITH_COLOR(color, fmt, arg...) DB_INFO(color fmt FONT_COLOR_RESET, ##arg)
130
131 //
132 #define warn_if(expr, fmt, arg...) do { \
133         if (expr) { \
134             DB_INFO("(%s) -> "fmt, #expr, ##arg); \
135         } \
136     } while (0)
137 #define ret_if(expr) do { \
138         if (expr) { \
139             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
140             return; \
141         } \
142     } while (0)
143 #define retv_if(expr, val) do { \
144         if (expr) { \
145             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
146             return (val); \
147         } \
148     } while (0)
149 #define retm_if(expr, fmt, arg...) do { \
150         if (expr) { \
151             DB_ERR(fmt, ##arg); \
152             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
153             return; \
154         } \
155     } while (0)
156 #define retvm_if(expr, val, fmt, arg...) do { \
157         if (expr) { \
158             DB_ERR(fmt, ##arg); \
159             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
160             return (val); \
161         } \
162     }  while (0)
163 #endif                          //__DB_DLOG_H__