@@ -280,11 +280,10 @@ CHIP_ERROR InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeCon
280
280
return CHIP_NO_ERROR;
281
281
}
282
282
283
- CHIP_ERROR InteractionModelEngine::OnReadInitialRequest (Messaging::ExchangeContext * apExchangeContext,
284
- const PayloadHeader & aPayloadHeader,
285
- System::PacketBufferHandle && aPayload,
286
- ReadHandler::InteractionType aInteractionType,
287
- Protocols::InteractionModel::Status & aStatus)
283
+ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest (Messaging::ExchangeContext * apExchangeContext,
284
+ const PayloadHeader & aPayloadHeader,
285
+ System::PacketBufferHandle && aPayload,
286
+ ReadHandler::InteractionType aInteractionType)
288
287
{
289
288
ChipLogDetail (InteractionModel, " Received %s request" ,
290
289
aInteractionType == ReadHandler::InteractionType::Subscribe ? " Subscribe" : " Read" );
@@ -301,55 +300,68 @@ CHIP_ERROR InteractionModelEngine::OnReadInitialRequest(Messaging::ExchangeConte
301
300
if (apExchangeContext->GetSessionHandle ()->GetFabricIndex () == kUndefinedFabricIndex )
302
301
{
303
302
// Subscriptions must be associated to a fabric.
304
- aStatus = Protocols::InteractionModel::Status::UnsupportedAccess;
305
- return CHIP_NO_ERROR;
303
+ return Status::UnsupportedAccess;
306
304
}
307
305
308
306
reader.Init (aPayload.Retain ());
309
307
310
308
SubscribeRequestMessage::Parser subscribeRequestParser;
311
- ReturnErrorOnFailure (subscribeRequestParser.Init (reader));
309
+ CHIP_ERROR err = subscribeRequestParser.Init (reader);
310
+ if (err != CHIP_NO_ERROR)
311
+ {
312
+ return Status::InvalidAction;
313
+ }
312
314
313
315
{
314
316
size_t requestedAttributePathCount = 0 ;
315
317
size_t requestedEventPathCount = 0 ;
316
318
AttributePathIBs::Parser attributePathListParser;
317
- CHIP_ERROR err = subscribeRequestParser.GetAttributeRequests (&attributePathListParser);
319
+ err = subscribeRequestParser.GetAttributeRequests (&attributePathListParser);
318
320
if (err == CHIP_NO_ERROR)
319
321
{
320
322
TLV::TLVReader pathReader;
321
323
attributePathListParser.GetReader (&pathReader);
322
- TLV::Utilities::Count (pathReader, requestedAttributePathCount, false );
324
+ err = TLV::Utilities::Count (pathReader, requestedAttributePathCount, false );
323
325
}
324
- else if (err ! = CHIP_ERROR_END_OF_TLV)
326
+ else if (err = = CHIP_ERROR_END_OF_TLV)
325
327
{
326
- aStatus = Protocols::InteractionModel::Status::InvalidAction;
327
- return CHIP_NO_ERROR;
328
+ err = CHIP_NO_ERROR;
328
329
}
330
+ if (err != CHIP_NO_ERROR)
331
+ {
332
+ return Status::InvalidAction;
333
+ }
334
+
329
335
EventPathIBs::Parser eventpathListParser;
330
336
err = subscribeRequestParser.GetEventRequests (&eventpathListParser);
331
337
if (err == CHIP_NO_ERROR)
332
338
{
333
339
TLV::TLVReader pathReader;
334
340
eventpathListParser.GetReader (&pathReader);
335
- TLV::Utilities::Count (pathReader, requestedEventPathCount, false );
341
+ err = TLV::Utilities::Count (pathReader, requestedEventPathCount, false );
342
+ }
343
+ else if (err == CHIP_ERROR_END_OF_TLV)
344
+ {
345
+ err = CHIP_NO_ERROR;
336
346
}
337
- else if (err != CHIP_ERROR_END_OF_TLV )
347
+ if (err != CHIP_NO_ERROR )
338
348
{
339
- aStatus = Protocols::InteractionModel::Status::InvalidAction;
340
- return CHIP_NO_ERROR;
349
+ return Status::InvalidAction;
341
350
}
342
351
343
352
// The following cast is safe, since we can only hold a few tens of paths in one request.
344
353
if (!EnsureResourceForSubscription (apExchangeContext->GetSessionHandle ()->GetFabricIndex (), requestedAttributePathCount,
345
354
requestedEventPathCount))
346
355
{
347
- aStatus = Protocols::InteractionModel::Status::PathsExhausted;
348
- return CHIP_NO_ERROR;
356
+ return Status::PathsExhausted;
349
357
}
350
358
}
351
359
352
- ReturnErrorOnFailure (subscribeRequestParser.GetKeepSubscriptions (&keepExistingSubscriptions));
360
+ err = subscribeRequestParser.GetKeepSubscriptions (&keepExistingSubscriptions);
361
+ if (err != CHIP_NO_ERROR)
362
+ {
363
+ return Status::InvalidAction;
364
+ }
353
365
354
366
if (!keepExistingSubscriptions)
355
367
{
@@ -386,40 +398,35 @@ CHIP_ERROR InteractionModelEngine::OnReadInitialRequest(Messaging::ExchangeConte
386
398
!HasActiveRead ())
387
399
{
388
400
ChipLogDetail (InteractionModel, " Reserve the last ReadHandler for IM read Interaction" );
389
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
390
- return CHIP_NO_ERROR;
401
+ return Status::ResourceExhausted;
391
402
}
392
403
393
404
#if CONFIG_IM_BUILD_FOR_UNIT_TEST
394
405
if ((handlerPoolCapacity - GetNumActiveReadHandlers ()) == 0 )
395
406
{
396
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
397
- return CHIP_NO_ERROR;
407
+ return Status::ResourceExhausted;
398
408
}
399
409
#endif
400
410
401
411
// We have already reserved enough resources for read requests, and have granted enough resources for current subscriptions, so
402
412
// we should be able to allocate resources requested by this request.
403
413
ReadHandler * handler = mReadHandlers .CreateObject (*this , apExchangeContext, aInteractionType);
404
- if (handler)
414
+ if (handler == nullptr )
405
415
{
406
- CHIP_ERROR err = handler->OnInitialRequest (std::move (aPayload));
407
- if (err == CHIP_ERROR_NO_MEMORY)
408
- {
409
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
410
- }
411
- else
412
- {
413
- aStatus = StatusIB (err).mStatus ;
414
- }
415
- return err;
416
+ ChipLogProgress (InteractionModel, " no resource for %s interaction" ,
417
+ aInteractionType == ReadHandler::InteractionType::Subscribe ? " Subscribe" : " Read" );
418
+ return Status::ResourceExhausted;
416
419
}
417
420
418
- ChipLogProgress (InteractionModel, " no resource for %s interaction" ,
419
- aInteractionType == ReadHandler::InteractionType::Subscribe ? " Subscribe" : " Read" );
420
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
421
+ CHIP_ERROR err = handler->OnInitialRequest (std::move (aPayload));
422
+ if (err == CHIP_ERROR_NO_MEMORY)
423
+ {
424
+ return Status::ResourceExhausted;
425
+ }
421
426
422
- return CHIP_NO_ERROR;
427
+ // TODO: Should probably map various TLV errors into InvalidAction, here
428
+ // or inside the read handler.
429
+ return StatusIB (err).mStatus ;
423
430
}
424
431
425
432
Protocols::InteractionModel::Status InteractionModelEngine::OnWriteRequest (Messaging::ExchangeContext * apExchangeContext,
@@ -506,7 +513,6 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
506
513
{
507
514
using namespace Protocols ::InteractionModel;
508
515
509
- CHIP_ERROR err = CHIP_NO_ERROR;
510
516
Protocols::InteractionModel::Status status = Protocols::InteractionModel::Status::Failure;
511
517
512
518
// Group Message can only be an InvokeCommandRequest or WriteRequest
@@ -515,27 +521,25 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
515
521
!aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::WriteRequest))
516
522
{
517
523
ChipLogProgress (InteractionModel, " Msg type %d not supported for group message" , aPayloadHeader.GetMessageType ());
518
- return err ;
524
+ return CHIP_NO_ERROR ;
519
525
}
520
526
521
527
if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::InvokeCommandRequest))
522
528
{
523
- SuccessOrExit (
524
- OnInvokeCommandRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedInvoke = */ false , status));
529
+ OnInvokeCommandRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedInvoke = */ false , status);
525
530
}
526
531
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::ReadRequest))
527
532
{
528
- SuccessOrExit (OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload),
529
- ReadHandler::InteractionType::Read, status));
533
+ status = OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), ReadHandler::InteractionType::Read);
530
534
}
531
535
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::WriteRequest))
532
536
{
533
537
status = OnWriteRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedWrite = */ false );
534
538
}
535
539
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::SubscribeRequest))
536
540
{
537
- SuccessOrExit ( OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload),
538
- ReadHandler::InteractionType::Subscribe, status) );
541
+ status =
542
+ OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), ReadHandler::InteractionType::Subscribe);
539
543
}
540
544
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::ReportData))
541
545
{
@@ -544,19 +548,19 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
544
548
}
545
549
else if (aPayloadHeader.HasMessageType (MsgType::TimedRequest))
546
550
{
547
- SuccessOrExit ( OnTimedRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), status) );
551
+ OnTimedRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), status);
548
552
}
549
553
else
550
554
{
551
555
ChipLogProgress (InteractionModel, " Msg type %d not supported" , aPayloadHeader.GetMessageType ());
552
556
}
553
557
554
- exit :
555
558
if (status != Protocols::InteractionModel::Status::Success && !apExchangeContext->IsGroupExchangeContext ())
556
559
{
557
- err = StatusResponse::Send (status, apExchangeContext, false /* aExpectResponse*/ );
560
+ return StatusResponse::Send (status, apExchangeContext, false /* aExpectResponse*/ );
558
561
}
559
- return err;
562
+
563
+ return CHIP_NO_ERROR;
560
564
}
561
565
562
566
void InteractionModelEngine::OnResponseTimeout (Messaging::ExchangeContext * ec)
0 commit comments