Skip to content

Commit

Permalink
Refs #21324: Apply rev suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Jul 17, 2024
1 parent 69cf7e3 commit e425fdf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "PublisherApp.hpp"], description=["Thi
#include <condition_variable>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

Expand Down Expand Up @@ -59,6 +60,7 @@ private:
//! Publish a sample
bool publish();

std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Publisher* publisher_;
eprosima::fastdds::dds::Topic* topic_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ using namespace eprosima::fastdds::dds;

$ctx.filename$PublisherApp::$ctx.filename$PublisherApp(
const int& domain_id)
: participant_(nullptr)
: factory_(nullptr)
, participant_(nullptr)
, publisher_(nullptr)
, topic_(nullptr)
, writer_(nullptr)
Expand All @@ -53,8 +54,8 @@ $ctx.filename$PublisherApp::$ctx.filename$PublisherApp(
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("$ctx.m_lastStructureScopedName$_pub_participant");
participant_ = DomainParticipantFactory::get_instance()->create_participant(
domain_id, pqos, nullptr, StatusMask::none());
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("$ctx.m_lastStructureScopedName$ Participant initialization failed");
Expand Down Expand Up @@ -102,7 +103,7 @@ $ctx.filename$PublisherApp::~$ctx.filename$PublisherApp()
participant_->delete_contained_entities();

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

Expand All @@ -112,13 +113,19 @@ void $ctx.filename$PublisherApp::on_publication_matched(
{
if (info.current_count_change == 1)
{
matched_ = info.current_count;
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << "$ctx.m_lastStructureScopedName$ Publisher matched." << std::endl;
cv_.notify_one();
}
else if (info.current_count_change == -1)
{
matched_ = info.current_count;
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << "$ctx.m_lastStructureScopedName$ Publisher unmatched." << std::endl;
}
else
Expand All @@ -138,7 +145,7 @@ void $ctx.filename$PublisherApp::run()
}
// Wait for period or stop event
std::unique_lock<std::mutex> period_lock(mutex_);
cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [&]()
cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [this]()
{
return is_stopped();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "SubscriberApp.hpp"], description=["Th
#include <condition_variable>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

Expand Down Expand Up @@ -61,6 +62,7 @@ private:
//! Return the current state of execution
bool is_stopped();

std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Subscriber* subscriber_;
eprosima::fastdds::dds::Topic* topic_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ using namespace eprosima::fastdds::dds;

$ctx.filename$SubscriberApp::$ctx.filename$SubscriberApp(
const int& domain_id)
: participant_(nullptr)
: factory_(nullptr)
, participant_(nullptr)
, subscriber_(nullptr)
, topic_(nullptr)
, reader_(nullptr)
Expand All @@ -49,8 +50,8 @@ $ctx.filename$SubscriberApp::$ctx.filename$SubscriberApp(
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("$ctx.m_lastStructureScopedName$_sub_participant");
participant_ = DomainParticipantFactory::get_instance()->create_participant(
domain_id, pqos, nullptr, StatusMask::none());
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("$ctx.m_lastStructureScopedName$ Participant initialization failed");
Expand Down Expand Up @@ -98,7 +99,7 @@ $ctx.filename$SubscriberApp::~$ctx.filename$SubscriberApp()
participant_->delete_contained_entities();

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

Expand Down Expand Up @@ -138,7 +139,7 @@ void $ctx.filename$SubscriberApp::on_data_available(
void $ctx.filename$SubscriberApp::run()
{
std::unique_lock<std::mutex> lck(terminate_cv_mtx_);
terminate_cv_.wait(lck, [&]
terminate_cv_.wait(lck, [this]
{
return is_stopped();
});
Expand Down

0 comments on commit e425fdf

Please sign in to comment.