Skip to content

Commit 3900053

Browse files
Adds handleNotifySubscriptionStillActive to AsyncReadTransaction, temporary debug logging
1 parent 985e53a commit 3900053

File tree

4 files changed

+211
-21
lines changed

4 files changed

+211
-21
lines changed

src/app/BufferedReadCallback.h

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class BufferedReadCallback : public ReadClient::Callback
7070
//
7171
void OnReportBegin() override;
7272
void OnReportEnd() override;
73+
void NotifySubscriptionStillActive(const ReadClient & apReadClient) override
74+
{
75+
mCallback.NotifySubscriptionStillActive(apReadClient);
76+
}
7377
void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override;
7478
void OnError(CHIP_ERROR aError) override
7579
{

src/controller/python/chip/clusters/Attribute.py

+185-8
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,52 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool
680680
self._pReadClient = None
681681
self._pReadCallback = None
682682
self._resultError = None
683+
684+
print("\n\n\n")
685+
print(f"AsyncReadTransaction - __init__")
686+
print(f"self._event_loop: {self._event_loop}")
687+
print(f"self._future: {self._future}")
688+
print(f"self._subscription_handler: {self._subscription_handler}")
689+
print(f"self._events: {self._events}")
690+
print(f"self._devCtrl: {self._devCtrl}")
691+
print(f"self._cache: {self._cache}")
692+
print(f"self._changedPathSet: {self._changedPathSet}")
693+
print(f"self._pReadClient: {self._pReadClient}")
694+
print(f"self._pReadCallback: {self._pReadCallback}")
695+
print(f"self._resultError: {self._resultError}")
696+
print("\n\n\n")
683697

684698
def SetClientObjPointers(self, pReadClient, pReadCallback):
685699
self._pReadClient = pReadClient
686700
self._pReadCallback = pReadCallback
701+
print("\n\n\n")
702+
print(f"AsyncReadTransaction - SetClientObjPointers")
703+
print(f"self._event_loop: {self._event_loop}")
704+
print(f"self._future: {self._future}")
705+
print(f"self._subscription_handler: {self._subscription_handler}")
706+
print(f"self._events: {self._events}")
707+
print(f"self._devCtrl: {self._devCtrl}")
708+
print(f"self._cache: {self._cache}")
709+
print(f"self._changedPathSet: {self._changedPathSet}")
710+
print(f"self._pReadClient: {self._pReadClient}")
711+
print(f"self._pReadCallback: {self._pReadCallback}")
712+
print(f"self._resultError: {self._resultError}")
713+
print("\n\n\n")
687714

688715
def GetAllEventValues(self):
716+
print("\n\n\n")
717+
print(f"AsyncReadTransaction - GetAllEventValues")
718+
print(f"self._event_loop: {self._event_loop}")
719+
print(f"self._future: {self._future}")
720+
print(f"self._subscription_handler: {self._subscription_handler}")
721+
print(f"self._events: {self._events}")
722+
print(f"self._devCtrl: {self._devCtrl}")
723+
print(f"self._cache: {self._cache}")
724+
print(f"self._changedPathSet: {self._changedPathSet}")
725+
print(f"self._pReadClient: {self._pReadClient}")
726+
print(f"self._pReadCallback: {self._pReadCallback}")
727+
print(f"self._resultError: {self._resultError}")
728+
print("\n\n\n")
689729
return self._events
690730

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

745+
print("\n\n\n")
746+
print(f"AsyncReadTransaction - handleAttributeData")
747+
print(f"self._event_loop: {self._event_loop}")
748+
print(f"self._future: {self._future}")
749+
print(f"self._subscription_handler: {self._subscription_handler}")
750+
print(f"self._events: {self._events}")
751+
print(f"self._devCtrl: {self._devCtrl}")
752+
print(f"self._cache: {self._cache}")
753+
print(f"self._changedPathSet: {self._changedPathSet}")
754+
print(f"self._pReadClient: {self._pReadClient}")
755+
print(f"self._pReadCallback: {self._pReadCallback}")
756+
print(f"self._resultError: {self._resultError}")
757+
print("\n\n\n")
758+
705759
except Exception as ex:
706760
logging.exception(ex)
707761

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

799+
print("\n\n\n")
800+
print(f"AsyncReadTransaction - handleEventData")
801+
print(f"self._event_loop: {self._event_loop}")
802+
print(f"self._future: {self._future}")
803+
print(f"self._subscription_handler: {self._subscription_handler}")
804+
print(f"self._events: {self._events}")
805+
print(f"self._devCtrl: {self._devCtrl}")
806+
print(f"self._cache: {self._cache}")
807+
print(f"self._changedPathSet: {self._changedPathSet}")
808+
print(f"self._pReadClient: {self._pReadClient}")
809+
print(f"self._pReadCallback: {self._pReadCallback}")
810+
print(f"self._resultError: {self._resultError}")
811+
print("\n\n\n")
812+
745813
except Exception as ex:
746814
logging.exception(ex)
747815

748816
def handleError(self, chipError: PyChipError):
749817
self._resultError = chipError.code
818+
819+
print("\n\n\n")
820+
print(f"AsyncReadTransaction - handleError")
821+
print(f"self._event_loop: {self._event_loop}")
822+
print(f"self._future: {self._future}")
823+
print(f"self._subscription_handler: {self._subscription_handler}")
824+
print(f"self._events: {self._events}")
825+
print(f"self._devCtrl: {self._devCtrl}")
826+
print(f"self._cache: {self._cache}")
827+
print(f"self._changedPathSet: {self._changedPathSet}")
828+
print(f"self._pReadClient: {self._pReadClient}")
829+
print(f"self._pReadCallback: {self._pReadCallback}")
830+
print(f"self._resultError: {self._resultError}")
831+
print("\n\n\n")
750832

751833
def _handleSubscriptionEstablished(self, subscriptionId):
752834
if not self._future.done():
@@ -762,6 +844,20 @@ def _handleSubscriptionEstablished(self, subscriptionId):
762844
else:
763845
self._subscription_handler._onResubscriptionSucceededCb(self._subscription_handler)
764846

847+
print("\n\n\n")
848+
print(f"AsyncReadTransaction - _handleSubscriptionEstablished")
849+
print(f"self._event_loop: {self._event_loop}")
850+
print(f"self._future: {self._future}")
851+
print(f"self._subscription_handler: {self._subscription_handler}")
852+
print(f"self._events: {self._events}")
853+
print(f"self._devCtrl: {self._devCtrl}")
854+
print(f"self._cache: {self._cache}")
855+
print(f"self._changedPathSet: {self._changedPathSet}")
856+
print(f"self._pReadClient: {self._pReadClient}")
857+
print(f"self._pReadCallback: {self._pReadCallback}")
858+
print(f"self._resultError: {self._resultError}")
859+
print("\n\n\n")
860+
765861
def handleSubscriptionEstablished(self, subscriptionId):
766862
self._event_loop.call_soon_threadsafe(
767863
self._handleSubscriptionEstablished, subscriptionId)
@@ -777,11 +873,52 @@ def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResub
777873
self._subscription_handler._onResubscriptionAttemptedCb,
778874
self._subscription_handler, terminationCause.code, nextResubscribeIntervalMsec)
779875

