Skip to content

Commit 94d1ad8

Browse files
committed
Add two more patches
- [Python] Remove Python Bluetooth and ChipStack event loop integration - [Python] Add TriggerResubscribeIfScheduled to SubscriptionTransaction
1 parent eec94fe commit 94d1ad8

2 files changed

+149
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
From 9e3eeeaf21a3a258ea6d068f8ade8c321b7b5563 Mon Sep 17 00:00:00 2001
2+
From: Stefan Agner <stefan@agner.ch>
3+
Date: Fri, 7 Jun 2024 15:50:34 +0200
4+
Subject: [PATCH] [Python] Add TriggerResubscribeIfScheduled to
5+
SubscriptionTransaction (#33774)
6+
7+
Add TriggerResubscribeIfScheduled to SubscriptionTransaction. If the
8+
ReadClient currently has a resubscription attempt scheduled, This
9+
function allows to trigger that attempt immediately. This is useful
10+
when the server side is up and communicating, and it's a good time to
11+
try to resubscribe.
12+
---
13+
src/controller/python/chip/clusters/Attribute.py | 7 +++++++
14+
src/controller/python/chip/clusters/attribute.cpp | 6 ++++++
15+
2 files changed, 13 insertions(+)
16+
17+
diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py
18+
index 51389e19a1..838936e83b 100644
19+
--- a/src/controller/python/chip/clusters/Attribute.py
20+
+++ b/src/controller/python/chip/clusters/Attribute.py
21+
@@ -478,6 +478,13 @@ class SubscriptionTransaction:
22+
lambda: handle.pychip_ReadClient_OverrideLivenessTimeout(self._readTransaction._pReadClient, timeoutMs)
23+
)
24+
25+
+ async def TriggerResubscribeIfScheduled(self, reason: str):
26+
+ handle = chip.native.GetLibraryHandle()
27+
+ await builtins.chipStack.CallAsync(
28+
+ lambda: handle.pychip_ReadClient_TriggerResubscribeIfScheduled(
29+
+ self._readTransaction._pReadClient, reason.encode("utf-8"))
30+
+ )
31+
+
32+
def GetReportingIntervalsSeconds(self) -> Tuple[int, int]:
33+
'''
34+
Retrieve the reporting intervals associated with an active subscription.
35+
diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp
36+
index b73b4a49b4..7c5b2c906a 100644
37+
--- a/src/controller/python/chip/clusters/attribute.cpp
38+
+++ b/src/controller/python/chip/clusters/attribute.cpp
39+
@@ -464,6 +464,12 @@ void pychip_ReadClient_OverrideLivenessTimeout(ReadClient * pReadClient, uint32_
40+
pReadClient->OverrideLivenessTimeout(System::Clock::Milliseconds32(livenessTimeoutMs));
41+
}
42+
43+
+void pychip_ReadClient_TriggerResubscribeIfScheduled(ReadClient * pReadClient, const char * reason)
44+
+{
45+
+ VerifyOrDie(pReadClient != nullptr);
46+
+ pReadClient->TriggerResubscribeIfScheduled(reason);
47+
+}
48+
+
49+
PyChipError pychip_ReadClient_GetReportingIntervals(ReadClient * pReadClient, uint16_t * minIntervalSec, uint16_t * maxIntervalSec)
50+
{
51+
VerifyOrDie(pReadClient != nullptr);
52+
--
53+
2.45.2
54+

0 commit comments

Comments
 (0)