Skip to content

Commit bbffc93

Browse files
committed
app : Add option to disable Read Client
1 parent 701fcb2 commit bbffc93

17 files changed

+90
-18
lines changed

config/esp32/components/chip/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ if(CONFIG_DISABLE_IPV4)
124124
chip_gn_arg_append("chip_inet_config_enable_ipv4" "false")
125125
endif()
126126

127+
if(CONFIG_DISABLE_READ_CLIENT)
128+
chip_gn_arg_append("chip_enable_read_client" "false")
129+
endif()
130+
127131
if(CHIP_CODEGEN_PREGEN_DIR)
128132
chip_gn_arg_append("chip_code_pre_generated_directory" "\"${CHIP_CODEGEN_PREGEN_DIR}\"")
129133
endif()

config/esp32/components/chip/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ menu "CHIP Core"
108108
help
109109
Matter spec is based on IPv6 communication only. Enabling this option may save some flash/ram.
110110

111+
config DISABLE_READ_CLIENT
112+
bool "Disable read client in Interaction Model"
113+
default n
114+
help
115+
Some device types don't require the read client. Enabling this option may save some flash/ram.
116+
111117
config BUILD_CHIP_TESTS
112118
bool "Build CHIP tests"
113119
default n

examples/lighting-app/esp32/sdkconfig.defaults

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y
5858

5959
# Enable HKDF in mbedtls
6060
CONFIG_MBEDTLS_HKDF_C=y
61+
62+
# Disable Read Client
63+
CONFIG_DISABLE_READ_CLIENT=y

examples/lighting-app/linux/args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
2828

2929
matter_enable_tracing_support = true
3030

31+
chip_enable_read_client = false
32+
3133
# Perfetto requires C++17
3234
cpp_standard = "gnu++17"

