Skip to content

Commit

Permalink
fix introduction of fastdds includes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex031544 committed Sep 1, 2020
1 parent fc1ba72 commit 4762f94
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 41 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ COPY --from=builder \
/usr/local/include/fastrtps \
/usr/local/include/fastrtps

COPY --from=builder \
/usr/local/include/fastdds \
/usr/local/include/fastdds

COPY --from=builder \
/usr/local/lib/libfastrtps.so* \
/usr/local/lib/
Expand Down
4 changes: 4 additions & 0 deletions dockerhub/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ COPY --from=builder \
/usr/local/include/fastrtps \
/usr/local/include/fastrtps

COPY --from=builder \
/usr/local/include/fastdds \
/usr/local/include/fastdds

COPY --from=builder \
/usr/local/lib/libfastrtps.so* \
/usr/local/lib/
Expand Down
4 changes: 4 additions & 0 deletions dockerhub/Dockerfile.example
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ COPY --from=builder \
/usr/local/include/fastrtps \
/usr/local/include/fastrtps

COPY --from=builder \
/usr/local/include/fastdds \
/usr/local/include/fastdds

COPY --from=builder \
/usr/local/lib/libfastrtps.so* \
/usr/local/lib/
Expand Down
56 changes: 35 additions & 21 deletions examples/multiStageBuild/HelloWorldExample/HelloWorldPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ bool HelloWorldPublisher::init()
PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
PParam.rtps.builtin.domainId = 0;
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_pub");
mp_participant = Domain::createParticipant(PParam);

if(mp_participant==nullptr)
if (mp_participant == nullptr)
{
return false;
}
//REGISTER THE TYPE

Domain::registerType(mp_participant,&m_type);
Domain::registerType(mp_participant, &m_type);

//CREATE THE PUBLISHER
PublisherAttributes Wparam;
Expand All @@ -65,11 +66,13 @@ bool HelloWorldPublisher::init()
Wparam.topic.resourceLimitsQos.max_samples = 50;
Wparam.topic.resourceLimitsQos.allocated_samples = 20;
Wparam.times.heartbeatPeriod.seconds = 2;
Wparam.times.heartbeatPeriod.nanosec = 200*1000*1000;
Wparam.times.heartbeatPeriod.nanosec = 200 * 1000 * 1000;
Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
mp_publisher = Domain::createPublisher(mp_participant,Wparam,(PublisherListener*)&m_listener);
if(mp_publisher == nullptr)
mp_publisher = Domain::createPublisher(mp_participant, Wparam, (PublisherListener*)&m_listener);
if (mp_publisher == nullptr)
{
return false;
}

return true;

Expand All @@ -81,50 +84,60 @@ HelloWorldPublisher::~HelloWorldPublisher()
Domain::removeParticipant(mp_participant);
}

void HelloWorldPublisher::PubListener::onPublicationMatched(Publisher* /*pub*/,MatchingInfo& info)
void HelloWorldPublisher::PubListener::onPublicationMatched(
Publisher* /*pub*/,
MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
if (info.status == MATCHED_MATCHING)
{
n_matched++;
firstConnected = true;
std::cout << "Publisher matched"<<std::endl;
std::cout << "Publisher matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Publisher unmatched"<<std::endl;
std::cout << "Publisher unmatched" << std::endl;
}
}

