From 2403120d30861cefda84c9e5082321cfa24fb2d6 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Thu, 6 Jun 2024 13:56:27 -0400 Subject: [PATCH] Fix some of the minor TODOs. --- .../python/chip/bdx/bdx-transfer-manager.cpp | 19 ++++++++++-- .../python/chip/bdx/bdx-transfer-manager.h | 6 +++- .../python/chip/bdx/bdx-transfer.cpp | 31 +++++++++---------- src/controller/python/chip/bdx/bdx-transfer.h | 5 +-- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/controller/python/chip/bdx/bdx-transfer-manager.cpp b/src/controller/python/chip/bdx/bdx-transfer-manager.cpp index b2bde229d592ca..cc9f6f7cd8c825 100644 --- a/src/controller/python/chip/bdx/bdx-transfer-manager.cpp +++ b/src/controller/python/chip/bdx/bdx-transfer-manager.cpp @@ -44,8 +44,7 @@ BdxTransfer * BdxTransferManager::Allocate() BdxTransfer * result = mTransferPool.CreateObject(); VerifyOrReturn(result != nullptr); - // TODO: This needs to intercept the delegate calls so it can free the transfer after it completes. - result->SetDelegate(mBdxTransferDelegate); + result->SetDelegate(this); --mExpectedTransfers; return result; @@ -58,5 +57,21 @@ void BdxTransferManager::Release(BdxTransfer * bdxTransfer) mTransferPool.ReleaseObject(bdxTransfer); } +void BdxTransferManager::InitMessageReceived(BdxTransfer * transfer, TransferSession::TransferInitData init_data) +{ + mBdxTransferDelegate->InitMessageReceived(transfer, init_data); +} + +void BdxTransferManager::DataReceived(BdxTransfer * transfer, const ByteSpan & block) +{ + mBdxTransferDelegate->DataReceived(transfer, block); +} + +void BdxTransferManager::TransferCompleted(BdxTransfer * transfer, CHIP_ERROR result) +{ + mBdxTransferDelegate->TransferCompleted(transfer, result); + mTransferPool.ReleaseObject(transfer); +} + } // namespace bdx } // namespace chip diff --git a/src/controller/python/chip/bdx/bdx-transfer-manager.h b/src/controller/python/chip/bdx/bdx-transfer-manager.h index 73d29c8fa5f7d4..1d476ba95d4787 100644 --- a/src/controller/python/chip/bdx/bdx-transfer-manager.h +++ b/src/controller/python/chip/bdx/bdx-transfer-manager.h @@ -28,7 +28,7 @@ namespace bdx { // This class implements the pool interface used to allocate BdxTransfer objects. It keeps track of the number of transfers // that are expected to be created and only allocates a BdxTransfer object if a transfer is expected. -class BdxTransferManager : public BdxTransferPool +class BdxTransferManager : public BdxTransferPool, public BdxTransfer::Delegate { public: BdxTransferManager(BdxTransfer::Delegate * bdxTransferDelegate); @@ -41,6 +41,10 @@ class BdxTransferManager : public BdxTransferPool BdxTransfer * Allocate() override; void Release(BdxTransfer * bdxTransfer) override; + void InitMessageReceived(BdxTransfer * transfer, TransferSession::TransferInitData init_data) override; + void DataReceived(BdxTransfer * transfer, const ByteSpan & block) override; + void TransferCompleted(BdxTransfer * transfer, CHIP_ERROR result) override; + private: ObjectPool mTransferPool; BdxTransfer::Delegate * mBdxTransferDelegate = nullptr; diff --git a/src/controller/python/chip/bdx/bdx-transfer.cpp b/src/controller/python/chip/bdx/bdx-transfer.cpp index 9c622df59962fc..38ca95590a32c0 100644 --- a/src/controller/python/chip/bdx/bdx-transfer.cpp +++ b/src/controller/python/chip/bdx/bdx-transfer.cpp @@ -41,14 +41,15 @@ CHIP_ERROR BdxTransfer::AcceptSend() VerifyOrReturnError(mAwaitingAccept, CHIP_ERROR_INCORRECT_STATE); mAwaitingAccept = false; - TransferSession::TransferAcceptData accept_data; - accept_data.ControlMode = mInitData.TransferCtlFlags; // TODO: Is this value correct? - accept_data.MaxBlockSize = mInitData.MaxBlockSize; - // TODO: Check the acceptable control modes for a Diagnostic Logs cluster transfer. - return mTransfer.AcceptTransfer(accept_data); + TransferSession::TransferAcceptData acceptData; + acceptData.ControlMode = TransferControlFlags::kSenderDrive; + acceptData.MaxBlockSize = mTransfer.GetTransferBlockSize(); + acceptData.StartOffset = mTransfer.GetStartOffset(); + acceptData.Length = mTransfer.GetTransferLength(); + return mTransfer.AcceptTransfer(acceptData); } -CHIP_ERROR BdxTransfer::AcceptReceive(const ByteSpan data_to_send) +CHIP_ERROR BdxTransfer::AcceptReceive(const ByteSpan & data_to_send) { VerifyOrReturnError(mAwaitingAccept, CHIP_ERROR_INCORRECT_STATE); mAwaitingAccept = false; @@ -60,10 +61,12 @@ CHIP_ERROR BdxTransfer::AcceptReceive(const ByteSpan data_to_send) memcpy(mData, data_to_send.data(), data_to_send.size()); mDataCount = data_to_send.size(); - TransferSession::TransferAcceptData accept_data; - accept_data.ControlMode = mInitData.TransferCtlFlags; // TODO: Is this value correct? - accept_data.MaxBlockSize = mInitData.MaxBlockSize; - return mTransfer.AcceptTransfer(accept_data); + TransferSession::TransferAcceptData acceptData; + acceptData.ControlMode = TransferControlFlags::kReceiverDrive; + acceptData.MaxBlockSize = mTransfer.GetTransferBlockSize(); + acceptData.StartOffset = mTransfer.GetStartOffset(); + acceptData.Length = mTransfer.GetTransferLength(); + return mTransfer.AcceptTransfer(acceptData); } CHIP_ERROR BdxTransfer::Reject() @@ -82,13 +85,10 @@ void BdxTransfer::HandleTransferSessionOutput(TransferSession::OutputEvent & eve switch (event.EventType) { case TransferSession::OutputEventType::kInitReceived: - mInitData = event.transferInitData; - mDelegate->InitMessageReceived(this, mInitData); + mDelegate->InitMessageReceived(this, event.transferInitData); break; case TransferSession::OutputEventType::kStatusReceived: ChipLogError(BDX, "Received StatusReport %x", static_cast(event.statusData.statusCode)); - // TODO: Not a great error type. The issue isn't internal, it's external. We can check the status code, but I don't know - // if that would produce a better error type. Maybe CHIP_ERROR_IM_STATUS_CODE_RECEIVED? EndSession(CHIP_ERROR_INTERNAL); break; case TransferSession::OutputEventType::kInternalError: @@ -116,8 +116,7 @@ void BdxTransfer::HandleTransferSessionOutput(TransferSession::OutputEvent & eve EndSession(CHIP_NO_ERROR); break; case TransferSession::OutputEventType::kQueryWithSkipReceived: - mDataTransferredCount += event.bytesToSkip.BytesToSkip; - mDataTransferredCount = std::min(mDataTransferredCount, mDataCount); + mDataTransferredCount = std::min(mDataTransferredCount + event.bytesToSkip.BytesToSkip, mDataCount); // Fallthrough intentional. case TransferSession::OutputEventType::kQueryReceived: SendBlock(); diff --git a/src/controller/python/chip/bdx/bdx-transfer.h b/src/controller/python/chip/bdx/bdx-transfer.h index 2e255a4f0e5e50..d856563cddfbc9 100644 --- a/src/controller/python/chip/bdx/bdx-transfer.h +++ b/src/controller/python/chip/bdx/bdx-transfer.h @@ -15,7 +15,6 @@ * limitations under the License. */ -// TODO: Includes. #include #include @@ -52,8 +51,7 @@ class BdxTransfer : public Responder // Accepts the transfer. The data provided here will be sent over the transfer. This must only be called if the transfer // receives data from this controller. - // TODO: Should the parameter be const&? - CHIP_ERROR AcceptReceive(const ByteSpan data_to_send); + CHIP_ERROR AcceptReceive(const ByteSpan & data_to_send); // Rejects the transfer. CHIP_ERROR Reject(); @@ -70,7 +68,6 @@ class BdxTransfer : public Responder Delegate * mDelegate = nullptr; bool mAwaitingAccept = false; - TransferSession::TransferInitData mInitData; // TODO: Request the data from a data source rather than copy the data here. uint8_t * mData = nullptr;