|
| 1 | +From a4fb58131d9023ad3a3ec01d44c5ae87946d6b59 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Stefan Agner <stefan@agner.ch> |
| 3 | +Date: Thu, 6 Jun 2024 17:11:34 +0200 |
| 4 | +Subject: [PATCH] [Python] Remove Python Bluetooth and ChipStack event loop |
| 5 | + integration (#33775) |
| 6 | + |
| 7 | +The Python Bluetooth implementation for Linux (`BluezManager` in |
| 8 | +ChipBluezMgr.py) and macOS (`CoreBluetoothManager` in |
| 9 | +ChipCoreBluetoothMgr.py) integrate with ChipStack to pump their event |
| 10 | +loops on long running operations such as commissioning (through |
| 11 | +`CallAsyncWithCompleteCallback()`). From what I can tell, the Python |
| 12 | +Bluetooth stack is only used for some mbed integration tests. |
| 13 | +Specifically through `scan_chip_ble_devices()` |
| 14 | +in src/test_driver/mbed/integration_tests/common/utils.py. This |
| 15 | +operation doesn't need the event loop integration. |
| 16 | + |
| 17 | +So as a first step, this PR simply breaks this tie and removes the |
| 18 | +event loop integration with the Device ChipStack/ChipDeviceController. |
| 19 | +--- |
| 20 | + src/controller/python/chip/ChipBluezMgr.py | 1 - |
| 21 | + src/controller/python/chip/ChipCoreBluetoothMgr.py | 2 -- |
| 22 | + src/controller/python/chip/ChipDeviceCtrl.py | 5 ----- |
| 23 | + src/controller/python/chip/ChipStack.py | 8 +------- |
| 24 | + 4 files changed, 1 insertion(+), 15 deletions(-) |
| 25 | + |
| 26 | +diff --git a/src/controller/python/chip/ChipBluezMgr.py b/src/controller/python/chip/ChipBluezMgr.py |
| 27 | +index e480750b60..bacf383710 100644 |
| 28 | +--- a/src/controller/python/chip/ChipBluezMgr.py |
| 29 | ++++ b/src/controller/python/chip/ChipBluezMgr.py |
| 30 | +@@ -807,7 +807,6 @@ class BluezManager(ChipBleBase): |
| 31 | + self.rx = None |
| 32 | + self.setInputHook(self.readlineCB) |
| 33 | + self.devMgr = devMgr |
| 34 | +- self.devMgr.SetBlockingCB(self.devMgrCB) |
| 35 | + |
| 36 | + def __del__(self): |
| 37 | + self.disconnect() |
| 38 | +diff --git a/src/controller/python/chip/ChipCoreBluetoothMgr.py b/src/controller/python/chip/ChipCoreBluetoothMgr.py |
| 39 | +index 3f792a5a4d..4a65f1e237 100644 |
| 40 | +--- a/src/controller/python/chip/ChipCoreBluetoothMgr.py |
| 41 | ++++ b/src/controller/python/chip/ChipCoreBluetoothMgr.py |
| 42 | +@@ -184,8 +184,6 @@ class CoreBluetoothManager(ChipBleBase): |
| 43 | + def __del__(self): |
| 44 | + self.disconnect() |
| 45 | + self.setInputHook(self.orig_input_hook) |
| 46 | +- self.devCtrl.SetBlockingCB(None) |
| 47 | +- self.devCtrl.SetBleEventCB(None) |
| 48 | + |
| 49 | + def devMgrCB(self): |
| 50 | + """A callback used by ChipDeviceCtrl.py to drive the OSX runloop while the |
| 51 | +diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py |
| 52 | +index 1d1627c46d..acbbc88b3e 100644 |
| 53 | +--- a/src/controller/python/chip/ChipDeviceCtrl.py |
| 54 | ++++ b/src/controller/python/chip/ChipDeviceCtrl.py |
| 55 | +@@ -1461,11 +1461,6 @@ class ChipDeviceControllerBase(): |
| 56 | + else: |
| 57 | + return res.events |
| 58 | + |
| 59 | +- def SetBlockingCB(self, blockingCB): |
| 60 | +- self.CheckIsActive() |
| 61 | +- |
| 62 | +- self._ChipStack.blockingCB = blockingCB |
| 63 | +- |
| 64 | + def SetIpk(self, ipk: bytes): |
| 65 | + self._ChipStack.Call( |
| 66 | + lambda: self._dmLib.pychip_DeviceController_SetIpk(self.devCtrl, ipk, len(ipk)) |
| 67 | +diff --git a/src/controller/python/chip/ChipStack.py b/src/controller/python/chip/ChipStack.py |
| 68 | +index b47c463982..5fd0601ba2 100644 |
| 69 | +--- a/src/controller/python/chip/ChipStack.py |
| 70 | ++++ b/src/controller/python/chip/ChipStack.py |
| 71 | +@@ -165,8 +165,6 @@ class ChipStack(object): |
| 72 | + callback() |
| 73 | + |
| 74 | + self.cbHandleChipThreadRun = HandleChipThreadRun |
| 75 | +- # set by other modules(BLE) that require service by thread while thread blocks. |
| 76 | +- self.blockingCB = None |
| 77 | + |
| 78 | + # |
| 79 | + # Storage has to be initialized BEFORE initializing the stack, since the latter |
| 80 | +@@ -255,11 +253,7 @@ class ChipStack(object): |
| 81 | + if not res.is_success: |
| 82 | + self.completeEvent.set() |
| 83 | + raise res.to_exception() |
| 84 | +- while not self.completeEvent.isSet(): |
| 85 | +- if self.blockingCB: |
| 86 | +- self.blockingCB() |
| 87 | +- |
| 88 | +- self.completeEvent.wait(0.05) |
| 89 | ++ self.completeEvent.wait() |
| 90 | + if isinstance(self.callbackRes, ChipStackException): |
| 91 | + raise self.callbackRes |
| 92 | + return self.callbackRes |
| 93 | +-- |
| 94 | +2.45.2 |
| 95 | + |
0 commit comments