Skip to content

Commit

Permalink
Refs #21266: Delete namespace used in delivery_mechanism example
Browse files Browse the repository at this point in the history
Signed-off-by: Carlosespicur <[email protected]>
  • Loading branch information
Carlosespicur committed Jul 3, 2024
1 parent cb54401 commit 95a6922
Show file tree
Hide file tree
Showing 23 changed files with 1,475 additions and 110 deletions.
2 changes: 0 additions & 2 deletions examples/cpp/delivery_mechanisms/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "SubscriberApp.hpp"
#include "PubSubApp.hpp"

using namespace eprosima::fastdds::dds;

namespace eprosima {
namespace fastdds {
namespace examples {
Expand Down
1 change: 0 additions & 1 deletion examples/cpp/delivery_mechanisms/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace fastdds {
namespace examples {
namespace delivery_mechanisms {

using namespace eprosima::fastdds::dds;
using dds::Log;

class CLIParser
Expand Down
59 changes: 29 additions & 30 deletions examples/cpp/delivery_mechanisms/PubSubApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "CLIParser.hpp"
#include "DeliveryMechanismsPubSubTypes.hpp"

using namespace eprosima::fastdds::dds;
using namespace eprosima::fastdds::rtps;

namespace eprosima {
Expand Down Expand Up @@ -75,14 +74,14 @@ PubSubApp::PubSubApp(
}

// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
dds::DomainParticipantQos pqos = dds::PARTICIPANT_QOS_DEFAULT;
pqos.name("DeliveryMechanisms_pubsub_participant");
pqos.transport().use_builtin_transports = false;

uint32_t max_samples = samples_;
if (max_samples == 0)
{
max_samples = DATAWRITER_QOS_DEFAULT.resource_limits().max_samples_per_instance;
max_samples = dds::DATAWRITER_QOS_DEFAULT.resource_limits().max_samples_per_instance;
}

if (config.ignore_local_endpoints)
Expand Down Expand Up @@ -196,9 +195,9 @@ PubSubApp::PubSubApp(
}
}

auto factory = DomainParticipantFactory::get_instance();
auto factory = dds::DomainParticipantFactory::get_instance();
factory->set_library_settings(library_settings);
participant_ = factory->create_participant(config.domain, pqos, nullptr, StatusMask::none());
participant_ = factory->create_participant(config.domain, pqos, nullptr, dds::StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("Participant initialization failed");
Expand All @@ -208,25 +207,25 @@ PubSubApp::PubSubApp(
type_.register_type(participant_);

// Create the publisher
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
dds::PublisherQos pub_qos = dds::PUBLISHER_QOS_DEFAULT;
participant_->get_default_publisher_qos(pub_qos);
publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none());
publisher_ = participant_->create_publisher(pub_qos, nullptr, dds::StatusMask::none());
if (publisher_ == nullptr)
{
throw std::runtime_error("Publisher initialization failed");
}

// Create the subscriber
SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT;
dds::SubscriberQos sub_qos = dds::SUBSCRIBER_QOS_DEFAULT;
participant_->get_default_subscriber_qos(sub_qos);
subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none());
subscriber_ = participant_->create_subscriber(sub_qos, nullptr, dds::StatusMask::none());
if (subscriber_ == nullptr)
{
throw std::runtime_error("Subscriber initialization failed");
}

// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
dds::TopicQos topic_qos = dds::TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic(topic_name, type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
Expand All @@ -235,16 +234,16 @@ PubSubApp::PubSubApp(
}

// Create the data reader and data writer
DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT;
DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT;
dds::DataReaderQos reader_qos = dds::DATAREADER_QOS_DEFAULT;
dds::DataWriterQos writer_qos = dds::DATAWRITER_QOS_DEFAULT;
subscriber_->get_default_datareader_qos(reader_qos);
publisher_->get_default_datawriter_qos(writer_qos);
reader_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
reader_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
reader_qos.reliability().kind = dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.reliability().kind = dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.durability().kind = dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.durability().kind = dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
reader_qos.history().kind = dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_qos.history().kind = dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
reader_qos.history().depth = max_samples;
writer_qos.history().depth = max_samples;
reader_qos.resource_limits().max_samples_per_instance = max_samples;
Expand All @@ -261,12 +260,12 @@ PubSubApp::PubSubApp(
reader_qos.data_sharing().off();
writer_qos.data_sharing().off();
}
reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all());
reader_ = subscriber_->create_datareader(topic_, reader_qos, this, dds::StatusMask::all());
if (reader_ == nullptr)
{
throw std::runtime_error("DataReader initialization failed");
}
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all());
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, dds::StatusMask::all());
if (writer_ == nullptr)
{
throw std::runtime_error("DataWriter initialization failed");
Expand All @@ -281,13 +280,13 @@ PubSubApp::~PubSubApp()
participant_->delete_contained_entities();

// Delete DomainParticipant
DomainParticipantFactory::get_instance()->delete_participant(participant_);
dds::DomainParticipantFactory::get_instance()->delete_participant(participant_);
}
}

void PubSubApp::on_publication_matched(
eprosima::fastdds::dds::DataWriter* /*writer*/,
const PublicationMatchedStatus& info)
const dds::PublicationMatchedStatus& info)
{
if (info.current_count_change == 1)
{
Expand All @@ -308,8 +307,8 @@ void PubSubApp::on_publication_matched(
}

void PubSubApp::on_subscription_matched(
DataReader* /*reader*/,
const SubscriptionMatchedStatus& info)
dds::DataReader* /*reader*/,
const dds::SubscriptionMatchedStatus& info)
{
if (info.current_count_change == 1)
{
Expand All @@ -327,18 +326,18 @@ void PubSubApp::on_subscription_matched(
}

void PubSubApp::on_data_available(
DataReader* reader)
dds::DataReader* reader)
{
FASTDDS_CONST_SEQUENCE(DataSeq, DeliveryMechanisms);

DataSeq delivery_mechanisms_sequence;
SampleInfoSeq info_sequence;
dds::SampleInfoSeq info_sequence;
while ((!is_stopped()) && ((samples_ == 0) || ((samples_ > 0) && (received_samples_ < samples_)))
&& (RETCODE_OK == reader->take(delivery_mechanisms_sequence, info_sequence)))
&& (dds::RETCODE_OK == reader->take(delivery_mechanisms_sequence, info_sequence)))
{
for (LoanableCollection::size_type i = 0; i < info_sequence.length(); ++i)
for (dds::LoanableCollection::size_type i = 0; i < info_sequence.length(); ++i)
{
if ((info_sequence[i].instance_state == ALIVE_INSTANCE_STATE) && info_sequence[i].valid_data)
if ((info_sequence[i].instance_state == dds::ALIVE_INSTANCE_STATE) && info_sequence[i].valid_data)
{
const DeliveryMechanisms& delivery_mechanisms_ = delivery_mechanisms_sequence[i];

Expand Down Expand Up @@ -389,7 +388,7 @@ bool PubSubApp::publish()
return ((matched_ > 0) || is_stopped());
});
void* sample_ = nullptr;
if (!is_stopped() && (RETCODE_OK == writer_->loan_sample(sample_)))
if (!is_stopped() && (dds::RETCODE_OK == writer_->loan_sample(sample_)))
{
DeliveryMechanisms* delivery_mechanisms_ = static_cast<DeliveryMechanisms*>(sample_);
delivery_mechanisms_->index() = ++index_of_last_sample_sent_;
Expand Down
29 changes: 13 additions & 16 deletions examples/cpp/delivery_mechanisms/PubSubApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@

#include "Application.hpp"
#include "CLIParser.hpp"
#include "DeliveryMechanismsPubSubTypes.hpp"

using namespace eprosima::fastdds::dds;

namespace eprosima {
namespace fastdds {
namespace examples {
namespace delivery_mechanisms {

class PubSubApp : public Application, public DataReaderListener, public DataWriterListener
class PubSubApp : public Application, public dds::DataReaderListener, public dds::DataWriterListener
{
public:

Expand All @@ -56,17 +53,17 @@ class PubSubApp : public Application, public DataReaderListener, public DataWrit

//! Subscription callback
void on_data_available(
DataReader* reader) override;
dds::DataReader* reader) override;

//! Publisher matched method
void on_publication_matched(
DataWriter* writer,
const PublicationMatchedStatus& info) override;
dds::DataWriter* writer,
const dds::PublicationMatchedStatus& info) override;

//! Subscriber matched method
void on_subscription_matched(
DataReader* reader,
const SubscriptionMatchedStatus& info) override;
dds::DataReader* reader,
const dds::SubscriptionMatchedStatus& info) override;

//! Run the subscriber
void run() override;
Expand All @@ -82,19 +79,19 @@ class PubSubApp : public Application, public DataReaderListener, public DataWrit
//! Publish a sample
bool publish();

DomainParticipant* participant_;
dds::DomainParticipant* participant_;

Publisher* publisher_;
dds::Publisher* publisher_;

Subscriber* subscriber_;
dds::Subscriber* subscriber_;

Topic* topic_;
dds::Topic* topic_;

DataReader* reader_;
dds::DataReader* reader_;

DataWriter* writer_;
dds::DataWriter* writer_;

TypeSupport type_;
dds::TypeSupport type_;

std::condition_variable cv_;

Expand Down
32 changes: 15 additions & 17 deletions examples/cpp/delivery_mechanisms/PublisherApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
#include <fastdds/rtps/transport/UDPv6TransportDescriptor.hpp>

#include "PublisherApp.hpp"
#include "DeliveryMechanisms.hpp"
#include "DeliveryMechanismsPubSubTypes.hpp"

using namespace eprosima::fastdds::dds;
using namespace eprosima::fastdds::rtps;

namespace eprosima {
Expand Down Expand Up @@ -68,13 +66,13 @@ PublisherApp::PublisherApp(
}

// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
dds::DomainParticipantQos pqos = dds::PARTICIPANT_QOS_DEFAULT;
pqos.name("DeliveryMechanisms_pub_participant");

uint32_t max_samples = samples_;
if (max_samples == 0)
{
max_samples = DATAWRITER_QOS_DEFAULT.resource_limits().max_samples_per_instance;
max_samples = dds::DATAWRITER_QOS_DEFAULT.resource_limits().max_samples_per_instance;
}

// Transport default definitions
Expand Down Expand Up @@ -171,9 +169,9 @@ PublisherApp::PublisherApp(
}
}

auto factory = DomainParticipantFactory::get_instance();
auto factory = dds::DomainParticipantFactory::get_instance();
factory->set_library_settings(library_settings);
participant_ = factory->create_participant(config.domain, pqos, nullptr, StatusMask::none());
participant_ = factory->create_participant(config.domain, pqos, nullptr, dds::StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("Participant initialization failed");
Expand All @@ -183,16 +181,16 @@ PublisherApp::PublisherApp(
type_.register_type(participant_);

// Create the publisher
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
dds::PublisherQos pub_qos = dds::PUBLISHER_QOS_DEFAULT;
participant_->get_default_publisher_qos(pub_qos);
publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none());
publisher_ = participant_->create_publisher(pub_qos, nullptr, dds::StatusMask::none());
if (publisher_ == nullptr)
{
throw std::runtime_error("Publisher initialization failed");
}

// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
dds::TopicQos topic_qos = dds::TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic(topic_name, type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
Expand All @@ -201,11 +199,11 @@ PublisherApp::PublisherApp(
}

// Create the data writer
DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT;
dds::DataWriterQos writer_qos = dds::DATAWRITER_QOS_DEFAULT;
publisher_->get_default_datawriter_qos(writer_qos);
writer_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_qos.reliability().kind = dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.durability().kind = dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.history().kind = dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_qos.history().depth = max_samples;
writer_qos.resource_limits().max_samples_per_instance = max_samples;
writer_qos.resource_limits().max_samples = writer_qos.resource_limits().max_instances * max_samples;
Expand All @@ -217,7 +215,7 @@ PublisherApp::PublisherApp(
{
writer_qos.data_sharing().off();
}
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all());
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, dds::StatusMask::all());
if (writer_ == nullptr)
{
throw std::runtime_error("DataWriter initialization failed");
Expand All @@ -232,13 +230,13 @@ PublisherApp::~PublisherApp()
participant_->delete_contained_entities();

// Delete DomainParticipant
DomainParticipantFactory::get_instance()->delete_participant(participant_);
dds::DomainParticipantFactory::get_instance()->delete_participant(participant_);
}
}

void PublisherApp::on_publication_matched(
eprosima::fastdds::dds::DataWriter* /*writer*/,
const PublicationMatchedStatus& info)
const dds::PublicationMatchedStatus& info)
{
if (info.current_count_change == 1)
{
Expand Down Expand Up @@ -286,7 +284,7 @@ bool PublisherApp::publish()
return ((matched_ > 0) || is_stopped());
});
void* sample_ = nullptr;
if (!is_stopped() && (RETCODE_OK == writer_->loan_sample(sample_)))
if (!is_stopped() && (dds::RETCODE_OK == writer_->loan_sample(sample_)))
{
DeliveryMechanisms* delivery_mechanisms_ = static_cast<DeliveryMechanisms*>(sample_);
delivery_mechanisms_->index() = ++index_of_last_sample_sent_;
Expand Down
Loading

0 comments on commit 95a6922

Please sign in to comment.