876+
print("\n\n\n")
877+
print(f"AsyncReadTransaction - handleResubscriptionAttempted")
878+
print(f"self._event_loop: {self._event_loop}")
879+
print(f"self._future: {self._future}")
880+
print(f"self._subscription_handler: {self._subscription_handler}")
881+
print(f"self._events: {self._events}")
882+
print(f"self._devCtrl: {self._devCtrl}")
883+
print(f"self._cache: {self._cache}")
884+
print(f"self._changedPathSet: {self._changedPathSet}")
885+
print(f"self._pReadClient: {self._pReadClient}")
886+
print(f"self._pReadCallback: {self._pReadCallback}")
887+
print(f"self._resultError: {self._resultError}")
888+
print("\n\n\n")
889+
780890
def _handleReportBegin(self):
891+
print("\n\n\n")
892+
print(f"AsyncReadTransaction - _handleReportBegin")
893+
print(f"self._event_loop: {self._event_loop}")
894+
print(f"self._future: {self._future}")
895+
print(f"self._subscription_handler: {self._subscription_handler}")
896+
print(f"self._events: {self._events}")
897+
print(f"self._devCtrl: {self._devCtrl}")
898+
print(f"self._cache: {self._cache}")
899+
print(f"self._changedPathSet: {self._changedPathSet}")
900+
print(f"self._pReadClient: {self._pReadClient}")
901+
print(f"self._pReadCallback: {self._pReadCallback}")
902+
print(f"self._resultError: {self._resultError}")
903+
print("\n\n\n")
781904
pass
782905

