Skip to content

Commit

Permalink
Merge 693dd38 into c1df923
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn authored Aug 28, 2024
2 parents c1df923 + 693dd38 commit 4728140
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
3 changes: 1 addition & 2 deletions examples/ota-provider-app/esp32/main/BdxOtaSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
{
ChipLogError(BDX, "onTransferComplete Callback not set");
}
mStopPolling = true; // Stop polling the TransferSession only after receiving BlockAckEOF
Reset();
break;
case TransferSession::OutputEventType::kStatusReceived:
Expand Down Expand Up @@ -228,7 +227,7 @@ void BdxOtaSender::Reset()
{
mFabricIndex.ClearValue();
mNodeId.ClearValue();
mTransfer.Reset();
ResetTransfer();
if (mExchangeCtx != nullptr)
{
mExchangeCtx->Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
break;
case TransferSession::OutputEventType::kAckEOFReceived:
ChipLogDetail(BDX, "Transfer completed, got AckEOF");
mStopPolling = true; // Stop polling the TransferSession only after receiving BlockAckEOF
Reset();
break;
case TransferSession::OutputEventType::kStatusReceived:
Expand Down Expand Up @@ -212,7 +211,7 @@ void BdxOtaSender::Reset()
{
mFabricIndex.ClearValue();
mNodeId.ClearValue();
Responder::ResetTransfer();
ResetTransfer();
if (mExchangeCtx != nullptr)
{
mExchangeCtx->Close();
Expand Down
39 changes: 15 additions & 24 deletions src/protocols/bdx/TransferFacilitator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ namespace bdx {
constexpr System::Clock::Timeout TransferFacilitator::kDefaultPollFreq;
constexpr System::Clock::Timeout TransferFacilitator::kImmediatePollDelay;

TransferFacilitator::~TransferFacilitator()
{
ResetTransfer();
}

void TransferFacilitator::ResetTransfer()
{
mTransfer.Reset();
ChipLogProgress(BDX, "Stop polling for messages");

VerifyOrReturn(mSystemLayer != nullptr);
mSystemLayer->CancelTimer(PollTimerHandler, this);
}

CHIP_ERROR TransferFacilitator::OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
chip::System::PacketBufferHandle && payload)
{
Expand Down Expand Up @@ -78,15 +92,7 @@ void TransferFacilitator::PollForOutput()
HandleTransferSessionOutput(outEvent);

VerifyOrReturn(mSystemLayer != nullptr, ChipLogError(BDX, "%s mSystemLayer is null", __FUNCTION__));
if (!mStopPolling)
{
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
}
else
{
mSystemLayer->CancelTimer(PollTimerHandler, this);
mStopPolling = false;
}
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
}

void TransferFacilitator::ScheduleImmediatePoll()
Expand All @@ -106,18 +112,10 @@ CHIP_ERROR Responder::PrepareForTransfer(System::Layer * layer, TransferRole rol
ReturnErrorOnFailure(mTransfer.WaitForTransfer(role, xferControlOpts, maxBlockSize, timeout));

ChipLogProgress(BDX, "Start polling for messages");
mStopPolling = false;
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
return CHIP_NO_ERROR;
}

void Responder::ResetTransfer()
{
mTransfer.Reset();
ChipLogProgress(BDX, "Stop polling for messages");
mStopPolling = true;
}

CHIP_ERROR Initiator::InitiateTransfer(System::Layer * layer, TransferRole role, const TransferSession::TransferInitData & initData,
System::Clock::Timeout timeout, System::Clock::Timeout pollFreq)
{
Expand All @@ -132,12 +130,5 @@ CHIP_ERROR Initiator::InitiateTransfer(System::Layer * layer, TransferRole role,
return CHIP_NO_ERROR;
}

void Initiator::ResetTransfer()
{
mTransfer.Reset();
ChipLogProgress(BDX, "Stop polling for messages");
mStopPolling = true;
}

} // namespace bdx
} // namespace chip
17 changes: 6 additions & 11 deletions src/protocols/bdx/TransferFacilitator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class TransferFacilitator : public Messaging::ExchangeDelegate, public Messaging
{
public:
TransferFacilitator() : mExchangeCtx(nullptr), mSystemLayer(nullptr), mPollFreq(kDefaultPollFreq) {}
~TransferFacilitator() override = default;
~TransferFacilitator() override;

/**
* Calls reset on the TransferSession object and stops the poll timer.
*/
void ResetTransfer();

private:
//// UnsolicitedMessageHandler Implementation ////
Expand Down Expand Up @@ -96,7 +101,6 @@ class TransferFacilitator : public Messaging::ExchangeDelegate, public Messaging
System::Clock::Timeout mPollFreq;
static constexpr System::Clock::Timeout kDefaultPollFreq = System::Clock::Milliseconds32(500);
static constexpr System::Clock::Timeout kImmediatePollDelay = System::Clock::Milliseconds32(1);
bool mStopPolling = false;
};

/**
Expand All @@ -121,11 +125,6 @@ class Responder : public TransferFacilitator
CHIP_ERROR PrepareForTransfer(System::Layer * layer, TransferRole role, BitFlags<TransferControlFlags> xferControlOpts,
uint16_t maxBlockSize, System::Clock::Timeout timeout,
System::Clock::Timeout pollFreq = TransferFacilitator::kDefaultPollFreq);

/**
* Calls reset on the TransferSession object and stops the poll timer.
*/
void ResetTransfer();
};

/**
Expand All @@ -150,10 +149,6 @@ class Initiator : public TransferFacilitator
CHIP_ERROR InitiateTransfer(System::Layer * layer, TransferRole role, const TransferSession::TransferInitData & initData,
System::Clock::Timeout timeout,
System::Clock::Timeout pollFreq = TransferFacilitator::kDefaultPollFreq);
/**
* Calls reset on the TransferSession object and stops the poll timer.
*/
void ResetTransfer();
};

} // namespace bdx
Expand Down

0 comments on commit 4728140

Please sign in to comment.