Skip to content

Commit

Permalink
Refs #20342: Delete Sender's Resource deprecated API
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <[email protected]>
  • Loading branch information
cferreiragonz committed Mar 11, 2024
1 parent 5aa923c commit 5de9ef4
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 184 deletions.
26 changes: 0 additions & 26 deletions include/fastdds/rtps/transport/ChainingTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,32 +299,6 @@ class ChainingTransport : public TransportInterface
return low_level_transport_->max_recv_buffer_size();
}

/**
* Blocking Send through the specified channel. It may perform operations on the output buffer.
* At the end the function must call to the low-level transport's `send()` function.
* @code{.cpp}
// Example of calling the low-level transport `send()` function.
return low_sender_resource->send(send_buffer, send_buffer_size, destination_locators_begin,
destination_locators_end, timeout);
@endcode
* @param low_sender_resource SenderResource generated by the lower transport.
* @param send_buffer Slice into the raw data to send.
* @param send_buffer_size Size of the raw data. It will be used as a bounds check for the previous argument.
* It must not exceed the \c sendBufferSize fed to this class during construction.
* @param destination_locators_begin First iterator of the list of Locators describing the remote destinations
* we're sending to.
* @param destination_locators_end End iterator of the list of Locators describing the remote destinations
* we're sending to.
* @param timeout Maximum blocking time.
*/
RTPS_DllAPI virtual bool send(
fastrtps::rtps::SenderResource* low_sender_resource,
const fastrtps::rtps::octet* send_buffer,
uint32_t send_buffer_size,
fastrtps::rtps::LocatorsIterator* destination_locators_begin,
fastrtps::rtps::LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& timeout) = 0;

/**
* Blocking Send through the specified channel. It may perform operations on the output buffer.
* At the end the function must call to the low-level transport's `send()` function.
Expand Down
64 changes: 3 additions & 61 deletions include/fastdds/rtps/transport/SenderResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,6 @@ class SenderResource

using NetworkBuffer = eprosima::fastdds::rtps::NetworkBuffer;

/**
* Sends to a destination locator, through the channel managed by this resource.
* @param data Raw data slice to be sent.
* @param dataLength Length of the data to be sent. Will be used as a boundary for
* the previous parameter.
* @param destination_locators_begin destination endpoint Locators iterator begin.
* @param destination_locators_end destination endpoint Locators iterator end.
* @param max_blocking_time_point If transport supports it then it will use it as maximum blocking time.
* @return Success of the send operation.
*/
bool send(
const octet* data,
uint32_t dataLength,
LocatorsIterator* destination_locators_begin,
LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& max_blocking_time_point)
{
bool returned_value = false;

if (send_lambda_ && !send_buffers_lambda_)
{
EPROSIMA_LOG_WARNING(RTPS, "The usage of send_lambda_ on SenderResource has been deprecated."
<< std::endl << "Please implement send_buffers_lambda_ instead.");
return send_lambda_(data, dataLength,
destination_locators_begin, destination_locators_end, max_blocking_time_point);
}

// Use a list of NetworkBuffer to send the message
std::list<NetworkBuffer> buffers;
buffers.push_back(NetworkBuffer(data, dataLength));
uint32_t total_bytes = dataLength;

returned_value = send(buffers, total_bytes, destination_locators_begin, destination_locators_end,
max_blocking_time_point);

return returned_value;
}

