From 732b12ed7a0002f87c48b887ebc142684878d5ef Mon Sep 17 00:00:00 2001 From: William Date: Wed, 9 Aug 2023 18:09:31 +0100 Subject: [PATCH] Reorder mode base and op state (#28573) * Reordered Mode Base functions. * Moved generic OpState cluster objects into one header file. * Reordered OperationalStateServer functions. * Moved OpState delegate in the server header file. * Updated the TestOperationalStateDelegate inctludes following the operational state delegate change in location. * Renamed TestOperationalStateDelegate.cpp -> src/app/tests/TestOperationalStateClusterObjects.cpp * Restyled by clang-format * Minor corrections following revision. * Moved the initialization of the mCurrentMode attribute from the constructor. * Restyled by clang-format * Improved the name of private Mode Base register functions. * Reverted change in the ifdef in the mode base init method. This was accendentally changed during a merge. --------- Co-authored-by: Restyled.io --- .../mode-base-server/mode-base-server.cpp | 9 ++++----- .../clusters/mode-base-server/mode-base-server.h | 15 ++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/mode-base-server/mode-base-server.cpp b/src/app/clusters/mode-base-server/mode-base-server.cpp index b5b8a403b9ba3e..cb55bc214c8676 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.cpp +++ b/src/app/clusters/mode-base-server/mode-base-server.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include using namespace chip; @@ -52,7 +51,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClus Instance::~Instance() { - UnregisterInstance(); + UnregisterThisInstance(); chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } @@ -69,7 +68,7 @@ CHIP_ERROR Instance::Init() ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); - RegisterInstance(); + RegisterThisInstance(); ReturnErrorOnFailure(mDelegate->Init()); // If the StartUpMode is set, the CurrentMode attribute SHALL be set to the StartUpMode value, when the server is powered up. @@ -350,7 +349,7 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & attributePath, Attr return CHIP_ERROR_INCORRECT_STATE; } -void Instance::RegisterInstance() +void Instance::RegisterThisInstance() { if (!gModeBaseAliasesInstances.Contains(this)) { @@ -358,7 +357,7 @@ void Instance::RegisterInstance() } } -void Instance::UnregisterInstance() +void Instance::UnregisterThisInstance() { gModeBaseAliasesInstances.Remove(this); } diff --git a/src/app/clusters/mode-base-server/mode-base-server.h b/src/app/clusters/mode-base-server/mode-base-server.h index 10a2a97c07080f..ef88ee8269dd46 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.h +++ b/src/app/clusters/mode-base-server/mode-base-server.h @@ -124,11 +124,12 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface private: Delegate * mDelegate; - EndpointId mEndpointId{}; - ClusterId mClusterId{}; + EndpointId mEndpointId; + ClusterId mClusterId; // Attribute data store - uint8_t mCurrentMode; + uint8_t mCurrentMode = 0; // This is a temporary value and may not be valid. We will change this to the value of the first + // mode in the list at the start of the Init function to ensure that it represents a valid mode. DataModel::Nullable mStartUpMode; DataModel::Nullable mOnMode; uint32_t mFeature; @@ -146,14 +147,14 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; /** - * Register this ModeBase instance. + * Register this ModeBase instance in gModeBaseAliasesInstances. */ - void RegisterInstance(); + void RegisterThisInstance(); /** - * Unregister this ModeBase instance. + * Unregister this ModeBase instance in gModeBaseAliasesInstances. */ - void UnregisterInstance(); + void UnregisterThisInstance(); /** * Internal change-to-mode command handler function.