From 3f746296ec15170723ac99fce931282b180355b1 Mon Sep 17 00:00:00 2001 From: Yunhan Wang Date: Thu, 21 Jul 2022 10:25:32 -0700 Subject: [PATCH] rebase --- src/app/ReadClient.cpp | 6 +---- src/app/ReadHandler.cpp | 14 +---------- src/app/tests/TestReadInteraction.cpp | 36 +++++++++++++++------------ src/messaging/ExchangeContext.h | 22 ---------------- 4 files changed, 22 insertions(+), 56 deletions(-) diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index f98de26f50509c..ec6ceb0fed24ae 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -421,11 +421,7 @@ void ReadClient::ResponseMessageHandled(CHIP_ERROR aError, Messaging::ExchangeCo { if (aError != CHIP_NO_ERROR) { - CHIP_ERROR err = StatusResponse::Send(Status::InvalidAction, apExchangeContext, false /*aExpectResponse*/); - if (err == CHIP_NO_ERROR) - { - mpExchangeCtx = nullptr; - } + StatusResponse::Send(Status::InvalidAction, apExchangeContext, false /*aExpectResponse*/); } if ((!IsSubscriptionType() && !mPendingMoreChunks) || aError != CHIP_NO_ERROR) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index cc0032be627294..f6792e4a489a5f 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -170,10 +170,6 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange if (!suppressErrorStatusResponse) { err = StatusResponse::Send(Status::InvalidAction, apExchangeContext, false /*aExpectResponse*/); - if (err == CHIP_NO_ERROR) - { - mpExchangeCtx = nullptr; - } } Close(); } @@ -280,16 +276,8 @@ bool ReadHandler::IsFromSubscriber(Messaging::ExchangeContext & apExchangeContex CHIP_ERROR ReadHandler::OnUnknownMsgType() { - VerifyOrReturnError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = - StatusResponse::Send(Protocols::InteractionModel::Status::InvalidAction, mpExchangeCtx, false /*aExpectResponse*/); - if (err != CHIP_NO_ERROR) - { - // We have to manually close the exchange, because we called - // WillSendMessage already. - mpExchangeCtx->Close(); - } - mpExchangeCtx = nullptr; + StatusResponse::Send(Protocols::InteractionModel::Status::InvalidAction, mExchangeCtx.Get(), false /*aExpectResponse*/); Close(); return err; } diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 2e8a6045269676..f6969e3c7ade7a 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -2754,11 +2754,13 @@ void TestReadInteraction::TestReadInvalidMessage1(nlTestSuite * apSuite, void * chip::app::InitWriterWithSpaceReserved(writer, 0); err = request.Init(&writer); err = writer.Finalize(&msgBuf); - readClient.mpExchangeCtx = - readClient.mpExchangeMgr->NewContext(readPrepareParams.mSessionHolder.Get().Value(), &readClient); + + auto exchange = readClient.mpExchangeMgr->NewContext(readPrepareParams.mSessionHolder.Get().Value(), &readClient); + NL_TEST_ASSERT(apSuite, exchange != nullptr); + readClient.mExchange.Grab(exchange); readClient.MoveToState(app::ReadClient::ClientState::AwaitingInitialReport); - err = readClient.mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReadRequest, std::move(msgBuf), - Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); + err = readClient.mExchange->SendMessage(Protocols::InteractionModel::MsgType::ReadRequest, std::move(msgBuf), + Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, delegate.mError != CHIP_NO_ERROR); @@ -2820,11 +2822,11 @@ void TestReadInteraction::TestReadInvalidMessage2(nlTestSuite * apSuite, void * payloadHeader.SetExchangeID(0); payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::StatusResponse); - rm->ClearRetransTable(readClient.mpExchangeCtx); + rm->ClearRetransTable(readClient.mExchange.Get()); ctx.GetLoopback().mSentMessageCount = 0; ctx.GetLoopback().mNumMessagesToDrop = 0; ctx.GetLoopback().mNumMessagesToDropSinceIndex = 0; - readClient.OnMessageReceived(readClient.mpExchangeCtx, payloadHeader, std::move(msgBuf)); + readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); } @@ -2880,10 +2882,10 @@ void TestReadInteraction::TestSubscribeInvalidMessage1(nlTestSuite * apSuite, vo ctx.GetLoopback().mNumMessagesToDrop = 0; ctx.GetLoopback().mNumMessagesToDropSinceIndex = 0; - rm->ClearRetransTable(readClient.mpExchangeCtx); + rm->ClearRetransTable(readClient.mExchange.Get()); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); - rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mpExchangeCtx); + rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mExchangeCtx.Get()); System::PacketBufferHandle msgBuf; ReadRequestMessage::Builder request; @@ -2892,7 +2894,7 @@ void TestReadInteraction::TestSubscribeInvalidMessage1(nlTestSuite * apSuite, vo request.Init(&writer); writer.Finalize(&msgBuf); - err = readClient.mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(msgBuf)); + err = readClient.mExchange->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(msgBuf)); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 4); } @@ -2933,11 +2935,13 @@ void TestReadInteraction::TestSubscribeInvalidMessage2(nlTestSuite * apSuite, vo chip::app::InitWriterWithSpaceReserved(writer, 0); err = request.Init(&writer); err = writer.Finalize(&msgBuf); - readClient.mpExchangeCtx = - readClient.mpExchangeMgr->NewContext(readPrepareParams.mSessionHolder.Get().Value(), &readClient); + + auto exchange = readClient.mpExchangeMgr->NewContext(readPrepareParams.mSessionHolder.Get().Value(), &readClient); + NL_TEST_ASSERT(apSuite, exchange != nullptr); + readClient.mExchange.Grab(exchange); readClient.MoveToState(app::ReadClient::ClientState::AwaitingInitialReport); - err = readClient.mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::SubscribeRequest, std::move(msgBuf), - Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); + err = readClient.mExchange->SendMessage(Protocols::InteractionModel::MsgType::SubscribeRequest, std::move(msgBuf), + Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, delegate.mError != CHIP_NO_ERROR); @@ -3002,14 +3006,14 @@ void TestReadInteraction::TestSubscribeInvalidMessage3(nlTestSuite * apSuite, vo payloadHeader.SetExchangeID(0); payloadHeader.SetMessageType(chip::Protocols::InteractionModel::MsgType::StatusResponse); - rm->ClearRetransTable(readClient.mpExchangeCtx); + rm->ClearRetransTable(readClient.mExchange.Get()); NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); - rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mpExchangeCtx); + rm->ClearRetransTable(engine->ActiveHandlerAt(0)->mExchangeCtx.Get()); ctx.GetLoopback().mSentMessageCount = 0; ctx.GetLoopback().mNumMessagesToDrop = 0; ctx.GetLoopback().mNumMessagesToDropSinceIndex = 0; - readClient.OnMessageReceived(readClient.mpExchangeCtx, payloadHeader, std::move(msgBuf)); + readClient.OnMessageReceived(readClient.mExchange.Get(), payloadHeader, std::move(msgBuf)); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, ctx.GetLoopback().mSentMessageCount == 2); } diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index 7e0f050552a63b..3e7e56121c6d26 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -196,7 +196,6 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, // SecureSession. void AbortAllOtherCommunicationOnFabric(); -<<<<<<< HEAD /** * Determine whether a response is currently expected for a message that was sent over * this exchange. While this is true, attempts to send other messages that expect a response @@ -213,8 +212,6 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, */ bool IsSendExpected() const { return mFlags.Has(Flags::kFlagWillSendMessage); } -======= ->>>>>>> 32c530c6c (address comments) private: class ExchangeSessionHolder : public SessionHolderWithDelegate { @@ -233,25 +230,6 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, uint16_t mExchangeId; // Assigned exchange ID. /** -<<<<<<< HEAD -======= - * Determine whether a response is currently expected for a message that was sent over - * this exchange. While this is true, attempts to send other messages that expect a response - * will fail. - * - * @return Returns 'true' if response expected, else 'false'. - */ - bool IsResponseExpected() const; - - /** - * Determine whether we are expecting our consumer to send a message on - * this exchange (i.e. WillSendMessage was called and the message has not - * yet been sent). - */ - bool IsSendExpected() const { return mFlags.Has(Flags::kFlagWillSendMessage); } - - /** ->>>>>>> 32c530c6c (address comments) * Track whether we are now expecting a response to a message sent via this exchange (because that * message had the kExpectResponse flag set in its sendFlags). *