/**
* Sends to a destination locator, through the channel managed by this resource.
* @param buffers List of buffers to send.
Expand All @@ -100,22 +62,8 @@ class SenderResource
LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& max_blocking_time_point)
{
bool returned_value = false;

if (send_buffers_lambda_)
{
returned_value = send_buffers_lambda_(buffers, total_bytes, destination_locators_begin, destination_locators_end,
max_blocking_time_point);
}

if (send_lambda_)
{
EPROSIMA_LOG_ERROR(RTPS, "The usage of send_lambda_ on SenderResource has been deprecated."
<< std::endl << "Please implement send_buffers_lambda_ instead.");
send_lambda_ = nullptr;
}

return returned_value;
return send_buffers_lambda_(buffers, total_bytes, destination_locators_begin, destination_locators_end,
max_blocking_time_point);
}

/**
Expand All @@ -126,7 +74,7 @@ class SenderResource
SenderResource&& rValueResource)
{
clean_up.swap(rValueResource.clean_up);
send_lambda_.swap(rValueResource.send_lambda_);
send_buffers_lambda_.swap(rValueResource.send_buffers_lambda_);
}

virtual ~SenderResource() = default;
Expand Down Expand Up @@ -158,12 +106,6 @@ class SenderResource
int32_t transport_kind_;

std::function<void()> clean_up;
std::function<bool(
const octet*,
uint32_t,
LocatorsIterator* destination_locators_begin,
LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point&)> send_lambda_;

std::function<bool(
const std::list<NetworkBuffer>&,
Expand Down
16 changes: 0 additions & 16 deletions src/cpp/rtps/transport/ChainingSenderResource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ class ChainingSenderResource : public fastrtps::rtps::SenderResource
// low_sender_resources_ makes its clean up on destruction.
};

send_lambda_ = [this, &transport](
const fastrtps::rtps::octet* data,
uint32_t dataSize,
fastrtps::rtps::LocatorsIterator* destination_locators_begin,
fastrtps::rtps::LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& timeout) -> bool
{
if (low_sender_resource_)
{
return transport.send(low_sender_resource_.get(), data, dataSize,
destination_locators_begin, destination_locators_end, timeout);
}

return false;
};

send_buffers_lambda_ = [this, &transport](
const std::list<NetworkBuffer>& buffers,
uint32_t total_bytes,
Expand Down
15 changes: 0 additions & 15 deletions test/blackbox/common/BlackboxTestsTransportCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ class TestChainingTransport : public eprosima::fastdds::rtps::ChainingTransport
return low_level_transport_->init(properties, max_msg_size_no_frag);
}

bool send(
eprosima::fastrtps::rtps::SenderResource* low_sender_resource,
const eprosima::fastrtps::rtps::octet* send_buffer,
uint32_t send_buffer_size,
eprosima::fastrtps::rtps::LocatorsIterator* destination_locators_begin,
eprosima::fastrtps::rtps::LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& timeout) override
{
descriptor_.send_function_called();

// Call low level transport
return low_sender_resource->send(send_buffer, send_buffer_size, destination_locators_begin,
destination_locators_end, timeout);
}

bool send(
eprosima::fastrtps::rtps::SenderResource* low_sender_resource,
const std::list<NetworkBuffer>& buffers,
Expand Down
17 changes: 3 additions & 14 deletions test/blackbox/common/DatagramInjectionTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,16 @@ class DatagramInjectionTransport : public ChainingTransport

bool send(
eprosima::fastrtps::rtps::SenderResource* low_sender_resource,
const eprosima::fastrtps::rtps::octet* send_buffer,
uint32_t send_buffer_size,
const std::list<NetworkBuffer>& buffers,
uint32_t total_bytes,
eprosima::fastrtps::rtps::LocatorsIterator* destination_locators_begin,
eprosima::fastrtps::rtps::LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& timeout) override
{
return low_sender_resource->send(send_buffer, send_buffer_size, destination_locators_begin,
return low_sender_resource->send(buffers, total_bytes, destination_locators_begin,
destination_locators_end, timeout);
}

bool send(
eprosima::fastrtps::rtps::SenderResource* /*low_sender_resource*/,
const std::list<NetworkBuffer>& /*buffers*/,
uint32_t /*total_bytes*/,
eprosima::fastrtps::rtps::LocatorsIterator* /*destination_locators_begin*/,
eprosima::fastrtps::rtps::LocatorsIterator* /*destination_locators_end*/,
const std::chrono::steady_clock::time_point& /*timeout*/) override
{
return true;
}

