Add 3.0 APIs and sync APIs same as 2.4
[platform/core/convergence/service-adaptor.git] / include / service_adaptor_internal.h
1 /*
2  * Service Adaptor
3  *
4  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Yongjin Kim <youth.kim@samsung.com>
7  *          Jinhyeong Ahn <jinh.ahn@samsung.com>
8  *          Jiwon Kim <jiwon177.kim@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24 #ifndef __TIZEN_CONVERGENCE_SAL_INTERNAL_H__
25 #define __TIZEN_CONVERGENCE_SAL_INTERNAL_H__
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <assert.h>
30
31 #ifdef API
32 #undef API
33 #endif
34 #define API __attribute__ ((visibility("default")))
35
36 #define LOG_TAG "SERVICE-ADAPTOR"
37 #include <dlog.h>
38 #define DLOG(prio, fmt, arg...) \
39         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
40
41
42 #if defined(_SERVICE_ADAPTOR_IPC_SERVER)
43 #define IPC_ROLE "[SERVER]"
44 #elif defined(_SERVICE_ADAPTOR_IPC_CLIENT)
45 #define IPC_ROLE "[CLIENT]"
46 #else
47 #define IPC_ROLE "[LIB]"
48 #endif
49
50 /**
51  * Colors of font
52  */
53 #define FONT_COLOR_RESET      "\033[0m"
54 #define FONT_COLOR_BLACK      "\033[30m"             /* Black */
55 #define FONT_COLOR_RED        "\033[31m"             /* Red */
56 #define FONT_COLOR_GREEN      "\033[32m"             /* Green */
57 #define FONT_COLOR_YELLOW     "\033[33m"             /* Yellow */
58 #define FONT_COLOR_BLUE       "\033[34m"             /* Blue */
59 #define FONT_COLOR_PURPLE     "\033[35m"             /* Purple */
60 #define FONT_COLOR_CYAN       "\033[36m"             /* Cyan */
61 #define FONT_COLOR_WHITE      "\033[37m"             /* White */
62 #define FONT_COLOR_BOLDBLACK  "\033[1m\033[30m"      /* Bold Black */
63 #define FONT_COLOR_BOLDRED    "\033[1m\033[31m"      /* Bold Red */
64 #define FONT_COLOR_BOLDGREEN  "\033[1m\033[32m"      /* Bold Green */
65 #define FONT_COLOR_BOLDYELLOW "\033[1m\033[33m"      /* Bold Yellow */
66 #define FONT_COLOR_BOLDBLUE   "\033[1m\033[34m"      /* Bold Blue */
67 #define FONT_COLOR_BOLDPURPLE "\033[1m\033[35m"      /* Bold Purple */
68 #define FONT_COLOR_BOLDCYAN   "\033[1m\033[36m"      /* Bold Cyan */
69 #define FONT_COLOR_BOLDWHITE  "\033[1m\033[37m"      /* Bold White */
70
71 #define INFO(fmt, arg...) SLOGI(FONT_COLOR_YELLOW""IPC_ROLE" "fmt""FONT_COLOR_RESET, ##arg)
72 #define ERR(fmt, arg...) SLOGE(FONT_COLOR_RED""IPC_ROLE" "fmt""FONT_COLOR_RESET, ##arg)
73 #define DBG(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
74 #define WARN(fmt, arg...) SLOGD(IPC_ROLE" "fmt, ##arg)
75 #define VERBOSE(fmt, arg...) SLOGV(IPC_ROLE" "fmt, ##arg)
76
77 #ifdef SERVICE_ADAPTOR_DEBUGGING
78
79         #define SAL_FN_CALL DBG(">>>>>>>> called")
80         #define SAL_FN_END DBG("<<<<<<<< ended")
81 //        #define SAL_FN_CALL INFO(">>>>>>>> called")
82 //        #define SAL_FN_END INFO("<<<<<<<< ended")
83
84         #define SAL_DBG(fmt, arg...) DBG(fmt, ##arg)
85         #define SAL_WARN(fmt, arg...) WARN(fmt, ##arg)
86         #define SAL_ERR(fmt, arg...) ERR(fmt, ##arg)
87         #define SAL_INFO(fmt, arg...) INFO(fmt, ##arg)
88         #define SAL_VERBOSE(fmt, arg...) VERBOSE(fmt, ##arg)
89
90 #else /* SERVICE_ADAPTOR_DEBUGGING */
91         #define SAL_FN_CALL
92         #define SAL_FN_END
93
94         #define SAL_DBG(fmt, arg...)
95         #define SAL_WARN(fmt, arg...)
96         #define SAL_ERR(fmt, arg...) ERR(fmt, ##arg)
97         #define SAL_INFO(fmt, arg...)
98         #define SAL_VERBOSE(fmt, arg...)
99
100 #endif /* SERVICE_ADAPTOR_DEBUGGING */
101
102 #define WARN_IF(expr, fmt, arg...) do { \
103         if (expr) { \
104                 SAL_WARN(fmt, ##arg); \
105         } \
106 } while (0)
107 #define RET_IF(expr) do { \
108         if (expr) { \
109                 SAL_ERR("(%s)", #expr); \
110                 return; \
111         } \
112 } while (0)
113 #define RETV_IF(expr, val) do { \
114         if (expr) { \
115                 SAL_ERR("(%s)", #expr); \
116                 return (val); \
117         } \
118 } while (0)
119 #define RETM_IF(expr, fmt, arg...) do { \
120         if (expr) { \
121                 SAL_ERR(fmt, ##arg); \
122                 return; \
123         } \
124 } while (0)
125 #define RETVM_IF(expr, val, fmt, arg...) do { \
126         if (expr) { \
127                 SAL_ERR(fmt, ##arg); \
128                 return (val); \
129         } \
130 } while (0)
131 #define TRY_IF(expr, fmt, arg...) do { \
132         if (expr) { \
133                 SAL_INFO(fmt, ##arg); \
134                 goto catch; \
135         } \
136 } while (0)
137 #define TRYM_IF(expr, fmt, arg...) do { \
138         if (expr) { \
139                 SAL_ERR(fmt, ##arg); \
140                 goto catch; \
141         } \
142 } while (0)
143 #define TRYVM_IF(expr, val, fmt, arg...) do { \
144         if (expr) { \
145                 SAL_ERR(fmt, ##arg); \
146                 val; \
147                 goto catch; \
148         } \
149 } while (0)
150
151 #define SAL_STRDUP(dst, ptr) do { \
152         if (ptr) \
153                 dst = strdup(ptr); \
154         ptr = NULL; \
155 } while(0)
156
157 #define SAL_FREE(ptr) do { \
158         if (ptr) \
159                 free(ptr); \
160         ptr = NULL; \
161 } while(0)
162
163 #endif /* __TIZEN_CONVERGENCE_SAL_INTERNAL_H__ */