@@ -59,133 +59,105 @@ using Transport::Session;
59
59
namespace {
60
60
61
61
template <typename Provider, typename T>
62
- static CHIP_ERROR ReadInternal (Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&), AttributeValueEncoder& aEncoder)
62
+ static CHIP_ERROR ReadIfSupported (Provider * const provider, CHIP_ERROR (Provider::*const nonConstGetter)(T &),
63
+ AttributeValueEncoder & aEncoder)
63
64
{
64
- T data;
65
-
66
65
if (nullptr == provider)
67
66
{
68
67
return CHIP_ERROR_PERSISTED_STORAGE_FAILED;
69
68
}
70
69
71
- CHIP_ERROR err = (provider->*getter)(data);
72
- if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
73
- {
74
- data = 0 ;
75
- }
76
- else if (err != CHIP_NO_ERROR)
70
+ T value;
71
+ CHIP_ERROR err = (provider->*nonConstGetter)(value);
72
+ if (err != CHIP_NO_ERROR)
77
73
{
78
74
return err;
79
75
}
80
76
81
- return aEncoder.Encode (data );
77
+ return aEncoder.Encode (value );
82
78
}
83
79
84
80
template <typename Provider, typename T>
85
- static CHIP_ERROR ReadInternal (Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&) const , AttributeValueEncoder& aEncoder)
81
+ static CHIP_ERROR ReadIfSupported (Provider * const provider, CHIP_ERROR (Provider::*const getter)(T &) const ,
82
+ AttributeValueEncoder & aEncoder)
86
83
{
87
- // Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not correctly marked as const.
88
- using NonConstGetter = CHIP_ERROR (Provider::*)(T&);
84
+ // Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not
85
+ // correctly marked as const.
86
+ using NonConstGetter = CHIP_ERROR (Provider::*)(T &);
89
87
NonConstGetter nonConstGetter = reinterpret_cast <NonConstGetter>(getter);
90
-
91
- return ReadInternal (provider, nonConstGetter, aEncoder);
88
+ return ReadIfSupported (provider, nonConstGetter, aEncoder);
92
89
}
93
90
94
- template <typename ... Args>
95
- static CHIP_ERROR ReadIfSupported (Args &&... args)
96
- {
97
- return ReadInternal (std::forward<Args>(args)...);
98
- }
99
-
100
- class GeneralCommissioningAttrAccess : public AttributeAccessInterface
91
+ class _ : public AttributeAccessInterface
101
92
{
102
93
public:
103
- // Register for the GeneralCommissioning cluster on all endpoints.
104
- GeneralCommissioningAttrAccess () : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}
105
-
106
- CHIP_ERROR Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override ;
107
-
108
- private:
109
- CHIP_ERROR ReadBasicCommissioningInfo (AttributeValueEncoder & aEncoder);
110
- CHIP_ERROR ReadSupportsConcurrentConnection (AttributeValueEncoder & aEncoder);
111
- };
112
-
113
- GeneralCommissioningAttrAccess gAttrAccess ;
114
-
115
- CHIP_ERROR GeneralCommissioningAttrAccess::Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
116
- {
117
- if (aPath.mClusterId != GeneralCommissioning::Id)
118
- {
119
- // We shouldn't have been called at all.
120
- return CHIP_ERROR_INVALID_ARGUMENT;
121
- }
94
+ _ () : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}
122
95
123
- switch ( aPath. mAttributeId )
96
+ CHIP_ERROR Read ( const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder )
124
97
{
125
- case RegulatoryConfig::Id: {
126
- return ReadIfSupported (&DeviceLayer::ConfigurationMgr (), &ConfigurationManager::GetRegulatoryLocation, aEncoder);
127
- }
128
- case LocationCapability::Id: {
129
- return ReadIfSupported (&DeviceLayer::ConfigurationMgr (), &ConfigurationManager::GetLocationCapability, aEncoder);
130
- }
131
- case BasicCommissioningInfo::Id: {
132
- return ReadBasicCommissioningInfo (aEncoder);
133
- }
134
- case SupportsConcurrentConnection::Id: {
135
- return ReadSupportsConcurrentConnection (aEncoder);
136
- }
137
- #if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
138
- case TCAcceptedVersion::Id: {
139
- app::EnhancedSetupFlowProvider * provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
140
- auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion;
141
- return ReadIfSupported (provider, getter, aEncoder);
142
- }
143
- case TCMinRequiredVersion::Id: {
144
- auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
145
- auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion;
146
- return ReadIfSupported (provider, getter, aEncoder);
147
- }
148
- case TCAcknowledgements::Id: {
149
- auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
150
- auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements;
151
- return ReadIfSupported (provider, getter, aEncoder);
152
- }
153
- case TCAcknowledgementsRequired::Id: {
154
- auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
155
- auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements;
156
- return ReadIfSupported (provider, getter, aEncoder);
157
- }
158
- #endif
159
- default :
160
- break ;
161
- }
162
- return CHIP_NO_ERROR;
163
- }
164
-
165
- CHIP_ERROR GeneralCommissioningAttrAccess::ReadBasicCommissioningInfo (AttributeValueEncoder & aEncoder)
166
- {
167
- BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo;
98
+ if (aPath.mClusterId != GeneralCommissioning::Id)
99
+ {
100
+ // We shouldn't have been called at all.
101
+ return CHIP_ERROR_INVALID_ARGUMENT;
102
+ }
168
103
169
- // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
170
- // the CommissioningParameters at the beginning of commissioning flow.
171
- basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC;
172
- basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC;
173
- static_assert (CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC,
174
- " Max cumulative failsafe seconds must be larger than failsafe expiry length seconds" );
104
+ switch (aPath.mAttributeId )
105
+ {
106
+ case RegulatoryConfig::Id: {
107
+ return ReadIfSupported (&DeviceLayer::ConfigurationMgr (), &ConfigurationManager::GetRegulatoryLocation, aEncoder);
108
+ }
109
+ case LocationCapability::Id: {
110
+ return ReadIfSupported (&DeviceLayer::ConfigurationMgr (), &ConfigurationManager::GetLocationCapability, aEncoder);
111
+ }
112
+ case BasicCommissioningInfo::Id: {
113
+ BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo;
175
114
176
- return aEncoder.Encode (basicCommissioningInfo);
177
- }
115
+ // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
116
+ // the CommissioningParameters at the beginning of commissioning flow.
117
+ basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC;
118
+ basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC;
119
+ static_assert (CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC,
120
+ " Max cumulative failsafe seconds must be larger than failsafe expiry length seconds" );
178
121
179
- CHIP_ERROR GeneralCommissioningAttrAccess::ReadSupportsConcurrentConnection (AttributeValueEncoder & aEncoder)
180
- {
181
- SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection;
122
+ return aEncoder.Encode (basicCommissioningInfo);
123
+ }
124
+ case SupportsConcurrentConnection::Id: {
125
+ SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection;
182
126
183
- // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
184
- // the CommissioningParameters at the beginning of commissioning flow.
185
- supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0 ;
127
+ // TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
128
+ // the CommissioningParameters at the beginning of commissioning flow.
129
+ supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0 ;
186
130
187
- return aEncoder.Encode (supportsConcurrentConnection);
188
- }
131
+ return aEncoder.Encode (supportsConcurrentConnection);
132
+ }
133
+ #if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
134
+ case TCAcceptedVersion::Id: {
135
+ auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
136
+ auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion;
137
+ return ReadIfSupported (provider, getter, aEncoder);
138
+ }
139
+ case TCMinRequiredVersion::Id: {
140
+ auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
141
+ auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion;
142
+ return ReadIfSupported (provider, getter, aEncoder);
143
+ }
144
+ case TCAcknowledgements::Id: {
145
+ auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
146
+ auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements;
147
+ return ReadIfSupported (provider, getter, aEncoder);
148
+ }
149
+ case TCAcknowledgementsRequired::Id: {
150
+ auto provider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
151
+ auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements;
152
+ return ReadIfSupported (provider, getter, aEncoder);
153
+ }
154
+ #endif
155
+ default :
156
+ break ;
157
+ }
158
+ return CHIP_NO_ERROR;
159
+ }
160
+ } gAttributeAccessInstance ;
189
161
190
162
} // anonymous namespace
191
163
@@ -257,7 +229,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
257
229
{
258
230
MATTER_TRACE_SCOPE (" CommissioningComplete" , " GeneralCommissioning" );
259
231
260
- #if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
232
+ #if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
261
233
EnhancedSetupFlowProvider * enhancedSetupFlowProvider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
262
234
#endif
263
235
DeviceControlServer * const devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr ();
@@ -287,7 +259,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
287
259
{
288
260
CHIP_ERROR err;
289
261
290
- #if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
262
+ #if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
291
263
292
264
uint16_t termsAndConditionsAcceptedAcknowledgements;
293
265
bool hasRequiredTermAccepted;
@@ -297,8 +269,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
297
269
termsAndConditionsAcceptedAcknowledgements);
298
270
CheckSuccess (err, Failure);
299
271
300
- err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted (
301
- hasRequiredTermAccepted);
272
+ err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted (hasRequiredTermAccepted);
302
273
CheckSuccess (err, Failure);
303
274
304
275
err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted (
@@ -408,7 +379,7 @@ bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback(
408
379
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
409
380
const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData)
410
381
{
411
- #if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
382
+ #if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
412
383
MATTER_TRACE_SCOPE (" SetTCAcknowledgements" , " GeneralCommissioning" );
413
384
Commands::SetTCAcknowledgementsResponse::Type response;
414
385
EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance ().GetEnhancedSetupFlowProvider ();
@@ -437,7 +408,7 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t
437
408
void MatterGeneralCommissioningPluginServerInitCallback ()
438
409
{
439
410
Breadcrumb::Set (0 , 0 );
440
- registerAttributeAccessOverride (&gAttrAccess );
411
+ registerAttributeAccessOverride (&gAttributeAccessInstance );
441
412
DeviceLayer::PlatformMgrImpl ().AddEventHandler (OnPlatformEventHandler);
442
413
}
443
414
0 commit comments