@@ -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 );
336
342
}
337
- else if (err ! = CHIP_ERROR_END_OF_TLV)
343
+ else if (err = = CHIP_ERROR_END_OF_TLV)
338
344
{
339
- aStatus = Protocols::InteractionModel::Status::InvalidAction;
340
- return CHIP_NO_ERROR;
345
+ err = CHIP_NO_ERROR;
346
+ }
347
+ if (err != CHIP_NO_ERROR)
348
+ {
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
{
@@ -381,33 +393,29 @@ CHIP_ERROR InteractionModelEngine::OnReadInitialRequest(Messaging::ExchangeConte
381
393
382
394
if ((handlerPoolCapacity - GetNumActiveReadHandlers ()) == 0 )
383
395
{
384
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
385
- return CHIP_NO_ERROR;
396
+ return Status::ResourceExhausted;
386
397
}
387
398
#endif
388
399
389
400
// We have already reserved enough resources for read requests, and have granted enough resources for current subscriptions, so
390
401
// we should be able to allocate resources requested by this request.
391
402
ReadHandler * handler = mReadHandlers .CreateObject (*this , apExchangeContext, aInteractionType);
392
- if (handler)
403
+ if (handler == nullptr )
393
404
{
394
- CHIP_ERROR err = handler->OnInitialRequest (std::move (aPayload));
395
- if (err == CHIP_ERROR_NO_MEMORY)
396
- {
397
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
398
- }
399
- else
400
- {
401
- aStatus = StatusIB (err).mStatus ;
402
- }
403
- return err;
405
+ ChipLogProgress (InteractionModel, " no resource for %s interaction" ,
406
+ aInteractionType == ReadHandler::InteractionType::Subscribe ? " Subscribe" : " Read" );
407
+ return Status::ResourceExhausted;
404
408
}
405
409
406
- ChipLogProgress (InteractionModel, " no resource for %s interaction" ,
407
- aInteractionType == ReadHandler::InteractionType::Subscribe ? " Subscribe" : " Read" );
408
- aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
410
+ CHIP_ERROR err = handler->OnInitialRequest (std::move (aPayload));
411
+ if (err == CHIP_ERROR_NO_MEMORY)
412
+ {
413
+ return Status::ResourceExhausted;
414
+ }
409
415
410
- return CHIP_NO_ERROR;
416
+ // TODO: Should probably map various TLV errors into InvalidAction, here
417
+ // or inside the read handler.
418
+ return StatusIB (err).mStatus ;
411
419
}
412
420
413
421
Protocols::InteractionModel::Status InteractionModelEngine::OnWriteRequest (Messaging::ExchangeContext * apExchangeContext,
@@ -494,7 +502,6 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
494
502
{
495
503
using namespace Protocols ::InteractionModel;
496
504
497
- CHIP_ERROR err = CHIP_NO_ERROR;
498
505
Protocols::InteractionModel::Status status = Protocols::InteractionModel::Status::Failure;
499
506
500
507
// Group Message can only be an InvokeCommandRequest or WriteRequest
@@ -503,27 +510,25 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
503
510
!aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::WriteRequest))
504
511
{
505
512
ChipLogProgress (InteractionModel, " Msg type %d not supported for group message" , aPayloadHeader.GetMessageType ());
506
- return err ;
513
+ return CHIP_NO_ERROR ;
507
514
}
508
515
509
516
if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::InvokeCommandRequest))
510
517
{
511
- SuccessOrExit (
512
- OnInvokeCommandRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedInvoke = */ false , status));
518
+ OnInvokeCommandRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedInvoke = */ false , status);
513
519
}
514
520
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::ReadRequest))
515
521
{
516
- SuccessOrExit (OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload),
517
- ReadHandler::InteractionType::Read, status));
522
+ status = OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), ReadHandler::InteractionType::Read);
518
523
}
519
524
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::WriteRequest))
520
525
{
521
526
status = OnWriteRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), /* aIsTimedWrite = */ false );
522
527
}
523
528
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::SubscribeRequest))
524
529
{
525
- SuccessOrExit ( OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload),
526
- ReadHandler::InteractionType::Subscribe, status) );
530
+ status =
531
+ OnReadInitialRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), ReadHandler::InteractionType::Subscribe);
527
532
}
528
533
else if (aPayloadHeader.HasMessageType (Protocols::InteractionModel::MsgType::ReportData))
529
534
{
@@ -532,19 +537,19 @@ CHIP_ERROR InteractionModelEngine::OnMessageReceived(Messaging::ExchangeContext
532
537
}
533
538
else if (aPayloadHeader.HasMessageType (MsgType::TimedRequest))
534
539
{
535
- SuccessOrExit ( OnTimedRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), status) );
540
+ OnTimedRequest (apExchangeContext, aPayloadHeader, std::move (aPayload), status);
536
541
}
537
542
else
538
543
{
539
544
ChipLogProgress (InteractionModel, " Msg type %d not supported" , aPayloadHeader.GetMessageType ());
540
545
}
541
546
542
- exit :
543
547
if (status != Protocols::InteractionModel::Status::Success && !apExchangeContext->IsGroupExchangeContext ())
544
548
{
545
- err = StatusResponse::Send (status, apExchangeContext, false /* aExpectResponse*/ );
549
+ return StatusResponse::Send (status, apExchangeContext, false /* aExpectResponse*/ );
546
550
}
547
- return err;
551
+
552
+ return CHIP_NO_ERROR;
548
553
}
549
554
550
555
void InteractionModelEngine::OnResponseTimeout (Messaging::ExchangeContext * ec)
0 commit comments