From 0a58add7facb941b71c2439986f77cd4b159263b Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Tue, 25 Jul 2023 16:14:25 +0800 Subject: [PATCH] app : Add option to disable Read Client --- config/esp32/components/chip/CMakeLists.txt | 4 ++++ config/esp32/components/chip/Kconfig | 6 ++++++ .../lighting-app/esp32/sdkconfig.defaults | 3 +++ examples/lighting-app/linux/args.gni | 2 ++ src/app/AttributePathParams.h | 2 ++ src/app/BUILD.gn | 14 +++++++++---- src/app/BufferedReadCallback.h | 2 ++ src/app/ClusterStateCache.h | 7 ++++--- src/app/InteractionModelEngine.cpp | 14 +++++++++++++ src/app/InteractionModelEngine.h | 8 ++++++++ src/app/ReadClient.h | 6 ++++-- src/app/common_flags.gni | 1 + src/controller/BUILD.gn | 20 ++++++++++++------- src/controller/CHIPCluster.h | 2 ++ src/controller/CHIPDeviceController.h | 12 +++++++++-- src/controller/ReadInteraction.h | 2 ++ src/controller/TypedReadCallback.h | 2 ++ 17 files changed, 89 insertions(+), 18 deletions(-) diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index d35791cf1ed3c0..f8c6e839bffbb5 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -124,6 +124,10 @@ if(CONFIG_DISABLE_IPV4) chip_gn_arg_append("chip_inet_config_enable_ipv4" "false") endif() +if(CONFIG_DISABLE_READ_CLIENT) + chip_gn_arg_append("chip_enable_read_client" "false") +endif() + if(CHIP_CODEGEN_PREGEN_DIR) chip_gn_arg_append("chip_code_pre_generated_directory" "\"${CHIP_CODEGEN_PREGEN_DIR}\"") endif() diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 99de12afa97e6e..5c871c2d043a30 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -108,6 +108,12 @@ menu "CHIP Core" help Matter spec is based on IPv6 communication only. Enabling this option may save some flash/ram. + config DISABLE_READ_CLIENT + bool "Disable read client in Interaction Model" + default n + help + Some device types don't require the read client. Enabling this option may save some flash/ram. + config BUILD_CHIP_TESTS bool "Build CHIP tests" default n diff --git a/examples/lighting-app/esp32/sdkconfig.defaults b/examples/lighting-app/esp32/sdkconfig.defaults index 59c0af656896f0..f87a164ae41dd2 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults +++ b/examples/lighting-app/esp32/sdkconfig.defaults @@ -58,3 +58,6 @@ CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y # Enable HKDF in mbedtls CONFIG_MBEDTLS_HKDF_C=y + +# Disable Read Client +CONFIG_DISABLE_READ_CLIENT=y diff --git a/examples/lighting-app/linux/args.gni b/examples/lighting-app/linux/args.gni index 03e65b9c89f3e3..4cd35a499a951c 100644 --- a/examples/lighting-app/linux/args.gni +++ b/examples/lighting-app/linux/args.gni @@ -28,5 +28,7 @@ chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] matter_enable_tracing_support = true +chip_enable_read_client = false + # Perfetto requires C++17 cpp_standard = "gnu++17" diff --git a/src/app/AttributePathParams.h b/src/app/AttributePathParams.h index adfc77cfe27830..b03153d71c2e2f 100644 --- a/src/app/AttributePathParams.h +++ b/src/app/AttributePathParams.h @@ -24,7 +24,9 @@ namespace chip { namespace app { +#if CHIP_CONFIG_ENABLE_READ_CLIENT class ReadClient; +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT struct AttributePathParams { // diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 7f2c4d82280392..ded31ad69e471b 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -57,6 +57,7 @@ buildconfig_header("app_buildconfig") { "CHIP_CONFIG_PERSIST_SUBSCRIPTIONS=${chip_persist_subscriptions}", "CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE=${enable_eventlist_attribute}", "CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}", + "CHIP_CONFIG_ENABLE_READ_CLIENT=${chip_enable_read_client}", ] } @@ -75,7 +76,6 @@ static_library("app") { "AttributePathExpandIterator.h", "AttributePathParams.h", "AttributePersistenceProvider.h", - "BufferedReadCallback.cpp", "CASEClient.cpp", "CASEClient.h", "CASEClientPool.h", @@ -83,8 +83,6 @@ static_library("app") { "CASESessionManager.h", "ChunkedWriteCallback.cpp", "ChunkedWriteCallback.h", - "ClusterStateCache.cpp", - "ClusterStateCache.h", "CommandHandler.cpp", "CommandResponseHelper.h", "CommandSender.cpp", @@ -178,7 +176,6 @@ static_library("app") { "OperationalSessionSetup.cpp", "OperationalSessionSetup.h", "OperationalSessionSetupPool.h", - "ReadClient.cpp", "ReadHandler.cpp", "RequiredPrivilege.cpp", "RequiredPrivilege.h", @@ -206,6 +203,15 @@ static_library("app") { ] } + if (chip_enable_read_client) { + sources += [ + "BufferedReadCallback.cpp", + "ClusterStateCache.cpp", + "ClusterStateCache.h", + "ReadClient.cpp", + ] + } + public_deps = [ ":app_config", "${chip_root}/src/access", diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index 747855be1d6ea7..6080f10f5ecf17 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -25,6 +25,7 @@ #include #include +#if CHIP_CONFIG_ENABLE_READ_CLIENT namespace chip { namespace app { @@ -128,3 +129,4 @@ class BufferedReadCallback : public ReadClient::Callback } // namespace app } // namespace chip +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT diff --git a/src/app/ClusterStateCache.h b/src/app/ClusterStateCache.h index e773dcb4e55ea6..25b017b1c409cf 100644 --- a/src/app/ClusterStateCache.h +++ b/src/app/ClusterStateCache.h @@ -32,7 +32,7 @@ #include #include #include - +#if CHIP_CONFIG_ENABLE_READ_CLIENT namespace chip { namespace app { /* @@ -655,5 +655,6 @@ class ClusterStateCache : protected ReadClient::Callback const bool mCacheData = true; }; -}; // namespace app -}; // namespace chip +}; // namespace app +}; // namespace chip +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 6c32952135c902..9700da3112f620 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -105,6 +105,7 @@ void InteractionModelEngine::Shutdown() mReadHandlers.ReleaseAll(); +#if CHIP_CONFIG_ENABLE_READ_CLIENT // Shut down any subscription clients that are still around. They won't be // able to work after this point anyway, since we're about to drop our refs // to them. @@ -131,6 +132,7 @@ void InteractionModelEngine::Shutdown() // After that, we just null out our tracker. // mpActiveReadClientList = nullptr; +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT for (auto & writeHandler : mWriteHandlers) { @@ -251,6 +253,7 @@ uint32_t InteractionModelEngine::GetNumActiveWriteHandlers() const return numActive; } +#if CHIP_CONFIG_ENABLE_READ_CLIENT CHIP_ERROR InteractionModelEngine::ShutdownSubscription(const ScopedNodeId & aPeerNodeId, SubscriptionId aSubscriptionId) { assertChipStackLockedByCurrentThread(); @@ -308,6 +311,7 @@ void InteractionModelEngine::ShutdownMatchingSubscriptions(const OptionalOnMessageReceived(apExchangeContext, aPayloadHeader, std::move(aPayload)); } +#if CHIP_CONFIG_ENABLE_READ_CLIENT Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload) { @@ -835,6 +840,7 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex return Status::InvalidSubscription; } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT CHIP_ERROR InteractionModelEngine::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate) @@ -878,10 +884,12 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext status = OnReadInitialRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), ReadHandler::InteractionType::Subscribe); } +#if CHIP_CONFIG_ENABLE_READ_CLIENT else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::ReportData)) { status = OnUnsolicitedReportData(apExchangeContext, aPayloadHeader, std::move(aPayload)); } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT else if (aPayloadHeader.HasMessageType(MsgType::TimedRequest)) { OnTimedRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), status); @@ -906,11 +914,13 @@ void InteractionModelEngine::OnResponseTimeout(Messaging::ExchangeContext * ec) ChipLogValueExchange(ec)); } +#if CHIP_CONFIG_ENABLE_READ_CLIENT void InteractionModelEngine::AddReadClient(ReadClient * apReadClient) { apReadClient->SetNextClient(mpActiveReadClientList); mpActiveReadClientList = apReadClient; } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT bool InteractionModelEngine::TrimFabricForSubscriptions(FabricIndex aFabricIndex, bool aForceEvict) { @@ -1308,6 +1318,7 @@ Protocols::InteractionModel::Status InteractionModelEngine::EnsureResourceForRea return Status::Success; } +#if CHIP_CONFIG_ENABLE_READ_CLIENT void InteractionModelEngine::RemoveReadClient(ReadClient * apReadClient) { ReadClient * pPrevListItem = nullptr; @@ -1366,6 +1377,7 @@ bool InteractionModelEngine::InActiveReadClientList(ReadClient * apReadClient) return false; } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT bool InteractionModelEngine::HasConflictWriteRequests(const WriteHandler * apWriteHandler, const ConcreteAttributePath & aPath) { @@ -1724,6 +1736,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa return Loop::Continue; }); +#if CHIP_CONFIG_ENABLE_READ_CLIENT for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient()) { if (readClient->GetFabricIndex() == fabricIndex) @@ -1732,6 +1745,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa readClient->Close(CHIP_ERROR_IM_FABRIC_DELETED, false); } } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT for (auto & handler : mWriteHandlers) { diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index b7de62e16ff0be..5ba85c9ebbd8a9 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -128,6 +128,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, */ CASESessionManager * GetCASESessionManager() const { return mpCASESessionMgr; } +#if CHIP_CONFIG_ENABLE_READ_CLIENT /** * Tears down an active subscription. * @@ -150,6 +151,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, * Tears down all active subscriptions. */ void ShutdownAllSubscriptions(); +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT uint32_t GetNumActiveReadHandlers() const; uint32_t GetNumActiveReadHandlers(ReadHandler::InteractionType type) const; @@ -231,6 +233,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, void OnTimedWrite(TimedHandler * apTimedHandler, Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); +#if CHIP_CONFIG_ENABLE_READ_CLIENT /** * Add a read client to the internally tracked list of weak references. This list is used to * correctly dispatch unsolicited reports to the right matching handler by subscription ID. @@ -251,6 +254,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, * Return the number of active read clients being tracked by the engine. */ size_t GetNumActiveReadClients(); +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT /** * Returns the number of dirty subscriptions. Including the subscriptions that are generating reports. @@ -345,6 +349,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, // void ShutdownActiveReads() { +#if CHIP_CONFIG_ENABLE_READ_CLIENT for (auto * readClient = mpActiveReadClientList; readClient != nullptr;) { readClient->mpImEngine = nullptr; @@ -358,6 +363,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, // After that, we just null out our tracker. // mpActiveReadClientList = nullptr; +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT mReadHandlers.ReleaseAll(); } @@ -594,7 +600,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, ObjectPool mReadHandlers; +#if CHIP_CONFIG_ENABLE_READ_CLIENT ReadClient * mpActiveReadClientList = nullptr; +#endif ReadHandler::ApplicationCallback * mpReadHandlerApplicationCallback = nullptr; diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 0951b0bec1cc0e..18984031a57662 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -49,6 +49,7 @@ #include #include +#if CHIP_CONFIG_ENABLE_READ_CLIENT namespace chip { namespace app { @@ -601,5 +602,6 @@ class ReadClient : public Messaging::ExchangeDelegate kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer; }; -}; // namespace app -}; // namespace chip +}; // namespace app +}; // namespace chip +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT diff --git a/src/app/common_flags.gni b/src/app/common_flags.gni index 1d4309810d57e8..5e5a82afd7d5e1 100644 --- a/src/app/common_flags.gni +++ b/src/app/common_flags.gni @@ -15,4 +15,5 @@ declare_args() { # Temporary flag for interaction model and echo protocols, set it to true to enable chip_app_use_echo = false + chip_enable_read_client = true } diff --git a/src/controller/BUILD.gn b/src/controller/BUILD.gn index 3172c1815a1271..9e7a8145911b60 100644 --- a/src/controller/BUILD.gn +++ b/src/controller/BUILD.gn @@ -15,21 +15,21 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") import("${chip_root}/src/platform/python.gni") +import("${chip_root}/src/app/common_flags.gni") +import("${chip_root}/src/lib/lib.gni") static_library("controller") { output_name = "libChipController" sources = [ "CHIPCluster.h" ] - if (chip_controller) { + if (chip_controller && chip_build_controller) { sources += [ "AbstractDnssdDiscoveryController.cpp", "AutoCommissioner.cpp", "AutoCommissioner.h", "CHIPCommissionableNodeController.cpp", "CHIPCommissionableNodeController.h", - "CHIPDeviceController.cpp", - "CHIPDeviceController.h", "CHIPDeviceControllerFactory.cpp", "CHIPDeviceControllerFactory.h", "CommissioneeDeviceProxy.cpp", @@ -37,10 +37,6 @@ static_library("controller") { "CommissionerDiscoveryController.cpp", "CommissionerDiscoveryController.h", "CommissioningDelegate.cpp", - "CommissioningWindowOpener.cpp", - "CommissioningWindowOpener.h", - "CurrentFabricRemover.cpp", - "CurrentFabricRemover.h", "DeviceDiscoveryDelegate.h", "DevicePairingDelegate.h", "EmptyDataModelHandler.cpp", @@ -49,6 +45,16 @@ static_library("controller") { "SetUpCodePairer.cpp", "SetUpCodePairer.h", ] + if (chip_enable_read_client) { + sources += [ + "CHIPDeviceController.cpp", + "CHIPDeviceController.h", + "CommissioningWindowOpener.cpp", + "CommissioningWindowOpener.h", + "CurrentFabricRemover.cpp", + "CurrentFabricRemover.h", + ] + } } cflags = [ "-Wconversion" ] diff --git a/src/controller/CHIPCluster.h b/src/controller/CHIPCluster.h index ab37a52ece8e24..4324092871424b 100644 --- a/src/controller/CHIPCluster.h +++ b/src/controller/CHIPCluster.h @@ -221,6 +221,7 @@ class DLL_EXPORT ClusterBase return WriteAttribute(requestData, context, successCb, failureCb, NullOptional, doneCb, aDataVersion); } +#if CHIP_CONFIG_ENABLE_READ_CLIENT /** * Read an attribute and get a type-safe callback with the attribute value. */ @@ -399,6 +400,7 @@ class DLL_EXPORT ClusterBase onSubscriptionEstablishedCb, onResubscriptionAttemptCb, aKeepPreviousSubscriptions, aIsUrgentEvent); } +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT protected: Messaging::ExchangeManager & mExchangeManager; diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 9fd8d1cfe7ee03..2d85fdce3068e4 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -384,8 +384,10 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable public Protocols::UserDirectedCommissioning::InstanceNameResolver, #endif - public SessionEstablishmentDelegate, - public app::ClusterStateCache::Callback +#if CHIP_CONFIG_ENABLE_READ_CLIENT + public app::ClusterStateCache::Callback, +#endif + public SessionEstablishmentDelegate { public: DeviceCommissioner(); @@ -683,8 +685,10 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, void RegisterPairingDelegate(DevicePairingDelegate * pairingDelegate) { mPairingDelegate = pairingDelegate; } DevicePairingDelegate * GetPairingDelegate() const { return mPairingDelegate; } +#if CHIP_CONFIG_ENABLE_READ_CLIENT // ClusterStateCache::Callback impl void OnDone(app::ReadClient *) override; +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT // Issue an NOC chain using the associated OperationalCredentialsDelegate. The NOC chain will // be provided in X509 DER format. @@ -915,11 +919,13 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, void SendCommissioningReadRequest(DeviceProxy * proxy, Optional timeout, app::AttributePathParams * readPaths, size_t readPathsSize); +#if CHIP_CONFIG_ENABLE_READ_CLIENT // Parsers for the two different read clients void ParseCommissioningInfo(); void ParseFabrics(); // Called by ParseCommissioningInfo void ParseTimeSyncInfo(ReadCommissioningInfo & info); +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT static CHIP_ERROR ConvertFromOperationalCertStatus(chip::app::Clusters::OperationalCredentials::NodeOperationalCertStatusEnum err); @@ -959,8 +965,10 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, nullptr; // Commissioning delegate that issued the PerformCommissioningStep command CompletionStatus commissioningCompletionStatus; +#if CHIP_CONFIG_ENABLE_READ_CLIENT Platform::UniquePtr mAttributeCache; Platform::UniquePtr mReadClient; +#endif Credentials::AttestationVerificationResult mAttestationResult; Platform::UniquePtr mAttestationDeviceInfo; Credentials::DeviceAttestationVerifier * mDeviceAttestationVerifier = nullptr; diff --git a/src/controller/ReadInteraction.h b/src/controller/ReadInteraction.h index 88c1f902121de6..34491dd9edfebf 100644 --- a/src/controller/ReadInteraction.h +++ b/src/controller/ReadInteraction.h @@ -23,6 +23,7 @@ #include #include +#if CHIP_CONFIG_ENABLE_READ_CLIENT namespace chip { namespace Controller { namespace detail { @@ -328,3 +329,4 @@ CHIP_ERROR SubscribeEvent( } // namespace Controller } // namespace chip +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT diff --git a/src/controller/TypedReadCallback.h b/src/controller/TypedReadCallback.h index aa0e4394ad4e5e..f35a39670ee8e7 100644 --- a/src/controller/TypedReadCallback.h +++ b/src/controller/TypedReadCallback.h @@ -24,6 +24,7 @@ #include #include +#if CHIP_CONFIG_ENABLE_READ_CLIENT namespace chip { namespace Controller { @@ -290,3 +291,4 @@ class TypedReadEventCallback final : public app::ReadClient::Callback } // namespace Controller } // namespace chip +#endif // CHIP_CONFIG_ENABLE_READ_CLIENT