@@ -238,6 +238,8 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device
238
238
239
239
void OnDone () override ;
240
240
241
+ void OnDeallocatePaths (ReadPrepareParams && aReadPrepareParams) override ;
242
+
241
243
void OnSubscriptionEstablished (uint64_t aSubscriptionId) override ;
242
244
243
245
void ReportError (CHIP_ERROR err);
@@ -274,6 +276,7 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device
274
276
- (void )subscribeWithQueue : (dispatch_queue_t )queue
275
277
minInterval : (uint16_t )minInterval
276
278
maxInterval : (uint16_t )maxInterval
279
+ params : (nullable CHIPSubscribeParams *)params
277
280
reportHandler : (void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
278
281
subscriptionEstablished : (nullable void (^)(void ))subscriptionEstablishedHandler
279
282
{
@@ -284,18 +287,30 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
284
287
});
285
288
return ;
286
289
}
287
- AttributePathParams attributePath; // Wildcard endpoint, cluster, attribute.
288
- ReadPrepareParams params (device->GetSecureSession ().Value ());
289
- params.mMinIntervalFloorSeconds = minInterval;
290
- params.mMaxIntervalCeilingSeconds = maxInterval;
291
- params.mpAttributePathParamsList = &attributePath;
292
- params.mAttributePathParamsListSize = 1 ;
290
+
291
+ // Wildcard endpoint, cluster, attribute.
292
+ auto attributePath = std::make_unique<AttributePathParams>();
293
+ ReadPrepareParams readParams (device->GetSecureSession ().Value ());
294
+ readParams.mMinIntervalFloorSeconds = minInterval;
295
+ readParams.mMaxIntervalCeilingSeconds = maxInterval;
296
+ readParams.mpAttributePathParamsList = attributePath.get ();
297
+ readParams.mAttributePathParamsListSize = 1 ;
298
+ readParams.mKeepSubscriptions
299
+ = (params != nil ) && (params.keepPreviousSubscriptions != nil ) && [params.keepPreviousSubscriptions boolValue ];
293
300
294
301
auto callback = std::make_unique<SubscriptionCallback>(queue, reportHandler, subscriptionEstablishedHandler);
295
302
auto readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance (), device->GetExchangeManager (),
296
303
callback->GetBufferedCallback (), ReadClient::InteractionType::Subscribe);
297
304
298
- CHIP_ERROR err = readClient->SendRequest (params);
305
+ CHIP_ERROR err;
306
+ if (params != nil && params.autoResubscribe != nil && ![params.autoResubscribe boolValue ]) {
307
+ err = readClient->SendRequest (readParams);
308
+ } else {
309
+ // SendAutoResubscribeRequest cleans up the params, even on failure.
310
+ attributePath.release ();
311
+ err = readClient->SendAutoResubscribeRequest (std::move (readParams));
312
+ }
313
+
299
314
if (err != CHIP_NO_ERROR) {
300
315
dispatch_async (queue, ^{
301
316
reportHandler (nil , [CHIPError errorForCHIPErrorCode: err]);
@@ -1266,12 +1281,31 @@ - (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(null
1266
1281
}
1267
1282
}
1268
1283
1284
+ void SubscriptionCallback::OnDeallocatePaths (ReadPrepareParams && aReadPrepareParams)
1285
+ {
1286
+ VerifyOrDie ((aReadPrepareParams.mAttributePathParamsListSize == 0 && aReadPrepareParams.mpAttributePathParamsList == nullptr )
1287
+ || (aReadPrepareParams.mAttributePathParamsListSize == 1 && aReadPrepareParams.mpAttributePathParamsList != nullptr ));
1288
+ if (aReadPrepareParams.mpAttributePathParamsList ) {
1289
+ delete aReadPrepareParams.mpAttributePathParamsList ;
1290
+ }
1291
+
1292
+ VerifyOrDie ((aReadPrepareParams.mDataVersionFilterListSize == 0 && aReadPrepareParams.mpDataVersionFilterList == nullptr )
1293
+ || (aReadPrepareParams.mDataVersionFilterListSize == 1 && aReadPrepareParams.mpDataVersionFilterList != nullptr ));
1294
+ if (aReadPrepareParams.mpDataVersionFilterList != nullptr ) {
1295
+ delete aReadPrepareParams.mpDataVersionFilterList ;
1296
+ }
1297
+
1298
+ VerifyOrDie ((aReadPrepareParams.mEventPathParamsListSize == 0 && aReadPrepareParams.mpEventPathParamsList == nullptr )
1299
+ || (aReadPrepareParams.mEventPathParamsListSize == 1 && aReadPrepareParams.mpEventPathParamsList != nullptr ));
1300
+ if (aReadPrepareParams.mpEventPathParamsList ) {
1301
+ delete aReadPrepareParams.mpEventPathParamsList ;
1302
+ }
1303
+ }
1304
+
1269
1305
void SubscriptionCallback::OnSubscriptionEstablished (uint64_t aSubscriptionId)
1270
1306
{
1271
1307
if (mSubscriptionEstablishedHandler ) {
1272
1308
dispatch_async (mQueue , mSubscriptionEstablishedHandler );
1273
- // Don't need it anymore.
1274
- mSubscriptionEstablishedHandler = nil ;
1275
1309
}
1276
1310
}
1277
1311
0 commit comments