Skip to content

Commit 07a9a8c

Browse files
committed
[Python] Remove obsolete callback handling
The Call() function currently still has some callback handling code the completeEvent and callbackRes variables. These are only used when callbacks are in play, like pychip_DeviceController_Commission or pychip_DeviceController_OpenCommissioningWindow. When calling these functions CallAsyncWithCompleteCallback() needs to be used (and is beeing used in all cases). In practice, on single threaded applications this is not a problem. However, when calling the SDK from multiple threads, then another Call() Might accidentally release a call to CallAsyncWithCompleteCallback() early.
1 parent 20b1457 commit 07a9a8c

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

src/controller/python/chip/ChipStack.py

-19
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ def __call__(self):
194194
pythonapi.Py_DecRef(py_object(self))
195195

196196

197-
_CompleteFunct = CFUNCTYPE(None, c_void_p, c_void_p)
198-
_ErrorFunct = CFUNCTYPE(None, c_void_p, c_void_p,
199-
c_ulong, POINTER(DeviceStatusStruct))
200197
_LogMessageFunct = CFUNCTYPE(
201198
None, c_int64, c_int64, c_char_p, c_uint8, c_char_p)
202199
_ChipThreadTaskRunnerFunct = CFUNCTYPE(None, py_object)
@@ -272,21 +269,11 @@ def __init__(self, persistentStoragePath: str, installDefaultLogHandler=True,
272269
self.logger.addHandler(logHandler)
273270
self.logger.setLevel(logging.DEBUG)
274271

275-
def HandleComplete(appState, reqState):
276-
self.callbackRes = True
277-
self.completeEvent.set()
278-
279-
def HandleError(appState, reqState, err, devStatusPtr):
280-
self.callbackRes = self.ErrorToException(err, devStatusPtr)
281-
self.completeEvent.set()
282-
283272
@_ChipThreadTaskRunnerFunct
284273
def HandleChipThreadRun(callback):
285274
callback()
286275

287276
self.cbHandleChipThreadRun = HandleChipThreadRun
288-
self.cbHandleComplete = _CompleteFunct(HandleComplete)
289-
self.cbHandleError = _ErrorFunct(HandleError)
290277
# set by other modules(BLE) that require service by thread while thread blocks.
291278
self.blockingCB = None
292279

@@ -389,15 +376,9 @@ def Call(self, callFunct, timeoutMs: int = None):
389376
This function is a wrapper of PostTaskOnChipThread, which includes some handling of application specific logics.
390377
Calling this function on CHIP on CHIP mainloop thread will cause deadlock.
391378
'''
392-
# throw error if op in progress
393-
self.callbackRes = None
394-
self.completeEvent.clear()
395379
# TODO: Lock probably no longer necessary, see https://github.com/project-chip/connectedhomeip/issues/33321.
396380
with self.networkLock:
397381
res = self.PostTaskOnChipThread(callFunct).Wait(timeoutMs)
398-
self.completeEvent.set()
399-
if res == 0 and self.callbackRes is not None:
400-
return self.callbackRes
401382
return res
402383

403384
async def CallAsync(self, callFunct, timeoutMs: int = None):

0 commit comments

Comments
 (0)