|
18 | 18 | #include <app-common/zap-generated/attributes/Accessors.h>
|
19 | 19 | #include <app/util/config.h>
|
20 | 20 |
|
| 21 | +using namespace chip; |
| 22 | +using namespace chip::app; |
21 | 23 | using namespace chip::app::Clusters;
|
22 | 24 | using chip::Protocols::InteractionModel::Status;
|
23 | 25 | template <typename T>
|
24 | 26 | using List = chip::app::DataModel::List<T>;
|
25 | 27 | using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;
|
26 | 28 |
|
27 |
| -#ifdef ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER |
| 29 | +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER |
28 | 30 | #include <chef-rvc-mode-delegate.h>
|
29 | 31 | using namespace chip::app::Clusters::RvcRunMode;
|
30 |
| -static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr; |
31 |
| -static ModeBase::Instance * gRvcRunModeInstance = nullptr; |
| 32 | + |
| 33 | +static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate; |
| 34 | +static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance; |
32 | 35 |
|
33 | 36 | CHIP_ERROR RvcRunModeDelegate::Init()
|
34 | 37 | {
|
@@ -87,40 +90,82 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
|
87 | 90 | return CHIP_NO_ERROR;
|
88 | 91 | }
|
89 | 92 |
|
90 |
| -ModeBase::Instance * RvcRunMode::Instance() |
| 93 | +void RvcRunMode::Shutdown() |
91 | 94 | {
|
92 |
| - return gRvcRunModeInstance; |
| 95 | + gRvcRunModeInstance.reset(); |
| 96 | + gRvcRunModeDelegate.reset(); |
93 | 97 | }
|
94 | 98 |
|
95 |
| -void RvcRunMode::Shutdown() |
| 99 | +chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, |
| 100 | + const EmberAfAttributeMetadata * attributeMetadata, |
| 101 | + uint8_t * buffer) |
96 | 102 | {
|
97 |
| - if (gRvcRunModeInstance != nullptr) |
| 103 | + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1 |
| 104 | + VerifyOrDie(gRvcRunModeInstance != nullptr); |
| 105 | + chip::Protocols::InteractionModel::Status ret; |
| 106 | + chip::AttributeId attributeId = attributeMetadata->attributeId; |
| 107 | + |
| 108 | + switch (attributeId) |
98 | 109 | {
|
99 |
| - delete gRvcRunModeInstance; |
100 |
| - gRvcRunModeInstance = nullptr; |
| 110 | + case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { |
| 111 | + uint8_t m = static_cast<uint8_t>(buffer[0]); |
| 112 | + ret = gRvcRunModeInstance->UpdateCurrentMode(m); |
| 113 | + if (chip::Protocols::InteractionModel::Status::Success != ret) |
| 114 | + { |
| 115 | + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret)); |
| 116 | + } |
101 | 117 | }
|
102 |
| - if (gRvcRunModeDelegate != nullptr) |
| 118 | + break; |
| 119 | + default: |
| 120 | + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; |
| 121 | + ChipLogError(DeviceLayer, "Unsupported Writng Attribute ID: %d", static_cast<int>(attributeId)); |
| 122 | + break; |
| 123 | + } |
| 124 | + |
| 125 | + return ret; |
| 126 | +} |
| 127 | + |
| 128 | +chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, |
| 129 | + const EmberAfAttributeMetadata * attributeMetadata, |
| 130 | + uint8_t * buffer, uint16_t maxReadLength) |
| 131 | +{ |
| 132 | + chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; |
| 133 | + chip::AttributeId attributeId = attributeMetadata->attributeId; |
| 134 | + |
| 135 | + switch (attributeId) |
103 | 136 | {
|
104 |
| - delete gRvcRunModeDelegate; |
105 |
| - gRvcRunModeDelegate = nullptr; |
| 137 | + case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { |
| 138 | + *buffer = gRvcRunModeInstance->GetCurrentMode(); |
| 139 | + ChipLogDetail(DeviceLayer, "Reading RunMode CurrentMode : %d", static_cast<int>(attributeId)); |
| 140 | + } |
| 141 | + break; |
| 142 | + default: |
| 143 | + ret = chip::Protocols::InteractionModel::Status::UnsupportedRead; |
| 144 | + ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcRunMode", static_cast<int>(attributeId)); |
| 145 | + break; |
106 | 146 | }
|
| 147 | + |
| 148 | + return ret; |
107 | 149 | }
|
108 | 150 |
|
109 | 151 | void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId)
|
110 | 152 | {
|
111 | 153 | VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
|
112 |
| - VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr); |
113 |
| - gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate; |
114 |
| - gRvcRunModeInstance = |
115 |
| - new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff)); |
| 154 | + VerifyOrDie(!gRvcRunModeDelegate && !gRvcRunModeInstance); |
| 155 | + |
| 156 | + gRvcRunModeDelegate = std::make_unique<RvcRunModeDelegate>(); |
| 157 | + gRvcRunModeInstance = std::make_unique<ModeBase::Instance>(gRvcRunModeDelegate.get(), endpointId, RvcRunMode::Id, |
| 158 | + chip::to_underlying(RvcRunMode::Feature::kNoFeatures)); |
116 | 159 | gRvcRunModeInstance->Init();
|
117 | 160 | }
|
118 | 161 |
|
119 |
| -#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER |
| 162 | +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER |
| 163 | + |
| 164 | +#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER |
120 | 165 | #include <chef-rvc-mode-delegate.h>
|
121 | 166 | using namespace chip::app::Clusters::RvcCleanMode;
|
122 |
| -static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr; |
123 |
| -static ModeBase::Instance * gRvcCleanModeInstance = nullptr; |
| 167 | +static std::unique_ptr<RvcCleanModeDelegate> gRvcCleanModeDelegate; |
| 168 | +static std::unique_ptr<ModeBase::Instance> gRvcCleanModeInstance; |
124 | 169 |
|
125 | 170 | CHIP_ERROR RvcCleanModeDelegate::Init()
|
126 | 171 | {
|
@@ -178,33 +223,75 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
|
178 | 223 | return CHIP_NO_ERROR;
|
179 | 224 | }
|
180 | 225 |
|
181 |
| -ModeBase::Instance * RvcCleanMode::Instance() |
| 226 | +void RvcCleanMode::Shutdown() |
182 | 227 | {
|
183 |
| - return gRvcCleanModeInstance; |
| 228 | + gRvcCleanModeInstance.reset(); |
| 229 | + gRvcCleanModeDelegate.reset(); |
184 | 230 | }
|
185 | 231 |
|
186 |
| -void RvcCleanMode::Shutdown() |
| 232 | +chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, |
| 233 | + const EmberAfAttributeMetadata * attributeMetadata, |
| 234 | + uint8_t * buffer) |
187 | 235 | {
|
188 |
| - if (gRvcCleanModeInstance != nullptr) |
| 236 | + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1 |
| 237 | + VerifyOrDie(gRvcCleanModeInstance != nullptr); |
| 238 | + chip::Protocols::InteractionModel::Status ret; |
| 239 | + chip::AttributeId attributeId = attributeMetadata->attributeId; |
| 240 | + |
| 241 | + switch (attributeId) |
189 | 242 | {
|
190 |
| - delete gRvcCleanModeInstance; |
191 |
| - gRvcCleanModeInstance = nullptr; |
| 243 | + case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: { |
| 244 | + uint8_t m = static_cast<uint8_t>(buffer[0]); |
| 245 | + ret = gRvcCleanModeInstance->UpdateCurrentMode(m); |
| 246 | + if (chip::Protocols::InteractionModel::Status::Success != ret) |
| 247 | + { |
| 248 | + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret)); |
| 249 | + } |
| 250 | + } |
| 251 | + break; |
| 252 | + default: |
| 253 | + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; |
| 254 | + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId)); |
| 255 | + break; |
192 | 256 | }
|
193 |
| - if (gRvcCleanModeDelegate != nullptr) |
| 257 | + |
| 258 | + return ret; |
| 259 | +} |
| 260 | + |
| 261 | +chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, |
| 262 | + const EmberAfAttributeMetadata * attributeMetadata, |
| 263 | + uint8_t * buffer, uint16_t maxReadLength) |
| 264 | +{ |
| 265 | + VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted); |
| 266 | + buffer[0] = gRvcCleanModeInstance->GetCurrentMode(); |
| 267 | + |
| 268 | + chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; |
| 269 | + chip::AttributeId attributeId = attributeMetadata->attributeId; |
| 270 | + |
| 271 | + switch (attributeId) |
194 | 272 | {
|
195 |
| - delete gRvcCleanModeDelegate; |
196 |
| - gRvcCleanModeDelegate = nullptr; |
| 273 | + case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: { |
| 274 | + *buffer = gRvcCleanModeInstance->GetCurrentMode(); |
| 275 | + ChipLogDetail(DeviceLayer, "Reading CleanMode CurrentMode : %d", static_cast<int>(attributeId)); |
197 | 276 | }
|
| 277 | + break; |
| 278 | + default: |
| 279 | + ret = chip::Protocols::InteractionModel::Status::UnsupportedRead; |
| 280 | + ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcCleanMode", static_cast<int>(attributeId)); |
| 281 | + break; |
| 282 | + } |
| 283 | + |
| 284 | + return ret; |
198 | 285 | }
|
199 | 286 |
|
200 | 287 | void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
|
201 | 288 | {
|
202 | 289 | VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
|
203 |
| - VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr); |
204 |
| - gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate; |
205 |
| - gRvcCleanModeInstance = |
206 |
| - new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff)); |
| 290 | + VerifyOrDie(!gRvcCleanModeDelegate && !gRvcCleanModeInstance); |
| 291 | + |
| 292 | + gRvcCleanModeDelegate = std::make_unique<RvcCleanModeDelegate>(); |
| 293 | + gRvcCleanModeInstance = std::make_unique<ModeBase::Instance>(gRvcCleanModeDelegate.get(), endpointId, RvcCleanMode::Id, |
| 294 | + chip::to_underlying(RvcCleanMode::Feature::kNoFeatures)); |
207 | 295 | gRvcCleanModeInstance->Init();
|
208 | 296 | }
|
209 |
| -#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER |
210 |
| -#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER |
| 297 | +#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER |
0 commit comments