From acc7a7dbff94bb3f6e93c9f61893d92d5bcd55b1 Mon Sep 17 00:00:00 2001 From: sabollim Date: Thu, 13 Feb 2025 19:59:38 +0530 Subject: [PATCH 01/24] Closure control sluster Server Code --- src/app/chip_data_model.gni | 5 + .../closure-control-server.cpp | 284 ++++++++++++++++++ .../closure-control-server.h | 136 +++++++++ src/app/common/templates/config-data.yaml | 1 + src/app/zap_cluster_list.json | 1 + 5 files changed, 427 insertions(+) create mode 100644 src/app/clusters/closure-control-server/closure-control-server.cpp create mode 100644 src/app/clusters/closure-control-server/closure-control-server.h diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 9dbe7ec193a0e4..5ef9fa360c98ed 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -451,6 +451,11 @@ template("chip_data_model") { "${_app_root}/clusters/${cluster}/ArlEncoder.cpp", "${_app_root}/clusters/${cluster}/ArlEncoder.h", ] + } else if (cluster == "closure-control-server") { + sources += [ + "${_app_root}/clusters/${cluster}/${cluster}.cpp", + "${_app_root}/clusters/${cluster}/${cluster}.h", + ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] } diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp new file mode 100644 index 00000000000000..130910d77ad812 --- /dev/null +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include "closure-control-server.h" + + #include + #include + #include + #include + #include + #include + + using namespace chip; + using namespace chip::app; + using namespace chip::app::DataModel; + using namespace chip::app::Clusters; + using namespace chip::app::Clusters::ClosureControl; + using namespace chip::app::Clusters::ClosureControl::Attributes; + using namespace chip::app::Clusters::ClosureControl::Commands; + using chip::Protocols::InteractionModel::Status; + + namespace chip { + namespace app { + namespace Clusters { + namespace ClosureControl { + + CHIP_ERROR Instance::Init() + { + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(this)); + VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE); + + return CHIP_NO_ERROR; + } + + void Instance::Shutdown() + { + CommandHandlerInterfaceRegistry::Instance().UnregisterCommandHandler(this); + AttributeAccessInterfaceRegistry::Instance().Unregister(this); + } + + bool Instance::HasFeature(Feature aFeature) const + { + return mFeature.Has(aFeature); + } + + bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const + { + return mOptionalAttrs.Has(aOptionalAttrs); + } + + // AttributeAccessInterface + CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) + { + VerifyOrDie(aPath.mClusterId == ClosureControl::Id); + + switch (aPath.mAttributeId) + { + case CountdownTime::Id: + if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) + { + return aEncoder.Encode(mDelegate.GetCountdownTime()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case MainState::Id: + return aEncoder.Encode(mDelegate.GetMainState()); + case CurrentErrorList::Id: + return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); + case OverallState::Id: + return aEncoder.Encode(mDelegate.GetOverallState()); + case OverallTarget::Id: + return aEncoder.Encode(mDelegate.GetOverallTarget()); + case RestingProcedure::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetRestingProcedure()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerCondition::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetTriggerCondition()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerPosition::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetTriggerPosition()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case WaitingDelay::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetWaitingDelay()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case KickoffTimer::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetKickoffTimer()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + /* FeatureMap - is held locally */ + case FeatureMap::Id: + return aEncoder.Encode(mFeature); + // TODO CHECK CLUSTER REVISION + } + /* Allow all other unhandled attributes to fall through to Ember */ + return CHIP_NO_ERROR; + } + + CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & encoder) + { + CHIP_ERROR err = CHIP_NO_ERROR; + + ReturnErrorOnFailure(mDelegate.StartCurrentErrorListRead()); + for (size_t i = 0; true; i++) + { + ClosureErrorEnum error; + + err = mDelegate.GetCurrentErrorListAtIndex(i, error); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) + { + // Convert end of list to CHIP_NO_ERROR + err = CHIP_NO_ERROR; + goto exit; + } + + // Check if another error occurred before trying to encode + SuccessOrExit(err); + + err = encoder.Encode(error); + SuccessOrExit(err); + } + + exit: + // Tell the delegate the read is complete + err = mDelegate.EndCurrentErrorListRead(); + return err; + } + + CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) + { + switch (aPath.mAttributeId) + { + default: + // Unknown attribute; return error. None of the other attributes for + // this cluster are writable, so should not be ending up in this code to + // start with. + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + } + } + + // CommandHandlerInterface + void Instance::InvokeCommand(HandlerContext & handlerContext) + { + using namespace Commands; + + switch (handlerContext.mRequestPath.mCommandId) + { + case Stop::Id: + if (!HasFeature(Feature::kInstantaneous)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleStop(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case MoveTo::Id: + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleMoveTo(ctx, commandData); }); + return; + case Calibrate::Id: + if (HasFeature(Feature::kCalibration)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCalibrate(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case ConfigureFallback::Id: + if (HasFeature(Feature::kFallback)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleConfigureFallback(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case CancelFallback::Id: + if (HasFeature(Feature::kFallback)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCancelFallback(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + } + } + + void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData) + { + // No parameters for this command + // Call the delegate + Status status = mDelegate.Stop(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); + } + + void Instance::HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData) + { + const Optional tag = commandData.tag; + const Optional latch = commandData.latch; + const Optional speed = commandData.speed; + + // Call the delegate + Status status = mDelegate.MoveTo(tag, latch, speed); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); + } + + void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData) + { + // No parameters for this command + // Call the delegate + Status status = mDelegate.Calibrate(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); + } + + void Instance::HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData) + { + const Optional restingProcedure = commandData.restingProcedure; + const Optional triggerCondition = commandData.triggerCondition; + const Optional triggerPosition = commandData.triggerPosition; + const Optional waitingDelay = commandData.waitingDelay; + + // Call the delegate + Status status = mDelegate.ConfigureFallback(restingProcedure, triggerCondition, triggerPosition, waitingDelay); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); + } + + void Instance::HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData) + { + // No parameters for this command + // Call the delegate + Status status = mDelegate.CancelFallback(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); + } + + } // namespace ClosureControl + } // namespace Clusters + } // namespace app + } // namespace chip + + // ----------------------------------------------------------------------------- + // Plugin initialization + + void MatterClosureControlPluginServerInitCallback() {} \ No newline at end of file diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h new file mode 100644 index 00000000000000..4cfc0701d041a8 --- /dev/null +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -0,0 +1,136 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #pragma once + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + namespace chip { + namespace app { + namespace Clusters { + namespace ClosureControl { + + /** @brief + * Defines methods for implementing application-specific logic for the Closure Control Cluster. + */ + class Delegate + { + public: + virtual ~Delegate() = default; + + void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } + EndpointId GetEndpointId() { return mEndpointId; } + + // ------------------------------------------------------------------ + // Commands + virtual Protocols::InteractionModel::Status Stop() = 0; + virtual Protocols::InteractionModel::Status MoveTo(const Optional tag, + const Optional latch, + const Optional speed) = 0; + virtual Protocols::InteractionModel::Status Calibrate() = 0; + virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional restingProcedure, + const Optional triggerCondition, + const Optional triggerPosition, + const Optional waitingDelay) = 0; + virtual Protocols::InteractionModel::Status CancelFallback() = 0; + + // ------------------------------------------------------------------ + // Get attribute methods + virtual DataModel::Nullable GetCountdownTime() = 0; + virtual MainStateEnum GetMainState() = 0; + virtual DataModel::Nullable GetOverallState() = 0; + virtual DataModel::Nullable GetOverallTarget() = 0; + virtual RestingProcedureEnum GetRestingProcedure() = 0; + virtual TriggerConditionEnum GetTriggerCondition() = 0; + virtual TriggerPositionEnum GetTriggerPosition() = 0; + virtual uint32_t GetWaitingDelay() = 0; + virtual uint32_t GetKickoffTimer() = 0; + + /* These functions are called by the ReadAttribute handler to iterate through lists + * The cluster server will call StartRead to allow the delegate to create a temporary + * lock on the data. + * The delegate is expected to not change these values once StartRead has been called + * until the EndRead() has been called (e.g. releasing a lock on the data) + */ + virtual CHIP_ERROR StartCurrentErrorListRead() = 0; + virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t,ClosureErrorEnum &) = 0; + virtual CHIP_ERROR EndCurrentErrorListRead() = 0; + + protected: + EndpointId mEndpointId = 0; + }; + + enum class OptionalAttributes : uint32_t + { + kCountdownTime = 0x1 + }; + + class Instance : public AttributeAccessInterface, public CommandHandlerInterface + { + public: + Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, + OptionalAttributes aOptionalAttrs) : + AttributeAccessInterface(MakeOptional(aEndpointId), Id), + CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), + mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) + { + /* set the base class delegates endpointId */ + mDelegate.SetEndpointId(aEndpointId); + } + ~Instance() { Shutdown(); } + + CHIP_ERROR Init(); + void Shutdown(); + + bool HasFeature(Feature aFeature) const; + bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; + + private: + Delegate & mDelegate; + BitMask mFeature; + BitMask mOptionalAttrs; + + // AttributeAccessInterface + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; + + CHIP_ERROR EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & aEncoder); + + // CommandHandlerInterface + void InvokeCommand(HandlerContext & handlerContext) override; + + void HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData); + void HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData); + void HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData); + void HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData); + void HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData); + }; + + } // namespace ClosureControl + } // namespace Clusters + } // namespace app + } // namespace chip \ No newline at end of file diff --git a/src/app/common/templates/config-data.yaml b/src/app/common/templates/config-data.yaml index 7dcf2b6b68ec6f..fdf0e7c90db2dc 100644 --- a/src/app/common/templates/config-data.yaml +++ b/src/app/common/templates/config-data.yaml @@ -54,6 +54,7 @@ CommandHandlerInterfaceOnlyClusters: - Software Diagnostics - Wi-Fi Network Diagnostics - Administrator Commissioning + - Closure Control # We need a more configurable way of deciding which clusters have which init functions.... # See https://github.com/project-chip/connectedhomeip/issues/4369 diff --git a/src/app/zap_cluster_list.json b/src/app/zap_cluster_list.json index 971d7abede1c89..9f6c0b42bd7191 100644 --- a/src/app/zap_cluster_list.json +++ b/src/app/zap_cluster_list.json @@ -176,6 +176,7 @@ ], "CHANNEL_CLUSTER": ["channel-server"], "CHIME_CLUSTER": ["chime-server"], + "CLOSURE_CONTROL_CLUSTER": ["closure-control-server"], "COLOR_CONTROL_CLUSTER": ["color-control-server"], "COMMISSIONER_CONTROL_CLUSTER": ["commissioner-control-server"], "COMMISSIONING_CLUSTER": [], From 88785eee6c1988b7c31f16e93b6b6068c55ff9a4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 17 Feb 2025 09:32:39 +0000 Subject: [PATCH 02/24] Restyled by whitespace --- .../closure-control-server.cpp | 72 +++++++++---------- .../closure-control-server.h | 60 ++++++++-------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 130910d77ad812..13f90134bf3971 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -22,7 +22,7 @@ #include #include #include - + using namespace chip; using namespace chip::app; using namespace chip::app::DataModel; @@ -31,47 +31,47 @@ using namespace chip::app::Clusters::ClosureControl::Attributes; using namespace chip::app::Clusters::ClosureControl::Commands; using chip::Protocols::InteractionModel::Status; - + namespace chip { namespace app { namespace Clusters { namespace ClosureControl { - + CHIP_ERROR Instance::Init() { ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(this)); VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE); - + return CHIP_NO_ERROR; } - + void Instance::Shutdown() { CommandHandlerInterfaceRegistry::Instance().UnregisterCommandHandler(this); AttributeAccessInterfaceRegistry::Instance().Unregister(this); } - + bool Instance::HasFeature(Feature aFeature) const { return mFeature.Has(aFeature); } - + bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const { return mOptionalAttrs.Has(aOptionalAttrs); } - + // AttributeAccessInterface CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { VerifyOrDie(aPath.mClusterId == ClosureControl::Id); - + switch (aPath.mAttributeId) { case CountdownTime::Id: if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) { - return aEncoder.Encode(mDelegate.GetCountdownTime()); + return aEncoder.Encode(mDelegate.GetCountdownTime()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); case MainState::Id: @@ -120,16 +120,16 @@ /* Allow all other unhandled attributes to fall through to Ember */ return CHIP_NO_ERROR; } - + CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & encoder) { CHIP_ERROR err = CHIP_NO_ERROR; - + ReturnErrorOnFailure(mDelegate.StartCurrentErrorListRead()); for (size_t i = 0; true; i++) { ClosureErrorEnum error; - + err = mDelegate.GetCurrentErrorListAtIndex(i, error); if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { @@ -137,20 +137,20 @@ err = CHIP_NO_ERROR; goto exit; } - + // Check if another error occurred before trying to encode SuccessOrExit(err); - + err = encoder.Encode(error); SuccessOrExit(err); } - + exit: // Tell the delegate the read is complete err = mDelegate.EndCurrentErrorListRead(); return err; } - + CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) { switch (aPath.mAttributeId) @@ -162,19 +162,19 @@ return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); } } - + // CommandHandlerInterface void Instance::InvokeCommand(HandlerContext & handlerContext) { using namespace Commands; - + switch (handlerContext.mRequestPath.mCommandId) { case Stop::Id: if (!HasFeature(Feature::kInstantaneous)) { HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleStop(ctx, commandData); }); + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleStop(ctx, commandData); }); } else { @@ -220,65 +220,65 @@ return; } } - + void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData) { // No parameters for this command // Call the delegate Status status = mDelegate.Stop(); - + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } - + void Instance::HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData) { const Optional tag = commandData.tag; const Optional latch = commandData.latch; const Optional speed = commandData.speed; - + // Call the delegate Status status = mDelegate.MoveTo(tag, latch, speed); - + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } - + void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData) { // No parameters for this command // Call the delegate Status status = mDelegate.Calibrate(); - + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } - + void Instance::HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData) { const Optional restingProcedure = commandData.restingProcedure; const Optional triggerCondition = commandData.triggerCondition; const Optional triggerPosition = commandData.triggerPosition; const Optional waitingDelay = commandData.waitingDelay; - + // Call the delegate Status status = mDelegate.ConfigureFallback(restingProcedure, triggerCondition, triggerPosition, waitingDelay); - + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } - + void Instance::HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData) { // No parameters for this command // Call the delegate Status status = mDelegate.CancelFallback(); - + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } - + } // namespace ClosureControl } // namespace Clusters } // namespace app } // namespace chip - + // ----------------------------------------------------------------------------- // Plugin initialization - - void MatterClosureControlPluginServerInitCallback() {} \ No newline at end of file + + void MatterClosureControlPluginServerInitCallback() {} diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 4cfc0701d041a8..572479cf8c11ed 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -28,7 +28,7 @@ #include #include #include - + namespace chip { namespace app { namespace Clusters { @@ -41,35 +41,35 @@ { public: virtual ~Delegate() = default; - + void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } EndpointId GetEndpointId() { return mEndpointId; } - + // ------------------------------------------------------------------ // Commands - virtual Protocols::InteractionModel::Status Stop() = 0; + virtual Protocols::InteractionModel::Status Stop() = 0; virtual Protocols::InteractionModel::Status MoveTo(const Optional tag, const Optional latch, - const Optional speed) = 0; - virtual Protocols::InteractionModel::Status Calibrate() = 0; + const Optional speed) = 0; + virtual Protocols::InteractionModel::Status Calibrate() = 0; virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional restingProcedure, const Optional triggerCondition, const Optional triggerPosition, - const Optional waitingDelay) = 0; - virtual Protocols::InteractionModel::Status CancelFallback() = 0; - + const Optional waitingDelay) = 0; + virtual Protocols::InteractionModel::Status CancelFallback() = 0; + // ------------------------------------------------------------------ // Get attribute methods virtual DataModel::Nullable GetCountdownTime() = 0; - virtual MainStateEnum GetMainState() = 0; - virtual DataModel::Nullable GetOverallState() = 0; - virtual DataModel::Nullable GetOverallTarget() = 0; - virtual RestingProcedureEnum GetRestingProcedure() = 0; - virtual TriggerConditionEnum GetTriggerCondition() = 0; - virtual TriggerPositionEnum GetTriggerPosition() = 0; - virtual uint32_t GetWaitingDelay() = 0; + virtual MainStateEnum GetMainState() = 0; + virtual DataModel::Nullable GetOverallState() = 0; + virtual DataModel::Nullable GetOverallTarget() = 0; + virtual RestingProcedureEnum GetRestingProcedure() = 0; + virtual TriggerConditionEnum GetTriggerCondition() = 0; + virtual TriggerPositionEnum GetTriggerPosition() = 0; + virtual uint32_t GetWaitingDelay() = 0; virtual uint32_t GetKickoffTimer() = 0; - + /* These functions are called by the ReadAttribute handler to iterate through lists * The cluster server will call StartRead to allow the delegate to create a temporary * lock on the data. @@ -79,58 +79,58 @@ virtual CHIP_ERROR StartCurrentErrorListRead() = 0; virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t,ClosureErrorEnum &) = 0; virtual CHIP_ERROR EndCurrentErrorListRead() = 0; - + protected: EndpointId mEndpointId = 0; }; - + enum class OptionalAttributes : uint32_t { kCountdownTime = 0x1 }; - + class Instance : public AttributeAccessInterface, public CommandHandlerInterface { public: Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), Id), - CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), + CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ mDelegate.SetEndpointId(aEndpointId); } ~Instance() { Shutdown(); } - + CHIP_ERROR Init(); void Shutdown(); - + bool HasFeature(Feature aFeature) const; bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; - + private: Delegate & mDelegate; BitMask mFeature; BitMask mOptionalAttrs; - + // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; - + CHIP_ERROR EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & aEncoder); - + // CommandHandlerInterface void InvokeCommand(HandlerContext & handlerContext) override; - + void HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData); void HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData); void HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData); void HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData); void HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData); }; - + } // namespace ClosureControl } // namespace Clusters } // namespace app - } // namespace chip \ No newline at end of file + } // namespace chip From 236a68bc22b6741c164bfb5ec9c39cce3ad24b73 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 17 Feb 2025 09:32:42 +0000 Subject: [PATCH 03/24] Restyled by clang-format --- .../closure-control-server.cpp | 537 +++++++++--------- .../closure-control-server.h | 227 ++++---- 2 files changed, 381 insertions(+), 383 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 13f90134bf3971..7db28808ed5a71 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -14,271 +14,272 @@ * limitations under the License. */ - #include "closure-control-server.h" - - #include - #include - #include - #include - #include - #include - - using namespace chip; - using namespace chip::app; - using namespace chip::app::DataModel; - using namespace chip::app::Clusters; - using namespace chip::app::Clusters::ClosureControl; - using namespace chip::app::Clusters::ClosureControl::Attributes; - using namespace chip::app::Clusters::ClosureControl::Commands; - using chip::Protocols::InteractionModel::Status; - - namespace chip { - namespace app { - namespace Clusters { - namespace ClosureControl { - - CHIP_ERROR Instance::Init() - { - ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(this)); - VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE); - - return CHIP_NO_ERROR; - } - - void Instance::Shutdown() - { - CommandHandlerInterfaceRegistry::Instance().UnregisterCommandHandler(this); - AttributeAccessInterfaceRegistry::Instance().Unregister(this); - } - - bool Instance::HasFeature(Feature aFeature) const - { - return mFeature.Has(aFeature); - } - - bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const - { - return mOptionalAttrs.Has(aOptionalAttrs); - } - - // AttributeAccessInterface - CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) - { - VerifyOrDie(aPath.mClusterId == ClosureControl::Id); - - switch (aPath.mAttributeId) - { - case CountdownTime::Id: - if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) - { - return aEncoder.Encode(mDelegate.GetCountdownTime()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - case MainState::Id: - return aEncoder.Encode(mDelegate.GetMainState()); - case CurrentErrorList::Id: - return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); - case OverallState::Id: - return aEncoder.Encode(mDelegate.GetOverallState()); - case OverallTarget::Id: - return aEncoder.Encode(mDelegate.GetOverallTarget()); - case RestingProcedure::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetRestingProcedure()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - case TriggerCondition::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetTriggerCondition()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - case TriggerPosition::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetTriggerPosition()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - case WaitingDelay::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetWaitingDelay()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - case KickoffTimer::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetKickoffTimer()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - /* FeatureMap - is held locally */ - case FeatureMap::Id: - return aEncoder.Encode(mFeature); - // TODO CHECK CLUSTER REVISION - } - /* Allow all other unhandled attributes to fall through to Ember */ - return CHIP_NO_ERROR; - } - - CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & encoder) - { - CHIP_ERROR err = CHIP_NO_ERROR; - - ReturnErrorOnFailure(mDelegate.StartCurrentErrorListRead()); - for (size_t i = 0; true; i++) - { - ClosureErrorEnum error; - - err = mDelegate.GetCurrentErrorListAtIndex(i, error); - if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) - { - // Convert end of list to CHIP_NO_ERROR - err = CHIP_NO_ERROR; - goto exit; - } - - // Check if another error occurred before trying to encode - SuccessOrExit(err); - - err = encoder.Encode(error); - SuccessOrExit(err); - } - - exit: - // Tell the delegate the read is complete - err = mDelegate.EndCurrentErrorListRead(); - return err; - } - - CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) - { - switch (aPath.mAttributeId) - { - default: - // Unknown attribute; return error. None of the other attributes for - // this cluster are writable, so should not be ending up in this code to - // start with. - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - } - } - - // CommandHandlerInterface - void Instance::InvokeCommand(HandlerContext & handlerContext) - { - using namespace Commands; - - switch (handlerContext.mRequestPath.mCommandId) - { - case Stop::Id: - if (!HasFeature(Feature::kInstantaneous)) - { - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleStop(ctx, commandData); }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - return; - case MoveTo::Id: - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleMoveTo(ctx, commandData); }); - return; - case Calibrate::Id: - if (HasFeature(Feature::kCalibration)) - { - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCalibrate(ctx, commandData); }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - return; - case ConfigureFallback::Id: - if (HasFeature(Feature::kFallback)) - { - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleConfigureFallback(ctx, commandData); }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - return; - case CancelFallback::Id: - if (HasFeature(Feature::kFallback)) - { - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCancelFallback(ctx, commandData); }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - return; - } - } - - void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData) - { - // No parameters for this command - // Call the delegate - Status status = mDelegate.Stop(); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); - } - - void Instance::HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData) - { - const Optional tag = commandData.tag; - const Optional latch = commandData.latch; - const Optional speed = commandData.speed; - - // Call the delegate - Status status = mDelegate.MoveTo(tag, latch, speed); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); - } - - void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData) - { - // No parameters for this command - // Call the delegate - Status status = mDelegate.Calibrate(); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); - } - - void Instance::HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData) - { - const Optional restingProcedure = commandData.restingProcedure; - const Optional triggerCondition = commandData.triggerCondition; - const Optional triggerPosition = commandData.triggerPosition; - const Optional waitingDelay = commandData.waitingDelay; - - // Call the delegate - Status status = mDelegate.ConfigureFallback(restingProcedure, triggerCondition, triggerPosition, waitingDelay); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); - } - - void Instance::HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData) - { - // No parameters for this command - // Call the delegate - Status status = mDelegate.CancelFallback(); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); - } - - } // namespace ClosureControl - } // namespace Clusters - } // namespace app - } // namespace chip - - // ----------------------------------------------------------------------------- - // Plugin initialization - - void MatterClosureControlPluginServerInitCallback() {} +#include "closure-control-server.h" + +#include +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::DataModel; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::ClosureControl; +using namespace chip::app::Clusters::ClosureControl::Attributes; +using namespace chip::app::Clusters::ClosureControl::Commands; +using chip::Protocols::InteractionModel::Status; + +namespace chip { +namespace app { +namespace Clusters { +namespace ClosureControl { + +CHIP_ERROR Instance::Init() +{ + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(this)); + VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE); + + return CHIP_NO_ERROR; +} + +void Instance::Shutdown() +{ + CommandHandlerInterfaceRegistry::Instance().UnregisterCommandHandler(this); + AttributeAccessInterfaceRegistry::Instance().Unregister(this); +} + +bool Instance::HasFeature(Feature aFeature) const +{ + return mFeature.Has(aFeature); +} + +bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const +{ + return mOptionalAttrs.Has(aOptionalAttrs); +} + +// AttributeAccessInterface +CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + VerifyOrDie(aPath.mClusterId == ClosureControl::Id); + + switch (aPath.mAttributeId) + { + case CountdownTime::Id: + if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) + { + return aEncoder.Encode(mDelegate.GetCountdownTime()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case MainState::Id: + return aEncoder.Encode(mDelegate.GetMainState()); + case CurrentErrorList::Id: + return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); + case OverallState::Id: + return aEncoder.Encode(mDelegate.GetOverallState()); + case OverallTarget::Id: + return aEncoder.Encode(mDelegate.GetOverallTarget()); + case RestingProcedure::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetRestingProcedure()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerCondition::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetTriggerCondition()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerPosition::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetTriggerPosition()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case WaitingDelay::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetWaitingDelay()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case KickoffTimer::Id: + if (HasFeature(Feature::kFallback)) + { + return aEncoder.Encode(mDelegate.GetKickoffTimer()); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + /* FeatureMap - is held locally */ + case FeatureMap::Id: + return aEncoder.Encode(mFeature); + // TODO CHECK CLUSTER REVISION + } + /* Allow all other unhandled attributes to fall through to Ember */ + return CHIP_NO_ERROR; +} + +CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & encoder) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + ReturnErrorOnFailure(mDelegate.StartCurrentErrorListRead()); + for (size_t i = 0; true; i++) + { + ClosureErrorEnum error; + + err = mDelegate.GetCurrentErrorListAtIndex(i, error); + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) + { + // Convert end of list to CHIP_NO_ERROR + err = CHIP_NO_ERROR; + goto exit; + } + + // Check if another error occurred before trying to encode + SuccessOrExit(err); + + err = encoder.Encode(error); + SuccessOrExit(err); + } + +exit: + // Tell the delegate the read is complete + err = mDelegate.EndCurrentErrorListRead(); + return err; +} + +CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) +{ + switch (aPath.mAttributeId) + { + default: + // Unknown attribute; return error. None of the other attributes for + // this cluster are writable, so should not be ending up in this code to + // start with. + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + } +} + +// CommandHandlerInterface +void Instance::InvokeCommand(HandlerContext & handlerContext) +{ + using namespace Commands; + + switch (handlerContext.mRequestPath.mCommandId) + { + case Stop::Id: + if (!HasFeature(Feature::kInstantaneous)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleStop(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case MoveTo::Id: + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleMoveTo(ctx, commandData); }); + return; + case Calibrate::Id: + if (HasFeature(Feature::kCalibration)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCalibrate(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case ConfigureFallback::Id: + if (HasFeature(Feature::kFallback)) + { + HandleCommand(handlerContext, [this](HandlerContext & ctx, const auto & commandData) { + HandleConfigureFallback(ctx, commandData); + }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + case CancelFallback::Id: + if (HasFeature(Feature::kFallback)) + { + HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCancelFallback(ctx, commandData); }); + } + else + { + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); + } + return; + } +} + +void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData) +{ + // No parameters for this command + // Call the delegate + Status status = mDelegate.Stop(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); +} + +void Instance::HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData) +{ + const Optional tag = commandData.tag; + const Optional latch = commandData.latch; + const Optional speed = commandData.speed; + + // Call the delegate + Status status = mDelegate.MoveTo(tag, latch, speed); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); +} + +void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData) +{ + // No parameters for this command + // Call the delegate + Status status = mDelegate.Calibrate(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); +} + +void Instance::HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData) +{ + const Optional restingProcedure = commandData.restingProcedure; + const Optional triggerCondition = commandData.triggerCondition; + const Optional triggerPosition = commandData.triggerPosition; + const Optional waitingDelay = commandData.waitingDelay; + + // Call the delegate + Status status = mDelegate.ConfigureFallback(restingProcedure, triggerCondition, triggerPosition, waitingDelay); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); +} + +void Instance::HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData) +{ + // No parameters for this command + // Call the delegate + Status status = mDelegate.CancelFallback(); + + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); +} + +} // namespace ClosureControl +} // namespace Clusters +} // namespace app +} // namespace chip + +// ----------------------------------------------------------------------------- +// Plugin initialization + +void MatterClosureControlPluginServerInitCallback() {} diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 572479cf8c11ed..aa3d7c33f5b4e0 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -16,121 +16,118 @@ * limitations under the License. */ - #pragma once - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - namespace chip { - namespace app { - namespace Clusters { - namespace ClosureControl { - - /** @brief - * Defines methods for implementing application-specific logic for the Closure Control Cluster. - */ - class Delegate - { - public: - virtual ~Delegate() = default; - - void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } - EndpointId GetEndpointId() { return mEndpointId; } +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ClosureControl { + +/** @brief + * Defines methods for implementing application-specific logic for the Closure Control Cluster. + */ +class Delegate +{ +public: + virtual ~Delegate() = default; + + void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } + EndpointId GetEndpointId() { return mEndpointId; } // ------------------------------------------------------------------ // Commands - virtual Protocols::InteractionModel::Status Stop() = 0; - virtual Protocols::InteractionModel::Status MoveTo(const Optional tag, - const Optional latch, - const Optional speed) = 0; - virtual Protocols::InteractionModel::Status Calibrate() = 0; - virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional restingProcedure, - const Optional triggerCondition, - const Optional triggerPosition, - const Optional waitingDelay) = 0; - virtual Protocols::InteractionModel::Status CancelFallback() = 0; - - // ------------------------------------------------------------------ - // Get attribute methods - virtual DataModel::Nullable GetCountdownTime() = 0; - virtual MainStateEnum GetMainState() = 0; - virtual DataModel::Nullable GetOverallState() = 0; - virtual DataModel::Nullable GetOverallTarget() = 0; - virtual RestingProcedureEnum GetRestingProcedure() = 0; - virtual TriggerConditionEnum GetTriggerCondition() = 0; - virtual TriggerPositionEnum GetTriggerPosition() = 0; - virtual uint32_t GetWaitingDelay() = 0; - virtual uint32_t GetKickoffTimer() = 0; - - /* These functions are called by the ReadAttribute handler to iterate through lists - * The cluster server will call StartRead to allow the delegate to create a temporary - * lock on the data. - * The delegate is expected to not change these values once StartRead has been called - * until the EndRead() has been called (e.g. releasing a lock on the data) - */ - virtual CHIP_ERROR StartCurrentErrorListRead() = 0; - virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t,ClosureErrorEnum &) = 0; - virtual CHIP_ERROR EndCurrentErrorListRead() = 0; - - protected: - EndpointId mEndpointId = 0; - }; - - enum class OptionalAttributes : uint32_t - { - kCountdownTime = 0x1 - }; - - class Instance : public AttributeAccessInterface, public CommandHandlerInterface - { - public: - Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, - OptionalAttributes aOptionalAttrs) : - AttributeAccessInterface(MakeOptional(aEndpointId), Id), - CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), - mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) - { - /* set the base class delegates endpointId */ - mDelegate.SetEndpointId(aEndpointId); - } - ~Instance() { Shutdown(); } - - CHIP_ERROR Init(); - void Shutdown(); - - bool HasFeature(Feature aFeature) const; - bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; - - private: - Delegate & mDelegate; - BitMask mFeature; - BitMask mOptionalAttrs; - - // AttributeAccessInterface - CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; - CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; - - CHIP_ERROR EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & aEncoder); - - // CommandHandlerInterface - void InvokeCommand(HandlerContext & handlerContext) override; - - void HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData); - void HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData); - void HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData); - void HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData); - void HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData); - }; - - } // namespace ClosureControl - } // namespace Clusters - } // namespace app - } // namespace chip + virtual Protocols::InteractionModel::Status Stop() = 0; + virtual Protocols::InteractionModel::Status MoveTo(const Optional tag, const Optional latch, + const Optional speed) = 0; + virtual Protocols::InteractionModel::Status Calibrate() = 0; + virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional restingProcedure, + const Optional triggerCondition, + const Optional triggerPosition, + const Optional waitingDelay) = 0; + virtual Protocols::InteractionModel::Status CancelFallback() = 0; + + // ------------------------------------------------------------------ + // Get attribute methods + virtual DataModel::Nullable GetCountdownTime() = 0; + virtual MainStateEnum GetMainState() = 0; + virtual DataModel::Nullable GetOverallState() = 0; + virtual DataModel::Nullable GetOverallTarget() = 0; + virtual RestingProcedureEnum GetRestingProcedure() = 0; + virtual TriggerConditionEnum GetTriggerCondition() = 0; + virtual TriggerPositionEnum GetTriggerPosition() = 0; + virtual uint32_t GetWaitingDelay() = 0; + virtual uint32_t GetKickoffTimer() = 0; + + /* These functions are called by the ReadAttribute handler to iterate through lists + * The cluster server will call StartRead to allow the delegate to create a temporary + * lock on the data. + * The delegate is expected to not change these values once StartRead has been called + * until the EndRead() has been called (e.g. releasing a lock on the data) + */ + virtual CHIP_ERROR StartCurrentErrorListRead() = 0; + virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t, ClosureErrorEnum &) = 0; + virtual CHIP_ERROR EndCurrentErrorListRead() = 0; + +protected: + EndpointId mEndpointId = 0; +}; + +enum class OptionalAttributes : uint32_t +{ + kCountdownTime = 0x1 +}; + +class Instance : public AttributeAccessInterface, public CommandHandlerInterface +{ +public: + Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : + AttributeAccessInterface(MakeOptional(aEndpointId), Id), CommandHandlerInterface(MakeOptional(aEndpointId), Id), + mDelegate(aDelegate), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) + { + /* set the base class delegates endpointId */ + mDelegate.SetEndpointId(aEndpointId); + } + ~Instance() { Shutdown(); } + + CHIP_ERROR Init(); + void Shutdown(); + + bool HasFeature(Feature aFeature) const; + bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; + +private: + Delegate & mDelegate; + BitMask mFeature; + BitMask mOptionalAttrs; + + // AttributeAccessInterface + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; + + CHIP_ERROR EncodeCurrentErrorList(const AttributeValueEncoder::ListEncodeHelper & aEncoder); + + // CommandHandlerInterface + void InvokeCommand(HandlerContext & handlerContext) override; + + void HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData); + void HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData); + void HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData); + void HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData); + void HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData); +}; + +} // namespace ClosureControl +} // namespace Clusters +} // namespace app +} // namespace chip From 280df4f7cfabae6222134763cdef4ab93b3b9d7b Mon Sep 17 00:00:00 2001 From: sabollim Date: Mon, 17 Feb 2025 21:13:06 +0530 Subject: [PATCH 04/24] Changing MainState and Countdowntime Implementation --- .../closure-control-server.cpp | 78 ++++++++++++++++++- .../closure-control-server.h | 50 +++++++++++- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 7db28808ed5a71..ba21065779bf71 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -61,6 +61,82 @@ bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const return mOptionalAttrs.Has(aOptionalAttrs); } +bool Instance::IsSupportedState(MainStateEnum aMainState) +{ + switch (aMainState) + { + case MainStateEnum::kCalibrating: + return HasFeature(Feature::kCalibration); + case MainStateEnum::kProtected: + return HasFeature(Feature::kProtection); + case MainStateEnum::kDisengaged: + return HasFeature(Feature::kManuallyOperable); + case MainStateEnum::kPendingFallback: + return HasFeature(Feature::kFallback); + default: + return true; + } + return true; +} + +CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) +{ + if (!IsSupportedState(aMainState)) + { + return CHIP_ERROR_INVALID_ARGUMENT; + } + + MainStateEnum oldMainState = mMainState; + mMainState = aMainState; + if (mMainState != oldMainState) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::MainState::Id); + UpdateCountdownTimeFromClusterLogic(); + } + return CHIP_NO_ERROR; +} + +MainStateEnum Instance::GetMainState() const +{ + return mMainState; +} + +void Instance::UpdateCountdownTime(bool fromDelegate) +{ + app::DataModel::Nullable newCountdownTime = mDelegate.GetCountdownTime(); + auto now = System::SystemClock().GetMonotonicTimestamp(); + + bool markDirty = false; + + if (fromDelegate) + { + // Updates from delegate are reduce-reported to every 10s max (choice of this implementation), in addition + // to default change-from-null, change-from-zero and increment policy. + auto predicate = [](const decltype(mCountdownTime)::SufficientChangePredicateCandidate & candidate) -> bool { + if (candidate.lastDirtyValue.IsNull() || candidate.newValue.IsNull()) + { + return false; + } + + uint32_t lastDirtyValue = candidate.lastDirtyValue.Value(); + uint32_t newValue = candidate.newValue.Value(); + uint32_t kNumSecondsDeltaToReport = 10; + return (newValue < lastDirtyValue) && ((lastDirtyValue - newValue) > kNumSecondsDeltaToReport); + }; + markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); + } + else + { + auto predicate = [](const decltype(mCountdownTime)::SufficientChangePredicateCandidate &) -> bool { return true; }; + markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); + } + + if (markDirty) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::CountdownTime::Id); + } +} + // AttributeAccessInterface CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) { @@ -75,7 +151,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); case MainState::Id: - return aEncoder.Encode(mDelegate.GetMainState()); + return aEncoder.Encode(GetMainState()); case CurrentErrorList::Id: return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); case OverallState::Id: diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index aa3d7c33f5b4e0..3b68648a979941 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace chip { namespace app { @@ -60,7 +61,6 @@ class Delegate // ------------------------------------------------------------------ // Get attribute methods virtual DataModel::Nullable GetCountdownTime() = 0; - virtual MainStateEnum GetMainState() = 0; virtual DataModel::Nullable GetOverallState() = 0; virtual DataModel::Nullable GetOverallTarget() = 0; virtual RestingProcedureEnum GetRestingProcedure() = 0; @@ -91,9 +91,9 @@ enum class OptionalAttributes : uint32_t class Instance : public AttributeAccessInterface, public CommandHandlerInterface { public: - Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : + Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs, ClusterId aClusterId) : AttributeAccessInterface(MakeOptional(aEndpointId), Id), CommandHandlerInterface(MakeOptional(aEndpointId), Id), - mDelegate(aDelegate), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) + mDelegate(aDelegate), mClusterId(aClusterId), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ mDelegate.SetEndpointId(aEndpointId); @@ -105,11 +105,55 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface bool HasFeature(Feature aFeature) const; bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; + + // Attribute setters + /** + * Set Main State. + * @param aMainState The Main state that should now be the current one. + * @return CHIP_NO_ERROR if set was successful. + */ + CHIP_ERROR SetMainState(const MainStateEnum & aMainState); + + // Attribute getters + /** + * Get Main State. + * @return The Main State. + */ + MainStateEnum GetMainState() const; + + /** + * @brief Whenever application delegate wants to possibly report a new updated time, + * call this method. The `GetCountdownTime()` method will be called on the delegate. + */ + void UpdateCountdownTimeFromDelegate() { UpdateCountdownTime(/* fromDelegate = */ true); } + + /** + * This function returns true if the phase value given exists in the PhaseList attribute, otherwise it returns false. + */ + bool IsSupportedState(MainStateEnum aMainState); + +protected: + /** + * Causes reporting/udpating of CountdownTime attribute from driver if sufficient changes have + * occurred (based on Q quality definition for operational state). Calls the Delegate::GetCountdownTime() method. + * + * @param fromDelegate true if the change notice was triggered by the delegate, false if internal to cluster logic. + */ + void UpdateCountdownTime(bool fromDelegate); + + /** + * @brief Whenever the cluster logic thinks time should be updated, call this. + */ + void UpdateCountdownTimeFromClusterLogic() { UpdateCountdownTime(/* fromDelegate=*/false); } private: Delegate & mDelegate; + const ClusterId mClusterId; + BitMask mFeature; BitMask mOptionalAttrs; + MainStateEnum mMainState; + app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; From 2e82a85082bcc05ae379bbba1c2d1064e2e5b15a Mon Sep 17 00:00:00 2001 From: sabollim Date: Wed, 19 Feb 2025 00:15:17 +0530 Subject: [PATCH 05/24] Handling OverallState and OverallTarget from Instance --- .../closure-control-server.cpp | 54 +++++++++++++------ .../closure-control-server.h | 34 ++++++++++-- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index ba21065779bf71..3d01f7142e5117 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -91,7 +91,28 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) if (mMainState != oldMainState) { MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::MainState::Id); - UpdateCountdownTimeFromClusterLogic(); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR Instance::SetOverallState(const DataModel::Nullable & aOverallState) +{ + DataModel::Nullable oldOverallState = mOverallState; + mOverallState = aOverallState; + if (mOverallState != oldOverallState) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR Instance::SetOverallTarget(const DataModel::Nullable & aOverallTarget) +{ + DataModel::Nullable oldOverallTarget = mOverallTarget; + mOverallTarget = aOverallTarget; + if (mOverallTarget != oldOverallTarget) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); } return CHIP_NO_ERROR; } @@ -101,6 +122,16 @@ MainStateEnum Instance::GetMainState() const return mMainState; } +DataModel::Nullable Instance::GetOverallState() const +{ + return mOverallState; +} + +DataModel::Nullable Instance::GetOverallTarget() const +{ + return mOverallTarget; +} + void Instance::UpdateCountdownTime(bool fromDelegate) { app::DataModel::Nullable newCountdownTime = mDelegate.GetCountdownTime(); @@ -110,20 +141,11 @@ void Instance::UpdateCountdownTime(bool fromDelegate) if (fromDelegate) { - // Updates from delegate are reduce-reported to every 10s max (choice of this implementation), in addition + // Updates from delegate are reduce-reported to every 1s max (choice of this implementation), in addition // to default change-from-null, change-from-zero and increment policy. - auto predicate = [](const decltype(mCountdownTime)::SufficientChangePredicateCandidate & candidate) -> bool { - if (candidate.lastDirtyValue.IsNull() || candidate.newValue.IsNull()) - { - return false; - } - - uint32_t lastDirtyValue = candidate.lastDirtyValue.Value(); - uint32_t newValue = candidate.newValue.Value(); - uint32_t kNumSecondsDeltaToReport = 10; - return (newValue < lastDirtyValue) && ((lastDirtyValue - newValue) > kNumSecondsDeltaToReport); - }; - markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); + System::Clock::Milliseconds64 reportInterval = System::Clock::Milliseconds64(1000); + auto predicate = mCountdownTime.GetPredicateForSufficientTimeSinceLastDirty(reportInterval); + markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); } else { @@ -155,9 +177,9 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu case CurrentErrorList::Id: return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); case OverallState::Id: - return aEncoder.Encode(mDelegate.GetOverallState()); + return aEncoder.Encode(GetOverallState()); case OverallTarget::Id: - return aEncoder.Encode(mDelegate.GetOverallTarget()); + return aEncoder.Encode(GetOverallTarget()); case RestingProcedure::Id: if (HasFeature(Feature::kFallback)) { diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 3b68648a979941..242300c0654667 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -61,8 +61,6 @@ class Delegate // ------------------------------------------------------------------ // Get attribute methods virtual DataModel::Nullable GetCountdownTime() = 0; - virtual DataModel::Nullable GetOverallState() = 0; - virtual DataModel::Nullable GetOverallTarget() = 0; virtual RestingProcedureEnum GetRestingProcedure() = 0; virtual TriggerConditionEnum GetTriggerCondition() = 0; virtual TriggerPositionEnum GetTriggerPosition() = 0; @@ -114,6 +112,20 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface */ CHIP_ERROR SetMainState(const MainStateEnum & aMainState); + /** + * Set OverallState. + * @param aMainState The OverallState that should now be the current State. + * @return CHIP_NO_ERROR if set was successful. + */ + CHIP_ERROR SetOverallState(const DataModel::Nullable & aOverallState); + + /** + * Set OverallTarget. + * @param aMainState The OverallTarget that should be set. + * @return CHIP_NO_ERROR if set was successful. + */ + CHIP_ERROR SetOverallTarget(const DataModel::Nullable & aOverallTarget); + // Attribute getters /** * Get Main State. @@ -121,6 +133,18 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface */ MainStateEnum GetMainState() const; + /** + * Get OverallState. + * @return The OverallState. + */ + DataModel::Nullable GetOverallState() const; + + /** + * Get OverallTarget. + * @return The OverallTarget. + */ + DataModel::Nullable GetOverallTarget() const; + /** * @brief Whenever application delegate wants to possibly report a new updated time, * call this method. The `GetCountdownTime()` method will be called on the delegate. @@ -149,11 +173,13 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface private: Delegate & mDelegate; const ClusterId mClusterId; - BitMask mFeature; BitMask mOptionalAttrs; - MainStateEnum mMainState; + app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; + MainStateEnum mMainState; + DataModel::Nullable & mOverallState; + DataModel::Nullable & mOverallTarget; // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; From c230a1d47f5deabfd03f91cade31860e8b0f1f60 Mon Sep 17 00:00:00 2001 From: sabollim Date: Wed, 19 Feb 2025 00:56:19 +0530 Subject: [PATCH 06/24] Addressing PR comments --- .../closure-control-server.cpp | 16 ++++------------ .../closure-control-server.h | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 3d01f7142e5117..2bf902bc15b311 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -97,23 +97,15 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) CHIP_ERROR Instance::SetOverallState(const DataModel::Nullable & aOverallState) { - DataModel::Nullable oldOverallState = mOverallState; - mOverallState = aOverallState; - if (mOverallState != oldOverallState) - { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); - } + mOverallState = aOverallState; + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); return CHIP_NO_ERROR; } CHIP_ERROR Instance::SetOverallTarget(const DataModel::Nullable & aOverallTarget) { - DataModel::Nullable oldOverallTarget = mOverallTarget; - mOverallTarget = aOverallTarget; - if (mOverallTarget != oldOverallTarget) - { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); - } + mOverallTarget = aOverallTarget; + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 242300c0654667..4415697c0d1740 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -178,8 +178,8 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; MainStateEnum mMainState; - DataModel::Nullable & mOverallState; - DataModel::Nullable & mOverallTarget; + DataModel::Nullable mOverallState; + DataModel::Nullable mOverallTarget; // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; From bccbebeea95e5c70d2539c66c3ebadd93901ea3e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 18 Feb 2025 19:27:12 +0000 Subject: [PATCH 07/24] Restyled by whitespace --- .../closure-control-server/closure-control-server.cpp | 2 +- .../closure-control-server/closure-control-server.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 2bf902bc15b311..7f8112286e02f0 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -85,7 +85,7 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) { return CHIP_ERROR_INVALID_ARGUMENT; } - + MainStateEnum oldMainState = mMainState; mMainState = aMainState; if (mMainState != oldMainState) diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 4415697c0d1740..462dc0e4e55cfb 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -103,7 +103,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface bool HasFeature(Feature aFeature) const; bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; - + // Attribute setters /** * Set Main State. @@ -111,7 +111,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @return CHIP_NO_ERROR if set was successful. */ CHIP_ERROR SetMainState(const MainStateEnum & aMainState); - + /** * Set OverallState. * @param aMainState The OverallState that should now be the current State. @@ -132,7 +132,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @return The Main State. */ MainStateEnum GetMainState() const; - + /** * Get OverallState. * @return The OverallState. @@ -150,7 +150,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * call this method. The `GetCountdownTime()` method will be called on the delegate. */ void UpdateCountdownTimeFromDelegate() { UpdateCountdownTime(/* fromDelegate = */ true); } - + /** * This function returns true if the phase value given exists in the PhaseList attribute, otherwise it returns false. */ From 5c130df9006cc8cf81da3455ba34215919184229 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 18 Feb 2025 19:27:19 +0000 Subject: [PATCH 08/24] Restyled by clang-format --- .../closure-control-server.cpp | 4 ++-- .../closure-control-server.h | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 7f8112286e02f0..5605793457db41 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -87,7 +87,7 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) } MainStateEnum oldMainState = mMainState; - mMainState = aMainState; + mMainState = aMainState; if (mMainState != oldMainState) { MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::MainState::Id); @@ -137,7 +137,7 @@ void Instance::UpdateCountdownTime(bool fromDelegate) // to default change-from-null, change-from-zero and increment policy. System::Clock::Milliseconds64 reportInterval = System::Clock::Milliseconds64(1000); auto predicate = mCountdownTime.GetPredicateForSufficientTimeSinceLastDirty(reportInterval); - markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); + markDirty = (mCountdownTime.SetValue(newCountdownTime, now, predicate) == AttributeDirtyState::kMustReport); } else { diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 462dc0e4e55cfb..81ff4a4a805678 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -24,11 +24,11 @@ #include #include #include +#include #include #include #include #include -#include namespace chip { namespace app { @@ -60,12 +60,12 @@ class Delegate // ------------------------------------------------------------------ // Get attribute methods - virtual DataModel::Nullable GetCountdownTime() = 0; - virtual RestingProcedureEnum GetRestingProcedure() = 0; - virtual TriggerConditionEnum GetTriggerCondition() = 0; - virtual TriggerPositionEnum GetTriggerPosition() = 0; - virtual uint32_t GetWaitingDelay() = 0; - virtual uint32_t GetKickoffTimer() = 0; + virtual DataModel::Nullable GetCountdownTime() = 0; + virtual RestingProcedureEnum GetRestingProcedure() = 0; + virtual TriggerConditionEnum GetTriggerCondition() = 0; + virtual TriggerPositionEnum GetTriggerPosition() = 0; + virtual uint32_t GetWaitingDelay() = 0; + virtual uint32_t GetKickoffTimer() = 0; /* These functions are called by the ReadAttribute handler to iterate through lists * The cluster server will call StartRead to allow the delegate to create a temporary @@ -89,9 +89,11 @@ enum class OptionalAttributes : uint32_t class Instance : public AttributeAccessInterface, public CommandHandlerInterface { public: - Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs, ClusterId aClusterId) : - AttributeAccessInterface(MakeOptional(aEndpointId), Id), CommandHandlerInterface(MakeOptional(aEndpointId), Id), - mDelegate(aDelegate), mClusterId(aClusterId), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) + Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs, + ClusterId aClusterId) : + AttributeAccessInterface(MakeOptional(aEndpointId), Id), + CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), mClusterId(aClusterId), mFeature(aFeature), + mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ mDelegate.SetEndpointId(aEndpointId); From 3ee28a19e1a534f72b6d94ecd023858160fe0108 Mon Sep 17 00:00:00 2001 From: sabollim Date: Wed, 19 Feb 2025 13:12:18 +0530 Subject: [PATCH 09/24] Updating missing zap changes --- .../app-common/zap-generated/callback.h | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/zzz_generated/app-common/app-common/zap-generated/callback.h b/zzz_generated/app-common/app-common/zap-generated/callback.h index 0195a63f42581f..8e9fed9eb13973 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -6427,36 +6427,6 @@ bool emberAfWindowCoveringClusterGoToTiltValueCallback( bool emberAfWindowCoveringClusterGoToTiltPercentageCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::WindowCovering::Commands::GoToTiltPercentage::DecodableType & commandData); -/** - * @brief Closure Control Cluster Stop Command callback (from client) - */ -bool emberAfClosureControlClusterStopCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::ClosureControl::Commands::Stop::DecodableType & commandData); -/** - * @brief Closure Control Cluster MoveTo Command callback (from client) - */ -bool emberAfClosureControlClusterMoveToCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::ClosureControl::Commands::MoveTo::DecodableType & commandData); -/** - * @brief Closure Control Cluster Calibrate Command callback (from client) - */ -bool emberAfClosureControlClusterCalibrateCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::ClosureControl::Commands::Calibrate::DecodableType & commandData); -/** - * @brief Closure Control Cluster ConfigureFallback Command callback (from client) - */ -bool emberAfClosureControlClusterConfigureFallbackCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::ClosureControl::Commands::ConfigureFallback::DecodableType & commandData); -/** - * @brief Closure Control Cluster CancelFallback Command callback (from client) - */ -bool emberAfClosureControlClusterCancelFallbackCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::ClosureControl::Commands::CancelFallback::DecodableType & commandData); /** * @brief Thermostat Cluster SetpointRaiseLower Command callback (from client) */ From 266ea213b15ecb1fc3afd7309483c93a87e603fe Mon Sep 17 00:00:00 2001 From: sabollim Date: Thu, 20 Feb 2025 00:16:41 +0530 Subject: [PATCH 10/24] Adding wrapper for struct handling --- .../closure-control-cluster-objects.h | 165 ++++++++++++++++++ .../closure-control-server.cpp | 26 ++- .../closure-control-server.h | 17 +- 3 files changed, 194 insertions(+), 14 deletions(-) create mode 100644 src/app/clusters/closure-control-server/closure-control-cluster-objects.h diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h new file mode 100644 index 00000000000000..d8401aeeecc9ac --- /dev/null +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -0,0 +1,165 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ClosureControl { + +/** + * A class which represents the overall state of an closure control cluster derivation instance. + */ +struct GenericOverallState : public Structs::OverallStateStruct::Type +{ + GenericOverallState(Optional positioningValue = NullOptional, + Optional latchingValue = NullOptional, + Optional speedValue = NullOptional, + Optional extraInfoValue = NullOptional) + { + Set(positioningValue, latchingValue, speedValue, extraInfoValue); + } + + GenericOverallState(const GenericOverallState & overallState) { *this = overallState; } + + GenericOverallState & operator=(const GenericOverallState & overallState) + { + Set(overallState.positioning, overallState.latching, overallState.speed, overallState.extraInfo); + return *this; + } + + void Set(Optional positioningValue = NullOptional, + Optional latchingValue = NullOptional, + Optional speedValue = NullOptional, + Optional extraInfoValue = NullOptional) + { + if (positioningValue.HasValue()) { + positioning = positioningValue; + } + if (latchingValue.HasValue()) { + latching = latchingValue; + } + if (speedValue.HasValue()) { + speed = speedValue; + } + if (extraInfoValue.HasValue()) { + extraInfo = extraInfoValue; + } + } + + bool IsEqual(const Structs::OverallStateStruct::Type & rhs) const + { + if (positioning.HasValue() != rhs.positioning.HasValue() || + latching.HasValue() != rhs.latching.HasValue() || + speed.HasValue() != rhs.speed.HasValue() || + extraInfo.HasValue() != rhs.extraInfo.HasValue()) + { + return false; + } + + if (positioning.HasValue() && positioning.Value() != rhs.positioning.Value()) + { + return false; + } + if (latching.HasValue() && latching.Value() != rhs.latching.Value()) + { + return false; + } + if (speed.HasValue() && speed.Value() != rhs.speed.Value()) + { + return false; + } + if (extraInfo.HasValue() && extraInfo.Value() != rhs.extraInfo.Value()) + { + return false; + } + + return true; + } +}; + +/** + * A class which represents the overall target state of an closure control cluster derivation instance. + */ +struct GenericOverallTarget : public Structs::OverallTargetStruct::Type +{ + GenericOverallTarget(Optional tagPositionValue = NullOptional, + Optional tagLatchValue = NullOptional, + Optional speedValue = NullOptional) + { + Set(tagPositionValue, tagLatchValue, speedValue); + } + + GenericOverallTarget(const GenericOverallTarget & overallTarget) { *this = overallTarget; } + + GenericOverallTarget & operator=(const GenericOverallTarget & overallTarget) + { + Set(overallTarget.tagPosition, overallTarget.tagLatch, overallTarget.speed); + return *this; + } + + void Set(Optional tagPositionValue = NullOptional, + Optional tagLatchValue = NullOptional, + Optional speedValue = NullOptional) + { + if (tagPositionValue.HasValue()) { + tagPosition = tagPositionValue; + } + if (tagLatchValue.HasValue()) { + tagLatch = tagLatchValue; + } + if (speedValue.HasValue()) { + speed = speedValue; + } + } + + bool IsEqual(const Structs::OverallTargetStruct::Type & rhs) const + { + if (tagPosition.HasValue() != rhs.tagPosition.HasValue() || + tagLatch.HasValue() != rhs.tagLatch.HasValue() || + speed.HasValue() != rhs.speed.HasValue()) + { + return false; + } + + if (tagPosition.HasValue() && tagPosition.Value() != rhs.tagPosition.Value()) + { + return false; + } + if (tagLatch.HasValue() && tagLatch.Value() != rhs.tagLatch.Value()) + { + return false; + } + if (speed.HasValue() && speed.Value() != rhs.speed.Value()) + { + return false; + } + + return true; + } +}; + +} // namespace ClosureControl +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 5605793457db41..9dfec2abadfe05 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -95,17 +95,31 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) return CHIP_NO_ERROR; } -CHIP_ERROR Instance::SetOverallState(const DataModel::Nullable & aOverallState) +CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { + GenericOverallState oldOverallState = mOverallState; mOverallState = aOverallState; - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); + + // If the overall target state has changed, trigger the attribute change callback + if (!oldOverallState.IsEqual(mOverallState)) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); + } + return CHIP_NO_ERROR; } -CHIP_ERROR Instance::SetOverallTarget(const DataModel::Nullable & aOverallTarget) +CHIP_ERROR Instance::SetOverallTarget(const GenericOverallTarget & aOverallTarget) { + GenericOverallTarget oldOverallTarget = mOverallTarget; mOverallTarget = aOverallTarget; - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); + + // If the overall target state has changed, trigger the attribute change callback + if (!oldOverallTarget.IsEqual(mOverallTarget)) + { + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); + } + return CHIP_NO_ERROR; } @@ -114,12 +128,12 @@ MainStateEnum Instance::GetMainState() const return mMainState; } -DataModel::Nullable Instance::GetOverallState() const +GenericOverallState Instance::GetOverallState() const { return mOverallState; } -DataModel::Nullable Instance::GetOverallTarget() const +GenericOverallTarget Instance::GetOverallTarget() const { return mOverallTarget; } diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 81ff4a4a805678..5d67f2cd008280 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -18,6 +18,7 @@ #pragma once +#include "closure-control-cluster-objects.h" #include #include #include @@ -119,14 +120,14 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @param aMainState The OverallState that should now be the current State. * @return CHIP_NO_ERROR if set was successful. */ - CHIP_ERROR SetOverallState(const DataModel::Nullable & aOverallState); + CHIP_ERROR SetOverallState(const GenericOverallState & aOverallState); /** * Set OverallTarget. * @param aMainState The OverallTarget that should be set. * @return CHIP_NO_ERROR if set was successful. */ - CHIP_ERROR SetOverallTarget(const DataModel::Nullable & aOverallTarget); + CHIP_ERROR SetOverallTarget(const GenericOverallTarget & aOverallTarget); // Attribute getters /** @@ -137,15 +138,15 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface /** * Get OverallState. - * @return The OverallState. + * @return The GenericOverallState to fill with the current Overall State */ - DataModel::Nullable GetOverallState() const; + GenericOverallState GetOverallState() const; /** * Get OverallTarget. - * @return The OverallTarget. + * @return The GenericOverallTarget to fill with the current Overall Target */ - DataModel::Nullable GetOverallTarget() const; + GenericOverallTarget GetOverallTarget() const; /** * @brief Whenever application delegate wants to possibly report a new updated time, @@ -180,8 +181,8 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; MainStateEnum mMainState; - DataModel::Nullable mOverallState; - DataModel::Nullable mOverallTarget; + GenericOverallState mOverallState; + GenericOverallTarget mOverallTarget; // AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; From b03460e902f54a7951c2b6f56eb317124dd8c59c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Feb 2025 18:47:32 +0000 Subject: [PATCH 11/24] Restyled by whitespace --- .../closure-control-server/closure-control-cluster-objects.h | 2 +- .../clusters/closure-control-server/closure-control-server.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index d8401aeeecc9ac..b75fa0487f8002 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -157,7 +157,7 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type return true; } -}; +}; } // namespace ClosureControl } // namespace Clusters diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 9dfec2abadfe05..0d302c9b856109 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -99,7 +99,7 @@ CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { GenericOverallState oldOverallState = mOverallState; mOverallState = aOverallState; - + // If the overall target state has changed, trigger the attribute change callback if (!oldOverallState.IsEqual(mOverallState)) { From 1ad934c1df596736209fc919722c0988e7a2bf42 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 19 Feb 2025 18:47:37 +0000 Subject: [PATCH 12/24] Restyled by clang-format --- .../closure-control-cluster-objects.h | 53 ++++++++++--------- .../closure-control-server.cpp | 4 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index b75fa0487f8002..1e3eb36a0c6766 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -32,10 +32,10 @@ namespace ClosureControl { */ struct GenericOverallState : public Structs::OverallStateStruct::Type { - GenericOverallState(Optional positioningValue = NullOptional, - Optional latchingValue = NullOptional, + GenericOverallState(Optional positioningValue = NullOptional, + Optional latchingValue = NullOptional, Optional speedValue = NullOptional, - Optional extraInfoValue = NullOptional) + Optional extraInfoValue = NullOptional) { Set(positioningValue, latchingValue, speedValue, extraInfoValue); } @@ -48,31 +48,31 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type return *this; } - void Set(Optional positioningValue = NullOptional, - Optional latchingValue = NullOptional, - Optional speedValue = NullOptional, - Optional extraInfoValue = NullOptional) + void Set(Optional positioningValue = NullOptional, Optional latchingValue = NullOptional, + Optional speedValue = NullOptional, Optional extraInfoValue = NullOptional) { - if (positioningValue.HasValue()) { + if (positioningValue.HasValue()) + { positioning = positioningValue; } - if (latchingValue.HasValue()) { + if (latchingValue.HasValue()) + { latching = latchingValue; } - if (speedValue.HasValue()) { + if (speedValue.HasValue()) + { speed = speedValue; } - if (extraInfoValue.HasValue()) { + if (extraInfoValue.HasValue()) + { extraInfo = extraInfoValue; } } bool IsEqual(const Structs::OverallStateStruct::Type & rhs) const { - if (positioning.HasValue() != rhs.positioning.HasValue() || - latching.HasValue() != rhs.latching.HasValue() || - speed.HasValue() != rhs.speed.HasValue() || - extraInfo.HasValue() != rhs.extraInfo.HasValue()) + if (positioning.HasValue() != rhs.positioning.HasValue() || latching.HasValue() != rhs.latching.HasValue() || + speed.HasValue() != rhs.speed.HasValue() || extraInfo.HasValue() != rhs.extraInfo.HasValue()) { return false; } @@ -103,9 +103,9 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type */ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type { - GenericOverallTarget(Optional tagPositionValue = NullOptional, - Optional tagLatchValue = NullOptional, - Optional speedValue = NullOptional) + GenericOverallTarget(Optional tagPositionValue = NullOptional, + Optional tagLatchValue = NullOptional, + Optional speedValue = NullOptional) { Set(tagPositionValue, tagLatchValue, speedValue); } @@ -118,25 +118,26 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type return *this; } - void Set(Optional tagPositionValue = NullOptional, - Optional tagLatchValue = NullOptional, - Optional speedValue = NullOptional) + void Set(Optional tagPositionValue = NullOptional, Optional tagLatchValue = NullOptional, + Optional speedValue = NullOptional) { - if (tagPositionValue.HasValue()) { + if (tagPositionValue.HasValue()) + { tagPosition = tagPositionValue; } - if (tagLatchValue.HasValue()) { + if (tagLatchValue.HasValue()) + { tagLatch = tagLatchValue; } - if (speedValue.HasValue()) { + if (speedValue.HasValue()) + { speed = speedValue; } } bool IsEqual(const Structs::OverallTargetStruct::Type & rhs) const { - if (tagPosition.HasValue() != rhs.tagPosition.HasValue() || - tagLatch.HasValue() != rhs.tagLatch.HasValue() || + if (tagPosition.HasValue() != rhs.tagPosition.HasValue() || tagLatch.HasValue() != rhs.tagLatch.HasValue() || speed.HasValue() != rhs.speed.HasValue()) { return false; diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 0d302c9b856109..e2c0ee3186c4d8 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -98,7 +98,7 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { GenericOverallState oldOverallState = mOverallState; - mOverallState = aOverallState; + mOverallState = aOverallState; // If the overall target state has changed, trigger the attribute change callback if (!oldOverallState.IsEqual(mOverallState)) @@ -112,7 +112,7 @@ CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) CHIP_ERROR Instance::SetOverallTarget(const GenericOverallTarget & aOverallTarget) { GenericOverallTarget oldOverallTarget = mOverallTarget; - mOverallTarget = aOverallTarget; + mOverallTarget = aOverallTarget; // If the overall target state has changed, trigger the attribute change callback if (!oldOverallTarget.IsEqual(mOverallTarget)) From 757a2c746d7abf85ef9b660c7f27120505f0434e Mon Sep 17 00:00:00 2001 From: sabollim Date: Thu, 20 Feb 2025 16:00:07 +0530 Subject: [PATCH 13/24] Addressing PR comments --- src/app/chip_data_model.gni | 1 + .../closure-control-cluster-objects.h | 7 +- .../closure-control-server.cpp | 68 ++++++++++++------- .../closure-control-server.h | 67 ++++++++++-------- 4 files changed, 85 insertions(+), 58 deletions(-) diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 1ca6a927c4f6b3..8b8c4f01d689da 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -460,6 +460,7 @@ template("chip_data_model") { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp", "${_app_root}/clusters/${cluster}/${cluster}.h", + "${_app_root}/clusters/${cluster}/closure-control-cluster-objects.h", ] } else { sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ] diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index 1e3eb36a0c6766..613e58fe0ed700 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2025 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,6 @@ #pragma once #include - #include namespace chip { @@ -28,7 +27,7 @@ namespace Clusters { namespace ClosureControl { /** - * A class which represents the overall state of an closure control cluster derivation instance. + * Structure represents the overall state of a closure control cluster derivation instance. */ struct GenericOverallState : public Structs::OverallStateStruct::Type { @@ -99,7 +98,7 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type }; /** - * A class which represents the overall target state of an closure control cluster derivation instance. + * Structure represents the overall target state of a closure control cluster derivation instance. */ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type { diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index e2c0ee3186c4d8..0d78406e9f705c 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -74,6 +74,7 @@ bool Instance::IsSupportedState(MainStateEnum aMainState) case MainStateEnum::kPendingFallback: return HasFeature(Feature::kFallback); default: + // Remaining MainState have Mandatory conformance,so will be supported. return true; } return true; @@ -85,25 +86,22 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) { return CHIP_ERROR_INVALID_ARGUMENT; } - - MainStateEnum oldMainState = mMainState; - mMainState = aMainState; - if (mMainState != oldMainState) + // If the Main State has changed, trigger the attribute change callback + if (mMainState != aMainState) { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::MainState::Id); + mMainState = aMainState; + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::MainState::Id); } return CHIP_NO_ERROR; } CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { - GenericOverallState oldOverallState = mOverallState; - mOverallState = aOverallState; - // If the overall target state has changed, trigger the attribute change callback - if (!oldOverallState.IsEqual(mOverallState)) + if (!mOverallState.IsEqual(aOverallState)) { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallState::Id); + mOverallState = aOverallState; + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::OverallState::Id); } return CHIP_NO_ERROR; @@ -111,13 +109,11 @@ CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) CHIP_ERROR Instance::SetOverallTarget(const GenericOverallTarget & aOverallTarget) { - GenericOverallTarget oldOverallTarget = mOverallTarget; - mOverallTarget = aOverallTarget; - // If the overall target state has changed, trigger the attribute change callback - if (!oldOverallTarget.IsEqual(mOverallTarget)) + if (!mOverallTarget.IsEqual(aOverallTarget)) { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::OverallTarget::Id); + mOverallTarget = aOverallTarget; + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::OverallTarget::Id); } return CHIP_NO_ERROR; @@ -161,7 +157,7 @@ void Instance::UpdateCountdownTime(bool fromDelegate) if (markDirty) { - MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), mClusterId, Attributes::CountdownTime::Id); + MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::CountdownTime::Id); } } @@ -173,53 +169,63 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu switch (aPath.mAttributeId) { case CountdownTime::Id: + // Optional Attribute if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) { return aEncoder.Encode(mDelegate.GetCountdownTime()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case MainState::Id: return aEncoder.Encode(GetMainState()); + case CurrentErrorList::Id: return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { return this->EncodeCurrentErrorList(encoder); }); + case OverallState::Id: return aEncoder.Encode(GetOverallState()); + case OverallTarget::Id: return aEncoder.Encode(GetOverallTarget()); + case RestingProcedure::Id: if (HasFeature(Feature::kFallback)) { return aEncoder.Encode(mDelegate.GetRestingProcedure()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerCondition::Id: if (HasFeature(Feature::kFallback)) { return aEncoder.Encode(mDelegate.GetTriggerCondition()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case TriggerPosition::Id: if (HasFeature(Feature::kFallback)) { return aEncoder.Encode(mDelegate.GetTriggerPosition()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case WaitingDelay::Id: if (HasFeature(Feature::kFallback)) { return aEncoder.Encode(mDelegate.GetWaitingDelay()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case KickoffTimer::Id: if (HasFeature(Feature::kFallback)) { return aEncoder.Encode(mDelegate.GetKickoffTimer()); } return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + /* FeatureMap - is held locally */ case FeatureMap::Id: return aEncoder.Encode(mFeature); - // TODO CHECK CLUSTER REVISION } /* Allow all other unhandled attributes to fall through to Ember */ return CHIP_NO_ERROR; @@ -238,8 +244,7 @@ CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEnc if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { // Convert end of list to CHIP_NO_ERROR - err = CHIP_NO_ERROR; - goto exit; + ExitNow(err = CHIP_NO_ERROR); } // Check if another error occurred before trying to encode @@ -251,14 +256,27 @@ CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEnc exit: // Tell the delegate the read is complete - err = mDelegate.EndCurrentErrorListRead(); + ReturnErrorOnFailure(mDelegate.EndCurrentErrorListRead()); return err; } CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) { + VerifyOrDie(aPath.mClusterId == ClosureControl::Id); + switch (aPath.mAttributeId) { + case CountdownTime::Id: + if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) + { + return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite); + } + return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); + case MainState::Id: + case CurrentErrorList::Id: + case OverallState::Id: + case OverallTarget::Id: + return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite); default: // Unknown attribute; return error. None of the other attributes for // this cluster are writable, so should not be ending up in this code to @@ -284,11 +302,11 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) { handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); } - return; + break; case MoveTo::Id: HandleCommand( handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleMoveTo(ctx, commandData); }); - return; + break; case Calibrate::Id: if (HasFeature(Feature::kCalibration)) { @@ -299,7 +317,7 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) { handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); } - return; + break; case ConfigureFallback::Id: if (HasFeature(Feature::kFallback)) { @@ -311,7 +329,7 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) { handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); } - return; + break; case CancelFallback::Id: if (HasFeature(Feature::kFallback)) { @@ -322,7 +340,7 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) { handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); } - return; + break; } } diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 5d67f2cd008280..a25b5913caadc3 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -36,8 +36,8 @@ namespace app { namespace Clusters { namespace ClosureControl { -/** @brief - * Defines methods for implementing application-specific logic for the Closure Control Cluster. +/** + * @brief Defines methods for implementing application-specific logic for the Closure Control Cluster. */ class Delegate { @@ -79,7 +79,7 @@ class Delegate virtual CHIP_ERROR EndCurrentErrorListRead() = 0; protected: - EndpointId mEndpointId = 0; + EndpointId mEndpointId = chip::kInvalidEndpointId; }; enum class OptionalAttributes : uint32_t @@ -90,10 +90,17 @@ enum class OptionalAttributes : uint32_t class Instance : public AttributeAccessInterface, public CommandHandlerInterface { public: - Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs, - ClusterId aClusterId) : - AttributeAccessInterface(MakeOptional(aEndpointId), Id), - CommandHandlerInterface(MakeOptional(aEndpointId), Id), mDelegate(aDelegate), mClusterId(aClusterId), mFeature(aFeature), + /** + * @brief Creates a closure control 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[in] aEndpointId The endpoint on which this cluster exists. + * @param[in] aDelegate The Delegate used by this Instance. + * @param[in] aFeature The bitmask value that identifies which features are supported by this instance. + * @param[in] aOptionalAttrs The Enum Value that identifies which optional attributes are supported by this instance. + */ + Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : + AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), + CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ @@ -109,73 +116,75 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface // Attribute setters /** - * Set Main State. - * @param aMainState The Main state that should now be the current one. + * @brief Set Main State. + * @param[in] aMainState The Main state that should now be the current one. * @return CHIP_NO_ERROR if set was successful. */ CHIP_ERROR SetMainState(const MainStateEnum & aMainState); /** - * Set OverallState. - * @param aMainState The OverallState that should now be the current State. + * @brief Set OverallState. + * @param[in] aOverallState The OverallState that should now be the current State. * @return CHIP_NO_ERROR if set was successful. */ CHIP_ERROR SetOverallState(const GenericOverallState & aOverallState); /** - * Set OverallTarget. - * @param aMainState The OverallTarget that should be set. + * @brief Set OverallTarget. + * @param[in] aOverallTarget The OverallTarget that should now be the Overall Target. * @return CHIP_NO_ERROR if set was successful. */ CHIP_ERROR SetOverallTarget(const GenericOverallTarget & aOverallTarget); // Attribute getters /** - * Get Main State. - * @return The Main State. + * @brief Get MainState. + * @return Current MainState. */ MainStateEnum GetMainState() const; /** - * Get OverallState. - * @return The GenericOverallState to fill with the current Overall State + * @brief Get OverallState. + * @return Current OverallState. */ GenericOverallState GetOverallState() const; /** - * Get OverallTarget. - * @return The GenericOverallTarget to fill with the current Overall Target + * @brief Get OverallTarget. + * @return Current OverallTarget. */ GenericOverallTarget GetOverallTarget() const; /** - * @brief Whenever application delegate wants to possibly report a new updated time, - * call this method. The `GetCountdownTime()` method will be called on the delegate. + * @brief Whenever application wants to trigger an update to report a new updated time, + * call this method. The `GetCountdownTime()` method will be called on the application. */ - void UpdateCountdownTimeFromDelegate() { UpdateCountdownTime(/* fromDelegate = */ true); } + inline void UpdateCountdownTimeFromDelegate() { UpdateCountdownTime(/* fromDelegate = */ true); } /** - * This function returns true if the phase value given exists in the PhaseList attribute, otherwise it returns false. + * @brief This function checks if Main State is supported or not based on features supported. + * @param[in] aMainState MainState + * @return true if State is supported, false if State is not supported */ bool IsSupportedState(MainStateEnum aMainState); protected: /** - * Causes reporting/udpating of CountdownTime attribute from driver if sufficient changes have - * occurred (based on Q quality definition for operational state). Calls the Delegate::GetCountdownTime() method. + * @brief Causes reporting/udpating of CountdownTime attribute from driver if sufficient changes have + * occurred (based on Q quality definition for operational state). Calls the Delegate::GetCountdownTime() method. * - * @param fromDelegate true if the change notice was triggered by the delegate, false if internal to cluster logic. + * @param[in] fromDelegate true if the change notice was triggered by the delegate, false if internal to cluster logic. */ void UpdateCountdownTime(bool fromDelegate); /** - * @brief Whenever the cluster logic thinks time should be updated, call this. + * @brief Whenever cluster logic wants to trigger an update to report a new updated time, + * call this method. */ - void UpdateCountdownTimeFromClusterLogic() { UpdateCountdownTime(/* fromDelegate=*/false); } + inline void UpdateCountdownTimeFromClusterLogic() { UpdateCountdownTime(/* fromDelegate=*/false); } private: Delegate & mDelegate; - const ClusterId mClusterId; BitMask mFeature; BitMask mOptionalAttrs; From 45d329401d24727e780ceb39a66621129bd9a834 Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 21 Feb 2025 00:23:48 +0530 Subject: [PATCH 14/24] Addressing PR comments --- .../closure-control-server/closure-control-server.cpp | 7 ++----- .../closure-control-server/closure-control-server.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 0d78406e9f705c..63b5f9e371d6fa 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -241,11 +241,8 @@ CHIP_ERROR Instance::EncodeCurrentErrorList(const AttributeValueEncoder::ListEnc ClosureErrorEnum error; err = mDelegate.GetCurrentErrorListAtIndex(i, error); - if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) - { - // Convert end of list to CHIP_NO_ERROR - ExitNow(err = CHIP_NO_ERROR); - } + // Convert end of list to CHIP_NO_ERROR + VerifyOrExit(err != CHIP_ERROR_PROVIDER_LIST_EXHAUSTED, err = CHIP_NO_ERROR); // Check if another error occurred before trying to encode SuccessOrExit(err); diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index a25b5913caadc3..ab69b5a7366908 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -96,7 +96,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @param[in] aEndpointId The endpoint on which this cluster exists. * @param[in] aDelegate The Delegate used by this Instance. * @param[in] aFeature The bitmask value that identifies which features are supported by this instance. - * @param[in] aOptionalAttrs The Enum Value that identifies which optional attributes are supported by this instance. + * @param[in] aOptionalAttrs The bitmask Value that identifies which optional attributes are supported by this instance. */ Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), From ed605a72769a20c608d52cb5373addcd3c2410d0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 20 Feb 2025 18:56:05 +0000 Subject: [PATCH 15/24] Restyled by clang-format --- .../clusters/closure-control-server/closure-control-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 63b5f9e371d6fa..b6c6025486eb5c 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -74,7 +74,7 @@ bool Instance::IsSupportedState(MainStateEnum aMainState) case MainStateEnum::kPendingFallback: return HasFeature(Feature::kFallback); default: - // Remaining MainState have Mandatory conformance,so will be supported. + // Remaining MainState have Mandatory conformance,so will be supported. return true; } return true; From bd5a0a54080387dbc15fc7525db43944da4641aa Mon Sep 17 00:00:00 2001 From: sabollim Date: Wed, 26 Feb 2025 03:15:11 +0530 Subject: [PATCH 16/24] addressing PR comments --- .../closure-control-cluster-objects.h | 35 ++++--------------- .../closure-control-server.cpp | 13 +++---- .../closure-control-server.h | 30 ++++++++-------- 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index 613e58fe0ed700..0c8c376924c0f9 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -50,22 +50,10 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type void Set(Optional positioningValue = NullOptional, Optional latchingValue = NullOptional, Optional speedValue = NullOptional, Optional extraInfoValue = NullOptional) { - if (positioningValue.HasValue()) - { - positioning = positioningValue; - } - if (latchingValue.HasValue()) - { - latching = latchingValue; - } - if (speedValue.HasValue()) - { - speed = speedValue; - } - if (extraInfoValue.HasValue()) - { - extraInfo = extraInfoValue; - } + positioning = positioningValue; + latching = latchingValue; + speed = speedValue; + extraInfo = extraInfoValue; } bool IsEqual(const Structs::OverallStateStruct::Type & rhs) const @@ -120,18 +108,9 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type void Set(Optional tagPositionValue = NullOptional, Optional tagLatchValue = NullOptional, Optional speedValue = NullOptional) { - if (tagPositionValue.HasValue()) - { - tagPosition = tagPositionValue; - } - if (tagLatchValue.HasValue()) - { - tagLatch = tagLatchValue; - } - if (speedValue.HasValue()) - { - speed = speedValue; - } + tagPosition = tagPositionValue; + tagLatch = tagLatchValue; + speed = speedValue; } bool IsEqual(const Structs::OverallTargetStruct::Type & rhs) const diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index b6c6025486eb5c..bd6814c579ee7e 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -56,7 +56,7 @@ bool Instance::HasFeature(Feature aFeature) const return mFeature.Has(aFeature); } -bool Instance::SupportsOptAttr(OptionalAttributes aOptionalAttrs) const +bool Instance::SupportsOptAttr(OptionalAttribute aOptionalAttrs) const { return mOptionalAttrs.Has(aOptionalAttrs); } @@ -80,7 +80,7 @@ bool Instance::IsSupportedState(MainStateEnum aMainState) return true; } -CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) +CHIP_ERROR Instance::SetMainState(MainStateEnum aMainState) { if (!IsSupportedState(aMainState)) { @@ -91,6 +91,7 @@ CHIP_ERROR Instance::SetMainState(const MainStateEnum & aMainState) { mMainState = aMainState; MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::MainState::Id); + UpdateCountdownTimeFromClusterLogic(); } return CHIP_NO_ERROR; } @@ -124,12 +125,12 @@ MainStateEnum Instance::GetMainState() const return mMainState; } -GenericOverallState Instance::GetOverallState() const +const GenericOverallState & Instance::GetOverallState() const { return mOverallState; } -GenericOverallTarget Instance::GetOverallTarget() const +const GenericOverallTarget & Instance::GetOverallTarget() const { return mOverallTarget; } @@ -170,7 +171,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu { case CountdownTime::Id: // Optional Attribute - if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) + if (SupportsOptAttr(OptionalAttribute::kCountdownTime)) { return aEncoder.Encode(mDelegate.GetCountdownTime()); } @@ -264,7 +265,7 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeVal switch (aPath.mAttributeId) { case CountdownTime::Id: - if (SupportsOptAttr(OptionalAttributes::kCountdownTime)) + if (SupportsOptAttr(OptionalAttribute::kCountdownTime)) { return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite); } diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index ab69b5a7366908..dfb8c3948bd187 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -44,19 +44,20 @@ class Delegate public: virtual ~Delegate() = default; + // Only Cluster Instance should be calling the SetEdpointId. void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } EndpointId GetEndpointId() { return mEndpointId; } // ------------------------------------------------------------------ // Commands virtual Protocols::InteractionModel::Status Stop() = 0; - virtual Protocols::InteractionModel::Status MoveTo(const Optional tag, const Optional latch, - const Optional speed) = 0; + virtual Protocols::InteractionModel::Status MoveTo(const Optional & tag, const Optional & latch, + const Optional & speed) = 0; virtual Protocols::InteractionModel::Status Calibrate() = 0; - virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional restingProcedure, - const Optional triggerCondition, - const Optional triggerPosition, - const Optional waitingDelay) = 0; + virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional & restingProcedure, + const Optional & triggerCondition, + const Optional & triggerPosition, + const Optional & waitingDelay) = 0; virtual Protocols::InteractionModel::Status CancelFallback() = 0; // ------------------------------------------------------------------ @@ -71,8 +72,9 @@ class Delegate /* These functions are called by the ReadAttribute handler to iterate through lists * The cluster server will call StartRead to allow the delegate to create a temporary * lock on the data. + * The delegate is expected to send CHIP_ERROR_PROVIDER_LIST_EXHAUSTED to notify end of list. * The delegate is expected to not change these values once StartRead has been called - * until the EndRead() has been called (e.g. releasing a lock on the data) + * until the EndRead() has been called (i.e. releasing a lock on the data) */ virtual CHIP_ERROR StartCurrentErrorListRead() = 0; virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t, ClosureErrorEnum &) = 0; @@ -82,7 +84,7 @@ class Delegate EndpointId mEndpointId = chip::kInvalidEndpointId; }; -enum class OptionalAttributes : uint32_t +enum class OptionalAttribute : uint32_t { kCountdownTime = 0x1 }; @@ -98,7 +100,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @param[in] aFeature The bitmask value that identifies which features are supported by this instance. * @param[in] aOptionalAttrs The bitmask Value that identifies which optional attributes are supported by this instance. */ - Instance(EndpointId aEndpointId, Delegate & aDelegate, Feature aFeature, OptionalAttributes aOptionalAttrs) : + Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeature, BitMask aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeature(aFeature), mOptionalAttrs(aOptionalAttrs) @@ -112,7 +114,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface void Shutdown(); bool HasFeature(Feature aFeature) const; - bool SupportsOptAttr(OptionalAttributes aOptionalAttrs) const; + bool SupportsOptAttr(OptionalAttribute aOptionalAttrs) const; // Attribute setters /** @@ -120,7 +122,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @param[in] aMainState The Main state that should now be the current one. * @return CHIP_NO_ERROR if set was successful. */ - CHIP_ERROR SetMainState(const MainStateEnum & aMainState); + CHIP_ERROR SetMainState(MainStateEnum aMainState); /** * @brief Set OverallState. @@ -147,13 +149,13 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @brief Get OverallState. * @return Current OverallState. */ - GenericOverallState GetOverallState() const; + const GenericOverallState & GetOverallState() const; /** * @brief Get OverallTarget. * @return Current OverallTarget. */ - GenericOverallTarget GetOverallTarget() const; + const GenericOverallTarget & GetOverallTarget() const; /** * @brief Whenever application wants to trigger an update to report a new updated time, @@ -186,7 +188,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface private: Delegate & mDelegate; BitMask mFeature; - BitMask mOptionalAttrs; + BitMask mOptionalAttrs; app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; MainStateEnum mMainState; From afae064e955b99c9c809b6b826701c8f99248dea Mon Sep 17 00:00:00 2001 From: sabollim Date: Wed, 26 Feb 2025 13:29:34 +0530 Subject: [PATCH 17/24] changing IsEqual to operator== --- .../closure-control-server/closure-control-cluster-objects.h | 4 ++-- .../closure-control-server/closure-control-server.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index 0c8c376924c0f9..fe98d80c24d5ed 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -56,7 +56,7 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type extraInfo = extraInfoValue; } - bool IsEqual(const Structs::OverallStateStruct::Type & rhs) const + bool operator==(const Structs::OverallStateStruct::Type & rhs) const { if (positioning.HasValue() != rhs.positioning.HasValue() || latching.HasValue() != rhs.latching.HasValue() || speed.HasValue() != rhs.speed.HasValue() || extraInfo.HasValue() != rhs.extraInfo.HasValue()) @@ -113,7 +113,7 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type speed = speedValue; } - bool IsEqual(const Structs::OverallTargetStruct::Type & rhs) const + bool operator==(const Structs::OverallTargetStruct::Type & rhs) const { if (tagPosition.HasValue() != rhs.tagPosition.HasValue() || tagLatch.HasValue() != rhs.tagLatch.HasValue() || speed.HasValue() != rhs.speed.HasValue()) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index bd6814c579ee7e..5bda7a9a3521cb 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -99,7 +99,7 @@ CHIP_ERROR Instance::SetMainState(MainStateEnum aMainState) CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { // If the overall target state has changed, trigger the attribute change callback - if (!mOverallState.IsEqual(aOverallState)) + if (!(mOverallState == aOverallState)) { mOverallState = aOverallState; MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::OverallState::Id); @@ -111,7 +111,7 @@ CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) CHIP_ERROR Instance::SetOverallTarget(const GenericOverallTarget & aOverallTarget) { // If the overall target state has changed, trigger the attribute change callback - if (!mOverallTarget.IsEqual(aOverallTarget)) + if (!(mOverallTarget == aOverallTarget)) { mOverallTarget = aOverallTarget; MatterReportingAttributeChangeCallback(mDelegate.GetEndpointId(), ClosureControl::Id, Attributes::OverallTarget::Id); From ba8d87ceb08cd20fa0d121091ff15f90e57d6b30 Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 28 Feb 2025 01:22:05 +0530 Subject: [PATCH 18/24] Addressing PR comments --- .../closure-control-cluster-objects.h | 46 +------------------ .../closure-control-server.cpp | 4 +- .../closure-control-server.h | 12 ++--- 3 files changed, 10 insertions(+), 52 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index fe98d80c24d5ed..726a1aa6deb7f4 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -58,30 +58,7 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type bool operator==(const Structs::OverallStateStruct::Type & rhs) const { - if (positioning.HasValue() != rhs.positioning.HasValue() || latching.HasValue() != rhs.latching.HasValue() || - speed.HasValue() != rhs.speed.HasValue() || extraInfo.HasValue() != rhs.extraInfo.HasValue()) - { - return false; - } - - if (positioning.HasValue() && positioning.Value() != rhs.positioning.Value()) - { - return false; - } - if (latching.HasValue() && latching.Value() != rhs.latching.Value()) - { - return false; - } - if (speed.HasValue() && speed.Value() != rhs.speed.Value()) - { - return false; - } - if (extraInfo.HasValue() && extraInfo.Value() != rhs.extraInfo.Value()) - { - return false; - } - - return true; + return positioning == rhs.positioning && latching == rhs.latching && speed == rhs.speed && extraInfo == rhs.extraInfo; } }; @@ -115,26 +92,7 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type bool operator==(const Structs::OverallTargetStruct::Type & rhs) const { - if (tagPosition.HasValue() != rhs.tagPosition.HasValue() || tagLatch.HasValue() != rhs.tagLatch.HasValue() || - speed.HasValue() != rhs.speed.HasValue()) - { - return false; - } - - if (tagPosition.HasValue() && tagPosition.Value() != rhs.tagPosition.Value()) - { - return false; - } - if (tagLatch.HasValue() && tagLatch.Value() != rhs.tagLatch.Value()) - { - return false; - } - if (speed.HasValue() && speed.Value() != rhs.speed.Value()) - { - return false; - } - - return true; + return tagPosition == rhs.tagPosition && tagLatch == rhs.tagLatch && speed == rhs.speed; } }; diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 5bda7a9a3521cb..992d4c8a6b7ed9 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -51,9 +51,9 @@ void Instance::Shutdown() AttributeAccessInterfaceRegistry::Instance().Unregister(this); } -bool Instance::HasFeature(Feature aFeature) const +bool Instance::HasFeature(Feature aFeatures) const { - return mFeature.Has(aFeature); + return mFeature.Has(aFeatures); } bool Instance::SupportsOptAttr(OptionalAttribute aOptionalAttrs) const diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index dfb8c3948bd187..3cc9211ab9698d 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -44,7 +44,7 @@ class Delegate public: virtual ~Delegate() = default; - // Only Cluster Instance should be calling the SetEdpointId. + // Only Cluster Instance should be calling SetEdpointId. void SetEndpointId(EndpointId aEndpoint) { mEndpointId = aEndpoint; } EndpointId GetEndpointId() { return mEndpointId; } @@ -72,11 +72,11 @@ class Delegate /* These functions are called by the ReadAttribute handler to iterate through lists * The cluster server will call StartRead to allow the delegate to create a temporary * lock on the data. - * The delegate is expected to send CHIP_ERROR_PROVIDER_LIST_EXHAUSTED to notify end of list. * The delegate is expected to not change these values once StartRead has been called * until the EndRead() has been called (i.e. releasing a lock on the data) */ virtual CHIP_ERROR StartCurrentErrorListRead() = 0; + // The delegate is expected to return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED to indicate end of list. virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t, ClosureErrorEnum &) = 0; virtual CHIP_ERROR EndCurrentErrorListRead() = 0; @@ -97,12 +97,12 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * this instance to be registered and called by the interaction model at the appropriate times. * @param[in] aEndpointId The endpoint on which this cluster exists. * @param[in] aDelegate The Delegate used by this Instance. - * @param[in] aFeature The bitmask value that identifies which features are supported by this instance. + * @param[in] aFeatures The bitmask value that identifies which features are supported by this instance. * @param[in] aOptionalAttrs The bitmask Value that identifies which optional attributes are supported by this instance. */ - Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeature, BitMask aOptionalAttrs) : + Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeatures, BitMask aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), - CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeature(aFeature), + CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeature(aFeatures), mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ @@ -113,7 +113,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface CHIP_ERROR Init(); void Shutdown(); - bool HasFeature(Feature aFeature) const; + bool HasFeature(Feature aFeatures) const; bool SupportsOptAttr(OptionalAttribute aOptionalAttrs) const; // Attribute setters From 408c94dd3fbb7d2a8268fc248508756315e3de63 Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 28 Feb 2025 01:26:01 +0530 Subject: [PATCH 19/24] Addresssing PR comments --- .../closure-control-server/closure-control-server.cpp | 4 ++-- .../clusters/closure-control-server/closure-control-server.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index 992d4c8a6b7ed9..e2b410a9405d1e 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -53,7 +53,7 @@ void Instance::Shutdown() bool Instance::HasFeature(Feature aFeatures) const { - return mFeature.Has(aFeatures); + return mFeatures.Has(aFeatures); } bool Instance::SupportsOptAttr(OptionalAttribute aOptionalAttrs) const @@ -226,7 +226,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu /* FeatureMap - is held locally */ case FeatureMap::Id: - return aEncoder.Encode(mFeature); + return aEncoder.Encode(mFeatures); } /* Allow all other unhandled attributes to fall through to Ember */ return CHIP_NO_ERROR; diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 3cc9211ab9698d..2f7654332be6bf 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -102,7 +102,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface */ Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeatures, BitMask aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), - CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeature(aFeatures), + CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeatures(aFeatures), mOptionalAttrs(aOptionalAttrs) { /* set the base class delegates endpointId */ @@ -187,7 +187,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface private: Delegate & mDelegate; - BitMask mFeature; + BitMask mFeatures; BitMask mOptionalAttrs; app::QuieterReportingAttribute mCountdownTime{ DataModel::NullNullable }; From b4f685ea752dd8594dda0d07d824f5c5718ba1ff Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 28 Feb 2025 01:32:17 +0530 Subject: [PATCH 20/24] Removing Fallback feature attribute and commands as FB feature is removed from spec --- .../closure-control-server.cpp | 84 +------------------ .../closure-control-server.h | 16 +--- 2 files changed, 4 insertions(+), 96 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index e2b410a9405d1e..b47505d3a852bd 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -188,47 +188,12 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu case OverallTarget::Id: return aEncoder.Encode(GetOverallTarget()); - - case RestingProcedure::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetRestingProcedure()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - - case TriggerCondition::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetTriggerCondition()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - - case TriggerPosition::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetTriggerPosition()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - - case WaitingDelay::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetWaitingDelay()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - - case KickoffTimer::Id: - if (HasFeature(Feature::kFallback)) - { - return aEncoder.Encode(mDelegate.GetKickoffTimer()); - } - return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); - + /* FeatureMap - is held locally */ case FeatureMap::Id: return aEncoder.Encode(mFeatures); } - /* Allow all other unhandled attributes to fall through to Ember */ + return CHIP_NO_ERROR; } @@ -316,29 +281,6 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); } break; - case ConfigureFallback::Id: - if (HasFeature(Feature::kFallback)) - { - HandleCommand(handlerContext, [this](HandlerContext & ctx, const auto & commandData) { - HandleConfigureFallback(ctx, commandData); - }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - break; - case CancelFallback::Id: - if (HasFeature(Feature::kFallback)) - { - HandleCommand( - handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleCancelFallback(ctx, commandData); }); - } - else - { - handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::UnsupportedCommand); - } - break; } } @@ -372,28 +314,6 @@ void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate:: ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } -void Instance::HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData) -{ - const Optional restingProcedure = commandData.restingProcedure; - const Optional triggerCondition = commandData.triggerCondition; - const Optional triggerPosition = commandData.triggerPosition; - const Optional waitingDelay = commandData.waitingDelay; - - // Call the delegate - Status status = mDelegate.ConfigureFallback(restingProcedure, triggerCondition, triggerPosition, waitingDelay); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); -} - -void Instance::HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData) -{ - // No parameters for this command - // Call the delegate - Status status = mDelegate.CancelFallback(); - - ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); -} - } // namespace ClosureControl } // namespace Clusters } // namespace app diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 2f7654332be6bf..0865501aabe0fc 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -50,24 +50,14 @@ class Delegate // ------------------------------------------------------------------ // Commands - virtual Protocols::InteractionModel::Status Stop() = 0; + virtual Protocols::InteractionModel::Status Stop() = 0; virtual Protocols::InteractionModel::Status MoveTo(const Optional & tag, const Optional & latch, const Optional & speed) = 0; - virtual Protocols::InteractionModel::Status Calibrate() = 0; - virtual Protocols::InteractionModel::Status ConfigureFallback(const Optional & restingProcedure, - const Optional & triggerCondition, - const Optional & triggerPosition, - const Optional & waitingDelay) = 0; - virtual Protocols::InteractionModel::Status CancelFallback() = 0; + virtual Protocols::InteractionModel::Status Calibrate() = 0; // ------------------------------------------------------------------ // Get attribute methods virtual DataModel::Nullable GetCountdownTime() = 0; - virtual RestingProcedureEnum GetRestingProcedure() = 0; - virtual TriggerConditionEnum GetTriggerCondition() = 0; - virtual TriggerPositionEnum GetTriggerPosition() = 0; - virtual uint32_t GetWaitingDelay() = 0; - virtual uint32_t GetKickoffTimer() = 0; /* These functions are called by the ReadAttribute handler to iterate through lists * The cluster server will call StartRead to allow the delegate to create a temporary @@ -207,8 +197,6 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface void HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData); void HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData); void HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData); - void HandleConfigureFallback(HandlerContext & ctx, const Commands::ConfigureFallback::DecodableType & commandData); - void HandleCancelFallback(HandlerContext & ctx, const Commands::CancelFallback::DecodableType & commandData); }; } // namespace ClosureControl From 5f8858c8c5ade02050cb7fb024f8c814f78ea494 Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 28 Feb 2025 02:00:18 +0530 Subject: [PATCH 21/24] Addressing PR comments --- .../closure-control-server.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index b47505d3a852bd..e49871fd1ac519 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -98,7 +98,7 @@ CHIP_ERROR Instance::SetMainState(MainStateEnum aMainState) CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) { - // If the overall target state has changed, trigger the attribute change callback + // If the overall state has changed, trigger the attribute change callback if (!(mOverallState == aOverallState)) { mOverallState = aOverallState; @@ -110,7 +110,7 @@ CHIP_ERROR Instance::SetOverallState(const GenericOverallState & aOverallState) CHIP_ERROR Instance::SetOverallTarget(const GenericOverallTarget & aOverallTarget) { - // If the overall target state has changed, trigger the attribute change callback + // If the overall target has changed, trigger the attribute change callback if (!(mOverallTarget == aOverallTarget)) { mOverallTarget = aOverallTarget; @@ -241,9 +241,6 @@ CHIP_ERROR Instance::Write(const ConcreteDataAttributePath & aPath, AttributeVal case OverallTarget::Id: return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite); default: - // Unknown attribute; return error. None of the other attributes for - // this cluster are writable, so should not be ending up in this code to - // start with. return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); } } @@ -286,8 +283,6 @@ void Instance::InvokeCommand(HandlerContext & handlerContext) void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableType & commandData) { - // No parameters for this command - // Call the delegate Status status = mDelegate.Stop(); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); @@ -295,20 +290,13 @@ void Instance::HandleStop(HandlerContext & ctx, const Commands::Stop::DecodableT void Instance::HandleMoveTo(HandlerContext & ctx, const Commands::MoveTo::DecodableType & commandData) { - const Optional tag = commandData.tag; - const Optional latch = commandData.latch; - const Optional speed = commandData.speed; - - // Call the delegate - Status status = mDelegate.MoveTo(tag, latch, speed); + Status status = mDelegate.MoveTo(commandData.tag, commandData.latch, commandData.speed); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); } void Instance::HandleCalibrate(HandlerContext & ctx, const Commands::Calibrate::DecodableType & commandData) { - // No parameters for this command - // Call the delegate Status status = mDelegate.Calibrate(); ctx.mCommandHandler.AddStatus(ctx.mRequestPath, status); From c2825992a0d10ba8064e8e4f8e2d35f1ad892d7f Mon Sep 17 00:00:00 2001 From: sabollim Date: Fri, 28 Feb 2025 02:29:04 +0530 Subject: [PATCH 22/24] Updating countdonwtime quiet reporting policy --- .../clusters/closure-control-server/closure-control-server.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 0865501aabe0fc..8b614a80c634e1 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -97,6 +97,10 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface { /* set the base class delegates endpointId */ mDelegate.SetEndpointId(aEndpointId); + /* set Countdown Time quiet reporting policy as per reporting requirements in specification */ + mCountdownTime.policy() + .Set(QuieterReportingPolicyEnum::kMarkDirtyOnIncrement) + .Set(QuieterReportingPolicyEnum::kMarkDirtyOnChangeToFromZero); } ~Instance() { Shutdown(); } From acb1c5b764069a4769538ad06ea15b3022eeb3b6 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 27 Feb 2025 21:01:09 +0000 Subject: [PATCH 23/24] Restyled by whitespace --- .../closure-control-server/closure-control-server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index e49871fd1ac519..be657339b7f5a2 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -188,12 +188,12 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu case OverallTarget::Id: return aEncoder.Encode(GetOverallTarget()); - + /* FeatureMap - is held locally */ case FeatureMap::Id: return aEncoder.Encode(mFeatures); } - + return CHIP_NO_ERROR; } From a1766e6273085ec71a31d18d0b73866ef7d04298 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 27 Feb 2025 21:01:14 +0000 Subject: [PATCH 24/24] Restyled by clang-format --- .../closure-control-cluster-objects.h | 14 +++++++------- .../closure-control-server.cpp | 2 +- .../closure-control-server.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h index 726a1aa6deb7f4..4405cd505b8858 100644 --- a/src/app/clusters/closure-control-server/closure-control-cluster-objects.h +++ b/src/app/clusters/closure-control-server/closure-control-cluster-objects.h @@ -51,14 +51,14 @@ struct GenericOverallState : public Structs::OverallStateStruct::Type Optional speedValue = NullOptional, Optional extraInfoValue = NullOptional) { positioning = positioningValue; - latching = latchingValue; - speed = speedValue; - extraInfo = extraInfoValue; + latching = latchingValue; + speed = speedValue; + extraInfo = extraInfoValue; } bool operator==(const Structs::OverallStateStruct::Type & rhs) const { - return positioning == rhs.positioning && latching == rhs.latching && speed == rhs.speed && extraInfo == rhs.extraInfo; + return positioning == rhs.positioning && latching == rhs.latching && speed == rhs.speed && extraInfo == rhs.extraInfo; } }; @@ -86,13 +86,13 @@ struct GenericOverallTarget : public Structs::OverallTargetStruct::Type Optional speedValue = NullOptional) { tagPosition = tagPositionValue; - tagLatch = tagLatchValue; - speed = speedValue; + tagLatch = tagLatchValue; + speed = speedValue; } bool operator==(const Structs::OverallTargetStruct::Type & rhs) const { - return tagPosition == rhs.tagPosition && tagLatch == rhs.tagLatch && speed == rhs.speed; + return tagPosition == rhs.tagPosition && tagLatch == rhs.tagLatch && speed == rhs.speed; } }; diff --git a/src/app/clusters/closure-control-server/closure-control-server.cpp b/src/app/clusters/closure-control-server/closure-control-server.cpp index be657339b7f5a2..9e4290378a7634 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.cpp +++ b/src/app/clusters/closure-control-server/closure-control-server.cpp @@ -80,7 +80,7 @@ bool Instance::IsSupportedState(MainStateEnum aMainState) return true; } -CHIP_ERROR Instance::SetMainState(MainStateEnum aMainState) +CHIP_ERROR Instance::SetMainState(MainStateEnum aMainState) { if (!IsSupportedState(aMainState)) { diff --git a/src/app/clusters/closure-control-server/closure-control-server.h b/src/app/clusters/closure-control-server/closure-control-server.h index 8b614a80c634e1..f5324251f802fc 100644 --- a/src/app/clusters/closure-control-server/closure-control-server.h +++ b/src/app/clusters/closure-control-server/closure-control-server.h @@ -65,7 +65,7 @@ class Delegate * The delegate is expected to not change these values once StartRead has been called * until the EndRead() has been called (i.e. releasing a lock on the data) */ - virtual CHIP_ERROR StartCurrentErrorListRead() = 0; + virtual CHIP_ERROR StartCurrentErrorListRead() = 0; // The delegate is expected to return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED to indicate end of list. virtual CHIP_ERROR GetCurrentErrorListAtIndex(size_t, ClosureErrorEnum &) = 0; virtual CHIP_ERROR EndCurrentErrorListRead() = 0; @@ -90,7 +90,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface * @param[in] aFeatures The bitmask value that identifies which features are supported by this instance. * @param[in] aOptionalAttrs The bitmask Value that identifies which optional attributes are supported by this instance. */ - Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeatures, BitMask aOptionalAttrs) : + Instance(EndpointId aEndpointId, Delegate & aDelegate, BitMask aFeatures, BitMask aOptionalAttrs) : AttributeAccessInterface(MakeOptional(aEndpointId), ClosureControl::Id), CommandHandlerInterface(MakeOptional(aEndpointId), ClosureControl::Id), mDelegate(aDelegate), mFeatures(aFeatures), mOptionalAttrs(aOptionalAttrs) @@ -99,8 +99,8 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface mDelegate.SetEndpointId(aEndpointId); /* set Countdown Time quiet reporting policy as per reporting requirements in specification */ mCountdownTime.policy() - .Set(QuieterReportingPolicyEnum::kMarkDirtyOnIncrement) - .Set(QuieterReportingPolicyEnum::kMarkDirtyOnChangeToFromZero); + .Set(QuieterReportingPolicyEnum::kMarkDirtyOnIncrement) + .Set(QuieterReportingPolicyEnum::kMarkDirtyOnChangeToFromZero); } ~Instance() { Shutdown(); }