Skip to content

Commit

Permalink
[Python] Remove Python Bluetooth and ChipStack event loop integration (
Browse files Browse the repository at this point in the history
…project-chip#33775)

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.
  • Loading branch information
agners authored Jun 6, 2024
1 parent d15f6c1 commit 88ebdf7
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 15 deletions.
1 change: 0 additions & 1 deletion src/controller/python/chip/ChipBluezMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions src/controller/python/chip/ChipCoreBluetoothMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 1 addition & 7 deletions src/controller/python/chip/ChipStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88ebdf7

Please sign in to comment.