|
17 | 17 | #include <app/codegen-data-model-provider/CodegenDataModelProvider.h>
|
18 | 18 |
|
19 | 19 | #include <app-common/zap-generated/attribute-type.h>
|
| 20 | +#include <app/CommandHandlerInterfaceRegistry.h> |
20 | 21 | #include <app/RequiredPrivilege.h>
|
21 | 22 | #include <app/util/IMClusterCommandHandler.h>
|
22 | 23 | #include <app/util/attribute-storage.h>
|
@@ -229,20 +230,28 @@ bool CodegenDataModelProvider::EmberCommandListIterator::Exists(const CommandId
|
229 | 230 | return (*mCurrentHint == toCheck);
|
230 | 231 | }
|
231 | 232 |
|
232 |
| -DataModel::ActionReturnStatus CodegenDataModelProvider::Invoke(const DataModel::InvokeRequest & request, |
233 |
| - TLV::TLVReader & input_arguments, CommandHandler * handler) |
| 233 | +std::optional<DataModel::ActionReturnStatus> CodegenDataModelProvider::Invoke(const DataModel::InvokeRequest & request, |
| 234 | + TLV::TLVReader & input_arguments, |
| 235 | + CommandHandler * handler) |
234 | 236 | {
|
235 |
| - // TODO: CommandHandlerInterface support is currently |
236 |
| - // residing in InteractionModelEngine itself. We may want to separate this out |
237 |
| - // into its own registry, similar to attributes, so that IM is decoupled from actual storage of things. |
238 |
| - // |
239 |
| - // Open issue at https://github.com/project-chip/connectedhomeip/issues/34258 |
240 |
| - |
241 |
| - // Ember dispatching automatically uses `handler` to set an appropriate result or status |
242 |
| - // This never fails (as handler error is encoded as needed). |
243 |
| - DispatchSingleClusterCommand(request.path, input_arguments, handler); |
| 237 | + CommandHandlerInterface * handler_interface = |
| 238 | + CommandHandlerInterfaceRegistry::Instance().GetCommandHandler(request.path.mEndpointId, request.path.mClusterId); |
| 239 | + |
| 240 | + if (handler_interface) |
| 241 | + { |
| 242 | + CommandHandlerInterface::HandlerContext context(*handler, request.path, input_arguments); |
| 243 | + handler_interface->InvokeCommand(context); |
244 | 244 |
|
245 |
| - return CHIP_NO_ERROR; |
| 245 | + // If the command was handled, don't proceed any further and return successfully. |
| 246 | + if (context.mCommandHandled) |
| 247 | + { |
| 248 | + return std::nullopt; |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + // Ember always sets the return in the handler |
| 253 | + DispatchSingleClusterCommand(request.path, input_arguments, handler); |
| 254 | + return std::nullopt; |
246 | 255 | }
|
247 | 256 |
|
248 | 257 | EndpointId CodegenDataModelProvider::FirstEndpoint()
|
|
0 commit comments