Added TransferBufferAccessor, saves few bytes on stack/heap

This commit is contained in:
Pavel Kirienko
2014-02-11 20:13:19 +04:00
parent 25d285e209
commit 031f90f326
4 changed files with 38 additions and 38 deletions
+8 -14
View File
@@ -86,8 +86,7 @@ bool TransferReceiver::validate(const RxFrame& frame) const
return true;
}
TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame,
const TransferBufferManagerKey& bufmgr_key)
TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame, TransferBufferAccessor& tba)
{
if (frame.frame_index == 0)
{
@@ -97,15 +96,15 @@ TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame,
if ((frame.frame_index == 0) && frame.last_frame) // Single-frame transfer
{
bufmgr_->remove(bufmgr_key);
tba.remove();
updateTransferTimings();
prepareForNextTransfer();
return RESULT_SINGLE_FRAME;
}
TransferBufferBase* buf = bufmgr_->access(bufmgr_key);
TransferBufferBase* buf = tba.access();
if (buf == NULL)
buf = bufmgr_->create(bufmgr_key);
buf = tba.create();
if (buf == NULL)
{
UAVCAN_TRACE("TransferReceiver", "Failed to access the buffer, %s", frame.toString().c_str());
@@ -117,7 +116,7 @@ TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame,
if (res != frame.payload_len)
{
UAVCAN_TRACE("TransferReceiver", "Buffer write failure [%i], %s", res, frame.toString().c_str());
bufmgr_->remove(bufmgr_key);
tba.remove();
prepareForNextTransfer();
return RESULT_NOT_COMPLETE;
}
@@ -141,13 +140,8 @@ bool TransferReceiver::isTimedOut(uint64_t ts_monotonic) const
return (ts_monotonic - ts) > (uint64_t(transfer_interval_) * INTERVAL_MULT);
}
TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame,
const TransferBufferManagerKey& bufmgr_key)
TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame, TransferBufferAccessor& tba)
{
assert(bufmgr_);
assert(bufmgr_key.getNodeID() == frame.source_node_id);
assert(bufmgr_key.getTransferType() == frame.transfer_type);
if ((frame.ts_monotonic == 0) ||
(frame.ts_monotonic < prev_transfer_ts_monotonic_) ||
(frame.ts_monotonic < this_transfer_ts_monotonic_))
@@ -174,7 +168,7 @@ TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame,
"Restart [not_inited=%i, iface_timeout=%i, recv_timeout=%i, same_iface=%i, first_frame=%i, tid_rel=%i], %s",
int(not_initialized), int(iface_timed_out), int(receiver_timed_out), int(same_iface), int(first_fame),
int(tid_rel), frame.toString().c_str());
bufmgr_->remove(bufmgr_key);
tba.remove();
iface_index_ = frame.iface_index;
tid_ = frame.transfer_id;
next_frame_index_ = 0;
@@ -188,7 +182,7 @@ TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame,
if (!validate(frame))
return RESULT_NOT_COMPLETE;
return receive(frame, bufmgr_key);
return receive(frame, tba);
}
}