void HelloWorldPublisher::runThread(uint32_t samples, uint32_t sleep)
void HelloWorldPublisher::runThread(
uint32_t samples,
uint32_t sleep)
{
if (samples == 0)
{
while(!stop)
while (!stop)
{
if(publish(false))
if (publish(false))
{
std::cout << "Message: "<<m_Hello.message()<< " with index: "<< m_Hello.index()<< " SENT"<<std::endl;
std::cout << "Message: " << m_Hello.message() << " with index: " << m_Hello.index() << " SENT" <<
std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
}
}
else
{
for(uint32_t i = 0;i<samples;++i)
for (uint32_t i = 0; i < samples; ++i)
{
if(!publish())
if (!publish())
{
--i;
}
else
{
std::cout << "Message: "<<m_Hello.message()<< " with index: "<< m_Hello.index()<< " SENT"<<std::endl;
std::cout << "Message: " << m_Hello.message() << " with index: " << m_Hello.index() << " SENT" <<
std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
}
}
}

void HelloWorldPublisher::run(uint32_t samples, uint32_t sleep)
void HelloWorldPublisher::run(
uint32_t samples,
uint32_t sleep)
{
stop = false;
std::thread thread(&HelloWorldPublisher::runThread, this, samples, sleep);
Expand All @@ -141,11 +154,12 @@ void HelloWorldPublisher::run(uint32_t samples, uint32_t sleep)
thread.join();
}

bool HelloWorldPublisher::publish(bool waitForListener)
bool HelloWorldPublisher::publish(
bool waitForListener)
{
if(m_listener.firstConnected || !waitForListener || m_listener.n_matched>0)
if (m_listener.firstConnected || !waitForListener || m_listener.n_matched > 0)
{
m_Hello.index(m_Hello.index()+1);
m_Hello.index(m_Hello.index() + 1);
mp_publisher->write((void*)&m_Hello);
return true;
}
Expand Down
48 changes: 28 additions & 20 deletions examples/multiStageBuild/HelloWorldExample/HelloWorldSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

HelloWorldSubscriber::HelloWorldSubscriber():mp_participant(nullptr),
mp_subscriber(nullptr)
HelloWorldSubscriber::HelloWorldSubscriber()
: mp_participant(nullptr)
, mp_subscriber(nullptr)
{
}

Expand All @@ -39,16 +40,17 @@ bool HelloWorldSubscriber::init()
PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
PParam.rtps.builtin.domainId = 0;
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_sub");
mp_participant = Domain::createParticipant(PParam);
if(mp_participant==nullptr)
if (mp_participant == nullptr)
{
return false;
}

//REGISTER THE TYPE

Domain::registerType(mp_participant,&m_type);
Domain::registerType(mp_participant, &m_type);
//CREATE THE SUBSCRIBER
SubscriberAttributes Rparam;
Rparam.topic.topicKind = NO_KEY;
Expand All @@ -60,59 +62,65 @@ bool HelloWorldSubscriber::init()
Rparam.topic.resourceLimitsQos.allocated_samples = 20;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
mp_subscriber = Domain::createSubscriber(mp_participant,Rparam,(SubscriberListener*)&m_listener);
mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, (SubscriberListener*)&m_listener);

if(mp_subscriber == nullptr)
if (mp_subscriber == nullptr)
{
return false;
}


return true;
}

HelloWorldSubscriber::~HelloWorldSubscriber() {
HelloWorldSubscriber::~HelloWorldSubscriber()
{
// TODO Auto-generated destructor stub
Domain::removeParticipant(mp_participant);
}

void HelloWorldSubscriber::SubListener::onSubscriptionMatched(Subscriber* /*sub*/,MatchingInfo& info)
void HelloWorldSubscriber::SubListener::onSubscriptionMatched(
Subscriber* /*sub*/,
MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
if (info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Subscriber matched"<<std::endl;
std::cout << "Subscriber matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Subscriber unmatched"<<std::endl;
std::cout << "Subscriber unmatched" << std::endl;
}
}

void HelloWorldSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
void HelloWorldSubscriber::SubListener::onNewDataMessage(
Subscriber* sub)
{
if(sub->takeNextData((void*)&m_Hello, &m_info))
if (sub->takeNextData((void*)&m_Hello, &m_info))
{
if(m_info.sampleKind == ALIVE)
if (m_info.sampleKind == ALIVE)
{
this->n_samples++;
// Print your structure data here.
std::cout << "Message "<<m_Hello.message()<< " "<< m_Hello.index()<< " RECEIVED"<<std::endl;
std::cout << "Message " << m_Hello.message() << " " << m_Hello.index() << " RECEIVED" << std::endl;
}
}

}


void HelloWorldSubscriber::run()
{
std::cout << "Subscriber running. Please press enter to stop the Subscriber" << std::endl;
std::cin.ignore();
}

void HelloWorldSubscriber::run(uint32_t number)
void HelloWorldSubscriber::run(
uint32_t number)
{
std::cout << "Subscriber running until "<< number << "samples have been received"<<std::endl;
while(number > this->m_listener.n_samples)
std::cout << "Subscriber running until " << number << "samples have been received" << std::endl;
while (number > this->m_listener.n_samples)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Expand Down

0 comments on commit 4762f94

Please sign in to comment.