modify terminology:calendar->book,allday->localtime,normal->utime,svc->service
[platform/core/pim/calendar-service.git] / common / cal_internal.h
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #ifndef __CALENDAR_SERVICE_INTERNAL_H__
20 #define __CALENDAR_SERVICE_INTERNAL_H__
21
22 #include <stdio.h>
23 #include <string.h>
24
25 #ifndef API
26 #define API __attribute__ ((visibility("default")))
27 #endif
28
29 #define SAFE_STRDUP(src) (src) ? strdup((char *)src) : NULL
30
31 #define CAL_DEBUGGING
32
33 #define LOG_TAG "CALENDAR_SVC"
34 #include <dlog.h>
35
36 #define COLOR_RED    "\033[0;31m"
37 #define COLOR_GREEN  "\033[0;32m"
38 #define COLOR_BROWN  "\033[0;33m"
39 #define COLOR_BLUE   "\033[0;34m"
40 #define COLOR_PURPLE "\033[0;35m"
41 #define COLOR_CYAN   "\033[0;36m"
42 #define COLOR_END    "\033[0;m"
43
44 #if defined(CAL_IPC_SERVER)
45 #define IPC_ROLE COLOR_BLUE"[SERVER]"COLOR_END
46 #elif defined(CAL_IPC_CLIENT)
47 #define IPC_ROLE COLOR_BROWN"[CLIENT]"COLOR_END
48 #else
49 #define IPC_ROLE COLOR_GREEN"[LIB]"COLOR_END
50 #endif
51
52 #ifdef CAL_DEBUGGING
53  #define INFO(fmt, arg...) SLOGI(IPC_ROLE" "fmt, ##arg)
54  #define ERR(fmt, arg...) SLOGE(IPC_ROLE" "fmt, ##arg)
55  #define DBG(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
56  #define WARN(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
57  #define VERBOSE(fmt, arg...) SLOGV(IPC_ROLE" "fmt, ##arg)
58 #else /* CAL_DEBUGGING */
59  #define INFO(fmt, arg...)
60  #define ERR(fmt, arg...)
61  #define DBG(fmt, arg...)
62  #define WARN(fmt, arg...)
63  #define VERBOSE(fmt, arg...)
64 #endif /* CAL_DEBUGGING */
65
66 #define SEC_INFO(fmt, arg...) SECURE_LOGI(fmt, ##arg)
67 #define SEC_ERR(fmt, arg...) SECURE_LOGE(fmt, ##arg)
68 #define SEC_DBG(fmt, arg...) SECURE_LOGD(fmt, ##arg)
69 #define SECURE(fmt, arg...) SECURE_LOGD(fmt, ##arg)
70
71 #define CAL_FN_CALL() DBG(">>>>>>>> called")
72 #define CAL_FN_END() DBG("<<<<<<<< ended")
73 #define CAL_DBG(fmt, arg...) DBG(fmt, ##arg)
74 #define CAL_WARN(fmt, arg...) WARN(fmt, ##arg)
75 #define CAL_ERR(fmt, arg...) ERR(fmt, ##arg)
76 #define CAL_INFO(fmt, arg...) INFO(fmt, ##arg)
77 #define CAL_VERBOSE(fmt, arg...) VERBOSE(fmt, ##arg)
78
79 #define WARN_IF(expr, fmt, arg...) do { \
80         if (expr) { \
81                 WARN(fmt, ##arg); \
82         } \
83 } while (0)
84 #define RET_IF(expr) do { \
85         if (expr) { \
86                 ERR("(%s)", #expr); \
87                 return; \
88         } \
89 } while (0)
90 #define RETV_IF(expr, val) do { \
91         if (expr) { \
92                 ERR("(%s)", #expr); \
93                 return (val); \
94         } \
95 } while (0)
96 #define RETM_IF(expr, fmt, arg...) do { \
97         if (expr) { \
98                 ERR(fmt, ##arg); \
99                 return; \
100         } \
101 } while (0)
102 #define RETVM_IF(expr, val, fmt, arg...) do { \
103         if (expr) { \
104                 ERR(fmt, ##arg); \
105                 return (val); \
106         } \
107 } while (0)
108 #define BREAK_IF(expr, fmt, arg...) do { \
109         if (expr) { \
110                 ERR(fmt, ##arg); \
111                 break; \
112         } \
113 } while (0)
114
115 #define CAL_START_TIMESTAMP struct timeval timeval_s = {0}; \
116         struct timeval timeval_e = {0}; \
117         struct timeval timeval_d = {0}; \
118         DBG(COLOR_PURPLE">>>>>"COLOR_END); \
119         gettimeofday(&timeval_s, NULL);
120
121 #define CAL_PRINT_TIMESTAMP gettimeofday(&timeval_e, NULL); \
122         timersub(&timeval_e, &timeval_s, &timeval_d); \
123         timeval_s = timeval_e; \
124         DBG(COLOR_PURPLE"<<<<< (%03d.%03dsec)"COLOR_END, timeval_d.tv_sec % 1000, timeval_d.tv_usec/1000);
125
126 #define CAL_PROFILE
127 #ifdef CAL_PROFILE
128 #define CAL_PROFILE_GET_TIME() (clock() / (CLOCKS_PER_SEC / 1000));
129 #define CAL_PROFILE_PRINT(starttime, endtime) ERR("%ld ~ %ld : %ld(%d sec) msec", starttime, endtime, endtime-starttime, (endtime-starttime)/1000);
130 #else
131 #define CAL_PROFILE_GET_TIME(input_time) 0
132 #define CAL_PROFILE_PRINT(starttime, endtime)
133 #endif
134
135 #define CAL_FREE(ptr) \
136         do { \
137                 if (ptr) \
138                 free(ptr); \
139                 ptr = NULL; \
140         } while (0)
141
142
143 /* Thread-local storage */
144 #if defined(CAL_IPC_SERVER)
145 #define TLS __thread
146 #elif defined(CAL_IPC_CLIENT)
147 #define TLS __thread
148 #else   /* CAL_NATIVE */
149 #define TLS
150 #endif
151
152 #endif /* __CALENDAR_SERVICE_INTERNAL_H__ */
153