Resolved Native API Reference issues for calendar-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 __CAL_INTERNAL_H__
20 #define __CAL_INTERNAL_H__
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <system_info.h>
25
26 #define SAFE_STRDUP(src) (src) ? strdup((char *)src) : NULL
27
28 #define CAL_DEBUGGING
29
30 #define LOG_TAG "CALENDAR_SVC"
31 #include <dlog.h>
32
33 #define COLOR_RED    "\033[0;31m"
34 #define COLOR_GREEN  "\033[0;32m"
35 #define COLOR_BROWN  "\033[0;33m"
36 #define COLOR_BLUE   "\033[0;34m"
37 #define COLOR_PURPLE "\033[0;35m"
38 #define COLOR_CYAN   "\033[0;36m"
39 #define COLOR_END    "\033[0;m"
40
41 #if defined(CAL_IPC_SERVER)
42 #define IPC_ROLE COLOR_BLUE "[SERVER]" COLOR_END
43 #elif defined(CAL_IPC_CLIENT)
44 #define IPC_ROLE COLOR_BROWN "[CLIENT]" COLOR_END
45 #else
46 #define IPC_ROLE COLOR_GREEN "[LIB]" COLOR_END
47 #endif
48
49 #ifdef CAL_DEBUGGING
50  #define INFO(fmt, arg...)    SLOGI(IPC_ROLE fmt, ##arg)
51  #define ERR(fmt, arg...)     SLOGE(IPC_ROLE fmt, ##arg)
52  #define DBG(fmt, arg...)     SLOGD(IPC_ROLE fmt, ##arg)
53  #define WARN(fmt, arg...)    SLOGD(IPC_ROLE fmt, ##arg)
54  #define VERBOSE(fmt, arg...) SLOGV(IPC_ROLE fmt, ##arg)
55 #else /* CAL_DEBUGGING */
56  #define INFO(fmt, arg...)
57  #define ERR(fmt, arg...)
58  #define DBG(fmt, arg...)
59  #define WARN(fmt, arg...)
60  #define VERBOSE(fmt, arg...)
61 #endif /* CAL_DEBUGGING */
62
63 #define SEC_INFO(fmt, arg...) SECURE_LOGI(fmt, ##arg)
64 #define SEC_ERR(fmt, arg...)  SECURE_LOGE(fmt, ##arg)
65 #define SEC_DBG(fmt, arg...)  SECURE_LOGD(fmt, ##arg)
66 #define SECURE(fmt, arg...)   SECURE_LOGD(fmt, ##arg)
67
68 #define CAL_FN_CALL() DBG(">>>>>>>> called")
69 #define CAL_FN_END() DBG("<<<<<<<< ended")
70 #define CAL_DBG(fmt, arg...) DBG(fmt, ##arg)
71 #define CAL_WARN(fmt, arg...) WARN(fmt, ##arg)
72 #define CAL_ERR(fmt, arg...) ERR(fmt, ##arg)
73 #define CAL_INFO(fmt, arg...) INFO(fmt, ##arg)
74 #define CAL_VERBOSE(fmt, arg...) VERBOSE(fmt, ##arg)
75
76 #define WARN_IF(expr, fmt, arg...) do { \
77         if (expr) { \
78                 WARN(fmt, ##arg); \
79         } \
80 } while (0)
81 #define RET_IF(expr) do { \
82         if (expr) { \
83                 ERR("(%s)", #expr); \
84                 return; \
85         } \
86 } while (0)
87 #define RETV_IF(expr, val) do { \
88         if (expr) { \
89                 ERR("(%s)", #expr); \
90                 return (val); \
91         } \
92 } while (0)
93 #define RETM_IF(expr, fmt, arg...) do { \
94         if (expr) { \
95                 ERR(fmt, ##arg); \
96                 return; \
97         } \
98 } while (0)
99 #define RETVM_IF(expr, val, fmt, arg...) do { \
100         if (expr) { \
101                 ERR(fmt, ##arg); \
102                 return (val); \
103         } \
104 } while (0)
105 #define BREAK_IF(expr, fmt, arg...) do { \
106         if (expr) { \
107                 ERR(fmt, ##arg); \
108                 break; \
109         } \
110 } while (0)
111
112 #define CAL_START_TIMESTAMP struct timeval timeval_s = {0}; \
113         struct timeval timeval_e = {0}; \
114         struct timeval timeval_d = {0}; \
115         DBG(COLOR_PURPLE ">>>>>" COLOR_END); \
116         gettimeofday(&timeval_s, NULL);
117
118 #define CAL_PRINT_TIMESTAMP gettimeofday(&timeval_e, NULL); \
119         timersub(&timeval_e, &timeval_s, &timeval_d); \
120         timeval_s = timeval_e; \
121         DBG(COLOR_PURPLE "<<<<< (%03d.%03dsec)" COLOR_END, (int)(timeval_d.tv_sec % 1000), (int)(timeval_d.tv_usec/1000));
122
123 #define CAL_PROFILE
124 #ifdef CAL_PROFILE
125 #define CAL_PROFILE_GET_TIME() (clock() / (CLOCKS_PER_SEC / 1000));
126 #define CAL_PROFILE_PRINT(starttime, endtime) ERR("%ld ~ %ld : %ld(%d sec) msec", starttime, endtime, endtime-starttime, (endtime-starttime)/1000);
127 #else
128 #define CAL_PROFILE_GET_TIME(input_time) 0
129 #define CAL_PROFILE_PRINT(starttime, endtime)
130 #endif
131
132 #define CAL_FREE(ptr) \
133         do { \
134                 if (ptr) \
135                 free(ptr); \
136                 ptr = NULL; \
137         } while (0)
138
139
140 /* Thread-local storage */
141 #if defined(CAL_IPC_SERVER)
142 #define TLS __thread
143 #elif defined(CAL_IPC_CLIENT)
144 #define TLS __thread
145 #else   /* CAL_NATIVE */
146 #define TLS
147 #endif
148
149 #define CALENDAR_FEATURE "http://tizen.org/feature/calendar"
150 #if defined(CAL_IPC_CLIENT)
151 #define CHECK_CALENDAR_SUPPORTED(feature_name) \
152         do { \
153                 bool is_supported = false; \
154                 if (!system_info_get_platform_bool(feature_name, &is_supported)) { \
155                         if (is_supported == false) { \
156                                 LOGE("[%s] feature is disabled", feature_name); \
157                                 return CALENDAR_ERROR_NOT_SUPPORTED; \
158                         } \
159                 } else { \
160                         LOGE("Error - Feature getting from System Info"); \
161                         return CALENDAR_ERROR_SYSTEM; \
162                 } \
163         } while (0)
164 #else
165 #define CHECK_CALENDAR_SUPPORTED(feature_name)
166 #endif
167
168 #endif /* __CAL_INTERNAL_H__ */
169