Skip to content

Commit

Permalink
[app] Add option to disable read client (project-chip#28149)
Browse files Browse the repository at this point in the history
* app : Add option to disable Read Client

* Restyled by gn

* Format changes

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
wqx6 and restyled-commits authored Aug 4, 2023
1 parent 6a5f704 commit 14bdc24
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 17 deletions.
4 changes: 4 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/lighting-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions examples/lighting-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ chip_project_config_include_dirs =
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]

matter_enable_tracing_support = true

chip_enable_read_client = false
2 changes: 2 additions & 0 deletions src/app/AttributePathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

namespace chip {
namespace app {
#if CHIP_CONFIG_ENABLE_READ_CLIENT
class ReadClient;
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
struct AttributePathParams
{
//
Expand Down
14 changes: 10 additions & 4 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ buildconfig_header("app_buildconfig") {
"CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION=${chip_subscription_timeout_resumption}",
"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}",
]
}

Expand All @@ -76,16 +77,13 @@ static_library("app") {
"AttributePathExpandIterator.h",
"AttributePathParams.h",
"AttributePersistenceProvider.h",
"BufferedReadCallback.cpp",
"CASEClient.cpp",
"CASEClient.h",
"CASEClientPool.h",
"CASESessionManager.cpp",
"CASESessionManager.h",
"ChunkedWriteCallback.cpp",
"ChunkedWriteCallback.h",
"ClusterStateCache.cpp",
"ClusterStateCache.h",
"CommandHandler.cpp",
"CommandResponseHelper.h",
"CommandSender.cpp",
Expand Down Expand Up @@ -179,7 +177,6 @@ static_library("app") {
"OperationalSessionSetup.cpp",
"OperationalSessionSetup.h",
"OperationalSessionSetupPool.h",
"ReadClient.cpp",
"ReadHandler.cpp",
"RequiredPrivilege.cpp",
"RequiredPrivilege.h",
Expand Down Expand Up @@ -210,6 +207,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",
Expand Down
2 changes: 2 additions & 0 deletions src/app/BufferedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <app/ReadClient.h>
#include <vector>

#if CHIP_CONFIG_ENABLE_READ_CLIENT
namespace chip {
namespace app {

Expand Down Expand Up @@ -133,3 +134,4 @@ class BufferedReadCallback : public ReadClient::Callback

} // namespace app
} // namespace chip
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
6 changes: 4 additions & 2 deletions src/app/ClusterStateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <set>
#include <vector>

#if CHIP_CONFIG_ENABLE_READ_CLIENT
namespace chip {
namespace app {
/*
Expand Down Expand Up @@ -660,5 +661,6 @@ class ClusterStateCache : protected ReadClient::Callback
const bool mCacheData = true;
};

}; // namespace app
}; // namespace chip
}; // namespace app
}; // namespace chip
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
14 changes: 14 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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.
Expand All @@ -134,6 +135,7 @@ void InteractionModelEngine::Shutdown()
// After that, we just null out our tracker.
//
mpActiveReadClientList = nullptr;
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

for (auto & writeHandler : mWriteHandlers)
{
Expand Down Expand Up @@ -254,6 +256,7 @@ uint32_t InteractionModelEngine::GetNumActiveWriteHandlers() const
return numActive;
}

#if CHIP_CONFIG_ENABLE_READ_CLIENT
CHIP_ERROR InteractionModelEngine::ShutdownSubscription(const ScopedNodeId & aPeerNodeId, SubscriptionId aSubscriptionId)
{
assertChipStackLockedByCurrentThread();
Expand Down Expand Up @@ -311,6 +314,7 @@ void InteractionModelEngine::ShutdownMatchingSubscriptions(const Optional<Fabric
readClient = nextClient;
}
}
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

void InteractionModelEngine::OnDone(CommandHandler & apCommandObj)
{
Expand Down Expand Up @@ -794,6 +798,7 @@ CHIP_ERROR InteractionModelEngine::OnTimedRequest(Messaging::ExchangeContext * a
return handler->OnMessageReceived(apExchangeContext, aPayloadHeader, std::move(aPayload));
}

#if CHIP_CONFIG_ENABLE_READ_CLIENT
Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchangeContext,
const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload)
{
Expand Down Expand Up @@ -849,6 +854,7 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex

return Status::InvalidSubscription;
}
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

CHIP_ERROR InteractionModelEngine::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
ExchangeDelegate *& newDelegate)
Expand Down Expand Up @@ -892,10 +898,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);
Expand All @@ -920,11 +928,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)
{
Expand Down Expand Up @@ -1322,6 +1332,7 @@ Protocols::InteractionModel::Status InteractionModelEngine::EnsureResourceForRea
return Status::Success;
}

#if CHIP_CONFIG_ENABLE_READ_CLIENT
void InteractionModelEngine::RemoveReadClient(ReadClient * apReadClient)
{
ReadClient * pPrevListItem = nullptr;
Expand Down Expand Up @@ -1380,6 +1391,7 @@ bool InteractionModelEngine::InActiveReadClientList(ReadClient * apReadClient)

return false;
}
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

bool InteractionModelEngine::HasConflictWriteRequests(const WriteHandler * apWriteHandler, const ConcreteAttributePath & aPath)
{
Expand Down Expand Up @@ -1738,6 +1750,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)
Expand All @@ -1746,6 +1759,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)
{
Expand Down
8 changes: 8 additions & 0 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
*/
CASESessionManager * GetCASESessionManager() const { return mpCASESessionMgr; }

#if CHIP_CONFIG_ENABLE_READ_CLIENT
/**
* Tears down an active subscription.
*
Expand All @@ -151,6 +152,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;
Expand Down Expand Up @@ -234,6 +236,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.
Expand All @@ -254,6 +257,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.
Expand Down Expand Up @@ -348,6 +352,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
//
void ShutdownActiveReads()
{
#if CHIP_CONFIG_ENABLE_READ_CLIENT
for (auto * readClient = mpActiveReadClientList; readClient != nullptr;)
{
readClient->mpImEngine = nullptr;
Expand All @@ -361,6 +366,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
// After that, we just null out our tracker.
//
mpActiveReadClientList = nullptr;
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

mReadHandlers.ReleaseAll();
}
Expand Down Expand Up @@ -599,7 +605,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,

ObjectPool<ReadHandler, CHIP_IM_MAX_NUM_READS + CHIP_IM_MAX_NUM_SUBSCRIPTIONS> mReadHandlers;

#if CHIP_CONFIG_ENABLE_READ_CLIENT
ReadClient * mpActiveReadClientList = nullptr;
#endif

ReadHandler::ApplicationCallback * mpReadHandlerApplicationCallback = nullptr;

Expand Down
6 changes: 4 additions & 2 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <protocols/Protocols.h>
#include <system/SystemPacketBuffer.h>

#if CHIP_CONFIG_ENABLE_READ_CLIENT
namespace chip {
namespace app {

Expand Down Expand Up @@ -613,5 +614,6 @@ class ReadClient : public Messaging::ExchangeDelegate
kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer;
};

}; // namespace app
}; // namespace chip
}; // namespace app
}; // namespace chip
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
1 change: 1 addition & 0 deletions src/app/common_flags.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 13 additions & 7 deletions src/controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/src/platform/python.gni")

Expand All @@ -21,26 +23,20 @@ static_library("controller") {

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",
"CommissioneeDeviceProxy.h",
"CommissionerDiscoveryController.cpp",
"CommissionerDiscoveryController.h",
"CommissioningDelegate.cpp",
"CommissioningWindowOpener.cpp",
"CommissioningWindowOpener.h",
"CurrentFabricRemover.cpp",
"CurrentFabricRemover.h",
"DeviceDiscoveryDelegate.h",
"DevicePairingDelegate.h",
"EmptyDataModelHandler.cpp",
Expand All @@ -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" ]
Expand Down
2 changes: 2 additions & 0 deletions src/controller/CHIPCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class DLL_EXPORT ClusterBase
return WriteAttribute<AttributeInfo>(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.
*/
Expand Down Expand Up @@ -399,6 +400,7 @@ class DLL_EXPORT ClusterBase
onSubscriptionEstablishedCb, onResubscriptionAttemptCb,
aKeepPreviousSubscriptions, aIsUrgentEvent);
}
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

protected:
Messaging::ExchangeManager & mExchangeManager;
Expand Down
Loading

0 comments on commit 14bdc24

Please sign in to comment.