diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 060556001e98c7..fb37a3cfec4f01 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -98,7 +98,6 @@ jobs: --known-failure controller/ExamplePersistentStorage.cpp \ --known-failure controller/ExamplePersistentStorage.h \ --known-failure app/AttributeAccessToken.h \ - --known-failure app/CommandHandlerInterface.h \ --known-failure app/CommandResponseSender.h \ --known-failure app/CommandSenderLegacyCallback.h \ --known-failure app/ReadHandler.h \ diff --git a/docs/upgrading.md b/docs/upgrading.md index cd18b533484279..9a8c68987bec3b 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -60,3 +60,19 @@ commandHandler->AddResponse(path, kReplyCommandId, replyEncoder); // so code does AddResponse rather than AddResponseData. ``` + +### `CommandHandlerInterface` in `chip::app::InteractionModelEngine` + +Command handler lists were placed in a separate registry class that is +independent of the InteractionModelEngine class. + +The following replacements exist: + +- `chip::app::InteractionModelEngine::RegisterCommandHandler` replaced by + `chip::app::CommandHandlerInterfaceRegistry::RegisterCommandHandler` +- `chip::app::InteractionModelEngine::UnregisterCommandHandler` replaced by + `chip::app::CommandHandlerInterfaceRegistry::UnregisterCommandHandler` +- `chip::app::InteractionModelEngine::FindCommandHandler` replaced by + `chip::app::CommandHandlerInterfaceRegistry::GetCommandHandler` +- `chip::app::InteractionModelEngine::UnregisterCommandHandlers` replaced by + `chip::app::CommandHandlerInterfaceRegistry::UnregisterAllCommandHandlersForEndpoint` diff --git a/examples/fabric-bridge-app/linux/main.cpp b/examples/fabric-bridge-app/linux/main.cpp index 7e0a70bc82b18b..d8fb45dea08a02 100644 --- a/examples/fabric-bridge-app/linux/main.cpp +++ b/examples/fabric-bridge-app/linux/main.cpp @@ -23,6 +23,7 @@ #include "DeviceManager.h" #include +#include #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE #include "RpcClient.h" @@ -173,7 +174,7 @@ void ApplicationInit() { ChipLogDetail(NotSpecified, "Fabric-Bridge: ApplicationInit()"); - InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler); + CommandHandlerInterfaceRegistry::RegisterCommandHandler(&gAdministratorCommissioningCommandHandler); #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE InitRpcServer(kFabricBridgeServerPort); diff --git a/examples/log-source-app/linux/main.cpp b/examples/log-source-app/linux/main.cpp index 9443a946e1a871..20ed1c54b5b215 100644 --- a/examples/log-source-app/linux/main.cpp +++ b/examples/log-source-app/linux/main.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -109,7 +110,7 @@ int main(int argc, char * argv[]) // Initialize device attestation config SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider()); - chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(&GetLogProvider()); + CommandHandlerInterfaceRegistry::RegisterCommandHandler(&GetLogProvider()); chip::DeviceLayer::PlatformMgr().RunEventLoop(); diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index c24e7e537dbb23..d04964ee5eb747 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -572,7 +572,7 @@ CHIP_ERROR InitVideoPlayerPlatform(jobject contentAppEndpointManager) { ContentAppCommandDelegate * delegate = new ContentAppCommandDelegate(contentAppEndpointManager, contentAppClusters[i].clusterId); - chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(delegate); + chip::app::CommandHandlerInterfaceRegistry::RegisterCommandHandler(delegate); ChipLogProgress(AppServer, "Registered command handler delegate for cluster %d", contentAppClusters[i].clusterId); } diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 0ca8c63d37bb62..ac9c21b01adfab 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -371,6 +371,9 @@ source_set("command-handler-interface") { "CommandHandler.cpp", "CommandHandler.h", "CommandHandlerExchangeInterface.h", + "CommandHandlerInterface.h", + "CommandHandlerInterfaceRegistry.cpp", + "CommandHandlerInterfaceRegistry.h", ] public_deps = [ diff --git a/src/app/CommandHandlerInterface.h b/src/app/CommandHandlerInterface.h index 6a0d8a4bc36e5c..4146556779756c 100644 --- a/src/app/CommandHandlerInterface.h +++ b/src/app/CommandHandlerInterface.h @@ -23,10 +23,8 @@ #include #include #include // So we can encode lists -#include #include #include -#include namespace chip { namespace app { diff --git a/src/app/CommandHandlerInterfaceRegistry.cpp b/src/app/CommandHandlerInterfaceRegistry.cpp new file mode 100644 index 00000000000000..74ea7d48d04955 --- /dev/null +++ b/src/app/CommandHandlerInterfaceRegistry.cpp @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +using namespace chip::app; + +namespace { + +CommandHandlerInterface * gCommandHandlerList = nullptr; + +} + +namespace chip { +namespace app { +namespace CommandHandlerInterfaceRegistry { + +void UnregisterAllHandlers() +{ + + CommandHandlerInterface * handlerIter = gCommandHandlerList; + + // + // Walk our list of command handlers and de-register them, before finally + // nulling out the list entirely. + // + while (handlerIter) + { + CommandHandlerInterface * nextHandler = handlerIter->GetNext(); + handlerIter->SetNext(nullptr); + handlerIter = nextHandler; + } + + gCommandHandlerList = nullptr; +} + +CHIP_ERROR RegisterCommandHandler(CommandHandlerInterface * handler) +{ + VerifyOrReturnError(handler != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + + for (auto * cur = gCommandHandlerList; cur; cur = cur->GetNext()) + { + if (cur->Matches(*handler)) + { + ChipLogError(InteractionModel, "Duplicate command handler registration failed"); + return CHIP_ERROR_INCORRECT_STATE; + } + } + + handler->SetNext(gCommandHandlerList); + gCommandHandlerList = handler; + + return CHIP_NO_ERROR; +} + +void UnregisterAllCommandHandlersForEndpoint(EndpointId endpointId) +{ + + CommandHandlerInterface * prev = nullptr; + + for (auto * cur = gCommandHandlerList; cur; cur = cur->GetNext()) + { + if (cur->MatchesEndpoint(endpointId)) + { + if (prev == nullptr) + { + gCommandHandlerList = cur->GetNext(); + } + else + { + prev->SetNext(cur->GetNext()); + } + + cur->SetNext(nullptr); + } + else + { + prev = cur; + } + } +} + +CHIP_ERROR UnregisterCommandHandler(CommandHandlerInterface * handler) +{ + VerifyOrReturnError(handler != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + CommandHandlerInterface * prev = nullptr; + + for (auto * cur = gCommandHandlerList; cur; cur = cur->GetNext()) + { + if (cur->Matches(*handler)) + { + if (prev == nullptr) + { + gCommandHandlerList = cur->GetNext(); + } + else + { + prev->SetNext(cur->GetNext()); + } + + cur->SetNext(nullptr); + + return CHIP_NO_ERROR; + } + + prev = cur; + } + + return CHIP_ERROR_KEY_NOT_FOUND; +} + +CommandHandlerInterface * GetCommandHandler(EndpointId endpointId, ClusterId clusterId) +{ + for (auto * cur = gCommandHandlerList; cur; cur = cur->GetNext()) + { + if (cur->Matches(endpointId, clusterId)) + { + return cur; + } + } + + return nullptr; +} + +} // namespace CommandHandlerInterfaceRegistry +} // namespace app +} // namespace chip diff --git a/src/app/CommandHandlerInterfaceRegistry.h b/src/app/CommandHandlerInterfaceRegistry.h new file mode 100644 index 00000000000000..14e00335fd859d --- /dev/null +++ b/src/app/CommandHandlerInterfaceRegistry.h @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include + +namespace chip { +namespace app { +namespace CommandHandlerInterfaceRegistry { + +/// Remove the entire linked list of handlers +void UnregisterAllHandlers(); + +/// Add a new handler to the list of registered command handlers +/// +/// At most one command handler can exist for a given endpoint/cluster combination. Trying +/// to register conflicting handlers will result in a `CHIP_ERROR_INCORRECT_STATE` error. +CHIP_ERROR RegisterCommandHandler(CommandHandlerInterface * handler); + +/// Unregister all commandHandlers that `MatchesEndpoint` for the given endpointId. +void UnregisterAllCommandHandlersForEndpoint(EndpointId endpointId); + +/// Unregister a single handler. +/// +/// If the handler is not registered, a `CHIP_ERROR_KEY_NOT_FOUND` is returned. +CHIP_ERROR UnregisterCommandHandler(CommandHandlerInterface * handler); + +/// Find the command handler for the given endpoint/cluster combination or return +/// nullptr if no such command handler exists. +CommandHandlerInterface * GetCommandHandler(EndpointId endpointId, ClusterId clusterId); + +} // namespace CommandHandlerInterfaceRegistry +} // namespace app +} // namespace chip diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index cb595e5bf239d1..4d7a01f650dba2 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -27,9 +27,10 @@ #include -#include "access/RequestPath.h" -#include "access/SubjectDescriptor.h" +#include +#include #include +#include #include #include #include @@ -99,20 +100,9 @@ void InteractionModelEngine::Shutdown() { mpExchangeMgr->GetSessionManager()->SystemLayer()->CancelTimer(ResumeSubscriptionsTimerCallback, this); - CommandHandlerInterface * handlerIter = mCommandHandlerList; - - // - // Walk our list of command handlers and de-register them, before finally - // nulling out the list entirely. - // - while (handlerIter) - { - CommandHandlerInterface * nextHandler = handlerIter->GetNext(); - handlerIter->SetNext(nullptr); - handlerIter = nextHandler; - } - - mCommandHandlerList = nullptr; + // TODO: individual object clears the entire command handler interface registry. + // This may not be expected. + CommandHandlerInterfaceRegistry::UnregisterAllHandlers(); mCommandResponderObjs.ReleaseAll(); @@ -1682,7 +1672,8 @@ CHIP_ERROR InteractionModelEngine::PushFront(SingleLinkedListNode *& aObjectL void InteractionModelEngine::DispatchCommand(CommandHandlerImpl & apCommandObj, const ConcreteCommandPath & aCommandPath, TLV::TLVReader & apPayload) { - CommandHandlerInterface * handler = FindCommandHandler(aCommandPath.mEndpointId, aCommandPath.mClusterId); + CommandHandlerInterface * handler = + CommandHandlerInterfaceRegistry::GetCommandHandler(aCommandPath.mEndpointId, aCommandPath.mClusterId); if (handler) { @@ -1706,93 +1697,6 @@ Protocols::InteractionModel::Status InteractionModelEngine::CommandExists(const return ServerClusterCommandExists(aCommandPath); } -CHIP_ERROR InteractionModelEngine::RegisterCommandHandler(CommandHandlerInterface * handler) -{ - VerifyOrReturnError(handler != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - for (auto * cur = mCommandHandlerList; cur; cur = cur->GetNext()) - { - if (cur->Matches(*handler)) - { - ChipLogError(InteractionModel, "Duplicate command handler registration failed"); - return CHIP_ERROR_INCORRECT_STATE; - } - } - - handler->SetNext(mCommandHandlerList); - mCommandHandlerList = handler; - - return CHIP_NO_ERROR; -} - -void InteractionModelEngine::UnregisterCommandHandlers(EndpointId endpointId) -{ - CommandHandlerInterface * prev = nullptr; - - for (auto * cur = mCommandHandlerList; cur; cur = cur->GetNext()) - { - if (cur->MatchesEndpoint(endpointId)) - { - if (prev == nullptr) - { - mCommandHandlerList = cur->GetNext(); - } - else - { - prev->SetNext(cur->GetNext()); - } - - cur->SetNext(nullptr); - } - else - { - prev = cur; - } - } -} - -CHIP_ERROR InteractionModelEngine::UnregisterCommandHandler(CommandHandlerInterface * handler) -{ - VerifyOrReturnError(handler != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - CommandHandlerInterface * prev = nullptr; - - for (auto * cur = mCommandHandlerList; cur; cur = cur->GetNext()) - { - if (cur->Matches(*handler)) - { - if (prev == nullptr) - { - mCommandHandlerList = cur->GetNext(); - } - else - { - prev->SetNext(cur->GetNext()); - } - - cur->SetNext(nullptr); - - return CHIP_NO_ERROR; - } - - prev = cur; - } - - return CHIP_ERROR_KEY_NOT_FOUND; -} - -CommandHandlerInterface * InteractionModelEngine::FindCommandHandler(EndpointId endpointId, ClusterId clusterId) -{ - for (auto * cur = mCommandHandlerList; cur; cur = cur->GetNext()) - { - if (cur->Matches(endpointId, clusterId)) - { - return cur; - } - } - - return nullptr; -} - InteractionModel::DataModel * InteractionModelEngine::GetDataModel() const { #if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index e2d299cce67280..2d143f14be50a1 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -216,11 +215,6 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, CHIP_ERROR PushFrontDataVersionFilterList(SingleLinkedListNode *& aDataVersionFilterList, DataVersionFilter & aDataVersionFilter); - CHIP_ERROR RegisterCommandHandler(CommandHandlerInterface * handler); - CHIP_ERROR UnregisterCommandHandler(CommandHandlerInterface * handler); - CommandHandlerInterface * FindCommandHandler(EndpointId endpointId, ClusterId clusterId); - void UnregisterCommandHandlers(EndpointId endpointId); - /* * Register an application callback to be notified of notable events when handling reads/subscribes. */ @@ -617,8 +611,6 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, Messaging::ExchangeManager * mpExchangeMgr = nullptr; - CommandHandlerInterface * mCommandHandlerList = nullptr; - #if CHIP_CONFIG_ENABLE_ICD_SERVER ICDManager * mICDManager = nullptr; #endif // CHIP_CONFIG_ENABLE_ICD_SERVER diff --git a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp index 035a3daef71b88..dc6e2a44de618a 100644 --- a/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp +++ b/src/app/clusters/device-energy-management-server/device-energy-management-server.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,7 @@ namespace DeviceEnergyManagement { CHIP_ERROR Instance::Init() { - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); return CHIP_NO_ERROR; @@ -45,7 +46,7 @@ CHIP_ERROR Instance::Init() void Instance::Shutdown() { - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } diff --git a/src/app/clusters/energy-evse-server/energy-evse-server.cpp b/src/app/clusters/energy-evse-server/energy-evse-server.cpp index 2e2f6867e094c1..af825217e2565a 100644 --- a/src/app/clusters/energy-evse-server/energy-evse-server.cpp +++ b/src/app/clusters/energy-evse-server/energy-evse-server.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,7 @@ namespace EnergyEvse { CHIP_ERROR Instance::Init() { - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); return CHIP_NO_ERROR; @@ -45,7 +46,7 @@ CHIP_ERROR Instance::Init() void Instance::Shutdown() { - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp index d47742570ed2e0..49022891f0b1e9 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -53,7 +54,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClus Instance::~Instance() { - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } @@ -88,7 +89,7 @@ CHIP_ERROR Instance::Init() Zcl, "Microwave Oven Control: feature bits error, if feature supports PowerNumberLimits it must support PowerAsNumber")); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); // If the PowerInWatts feature is supported, get the count of supported watt levels so we can later // ensure incoming watt level values are valid. diff --git a/src/app/clusters/mode-base-server/mode-base-server.cpp b/src/app/clusters/mode-base-server/mode-base-server.cpp index bb6aac6837c0bf..643dd3dd76bee2 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.cpp +++ b/src/app/clusters/mode-base-server/mode-base-server.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,7 @@ void Instance::Shutdown() return; } UnregisterThisInstance(); - chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } @@ -77,7 +78,7 @@ CHIP_ERROR Instance::Init() LoadPersistentAttributes(); - ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); RegisterThisInstance(); ReturnErrorOnFailure(mDelegate->Init()); diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index f2e74033d8266c..2cfe46c70993dc 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -358,7 +358,7 @@ Instance::Instance(EndpointId aEndpointId, EthernetDriver * apDelegate) : CHIP_ERROR Instance::Init() { - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); ReturnErrorOnFailure(DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler, reinterpret_cast(this))); ReturnErrorOnFailure(mpBaseDriver->Init(this)); diff --git a/src/app/clusters/operational-state-server/operational-state-server.cpp b/src/app/clusters/operational-state-server/operational-state-server.cpp index 50b4cd0178a8af..b6ae0d7a221253 100644 --- a/src/app/clusters/operational-state-server/operational-state-server.cpp +++ b/src/app/clusters/operational-state-server/operational-state-server.cpp @@ -20,9 +20,11 @@ * @brief Implementation for the Operational State Server Cluster ***************************************************************************/ #include "operational-state-server.h" + #include #include #include +#include #include #include #include @@ -47,7 +49,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId) : Instance(aDel Instance::~Instance() { - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } @@ -60,7 +62,7 @@ CHIP_ERROR Instance::Init() return CHIP_ERROR_INVALID_ARGUMENT; } - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index 25a0be188ad7af..4d1197a73b83b8 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClus Instance::~Instance() { - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } @@ -71,7 +72,7 @@ CHIP_ERROR Instance::Init() LoadPersistentAttributes(); - ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); ChipLogDetail(Zcl, "ResourceMonitoring: calling mDelegate->Init()"); ReturnErrorOnFailure(mDelegate->Init()); diff --git a/src/app/clusters/sample-mei-server/sample-mei-server.cpp b/src/app/clusters/sample-mei-server/sample-mei-server.cpp index afeca910b455fe..ac461aab008b45 100644 --- a/src/app/clusters/sample-mei-server/sample-mei-server.cpp +++ b/src/app/clusters/sample-mei-server/sample-mei-server.cpp @@ -6,9 +6,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -30,7 +30,7 @@ void MatterSampleMeiPluginServerInitCallback() { ChipLogProgress(Zcl, "Sample MEI Init. Ep %d, Total Ep %u", MATTER_DM_SAMPLE_MEI_CLUSTER_SERVER_ENDPOINT_COUNT, static_cast(kNumSupportedEndpoints)); - ReturnOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(&SampleMeiServer::Instance())); + ReturnOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(&SampleMeiServer::Instance())); VerifyOrReturn(registerAttributeAccessOverride(&SampleMeiServer::Instance()), CHIP_ERROR_INCORRECT_STATE); } diff --git a/src/app/clusters/scenes-server/scenes-server.cpp b/src/app/clusters/scenes-server/scenes-server.cpp index 860e29236fa868..e657a82f4654fe 100644 --- a/src/app/clusters/scenes-server/scenes-server.cpp +++ b/src/app/clusters/scenes-server/scenes-server.cpp @@ -17,10 +17,12 @@ */ #include "scenes-server.h" + #include #include #include #include +#include #include #include #include @@ -337,7 +339,7 @@ CHIP_ERROR ScenesServer::Init() // Prevents re-initializing VerifyOrReturnError(!mIsInitialized, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(chip::app::CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); mGroupProvider = Credentials::GetGroupDataProvider(); @@ -351,7 +353,7 @@ CHIP_ERROR ScenesServer::Init() void ScenesServer::Shutdown() { - chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + chip::app::CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); mGroupProvider = nullptr; mIsInitialized = false; diff --git a/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp index 2c0d76f79b649b..e6bc0daac67668 100644 --- a/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp +++ b/src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp @@ -24,9 +24,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -231,5 +231,5 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle void MatterSoftwareDiagnosticsPluginServerInitCallback() { registerAttributeAccessOverride(&gAttrAccess); - InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gCommandHandler); + CommandHandlerInterfaceRegistry::RegisterCommandHandler(&gCommandHandler); } diff --git a/src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp b/src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp index 888972b3075c33..d1f3de7c58bbc8 100644 --- a/src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp +++ b/src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp @@ -18,6 +18,7 @@ #include "thread-network-directory-server.h" #include +#include #include #include #include @@ -47,13 +48,13 @@ ThreadNetworkDirectoryServer::ThreadNetworkDirectoryServer(EndpointId endpoint, ThreadNetworkDirectoryServer::~ThreadNetworkDirectoryServer() { unregisterAttributeAccessOverride(this); - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); } CHIP_ERROR ThreadNetworkDirectoryServer::Init() { VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INTERNAL); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp b/src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp index d2815b582f5ce1..f99ccdf5aafad3 100644 --- a/src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp +++ b/src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp @@ -18,6 +18,7 @@ #include "wifi-network-management-server.h" #include +#include #include #include #include @@ -63,13 +64,13 @@ WiFiNetworkManagementServer::WiFiNetworkManagementServer(EndpointId endpoint) : WiFiNetworkManagementServer::~WiFiNetworkManagementServer() { unregisterAttributeAccessOverride(this); - InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); + CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); } CHIP_ERROR WiFiNetworkManagementServer::Init() { VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INTERNAL); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); + ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::RegisterCommandHandler(this)); return CHIP_NO_ERROR; } diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index d154b95cf9ab9e..f21132bd4026ca 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -421,10 +422,7 @@ static void shutdownEndpoint(EmberAfDefinedEndpoint * definedEndpoint) } } - // Clear out any command handler overrides registered for this - // endpoint. - chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandlers(definedEndpoint->endpoint); - + CommandHandlerInterfaceRegistry::UnregisterAllCommandHandlersForEndpoint(definedEndpoint->endpoint); unregisterAllAttributeAccessOverridesForEndpoint(definedEndpoint); } diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 88aae59da51a56..c1545bffa88977 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -100,8 +101,7 @@ Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCom return Status::UnsupportedCluster; } - auto * commandHandler = - InteractionModelEngine::GetInstance()->FindCommandHandler(aCommandPath.mEndpointId, aCommandPath.mClusterId); + auto * commandHandler = CommandHandlerInterfaceRegistry::GetCommandHandler(aCommandPath.mEndpointId, aCommandPath.mClusterId); if (commandHandler) { struct Context diff --git a/src/app/util/ember-global-attribute-access-interface.cpp b/src/app/util/ember-global-attribute-access-interface.cpp index 327ab09c479512..cbc4f070e7825e 100644 --- a/src/app/util/ember-global-attribute-access-interface.cpp +++ b/src/app/util/ember-global-attribute-access-interface.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -96,7 +97,7 @@ CHIP_ERROR GlobalAttributeReader::EncodeCommandList(const ConcreteClusterPath & { return aEncoder.EncodeList([&](const auto & encoder) { auto * commandHandler = - InteractionModelEngine::GetInstance()->FindCommandHandler(aClusterPath.mEndpointId, aClusterPath.mClusterId); + CommandHandlerInterfaceRegistry::GetCommandHandler(aClusterPath.mEndpointId, aClusterPath.mClusterId); if (commandHandler) { struct Context diff --git a/src/controller/tests/TestServerCommandDispatch.cpp b/src/controller/tests/TestServerCommandDispatch.cpp index 8c895008dfd67e..960d849fc660ad 100644 --- a/src/controller/tests/TestServerCommandDispatch.cpp +++ b/src/controller/tests/TestServerCommandDispatch.cpp @@ -24,11 +24,11 @@ #include -#include "app-common/zap-generated/ids/Attributes.h" -#include "app-common/zap-generated/ids/Clusters.h" -#include "protocols/interaction_model/Constants.h" #include +#include +#include #include +#include #include #include #include @@ -37,6 +37,7 @@ #include #include #include +#include using namespace chip; using namespace chip::app; @@ -61,10 +62,10 @@ class TestClusterCommandHandler : public chip::app::CommandHandlerInterface public: TestClusterCommandHandler() : chip::app::CommandHandlerInterface(Optional::Missing(), Clusters::UnitTesting::Id) { - chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this); + CommandHandlerInterfaceRegistry::RegisterCommandHandler(this); } - ~TestClusterCommandHandler() { chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); } + ~TestClusterCommandHandler() { CommandHandlerInterfaceRegistry::UnregisterCommandHandler(this); } void OverrideAcceptedCommands() { mOverrideAcceptedCommands = true; } void ClaimNoCommands() { mClaimNoCommands = true; }