Skip to content

Commit

Permalink
Adds handleNotifySubscriptionStillActive to AsyncReadTransaction, tem…
Browse files Browse the repository at this point in the history
…porary debug logging
  • Loading branch information
raul-marquez-csa committed May 23, 2024
1 parent 985e53a commit 3900053
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/app/BufferedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class BufferedReadCallback : public ReadClient::Callback
//
void OnReportBegin() override;
void OnReportEnd() override;
void NotifySubscriptionStillActive(const ReadClient & apReadClient) override
{
mCallback.NotifySubscriptionStillActive(apReadClient);
}
void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override;
void OnError(CHIP_ERROR aError) override
{
Expand Down
193 changes: 185 additions & 8 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,12 +680,52 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool
self._pReadClient = None
self._pReadCallback = None
self._resultError = None

print("\n\n\n")
print(f"AsyncReadTransaction - __init__")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

def SetClientObjPointers(self, pReadClient, pReadCallback):
self._pReadClient = pReadClient
self._pReadCallback = pReadCallback
print("\n\n\n")
print(f"AsyncReadTransaction - SetClientObjPointers")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

def GetAllEventValues(self):
print("\n\n\n")
print(f"AsyncReadTransaction - GetAllEventValues")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")
return self._events

def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int, status: int, data: bytes):
Expand All @@ -702,6 +742,20 @@ def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int
self._cache.UpdateTLV(path, dataVersion, attributeValue)
self._changedPathSet.add(path)

print("\n\n\n")
print(f"AsyncReadTransaction - handleAttributeData")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

except Exception as ex:
logging.exception(ex)

Expand Down Expand Up @@ -742,11 +796,39 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta
self._subscription_handler.OnEventChangeCb(
eventResult, self._subscription_handler)

print("\n\n\n")
print(f"AsyncReadTransaction - handleEventData")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

except Exception as ex:
logging.exception(ex)

def handleError(self, chipError: PyChipError):
self._resultError = chipError.code

print("\n\n\n")
print(f"AsyncReadTransaction - handleError")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

def _handleSubscriptionEstablished(self, subscriptionId):
if not self._future.done():
Expand All @@ -762,6 +844,20 @@ def _handleSubscriptionEstablished(self, subscriptionId):
else:
self._subscription_handler._onResubscriptionSucceededCb(self._subscription_handler)

print("\n\n\n")
print(f"AsyncReadTransaction - _handleSubscriptionEstablished")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

def handleSubscriptionEstablished(self, subscriptionId):
self._event_loop.call_soon_threadsafe(
self._handleSubscriptionEstablished, subscriptionId)
Expand All @@ -777,11 +873,52 @@ def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResub
self._subscription_handler._onResubscriptionAttemptedCb,
self._subscription_handler, terminationCause.code, nextResubscribeIntervalMsec)

print("\n\n\n")
print(f"AsyncReadTransaction - handleResubscriptionAttempted")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

def _handleReportBegin(self):
print("\n\n\n")
print(f"AsyncReadTransaction - _handleReportBegin")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")
pass

def _handleReportEnd(self):
def _handleReportEnd(self):
self._cache.UpdateCachedData(self._changedPathSet)

print("\n\n\n")
print(f"AsyncReadTransaction - _handleReportEnd")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

if (self._subscription_handler is not None):
for change in self._changedPathSet:
Expand Down Expand Up @@ -813,6 +950,20 @@ def _handleDone(self):
else:
self._future.set_result(AsyncReadTransaction.ReadResponse(
attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache))

print("\n\n\n")
print(f"AsyncReadTransaction - _handleDone")
print(f"self._event_loop: {self._event_loop}")
print(f"self._future: {self._future}")
print(f"self._subscription_handler: {self._subscription_handler}")
print(f"self._events: {self._events}")
print(f"self._devCtrl: {self._devCtrl}")
print(f"self._cache: {self._cache}")
print(f"self._changedPathSet: {self._changedPathSet}")
print(f"self._pReadClient: {self._pReadClient}")
print(f"self._pReadCallback: {self._pReadCallback}")
print(f"self._resultError: {self._resultError}")
print("\n\n\n")

#
# Decrement the ref on ourselves to match the increment that happened at allocation.
Expand All @@ -823,14 +974,33 @@ def _handleDone(self):

def handleDone(self):
self._event_loop.call_soon_threadsafe(self._handleDone)

def handleReportBegin(self):
pass

self._handleReportBegin()
def handleReportEnd(self):
# self._event_loop.call_soon_threadsafe(self._handleReportEnd)
self._handleReportEnd()

def _handleNotifySubscriptionStillActive(self):
pass

def handleNotifySubscriptionStillActive(self):
print("\n\n\n\n\n\n\n\n\n\n\n")
print(f"closure.handleNotifySubscriptionStillActive")
print(f"\t\tAsyncReadTransaction - _handleReportBegin")
print(f"\t\tself._event_loop: {self._event_loop}")
print(f"\t\tself._future: {self._future}")
print(f"\t\tself._subscription_handler: {self._subscription_handler}")
print(f"\t\tself._events: {self._events}")
print(f"\t\tself._devCtrl: {self._devCtrl}")
print(f"\t\tself._cache: {self._cache}")
print(f"\t\tself._changedPathSet: {self._changedPathSet}")
print(f"\t\tself._pReadClient: {self._pReadClient}")
print(f"\t\tself._pReadCallback: {self._pReadCallback}")
print(f"\t\tself._resultError: {self._resultError}")
print("\n\n\n\n\n\n\n\n\n\n\n")
self._handleNotifySubscriptionStillActive()


class AsyncWriteTransaction:
def __init__(self, future: Future, eventLoop):
Expand Down Expand Up @@ -889,7 +1059,8 @@ def handleDone(self):
None, py_object)
_OnReportEndCallbackFunct = CFUNCTYPE(
None, py_object)

