Skip to content

Commit de798bb

Browse files
committed
Revert Chef stubs.cpp to not using AttributeDelegate
1 parent 8480b14 commit de798bb

File tree

3 files changed

+12
-176
lines changed

3 files changed

+12
-176
lines changed

examples/chef/common/clusters/switch/SwitchDelegate.cpp

-46
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <app/server/Server.h>
2222
#include <app/util/att-storage.h>
2323
#include <platform/PlatformManager.h>
24-
#include "stubs.h"
2524

2625
using namespace chip;
2726
using namespace chip::app;
@@ -135,20 +134,6 @@ void SwitchEventHandler::OnSwitchMultiPressCompleteHandler(uint8_t previousPosit
135134

136135
static std::map<int, SwitchEventHandler *> gSwitchEventHandlers{};
137136

138-
139-
class SwitchAttributeDelegate : public AttributeDelegate
140-
{
141-
public:
142-
SwitchAttributeDelegate (ClusterId clusterId) : AttributeDelegate(clusterId) {}
143-
144-
chip::Protocols::InteractionModel::Status PreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) override;
145-
146-
void PostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) override;
147-
148-
private:
149-
};
150-
151-
152137
SwitchEventHandler * GetSwitchEventHandler(EndpointId endpointId)
153138
{
154139
if (gSwitchEventHandlers.find(endpointId) == gSwitchEventHandlers.end()) {
@@ -158,41 +143,10 @@ SwitchEventHandler * GetSwitchEventHandler(EndpointId endpointId)
158143
return gSwitchEventHandlers[endpointId];
159144
}
160145

161-
chip::Protocols::InteractionModel::Status SwitchAttributeDelegate::PreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value)
162-
{
163-
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
164-
printf("\033[41m %s, %d \033[0m \n", __func__, __LINE__);
165-
ChipLogProgress(Zcl, "SwitchAttributeDelegate::PostAttributeChangeCallback Endpoint: %d, Cluster: " ChipLogFormatMEI ", Type: %u, length %u", attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), type, size);
166-
167-
168-
return ret;
169-
}
170-
171-
void SwitchAttributeDelegate::PostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value)
172-
{
173-
printf("\033[41m %s, %d \033[0m \n", __func__, __LINE__);
174-
ChipLogProgress(Zcl, "SwitchAttributeDelegate::PostAttributeChangeCallback Endpoint: %d, Cluster: " ChipLogFormatMEI ", Type: %u, length %u", attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), type, size);
175-
176-
switch (attributePath.mAttributeId) {
177-
case Attributes::CurrentPosition::Id: {
178-
SwitchEventHandler *eventHandler = GetSwitchEventHandler(attributePath.mEndpointId);
179-
uint8_t newPosition = *value;
180-
181-
if (eventHandler) {
182-
eventHandler->OnSwitchLatchedHandler(newPosition);
183-
}
184-
}
185-
break;
186-
default:
187-
break;
188-
}
189-
}
190-
191146
void emberAfSwitchClusterInitCallback(EndpointId endpoint)
192147
{
193148
ChipLogProgress(Zcl, "Chef: emberAfSwitchClusterInitCallback");
194149
gSwitchEventHandlers[endpoint] = new SwitchEventHandler(endpoint);
195-
RegisterApplicationAttributeDelegate(Switch::Id, new SwitchAttributeDelegate(Switch::Id));
196150
printf("\033[44m %s, %d, Switch::ID=%u \033[0m \n", __func__, __LINE__, Switch::Id);
197151
}
198152

examples/chef/common/stubs.cpp

+12-65
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,12 @@
1919
#include "chef-concentration-measurement.h"
2020
#endif
2121

22-
#include "stubs.h"
23-
#include <map>
24-
2522
using chip::app::DataModel::Nullable;
2623

2724
using namespace chip;
2825
using namespace chip::app;
2926
using namespace chip::app::Clusters;
3027

