From bbc524865c1815e417a1df1fc7bc025f972d0db8 Mon Sep 17 00:00:00 2001 From: Nivi Sarkar <55898241+nivi-apple@users.noreply.github.com> Date: Mon, 9 Sep 2024 05:45:46 -0700 Subject: [PATCH] =?UTF-8?q?Add=20GetNextAction=20API=20so=20that=20a=20cal?= =?UTF-8?q?ler=20that=20might=20want=20to=20implement=20a=E2=80=A6=20(#354?= =?UTF-8?q?62)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add GetNextAction API so that a caller that might want to implement an event driven mechanism to drive the BDX transfer can get the next output event from the TransferSession on demand Currently we have the PollOutput API where the expectation is the caller needs to poll frequently for the next output event from the TransferSession which introduces a delay based on the poll interval in handling every single BDX message or transfer session event handled by the caller. * Update src/protocols/bdx/BdxTransferSession.h Co-authored-by: Boris Zbarsky * Address review comments * Apply suggestions from code review Co-authored-by: Boris Zbarsky * Restyled by clang-format --------- Co-authored-by: Boris Zbarsky Co-authored-by: Restyled.io --- src/protocols/bdx/BdxTransferSession.cpp | 5 +++++ src/protocols/bdx/BdxTransferSession.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/protocols/bdx/BdxTransferSession.cpp b/src/protocols/bdx/BdxTransferSession.cpp index 99588f0770a72e..0a513d7ea77460 100644 --- a/src/protocols/bdx/BdxTransferSession.cpp +++ b/src/protocols/bdx/BdxTransferSession.cpp @@ -134,6 +134,11 @@ void TransferSession::PollOutput(OutputEvent & event, System::Clock::Timestamp c mPendingOutput = OutputEventType::kNone; } +void TransferSession::GetNextAction(OutputEvent & event) +{ + PollOutput(event, System::SystemClock().GetMonotonicTimestamp()); +} + CHIP_ERROR TransferSession::StartTransfer(TransferRole role, const TransferInitData & initData, System::Clock::Timeout timeout) { VerifyOrReturnError(mState == TransferState::kUnitialized, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/protocols/bdx/BdxTransferSession.h b/src/protocols/bdx/BdxTransferSession.h index ccd241e7fe508c..4a50e70fbb6c84 100644 --- a/src/protocols/bdx/BdxTransferSession.h +++ b/src/protocols/bdx/BdxTransferSession.h @@ -165,6 +165,25 @@ class DLL_EXPORT TransferSession */ void PollOutput(OutputEvent & event, System::Clock::Timestamp curTime); + /** + * @brief + * Gets the pending output event from the transfer session in the event param passed in by the caller. + * The output event may contain some data for the caller to act upon. If there is no pending output event, + * the caller will get an event of type OutputEventType::kNone. + * + * It is possible that consecutive calls to this method may emit different outputs depending on the state of the + * TransferSession object. The caller is generally expected to keep calling this method until it gets an event of type + * OutputEventType::kNone. + * + * If the output event type is kMsgToSend, the caller is expected to send the message immediately on the + * relevant exchange. In this case the BDX session timeout timer will start when GetNextAction is called. + * + * See OutputEventType for all possible output event types. + * + * @param event Reference to an OutputEvent struct that will be filled out with any pending output event data + */ + void GetNextAction(OutputEvent & event); + /** * @brief * Initializes the TransferSession object and prepares a TransferInit message (emitted via PollOutput()).