Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds liveliness QoS [5621] #560

Merged
merged 48 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5c8bb45
Refs #5183 Adding C++ example of liveliness with one AUTOMATIC publisher
Apr 24, 2019
db06977
Refs #5183 Extending C++ examples to allow using a participant with t…
Apr 24, 2019
2b0892d
Refs #5183 Extending C++ example to allow configuration of liveliness…
Apr 24, 2019
651021a
Refs #5060 Format changes only
Apr 26, 2019
ea84505
Refs #5060 Removing WriterProxyLiveliness and adding new classes
Apr 26, 2019
b275273
Refs #5060 Adding liveliness manager to RTPSReader and WLP
Apr 29, 2019
5c8b207
Refs #5060 Removing liveliness information from WriterProxyData
Apr 29, 2019
aa877f2
Refs 5060 Adding functionality to liveliness manager + unit tests
Apr 30, 2019
ed5c8f5
Refs #5060 Adding liveliness methods at the reader-writer layer
Apr 30, 2019
67a2dc6
Refs #5060 Updating WLP so that it invokes writer listener when livel…
May 8, 2019
a36b2dd
Refs #5060 Adding callbacks to pub-sub layer
May 8, 2019
0d9a0da
Refs #5060 Implementing getters for liveliness status
May 8, 2019
8291c88
Refs #5060 Changes to implement assert_liveliness() method
May 8, 2019
76ff3e8
Refs #5060 Adding option to liveliness manager to exclude automatic w…
May 14, 2019
4e82af8
Refs #5060 Fixing WLP so that liveliness manager is created when WLP …
May 14, 2019
31b4d7d
Refs #5060 Fixing WLP so that liveliness manager is created when WLP …
May 20, 2019
2ae19ed
Refs #5060 Changes to WLP to make AUTOMATIC (writer) - AUTOMATIC (rea…
May 22, 2019
254e4e5
Refs #5060 Changes to WLP to make MANUAL_BY_PARTICIPANT (w) - MANUAL_…
May 23, 2019
c723ad7
Refs #5060 Changes to WLP to make MANUAL_BY_TOPIC (w) - MANUAL_BY_TOP…
May 23, 2019
a0f2215
Refs #5060 Changes to stateless reader and writer
May 23, 2019
94e67bb
Refs #5060 Implementing assert_liveliness method
May 24, 2019
3f7025a
Refs #5060 Changes to allow different liveliness kinds between writer…
May 29, 2019
3498e64
Refs #5060 Combining some blackbox tests
May 29, 2019
33d90fc
Refs #5060 Code clean-up
May 29, 2019
be80fb0
Refs #5060 Testing more than one pub/sub in the same participant
Jun 5, 2019
567d827
Refs #5060 Code clean up
Jun 6, 2019
9438353
Refs #5060 Fixing deadlock
Jun 11, 2019
32dae5a
Refs #5060 More code clean up
Jun 11, 2019
991043c
Refs #5060 Trying to fix builds
Jun 11, 2019
97e9b1f
Refs #5060 Trying to fix build of tests
Jun 11, 2019
0f1f9dd
Refs #5060 Fixing error message that shouldn't be logged
Jun 12, 2019
312c075
Refs #5060 Fixing warnings and trying to make tests for stable when r…
Jun 12, 2019
0022d93
Refs #5060 Addressing review comments
Jun 12, 2019
3604546
Refs #5060 Adding a python test for automatic liveliness
Jun 13, 2019
ae49d14
Refs #5058 Fixing windows builds
Jun 17, 2019
1fa061b
Refs #5060 Fixing mac warnings
Jun 17, 2019
73e013d
Refs #5060 Fixing mac build
richiware Jun 18, 2019
6147b79
Refs #5060 Fixing failing test on mac
richiware Jun 18, 2019
8196486
Refs #5060 Trying to make some tests more stable when using valgrind
Jun 18, 2019
64410ce
Refs #5060 Trying to make tests more stable by using condition variables
Jun 19, 2019
eb23919
Refs #5060 Resolving remaining review comments
Jun 19, 2019
74f0842
Refs #5060 Making some tests more stable on windows
Jun 20, 2019
d293ce8
Refs #5060 Fixing remaining tabs
Jun 20, 2019
fff31e2
Refs #5060 Fixing mac warning
Jun 20, 2019
3aa3b05
Refs #5060 Making some ests more stable on mac
raquelalvarezbanos Jun 20, 2019
369fc47
Refs #5060 Trying to fix remaining test that is failing on mac
richiware Jun 21, 2019
9deea8a
Refs #5060 Removing asserts and letting timers manage non-positive in…
richiware Jun 21, 2019
42ba11e
Refs #5060 Adding explanation about non-positive intervals
richiware Jun 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/C++/LivelinessQoS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 2.8.12)

if(NOT CMAKE_VERSION VERSION_LESS 3.0)
cmake_policy(SET CMP0048 NEW)
endif()

project(LivelinessQoS)

# Find requirements
if(NOT fastcdr_FOUND)
find_package(fastcdr REQUIRED)
endif()

if(NOT fastrtps_FOUND)
find_package(fastrtps REQUIRED)
endif()

# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(-std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()

