Skip to content

Commit

Permalink
Reorder mode base and op state (#28573)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 28, 2023
1 parent e8b629f commit 1699874
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/app/clusters/mode-base-server/mode-base-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <app/clusters/on-off-server/on-off-server.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <app/util/config.h>
#include <platform/DiagnosticDataProvider.h>

using namespace chip;
Expand Down Expand Up @@ -52,7 +51,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClus

Instance::~Instance()
{
UnregisterInstance();
UnregisterThisInstance();
chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this);
unregisterAttributeAccessOverride(this);
}
Expand All @@ -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.
Expand Down Expand Up @@ -350,15 +349,15 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & attributePath, Attr
return CHIP_ERROR_INCORRECT_STATE;
}

void Instance::RegisterInstance()
void Instance::RegisterThisInstance()
{
if (!gModeBaseAliasesInstances.Contains(this))
{
gModeBaseAliasesInstances.PushBack(this);
}
}

void Instance::UnregisterInstance()
void Instance::UnregisterThisInstance()
{
gModeBaseAliasesInstances.Remove(this);
}
Expand Down
15 changes: 8 additions & 7 deletions src/app/clusters/mode-base-server/mode-base-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> mStartUpMode;
DataModel::Nullable<uint8_t> mOnMode;
uint32_t mFeature;
Expand All @@ -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.
Expand Down

0 comments on commit 1699874

Please sign in to comment.