Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Jul 21, 2022
1 parent 91a9782 commit 3f74629
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 56 deletions.
6 changes: 1 addition & 5 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 1 addition & 13 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}
Expand Down
36 changes: 20 additions & 16 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 0 additions & 22 deletions src/messaging/ExchangeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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).
*
Expand Down

0 comments on commit 3f74629

Please sign in to comment.