From cf87fd8efb3cf82025108e40ce84e6bd78b121d2 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 6 Jun 2024 14:12:34 +0200 Subject: [PATCH] [Python] Remove Python Bluetooth and ChipStack event loop integration The Python Bluetooth implementation for Linux (`BluezManager` in ChipBluezMgr.py) and macOS (`CoreBluetoothManager` in ChipCoreBluetoothMgr.py) integrate with ChipStack to pump their event loops on long running operations such as commissioning (through `CallAsyncWithCompleteCallback()`). From what I can tell, the Python Bluetooth stack is only used for some mbed integration tests. Specifically through `scan_chip_ble_devices()` in src/test_driver/mbed/integration_tests/common/utils.py. This operation doesn't need the event loop integration. So as a first step, this PR simply breaks this tie and removes the event loop integration with the Device ChipStack/ChipDeviceController. --- src/controller/python/chip/ChipBluezMgr.py | 1 - src/controller/python/chip/ChipCoreBluetoothMgr.py | 2 -- src/controller/python/chip/ChipDeviceCtrl.py | 5 ----- src/controller/python/chip/ChipStack.py | 8 +------- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/controller/python/chip/ChipBluezMgr.py b/src/controller/python/chip/ChipBluezMgr.py index e480750b600af8..bacf383710eccd 100644 --- a/src/controller/python/chip/ChipBluezMgr.py +++ b/src/controller/python/chip/ChipBluezMgr.py @@ -807,7 +807,6 @@ def __init__(self, devMgr, logger=None): self.rx = None self.setInputHook(self.readlineCB) self.devMgr = devMgr - self.devMgr.SetBlockingCB(self.devMgrCB) def __del__(self): self.disconnect() diff --git a/src/controller/python/chip/ChipCoreBluetoothMgr.py b/src/controller/python/chip/ChipCoreBluetoothMgr.py index 3f792a5a4d2425..4a65f1e2377038 100644 --- a/src/controller/python/chip/ChipCoreBluetoothMgr.py +++ b/src/controller/python/chip/ChipCoreBluetoothMgr.py @@ -184,8 +184,6 @@ def __init__(self, devCtrl, logger=None): def __del__(self): self.disconnect() self.setInputHook(self.orig_input_hook) - self.devCtrl.SetBlockingCB(None) - self.devCtrl.SetBleEventCB(None) def devMgrCB(self): """A callback used by ChipDeviceCtrl.py to drive the OSX runloop while the diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 2ba7c584db927b..aca971e5d392f1 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -1591,11 +1591,6 @@ async def ReadEvent(self, nodeid: int, events: typing.List[typing.Union[ else: return res.events - def SetBlockingCB(self, blockingCB): - self.CheckIsActive() - - self._ChipStack.blockingCB = blockingCB - def SetIpk(self, ipk: bytes): self._ChipStack.Call( lambda: self._dmLib.pychip_DeviceController_SetIpk(self.devCtrl, ipk, len(ipk)) diff --git a/src/controller/python/chip/ChipStack.py b/src/controller/python/chip/ChipStack.py index b47c4639825da8..5fd0601ba204e7 100644 --- a/src/controller/python/chip/ChipStack.py +++ b/src/controller/python/chip/ChipStack.py @@ -165,8 +165,6 @@ def HandleChipThreadRun(callback): callback() self.cbHandleChipThreadRun = HandleChipThreadRun - # set by other modules(BLE) that require service by thread while thread blocks. - self.blockingCB = None # # Storage has to be initialized BEFORE initializing the stack, since the latter @@ -255,11 +253,7 @@ def CallAsyncWithCompleteCallback(self, callFunct): if not res.is_success: self.completeEvent.set() raise res.to_exception() - while not self.completeEvent.isSet(): - if self.blockingCB: - self.blockingCB() - - self.completeEvent.wait(0.05) + self.completeEvent.wait() if isinstance(self.callbackRes, ChipStackException): raise self.callbackRes return self.callbackRes