_OnNotifySubscriptionStillActiveCallbackFunct = CFUNCTYPE(
None, py_object)

@_OnReadAttributeDataCallbackFunct
def _OnReadAttributeDataCallback(closure, dataVersion: int, endpoint: int, cluster: int, attribute: int, status, data, len):
Expand Down Expand Up @@ -937,6 +1108,11 @@ def _OnReportEndCallback(closure):
closure.handleReportEnd()


@_OnNotifySubscriptionStillActiveCallbackFunct
def _OnNotifySubscriptionStillActiveCallback(closure):
closure.handleNotifySubscriptionStillActive()


@_OnReadDoneCallbackFunct
def _OnReadDoneCallback(closure):
closure.handleDone()
Expand Down Expand Up @@ -1208,14 +1384,15 @@ def Init():
_OnReadAttributeDataCallbackFunct, _OnReadEventDataCallbackFunct,
_OnSubscriptionEstablishedCallbackFunct, _OnResubscriptionAttemptedCallbackFunct,
_OnReadErrorCallbackFunct, _OnReadDoneCallbackFunct,
_OnReportBeginCallbackFunct, _OnReportEndCallbackFunct])
_OnReportBeginCallbackFunct, _OnReportEndCallbackFunct,
_OnNotifySubscriptionStillActiveCallbackFunct])

handle.pychip_WriteClient_InitCallbacks(
_OnWriteResponseCallback, _OnWriteErrorCallback, _OnWriteDoneCallback)
handle.pychip_ReadClient_InitCallbacks(
_OnReadAttributeDataCallback, _OnReadEventDataCallback,
_OnSubscriptionEstablishedCallback, _OnResubscriptionAttemptedCallback, _OnReadErrorCallback, _OnReadDoneCallback,
_OnReportBeginCallback, _OnReportEndCallback)
_OnReportBeginCallback, _OnReportEndCallback, _OnNotifySubscriptionStillActiveCallback)

_BuildAttributeIndex()
_BuildClusterIndex()
Expand Down
27 changes: 18 additions & 9 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ using OnReadErrorCallback = void (*)(PyObject * appContext, PyChip
using OnReadDoneCallback = void (*)(PyObject * appContext);
using OnReportBeginCallback = void (*)(PyObject * appContext);
using OnReportEndCallback = void (*)(PyObject * appContext);
using OnNotifySubscriptionStillActiveCallback = void (*)(PyObject * appContext);

OnReadAttributeDataCallback gOnReadAttributeDataCallback = nullptr;
OnReadEventDataCallback gOnReadEventDataCallback = nullptr;
Expand All @@ -92,6 +93,7 @@ OnReadErrorCallback gOnReadErrorCallback = nullptr;
OnReadDoneCallback gOnReadDoneCallback = nullptr;
OnReportBeginCallback gOnReportBeginCallback = nullptr;
OnReportBeginCallback gOnReportEndCallback = nullptr;
OnNotifySubscriptionStillActiveCallback gOnNotifySubscriptionStillActiveCallback = nullptr;

void PythonResubscribePolicy(uint32_t aNumCumulativeRetries, uint32_t & aNextSubscriptionIntervalMsec, bool & aShouldResubscribe)
{
Expand Down Expand Up @@ -225,6 +227,11 @@ class ReadClientCallback : public ReadClient::Callback

void OnReportEnd() override { gOnReportEndCallback(mAppContext); }

void NotifySubscriptionStillActive(const ReadClient & apReadClient) override
{
gOnNotifySubscriptionStillActiveCallback(mAppContext);
}

void OnDone(ReadClient *) override
{
gOnReadDoneCallback(mAppContext);
Expand Down Expand Up @@ -326,16 +333,18 @@ void pychip_ReadClient_InitCallbacks(OnReadAttributeDataCallback onReadAttribute
OnSubscriptionEstablishedCallback onSubscriptionEstablishedCallback,
OnResubscriptionAttemptedCallback onResubscriptionAttemptedCallback,
OnReadErrorCallback onReadErrorCallback, OnReadDoneCallback onReadDoneCallback,
OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback)
OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback,
OnNotifySubscriptionStillActiveCallback onNotifySubscriptionStillActiveCallback)
{
gOnReadAttributeDataCallback = onReadAttributeDataCallback;
gOnReadEventDataCallback = onReadEventDataCallback;
gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback;
gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback;
gOnReadErrorCallback = onReadErrorCallback;
gOnReadDoneCallback = onReadDoneCallback;
gOnReportBeginCallback = onReportBeginCallback;
gOnReportEndCallback = onReportEndCallback;
gOnReadAttributeDataCallback = onReadAttributeDataCallback;
gOnReadEventDataCallback = onReadEventDataCallback;
gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback;
gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback;
gOnReadErrorCallback = onReadErrorCallback;
gOnReadDoneCallback = onReadDoneCallback;
gOnReportBeginCallback = onReportBeginCallback;
gOnReportEndCallback = onReportEndCallback;
gOnNotifySubscriptionStillActiveCallback = onNotifySubscriptionStillActiveCallback;
}

PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy * device, size_t timedWriteTimeoutMsSizeT,
Expand Down
8 changes: 4 additions & 4 deletions src/python_testing/TC_IDM_4_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ async def test_TC_IDM_4_3(self):



# secs = 60
# print(f"\n\n\n\n\nTime to sleep {secs} second(s)")
# time.sleep(secs)
# print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")
secs = 60
print(f"\n\n\n\n\nTime to sleep {secs} second(s)")
time.sleep(secs)
print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")



Expand Down

0 comments on commit 3900053

Please sign in to comment.