src/app/AttributePathParams.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
namespace chip {
2626
namespace app {
27+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
2728
class ReadClient;
29+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
2830
struct AttributePathParams
2931
{
3032
//

src/app/BUILD.gn

+10-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ buildconfig_header("app_buildconfig") {
5757
"CHIP_CONFIG_PERSIST_SUBSCRIPTIONS=${chip_persist_subscriptions}",
5858
"CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE=${enable_eventlist_attribute}",
5959
"CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}",
60+
"CHIP_CONFIG_ENABLE_READ_CLIENT=${chip_enable_read_client}",
6061
]
6162
}
6263

@@ -75,16 +76,13 @@ static_library("app") {
7576
"AttributePathExpandIterator.h",
7677
"AttributePathParams.h",
7778
"AttributePersistenceProvider.h",
78-
"BufferedReadCallback.cpp",
7979
"CASEClient.cpp",
8080
"CASEClient.h",
8181
"CASEClientPool.h",
8282
"CASESessionManager.cpp",
8383
"CASESessionManager.h",
8484
"ChunkedWriteCallback.cpp",
8585
"ChunkedWriteCallback.h",
86-
"ClusterStateCache.cpp",
87-
"ClusterStateCache.h",
8886
"CommandHandler.cpp",
8987
"CommandResponseHelper.h",
9088
"CommandSender.cpp",
@@ -178,7 +176,6 @@ static_library("app") {
178176
"OperationalSessionSetup.cpp",
179177
"OperationalSessionSetup.h",
180178
"OperationalSessionSetupPool.h",
181-
"ReadClient.cpp",
182179
"ReadHandler.cpp",
183180
"RequiredPrivilege.cpp",
184181
"RequiredPrivilege.h",
@@ -206,6 +203,15 @@ static_library("app") {
206203
]
207204
}
208205

206+
if (chip_enable_read_client) {
207+
sources += [
208+
"BufferedReadCallback.cpp",
209+
"ClusterStateCache.cpp",
210+
"ClusterStateCache.h",
211+
"ReadClient.cpp",
212+
]
213+
}
214+
209215
public_deps = [
210216
":app_config",
211217
"${chip_root}/src/access",

src/app/BufferedReadCallback.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <app/ReadClient.h>
2626
#include <vector>
2727

28+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
2829
namespace chip {
2930
namespace app {
3031

@@ -128,3 +129,4 @@ class BufferedReadCallback : public ReadClient::Callback
128129

129130
} // namespace app
130131
} // namespace chip
132+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

src/app/ClusterStateCache.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <queue>
3333
#include <set>
3434
#include <vector>
35-
35+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
3636
namespace chip {
3737
namespace app {
3838
/*
@@ -655,5 +655,6 @@ class ClusterStateCache : protected ReadClient::Callback
655655
const bool mCacheData = true;
656656
};
657657

658-
}; // namespace app
659-
}; // namespace chip
658+
}; // namespace app
659+
}; // namespace chip
660+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

src/app/InteractionModelEngine.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void InteractionModelEngine::Shutdown()
105105

106106
mReadHandlers.ReleaseAll();
107107

108+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
108109
// Shut down any subscription clients that are still around. They won't be
109110
// able to work after this point anyway, since we're about to drop our refs
110111
// to them.
@@ -131,6 +132,7 @@ void InteractionModelEngine::Shutdown()
131132
// After that, we just null out our tracker.
132133
//
133134
mpActiveReadClientList = nullptr;
135+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
134136

135137
for (auto & writeHandler : mWriteHandlers)
136138
{
@@ -251,6 +253,7 @@ uint32_t InteractionModelEngine::GetNumActiveWriteHandlers() const
251253
return numActive;
252254
}
253255

256+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
254257
CHIP_ERROR InteractionModelEngine::ShutdownSubscription(const ScopedNodeId & aPeerNodeId, SubscriptionId aSubscriptionId)
255258
{
256259
assertChipStackLockedByCurrentThread();
@@ -308,6 +311,7 @@ void InteractionModelEngine::ShutdownMatchingSubscriptions(const Optional<Fabric
308311
readClient = nextClient;
309312
}
310313
}
314+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
311315

312316
void InteractionModelEngine::OnDone(CommandHandler & apCommandObj)
313317
{
@@ -780,6 +784,7 @@ CHIP_ERROR InteractionModelEngine::OnTimedRequest(Messaging::ExchangeContext * a
780784
return handler->OnMessageReceived(apExchangeContext, aPayloadHeader, std::move(aPayload));
781785
}
782786

787+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
783788
Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchangeContext,
784789
const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload)
785790
{
@@ -835,6 +840,7 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex
835840

836841
return Status::InvalidSubscription;
837842
}
843+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
838844

839845
CHIP_ERROR InteractionModelEngine::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
840846
ExchangeDelegate *& newDelegate)
@@ -878,10 +884,12 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
878884
status =
879885
OnReadInitialRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), ReadHandler::InteractionType::Subscribe);
880886
}
887+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
881888
else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::ReportData))
882889
{
883890
status = OnUnsolicitedReportData(apExchangeContext, aPayloadHeader, std::move(aPayload));
884891
}
892+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
885893
else if (aPayloadHeader.HasMessageType(MsgType::TimedRequest))
886894
{
887895
OnTimedRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), status);
@@ -906,11 +914,13 @@ void InteractionModelEngine::OnResponseTimeout(Messaging::ExchangeContext * ec)
906914
ChipLogValueExchange(ec));
907915
}
908916

917+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
909918
void InteractionModelEngine::AddReadClient(ReadClient * apReadClient)
910919
{
911920
apReadClient->SetNextClient(mpActiveReadClientList);
912921
mpActiveReadClientList = apReadClient;
913922
}
923+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
914924

915925
bool InteractionModelEngine::TrimFabricForSubscriptions(FabricIndex aFabricIndex, bool aForceEvict)
916926
{
@@ -1308,6 +1318,7 @@ Protocols::InteractionModel::Status InteractionModelEngine::EnsureResourceForRea
13081318
return Status::Success;
13091319
}
13101320

1321+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
13111322
void InteractionModelEngine::RemoveReadClient(ReadClient * apReadClient)
13121323
{
13131324
ReadClient * pPrevListItem = nullptr;
@@ -1366,6 +1377,7 @@ bool InteractionModelEngine::InActiveReadClientList(ReadClient * apReadClient)
13661377

13671378
return false;
13681379
}
1380+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
13691381

13701382
bool InteractionModelEngine::HasConflictWriteRequests(const WriteHandler * apWriteHandler, const ConcreteAttributePath & aPath)
13711383
{
@@ -1724,6 +1736,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa
17241736
return Loop::Continue;
17251737
});
17261738

1739+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
17271740
for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient())
17281741
{
17291742
if (readClient->GetFabricIndex() == fabricIndex)
@@ -1732,6 +1745,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa
17321745
readClient->Close(CHIP_ERROR_IM_FABRIC_DELETED, false);
17331746
}
17341747
}
1748+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
17351749

17361750
for (auto & handler : mWriteHandlers)
17371751
{

src/app/InteractionModelEngine.h

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
128128
*/
129129
CASESessionManager * GetCASESessionManager() const { return mpCASESessionMgr; }
130130

131+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
131132
/**
132133
* Tears down an active subscription.
133134
*
@@ -150,6 +151,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
150151
* Tears down all active subscriptions.
151152
*/
152153
void ShutdownAllSubscriptions();
154+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
153155

154156
uint32_t GetNumActiveReadHandlers() const;
155157
uint32_t GetNumActiveReadHandlers(ReadHandler::InteractionType type) const;
@@ -231,6 +233,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
231233
void OnTimedWrite(TimedHandler * apTimedHandler, Messaging::ExchangeContext * apExchangeContext,
232234
const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload);
233235

236+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
234237
/**
235238
* Add a read client to the internally tracked list of weak references. This list is used to
236239
* correctly dispatch unsolicited reports to the right matching handler by subscription ID.
@@ -251,6 +254,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
251254
* Return the number of active read clients being tracked by the engine.
252255
*/
253256
size_t GetNumActiveReadClients();
257+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
254258

255259
/**
256260
* Returns the number of dirty subscriptions. Including the subscriptions that are generating reports.
@@ -345,6 +349,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
345349
//
346350
void ShutdownActiveReads()
347351
{
352+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
348353
for (auto * readClient = mpActiveReadClientList; readClient != nullptr;)
349354
{
350355
readClient->mpImEngine = nullptr;
@@ -358,6 +363,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
358363
// After that, we just null out our tracker.
359364
//
360365
mpActiveReadClientList = nullptr;
366+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
361367

362368
mReadHandlers.ReleaseAll();
363369
}
@@ -594,7 +600,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
594600

595601
ObjectPool<ReadHandler, CHIP_IM_MAX_NUM_READS + CHIP_IM_MAX_NUM_SUBSCRIPTIONS> mReadHandlers;
596602

603+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
597604
ReadClient * mpActiveReadClientList = nullptr;
605+
#endif
598606

599607
ReadHandler::ApplicationCallback * mpReadHandlerApplicationCallback = nullptr;
600608

src/app/ReadClient.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <protocols/Protocols.h>
5050
#include <system/SystemPacketBuffer.h>
5151

52+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
5253
namespace chip {
5354
namespace app {
5455

@@ -601,5 +602,6 @@ class ReadClient : public Messaging::ExchangeDelegate
601602
kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer;
602603
};
603604

604-
}; // namespace app
605-
}; // namespace chip
605+
}; // namespace app
606+
}; // namespace chip
607+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

src/app/common_flags.gni

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
declare_args() {
1616
# Temporary flag for interaction model and echo protocols, set it to true to enable
1717
chip_app_use_echo = false
18+
chip_enable_read_client = true
1819
}

src/controller/BUILD.gn

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,28 @@
1515
import("//build_overrides/chip.gni")
1616
import("${chip_root}/src/platform/device.gni")
1717
import("${chip_root}/src/platform/python.gni")
18+
import("${chip_root}/src/app/common_flags.gni")
19+
import("${chip_root}/src/lib/lib.gni")
1820

1921
static_library("controller") {
2022
output_name = "libChipController"
2123

2224
sources = [ "CHIPCluster.h" ]
2325

24-
if (chip_controller) {
26+
if (chip_controller && chip_build_controller) {
2527
sources += [
2628
"AbstractDnssdDiscoveryController.cpp",
2729
"AutoCommissioner.cpp",
2830
"AutoCommissioner.h",
2931
"CHIPCommissionableNodeController.cpp",
3032
"CHIPCommissionableNodeController.h",
31-
"CHIPDeviceController.cpp",
32-
"CHIPDeviceController.h",
3333
"CHIPDeviceControllerFactory.cpp",
3434
"CHIPDeviceControllerFactory.h",
3535
"CommissioneeDeviceProxy.cpp",
3636
"CommissioneeDeviceProxy.h",
3737
"CommissionerDiscoveryController.cpp",
3838
"CommissionerDiscoveryController.h",
3939
"CommissioningDelegate.cpp",
40-
"CommissioningWindowOpener.cpp",
41-
"CommissioningWindowOpener.h",
42-
"CurrentFabricRemover.cpp",
43-
"CurrentFabricRemover.h",
4440
"DeviceDiscoveryDelegate.h",
4541
"DevicePairingDelegate.h",
4642
"EmptyDataModelHandler.cpp",
@@ -51,6 +47,17 @@ static_library("controller") {
5147
]
5248
}
5349

50+
if (chip_enable_read_client) {
51+
sources += [
52+
"CHIPDeviceController.cpp",
53+
"CHIPDeviceController.h",
54+
"CommissioningWindowOpener.cpp",
55+
"CommissioningWindowOpener.h",
56+
"CurrentFabricRemover.cpp",
57+
"CurrentFabricRemover.h",
58+
]
59+
}
60+
5461
cflags = [ "-Wconversion" ]
5562

5663
public_deps = [

src/controller/CHIPCluster.h

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class DLL_EXPORT ClusterBase
221221
return WriteAttribute<AttributeInfo>(requestData, context, successCb, failureCb, NullOptional, doneCb, aDataVersion);
222222
}
223223

224+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
224225
/**
225226
* Read an attribute and get a type-safe callback with the attribute value.
226227
*/
@@ -399,6 +400,7 @@ class DLL_EXPORT ClusterBase
399400
onSubscriptionEstablishedCb, onResubscriptionAttemptCb,
400401
aKeepPreviousSubscriptions, aIsUrgentEvent);
401402
}
403+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
402404

403405
protected:
404406
Messaging::ExchangeManager & mExchangeManager;

0 commit comments

Comments
 (0)