From 7ed7fff609cc6b176cd0ab331b359f9fe54bdb2e Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 31 Jan 2025 14:33:39 -0800 Subject: [PATCH] Address review comments --- .../app-templates/IMClusterCommandHandler.cpp | 3 ++- .../lighting-app/app-templates/IMClusterCommandHandler.cpp | 3 ++- .../codegen/CodegenDataModelProvider.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp index c445851b51207f..a095ead5997e2d 100644 --- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp +++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp @@ -1928,7 +1928,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV: errorStatus = Clusters::WindowCovering::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; default: - // If we already validated that the cluster does indeed exist in our CHI, + // If we already validated that the cluster does indeed exist (e.g. when dispatching to CommandHandlerInterface for that + // cluster). if (aClusterIsValid) { errorStatus = Protocols::InteractionModel::Status::UnsupportedCommand; diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp index eca0f0f79c9bf2..1cb0b97f11406b 100644 --- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp +++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp @@ -1015,7 +1015,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV: errorStatus = Clusters::ThreadNetworkDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; default: - // If we already validated that the cluster does indeed exist in our CHI, + // If we already validated that the cluster does indeed exist (e.g. when dispatching to CommandHandlerInterface for that + // cluster). if (aClusterIsValid) { errorStatus = Protocols::InteractionModel::Status::UnsupportedCommand; diff --git a/src/data-model-providers/codegen/CodegenDataModelProvider.cpp b/src/data-model-providers/codegen/CodegenDataModelProvider.cpp index 0b63ab69534e4f..cc961390a311aa 100644 --- a/src/data-model-providers/codegen/CodegenDataModelProvider.cpp +++ b/src/data-model-providers/codegen/CodegenDataModelProvider.cpp @@ -164,7 +164,12 @@ std::optional CodegenDataModelProvider::Invoke(co CommandHandlerInterface * handler_interface = CommandHandlerInterfaceRegistry::Instance().GetCommandHandler(request.path.mEndpointId, request.path.mClusterId); - if (handler_interface) + // Some CommandHandlerInterface instances are registered of ALL endpoints, so make sure first that + // the cluster actually exists on this endpoint before asking the CommandHandlerInterface whether it + // supports the command. + const bool clusterIsPresent = (FindServerCluster(request.path) != nullptr); + + if (clusterIsPresent && handler_interface) { clusterRecognizedByCHI = true; CommandHandlerInterface::HandlerContext context(*handler, request.path, input_arguments);