apply FSL(Flora Software License)
[apps/core/preloaded/libslp-alarm.git] / include / db-dlog.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 #ifndef __DB_DLOG_H__
18 #define __DB_DLOG_H__
19
20 #include <stdio.h>
21 #include <assert.h>
22 #include <dlog.h>
23 /**********************************************************************
24 ******************define, struct ,typedef, union, enum, global val *************************************
25 ***********************************************************************/
26 #define DB_FUN_BEG()   DB_INFO("====>>>>fun=%s, BEGIN====>>>>", __FUNCTION__);
27 #define DB_FUN_END()   DB_INFO("====>>>>fun=%s, END====>>>>",  __FUNCTION__);
28 #define DB_INFO(fmt, arg...) LOGD("[%s:%d] "fmt, __FILE__, __LINE__, ##arg);
29 #define DB_ERR(fmt, arg...) LOGE(FONT_COLOR_RED"[%s:%d] "fmt FONT_COLOR_RESET, __FILE__, __LINE__, ##arg);
30
31 #define DB_FUN_DEBUG_BEG()      //DB_INFO("====>>>>fun=%s, BEGIN====>>>>",__FUNCTION__);
32 #define DB_FUN_DEBUG_END()      //DB_INFO("====>>>>fun=%s, END====>>>>",  __FUNCTION__);
33 #define DB_DEBUG_INFO(fmt, arg...)      //DB_INFO(fmt, ##arg)
34 #define DB_DEBUG_INFO(fmt, arg...)      //DB_ERR(fmt,##arg)
35
36 #define DB_RET_IF(expr) \
37     do { \
38                 if (expr) {\
39                     nErr = FAILED;\
40                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
41                     goto End; \
42                 } \
43         } \
44     } while (1);
45 #define DB_RETV_IF(expr, val) \
46         do { \
47                 if (expr) { \
48                     nErr = FAILED;\
49                     ret = val;\
50                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
51                     goto End; \
52                 } \
53         } while (0);
54 #define DB_RETE_IF(expr, errorId) \
55     do { \
56                 if (expr) { \
57                     nErr = errorId;\
58                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
59                     goto End; \
60         } \
61     } while (0);
62 #define DB_RETEM_IF(expr, errorId, fmt, arg...) \
63     do { \
64                 if (expr) { \
65                     nErr = errorId;\
66                 DB_INFO_RED(fmt, ##arg); \
67                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
68                     goto End; \
69                 } \
70     } while (0);
71 #define DB_RETVE_IF(expr, val, errorId) \
72     do { \
73                 if (expr) { \
74                     nErr = errorId;\
75                     ret = val;\
76                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
77                     goto End; \
78                 } \
79     } while (0);
80 #define DB_RETM_IF(expr, fmt, arg...) \
81     do { \
82                 if (expr) { \
83                     nErr = FAILED;\
84                     DB_INFO_RED(fmt, ##arg); \
85                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
86                     goto End; \
87                 } \
88     } while (0);
89 #define DB_RETVM_IF(expr, val, fmt, arg...) \
90     do { \
91                 if (expr) { \
92                     nErr = FAILED;\
93                     ret = val;\
94                     DB_INFO_RED(fmt, ##arg); \
95                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
96                     goto End; \
97                 } \
98     } while (0);
99 #define DB_RETVME_IF(expr, val, errorId, fmt, arg...) \
100     do { \
101                 if (expr) { \
102                     nErr = errorId;\
103                     ret = val;\
104                     DB_INFO_RED(fmt, ##arg); \
105                     DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \
106                     goto End; \
107                 } \
108     } while (0);
109 /* anci c color type */
110 #define FONT_COLOR_RESET    "\033[0m"
111 #define FONT_COLOR_RED      "\033[31m"
112 #define FONT_COLOR_GREEN    "\033[32m"
113 #define FONT_COLOR_YELLOW   "\033[33m"
114 #define FONT_COLOR_BLUE     "\033[34m"
115 #define FONT_COLOR_PURPLE   "\033[35m"
116 #define FONT_COLOR_CYAN     "\033[36m"
117 #define FONT_COLOR_GRAY     "\033[37m"
118
119 #define DB_INFO_RED(fmt, arg...) DB_INFO(FONT_COLOR_RED fmt FONT_COLOR_RESET, ##arg)
120 #define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
121 #define DB_INFO_YELLOW(fmt, arg...) DB_INFO(FONT_COLOR_YELLOW fmt FONT_COLOR_RESET, ##arg)
122 #define DB_INFO_BLUE(fmt, arg...) DB_INFO(FONT_COLOR_BLUE fmt FONT_COLOR_RESET, ##arg)
123 #define DB_INFO_PURPLE(fmt, arg...) DB_INFO(FONT_COLOR_PURPLE fmt FONT_COLOR_RESET, ##arg)
124 #define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
125 #define DB_INFO_CYAN(fmt, arg...) DB_INFO(FONT_COLOR_CYAN fmt FONT_COLOR_RESET, ##arg)
126 #define DB_INFO_GRAY(fmt, arg...) DB_INFO(FONT_COLOR_GRAY fmt FONT_COLOR_RESET, ##arg)
127
128 #define DB_INFO_WITH_COLOR(color, fmt, arg...) DB_INFO(color fmt FONT_COLOR_RESET, ##arg)
129
130 //
131 #define warn_if(expr, fmt, arg...) do { \
132         if (expr) { \
133             DB_INFO("(%s) -> "fmt, #expr, ##arg); \
134         } \
135     } while (0)
136 #define ret_if(expr) do { \
137         if (expr) { \
138             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
139             return; \
140         } \
141     } while (0)
142 #define retv_if(expr, val) do { \
143         if (expr) { \
144             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
145             return (val); \
146         } \
147     } while (0)
148 #define retm_if(expr, fmt, arg...) do { \
149         if (expr) { \
150             DB_ERR(fmt, ##arg); \
151             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
152             return; \
153         } \
154     } while (0)
155 #define retvm_if(expr, val, fmt, arg...) do { \
156         if (expr) { \
157             DB_ERR(fmt, ##arg); \
158             DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \
159             return (val); \
160         } \
161     }  while (0)
162 #endif                          //__DB_DLOG_H__