From a228f2dca99eee7584d759f885c4271c8f067173 Mon Sep 17 00:00:00 2001 From: David Rempel Date: Fri, 9 Feb 2024 12:33:25 -0800 Subject: [PATCH] Better documentation, a set of braces I missed last time around, and added an extra header include. --- .../src/energy-preference-delegate.cpp | 6 +-- .../energy-preference-server.cpp | 27 +++++----- .../energy-preference-server.h | 50 +++++++++++++++---- 3 files changed, 59 insertions(+), 24 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp b/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp index 59e5fceee88980..aaaf5d53a224e3 100644 --- a/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp @@ -34,7 +34,7 @@ struct EPrefDelegate : public Delegate CHIP_ERROR GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance) override; size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) override; - size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) override; + size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) override; }; EPrefDelegate::EPrefDelegate() : Delegate() @@ -54,7 +54,7 @@ size_t EPrefDelegate::GetNumEnergyBalances(chip::EndpointId aEndpoint) return (ArraySize(gsEnergyBalances)); } -size_t EPrefDelegate::GetNumLowPowerModes(chip::EndpointId aEndpoint) +size_t EPrefDelegate::GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) { return (ArraySize(gsEnergyBalances)); } @@ -87,7 +87,7 @@ EPrefDelegate::GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aInde CHIP_ERROR EPrefDelegate::GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance) { - if (aIndex < GetNumLowPowerModes(aEndpoint)) + if (aIndex < GetNumLowPowerModeSensitivities(aEndpoint)) { balance = gsPowerBalances[aIndex]; return CHIP_NO_ERROR; diff --git a/src/app/clusters/energy-preference-server/energy-preference-server.cpp b/src/app/clusters/energy-preference-server/energy-preference-server.cpp index dd520600a59eb3..7d34c9f5953bdd 100644 --- a/src/app/clusters/energy-preference-server/energy-preference-server.cpp +++ b/src/app/clusters/energy-preference-server/energy-preference-server.cpp @@ -17,13 +17,14 @@ #include "energy-preference-server.h" -#include +#include // Needed for registerAttributeAccessOverride #include #include #include #include #include +#include // added in case we ever don't need app/util/attribute-storage.h at some point. #include #include @@ -34,7 +35,7 @@ using namespace chip::app::Clusters::EnergyPreference; using namespace chip::app::Clusters::EnergyPreference::Structs; using namespace chip::app::Clusters::EnergyPreference::Attributes; -using imcode = Protocols::InteractionModel::Status; +using Status = Protocols::InteractionModel::Status; namespace { @@ -159,7 +160,7 @@ Delegate * GetDelegate() } // Set matter energy preferences delegate -Protocols::InteractionModel::Status +Status MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) { @@ -171,43 +172,45 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAtt const bool lowPowerSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0); if (delegate == nullptr) - return imcode::UnsupportedWrite; + { + return Status::UnsupportedWrite; + } switch (attributePath.mAttributeId) { case CurrentEnergyBalance::Id: { if (balanceSupported == false) { - return imcode::UnsupportedAttribute; + return Status::UnsupportedAttribute; } uint8_t index = Encoding::Get8(value); size_t arraySize = delegate->GetNumEnergyBalances(endpoint); if (index >= arraySize) { - return imcode::ConstraintError; + return Status::ConstraintError; } - return imcode::Success; + return Status::Success; } case CurrentLowPowerModeSensitivity::Id: { if (lowPowerSupported == false) { - return imcode::UnsupportedAttribute; + return Status::UnsupportedAttribute; } uint8_t index = Encoding::Get8(value); - size_t arraySize = delegate->GetNumLowPowerModes(endpoint); + size_t arraySize = delegate->GetNumLowPowerModeSensitivities(endpoint); if (index >= arraySize) { - return imcode::ConstraintError; + return Status::ConstraintError; } - return imcode::Success; + return Status::Success; } default: - return imcode::Success; + return Status::Success; } } diff --git a/src/app/clusters/energy-preference-server/energy-preference-server.h b/src/app/clusters/energy-preference-server/energy-preference-server.h index dab4c26a7c3c06..fe3ef674fe2a2e 100644 --- a/src/app/clusters/energy-preference-server/energy-preference-server.h +++ b/src/app/clusters/energy-preference-server/energy-preference-server.h @@ -29,26 +29,58 @@ namespace chip::app::Clusters::EnergyPreference struct Delegate { + //Note: This delegate does not handle the "Current Active" indexes attributes storage. + //eg: Current Energy Balance and Current Low Power Mode Sensitivity. These can be handled using + //ember built in storage, or via the external callbacks as desired by the implementer. + virtual ~Delegate() {} - // Gives a reference to the energy balance struct at aIndex - // Balance struct should exist for the life time of the matter server + /** + * Get an Energy Balance. + * @param aEndpoint The endpoint to query. + * @param aIndex The index of the balance, with 0 representing the first one. + * @param aOutBalance The BalanceStruct to copy the data into. + * @return CHIP_ERROR_NOT_FOUND if the index is out of range. + */ virtual CHIP_ERROR GetEnergyBalanceAtIndex(chip::EndpointId aEndpoint, size_t aIndex, - chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0; + chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0; - // Gives a reference to the at aIndex + /** + * Get an Energy Priority. + * @param aEndpoint The endpoint to query. + * @param aIndex The index of the priority, with 0 representing the first one. + * @param aOutPriority The EnergyPriorityEnum to copy the data into. + * @return CHIP_ERROR_NOT_FOUND if the index is out of range. + */ virtual CHIP_ERROR GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, - chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & priority) = 0; + chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & aOutPriority) = 0; - // Gives a reference to the low power mode sensitivity balance struct at aIndex - // Balance struct should exist for the life time of the matter server + /** + * Get a Power Sensitity Balance Struct. + * @param aEndpoint The endpoint to query. + * @param aIndex The index of the priority, with 0 representing the first one. + * @param aOutBalance The BalanceStruct to copy the data into. + * @return CHIP_ERROR_NOT_FOUND if the index is out of range. + */ virtual CHIP_ERROR GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, - chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0; + chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0; + + /** + * Get the number of energy balances this endpoint has. + * @param aEndpoint The endpoint to query. + * @return the number of balance structs in the list. + */ virtual size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) = 0; - virtual size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) = 0; + + /** + * Get the number of low power mode sensitivities this endpoint has. + * @param aEndpoint The endpoint to query. + * @return the number of balance structs in the list. + */ + virtual size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) = 0; }; void SetDelegate(Delegate * aDelegate);