apply FSL license
[apps/core/preloaded/calendar.git] / include / cld-log.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://www.tizenopensource.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
19
20
21
22
23
24 #ifndef __CALENDAR_LOG_H__
25 #define __CALENDAR_LOG_H__
26
27 #define CAL_DEBUGGING
28 #define CAL_DLOG_OUT
29
30 //#define CAL_TIMECHECK
31 //#define CAL_USE_OWN_TIME
32
33 #ifdef CAL_DLOG_OUT
34 #define LOG_TAG "CALENDAR"
35 #include <dlog.h>
36 #define DLOG(prio, fmt, arg...) \
37         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
38 #define INFO(fmt, arg...) SLOGI(fmt, ##arg)
39 #define ERR(fmt, arg...) SLOGE("%s(%d) " fmt, __FUNCTION__, __LINE__, ##arg)
40 #define DBG(fmt, arg...) SLOGD("%s(%d) " fmt, __FUNCTION__, __LINE__, ##arg)
41 #else //CAL_DLOG_OUT
42 #define PRT(prio, fmt, arg...) \
43         do { fprintf((prio?stderr:stdout),"[Calendar]" fmt"\n", ##arg); } while (0)
44 #define INFO(fmt, arg...) PRT(0, fmt, ##arg)
45 #define ERR(fmt, arg...) PRT(1,"%s(%d) " fmt, __FUNCTION__, __LINE__, ##arg)
46 #define DBG(fmt, arg...) \
47         do { \
48                 printf("\x1b[105;37m[Calendar]\x1b[0m(%s)" fmt "\n", __FUNCTION__, ##arg); \
49         } while (0)
50 #endif //CAL_DLOG_OUT
51
52 #ifdef CAL_DEBUGGING
53
54 #ifdef CAL_USE_OWN_TIME
55 #define CAL_FN_START CAL_TIME_CHECK_START
56 #define CAL_FN_END CAL_TIME_CHECK_END
57 #else//CAL_USE_OWN_TIME
58 #ifdef CAL_TIMECHECK
59 #define CAL_FN_START DBG("START")
60 #define CAL_FN_END DBG("END")
61 #else//CAL_TIMECHECK
62 #define CAL_FN_START DBG("")
63 #define CAL_FN_END
64 #endif//CAL_TIMECHECK
65 #endif//CAL_USE_OWN_TIME
66
67 #define c_warn_if(expr, fmt, arg...) do { \
68         if (expr) { \
69                 ERR("(%s) -> "fmt, #expr, ##arg); \
70         } \
71 } while (0)
72 #define c_ret_if(expr) do { \
73         if (expr) { \
74                 DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
75                 return; \
76         } \
77 } while (0)
78 #define c_retv_if(expr, val) do { \
79         if (expr) { \
80                 DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
81                 return (val); \
82         } \
83 } while (0)
84 #define c_retm_if(expr, fmt, arg...) do { \
85         if (expr) { \
86                 ERR(fmt, ##arg); \
87                 DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
88                 return; \
89         } \
90 } while (0)
91 #define c_retvm_if(expr, val, fmt, arg...) do { \
92         if (expr) { \
93                 ERR(fmt, ##arg); \
94                 DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
95                 return (val); \
96         } \
97 } while (0)
98 #else //CAL_DEBUGGING
99 #define CAL_FN_START
100 #define CAL_FN_END
101 #define DBG(...)
102
103 #define c_warn_if(expr, fmt, arg...) do { \
104         if (expr) { \
105                 ERR(fmt, ##arg); \
106         } \
107 } while (0)
108 #define c_ret_if(expr) do { \
109         if (expr) { \
110                 return; \
111         } \
112 } while (0)
113 #define c_retv_if(expr, val) do { \
114         if (expr) { \
115                 return (val); \
116         } \
117 } while (0)
118 #define c_retm_if(expr, fmt, arg...) do { \
119         if (expr) { \
120                 ERR(fmt, ##arg); \
121                 return; \
122         } \
123 } while (0)
124 #define c_retvm_if(expr, val, fmt, arg...) do { \
125         if (expr) { \
126                 ERR(fmt, ##arg); \
127                 return (val); \
128         } \
129 } while (0)
130
131 #endif //CAL_DEBUGGING
132
133 #ifdef CAL_TIMECHECK
134 double cal_correction, cal_startT;
135 double cal_set_start_time(void);
136 double cal_exec_time(double start, double correction);
137 double cal_init_time(double correction);
138 #define CAL_TIME_CHECK_START   \
139         double cal_startT = 0, cal_correction = 0; \
140         cal_correction = cal_init_time(cal_correction);\
141         cal_startT = cal_set_start_time();
142 #define CAL_TIME_CHECK_END DBG("time = %f ms\n", cal_exec_time(cal_startT, cal_correction));
143 #else //CAL_TIMECHECK
144 #define CAL_TIME_CHECK_START
145 #define CAL_TIME_CHECK_END
146 #endif //CAL_TIMECHECK
147
148
149 #endif /* __CALENDAR_LOG_H__ */