Skip to content

Commit dad552e

Browse files
committed
Rename CallAsyncWithCallback to CallAsyncWithCompleteCallback
Also add a comment that the function needs to be released by registering a callback and setting the complete event.
1 parent 098d673 commit dad552e

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(self, deviceProxy: ctypes.c_void_p, dmLib=None):
186186
def __del__(self):
187187
if (self._dmLib is not None and hasattr(builtins, 'chipStack') and builtins.chipStack is not None):
188188
# This destructor is called from any threading context, including on the Matter threading context.
189-
# So, we cannot call chipStack.Call or chipStack.CallAsyncWithCallback which waits for the posted work to
189+
# So, we cannot call chipStack.Call or chipStack.CallAsyncWithCompleteCallback which waits for the posted work to
190190
# actually be executed. Instead, we just post/schedule the work and move on.
191191
builtins.chipStack.PostTaskOnChipThread(lambda: self._dmLib.pychip_FreeOperationalDeviceProxy(self._deviceProxy))
192192

@@ -447,7 +447,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError:
447447

448448
self.state = DCState.COMMISSIONING
449449
self._enablePairingCompeleteCallback(True)
450-
self._ChipStack.CallAsyncWithCallback(
450+
self._ChipStack.CallAsyncWithCompleteCallback(
451451
lambda: self._dmLib.pychip_DeviceController_ConnectBLE(
452452
self.devCtrl, discriminator, setupPinCode, nodeid)
453453
).raise_on_error()
@@ -459,7 +459,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError:
459459
def UnpairDevice(self, nodeid: int):
460460
self.CheckIsActive()
461461

462-
return self._ChipStack.CallAsyncWithCallback(
462+
return self._ChipStack.CallAsyncWithCompleteCallback(
463463
lambda: self._dmLib.pychip_DeviceController_UnpairDevice(
464464
self.devCtrl, nodeid, self.cbHandleDeviceUnpairCompleteFunct)
465465
).raise_on_error()
@@ -498,7 +498,7 @@ def EstablishPASESessionBLE(self, setupPinCode: int, discriminator: int, nodeid:
498498

499499
self.state = DCState.RENDEZVOUS_ONGOING
500500
self._enablePairingCompeleteCallback(True)
501-
return self._ChipStack.CallAsyncWithCallback(
501+
return self._ChipStack.CallAsyncWithCompleteCallback(
502502
lambda: self._dmLib.pychip_DeviceController_EstablishPASESessionBLE(
503503
self.devCtrl, setupPinCode, discriminator, nodeid)
504504
)
@@ -508,7 +508,7 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
508508

509509
self.state = DCState.RENDEZVOUS_ONGOING
510510
self._enablePairingCompeleteCallback(True)
511-
return self._ChipStack.CallAsyncWithCallback(
511+
return self._ChipStack.CallAsyncWithCompleteCallback(
512512
lambda: self._dmLib.pychip_DeviceController_EstablishPASESessionIP(
513513
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid, port)
514514
)
@@ -518,7 +518,7 @@ def EstablishPASESession(self, setUpCode: str, nodeid: int):
518518

519519
self.state = DCState.RENDEZVOUS_ONGOING
520520
self._enablePairingCompeleteCallback(True)
521-
return self._ChipStack.CallAsyncWithCallback(
521+
return self._ChipStack.CallAsyncWithCompleteCallback(
522522
lambda: self._dmLib.pychip_DeviceController_EstablishPASESession(
523523
self.devCtrl, setUpCode.encode("utf-8"), nodeid)
524524
)
@@ -737,7 +737,7 @@ def OpenCommissioningWindow(self, nodeid: int, timeout: int, iteration: int,
737737
Returns CommissioningParameters
738738
'''
739739
self.CheckIsActive()
740-
self._ChipStack.CallAsyncWithCallback(
740+
self._ChipStack.CallAsyncWithCompleteCallback(
741741
lambda: self._dmLib.pychip_DeviceController_OpenCommissioningWindow(
742742
self.devCtrl, self.pairingDelegate, nodeid, timeout, iteration, discriminator, option)
743743
).raise_on_error()
@@ -1898,7 +1898,7 @@ def Commission(self, nodeid) -> PyChipError:
18981898
self._ChipStack.commissioningCompleteEvent.clear()
18991899
self.state = DCState.COMMISSIONING
19001900

1901-
self._ChipStack.CallAsyncWithCallback(
1901+
self._ChipStack.CallAsyncWithCompleteCallback(
19021902
lambda: self._dmLib.pychip_DeviceController_Commission(
19031903
self.devCtrl, nodeid)
19041904
)
@@ -2014,7 +2014,7 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
20142014
self._ChipStack.commissioningCompleteEvent.clear()
20152015

20162016
self._enablePairingCompeleteCallback(True)
2017-
self._ChipStack.CallAsyncWithCallback(
2017+
self._ChipStack.CallAsyncWithCompleteCallback(
20182018
lambda: self._dmLib.pychip_DeviceController_OnNetworkCommission(
20192019
self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") + b"\x00" if filter is not None else None, discoveryTimeoutMsec)
20202020
)
@@ -2038,7 +2038,7 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
20382038
self._ChipStack.commissioningCompleteEvent.clear()
20392039

20402040
self._enablePairingCompeleteCallback(True)
2041-
self._ChipStack.CallAsyncWithCallback(
2041+
self._ChipStack.CallAsyncWithCompleteCallback(
20422042
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
20432043
self.devCtrl, setupPayload, nodeid, discoveryType.value)
20442044
)
@@ -2058,7 +2058,7 @@ def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> PyChipErr
20582058
self._ChipStack.commissioningCompleteEvent.clear()
20592059

20602060
self._enablePairingCompeleteCallback(True)
2061-
self._ChipStack.CallAsyncWithCallback(
2061+
self._ChipStack.CallAsyncWithCompleteCallback(
20622062
lambda: self._dmLib.pychip_DeviceController_ConnectIP(
20632063
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid)
20642064
)
@@ -2072,7 +2072,7 @@ def IssueNOCChain(self, csr: Clusters.OperationalCredentials.Commands.CSRRespons
20722072
The NOC chain will be provided in TLV cert format."""
20732073
self.CheckIsActive()
20742074

2075-
return self._ChipStack.CallAsyncWithCallback(
2075+
return self._ChipStack.CallAsyncWithCompleteCallback(
20762076
lambda: self._dmLib.pychip_DeviceController_IssueNOCChain(
20772077
self.devCtrl, py_object(self), csr.NOCSRElements, len(csr.NOCSRElements), nodeId)
20782078
)

src/controller/python/chip/ChipStack.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,11 @@ async def CallAsync(self, callFunct, timeoutMs: int = None):
413413

414414
return await asyncio.wait_for(callObj.future, timeoutMs / 1000 if timeoutMs else None)
415415

416-
def CallAsyncWithCallback(self, callFunct):
416+
def CallAsyncWithCompleteCallback(self, callFunct):
417417
'''Run a Python function on CHIP stack, and wait for the application specific response.
418418
This function is a wrapper of PostTaskOnChipThread, which includes some handling of application specific logics.
419419
Calling this function on CHIP on CHIP mainloop thread will cause deadlock.
420+
Make sure to register the necessary callbacks which release the function by setting the completeEvent.
420421
'''
421422
# throw error if op in progress
422423
self.callbackRes = None

0 commit comments

Comments
 (0)