Skip to content

Commit d99cf8e

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 d99cf8e

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/controller/python/chip/ChipStack.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import os
3333
import sys
3434
import time
35-
from ctypes import (CFUNCTYPE, POINTER, Structure, c_bool, c_char_p, c_int64, c_uint8, c_uint16, c_uint32, c_ulong, c_void_p,
36-
py_object, pythonapi)
35+
from ctypes import CFUNCTYPE, Structure, c_bool, c_char_p, c_int64, c_uint8, c_uint16, c_uint32, c_void_p, py_object, pythonapi
3736
from threading import Condition, Event, Lock
3837

3938
import chip.native
@@ -194,9 +193,6 @@ def __call__(self):
194193
pythonapi.Py_DecRef(py_object(self))
195194

196195

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))
200196
_LogMessageFunct = CFUNCTYPE(
201197
None, c_int64, c_int64, c_char_p, c_uint8, c_char_p)
202198
_ChipThreadTaskRunnerFunct = CFUNCTYPE(None, py_object)
@@ -272,21 +268,11 @@ def __init__(self, persistentStoragePath: str, installDefaultLogHandler=True,
272268
self.logger.addHandler(logHandler)
273269
self.logger.setLevel(logging.DEBUG)
274270

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-
283271
@_ChipThreadTaskRunnerFunct
284272
def HandleChipThreadRun(callback):
285273
callback()
286274

287275
self.cbHandleChipThreadRun = HandleChipThreadRun
288-
self.cbHandleComplete = _CompleteFunct(HandleComplete)
289-
self.cbHandleError = _ErrorFunct(HandleError)
290276
# set by other modules(BLE) that require service by thread while thread blocks.
291277
self.blockingCB = None
292278

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

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

0 commit comments

Comments
 (0)