diff --git a/src/app/clusters/operational-state-server/operational-state-delegate.h b/src/app/clusters/operational-state-server/operational-state-delegate.h index 6fd29bd7d48480..34bbe2d1ba10c0 100644 --- a/src/app/clusters/operational-state-server/operational-state-delegate.h +++ b/src/app/clusters/operational-state-server/operational-state-delegate.h @@ -187,21 +187,6 @@ struct GenericOperationalPhase char mPhaseNameBuffer[kOperationalPhaseNameMaxSize]; }; -/** - * A class which represents the operational completion of an Operational State cluster derivation instance. - */ -struct GenericOperationCompletion : public app::Clusters::OperationalState::Events::OperationCompletion::Type -{ - GenericOperationCompletion(uint8_t aCompletionErrorCode, - const Optional> & aTotalOperationalTime = NullOptional, - const Optional> & aPausedTime = NullOptional) - { - completionErrorCode = aCompletionErrorCode; - totalOperationalTime = aTotalOperationalTime; - pausedTime = aPausedTime; - } -}; - /** * A delegate to handle application logic of the Operational State aliased Cluster. * The delegate API assumes there will be separate delegate objects for each cluster instance. 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 a91f13d2f257a5..5fa7473f0e1641 100644 --- a/src/app/clusters/operational-state-server/operational-state-server.cpp +++ b/src/app/clusters/operational-state-server/operational-state-server.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -46,6 +45,55 @@ using namespace chip::app::Clusters::OperationalState::Attributes; using Status = Protocols::InteractionModel::Status; +/** + * A class which represents the operational error event of an Operational State cluster derivation instance. + */ +class GenericErrorEvent : private app::Clusters::OperationalState::Events::OperationalError::Type +{ + using super = app::Clusters::OperationalState::Events::OperationalError::Type; + +public: + GenericErrorEvent(ClusterId aClusterId, const Structs::ErrorStateStruct::Type & aError) : mClusterId(aClusterId) + { + errorState = aError; + } + using super::GetEventId; + using super::GetPriorityLevel; + ClusterId GetClusterId() const { return mClusterId; } + using super::Encode; + using super::kIsFabricScoped; + +private: + ClusterId mClusterId; +}; + +/** + * A class which represents the operational completion event of an Operational State cluster derivation instance. + */ +class GenericOperationCompletionEvent : private app::Clusters::OperationalState::Events::OperationCompletion::Type +{ + using super = app::Clusters::OperationalState::Events::OperationCompletion::Type; + +public: + GenericOperationCompletionEvent(ClusterId aClusterId, uint8_t aCompletionErrorCode, + const Optional> & aTotalOperationalTime = NullOptional, + const Optional> & aPausedTime = NullOptional) : + mClusterId(aClusterId) + { + completionErrorCode = aCompletionErrorCode; + totalOperationalTime = aTotalOperationalTime; + pausedTime = aPausedTime; + } + using super::GetEventId; + using super::GetPriorityLevel; + ClusterId GetClusterId() const { return mClusterId; } + using super::Encode; + using super::kIsFabricScoped; + +private: + ClusterId mClusterId; +}; + CHIP_ERROR OperationalStateServer::Init() { // Check if the cluster has been selected in zap @@ -302,44 +350,34 @@ CHIP_ERROR OperationalStateServer::Read(const ConcreteReadAttributePath & aPath, return CHIP_NO_ERROR; } -void OperationalStateServer::OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError) +void OperationalStateServer::OnOperationalErrorDetected(const Structs::ErrorStateStruct::Type & aError) { - ChipLogDetail(Zcl, "OperationalStateServer: OnOperationalErrorDetect"); - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id); + ChipLogDetail(Zcl, "OperationalStateServer: OnOperationalErrorDetected"); + MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::OperationalState::Id); + GenericErrorEvent event(mClusterId, aError); 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) + CHIP_ERROR error = app::LogEvent(event, mEndpointId, eventNumber); + + if (error != CHIP_NO_ERROR) { - ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationalError event: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationalError event: %" CHIP_ERROR_FORMAT, error.Format()); } } -void OperationalStateServer::OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent) +void OperationalStateServer::OnOperationCompletionDetected(uint8_t aCompletionErrorCode, + const Optional> & aTotalOperationalTime, + const Optional> & aPausedTime) { - ChipLogDetail(Zcl, "OperationalStateServer: OnOperationCompletionDetect"); - MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, OperationalState::Attributes::OperationalState::Id); + ChipLogDetail(Zcl, "OperationalStateServer: OnOperationCompletionDetected"); + GenericOperationCompletionEvent event(mClusterId, aCompletionErrorCode, aTotalOperationalTime, aPausedTime); 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) + CHIP_ERROR error = app::LogEvent(event, mEndpointId, eventNumber); + + if (error != CHIP_NO_ERROR) { - ChipLogError(Zcl, "OperationalStateServer: Failed to record OnOperationCompletionDetect event: %" CHIP_ERROR_FORMAT, - err.Format()); + ChipLogError(Zcl, "OperationalStateServer: Failed to record OperationCompletion event: %" CHIP_ERROR_FORMAT, + error.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 796fa4cc3640e4..5bb50d3b5df6ef 100644 --- a/src/app/clusters/operational-state-server/operational-state-server.h +++ b/src/app/clusters/operational-state-server/operational-state-server.h @@ -64,13 +64,17 @@ class OperationalStateServer : public CommandHandlerInterface, public AttributeA * @brief Called when the Node detects a OperationalError has been raised. * @param aError OperationalError which detects */ - void OnOperationalErrorDetect(const Structs::ErrorStateStruct::Type & aError); + void OnOperationalErrorDetected(const Structs::ErrorStateStruct::Type & aError); /** * @brief Called when the Node detects a OperationCompletion has been raised. - * @param aEvent OperationCompletion event + * @param aCompletionErrorCode CompletionErrorCode + * @param aTotalOperationalTime TotalOperationalTime + * @param aPausedTime PausedTime */ - void OnOperationCompletionDetect(const Events::OperationCompletion::Type & aEvent); + void OnOperationCompletionDetected(uint8_t aCompletionErrorCode, + const Optional> & aTotalOperationalTime = NullOptional, + const Optional> & aPausedTime = NullOptional); /** * Creates an operational state cluster instance. The Init() function needs to be called for this instance to be registered and diff --git a/src/app/tests/TestOperationalStateDelegate.cpp b/src/app/tests/TestOperationalStateDelegate.cpp index a4d5dce822bc8d..e82f80bbdaff84 100644 --- a/src/app/tests/TestOperationalStateDelegate.cpp +++ b/src/app/tests/TestOperationalStateDelegate.cpp @@ -542,42 +542,6 @@ void TestStructGenericOperationalPhaseCopyAssignment(nlTestSuite * inSuite, void memcmp(const_cast(phase.mPhaseName.Value().data()), phaseBuffer2, kOperationalPhaseNameMaxSize) == 0); } -void TestStructGenericOperationalCompletionConstructor(nlTestSuite * inSuite, void * inContext) -{ - using namespace chip::app; - using namespace chip::app::Clusters::OperationalState; - - // completion with only CompletionErrorCode - GenericOperationCompletion genericOperationCompletion(to_underlying(OperationalStateEnum::kError)); - NL_TEST_ASSERT(inSuite, genericOperationCompletion.completionErrorCode == to_underlying(OperationalStateEnum::kError)); - NL_TEST_ASSERT(inSuite, genericOperationCompletion.totalOperationalTime.HasValue() == false); - NL_TEST_ASSERT(inSuite, genericOperationCompletion.pausedTime.HasValue() == false); - - // completion with errorCode and TotalOperationalTime - uint32_t kTotalOperationalTime = 500; - GenericOperationCompletion genericOperationCompletion2( - to_underlying(OperationalStateEnum::kError), - Optional>(DataModel::Nullable(kTotalOperationalTime))); - NL_TEST_ASSERT(inSuite, genericOperationCompletion2.completionErrorCode == to_underlying(OperationalStateEnum::kError)); - - NL_TEST_ASSERT(inSuite, genericOperationCompletion2.totalOperationalTime.HasValue() == true); - NL_TEST_ASSERT(inSuite, genericOperationCompletion2.totalOperationalTime.Value().Value() == kTotalOperationalTime); - NL_TEST_ASSERT(inSuite, genericOperationCompletion2.pausedTime.HasValue() == false); - - // completion with errorCode, TotalOperationalTime and PausedTime - uint32_t kPausedTime = 2000; - GenericOperationCompletion genericOperationCompletion3( - to_underlying(OperationalStateEnum::kError), - Optional>(DataModel::Nullable(kTotalOperationalTime)), - Optional>(DataModel::Nullable(kPausedTime))); - NL_TEST_ASSERT(inSuite, genericOperationCompletion3.completionErrorCode == to_underlying(OperationalStateEnum::kError)); - - NL_TEST_ASSERT(inSuite, genericOperationCompletion3.totalOperationalTime.HasValue() == true); - NL_TEST_ASSERT(inSuite, genericOperationCompletion3.totalOperationalTime.Value().Value() == kTotalOperationalTime); - NL_TEST_ASSERT(inSuite, genericOperationCompletion3.pausedTime.HasValue() == true); - NL_TEST_ASSERT(inSuite, genericOperationCompletion3.pausedTime.Value().Value() == kPausedTime); -} - const nlTest sTests[] = { NL_TEST_DEF("Test struct GenericOperationalState: constructor with only StateID", TestStructGenericOperationalStateConstructorWithOnlyStateID), @@ -598,7 +562,6 @@ const nlTest sTests[] = { NL_TEST_DEF("Test struct GenericOperationalPhase: constructor", TestStructGenericOperationalPhaseConstructor), NL_TEST_DEF("Test struct GenericOperationalPhase: copy constructor", TestStructGenericOperationalPhaseCopyConstructor), NL_TEST_DEF("Test struct GenericOperationalPhase: copy assignment", TestStructGenericOperationalPhaseCopyAssignment), - NL_TEST_DEF("Test struct GenericOperationalCompletion: constructor", TestStructGenericOperationalCompletionConstructor), NL_TEST_SENTINEL() };