@geastack/host 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,6 +25,18 @@ the `@geastack/core` WebSocket constructor (since host 0.1.16 and core 0.1.41).
25
25
  Headers are applied to both the ESP-IDF WebSocket client and its owned
26
26
  transport, so bearer authentication works on the actual HTTP upgrade request.
27
27
  Connections opened with only a URL and subprotocol keep their defaults.
28
+ Every native transport (ESP-IDF, libcurl, NSURLSession) sends a `Uint8Array`
29
+ as a binary frame.
30
+
31
+ Apple builds also compile the Objective-C++ backends listed by the source
32
+ manifest's `objcxxSources()`: the CoreBluetooth GATT central
33
+ (`host/bluetooth_central_apple.mm`), Security.framework P-256
34
+ (`host/crypto_apple.mm`), the AudioToolbox Opus decoder (`host/opus_apple.mm`),
35
+ the app data directory (`host/files_apple.mm`) and macOS menu bar mode
36
+ (`host/menu_bar_apple.mm`). Each links its system framework through a Mach-O
37
+ linker option, so targets need no framework list. Other hosts fall back to the
38
+ weak defaults in `host/crypto.cpp`, `host/opus.cpp`, `host/files.cpp` and
39
+ `host/menu_bar.cpp`.
28
40
 
29
41
  ## License
30
42
 
package/bluetooth.cpp CHANGED
@@ -47,6 +47,18 @@ NullBluetoothHidDriver &nullDriver()
47
47
  return driver;
48
48
  }
49
49
 
50
+ BluetoothCentralDriver &unsupportedCentral()
51
+ {
52
+ static BluetoothCentralDriver driver;
53
+ return driver;
54
+ }
55
+
56
+ BluetoothCentralDriver *&centralSlot()
57
+ {
58
+ static BluetoothCentralDriver *driver = &unsupportedCentral();
59
+ return driver;
60
+ }
61
+
50
62
  BluetoothHidDriver *&driverSlot()
51
63
  {
52
64
  static BluetoothHidDriver *driver = &nullDriver();
@@ -65,6 +77,16 @@ BluetoothHidDriver *BluetoothHidDevice::driver()
65
77
  return driverSlot();
66
78
  }
67
79
 
80
+ void BluetoothCentralDevice::setDriver(BluetoothCentralDriver *driver)
81
+ {
82
+ centralSlot() = driver ? driver : &unsupportedCentral();
83
+ }
84
+
85
+ BluetoothCentralDriver *BluetoothCentralDevice::driver()
86
+ {
87
+ return centralSlot();
88
+ }
89
+
68
90
  void BluetoothHidDevice::preinit() const { driver()->preinit(); }
69
91
 
70
92
  void BluetoothHidDevice::init(const char *deviceName, std::uint16_t appearance, const char *macAddress) const
package/host/ble.cpp CHANGED
@@ -236,4 +236,48 @@ void HidBackend::configPushActivity(double index) {
236
236
  bluetooth().hid().configPushActivity(HidValue::from(index));
237
237
  }
238
238
 
