Skip to content

Commit

Permalink
Update src/platform/Darwin/BleConnectionDelegateImpl.mm such that it …
Browse files Browse the repository at this point in the history
…does not creates a PacketBufferHandle from the ble work queue but from the chip work queue
  • Loading branch information
vivien-apple committed Mar 6, 2023
1 parent 04082e1 commit 3dc49d7
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -375,34 +375,30 @@ - (void)peripheral:(CBPeripheral *)peripheral
didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
error:(NSError *)error
{
auto bridgedPeripheral = (__bridge void *) peripheral;
if (nil == error) {
chip::Ble::ChipBleUUID svcId;
chip::Ble::ChipBleUUID charId;
[BleConnection fillServiceWithCharacteristicUuids:characteristic svcId:&svcId charId:&charId];

// build a inet buffer from the rxEv and send to blelayer.
__block chip::System::PacketBufferHandle msgBuf
= chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length);

if (!msgBuf.IsNull()) {
dispatch_async(_chipWorkQueue, ^{
if (!_mBleLayer->HandleIndicationReceived((__bridge void *) peripheral, &svcId, &charId, std::move(msgBuf))) {
// since this error comes from device manager core
// we assume it would do the right thing, like closing the connection
ChipLogError(Ble, "Failed at handling incoming BLE data");
}
});
} else {
ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data");
dispatch_async(_chipWorkQueue, ^{
_mBleLayer->HandleConnectionError((__bridge void *) peripheral, CHIP_ERROR_NO_MEMORY);
});
}
dispatch_async(_chipWorkQueue, ^{
// build a inet buffer from the rxEv and send to blelayer.
auto msgBuf = chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length);

if (msgBuf.IsNull()) {
ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data");
_mBleLayer->HandleConnectionError(bridgedPeripheral, CHIP_ERROR_NO_MEMORY);
} else if (!_mBleLayer->HandleIndicationReceived(bridgedPeripheral, &svcId, &charId, std::move(msgBuf))) {
// since this error comes from device manager core
// we assume it would do the right thing, like closing the connection
ChipLogError(Ble, "Failed at handling incoming BLE data");
}
});
} else {
ChipLogError(
Ble, "BLE:Error receiving indication of Characteristics on the device: [%s]", [error.localizedDescription UTF8String]);
dispatch_async(_chipWorkQueue, ^{
_mBleLayer->HandleConnectionError((__bridge void *) peripheral, BLE_ERROR_GATT_INDICATE_FAILED);
_mBleLayer->HandleConnectionError(bridgedPeripheral, BLE_ERROR_GATT_INDICATE_FAILED);
});
}
}
Expand Down

0 comments on commit 3dc49d7

Please sign in to comment.