31-
static std::map<ClusterId, AttributeDelegate * > gApplicationAttributeDelegates{};
32-
33-
void chip::app::RegisterApplicationAttributeDelegate(ClusterId clusterId, AttributeDelegate * delegate)
34-
{
35-
// TODO assert (gApplicationAttributeDelegates.find(clusterId) == gApplicationAttributeDelegates.end() )
36-
37-
gApplicationAttributeDelegates[clusterId] = delegate;
38-
39-
}
40-
41-
42-
AttributeDelegate * GetApplicationAttributeDelegate(ClusterId clusterId)
43-
{
44-
if (gApplicationAttributeDelegates.find(clusterId) == gApplicationAttributeDelegates.end()) {
45-
return nullptr;
46-
}
47-
48-
return gApplicationAttributeDelegates[clusterId];
49-
}
50-
51-
5228
Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
5329
const EmberAfAttributeMetadata * attributeMetadata,
5430
uint8_t * buffer, uint16_t maxReadLength)
@@ -137,54 +113,25 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
137113

138114
void emberAfPluginSmokeCoAlarmSelfTestRequestCommand(EndpointId endpointId) {}
139115

140-
141-
chip::Protocols::InteractionModel::Status
142-
MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
143-
uint8_t * value)
144-
{
145-
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
146-
147-
ChipLogProgress(Zcl, "MatterPostAttributeChangeCallback Endpoint: %d, Cluster: " ChipLogFormatMEI ", Type: %u, length %u", attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), type, size);
148-
printf("\033[41m %s, %d \033[0m \n", __func__, __LINE__);
149-
150-
AttributeDelegate * delegate = GetApplicationAttributeDelegate(attributePath.mClusterId);
151-
if (delegate) {
152-
ret = delegate->PreAttributeChangeCallback(attributePath, type, size, value);
153-
}
154-
155-
return ret;
156-
}
157-
158116
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
159117
uint8_t * value)
160118
{
161-
// AttributeId attributeId = attributePath.mAttributeId;
162-
ChipLogProgress(Zcl, "MatterPostAttributeChangeCallback Endpoint: %d, Cluster: " ChipLogFormatMEI ", Type: %u, length %u", attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), type, size);
163-
printf("\033[41m %s, %d \033[0m \n", __func__, __LINE__);
119+
ClusterId clusterId = attributePath.mClusterId;
120+
AttributeId attributeId = attributePath.mAttributeId;
121+
ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));
164122

165-
AttributeDelegate * delegate = GetApplicationAttributeDelegate(attributePath.mClusterId);
166-
if (delegate) {
167-
delegate->PostAttributeChangeCallback(attributePath, type, size, value);
168-
}
169-
170-
#if 0
171-
switch (clusterId) {
172-
case OnOff::Id:
173-
ChipLogProgress(Zcl, "OnOff Cluster attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", ChipLogValueMEI(attributeId),
123+
if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
124+
{
125+
ChipLogProgress(Zcl, "OnOff attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", ChipLogValueMEI(attributeId),
174126
type, *value, size);
175-
break;
176-
case LevelControl::Id:
177-
ChipLogProgress(Zcl, "Level Control Cluster attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
178-
ChipLogValueMEI(attributeId), type, *value, size);
179-
break;
180-
case Switch::Id:
181-
ChipLogProgress(Zcl, "Switch Cluster attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
127+
}
128+
else if (clusterId == LevelControl::Id)
129+
{
130+
ChipLogProgress(Zcl, "Level Control attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
182131
ChipLogValueMEI(attributeId), type, *value, size);
183-
break;
184-
default:
185-
break;
132+
133+
// WIP Apply attribute change to Light
186134
}
187-
#endif
188135
}
189136

190137
/** @brief OnOff Cluster Init

examples/chef/common/stubs.h

-65
This file was deleted.

0 commit comments

Comments
 (0)