message(STATUS "Configuring HelloWorld example...")
file(GLOB LIVELINESSQOS_SOURCES_CXX "*.cxx")
file(GLOB LIVELINESSQOS_SOURCES_CPP "*.cpp")

add_executable(LivelinessQoS ${LIVELINESSQOS_SOURCES_CXX} ${LIVELINESSQOS_SOURCES_CPP})
target_link_libraries(LivelinessQoS fastrtps fastcdr)
install(TARGETS LivelinessQoS
RUNTIME DESTINATION examples/C++/LivelinessQoS/${BIN_INSTALL_DIR})
145 changes: 145 additions & 0 deletions examples/C++/LivelinessQoS/LivelinessPublisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file LivelinessPublisher.cpp
*
*/

#include "LivelinessPublisher.h"
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>

#include <thread>

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

LivelinessPublisher::LivelinessPublisher()
: participant_(nullptr)
, publisher_(nullptr)
{
}

bool LivelinessPublisher::init(
LivelinessQosPolicyKind kind,
int liveliness_ms)
{
topic_.index(0);
topic_.message("HelloWorld");

ParticipantAttributes PParam;
PParam.rtps.builtin.use_SIMPLE_RTPSParticipantDiscoveryProtocol = true;
PParam.rtps.builtin.use_SIMPLE_EndpointDiscoveryProtocol = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
PParam.rtps.builtin.domainId = 0;
PParam.rtps.builtin.use_WriterLivelinessProtocol = true;
PParam.rtps.setName("Participant_pub");
participant_ = Domain::createParticipant(PParam);
if(participant_==nullptr)
{
return false;
}
Domain::registerType(participant_,&type_);

PublisherAttributes Wparam;
Wparam.topic.topicKind = NO_KEY;
Wparam.topic.topicDataType = "Topic";
Wparam.topic.topicName = "Name";
Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Wparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Wparam.topic.historyQos.depth = 30;
Wparam.qos.m_liveliness.lease_duration = Duration_t(liveliness_ms * 1e-3);
Wparam.qos.m_liveliness.announcement_period = Duration_t(liveliness_ms * 1e-3 * 0.5);
Wparam.qos.m_liveliness.kind = kind;
publisher_ = Domain::createPublisher(participant_, Wparam, &listener_);
if(publisher_ == nullptr)
{
return false;
}
return true;
}

LivelinessPublisher::~LivelinessPublisher()
{
Domain::removeParticipant(participant_);
}

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

void LivelinessPublisher::PubListener::on_liveliness_lost(
Publisher *pub,
const LivelinessLostStatus &status)
{
std::cout << "Publisher " << pub->getGuid() << " lost liveliness: " << status.total_count << std::endl;
}

void LivelinessPublisher::run(uint32_t samples, uint32_t sleep)
{
std::thread thread1(&LivelinessPublisher::runThread, this, publisher_, samples, sleep);
thread1.join();
}

void LivelinessPublisher::runThread(
Publisher* pub,
uint32_t samples,
uint32_t sleep)
{

for(uint32_t i = 0;i<samples;++i)
{
if(!publish(pub))
{
--i;
}
else
{
std::cout << "Message with index: " << topic_.index()<< " SENT by publisher " << pub->getGuid() << std::endl;
}
eClock::my_sleep(sleep);
}

std::cin.ignore();
}

bool LivelinessPublisher::publish(
Publisher* pub,
bool waitForListener)
{
if(listener_.first_connected || !waitForListener || listener_.n_matched > 0)
{
topic_.index(topic_.index()+1);
pub->write((void*)&topic_);
return true;
}
return false;
}
94 changes: 94 additions & 0 deletions examples/C++/LivelinessQoS/LivelinessPublisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file LivelinessPublisher.h
*
*/

#ifndef LivelinessPublisher_H_
#define LivelinessPublisher_H_

#include "TopicType.h"
#include "Topic.h"

#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/PublisherListener.h>

#include <mutex>

class LivelinessPublisher {
public:

//! Constructor
LivelinessPublisher();

//! Destructor
virtual ~LivelinessPublisher();

//! Initialize
bool init(
eprosima::fastrtps::LivelinessQosPolicyKind kind,
int liveliness_ms);

//! Publish a sample
bool publish(
eprosima::fastrtps::Publisher* pub,
bool waitForListener = true);

//! Run for number samples
void run(uint32_t number, uint32_t sleep);

private:

Topic topic_;
TopicType type_;

eprosima::fastrtps::Participant* participant_;
eprosima::fastrtps::Publisher* publisher_;

class PubListener : public eprosima::fastrtps::PublisherListener
{
public:
PubListener()
: n_matched(0)
, first_connected(false)
{}

~PubListener()
{}

void onPublicationMatched(
eprosima::fastrtps::Publisher* pub,
eprosima::fastrtps::rtps::MatchingInfo& info) override;

void on_liveliness_lost(
eprosima::fastrtps::Publisher* pub,
const eprosima::fastrtps::LivelinessLostStatus& status) override;

int n_matched;
bool first_connected;
};
PubListener listener_;

void runThread(
eprosima::fastrtps::Publisher *pub,
uint32_t number,
uint32_t sleep);
};



#endif /* LivelinessPublisher_H_ */
Loading