Add the check logic for the client connection
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-internal.h
1 /*
2 * Open Adaptation Layer (OAL)
3 *
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
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 _OAL_INTERNAL_H_
21 #define _OAL_INTERNAL_H_
22
23 #include <glib.h>
24 #include <sys/types.h>
25 #include <dlog.h>
26 #include <bluetooth.h>
27
28 #include <oal-event.h>
29 #include "oal-manager.h"
30 #include "oal-utils.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define OAL_VERSION_STR "Samsung OAL Version v0.1"
37
38 #define PR_TASK_PERF_USER_TRACE 666
39 #define BT_ADDRESS_STRING_SIZE 18
40 #define BT_UUID_STRING_MAX 50
41
42 #undef LOG_TAG
43 #define LOG_TAG "BT_OAL"
44
45 #define BT_DBG(fmt, args...) \
46         LOGD(fmt, ##args)
47 #define BT_ERR(fmt, args...) \
48         LOGE(RED(fmt), ##args)
49 #define BT_INFO(fmt, args...) \
50                 LOGI(fmt, ##args)
51 #define BT_VBS(fmt, args...) \
52                 {SLOGI(fmt, ##args); LOGI(fmt, ##args); }
53 #define BT_WARN(fmt, args...) \
54                 LOGW(YELLOW(fmt), ##args)
55 #define NO_SUPP_CHK(status, fmt, args...) do {\
56                         if (status == BT_STATUS_UNSUPPORTED)    \
57                                 BT_WARN(fmt, ##args);                   \
58                         else                                                            \
59                                 BT_ERR(fmt, ##args);                    \
60                         } while (0)
61
62
63 #define API_TRACE(fmt, args...) {LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_API", GREEN(fmt), ##args); \
64                         LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_API]"fmt), ##args); }
65
66 #define send_event_trace(e, d, l, a, fmt, args...) do {\
67                                                                         bdstr_t bdstr;\
68                                                                         send_event_no_trace(e, d, l); \
69                                                                         LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_EVENT", GREEN(fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]); \
70                                                                         LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_EVENT]"fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]);\
71                                                                         } while (0)
72
73
74 #define ret_if(expr) \
75         do { \
76                 if (expr) { \
77                         BT_ERR("(%s) return", #expr); \
78                         return; \
79                 } \
80         } while (0)
81
82 #define retv_if(expr, val) \
83         do { \
84                 if (expr) { \
85                         BT_ERR("(%s) return", #expr); \
86                         return (val); \
87                 } \
88         } while (0)
89
90 #define OAL_CHECK_PARAMETER(arg, func) \
91         do { \
92                 if (arg == NULL) { \
93                         BT_ERR("INVALID PARAMETER"); \
94                         func OAL_STATUS_INVALID_PARAM; \
95                 } \
96         } while (0)
97
98 #define CHECK_OAL_INITIALIZED() \
99         do { \
100                 if (blued_api == NULL) { \
101                         BT_ERR("OAL Not Initialized"); \
102                         return OAL_STATUS_NOT_READY; \
103                 } \
104         } while (0)
105
106 #define BT_ADDRESS_STRING_SIZE 18
107
108 typedef struct {
109         int len;
110         uint8_t * adv_data;
111 } ble_adv_data_t;
112
113 /* Adapter manager */
114 void oal_mgr_cleanup(void);
115 void oal_mgr_stack_reload(void);
116
117 /* Device manager */
118 void device_mgr_init(const bt_interface_t * stack_if);
119 void device_mgr_cleanup(void);
120
121 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if);
122 const bt_interface_t* adapter_get_stack_interface(void);
123
124 /* Event Manager */
125 /* Use this when Address is to be printed */
126 void send_event_bda_trace(oal_event_t event, gpointer event_data, gsize len, bt_address_t *address);
127
128 void send_event_no_trace(oal_event_t event, gpointer event_data, gsize len);
129
130 /* Use this when no address printing is required */
131 #define _bt_dispatch_event send_event
132 void send_event(oal_event_t event, gpointer event_data, gsize len);
133 void _bt_event_dispatcher_init(oal_event_callback cb);
134 void _bt_event_dispatcher_deinit(void);
135
136 #ifdef __cplusplus
137 }
138 #endif /* __cplusplus */
139 #endif /*_OAL_HARDWARE_H_*/
140