From eb677a817d61cb32d7c30599a5459774fef0f734 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Thu, 4 Apr 2024 10:48:43 +0200 Subject: [PATCH 1/5] change cluster revision in light-switch-app --- .../light-switch-common/light-switch-app.matter | 2 +- .../light-switch-app/light-switch-common/light-switch-app.zap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.matter b/examples/light-switch-app/light-switch-common/light-switch-app.matter index e51a772add14e2..65e7c5198a4052 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.matter +++ b/examples/light-switch-app/light-switch-common/light-switch-app.matter @@ -2792,7 +2792,7 @@ endpoint 0 { callback attribute acceptedCommandList; callback attribute attributeList; ram attribute featureMap default = 0x0B; - ram attribute clusterRevision default = 1; + ram attribute clusterRevision default = 2; handle command SetUTCTime; handle command SetTrustedTimeSource; diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.zap b/examples/light-switch-app/light-switch-common/light-switch-app.zap index ba56db35a2669b..dcfa64d7c5e88f 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.zap +++ b/examples/light-switch-app/light-switch-common/light-switch-app.zap @@ -3826,7 +3826,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "1", + "defaultValue": "2", "reportable": 1, "minInterval": 1, "maxInterval": 65534, From db4fb4b0e5909dd7fd0b54d407f7e3dce7190115 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Thu, 4 Apr 2024 10:49:54 +0200 Subject: [PATCH 2/5] added delegate functions for better usability --- .../DefaultTimeSyncDelegate.cpp | 10 ++++++++++ .../DefaultTimeSyncDelegate.h | 2 ++ .../time-synchronization-delegate.h | 4 +++- .../time-synchronization-server.cpp | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp index e436d19f6d6136..a04a3e01f8adf7 100644 --- a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp +++ b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp @@ -78,3 +78,13 @@ void DefaultTimeSyncDelegate::UTCTimeAvailabilityChanged(uint64_t time) { // placeholder implementation } + +void DefaultTimeSyncDelegate::TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) +{ + // placeholder implementation +} + +void DefaultTimeSyncDelegate::NotifyTimeFailure() +{ + // placeholder implementation +} diff --git a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h index 01f156e4ea2ccb..90f3e5d716cbb0 100644 --- a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h +++ b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h @@ -37,6 +37,8 @@ class DefaultTimeSyncDelegate : public Delegate CHIP_ERROR UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP, chip::Callback::Callback * callback) override; void UTCTimeAvailabilityChanged(uint64_t time) override; + void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) override; + void NotifyTimeFailure() override; }; } // namespace TimeSynchronization diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h index 7d5bad65ff0d2e..c2ff80a4ad073d 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h +++ b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h @@ -109,7 +109,9 @@ class Delegate /** * @brief Signals application that UTCTime has changed through the timesync cluster. */ - virtual void UTCTimeAvailabilityChanged(uint64_t time) = 0; + virtual void UTCTimeAvailabilityChanged(uint64_t time) = 0; + virtual void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) = 0; + virtual void NotifyTimeFailure() = 0; virtual ~Delegate() = default; diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index d03d7842911d51..463b4a4c617245 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -215,6 +215,7 @@ static bool emitTimeFailureEvent(EndpointId ep) // TODO: re-schedule event for after min 1hr if no time is still available // https://github.com/project-chip/connectedhomeip/issues/27200 ChipLogProgress(Zcl, "Emit TimeFailure event [ep=%d]", ep); + GetDelegate()->NotifyTimeFailure(); return true; } @@ -504,6 +505,7 @@ CHIP_ERROR TimeSynchronizationServer::SetTrustedTimeSource(const DataModel::Null { AttemptToGetTime(); } + GetDelegate()->TrustedTimeSourceAvailabilityChanged(!mTrustedTimeSource.IsNull(), mGranularity); return err; } From a4d90ba8441ca9d30f6eba829303fa8dd1ce74e9 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Thu, 4 Apr 2024 10:52:56 +0200 Subject: [PATCH 3/5] - made AttemptToGetTimeFromTrustedNode() public API - free readclient memory after read is complete --- .../time-synchronization-server.cpp | 1 + .../time-synchronization-server/time-synchronization-server.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index 463b4a4c617245..fda3bb50d7fda0 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -357,6 +357,7 @@ void TimeSynchronizationServer::OnDone(ReadClient * apReadClient) SetUTCTime(kRootEndpointId, mTimeReadInfo->utcTime.Value(), ourGranularity, TimeSourceEnum::kNodeTimeCluster); if (err == CHIP_NO_ERROR) { + mTimeReadInfo = nullptr; return; } } diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.h b/src/app/clusters/time-synchronization-server/time-synchronization-server.h index ef40eaacc790c4..2581c9712e7862 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.h +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.h @@ -123,6 +123,8 @@ class TimeSynchronizationServer : public FabricTable::Delegate // ReadClient::Callback functions void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override; void OnDone(ReadClient * apReadClient) override; + + CHIP_ERROR AttemptToGetTimeFromTrustedNode(); #endif // Platform event handler functions @@ -166,7 +168,6 @@ class TimeSynchronizationServer : public FabricTable::Delegate // Called when the platform is set up - attempts to get time using the recommended source list in the spec. void AttemptToGetTime(); - CHIP_ERROR AttemptToGetTimeFromTrustedNode(); // Attempts to get fallback NTP from the delegate (last available source) // If successful, the function will set mGranulatiry and the time source // If unsuccessful, it will emit a TimeFailure event. From e4d764d6589ad2600fcb17033f466d371f06cbf6 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Thu, 4 Apr 2024 23:32:10 +0200 Subject: [PATCH 4/5] added default implementation for some delegate functions --- .../DefaultTimeSyncDelegate.cpp | 32 ------------------- .../DefaultTimeSyncDelegate.h | 7 ---- .../time-synchronization-delegate.h | 15 +++++---- 3 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp index a04a3e01f8adf7..59fb8b0bbee24d 100644 --- a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp +++ b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.cpp @@ -24,17 +24,6 @@ using chip::TimeSyncDataProvider; using namespace chip::app::Clusters::TimeSynchronization; -void DefaultTimeSyncDelegate::TimeZoneListChanged(const Span timeZoneList) -{ - // placeholder implementation -} - -bool DefaultTimeSyncDelegate::HandleUpdateDSTOffset(chip::CharSpan name) -{ - // placeholder implementation - return false; -} - bool DefaultTimeSyncDelegate::IsNTPAddressValid(chip::CharSpan ntp) { // placeholder implementation @@ -67,24 +56,3 @@ CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeFromPlatformSource(chip::Callback: } return CHIP_ERROR_NOT_IMPLEMENTED; } - -CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP, - chip::Callback::Callback * callback) -{ - return CHIP_ERROR_NOT_IMPLEMENTED; -} - -void DefaultTimeSyncDelegate::UTCTimeAvailabilityChanged(uint64_t time) -{ - // placeholder implementation -} - -void DefaultTimeSyncDelegate::TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) -{ - // placeholder implementation -} - -void DefaultTimeSyncDelegate::NotifyTimeFailure() -{ - // placeholder implementation -} diff --git a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h index 90f3e5d716cbb0..0d78ef2f0fe6e9 100644 --- a/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h +++ b/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h @@ -29,16 +29,9 @@ class DefaultTimeSyncDelegate : public Delegate public: DefaultTimeSyncDelegate() : Delegate(){}; - void TimeZoneListChanged(const Span timeZoneList) override; - bool HandleUpdateDSTOffset(CharSpan name) override; bool IsNTPAddressValid(CharSpan ntp) override; bool IsNTPAddressDomain(CharSpan ntp) override; CHIP_ERROR UpdateTimeFromPlatformSource(chip::Callback::Callback * callback) override; - CHIP_ERROR UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP, - chip::Callback::Callback * callback) override; - void UTCTimeAvailabilityChanged(uint64_t time) override; - void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) override; - void NotifyTimeFailure() override; }; } // namespace TimeSynchronization diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h index c2ff80a4ad073d..d81d5288ef4cb5 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h +++ b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h @@ -56,7 +56,7 @@ class Delegate * * @param timeZoneList new time zone list */ - virtual void TimeZoneListChanged(const Span timeZoneList) = 0; + virtual void TimeZoneListChanged(const Span timeZoneList) {} /** * @brief Give the delegate the chance to call SetDSTOffset on the TimeSynchronizationServer with a list of * DST offsets based on the provided time zone name. If the delegate does so, it should return true. @@ -64,7 +64,7 @@ class Delegate * * @param name name of active time zone */ - virtual bool HandleUpdateDSTOffset(const CharSpan name) = 0; + virtual bool HandleUpdateDSTOffset(const CharSpan name) { return false; } /** * @brief Returns true if the provided string is a valid NTP address (either domain name or IPv6 address). * @@ -104,14 +104,17 @@ class Delegate * a CHIP_ERROR. */ virtual CHIP_ERROR UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP, - chip::Callback::Callback * callback) = 0; + chip::Callback::Callback * callback) + { + return CHIP_ERROR_NOT_IMPLEMENTED; + } /** * @brief Signals application that UTCTime has changed through the timesync cluster. */ - virtual void UTCTimeAvailabilityChanged(uint64_t time) = 0; - virtual void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) = 0; - virtual void NotifyTimeFailure() = 0; + virtual void UTCTimeAvailabilityChanged(uint64_t time) {} + virtual void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) {} + virtual void NotifyTimeFailure() {} virtual ~Delegate() = default; From 049d625e3ff2361cf17d77e08915bc8839199019 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Fri, 12 Apr 2024 11:20:51 +0200 Subject: [PATCH 5/5] added documentation for delegate functions --- .../time-synchronization-delegate.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h index d81d5288ef4cb5..f38153528118fd 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h +++ b/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h @@ -110,10 +110,19 @@ class Delegate } /** - * @brief Signals application that UTCTime has changed through the timesync cluster. + * @brief Signals application that UTCTime has changed through the timesync cluster. This gets called when + * time is available for the first time or is updated. Therefore, @param time will always have a valid value. + * The negative case of time being unavailable is handled by NotifyTimeFailure(). */ virtual void UTCTimeAvailabilityChanged(uint64_t time) {} + /** + * @brief Signals application that a new trusted time source is available. The application can then decide + * if it wants to attempt to query for time from this source. + */ virtual void TrustedTimeSourceAvailabilityChanged(bool available, GranularityEnum granularity) {} + /** + * @brief Signals application that fetching time has failed. The reason is not relevant. + */ virtual void NotifyTimeFailure() {} virtual ~Delegate() = default;