Skip to content

Commit

Permalink
Fix compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
harimau-qirex committed Aug 22, 2024
1 parent 0ead7f3 commit deb4164
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/controller/python/chip/bdx/bdx-transfer-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
namespace chip {
namespace bdx {

BdxTransferManager::BdxTransferManager(BdxTransfer::Delegate * bdxTransferDelegate) : mBdxTransferDelegate(bdxTransferDelegate)
{
}

BdxTransferManager::~BdxTransferManager()
{
mTransferPool.ReleaseAll();
Expand All @@ -43,7 +47,7 @@ BdxTransfer * BdxTransferManager::Allocate()
VerifyOrReturnValue(mExpectedTransfers != 0, nullptr);

BdxTransfer * result = mTransferPool.CreateObject();
VerifyOrReturn(result != nullptr);
VerifyOrReturnValue(result != nullptr, nullptr);
result->SetDelegate(this);

--mExpectedTransfers;
Expand Down
9 changes: 5 additions & 4 deletions src/controller/python/chip/bdx/bdx-transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void BdxTransfer::HandleTransferSessionOutput(TransferSession::OutputEvent & eve
EndSession(CHIP_ERROR_TIMEOUT);
break;
case TransferSession::OutputEventType::kBlockReceived:
ByteSpan data(event.blockdata.Data, event.blockdata.Length);
if (mDelegate)
{
ByteSpan data(event.blockdata.Data, event.blockdata.Length);
mDelegate->DataReceived(this, data);
}
break;
Expand All @@ -117,7 +117,8 @@ void BdxTransfer::HandleTransferSessionOutput(TransferSession::OutputEvent & eve
break;
case TransferSession::OutputEventType::kQueryWithSkipReceived:
mDataTransferredCount = std::min<size_t>(mDataTransferredCount + event.bytesToSkip.BytesToSkip, mDataCount);
// Fallthrough intentional.
SendBlock();
break;
case TransferSession::OutputEventType::kQueryReceived:
SendBlock();
break;
Expand Down Expand Up @@ -170,11 +171,11 @@ CHIP_ERROR BdxTransfer::SendBlock()
block.Data = mData + mDataTransferredCount;
block.Length = std::min<size_t>(mTransfer.GetTransferBlockSize(), dataRemaining);
block.IsEof = block.Length == dataRemaining;
ReturnOnFailure(mTransfer.PrepareBlock(block));
ReturnErrorOnFailure(mTransfer.PrepareBlock(block));
mDataTransferredCount += block.Length;
ScheduleImmediatePoll();
return CHIP_NO_ERROR;
}

} // namespace bdx
} // namespace chip
} // namespace chip
2 changes: 2 additions & 0 deletions src/controller/python/chip/bdx/bdx-transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class BdxTransfer : public Responder
virtual void TransferCompleted(BdxTransfer * transfer, CHIP_ERROR result) = 0;
};

~BdxTransfer() override;

// Accepts the transfer. When a block of data arrives the delegate is invoked with the block. This must only be called if the
// transfer sends data to this controller.
CHIP_ERROR AcceptSend();
Expand Down
34 changes: 19 additions & 15 deletions src/controller/python/chip/bdx/bdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct TransferData
PyObject OnTransferObtainedContext = nullptr;
PyObject OnDataReceivedContext = nullptr;
PyObject OnTransferCompletedContext = nullptr;

bool operator==(const TransferData& other) const {
return Transfer == other.Transfer;
}
};

class TransferMap
Expand All @@ -54,31 +58,31 @@ class TransferMap
// This returns the transfer data associated with the given transfer.
TransferData * TransferDataForTransfer(bdx::BdxTransfer * transfer)
{
std::vector<TransferData>::iterator result = std::find(mTransfers.begin(), mTransfers.end(),
[transfer](const TransferData& data) {
return data.Transfer == transfer;
});
std::vector<TransferData>::iterator result = std::find_if(mTransfers.begin(), mTransfers.end(),
[transfer](const TransferData& data) {
return data.Transfer == transfer;
});
VerifyOrReturnValue(result != mTransfers.end(), nullptr);
return &*result;
}

TransferData * TransferDataForTransferObtainedContext(PyObject transferObtainedContext)
{
std::vector<TransferData>::iterator result = std::find(mTransfers.begin(), mTransfers.end(),
[transferObtainedContext](const TransferData& data) {
return data.OnTransferObtainedContext == transferObtainedContext;
});
std::vector<TransferData>::iterator result = std::find_if(mTransfers.begin(), mTransfers.end(),
[transferObtainedContext](const TransferData& data) {
return data.OnTransferObtainedContext == transferObtainedContext;
});
VerifyOrReturnValue(result != mTransfers.end(), nullptr);
return &*result;
}

// This returns the next transfer data that has no associated BdxTransfer.
TransferData * NextUnassociatedTransferData()
{
std::vector<TransferData>::iterator result = std::find(mTransfers.begin(), mTransfers.end(),
[](const TransferData& data) {
return data.Transfer == nullptr;
});
std::vector<TransferData>::iterator result = std::find_if(mTransfers.begin(), mTransfers.end(),
[](const TransferData& data) {
return data.Transfer == nullptr;
});
VerifyOrReturnValue(result != mTransfers.end(), nullptr);
return &*result;
}
Expand Down Expand Up @@ -167,9 +171,9 @@ void pychip_Bdx_InitCallbacks(OnTransferObtainedCallback onTransferObtainedCallb
OnDataReceivedCallback onDataReceivedCallback,
OnTransferCompletedCallback onTransferCompletedCallback)
{
OnTransferObtainedCallback gOnTransferObtainedCallback = onTransferObtainedCallback;
OnDataReceivedCallback gOnDataReceivedCallback = onDataReceivedCallback;
OnTransferCompletedCallback gOnTransferCompletedCallback = onTransferCompletedCallback;
gOnTransferObtainedCallback = onTransferObtainedCallback;
gOnDataReceivedCallback = onDataReceivedCallback;
gOnTransferCompletedCallback = onTransferCompletedCallback;
}

PyChipError pychip_Bdx_ExpectBdxTransfer(PyObject transferObtainedContext)
Expand Down

0 comments on commit deb4164

Please sign in to comment.