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_PERIPHERAL_H
20 #define CA_BLE_LINUX_PERIPHERAL_H
23 #include "advertisement.h"
31 * Linux BLE "peripheral" context.
33 typedef struct _CAPeripheralContext
38 * The base context contains core state used throughout the Linux
39 * BLE adapter implementation.
43 /// D-Bus bus name owner ID.
47 * LE advertising information.
49 * The LE advertising information will be registered with BlueZ,
50 * which BlueZ will then use to add advertising data to each of
51 * the detected Bluetooth hardware adapters. Only one set of
52 * advertising data is needed since the data is the same for all
55 CALEAdvertisement advertisement;
58 * List of @c CAGattService objects containing information for all
59 * exported and registered IoTivity BlueZ GATT related D-Bus
62 GList * gatt_services;
65 * Glib event loop that drives peripheral D-Bus signal
68 * @note A seperate thread drives this event loop. This is
69 * necessitated by the need for signal subscriptions to be
70 * done in what the GLib documentation refers to as the
71 * "thread-default main context". By the time the
72 * peripheral is started it's too late the use the main loop
73 * that was run when this Linux BLE transport adapter itself
74 * was started through @c CASelectNetwork() and the @c
75 * CAAdapterStart() callback the peripheral must have its
78 GMainLoop * event_loop;
80 /// Mutex used to synchronize access to context fields.
84 * Service registration condition variable.
86 * This condition variable is used to delay service registration
87 * until the thread performing service initialization completes.
88 * Initialization is performed in the same thread that will run
89 * the peripheral's event loop.
91 * @see @c GMainLoop documentation for further details.
95 } CAPeripheralContext;
98 * Initialize global state.
100 void CAPeripheralInitialize();
103 * Finalize global state.
105 void CAPeripheralFinalize();
108 * Initialize and start a Linux BLE "peripheral".
110 * Initialize all Linux BLE "peripheral" state (i.e. a global
111 * @c CAPeripheralContext instance), as well as register the OIC
112 * GATT transport service with BlueZ to begin advertising.
114 * @param[in] context Base context.
116 * @return @c CA_STATUS_OK on success.
118 CAResult_t CAPeripheralStart(CALEContext * context);
121 * Stop the Linux BLE "peripheral".
123 * @return @c CA_STATUS_OK on success.
125 CAResult_t CAPeripheralStop();
128 * Invoke function @a func for each registered GATT service.
130 * For each registered GATT service, invoke the function @a func,
131 * where the first (data) paramter will be a pointer to the
132 * ::CAGattService object, and the second will be the @a user_data
133 * argument provided to this function call.
135 * @param[in] func Function to be invoked for each
137 * @param[in] user_data User provided data passed as the second
138 * argument to the function @a func.
140 * @note This function exists to avoid exposing the BLE peripheral
143 void CAPeripheralForEachService(GFunc func, void * user_data);
146 #endif /* CA_BLE_LINUX_PERIPHERAL_H */