mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 15:13:34 +08:00
Fixed destruction/copying of TransferReceiver
This commit is contained in:
@@ -37,8 +37,6 @@ private:
|
|||||||
|
|
||||||
bool isInitialized() const { return iface_index_ != IFACE_INDEX_NOTSET; }
|
bool isInitialized() const { return iface_index_ != IFACE_INDEX_NOTSET; }
|
||||||
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
TidRelation getTidRelation(const RxFrame& frame) const;
|
TidRelation getTidRelation(const RxFrame& frame) const;
|
||||||
|
|
||||||
void updateTransferTimings();
|
void updateTransferTimings();
|
||||||
@@ -74,23 +72,6 @@ public:
|
|||||||
assert(bufmgr_key.getNodeID() != NODE_ID_BROADCAST);
|
assert(bufmgr_key.getNodeID() != NODE_ID_BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
~TransferReceiver() { cleanup(); }
|
|
||||||
|
|
||||||
TransferReceiver& operator=(const TransferReceiver& rhs)
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
prev_transfer_ts_monotonic_ = rhs.prev_transfer_ts_monotonic_;
|
|
||||||
this_transfer_ts_monotonic_ = rhs.this_transfer_ts_monotonic_;
|
|
||||||
first_frame_ts_utc_ = rhs.first_frame_ts_utc_;
|
|
||||||
transfer_interval_ = rhs.transfer_interval_;
|
|
||||||
bufmgr_ = rhs.bufmgr_;
|
|
||||||
tid_ = rhs.tid_;
|
|
||||||
bufmgr_key_ = rhs.bufmgr_key_;
|
|
||||||
iface_index_ = rhs.iface_index_;
|
|
||||||
next_frame_index_ = rhs.next_frame_index_;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTimedOut(uint64_t ts_monotonic) const;
|
bool isTimedOut(uint64_t ts_monotonic) const;
|
||||||
|
|
||||||
ResultCode addFrame(const RxFrame& frame);
|
ResultCode addFrame(const RxFrame& frame);
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ const uint32_t TransferReceiver::DEFAULT_TRANSFER_INTERVAL;
|
|||||||
const uint32_t TransferReceiver::MIN_TRANSFER_INTERVAL;
|
const uint32_t TransferReceiver::MIN_TRANSFER_INTERVAL;
|
||||||
const uint32_t TransferReceiver::MAX_TRANSFER_INTERVAL;
|
const uint32_t TransferReceiver::MAX_TRANSFER_INTERVAL;
|
||||||
|
|
||||||
void TransferReceiver::cleanup()
|
|
||||||
{
|
|
||||||
if (bufmgr_ != NULL && !bufmgr_key_.isEmpty())
|
|
||||||
bufmgr_->remove(bufmgr_key_);
|
|
||||||
}
|
|
||||||
|
|
||||||
TransferReceiver::TidRelation TransferReceiver::getTidRelation(const RxFrame& frame) const
|
TransferReceiver::TidRelation TransferReceiver::getTidRelation(const RxFrame& frame) const
|
||||||
{
|
{
|
||||||
const int distance = tid_.forwardDistance(frame.transfer_id);
|
const int distance = tid_.forwardDistance(frame.transfer_id);
|
||||||
|
|||||||
@@ -206,11 +206,11 @@ TEST(TransferReceiver, Basic)
|
|||||||
ASSERT_TRUE(matchBufferContent(bufmgr.access(gen.bufmgr_key), "12345678qwe"));
|
ASSERT_TRUE(matchBufferContent(bufmgr.access(gen.bufmgr_key), "12345678qwe"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buffer cleanup
|
* Destruction
|
||||||
*/
|
*/
|
||||||
ASSERT_TRUE(bufmgr.access(gen.bufmgr_key));
|
ASSERT_TRUE(bufmgr.access(gen.bufmgr_key));
|
||||||
context.receiver = TransferReceiver();
|
context.receiver.~TransferReceiver(); // TransferReceiver does not own the buffer, it must not be released!
|
||||||
ASSERT_FALSE(bufmgr.access(gen.bufmgr_key));
|
ASSERT_TRUE(bufmgr.access(gen.bufmgr_key)); // Making sure that the buffer is still there
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user