void receive(
TransportReceiverInterface* next_receiver,
const eprosima::fastrtps::rtps::octet* receive_buffer,
Expand Down
29 changes: 23 additions & 6 deletions test/unittest/transport/SharedMemTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ TEST_F(SHMTransportTests, send_and_receive_between_ports)
ASSERT_FALSE(send_resource_list.empty());
ASSERT_TRUE(transportUnderTest.IsInputChannelOpen(unicastLocator));
octet message[5] = { 'H', 'e', 'l', 'l', 'o' };
std::list<NetworkBuffer> buffer_list;
for (size_t i = 0; i < 5; ++i)
{
buffer_list.push_back(NetworkBuffer(&message[i], 1));
}

std::function<void()> recCallback = [&]()
{
Expand All @@ -754,7 +759,7 @@ TEST_F(SHMTransportTests, send_and_receive_between_ports)
Locators locators_begin(locator_list.begin());
Locators locators_end(locator_list.end());

EXPECT_TRUE(send_resource_list.at(0)->send(message, 5, &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, 5, &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100))));
};

Expand Down Expand Up @@ -800,6 +805,11 @@ TEST_F(SHMTransportTests, port_and_segment_overflow_discard)
ASSERT_TRUE(transportUnderTest.OpenOutputChannel(send_resource_list, outputChannelLocator));
ASSERT_FALSE(send_resource_list.empty());
octet message[4] = { 'H', 'e', 'l', 'l'};
std::list<NetworkBuffer> buffer_list;
for (size_t i = 0; i < 4; ++i)
{
buffer_list.push_back(NetworkBuffer(&message[i], 1));
}

LocatorList locator_list;
locator_list.push_back(unicastLocator);
Expand All @@ -810,8 +820,10 @@ TEST_F(SHMTransportTests, port_and_segment_overflow_discard)
// Internally the segment is bigger than "my_descriptor.segment_size" so a bigger buffer is tried
// to cause segment overflow
octet message_big[4096] = { 'H', 'e', 'l', 'l'};
std::list<NetworkBuffer> buffer_list;
buffer_list.push_back(NetworkBuffer(message_big, 4096));

EXPECT_TRUE(send_resource_list.at(0)->send(message_big, sizeof(message_big), &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, sizeof(message_big), &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100))));
}

Expand All @@ -822,7 +834,7 @@ TEST_F(SHMTransportTests, port_and_segment_overflow_discard)
Locators locators_end(locator_list.end());

// At least 4 msgs of 4 bytes are allowed
EXPECT_TRUE(send_resource_list.at(0)->send(message, sizeof(message), &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, sizeof(message), &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100))));
}

Expand All @@ -840,7 +852,7 @@ TEST_F(SHMTransportTests, port_and_segment_overflow_discard)
Locators locators_begin(locator_list.begin());
Locators locators_end(locator_list.end());

EXPECT_TRUE(send_resource_list.at(0)->send(message, sizeof(message), &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, sizeof(message), &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100))));
}

Expand All @@ -849,7 +861,7 @@ TEST_F(SHMTransportTests, port_and_segment_overflow_discard)
Locators locators_begin(locator_list.begin());
Locators locators_end(locator_list.end());

EXPECT_TRUE(send_resource_list.at(0)->send(message, sizeof(message), &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, sizeof(message), &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100))));
}

Expand Down Expand Up @@ -2027,6 +2039,11 @@ TEST_F(SHMTransportTests, dump_file)
ASSERT_FALSE(send_resource_list.empty());
ASSERT_TRUE(transportUnderTest.IsInputChannelOpen(unicastLocator));
octet message[5] = { 'H', 'e', 'l', 'l', 'o' };
std::list<NetworkBuffer> buffer_list;
for (size_t i = 0; i < 5; ++i)
{
buffer_list.push_back(NetworkBuffer(&message[i], 1));
}

std::function<void()> recCallback = [&]()
{
Expand All @@ -2043,7 +2060,7 @@ TEST_F(SHMTransportTests, dump_file)
Locators locators_begin(locator_list.begin());
Locators locators_end(locator_list.end());

EXPECT_TRUE(send_resource_list.at(0)->send(message, 5, &locators_begin, &locators_end,
EXPECT_TRUE(send_resource_list.at(0)->send(buffer_list, 5, &locators_begin, &locators_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(1000))));
};

Expand Down
Loading

0 comments on commit 5de9ef4

Please sign in to comment.