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 7, 2023
1 parent 16d4596 commit 91a04fb
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,19 @@ - (void)peripheral:(CBPeripheral *)peripheral
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, ^{
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((__bridge void *) peripheral, CHIP_ERROR_NO_MEMORY);
});
}
} else 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, "BLE:Error receiving indication of Characteristics on the device: [%s]", [error.localizedDescription UTF8String]);
Expand Down

0 comments on commit 91a04fb

Please sign in to comment.