Skip to content

Commit

Permalink
Refs 10522. Added example.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Feb 26, 2021
1 parent 5d34a34 commit 47c62d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
67 changes: 67 additions & 0 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4000,6 +4000,73 @@ void dds_usecase_examples()
//!--
}

{
// Create the DomainParticipant
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
// Error
return;
}

// Create the Publisher
Publisher* publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT);
if (nullptr == publisher)
{
// Error
return;
}

// Create the Subscriber
Subscriber* subscriber = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT);
if (nullptr == subscriber)
{
// Error
return;
}

// Create the Topic with the appropriate name and data type
std::string topic_name = "HelloWorldTopic";
std::string data_type = "HelloWorld";
Topic* topic = participant->create_topic(topic_name, data_type, TOPIC_QOS_DEFAULT);
if (nullptr == topic)
{
// Error
return;
}

//UNIQUE_NETWORK_FLOWS_USE_CASE
// Create the DataWriter
DataWriter* writer = publisher->create_datawriter(topic, DATAWRITER_QOS_DEFAULT);
if (nullptr == writer)
{
// Error
return;
}

// Create DataReader with unique flows
DataReaderQos drqos = DATAREADER_QOS_DEFAULT;
drqos.properties().properties().emplace_back("fastdds.unique_network_flows", "");
DataReader* reader = subscriber->create_datareader(topic, drqos);

// Print locators information
eprosima::fastdds::rtps::LocatorList locators;
writer->get_sending_locators(locators);
std::cout << "Writer is sending from the following locators:" << std::endl;
for (const auto& locator : locators)
{
std::cout << " " << locator << std::endl;
}

reader->get_listening_locators(locators);
std::cout << "Reader is listening on the following locators:" << std::endl;
for (const Locator_t& locator : locators)
{
std::cout << " " << locator << std::endl;
}
//!--
}
}

void dds_persistence_examples()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ On Fast DDS, there are two ways to select unique listening locators on the DataR
* The application can request the reader to be created with unique listening locators.
This is done using a :ref:`propertypolicyqos` including the property ``"fastdds.unique_network_flows"``.
In this case, the reader will listen on a unique port outside the range of ports typically used by RTPS.

Example
-------

The following snippet demonstrates all the APIs described on this page:

.. literalinclude:: /../code/DDSCodeTester.cpp
:language: c++
:start-after: //UNIQUE_NETWORK_FLOWS_USE_CASE
:end-before: //!--
:dedent: 8

0 comments on commit 47c62d8

Please sign in to comment.