1 /******************************************************************
3 * Copyright 2015 Intel Corporation All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************/
19 #ifndef CA_BLE_LINUX_CONTEXT_H
20 #define CA_BLE_LINUX_CONTEXT_H
22 #include "caadapterinterface.h"
24 #include "cathreadpool.h"
25 #include "caleinterface.h"
28 #include <semaphore.h>
34 * BLE Linux adapter base context.
36 typedef struct _CALEContext
38 /// Connection to the D-Bus system bus.
39 GDBusConnection * connection;
42 * Proxy to the BlueZ D-Bus object that implements the
43 * "org.freedesktop.DBus.ObjectManager" interface.
45 * @todo There's probably no need to keep this around after we've
46 * retrieved the managed objects the first time around since
47 * we can rely on signals to alert us to any subsequent
50 GDBusObjectManager * object_manager;
53 * List of @c GDBusObject objects obtained from the BlueZ
56 * @note This list will be updated later on as needed if changes
57 * in the BlueZ ObjectManager are detected.
64 * List of @c GDBusProxy objects for all BlueZ adapters (i.e.
65 * @c org.bluez.Adapter1). More than one adapter can exist if
66 * multiple Bluetooth hardware interfaces are detected by BlueZ.
73 * List of @c GDBusProxy objects for all BlueZ devices (i.e.
74 * @c org.bluez.Device1), such as those that matched the discovery
80 * GATT characteristics to Bluetooth MAC address map.
82 * Hash table that maps OIC Transport Profile GATT characteristic
83 * to a Bluetooth MAC address. The key is an interface proxy
84 * (@c GDBusProxy) to an @c org.bluez.GattCharacteristic1 object.
85 * The value is a pointer to the peer @c CAEndpoint_t object.
87 * On the client side, this maps a response characteristic to the
88 * corresponding MAC address. On the server side, this maps
89 * request characteristic to the corresponding MAC address.
91 * @note On the server side a map is overkill since only one
92 * client is ever connected to the server. No?
94 * @todo We may want to have a seperate server-side map to reduce
95 * contention on this map.
97 GHashTable * address_map;
100 * D-Bus signal subscription identifiers.
102 * The Linux BLE transport implementation subscribes to three
105 * @li @c org.freedesktop.DBus.ObjectManager.InterfacesAdded
106 * @li @c org.freedesktop.DBus.ObjectManager.InterfacesRemoved
108 * These subscription identifiers are only used when unsubscribing
109 * from the signals when stopping the LE transport.
111 * @todo Verify if we need the two property related signals at
115 guint interfaces_added_sub_id;
116 guint interfaces_removed_sub_id;
119 /// Glib event loop that drives D-Bus signal handling.
120 GMainLoop * event_loop;
123 * Callback invoked upon change in local Bluetooth adapter state.
125 CALEDeviceStateChangedCallback on_device_state_changed;
127 /// Callback invoked upon server receiving request data.
128 CABLEDataReceivedCallback on_server_received_data;
130 /// Callback invoked upon client receiving response data.
131 CABLEDataReceivedCallback on_client_received_data;
134 * Handle to thread pool to which client side tasks will be
137 ca_thread_pool_t client_thread_pool;
140 * Handle to thread pool to which server side tasks will be
143 ca_thread_pool_t server_thread_pool;
145 /// Callback invoked when reporting a client side error.
146 CABLEErrorHandleCallback on_client_error;
148 /// Callback invoked when reporting a server side error.
149 CABLEErrorHandleCallback on_server_error;
151 /// Mutex used to synchronize access to context fields.
155 * BlueZ adapter list initialization condition variable.
157 * This condition variable is used to prevent the BLE adapter
158 * "start" from completing until the thread performing BlueZ
159 * adapter query completes. Initialization is performed in the
160 * same thread that will run the event loop. The condition
161 * variable is also used to wait for peripheral devices to be
164 * @see @c GMainLoop documentation for further details.
169 * Semaphore that indicates completed start of the LE transport.
171 * In some corner cases the transport stop will complete before
172 * transport start completes. In such cases, the event loop
173 * run during LE transport start will never exit since the
174 * transport stop will have completed before the event loop that
176 * run. This semaphore is used to force the call to
177 * ::CAStartLEAdapter() to wait for the thread that runs the GLib
178 * event loop that drives D-Bus signal handling to completely
186 #endif /* CA_BLE_LINUX_CONTEXT_H */