239
+ // Generic GATT central (navigator.bluetooth.central).
240
+ namespace {
241
+ std::string text(const char *value) { return value ? value : ""; }
242
+ } // namespace
243
+
244
+ std::string CentralBackend::state() { return text(bluetooth().central().state()); }
245
+ void CentralBackend::startScan(const std::string &services) { bluetooth().central().startScan(services.c_str()); }
246
+ void CentralBackend::stopScan() { bluetooth().central().stopScan(); }
247
+ bool CentralBackend::scanning() { return bluetooth().central().scanning(); }
248
+ double CentralBackend::scanCount() { return bluetooth().central().scanCount(); }
249
+ std::string CentralBackend::scanIdAt(double index) { return text(bluetooth().central().scanIdAt(HidValue::from(index))); }
250
+ std::string CentralBackend::scanNameAt(double index) { return text(bluetooth().central().scanNameAt(HidValue::from(index))); }
251
+ double CentralBackend::scanRssiAt(double index) { return bluetooth().central().scanRssiAt(HidValue::from(index)); }
252
+ std::string CentralBackend::scanServicesAt(double index) {
253
+ return text(bluetooth().central().scanServicesAt(HidValue::from(index)));
254
+ }
255
+ std::vector<std::uint8_t> CentralBackend::scanManufacturerDataAt(double index) {
256
+ return bluetooth().central().scanManufacturerDataAt(HidValue::from(index));
257
+ }
258
+ void CentralBackend::clearScan() { bluetooth().central().clearScan(); }
259
+ void CentralBackend::connect(const std::string &id, const std::string &services) {
260
+ bluetooth().central().connect(id.c_str(), services.c_str());
261
+ }
262
+ std::string CentralBackend::link() { return text(bluetooth().central().link()); }
263
+ std::string CentralBackend::linkError() { return text(bluetooth().central().linkError()); }
264
+ void CentralBackend::subscribe(const std::string &service, const std::string &characteristic) {
265
+ bluetooth().central().subscribe(service.c_str(), characteristic.c_str());
266
+ }
267
+ bool CentralBackend::subscribed(const std::string &service, const std::string &characteristic) {
268
+ return bluetooth().central().subscribed(service.c_str(), characteristic.c_str());
269
+ }
270
+ bool CentralBackend::write(const std::string &service, const std::string &characteristic,
271
+ const std::vector<std::uint8_t> &bytes) {
272
+ return bluetooth().central().write(service.c_str(), characteristic.c_str(), bytes.data(),
273
+ static_cast<int>(bytes.size()));
274
+ }
275
+ std::vector<std::uint8_t> CentralBackend::read(const std::string &service, const std::string &characteristic) {
276
+ return bluetooth().central().read(service.c_str(), characteristic.c_str());
277
+ }
278
+ void CentralBackend::requestRead(const std::string &service, const std::string &characteristic) {
279
+ bluetooth().central().requestRead(service.c_str(), characteristic.c_str());
280
+ }
281
+ void CentralBackend::disconnect() { bluetooth().central().disconnect(); }
282
+
239
283
  } // namespace gea::framework::bluetooth
