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"
33 * BLE Linux adapter base context.
35 typedef struct _CALEContext
37 /// Connection to the D-Bus system bus.
38 GDBusConnection * connection;
41 * Proxy to the BlueZ D-Bus object that implements the
42 * "org.freedesktop.DBus.ObjectManager" interface.
44 * @todo There's probably no need to keep this around after we've
45 * retrieved the managed objects the first time around since
46 * we can rely on signals to alert us to any subsequent
49 GDBusObjectManager * object_manager;
52 * List of @c GDBusObject objects obtained from the BlueZ
55 * @note This list will be updated later on as needed if changes
56 * in the BlueZ ObjectManager are detected.
63 * List of @c GDBusProxy objects for all BlueZ adapters (i.e.
64 * @c org.bluez.Adapter1). More than one adapter can exist if
65 * multiple Bluetooth hardware interfaces are detected by BlueZ.
72 * List of @c GDBusProxy objects for all BlueZ devices (i.e.
73 * @c org.bluez.Device1), such as those that matched the discovery
79 * Bluetooth MAC address to GATT characteristic map.
81 * Hash table that maps Bluetooth MAC address to a OIC Transport
82 * Profile GATT characteristic. The key is a string containing
83 * the peer Bluetooth adapter MAC address. The value is an
84 * interface proxy (@c GDBusProxy) to an
85 * @c org.bluez.GattCharacteristic1 object.
87 * On the client side, this maps a Bluetooth peripheral MAC
88 * address to the corresponding request characteristic proxy. On
89 * the server side, this maps Bluetooth central MAC address to the
90 * corresponding response characteristic proxy.
92 * @note On the server side a map is overkill since only one
93 * client is ever connected to the server. No?
95 * @todo We may want to have a seperate server-side map to reduce
96 * contention on this map.
98 GHashTable * characteristic_map;
101 * GATT characteristics to Bluetooth MAC address map.
103 * Hash table that maps OIC Transport Profile GATT characteristic
104 * to a Bluetooth MAC address. The key is an interface proxy
105 * (@c GDBusProxy) to an @c org.bluez.GattCharacteristic1 object.
106 * The value is a pointer to the peer @c CAEndpoint_t object.
108 * On the client side, this maps a response characteristic to the
109 * corresponding MAC address. On the server side, this maps
110 * request characteristic to the corresponding MAC address.
112 * @note On the server side a map is overkill since only one
113 * client is ever connected to the server. No?
115 * @todo We may want to have a seperate server-side map to reduce
116 * contention on this map.
118 GHashTable * address_map;
121 * D-Bus signal subscription identifiers.
123 * The Linux BLE transport implementation subscribes to three
126 * @li @c org.freedesktop.DBus.ObjectManager.InterfacesAdded
127 * @li @c org.freedesktop.DBus.ObjectManager.InterfacesRemoved
128 * @li @c org.freedesktop.DBus.Properties.PropertiesChanged
129 * @li @c org.bluez.Adapter1.PropertyChanged
131 * These subscription identifiers are only used when unsubscribing
132 * from the signals when stopping the LE transport.
134 * @todo Verify if we need the two property related signals at
138 guint interfaces_added_sub_id;
139 guint interfaces_removed_sub_id;
140 guint properties_changed_sub_id;
141 guint property_changed_sub_id;
144 /// Glib event loop that drives D-Bus signal handling.
145 GMainLoop * event_loop;
148 * Callback invoked upon change in local Bluetooth adapter state.
150 CALEDeviceStateChangedCallback on_device_state_changed;
152 /// Callback invoked upon server receiving request data.
153 CABLEDataReceivedCallback on_server_received_data;
155 /// Callback invoked upon client receiving response data.
156 CABLEDataReceivedCallback on_client_received_data;
159 * Handle to thread pool to which client side tasks will be
162 ca_thread_pool_t client_thread_pool;
165 * Handle to thread pool to which server side tasks will be
168 ca_thread_pool_t server_thread_pool;
170 /// Callback invoked when reporting a client side error.
171 CABLEErrorHandleCallback on_client_error;
173 /// Callback invoked when reporting a server side error.
174 CABLEErrorHandleCallback on_server_error;
176 /// Mutex used to synchronize access to context fields.
180 * BlueZ adapter list initialization condition variable.
182 * This condition variable is used to prevent the BLE adapter
183 * "start" from completing until the thread performing BlueZ
184 * adapter query completes. Initialization is performed in the
185 * same thread that will run the event loop. The condition
186 * variable is also used to wait for peripheral devices to be
189 * @see @c GMainLoop documentation for further details.
196 #endif /* CA_BLE_LINUX_CONTEXT_H */