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

[20592] Fix hidden overloaded virtual methods (backport #4516) #4592

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/workflows/reusable-ubuntu-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ jobs:
colcon_meta_file: ${{ github.workspace }}/src/fastrtps/.github/workflows/config/ci.meta
colcon_build_args: ${{ inputs.colcon-args }}
cmake_args: ${{ inputs.cmake-args }}
<<<<<<< HEAD
cmake_args_default: -DCMAKE_CXX_FLAGS="-Werror -Wall"
=======
cmake_args_default: -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused-value -Woverloaded-virtual" -DFASTDDS_EXAMPLE_TESTS=ON
>>>>>>> 63cc242b2 (Fix hidden overloaded virtual methods (#4516))
cmake_build_type: ${{ matrix.cmake-build-type }}
workspace: ${{ github.workspace }}

Expand Down
126 changes: 126 additions & 0 deletions examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2021 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 DiscoveryServerPublisher.h
*
*/

#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_
#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_

#include <atomic>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

#include "types/HelloWorldPubSubTypes.h"
#include "common.h"

/**
* Class used to group into a single working unit a Publisher with a DataWriter, its listener, and a TypeSupport member
* corresponding to the HelloWorld datatype
*/
class HelloWorldPublisher
{
public:

HelloWorldPublisher();

virtual ~HelloWorldPublisher();

//! Initialize the publisher
bool init(
const std::string& topic_name,
const std::string& server_address,
unsigned short server_port,
unsigned short server_id,
TransportKind transport);

//! Publish a sample
void publish();

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

//! Return the current state of execution
static bool is_stopped();

//! Trigger the end of execution
static void stop();

private:

HelloWorld hello_;

eprosima::fastdds::dds::DomainParticipant* participant_;

eprosima::fastdds::dds::Publisher* publisher_;

eprosima::fastdds::dds::Topic* topic_;

eprosima::fastdds::dds::DataWriter* writer_;

eprosima::fastdds::dds::TypeSupport type_;

/**
* Class handling discovery events
*/
class PubListener : public eprosima::fastdds::dds::DomainParticipantListener
{
public:

PubListener()
: matched_(0)
{
}

~PubListener() override
{
}

//! Callback executed when a DataReader is matched or unmatched
void on_publication_matched(
eprosima::fastdds::dds::DataWriter* writer,
const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;

//! Callback executed when a DomainParticipant is discovered, dropped or removed
void on_participant_discovery(
eprosima::fastdds::dds::DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;

private:

using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery;

//! Number of DataReaders matched to the associated DataWriter
std::atomic<std::uint32_t> matched_;
}
listener_;

//! Run thread for number samples, publish every sleep seconds
void runThread(
uint32_t number,
uint32_t sleep);

//! Member used for control flow purposes
static std::atomic<bool> stop_;
};



#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ */
106 changes: 106 additions & 0 deletions examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2021 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 DiscoveryServerServer.h
*
*/

#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_
#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_

#include <atomic>
#include <condition_variable>
#include <mutex>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>

#include "common.h"

/**
* Class with a partipant configured to function as server in the Discovery Server mechanism
*/
class DiscoveryServer
{
public:

DiscoveryServer();

virtual ~DiscoveryServer();

//! Initialize the server
bool init(
const std::string& server_address,
unsigned short server_port,
unsigned short server_id,
TransportKind transport,
bool has_connection_server,
const std::string& connection_server_address,
unsigned short connection_server_port,
unsigned short connection_server_id);

//! Run
void run(
unsigned int timeout);

//! Return the current state of execution
static bool is_stopped();

//! Trigger the end of execution
static void stop();

private:

eprosima::fastdds::dds::DomainParticipant* participant_;

/**
* Class handling discovery events
*/
class ServerListener : public eprosima::fastdds::dds::DomainParticipantListener
{
public:

ServerListener()
{
}

~ServerListener() override
{
}

//! Callback executed when a DomainParticipant is discovered, dropped or removed
void on_participant_discovery(
eprosima::fastdds::dds::DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;

private:

using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery;
}
listener_;

//! Member used for control flow purposes
static std::atomic<bool> stop_;

//! Protects terminate condition variable
static std::mutex terminate_cv_mtx_;

//! Waits during execution until SIGINT or max_messages_ samples are received
static std::condition_variable terminate_cv_;
};



#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ */
140 changes: 140 additions & 0 deletions examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2021 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 DiscoveryServerSubscriber.h
*
*/

#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_
#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_

#include <atomic>
#include <condition_variable>
#include <mutex>

#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>

#include "types/HelloWorldPubSubTypes.h"
#include "common.h"

/**
* Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member
* corresponding to the HelloWorld datatype
*/
class HelloWorldSubscriber
{
public:

HelloWorldSubscriber();

virtual ~HelloWorldSubscriber();

//! Initialize the subscriber
bool init(
const std::string& topic_name,
uint32_t max_messages,
const std::string& server_address,
unsigned short server_port,
unsigned short server_id,
TransportKind transport);

//! RUN the subscriber until number samples are received
void run(
uint32_t number);

//! Return the current state of execution
static bool is_stopped();

//! Trigger the end of execution
static void stop();

private:

eprosima::fastdds::dds::DomainParticipant* participant_;

eprosima::fastdds::dds::Subscriber* subscriber_;

eprosima::fastdds::dds::Topic* topic_;

eprosima::fastdds::dds::DataReader* reader_;

eprosima::fastdds::dds::TypeSupport type_;

/**
* Class handling discovery and dataflow events
*/
class SubListener : public eprosima::fastdds::dds::DomainParticipantListener
{
public:

SubListener()
: matched_(0)
, samples_(0)
, max_messages_(0)
{
}

~SubListener() override
{
}

//! Set the maximum number of messages to receive before exiting
void set_max_messages(
uint32_t max_messages);

//! Callback executed when a new sample is received
void on_data_available(
eprosima::fastdds::dds::DataReader* reader) override;

//! Callback executed when a DataWriter is matched or unmatched
void on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;

//! Callback executed when a DomainParticipant is discovered, dropped or removed
void on_participant_discovery(
eprosima::fastdds::dds::DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;

private:

using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery;

HelloWorld hello_;

//! Number of DataWriters matched to the associated DataReader
int matched_;

//! Number of samples received
uint32_t samples_;

//! Number of messages to be received before triggering termination of execution
uint32_t max_messages_;
}
listener_;

//! Member used for control flow purposes
static std::atomic<bool> stop_;

//! Protects terminate condition variable
static std::mutex terminate_cv_mtx_;

//! Waits during execution until SIGINT or max_messages_ samples are received
static std::condition_variable terminate_cv_;
};

#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ */
Loading