revise packaging
[platform/core/pim/contacts-service.git] / common / ctsvc_internal.h
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 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
20 #ifndef __CTSVC_INTERNAL_H__
21 #define __CTSVC_INTERNAL_H__
22
23 #include <stdio.h>
24 #include <assert.h>
25
26 #include "contacts_errors.h"
27 #include "ctsvc_struct.h"
28 #include "ctsvc_view.h"
29
30 /*#define CONTACTS_DEBUGGING */
31 /*#define CONTACTS_TIMECHECK */
32
33 #define LOG_TAG "CONTACTS_SERVICE"
34 #include <dlog.h>
35
36 #if defined(_CONTACTS_IPC_SERVER)
37 #define IPC_ROLE "[SERVER]"
38 #elif defined(_CONTACTS_IPC_CLIENT)
39 #define IPC_ROLE "[CLIENT]"
40 #else
41 #define IPC_ROLE "[LIB]"
42 #endif
43
44 #define CTS_LOG_RED "\033[0;31m"
45 #define CTS_LOG_GREEN "\033[0;32m"
46 #define CTS_LOG_BROWN "\033[0;33m"
47 #define CTS_LOG_BLUE "\033[0;34m"
48 #define CTS_LOG_END "\033[0;m"
49
50 #define _INFO(fmt, arg...) SLOGI(CTS_LOG_GREEN IPC_ROLE CTS_LOG_END fmt, ##arg)
51 #define _ERR(fmt, arg...) SLOGE(CTS_LOG_GREEN IPC_ROLE CTS_LOG_END fmt, ##arg)
52 #define _DBG(fmt, arg...) SLOGD(CTS_LOG_GREEN IPC_ROLE CTS_LOG_END fmt, ##arg)
53 #define _WARN(fmt, arg...) SLOGW(CTS_LOG_GREEN IPC_ROLE CTS_LOG_END fmt, ##arg)
54
55 #define DEPRECATED_STRING_FORMAT "DEPRECATION WARNING: %s is deprecated and will be removed from next release."
56
57 #ifdef CONTACTS_DEBUGGING
58
59         #define CTS_FN_CALL _DBG(">>>>>>>> called")
60         #define CTS_FN_END _DBG("<<<<<<<< ended")
61
62         #define DBG(fmt, arg...) _DBG(fmt, ##arg)
63         #define WARN(fmt, arg...) _WARN(CTS_LOG_BROWN fmt CTS_LOG_END, ##arg)
64         #define ERR(fmt, arg...) _ERR(CTS_LOG_RED fmt CTS_LOG_END, ##arg)
65         #define INFO(fmt, arg...) _INFO(CTS_LOG_BLUE fmt CTS_LOG_END, ##arg)
66
67 #else /* CONTACTS_DEBUGGING */
68         #define CTS_FN_CALL
69         #define CTS_FN_END
70
71         #define DBG(fmt, arg...)
72         #define WARN(fmt, arg...) _WARN(fmt, ##arg)
73         #define ERR(fmt, arg...) _ERR(fmt, ##arg)
74         #define INFO(fmt, arg...) _INFO(fmt, ##arg)
75
76         #define G_DISABLE_ASSERT
77 #endif /* CONTACTS_DEBUGGING */
78
79 #define RET_IF(expr) \
80         do { \
81                 if (expr) { \
82                         ERR("(%s)", #expr); \
83                         return; \
84                 } \
85         } while (0)
86
87 #define RETV_IF(expr, val) \
88         do { \
89                 if (expr) { \
90                         ERR("(%s)", #expr); \
91                         return (val); \
92                 } \
93         } while (0)
94
95 #define RETM_IF(expr, fmt, arg...) \
96         do { \
97                 if (expr) { \
98                         ERR(fmt, ##arg); \
99                         return; \
100                 } \
101         } while (0)
102
103 #define RETVM_IF(expr, val, fmt, arg...) \
104         do { \
105                 if (expr) { \
106                         ERR(fmt, ##arg); \
107                         return (val); \
108                 } \
109         } while (0)
110
111 #define WARN_IF(expr, fmt, arg...) \
112         do { \
113                 if (expr) { \
114                         WARN(fmt, ##arg); \
115                 } \
116         } while (0)
117
118
119 /* TO DISABLE THIS MACRO, DEFINE "G_DISABLE_ASSERT" */
120 #define ASSERT_NOT_REACHED(fmt, arg...) do { \
121         ERR(fmt, ##arg); \
122         assert(!"DO NOT REACH HERE!"); \
123         } while (0)
124
125
126 /* Thread-local storage */
127 #ifdef _CONTACTS_IPC_SERVER
128 #define TLS __thread
129 #elif _CONTACTS_IPC_CLIENT
130 #define TLS __thread
131 #else /* _CONTACTS_NATIVE */
132 #define TLS
133 #endif
134
135 #endif /* __CTSVC_INTERNAL_H__ */
136