Skip to content

Commit 12aa64f

Browse files
committed
Clear associated atomic writes when fabric is removed
1 parent 9a4d415 commit 12aa64f

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/app/clusters/thermostat-server/thermostat-server.cpp

+26-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <app/CommandHandler.h>
2828
#include <app/ConcreteAttributePath.h>
2929
#include <app/ConcreteCommandPath.h>
30+
#include <app/server/Server.h>
3031
#include <lib/core/CHIPEncoding.h>
3132
#include <platform/internal/CHIPDeviceLayerInternal.h>
3233

@@ -112,7 +113,7 @@ void TimerExpiredCallback(System::Layer * systemLayer, void * callbackContext)
112113
{
113114
EndpointId endpoint = static_cast<EndpointId>(reinterpret_cast<uintptr_t>(callbackContext));
114115

115-
Delegate * delegate = GetDelegate(endpoint);
116+
auto delegate = GetDelegate(endpoint);
116117
VerifyOrReturn(delegate != nullptr, ChipLogError(Zcl, "Delegate is null. Unable to handle timer expired"));
117118

118119
delegate->ClearPendingPresetList();
@@ -731,7 +732,7 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
731732
}
732733
break;
733734
case PresetTypes::Id: {
734-
Delegate * delegate = GetDelegate(aPath.mEndpointId);
735+
auto delegate = GetDelegate(aPath.mEndpointId);
735736
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
736737

737738
return aEncoder.EncodeList([delegate](const auto & encoder) -> CHIP_ERROR {
@@ -750,14 +751,14 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
750751
}
751752
break;
752753
case NumberOfPresets::Id: {
753-
Delegate * delegate = GetDelegate(aPath.mEndpointId);
754+
auto delegate = GetDelegate(aPath.mEndpointId);
754755
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
755756

756757
ReturnErrorOnFailure(aEncoder.Encode(delegate->GetNumberOfPresets()));
757758
}
758759
break;
759760
case Presets::Id: {
760-
Delegate * delegate = GetDelegate(aPath.mEndpointId);
761+
auto delegate = GetDelegate(aPath.mEndpointId);
761762
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
762763

763764
auto & subjectDescriptor = aEncoder.GetSubjectDescriptor();
@@ -793,7 +794,7 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
793794
}
794795
break;
795796
case ActivePresetHandle::Id: {
796-
Delegate * delegate = GetDelegate(aPath.mEndpointId);
797+
auto delegate = GetDelegate(aPath.mEndpointId);
797798
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
798799

799800
uint8_t buffer[kPresetHandleSize];
@@ -839,7 +840,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
839840
{
840841
case Presets::Id: {
841842

842-
Delegate * delegate = GetDelegate(endpoint);
843+
auto delegate = GetDelegate(endpoint);
843844
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
844845

845846
// Presets are not editable, return INVALID_IN_STATE.
@@ -924,7 +925,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
924925
return CHIP_NO_ERROR;
925926
}
926927

927-
CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Delegate * delegate, const PresetStruct::Type & preset)
928+
CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * delegate, const PresetStruct::Type & preset)
928929
{
929930
if (!IsValidPresetEntry(preset))
930931
{
@@ -978,6 +979,19 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Delegate * delegate, const
978979
return delegate->AppendToPendingPresetList(preset);
979980
}
980981

982+
void ThermostatAttrAccess::OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
983+
{
984+
for (size_t i = 0; i < ArraySize(mAtomicWriteNodeIds); ++i)
985+
{
986+
auto nodeId = mAtomicWriteNodeIds[i];
987+
if (nodeId.GetFabricIndex() == fabricIndex)
988+
{
989+
mAtomicWriteNodeIds[i] = ScopedNodeId();
990+
mAtomicWriteState[i] = false;
991+
}
992+
}
993+
}
994+
981995
} // namespace Thermostat
982996
} // namespace Clusters
983997
} // namespace app
@@ -1309,7 +1323,7 @@ bool emberAfThermostatClusterSetActivePresetRequestCallback(
13091323
const Clusters::Thermostat::Commands::SetActivePresetRequest::DecodableType & commandData)
13101324
{
13111325
EndpointId endpoint = commandPath.mEndpointId;
1312-
Delegate * delegate = GetDelegate(endpoint);
1326+
auto delegate = GetDelegate(endpoint);
13131327

13141328
if (delegate == nullptr)
13151329
{
@@ -1399,7 +1413,7 @@ void handleAtomicBegin(CommandHandler * commandObj, const ConcreteCommandPath &
13991413
{
14001414
EndpointId endpoint = commandPath.mEndpointId;
14011415

1402-
Delegate * delegate = GetDelegate(endpoint);
1416+
auto delegate = GetDelegate(endpoint);
14031417

14041418
if (delegate == nullptr)
14051419
{
@@ -1585,7 +1599,7 @@ void handleAtomicCommit(CommandHandler * commandObj, const ConcreteCommandPath &
15851599
return;
15861600
}
15871601

1588-
Delegate * delegate = GetDelegate(endpoint);
1602+
auto delegate = GetDelegate(endpoint);
15891603

15901604
if (delegate == nullptr)
15911605
{
@@ -1618,7 +1632,7 @@ void handleAtomicRollback(CommandHandler * commandObj, const ConcreteCommandPath
16181632
return;
16191633
}
16201634

1621-
Delegate * delegate = GetDelegate(endpoint);
1635+
auto delegate = GetDelegate(endpoint);
16221636

16231637
if (delegate == nullptr)
16241638
{
@@ -1895,5 +1909,6 @@ bool emberAfThermostatClusterSetpointRaiseLowerCallback(app::CommandHandler * co
18951909

18961910
void MatterThermostatPluginServerInitCallback()
18971911
{
1912+
Server::GetInstance().GetFabricTable().AddFabricDelegate(&gThermostatAttrAccess);
18981913
registerAttributeAccessOverride(&gThermostatAttrAccess);
18991914
}

src/app/clusters/thermostat-server/thermostat-server.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static constexpr size_t kThermostatEndpointCount =
4040
/**
4141
* @brief Thermostat Attribute Access Interface.
4242
*/
43-
class ThermostatAttrAccess : public chip::app::AttributeAccessInterface
43+
class ThermostatAttrAccess : public chip::app::AttributeAccessInterface, public chip::FabricTable::Delegate
4444
{
4545
public:
4646
ThermostatAttrAccess() : AttributeAccessInterface(Optional<chip::EndpointId>::Missing(), Thermostat::Id) {}
@@ -105,7 +105,9 @@ class ThermostatAttrAccess : public chip::app::AttributeAccessInterface
105105
bool InAtomicWrite(CommandHandler * commandObj, EndpointId endpoint);
106106

107107
private:
108-
CHIP_ERROR AppendPendingPreset(Delegate * delegate, const Structs::PresetStruct::Type & preset);
108+
CHIP_ERROR AppendPendingPreset(Thermostat::Delegate * delegate, const Structs::PresetStruct::Type & preset);
109+
110+
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override;
109111

110112
ScopedNodeId mAtomicWriteNodeIds[kThermostatEndpointCount];
111113
bool mAtomicWriteState[kThermostatEndpointCount];

0 commit comments

Comments
 (0)