Skip to content

Commit 14bdc24

Browse files
[app] Add option to disable read client (#28149)
* app : Add option to disable Read Client * Restyled by gn * Format changes * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 6a5f704 commit 14bdc24

17 files changed

+89
-17
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
@@ -27,3 +27,5 @@ chip_project_config_include_dirs =
2727
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
2828

2929
matter_enable_tracing_support = true
30+
31+
chip_enable_read_client = false

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
@@ -58,6 +58,7 @@ buildconfig_header("app_buildconfig") {
5858
"CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION=${chip_subscription_timeout_resumption}",
5959
"CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE=${enable_eventlist_attribute}",
6060
"CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}",
61+
"CHIP_CONFIG_ENABLE_READ_CLIENT=${chip_enable_read_client}",
6162
]
6263
}
6364

@@ -76,16 +77,13 @@ static_library("app") {
7677
"AttributePathExpandIterator.h",
7778
"AttributePathParams.h",
7879
"AttributePersistenceProvider.h",
79-
"BufferedReadCallback.cpp",
8080
"CASEClient.cpp",
8181
"CASEClient.h",
8282
"CASEClientPool.h",
8383
"CASESessionManager.cpp",
8484
"CASESessionManager.h",
8585
"ChunkedWriteCallback.cpp",
8686
"ChunkedWriteCallback.h",
87-
"ClusterStateCache.cpp",
88-
"ClusterStateCache.h",
8987
"CommandHandler.cpp",
9088
"CommandResponseHelper.h",
9189
"CommandSender.cpp",
@@ -179,7 +177,6 @@ static_library("app") {
179177
"OperationalSessionSetup.cpp",
180178
"OperationalSessionSetup.h",
181179
"OperationalSessionSetupPool.h",
182-
"ReadClient.cpp",
183180
"ReadHandler.cpp",
184181
"RequiredPrivilege.cpp",
185182
"RequiredPrivilege.h",
@@ -210,6 +207,15 @@ static_library("app") {
210207
]
211208
}
212209

210+
if (chip_enable_read_client) {
211+
sources += [
212+
"BufferedReadCallback.cpp",
213+
"ClusterStateCache.cpp",
214+
"ClusterStateCache.h",
215+
"ReadClient.cpp",
216+
]
217+
}
218+
213219
public_deps = [
214220
":app_config",
215221
"${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

@@ -133,3 +134,4 @@ class BufferedReadCallback : public ReadClient::Callback
133134

134135
} // namespace app
135136
} // namespace chip
137+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

src/app/ClusterStateCache.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <set>
3434
#include <vector>
3535