783-
def _handleReportEnd(self):
906+
def _handleReportEnd(self):
784907
self._cache.UpdateCachedData(self._changedPathSet)
908+
909+
print("\n\n\n")
910+
print(f"AsyncReadTransaction - _handleReportEnd")
911+
print(f"self._event_loop: {self._event_loop}")
912+
print(f"self._future: {self._future}")
913+
print(f"self._subscription_handler: {self._subscription_handler}")
914+
print(f"self._events: {self._events}")
915+
print(f"self._devCtrl: {self._devCtrl}")
916+
print(f"self._cache: {self._cache}")
917+
print(f"self._changedPathSet: {self._changedPathSet}")
918+
print(f"self._pReadClient: {self._pReadClient}")
919+
print(f"self._pReadCallback: {self._pReadCallback}")
920+
print(f"self._resultError: {self._resultError}")
921+
print("\n\n\n")
785922

786923
if (self._subscription_handler is not None):
787924
for change in self._changedPathSet:
@@ -813,6 +950,20 @@ def _handleDone(self):
813950
else:
814951
self._future.set_result(AsyncReadTransaction.ReadResponse(
815952
attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache))
953+
954+
print("\n\n\n")
955+
print(f"AsyncReadTransaction - _handleDone")
956+
print(f"self._event_loop: {self._event_loop}")
957+
print(f"self._future: {self._future}")
958+
print(f"self._subscription_handler: {self._subscription_handler}")
959+
print(f"self._events: {self._events}")
960+
print(f"self._devCtrl: {self._devCtrl}")
961+
print(f"self._cache: {self._cache}")
962+
print(f"self._changedPathSet: {self._changedPathSet}")
963+
print(f"self._pReadClient: {self._pReadClient}")
964+
print(f"self._pReadCallback: {self._pReadCallback}")
965+
print(f"self._resultError: {self._resultError}")
966+
print("\n\n\n")
816967

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

824975
def handleDone(self):
825976
self._event_loop.call_soon_threadsafe(self._handleDone)
826-
977+
827978
def handleReportBegin(self):
828-
pass
829-
979+
self._handleReportBegin()
980+
830981
def handleReportEnd(self):
831-
# self._event_loop.call_soon_threadsafe(self._handleReportEnd)
832982
self._handleReportEnd()
833983

984+
def _handleNotifySubscriptionStillActive(self):
985+
pass
986+
987+
def handleNotifySubscriptionStillActive(self):
988+
print("\n\n\n\n\n\n\n\n\n\n\n")
989+
print(f"closure.handleNotifySubscriptionStillActive")
990+
print(f"\t\tAsyncReadTransaction - _handleReportBegin")
991+
print(f"\t\tself._event_loop: {self._event_loop}")
992+
print(f"\t\tself._future: {self._future}")
993+
print(f"\t\tself._subscription_handler: {self._subscription_handler}")
994+
print(f"\t\tself._events: {self._events}")
995+
print(f"\t\tself._devCtrl: {self._devCtrl}")
996+
print(f"\t\tself._cache: {self._cache}")
997+
print(f"\t\tself._changedPathSet: {self._changedPathSet}")
998+
print(f"\t\tself._pReadClient: {self._pReadClient}")
999+
print(f"\t\tself._pReadCallback: {self._pReadCallback}")
1000+
print(f"\t\tself._resultError: {self._resultError}")
1001+
print("\n\n\n\n\n\n\n\n\n\n\n")
1002+
self._handleNotifySubscriptionStillActive()
1003+
8341004

8351005
class AsyncWriteTransaction:
8361006
def __init__(self, future: Future, eventLoop):
@@ -889,7 +1059,8 @@ def handleDone(self):
8891059
None, py_object)
8901060
_OnReportEndCallbackFunct = CFUNCTYPE(
8911061
None, py_object)
892-
1062+
_OnNotifySubscriptionStillActiveCallbackFunct = CFUNCTYPE(
1063+
None, py_object)
8931064

8941065
@_OnReadAttributeDataCallbackFunct
8951066
def _OnReadAttributeDataCallback(closure, dataVersion: int, endpoint: int, cluster: int, attribute: int, status, data, len):
@@ -937,6 +1108,11 @@ def _OnReportEndCallback(closure):
9371108
closure.handleReportEnd()
9381109

9391110

1111+
@_OnNotifySubscriptionStillActiveCallbackFunct
1112+
def _OnNotifySubscriptionStillActiveCallback(closure):
1113+
closure.handleNotifySubscriptionStillActive()
1114+
1115+
9401116
@_OnReadDoneCallbackFunct
9411117
def _OnReadDoneCallback(closure):
9421118
closure.handleDone()
@@ -1208,14 +1384,15 @@ def Init():
12081384
_OnReadAttributeDataCallbackFunct, _OnReadEventDataCallbackFunct,
12091385
_OnSubscriptionEstablishedCallbackFunct, _OnResubscriptionAttemptedCallbackFunct,
12101386
_OnReadErrorCallbackFunct, _OnReadDoneCallbackFunct,
1211-
_OnReportBeginCallbackFunct, _OnReportEndCallbackFunct])
1387+
_OnReportBeginCallbackFunct, _OnReportEndCallbackFunct,
1388+
_OnNotifySubscriptionStillActiveCallbackFunct])
12121389

