d4e12a8fb73bdca1a3656fb742dbcabea436fc91
[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 #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
56 #ifdef SERVICE_ADAPTOR_DEBUGGING
57
58         #define SAL_FN_CALL DBG(">>>>>>>> called")
59         #define SAL_FN_END DBG("<<<<<<<< ended")
60
61         #define SAL_DBG(fmt, arg...) DBG(fmt, ##arg)
62         #define SAL_WARN(fmt, arg...) WARN(fmt, ##arg)
63         #define SAL_ERR(fmt, arg...) ERR(fmt, ##arg)
64         #define SAL_INFO(fmt, arg...) INFO(fmt, ##arg)
65         #define SAL_VERBOSE(fmt, arg...) VERBOSE(fmt, ##arg)
66
67 #else /* SERVICE_ADAPTOR_DEBUGGING */
68         #define SAL_FN_CALL
69         #define SAL_FN_END
70
71         #define SAL_DBG(fmt, arg...)
72         #define SAL_WARN(fmt, arg...)
73         #define SAL_ERR(fmt, arg...) ERR(fmt, ##arg)
74         #define SAL_INFO(fmt, arg...)
75         #define SAL_VERBOSE(fmt, arg...)
76
77 #endif /* SERVICE_ADAPTOR_DEBUGGING */
78
79 #define WARN_IF(expr, fmt, arg...) do { \
80         if (expr) { \
81                 SAL_WARN(fmt, ##arg); \
82         } \
83 } while (0)
84 #define RET_IF(expr) do { \
85         if (expr) { \
86                 SAL_ERR("(%s)", #expr); \
87                 return; \
88         } \
89 } while (0)
90 #define RETV_IF(expr, val) do { \
91         if (expr) { \
92                 SAL_ERR("(%s)", #expr); \
93                 return (val); \
94         } \
95 } while (0)
96 #define RETM_IF(expr, fmt, arg...) do { \
97         if (expr) { \
98                 SAL_ERR(fmt, ##arg); \
99                 return; \
100         } \
101 } while (0)
102 #define RETVM_IF(expr, val, fmt, arg...) do { \
103         if (expr) { \
104                 SAL_ERR(fmt, ##arg); \
105                 return (val); \
106         } \
107 } while (0)
108 #define TRYM_IF(expr, fmt, arg...) do { \
109         if (expr) { \
110                 SAL_ERR(fmt, ##arg); \
111                 goto catch; \
112         } \
113 } while (0)
114 #define TRYVM_IF(expr, val, fmt, arg...) do { \
115         if (expr) { \
116                 SAL_ERR(fmt, ##arg); \
117                 val; \
118                 goto catch; \
119         } \
120 } while (0)
121
122
123 #define SAL_FREE(ptr) do { \
124         if (ptr) \
125                 free(ptr); \
126         ptr = NULL; \
127 } while(0)
128
129 #endif /* __TIZEN_CONVERGENCE_SAL_INTERNAL_H__ */