30
30
#include < platform/CHIPDeviceLayer.h>
31
31
#include < platform/Darwin/BleConnectionDelegateImpl.h>
32
32
#include < platform/Darwin/BleScannerDelegate.h>
33
+ #include < platform/Darwin/BleUtils.h>
33
34
#include < platform/LockTracker.h>
34
35
#include < setup_payload/SetupPayload.h>
35
36
#include < tracing/metric_event.h>
39
40
40
41
using namespace chip ::Ble;
41
42
using namespace chip ::DeviceLayer;
43
+ using namespace chip ::DeviceLayer::Internal;
42
44
using namespace chip ::Tracing::DarwinPlatform;
43
45
44
46
constexpr uint64_t kScanningWithDiscriminatorTimeoutInSeconds = 60 ;
@@ -125,7 +127,7 @@ - (void)removePeripheralsFromCache;
125
127
assertChipStackLockedByCurrentThread ();
126
128
127
129
ChipLogProgress (Ble, " ConnectionDelegate NewConnection with conn obj: %p" , connObj);
128
- CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj;
130
+ CBPeripheral * peripheral = CBPeripheralFromBleConnObject ( connObj) ;
129
131
130
132
// The BLE_CONNECTION_OBJECT represent a CBPeripheral object. In order for it to be valid the central
131
133
// manager needs to still be running.
@@ -296,7 +298,7 @@ - (void)dispatchConnectionError:(CHIP_ERROR)error
296
298
- (void )dispatchConnectionComplete : (CBPeripheral *)peripheral
297
299
{
298
300
if (self.onConnectionComplete != nil ) {
299
- self.onConnectionComplete (self.appState , (__bridge void *) peripheral);
301
+ self.onConnectionComplete (self.appState , BleConnObjectFromCBPeripheral ( peripheral) );
300
302
}
301
303
}
302
304
@@ -465,12 +467,12 @@ - (void)peripheral:(CBPeripheral *)peripheral
465
467
chip::Ble::ChipBleUUID svcId;
466
468
chip::Ble::ChipBleUUID charId;
467
469
[BleConnection fillServiceWithCharacteristicUuids: characteristic svcId: &svcId charId: &charId];
468
- _mBleLayer->HandleWriteConfirmation ((__bridge void *) peripheral, &svcId, &charId);
470
+ _mBleLayer->HandleWriteConfirmation (BleConnObjectFromCBPeripheral ( peripheral) , &svcId, &charId);
469
471
} else {
470
472
ChipLogError (
471
473
Ble, " BLE:Error writing Characteristics in Chip service on the device: [%s]" , [error.localizedDescription UTF8String ]);
472
474
MATTER_LOG_METRIC (kMetricBLEWriteChrValueFailed , BLE_ERROR_GATT_WRITE_FAILED);
473
- _mBleLayer->HandleConnectionError ((__bridge void *) peripheral, BLE_ERROR_GATT_WRITE_FAILED);
475
+ _mBleLayer->HandleConnectionError (BleConnObjectFromCBPeripheral ( peripheral) , BLE_ERROR_GATT_WRITE_FAILED);
474
476
}
475
477
}
476
478
@@ -486,9 +488,9 @@ - (void)peripheral:(CBPeripheral *)peripheral
486
488
[BleConnection fillServiceWithCharacteristicUuids: characteristic svcId: &svcId charId: &charId];
487
489
488
490
if (isNotifying) {
489
- _mBleLayer->HandleSubscribeComplete ((__bridge void *) peripheral, &svcId, &charId);
491
+ _mBleLayer->HandleSubscribeComplete (BleConnObjectFromCBPeripheral ( peripheral) , &svcId, &charId);
490
492
} else {
491
- _mBleLayer->HandleUnsubscribeComplete ((__bridge void *) peripheral, &svcId, &charId);
493
+ _mBleLayer->HandleUnsubscribeComplete (BleConnObjectFromCBPeripheral ( peripheral) , &svcId, &charId);
492
494
}
493
495
} else {
494
496
ChipLogError (Ble, " BLE:Error subscribing/unsubcribing some characteristic on the device: [%s]" ,
@@ -497,11 +499,11 @@ - (void)peripheral:(CBPeripheral *)peripheral
497
499
if (isNotifying) {
498
500
MATTER_LOG_METRIC (kMetricBLEUpdateNotificationStateForChrFailed , BLE_ERROR_GATT_WRITE_FAILED);
499
501
// we're still notifying, so we must failed the unsubscription
500
- _mBleLayer->HandleConnectionError ((__bridge void *) peripheral, BLE_ERROR_GATT_UNSUBSCRIBE_FAILED);
502
+ _mBleLayer->HandleConnectionError (BleConnObjectFromCBPeripheral ( peripheral) , BLE_ERROR_GATT_UNSUBSCRIBE_FAILED);
501
503
} else {
502
504
// we're not notifying, so we must failed the subscription
503
505
MATTER_LOG_METRIC (kMetricBLEUpdateNotificationStateForChrFailed , BLE_ERROR_GATT_SUBSCRIBE_FAILED);
504
- _mBleLayer->HandleConnectionError ((__bridge void *) peripheral, BLE_ERROR_GATT_SUBSCRIBE_FAILED);
506
+ _mBleLayer->HandleConnectionError (BleConnObjectFromCBPeripheral ( peripheral) , BLE_ERROR_GATT_SUBSCRIBE_FAILED);
505
507
}
506
508
}
507
509
}
@@ -522,8 +524,8 @@ - (void)peripheral:(CBPeripheral *)peripheral
522
524
if (msgBuf.IsNull ()) {
523
525
ChipLogError (Ble, " Failed at allocating buffer for incoming BLE data" );
524
526
MATTER_LOG_METRIC (kMetricBLEUpdateValueForChrFailed , CHIP_ERROR_NO_MEMORY);
525
- _mBleLayer->HandleConnectionError ((__bridge void *) peripheral, CHIP_ERROR_NO_MEMORY);
526
- } else if (!_mBleLayer->HandleIndicationReceived ((__bridge void *) peripheral, &svcId, &charId, std::move (msgBuf))) {
527
+ _mBleLayer->HandleConnectionError (BleConnObjectFromCBPeripheral ( peripheral) , CHIP_ERROR_NO_MEMORY);
528
+ } else if (!_mBleLayer->HandleIndicationReceived (BleConnObjectFromCBPeripheral ( peripheral) , &svcId, &charId, std::move (msgBuf))) {
527
529
// since this error comes from device manager core
528
530
// we assume it would do the right thing, like closing the connection
529
531
ChipLogError (Ble, " Failed at handling incoming BLE data" );
@@ -533,7 +535,7 @@ - (void)peripheral:(CBPeripheral *)peripheral
533
535
ChipLogError (
534
536
Ble, " BLE:Error receiving indication of Characteristics on the device: [%s]" , [error.localizedDescription UTF8String ]);
535
537
MATTER_LOG_METRIC (kMetricBLEUpdateValueForChrFailed , BLE_ERROR_GATT_INDICATE_FAILED);
536
- _mBleLayer->HandleConnectionError ((__bridge void *) peripheral, BLE_ERROR_GATT_INDICATE_FAILED);
538
+ _mBleLayer->HandleConnectionError (BleConnObjectFromCBPeripheral ( peripheral) , BLE_ERROR_GATT_INDICATE_FAILED);
537
539
}
538
540
}
539
541
@@ -647,7 +649,7 @@ - (void)updateWithDelegate:(chip::DeviceLayer::BleScannerDelegate *)delegate pre
647
649
NSData * serviceData = _cachedPeripherals[cachedPeripheral][@" data" ];
648
650
ChipBLEDeviceIdentificationInfo info;
649
651
memcpy (&info, [serviceData bytes ], sizeof (info));
650
- delegate->OnBleScanAdd ((__bridge void *) cachedPeripheral, info);
652
+ delegate->OnBleScanAdd (BleConnObjectFromCBPeripheral ( cachedPeripheral) , info);
651
653
}
652
654
_scannerDelegate = delegate;
653
655
}
@@ -721,7 +723,7 @@ - (void)addPeripheralToCache:(CBPeripheral *)peripheral data:(NSData *)data
721
723
ChipBLEDeviceIdentificationInfo info;
722
724
auto bytes = (const uint8_t *) [data bytes ];
723
725
memcpy (&info, bytes, sizeof (info));
724
- delegate->OnBleScanAdd ((__bridge void *) peripheral, info);
726
+ delegate->OnBleScanAdd (BleConnObjectFromCBPeripheral ( peripheral) , info);
725
727
}
726
728
727
729
timeoutTimer = dispatch_source_create (DISPATCH_SOURCE_TYPE_TIMER, 0 , 0 , _workQueue);
@@ -768,7 +770,7 @@ - (void)removePeripheralFromCache:(CBPeripheral *)peripheral
768
770
769
771
auto delegate = _scannerDelegate;
770
772
if (delegate) {
771
- delegate->OnBleScanRemove ((__bridge void *) peripheral);
773
+ delegate->OnBleScanRemove (BleConnObjectFromCBPeripheral ( peripheral) );
772
774
}
773
775
}
774
776
}
0 commit comments