@@ -0,0 +1,412 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // CoreBluetooth backend for the generic GATT central (navigator.bluetooth.central,
3
+ // BluetoothCentralDriver in ble.h) on macOS and iOS. Everything runs on the main
4
+ // queue, where the Gea frame loop polls it: CoreBluetooth's delegate callbacks
5
+ // fill the scan list, the link state and the per-characteristic notification
6
+ // queues, and the app drains them each frame.
7
+ //
8
+ // The CBCentralManager is created on first use, so only apps that touch the
9
+ // central ask for Bluetooth access. Such apps need NSBluetoothAlwaysUsageDescription
10
+ // in their Info.plist (macos.json `infoPlist`), or the system terminates them.
11
+ #if defined(__APPLE__)
12
+
13
+ #import <CoreBluetooth/CoreBluetooth.h>
14
+ #import <Foundation/Foundation.h>
15
+
16
+ #include <map>
17
+ #include <set>
18
+ #include <string>
19
+ #include <vector>
20
+
21
+ #include "ble.h"
22
+
23
+ __asm__(".linker_option \"-framework\", \"CoreBluetooth\"");
24
+
25
+ namespace {
26
+
27
+ struct ScanEntry {
28
+ std::string id;
29
+ std::string name;
30
+ std::string services;
31
+ int rssi = 0;
32
+ std::vector<std::uint8_t> manufacturer;
33
+ };
34
+
35
+ std::string utf8(NSString *text) { return text ? std::string(text.UTF8String ?: "") : std::string(); }
36
+
37
+ NSString *nsString(const char *text) { return [NSString stringWithUTF8String:text ? text : ""] ?: @""; }
38
+
39
+ // "SERVICE/CHARACTERISTIC" in CoreBluetooth's canonical spelling, so "180f",
40
+ // "180F" and the full 128-bit form of a 16-bit UUID all name the same slot.
41
+ std::string slotKey(CBUUID *service, CBUUID *characteristic) {
42
+ return utf8(service.UUIDString) + "/" + utf8(characteristic.UUIDString);
43
+ }
44
+
45
+ CBUUID *uuidOf(const char *text) {
46
+ NSString *value = [nsString(text) stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
47
+ if (value.length == 0) return nil;
48
+ @try {
49
+ return [CBUUID UUIDWithString:value];
50
+ } @catch (NSException *) {
51
+ return nil;
52
+ }
53
+ }
54
+
55
+ NSArray<CBUUID *> *uuidsOf(const char *csv) {
56
+ NSMutableArray<CBUUID *> *uuids = [NSMutableArray array];
57
+ for (NSString *part in [nsString(csv) componentsSeparatedByString:@","]) {
58
+ CBUUID *uuid = uuidOf(part.UTF8String);
59
+ if (uuid) [uuids addObject:uuid];
60
+ }
61
+ return uuids;
62
+ }
63
+
64
+ } // namespace
65
+
66
+ @interface GeaBluetoothCentral : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate>
67
+ @end
68
+
69
+ @implementation GeaBluetoothCentral {
70
+ @public
71
+ CBCentralManager *_manager;
72
+ NSMutableDictionary<NSString *, CBPeripheral *> *_peripherals;
73
+ std::vector<ScanEntry> _scan;
74
+ std::map<std::string, std::size_t> _scanIndex;
75
+ NSArray<CBUUID *> *_scanServices;
76
+ bool _wantsScan;
77
+
78
+ CBPeripheral *_peripheral;
79
+ NSArray<CBUUID *> *_linkServices;
80
+ std::size_t _pendingServices;
81
+ std::string _link;
82
+ std::string _linkError;
83
+ std::map<std::string, CBCharacteristic *> _characteristics;
84
+ std::map<std::string, std::vector<std::uint8_t>> _received;
85
+ std::set<std::string> _subscribed;
86
+ }
87
+
88
+ - (instancetype)init {
89
+ if ((self = [super init])) {
90
+ _peripherals = [NSMutableDictionary dictionary];
91
+ _wantsScan = false;
92
+ _pendingServices = 0;
93
+ _link = "idle";
94
+ _manager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
95
+ }
96
+ return self;
97
+ }
98
+
99
+ - (const char *)state {
100
+ switch (_manager.state) {
101
+ case CBManagerStatePoweredOn: return "on";
102
+ case CBManagerStatePoweredOff: return "off";
103
+ case CBManagerStateUnauthorized: return "unauthorized";
104
+ case CBManagerStateUnsupported: return "unsupported";
105
+ case CBManagerStateResetting: return "resetting";
106
+ default: return "unknown";
107
+ }
108
+ }
109
+
110
+ - (void)resumeScan {
111
+ if (!_wantsScan || _manager.state != CBManagerStatePoweredOn) return;
112
+ [_manager scanForPeripheralsWithServices:_scanServices.count ? _scanServices : nil
113
+ options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @YES}];
114
+ }
115
+
116
+ - (void)startScan:(const char *)servicesCsv {
117
+ _scanServices = uuidsOf(servicesCsv);
118
+ _wantsScan = true;
119
+ [self resumeScan];
120
+ }
121
+
122
+ - (void)stopScan {
123
+ _wantsScan = false;
124
+ if (_manager.state == CBManagerStatePoweredOn) [_manager stopScan];
125
+ }
126
+
127
+ - (void)clearScan {
128
+ _scan.clear();
129
+ _scanIndex.clear();
130
+ }
131
+
132
+ - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
133
+ if (central.state == CBManagerStatePoweredOn) {
134
+ [self resumeScan];
135
+ } else if (_peripheral) {
136
+ [self closed:@"bluetooth is off"];
137
+ }
138
+ }
139
+
140
+ - (void)centralManager:(CBCentralManager *)central
141
+ didDiscoverPeripheral:(CBPeripheral *)peripheral
142
+ advertisementData:(NSDictionary<NSString *, id> *)data
143
+ RSSI:(NSNumber *)rssi {
144
+ NSString *identifier = peripheral.identifier.UUIDString;
145
+ _peripherals[identifier] = peripheral;
146
+ const std::string id = utf8(identifier);
147
+ auto found = _scanIndex.find(id);
148
+ if (found == _scanIndex.end()) {
149
+ if (_scan.size() >= 256) return;
150
+ found = _scanIndex.emplace(id, _scan.size()).first;
151
+ _scan.push_back(ScanEntry{id});
152
+ }
153
+ ScanEntry &entry = _scan[found->second];
154
+ NSString *name = data[CBAdvertisementDataLocalNameKey] ?: peripheral.name;
155
+ if (name.length) entry.name = utf8(name);
156
+ if (rssi && rssi.intValue != 127) entry.rssi = rssi.intValue;
157
+ NSArray<CBUUID *> *services = data[CBAdvertisementDataServiceUUIDsKey];
158
+ if (services.count) {
159
+ std::string joined;
160
+ for (CBUUID *service in services) {
161
+ if (!joined.empty()) joined += ",";
162
+ joined += utf8(service.UUIDString);
163
+ }
164
+ entry.services = joined;
165
+ }
166
+ NSData *manufacturer = data[CBAdvertisementDataManufacturerDataKey];
167
+ if (manufacturer.length) {
168
+ const auto *bytes = static_cast<const std::uint8_t *>(manufacturer.bytes);
169
+ entry.manufacturer.assign(bytes, bytes + manufacturer.length);
170
+ }
171
+ }
172
+
173
+ - (void)connect:(const char *)identifier services:(const char *)servicesCsv {
174
+ if (_peripheral) {
175
+ _peripheral.delegate = nil;
176
+ [_manager cancelPeripheralConnection:_peripheral];
177
+ _peripheral = nil;
178
+ }
179
+ _characteristics.clear();
180
+ _received.clear();
181
+ _subscribed.clear();
182
+ _linkError.clear();
183
+
184
+ NSString *key = nsString(identifier);
185
+ CBPeripheral *peripheral = _peripherals[key];
186
+ if (!peripheral) {
187
+ NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:key];
188
+ peripheral = uuid ? [_manager retrievePeripheralsWithIdentifiers:@[ uuid ]].firstObject : nil;
189
+ }
190
+ if (!peripheral) {
191
+ _link = "closed";
192
+ _linkError = "unknown peripheral";
193
+ return;
194
+ }
195
+ _peripheral = peripheral;
196
+ _linkServices = uuidsOf(servicesCsv);
197
+ _link = "connecting";
198
+ peripheral.delegate = self;
199
+ [_manager connectPeripheral:peripheral options:nil];
200
+ }
201
+
202
+ - (void)closed:(NSString *)reason {
203
+ _peripheral.delegate = nil;
204
+ _peripheral = nil;
205
+ _characteristics.clear();
206
+ _subscribed.clear();
207
+ _link = "closed";
208
+ _linkError = utf8(reason ?: @"disconnected");
209
+ }
210
+
211
+ - (void)disconnect {
212
+ if (_peripheral) [_manager cancelPeripheralConnection:_peripheral];
213
+ if (_peripheral || _link != "idle") [self closed:@"disconnected"];
214
+ }
215
+
216
+ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
217
+ if (peripheral != _peripheral) return;
218
+ _link = "discovering";
219
+ [peripheral discoverServices:_linkServices.count ? _linkServices : nil];
220
+ }
221
+
222
+ - (void)centralManager:(CBCentralManager *)central
223
+ didFailToConnectPeripheral:(CBPeripheral *)peripheral
224
+ error:(NSError *)error {
225
+ if (peripheral == _peripheral) [self closed:error.localizedDescription ?: @"connection failed"];
226
+ }
227
+
228
+ - (void)centralManager:(CBCentralManager *)central
229
+ didDisconnectPeripheral:(CBPeripheral *)peripheral
230
+ error:(NSError *)error {
231
+ if (peripheral == _peripheral) [self closed:error.localizedDescription ?: @"disconnected"];
232
+ }
233
+
234
+ - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
235
+ if (peripheral != _peripheral) return;
236
+ if (error) {
237
+ [_manager cancelPeripheralConnection:peripheral];
238
+ [self closed:error.localizedDescription];
239
+ return;
240
+ }
241
+ for (CBUUID *wanted in _linkServices) {
242
+ BOOL present = NO;
243
+ for (CBService *service in peripheral.services) present = present || [service.UUID isEqual:wanted];
244
+ if (!present) {
245
+ [_manager cancelPeripheralConnection:peripheral];
246
+ [self closed:[@"service not found: " stringByAppendingString:wanted.UUIDString]];
247
+ return;
248
+ }
249
+ }
250
+ _pendingServices = peripheral.services.count;
251
+ if (_pendingServices == 0) {
252
+ _link = "ready";
253
+ return;
254
+ }
255
+ for (CBService *service in peripheral.services) [peripheral discoverCharacteristics:nil forService:service];
256
+ }
257
+
258
+ - (void)peripheral:(CBPeripheral *)peripheral
259
+ didDiscoverCharacteristicsForService:(CBService *)service
260
+ error:(NSError *)error {
261
+ if (peripheral != _peripheral) return;
262
+ for (CBCharacteristic *characteristic in service.characteristics) {
263
+ _characteristics[slotKey(service.UUID, characteristic.UUID)] = characteristic;
264
+ }
265
+ if (_pendingServices > 0 && --_pendingServices == 0) _link = "ready";
266
+ }
267
+
268
+ - (CBCharacteristic *)characteristic:(const char *)service of:(const char *)characteristic {
269
+ CBUUID *serviceID = uuidOf(service);
270
+ CBUUID *characteristicID = uuidOf(characteristic);
271
+ if (!serviceID || !characteristicID) return nil;
272
+ auto found = _characteristics.find(slotKey(serviceID, characteristicID));
273
+ return found == _characteristics.end() ? nil : found->second;
274
+ }
275
+
276
+ - (void)subscribe:(const char *)service characteristic:(const char *)characteristic {
277
+ CBCharacteristic *target = [self characteristic:service of:characteristic];
278
+ if (target && _peripheral) [_peripheral setNotifyValue:YES forCharacteristic:target];
279
+ }
280
+
281
+ - (bool)subscribed:(const char *)service characteristic:(const char *)characteristic {
282
+ CBCharacteristic *target = [self characteristic:service of:characteristic];
283
+ return target && _subscribed.count(slotKey(target.service.UUID, target.UUID)) > 0;
284
+ }
285
+
286
+ - (void)peripheral:(CBPeripheral *)peripheral
287
+ didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic
288
+ error:(NSError *)error {
289
+ if (peripheral != _peripheral) return;
290
+ const std::string key = slotKey(characteristic.service.UUID, characteristic.UUID);
291
+ if (error || !characteristic.isNotifying) {
292
+ _subscribed.erase(key);
293
+ if (error) _linkError = utf8(error.localizedDescription);
294
+ return;
295
+ }
296
+ _subscribed.insert(key);
297
+ }
298
+
299
+ - (void)peripheral:(CBPeripheral *)peripheral
300
+ didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
301
+ error:(NSError *)error {
302
+ if (peripheral != _peripheral || error || !characteristic.value.length) return;
303
+ auto &queue = _received[slotKey(characteristic.service.UUID, characteristic.UUID)];
304
+ const auto *bytes = static_cast<const std::uint8_t *>(characteristic.value.bytes);
305
+ // Bounded: an app that never drains a chatty characteristic loses the oldest bytes.
306
+ constexpr std::size_t limit = 4 * 1024 * 1024;
307
+ queue.insert(queue.end(), bytes, bytes + characteristic.value.length);
308
+ if (queue.size() > limit) queue.erase(queue.begin(), queue.begin() + (queue.size() - limit));
309
+ }
310
+
311
+ - (bool)write:(const char *)service
312
+ characteristic:(const char *)characteristic
313
+ bytes:(const std::uint8_t *)bytes
314
+ length:(int)length {
315
+ CBCharacteristic *target = [self characteristic:service of:characteristic];
316
+ if (!target || _link != "ready" || length < 0) return false;
317
+ const BOOL quiet = (target.properties & CBCharacteristicPropertyWriteWithoutResponse) != 0;
318
+ const CBCharacteristicWriteType type = quiet ? CBCharacteristicWriteWithoutResponse : CBCharacteristicWriteWithResponse;
319
+ const NSUInteger chunk = MAX((NSUInteger)20, [_peripheral maximumWriteValueLengthForType:type]);
320
+ const NSUInteger total = static_cast<NSUInteger>(length);
321
+ for (NSUInteger offset = 0; offset < total; offset += chunk) {
322
+ NSData *part = [NSData dataWithBytes:bytes + offset length:MIN(chunk, total - offset)];
323
+ [_peripheral writeValue:part forCharacteristic:target type:type];
324
+ }
325
+ return true;
326
+ }
327
+
328
+ - (std::vector<std::uint8_t>)read:(const char *)service characteristic:(const char *)characteristic {
329
+ CBUUID *serviceID = uuidOf(service);
330
+ CBUUID *characteristicID = uuidOf(characteristic);
331
+ if (!serviceID || !characteristicID) return {};
332
+ auto found = _received.find(slotKey(serviceID, characteristicID));
333
+ if (found == _received.end()) return {};
334
+ std::vector<std::uint8_t> bytes = std::move(found->second);
335
+ found->second.clear();
336
+ return bytes;
337
+ }
338
+
339
+ - (void)requestRead:(const char *)service characteristic:(const char *)characteristic {
340
+ CBCharacteristic *target = [self characteristic:service of:characteristic];
341
+ if (target && _peripheral) [_peripheral readValueForCharacteristic:target];
342
+ }
343
+
344
+ @end
345
+
346
+ namespace gea::framework::bluetooth {
347
+ namespace {
348
+
349
+ class AppleBluetoothCentralDriver final : public BluetoothCentralDriver {
350
+ public:
351
+ const char *state() override { return [central() state]; }
352
+ void startScan(const char *servicesCsv) override { [central() startScan:servicesCsv]; }
353
+ void stopScan() override {
354
+ if (instance_) [instance_ stopScan];
355
+ }
356
+ bool scanning() override { return instance_ && instance_->_wantsScan; }
357
+ int scanCount() override { return instance_ ? static_cast<int>(instance_->_scan.size()) : 0; }
358
+ const char *scanIdAt(int index) override { return entry(index) ? entry(index)->id.c_str() : ""; }
359
+ const char *scanNameAt(int index) override { return entry(index) ? entry(index)->name.c_str() : ""; }
360
+ int scanRssiAt(int index) override { return entry(index) ? entry(index)->rssi : 0; }
361
+ const char *scanServicesAt(int index) override { return entry(index) ? entry(index)->services.c_str() : ""; }
362
+ std::vector<std::uint8_t> scanManufacturerDataAt(int index) override {
363
+ return entry(index) ? entry(index)->manufacturer : std::vector<std::uint8_t>{};
364
+ }
365
+ void clearScan() override {
366
+ if (instance_) [instance_ clearScan];
367
+ }
368
+ void connect(const char *id, const char *servicesCsv) override { [central() connect:id services:servicesCsv]; }
369
+ const char *link() override { return instance_ ? instance_->_link.c_str() : "idle"; }
370
+ const char *linkError() override { return instance_ ? instance_->_linkError.c_str() : ""; }
371
+ void subscribe(const char *service, const char *characteristic) override {
372
+ if (instance_) [instance_ subscribe:service characteristic:characteristic];
373
+ }
374
+ bool subscribed(const char *service, const char *characteristic) override {
375
+ return instance_ && [instance_ subscribed:service characteristic:characteristic];
376
+ }
377
+ bool write(const char *service, const char *characteristic, const std::uint8_t *bytes, int length) override {
378
+ return instance_ && [instance_ write:service characteristic:characteristic bytes:bytes length:length];
379
+ }
380
+ std::vector<std::uint8_t> read(const char *service, const char *characteristic) override {
381
+ return instance_ ? [instance_ read:service characteristic:characteristic] : std::vector<std::uint8_t>{};
382
+ }
383
+ void requestRead(const char *service, const char *characteristic) override {
384
+ if (instance_) [instance_ requestRead:service characteristic:characteristic];
385
+ }
386
+ void disconnect() override {
387
+ if (instance_) [instance_ disconnect];
388
+ }
389
+
390
+ private:
391
+ GeaBluetoothCentral *central() {
392
+ if (!instance_) instance_ = [[GeaBluetoothCentral alloc] init];
393
+ return instance_;
394
+ }
395
+ const ScanEntry *entry(int index) const {
396
+ if (!instance_ || index < 0 || static_cast<std::size_t>(index) >= instance_->_scan.size()) return nullptr;
397
+ return &instance_->_scan[static_cast<std::size_t>(index)];
398
+ }
399
+ GeaBluetoothCentral *instance_ = nil;
400
+ };
401
+
402
+ AppleBluetoothCentralDriver &appleCentral() {
403
+ static AppleBluetoothCentralDriver driver;
404
+ return driver;
405
+ }
406
+
407
+ [[maybe_unused]] const bool installed = (BluetoothCentralDevice::setDriver(&appleCentral()), true);
408
+
409
+ } // namespace
410
+ } // namespace gea::framework::bluetooth
411
+
412
+ #endif