12131390
handle.pychip_WriteClient_InitCallbacks(
12141391
_OnWriteResponseCallback, _OnWriteErrorCallback, _OnWriteDoneCallback)
12151392
handle.pychip_ReadClient_InitCallbacks(
12161393
_OnReadAttributeDataCallback, _OnReadEventDataCallback,
12171394
_OnSubscriptionEstablishedCallback, _OnResubscriptionAttemptedCallback, _OnReadErrorCallback, _OnReadDoneCallback,
1218-
_OnReportBeginCallback, _OnReportEndCallback)
1395+
_OnReportBeginCallback, _OnReportEndCallback, _OnNotifySubscriptionStillActiveCallback)
12191396

12201397
_BuildAttributeIndex()
12211398
_BuildClusterIndex()

src/controller/python/chip/clusters/attribute.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ using OnReadErrorCallback = void (*)(PyObject * appContext, PyChip
8383
using OnReadDoneCallback = void (*)(PyObject * appContext);
8484
using OnReportBeginCallback = void (*)(PyObject * appContext);
8585
using OnReportEndCallback = void (*)(PyObject * appContext);
86+
using OnNotifySubscriptionStillActiveCallback = void (*)(PyObject * appContext);
8687

8788
OnReadAttributeDataCallback gOnReadAttributeDataCallback = nullptr;
8889
OnReadEventDataCallback gOnReadEventDataCallback = nullptr;
@@ -92,6 +93,7 @@ OnReadErrorCallback gOnReadErrorCallback = nullptr;
9293
OnReadDoneCallback gOnReadDoneCallback = nullptr;
9394
OnReportBeginCallback gOnReportBeginCallback = nullptr;
9495
OnReportBeginCallback gOnReportEndCallback = nullptr;
96+
OnNotifySubscriptionStillActiveCallback gOnNotifySubscriptionStillActiveCallback = nullptr;
9597

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

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

230+
void NotifySubscriptionStillActive(const ReadClient & apReadClient) override
231+
{
232+
gOnNotifySubscriptionStillActiveCallback(mAppContext);
233+
}
234+
228235
void OnDone(ReadClient *) override
229236
{
230237
gOnReadDoneCallback(mAppContext);
@@ -326,16 +333,18 @@ void pychip_ReadClient_InitCallbacks(OnReadAttributeDataCallback onReadAttribute
326333
OnSubscriptionEstablishedCallback onSubscriptionEstablishedCallback,
327334
OnResubscriptionAttemptedCallback onResubscriptionAttemptedCallback,
328335
OnReadErrorCallback onReadErrorCallback, OnReadDoneCallback onReadDoneCallback,
329-
OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback)
336+
OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback,
337+
OnNotifySubscriptionStillActiveCallback onNotifySubscriptionStillActiveCallback)
330338
{
331-
gOnReadAttributeDataCallback = onReadAttributeDataCallback;
332-
gOnReadEventDataCallback = onReadEventDataCallback;
333-
gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback;
334-
gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback;
335-
gOnReadErrorCallback = onReadErrorCallback;
336-
gOnReadDoneCallback = onReadDoneCallback;
337-
gOnReportBeginCallback = onReportBeginCallback;
338-
gOnReportEndCallback = onReportEndCallback;
339+
gOnReadAttributeDataCallback = onReadAttributeDataCallback;
340+
gOnReadEventDataCallback = onReadEventDataCallback;
341+
gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback;
342+
gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback;
343+
gOnReadErrorCallback = onReadErrorCallback;
344+
gOnReadDoneCallback = onReadDoneCallback;
345+
gOnReportBeginCallback = onReportBeginCallback;
346+
gOnReportEndCallback = onReportEndCallback;
347+
gOnNotifySubscriptionStillActiveCallback = onNotifySubscriptionStillActiveCallback;
339348
}
340349

341350
PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy * device, size_t timedWriteTimeoutMsSizeT,

src/python_testing/TC_IDM_4_3.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ async def test_TC_IDM_4_3(self):
115115

116116

117117

118-
# secs = 60
119-
# print(f"\n\n\n\n\nTime to sleep {secs} second(s)")
120-
# time.sleep(secs)
121-
# print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")
118+
secs = 60
119+
print(f"\n\n\n\n\nTime to sleep {secs} second(s)")
120+
time.sleep(secs)
121+
print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")
122122

123123

124124

0 commit comments

Comments
 (0)