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