Skip to content

Commit 5822ca8

Browse files
Reserve the last read handler for ReadInteraction
1 parent 1423df5 commit 5822ca8

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/app/InteractionModelEngine.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ CHIP_ERROR InteractionModelEngine::NewReadClient(ReadClient ** const apReadClien
131131
ReadClient::Callback * aCallback)
132132
{
133133
*apReadClient = nullptr;
134-
135134
for (auto & readClient : mReadClients)
136135
{
137136
if (readClient.IsFree())
@@ -314,6 +313,15 @@ CHIP_ERROR InteractionModelEngine::OnReadInitialRequest(Messaging::ExchangeConte
314313
}
315314
}
316315

316+
// Reserve the last ReadHandler for ReadInteraction
317+
if (aInteractionType == ReadHandler::InteractionType::Subscribe &&
318+
((CHIP_IM_MAX_NUM_READ_HANDLER - GetNumActiveReadHandlers()) == 1) && !HasActiveRead())
319+
{
320+
ChipLogProgress(InteractionModel, "Reserve the last ReadHandler for IM read Interaction");
321+
aStatus = Protocols::InteractionModel::Status::ResourceExhausted;
322+
return CHIP_NO_ERROR;
323+
}
324+
317325
for (auto & readHandler : mReadHandlers)
318326
{
319327
if (readHandler.IsFree())
@@ -728,5 +736,18 @@ void InteractionModelEngine::OnTimedWrite(TimedHandler * apTimedHandler, Messagi
728736
}
729737
}
730738

739+
bool InteractionModelEngine::HasActiveRead()
740+
{
741+
for (auto & readHandler : mReadHandlers)
742+
{
743+
if (!readHandler.IsFree() && readHandler.IsReadType())
744+
{
745+
return true;
746+
}
747+
}
748+
749+
return false;
750+
}
751+
731752
} // namespace app
732753
} // namespace chip

src/app/InteractionModelEngine.h

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate, public Comman
275275
TLV::TLVReader & apPayload) override;
276276
bool CommandExists(const ConcreteCommandPath & aCommandPath) override;
277277

278+
bool HasActiveRead();
279+
278280
Messaging::ExchangeManager * mpExchangeMgr = nullptr;
279281
InteractionModelDelegate * mpDelegate = nullptr;
280282

src/app/tests/TestReadInteraction.cpp

+1-24
Original file line numberDiff line numberDiff line change
@@ -1193,36 +1193,13 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a
11931193
readPrepareParams3.mMinIntervalFloorSeconds = 2;
11941194
readPrepareParams3.mMaxIntervalCeilingSeconds = 5;
11951195

1196-
printf("\nSend 4th subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId);
1196+
printf("\nSend 4th subscribe request message to Node: %" PRIu64 ", resource exhausted\n", chip::kTestDeviceNodeId);
11971197

11981198
ReadClient readClient3;
11991199
readClient3.Init(&ctx.GetExchangeManager(), &delegate, ReadClient::InteractionType::Subscribe);
12001200
err = readClient3.SendSubscribeRequest(readPrepareParams3);
12011201
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
12021202
engine->GetReportingEngine().Run();
1203-
NL_TEST_ASSERT(apSuite, delegate.mGotReport);
1204-
NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 1);
1205-
NL_TEST_ASSERT(apSuite, !delegate.mReadError);
1206-
1207-
delegate.mNumAttributeResponse = 0;
1208-
delegate.mGotReport = false;
1209-
ReadPrepareParams readPrepareParams4(ctx.GetSessionBobToAlice());
1210-
chip::app::AttributePathParams attributePathParams4[1];
1211-
readPrepareParams4.mpAttributePathParamsList = attributePathParams4;
1212-
readPrepareParams4.mpAttributePathParamsList[0].mEndpointId = kTestEndpointId;
1213-
readPrepareParams4.mpAttributePathParamsList[0].mClusterId = kTestClusterId;
1214-
readPrepareParams4.mpAttributePathParamsList[0].mAttributeId = 1;
1215-
readPrepareParams4.mAttributePathParamsListSize = 1;
1216-
readPrepareParams4.mMinIntervalFloorSeconds = 2;
1217-
readPrepareParams4.mMaxIntervalCeilingSeconds = 5;
1218-
1219-
printf("\nSend 5th subscribe request message to Node: %" PRIu64 ", resource exhausted\n", chip::kTestDeviceNodeId);
1220-
1221-
ReadClient readClient4;
1222-
readClient4.Init(&ctx.GetExchangeManager(), &delegate, ReadClient::InteractionType::Subscribe);
1223-
err = readClient4.SendSubscribeRequest(readPrepareParams4);
1224-
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
1225-
engine->GetReportingEngine().Run();
12261203
NL_TEST_ASSERT(apSuite, !delegate.mGotReport);
12271204
NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 0);
12281205
NL_TEST_ASSERT(apSuite, delegate.mReadError);

0 commit comments

Comments
 (0)