36+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
3637
namespace chip {
3738
namespace app {
3839
/*
@@ -660,5 +661,6 @@ class ClusterStateCache : protected ReadClient::Callback
660661
const bool mCacheData = true;
661662
};
662663

663-
}; // namespace app
664-
}; // namespace chip
664+
}; // namespace app
665+
}; // namespace chip
666+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT

src/app/InteractionModelEngine.cpp

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

109109
mReadHandlers.ReleaseAll();
110110

111+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
111112
// Shut down any subscription clients that are still around. They won't be
112113
// able to work after this point anyway, since we're about to drop our refs
113114
// to them.
@@ -134,6 +135,7 @@ void InteractionModelEngine::Shutdown()
134135
// After that, we just null out our tracker.
135136
//
136137
mpActiveReadClientList = nullptr;
138+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
137139

138140
for (auto & writeHandler : mWriteHandlers)
139141
{
@@ -254,6 +256,7 @@ uint32_t InteractionModelEngine::GetNumActiveWriteHandlers() const
254256
return numActive;
255257
}
256258

259+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
257260
CHIP_ERROR InteractionModelEngine::ShutdownSubscription(const ScopedNodeId & aPeerNodeId, SubscriptionId aSubscriptionId)
258261
{
259262
assertChipStackLockedByCurrentThread();
@@ -311,6 +314,7 @@ void InteractionModelEngine::ShutdownMatchingSubscriptions(const Optional<Fabric
311314
readClient = nextClient;
312315
}
313316
}
317+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
314318

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

801+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
797802
Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContext * apExchangeContext,
798803
const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload)
799804
{
@@ -849,6 +854,7 @@ Status InteractionModelEngine::OnUnsolicitedReportData(Messaging::ExchangeContex
849854

850855
return Status::InvalidSubscription;
851856
}
857+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
852858

853859
CHIP_ERROR InteractionModelEngine::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
854860
ExchangeDelegate *& newDelegate)
@@ -892,10 +898,12 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
892898
status =
893899
OnReadInitialRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), ReadHandler::InteractionType::Subscribe);
894900
}
901+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
895902
else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::ReportData))
896903
{
897904
status = OnUnsolicitedReportData(apExchangeContext, aPayloadHeader, std::move(aPayload));
898905
}
906+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
899907
else if (aPayloadHeader.HasMessageType(MsgType::TimedRequest))
900908
{
901909
OnTimedRequest(apExchangeContext, aPayloadHeader, std::move(aPayload), status);
@@ -920,11 +928,13 @@ void InteractionModelEngine::OnResponseTimeout(Messaging::ExchangeContext * ec)
920928
ChipLogValueExchange(ec));
921929
}
922930

931+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
923932
void InteractionModelEngine::AddReadClient(ReadClient * apReadClient)
924933
{
925934
apReadClient->SetNextClient(mpActiveReadClientList);
926935
mpActiveReadClientList = apReadClient;
927936
}
937+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
928938

929939
bool InteractionModelEngine::TrimFabricForSubscriptions(FabricIndex aFabricIndex, bool aForceEvict)
930940
{
@@ -1322,6 +1332,7 @@ Protocols::InteractionModel::Status InteractionModelEngine::EnsureResourceForRea
13221332
return Status::Success;
13231333
}
13241334

1335+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
13251336
void InteractionModelEngine::RemoveReadClient(ReadClient * apReadClient)
13261337
{
13271338
ReadClient * pPrevListItem = nullptr;
@@ -1380,6 +1391,7 @@ bool InteractionModelEngine::InActiveReadClientList(ReadClient * apReadClient)
13801391

13811392
return false;
13821393
}
1394+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
13831395

13841396
bool InteractionModelEngine::HasConflictWriteRequests(const WriteHandler * apWriteHandler, const ConcreteAttributePath & aPath)
13851397
{
@@ -1738,6 +1750,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa
17381750
return Loop::Continue;
17391751
});
17401752

1753+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
17411754
for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient())
17421755
{
17431756
if (readClient->GetFabricIndex() == fabricIndex)
@@ -1746,6 +1759,7 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa
17461759
readClient->Close(CHIP_ERROR_IM_FABRIC_DELETED, false);
17471760
}
17481761
}
1762+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
17491763

17501764
for (auto & handler : mWriteHandlers)
17511765
{

src/app/InteractionModelEngine.h

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

132+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
132133
/**
133134
* Tears down an active subscription.
134135
*
@@ -151,6 +152,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
151152
* Tears down all active subscriptions.
152153
*/
153154
void ShutdownAllSubscriptions();
155+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
154156

155157
uint32_t GetNumActiveReadHandlers() const;
156158
uint32_t GetNumActiveReadHandlers(ReadHandler::InteractionType type) const;
@@ -234,6 +236,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
234236
void OnTimedWrite(TimedHandler * apTimedHandler, Messaging::ExchangeContext * apExchangeContext,
235237
const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload);
236238

239+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
237240
/**
238241
* Add a read client to the internally tracked list of weak references. This list is used to
239242
* correctly dispatch unsolicited reports to the right matching handler by subscription ID.
@@ -254,6 +257,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
254257
* Return the number of active read clients being tracked by the engine.
255258
*/
256259
size_t GetNumActiveReadClients();
260+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
257261

258262
/**
259263
* Returns the number of dirty subscriptions. Including the subscriptions that are generating reports.
@@ -348,6 +352,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
348352
//
349353
void ShutdownActiveReads()
350354
{
355+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
351356
for (auto * readClient = mpActiveReadClientList; readClient != nullptr;)
352357
{
353358
readClient->mpImEngine = nullptr;
@@ -361,6 +366,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
361366
// After that, we just null out our tracker.
362367
//
363368
mpActiveReadClientList = nullptr;
369+
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
364370

365371
mReadHandlers.ReleaseAll();
366372
}
@@ -599,7 +605,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
599605

600606
ObjectPool<ReadHandler, CHIP_IM_MAX_NUM_READS + CHIP_IM_MAX_NUM_SUBSCRIPTIONS> mReadHandlers;
601607

608+
#if CHIP_CONFIG_ENABLE_READ_CLIENT
602609
ReadClient * mpActiveReadClientList = nullptr;
610+
#endif
603611

604612
ReadHandler::ApplicationCallback * mpReadHandlerApplicationCallback = nullptr;
605613

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

@@ -613,5 +614,6 @@ class ReadClient : public Messaging::ExchangeDelegate
613614
kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer;
614615
};
615616

616-
}; // namespace app
617-
}; // namespace chip
617+
}; // namespace app
618+
}; // namespace chip
619+
#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

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
import("//build_overrides/chip.gni")
16+
import("${chip_root}/src/app/common_flags.gni")
17+
import("${chip_root}/src/lib/lib.gni")
1618
import("${chip_root}/src/platform/device.gni")
1719
import("${chip_root}/src/platform/python.gni")
1820

@@ -21,26 +23,20 @@ static_library("controller") {
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",
@@ -49,6 +45,16 @@ static_library("controller") {
4945
"SetUpCodePairer.cpp",
5046
"SetUpCodePairer.h",
5147
]
48+
if (chip_enable_read_client) {
49+
sources += [
50+
"CHIPDeviceController.cpp",
51+
"CHIPDeviceController.h",
52+
"CommissioningWindowOpener.cpp",
53+
"CommissioningWindowOpener.h",
54+
"CurrentFabricRemover.cpp",
55+
"CurrentFabricRemover.h",
56+
]
57+
}
5258
}
5359

5460
cflags = [ "-Wconversion" ]

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)