Fix: glib error
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / include / bt-core-common.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 #ifndef _BT_CORE_COMMON_H_
20 #define _BT_CORE_COMMON_H_
21
22 #include <sys/types.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #undef LOG_TAG
29 #define LOG_TAG "BLUETOOTH_FRWK_CORE"
30
31 #define LOG_COLOR_RESET    "\033[0m"
32 #define LOG_COLOR_RED      "\033[31m"
33 #define LOG_COLOR_YELLOW   "\033[33m"
34 #define LOG_COLOR_GREEN         "\033[32m"
35 #define LOG_COLOR_BLUE          "\033[36m"
36 #define LOG_COLOR_PURPLE   "\033[35m"
37
38 #define BT_DBG(fmt, args...) \
39         SLOGD(fmt, ##args)
40 #define BT_INFO(fmt, args...) \
41         SLOGI(fmt, ##args)
42 #define BT_ERR(fmt, args...) \
43         SLOGE(fmt, ##args)
44
45 #define BT_INFO_C(fmt, arg...) \
46         SLOGI_IF(TRUE,  LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
47 #define BT_ERR_C(fmt, arg...) \
48         SLOGI_IF(TRUE,  LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
49
50 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
51 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
52
53 #define ret_if(expr) \
54         do { \
55                 if (expr) { \
56                         BT_ERR("(%s) return", #expr); \
57                         return; \
58                 } \
59         } while (0)
60
61 #define retv_if(expr, val) \
62         do { \
63                 if (expr) { \
64                         BT_ERR("(%s) return", #expr); \
65                         return (val); \
66                 } \
67         } while (0)
68
69 #define BT_FREE_PARAMS(IP1, IP2, IP3, IP4, OP) \
70         do { \
71                 if (IP1) \
72                         g_array_free(IP1, TRUE); \
73                 if (IP2) \
74                         g_array_free(IP2, TRUE); \
75                 if (IP3) \
76                         g_array_free(IP3, TRUE); \
77                 if (IP4) \
78                         g_array_free(IP4, TRUE); \
79                 if (OP) \
80                         g_array_free(OP, TRUE); \
81         } while (0)
82
83 #define BT_ALLOC_PARAMS(IP1, IP2, IP3, IP4, OP) \
84         do { \
85                 IP1 = g_array_new(TRUE, TRUE, sizeof(gchar));   \
86                 IP2 = g_array_new(TRUE, TRUE, sizeof(gchar));   \
87                 IP3 = g_array_new(TRUE, TRUE, sizeof(gchar));   \
88                 IP4 = g_array_new(TRUE, TRUE, sizeof(gchar));   \
89         } while (0)
90
91 #ifdef __cplusplus
92 }
93 #endif /* __cplusplus */
94 #endif /*_BT_CORE_COMMON_H_*/
95