Skip to content

Commit a228f2d

Browse files
committed
Better documentation, a set of braces I missed last time around, and
added an extra header include.
1 parent d0bca83 commit a228f2d

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct EPrefDelegate : public Delegate
3434
CHIP_ERROR GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance) override;
3535

3636
size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) override;
37-
size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) override;
37+
size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) override;
3838
};
3939

4040
EPrefDelegate::EPrefDelegate() : Delegate()
@@ -54,7 +54,7 @@ size_t EPrefDelegate::GetNumEnergyBalances(chip::EndpointId aEndpoint)
5454
return (ArraySize(gsEnergyBalances));
5555
}
5656

57-
size_t EPrefDelegate::GetNumLowPowerModes(chip::EndpointId aEndpoint)
57+
size_t EPrefDelegate::GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint)
5858
{
5959
return (ArraySize(gsEnergyBalances));
6060
}
@@ -87,7 +87,7 @@ EPrefDelegate::GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aInde
8787
CHIP_ERROR
8888
EPrefDelegate::GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex, BalanceStruct::Type & balance)
8989
{
90-
if (aIndex < GetNumLowPowerModes(aEndpoint))
90+
if (aIndex < GetNumLowPowerModeSensitivities(aEndpoint))
9191
{
9292
balance = gsPowerBalances[aIndex];
9393
return CHIP_NO_ERROR;

src/app/clusters/energy-preference-server/energy-preference-server.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
#include "energy-preference-server.h"
1919

20-
#include <app/util/attribute-storage.h>
20+
#include <app/util/attribute-storage.h> // Needed for registerAttributeAccessOverride
2121

2222
#include <app-common/zap-generated/attributes/Accessors.h>
2323
#include <app-common/zap-generated/callback.h>
2424
#include <app-common/zap-generated/cluster-objects.h>
2525
#include <app-common/zap-generated/ids/Attributes.h>
2626
#include <app/ConcreteAttributePath.h>
27+
#include <app/AttributeAccessInterface.h> // added in case we ever don't need app/util/attribute-storage.h at some point.
2728
#include <app/util/error-mapping.h>
2829
#include <lib/core/CHIPEncoding.h>
2930

@@ -34,7 +35,7 @@ using namespace chip::app::Clusters::EnergyPreference;
3435
using namespace chip::app::Clusters::EnergyPreference::Structs;
3536
using namespace chip::app::Clusters::EnergyPreference::Attributes;
3637

37-
using imcode = Protocols::InteractionModel::Status;
38+
using Status = Protocols::InteractionModel::Status;
3839

3940
namespace {
4041

@@ -159,7 +160,7 @@ Delegate * GetDelegate()
159160

160161
} // Set matter energy preferences delegate
161162

162-
Protocols::InteractionModel::Status
163+
Status
163164
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAttributePath & attributePath,
164165
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
165166
{
@@ -171,43 +172,45 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAtt
171172
const bool lowPowerSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0);
172173

173174
if (delegate == nullptr)
174-
return imcode::UnsupportedWrite;
175+
{
176+
return Status::UnsupportedWrite;
177+
}
175178

176179
switch (attributePath.mAttributeId)
177180
{
178181
case CurrentEnergyBalance::Id: {
179182
if (balanceSupported == false)
180183
{
181-
return imcode::UnsupportedAttribute;
184+
return Status::UnsupportedAttribute;
182185
}
183186

184187
uint8_t index = Encoding::Get8(value);
185188
size_t arraySize = delegate->GetNumEnergyBalances(endpoint);
186189
if (index >= arraySize)
187190
{
188-
return imcode::ConstraintError;
191+
return Status::ConstraintError;
189192
}
190193

191-
return imcode::Success;
194+
return Status::Success;
192195
}
193196

194197
case CurrentLowPowerModeSensitivity::Id: {
195198
if (lowPowerSupported == false)
196199
{
197-
return imcode::UnsupportedAttribute;
200+
return Status::UnsupportedAttribute;
198201
}
199202

200203
uint8_t index = Encoding::Get8(value);
201-
size_t arraySize = delegate->GetNumLowPowerModes(endpoint);
204+
size_t arraySize = delegate->GetNumLowPowerModeSensitivities(endpoint);
202205
if (index >= arraySize)
203206
{
204-
return imcode::ConstraintError;
207+
return Status::ConstraintError;
205208
}
206209

207-
return imcode::Success;
210+
return Status::Success;
208211
}
209212
default:
210-
return imcode::Success;
213+
return Status::Success;
211214
}
212215
}
213216

src/app/clusters/energy-preference-server/energy-preference-server.h

+41-9
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,58 @@ namespace chip::app::Clusters::EnergyPreference
2929

3030
struct Delegate
3131
{
32+
//Note: This delegate does not handle the "Current Active" indexes attributes storage.
33+
//eg: Current Energy Balance and Current Low Power Mode Sensitivity. These can be handled using
34+
//ember built in storage, or via the external callbacks as desired by the implementer.
35+
3236
virtual ~Delegate() {}
3337

34-
// Gives a reference to the energy balance struct at aIndex
35-
// Balance struct should exist for the life time of the matter server
38+
/**
39+
* Get an Energy Balance.
40+
* @param aEndpoint The endpoint to query.
41+
* @param aIndex The index of the balance, with 0 representing the first one.
42+
* @param aOutBalance The BalanceStruct to copy the data into.
43+
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
44+
*/
3645
virtual CHIP_ERROR GetEnergyBalanceAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
37-
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
46+
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0;
3847

39-
// Gives a reference to the at aIndex
48+
/**
49+
* Get an Energy Priority.
50+
* @param aEndpoint The endpoint to query.
51+
* @param aIndex The index of the priority, with 0 representing the first one.
52+
* @param aOutPriority The EnergyPriorityEnum to copy the data into.
53+
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
54+
*/
4055
virtual CHIP_ERROR GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
41-
chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & priority) = 0;
56+
chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & aOutPriority) = 0;
4257

4358

44-
// Gives a reference to the low power mode sensitivity balance struct at aIndex
45-
// Balance struct should exist for the life time of the matter server
59+
/**
60+
* Get a Power Sensitity Balance Struct.
61+
* @param aEndpoint The endpoint to query.
62+
* @param aIndex The index of the priority, with 0 representing the first one.
63+
* @param aOutBalance The BalanceStruct to copy the data into.
64+
* @return CHIP_ERROR_NOT_FOUND if the index is out of range.
65+
*/
4666
virtual CHIP_ERROR
4767
GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
48-
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
68+
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & aOutBalance) = 0;
69+
4970

71+
/**
72+
* Get the number of energy balances this endpoint has.
73+
* @param aEndpoint The endpoint to query.
74+
* @return the number of balance structs in the list.
75+
*/
5076
virtual size_t GetNumEnergyBalances(chip::EndpointId aEndpoint) = 0;
51-
virtual size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) = 0;
77+
78+
/**
79+
* Get the number of low power mode sensitivities this endpoint has.
80+
* @param aEndpoint The endpoint to query.
81+
* @return the number of balance structs in the list.
82+
*/
83+
virtual size_t GetNumLowPowerModeSensitivities(chip::EndpointId aEndpoint) = 0;
5284
};
5385

5486
void SetDelegate(Delegate * aDelegate);

0 commit comments

Comments
 (0)