From d3b13a359e174ff19151423a75b80a264793a991 Mon Sep 17 00:00:00 2001 From: mideayanghui <106149377+mideayanghui@users.noreply.github.com> Date: Fri, 21 Jul 2023 00:51:14 +0800 Subject: [PATCH] [OPSTATE] Add OperationalError Event and OperationCompletion Event api (#27990) * Add OperationalError event api for operational state cluster * fix build error * Add OperationCompletion event api for operational state cluster * fix build error * save the zap for all-clusters-app.zap * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../operational-state-server.cpp | 45 +++++++++++++++++++ .../operational-state-server.h | 15 ++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/operational-state-server/operational-state-server.cpp b/src/app/clusters/operational-state-server/operational-state-server.cpp index ec54a41f2b7b60..b3fd2d89523f00 100644 --- a/src/app/clusters/operational-state-server/operational-state-server.cpp +++ b/src/app/clusters/operational-state-server/operational-state-server.cpp @@ -29,7 +29,10 @@ #include #include #include +#include +#include #include +#include #include #include #include @@ -294,3 +297,45 @@ CHIP_ERROR OperationalStateServer::Read(const ConcreteReadAttributePath & aPath, } return CHIP_NO_ERROR; } + +void OperationalStateServer::OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError) +{ + ChipLogDetail(Zcl, "OperationalStateServer: OnOperationalErrorDetect"); + MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id); + + EventNumber eventNumber; + Events::OperationalError::Type event{ aError }; + EventLogger eventData(event); + ConcreteEventPath path(mEndpointId, mClusterId, event.GetEventId()); + EventManagement & logMgmt = chip::app::EventManagement::GetInstance(); + EventOptions eventOptions; + eventOptions.mPath = path; + eventOptions.mPriority = event.GetPriorityLevel(); + + CHIP_ERROR err = logMgmt.LogEvent(&eventData, eventOptions, eventNumber); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationalError event: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +void OperationalStateServer::OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent) +{ + ChipLogDetail(Zcl, "OperationalStateServer: OnOperationCompletionDetect"); + MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id); + + EventNumber eventNumber; + EventLogger eventData(aEvent); + ConcreteEventPath path(mEndpointId, mClusterId, aEvent.GetEventId()); + EventManagement & logMgmt = chip::app::EventManagement::GetInstance(); + EventOptions eventOptions; + eventOptions.mPath = path; + eventOptions.mPriority = aEvent.GetPriorityLevel(); + + CHIP_ERROR err = logMgmt.LogEvent(&eventData, eventOptions, eventNumber); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "OperationalStateServer: Failed to record OnOperationCompletionDetect event: %" CHIP_ERROR_FORMAT, + err.Format()); + } +} diff --git a/src/app/clusters/operational-state-server/operational-state-server.h b/src/app/clusters/operational-state-server/operational-state-server.h index 247ef3779ffd7a..796fa4cc3640e4 100644 --- a/src/app/clusters/operational-state-server/operational-state-server.h +++ b/src/app/clusters/operational-state-server/operational-state-server.h @@ -60,11 +60,23 @@ class OperationalStateServer : public CommandHandlerInterface, public AttributeA */ void Shutdown(); + /** + * @brief Called when the Node detects a OperationalError has been raised. + * @param aError OperationalError which detects + */ + void OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError); + + /** + * @brief Called when the Node detects a OperationCompletion has been raised. + * @param aEvent OperationCompletion event + */ + void OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent); + /** * Creates an operational state cluster instance. The Init() function needs to be called for this instance to be registered and * called by the interaction model at the appropriate times. * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. - * @param aClusterId The ID of the ModeSelect aliased cluster to be instantiated. + * @param aClusterId The ID of the operational state aliased cluster to be instantiated. */ OperationalStateServer(EndpointId aEndpointId, ClusterId aClusterId) : CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId), @@ -113,7 +125,6 @@ class OperationalStateServer : public CommandHandlerInterface, public AttributeA EndpointId mEndpointId; ClusterId mClusterId; }; - } // namespace OperationalState } // namespace Clusters } // namespace app