Commit a9be026c authored by 嵇洲's avatar 嵇洲

[示例demo]

parent 667ffa17
cmake_minimum_required(VERSION 3.20)
project("generated_code")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
# 添加 ./lib 到 CMAKE_PREFIX_PATH
message(STATUS ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS ${CMAKE_FRAMEWORK_PATH})
# set(fastcdr_DIR "/root/Fast-DDS/install/lib/cmake/fastcdr")
# set(foonathan_memory_DIR "/root/Fast-DDS/install/lib/foonathan_memory/cmake")
# set(fastdds_DIR "/root/Fast-DDS/install/share/fastdds/cmake")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastdds 3 REQUIRED)
if(fastdds_FOUND)
message(STATUS ${fastdds_VERSION})
message(STATUS ${fastdds_INCLUDE_DIRS})
message(STATUS ${fastdds_LIBRARIES})
else()
message(FATAL_ERROR "Could not find Fast DDS")
endif()
message(STATUS "Configuring test...")
# add_library(test_lib testTypeObjectSupport.cxx testPubSubTypes.cxx)
# target_link_libraries(test_lib fastcdr fastdds)
file(GLOB SOURCES src/*.cpp src/*.ipp src/*.cxx src/fastdds/*.cpp src/manager/*.cxx)
message(STATUS ${SOURCES})
add_executable(test ${SOURCES})
target_include_directories(test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(test fastcdr fastdds
)
// 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.
/*!
* @file IPCPublisher.hpp
* This header file contains the declaration of the publisher functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__IPCPublisher_HPP
#define FAST_DDS_GENERATED__IPCPublisher_HPP
#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>
#include "IPublisher.h"
#include "test.hpp"
#include <string>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
//#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.hpp>
#include "testPubSubTypes.hpp"
using namespace eprosima::fastdds::dds;
class IPCPublisherBase {
public:
virtual ~IPCPublisherBase() = default;
virtual void stop() = 0;
};
template<typename MessageT>
class IPCPublisher : public IPCPublisherBase, public eprosima::fastdds::dds::DataWriterListener
{
public:
IPCPublisher(const int& domain_id, const std::string& topicName) : factory_(nullptr)
, participant_(nullptr)
, publisher_(nullptr)
, topic_(nullptr)
, writer_(nullptr)
, type_(new typename MakePubSubType<MessageT>::Type)
, matched_(0)
, samples_sent_(0)
, stop_(false)
, topicName_(topicName) {
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("HelloSecurity_pub_participant");
factory_ = DomainParticipantFactory::get_shared_instance();
// PropertyPolicy property_policy;
// property_policy.properties().properties().emplace_back("fastrtps.transport", "SHM");
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("HelloSecurity Participant initialization failed");
}
// Register the type
type_.register_type(participant_);
// Create the publisher
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
participant_->get_default_publisher_qos(pub_qos);
publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none());
if (publisher_ == nullptr)
{
throw std::runtime_error("HelloSecurity Publisher initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic(topicName_, type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("HelloSecurity Topic initialization failed");
}
// Create the data writer
DataWriterQos writer_qos = 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_ALL_HISTORY_QOS;
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all());
if (writer_ == nullptr)
{
throw std::runtime_error("HelloSecurity DataWriter initialization failed");
}
};
~IPCPublisher() {}
//! Publisher matched method
void on_publication_matched(
eprosima::fastdds::dds::DataWriter* writer,
const eprosima::fastdds::dds::PublicationMatchedStatus& info) override {
if (info.current_count_change == 1) {
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << "HelloSecurity Publisher matched." << std::endl;
cv_.notify_one();
}
else if (info.current_count_change == -1)
{
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << "HelloSecurity Publisher unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for PublicationMatchedStatus current count change" << std::endl;
}
}
//! Run publisher
void run() {}
//! Trigger the end of execution
void stop() {
stop_.store(true);
cv_.notify_one();
}
std::string getTopic() const {
return topicName_;
}
//! Publish a sample
bool publish(const MessageT& msg) {
bool ret = false;
// Wait for the data endpoints discovery
std::unique_lock<std::mutex> matched_lock(mutex_);
cv_.wait(matched_lock, [&]()
{
// at least one has been discovered
return ((matched_ > 0) || is_stopped());
});
if (!is_stopped())
{
ret = (RETCODE_OK == writer_->write(&msg));
}
return ret;
}
private:
//! Return the current state of execution
bool is_stopped() {
return stop_.load();
}
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
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_;
std::condition_variable cv_;
int32_t matched_;
std::mutex mutex_;
const uint32_t period_ms_ = 100; // in ms
uint16_t samples_sent_;
std::atomic<bool> stop_;
std::string topicName_;
};
#endif // FAST_DDS_GENERATED__IPCPublisher_HPP
\ No newline at end of file
// 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.
/*!
* @file IPCSubscriber.hpp
* This header file contains the declaration of the subscriber functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__IPCSubscriber_HPP
#define FAST_DDS_GENERATED__IPCSubscriber_HPP
#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>
#include <string>
#include "test.hpp"
#include "IPublisher.h"
#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include "testPubSubTypes.hpp"
#include <type_traits>
using namespace eprosima::fastdds::dds;
class IPCSubscriberBase {
public:
virtual ~IPCSubscriberBase() = default;
virtual void stop() = 0;
};
template<typename MessageT>
class IPCSubscriber : public IPCSubscriberBase,
public eprosima::fastdds::dds::DataReaderListener
{
public:
//static_assert(has_register_type<MessageSubType>::value, "MessageSubType must have a register_type member function that takes a DomainParticipant");
// 订阅者数据接收回调
typedef std::function<void(const MessageT& sample)> IPCSubscriberDataCallBack;
//std::unique_ptr<typename MakePubSubType<MessageT>::Type> messageSubType_;
IPCSubscriber(const int& domain_id, const std::string& topicName): factory_(nullptr)
, participant_(nullptr)
, subscriber_(nullptr)
, topic_(nullptr)
, reader_(nullptr)
, type_(new typename MakePubSubType<MessageT>::Type)
//, type_(new OneMessagePubSubType)
, samples_received_(0)
, stop_(false)
,topicName_(topicName)
{
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("OneMessage_sub_participant");
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("HelloSecurity Participant initialization failed");
}
// Register the type
// MessageSubType* aa = new MessageSubType;
// type_ = *((eprosima::fastdds::dds::TypeSupport*)aa);
type_.register_type(participant_);
// Create the subscriber
SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT;
participant_->get_default_subscriber_qos(sub_qos);
subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none());
if (subscriber_ == nullptr)
{
throw std::runtime_error("HelloSecurity Subscriber initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic(topicName_, type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("HelloSecurity Topic initialization failed");
}
// Create the reader
DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT;
subscriber_->get_default_datareader_qos(reader_qos);
reader_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
reader_qos.history().kind = HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS;
reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all());
if (reader_ == nullptr)
{
throw std::runtime_error("HelloSecurity DataReader initialization failed");
}
}
virtual ~IPCSubscriber() {
if (nullptr != participant_)
{
// Delete DDS entities contained within the DomainParticipant
participant_->delete_contained_entities();
// Delete DomainParticipant
factory_->delete_participant(participant_);
}
}
//! Subscription callback
void on_data_available(
eprosima::fastdds::dds::DataReader* reader) override {
MessageT sample_;
SampleInfo info;
while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&sample_, &info)))
{
if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data)
{
//std::cout << "Sample '" << std::to_string(++samples_received_) << " RECEIVED " << sample_.securityData() << std::endl;
std::cout << "Sample '" << std::to_string(++samples_received_) << " RECEIVED " << std::endl;
if(m_callBack != nullptr) {
m_callBack(sample_);
}
}
}
}
//! Subscriber matched method
void on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override {
if (info.current_count_change == 1)
{
std::cout << "HelloSecurity Subscriber matched." << std::endl;
}
else if (info.current_count_change == -1)
{
std::cout << "HelloSecurity Subscriber unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl;
}
}
//! Run subscriber
void run(){
std::unique_lock<std::mutex> lck(terminate_cv_mtx_);
terminate_cv_.wait(lck, [this]
{
return is_stopped();
});
}
//! Trigger the end of execution
void stop() {
stop_.store(true);
terminate_cv_.notify_all();
}
void setDataHandler(IPCSubscriberDataCallBack callBack) {
m_callBack = callBack;
}
void startListen();
std::string getTopic() const {
return topicName_;
}
private:
IPCSubscriberDataCallBack m_callBack = nullptr;
//! Return the current state of execution
bool is_stopped() {
return stop_.load();
}
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
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_;
//MessageSubType type_;
uint16_t samples_received_;
std::atomic<bool> stop_;
mutable std::mutex terminate_cv_mtx_;
std::condition_variable terminate_cv_;
std::string topicName_;
};
#endif // FAST_DDS_GENERATED__IPCSubscriber_HPP
\ No newline at end of file
#ifndef FAST_DDS_GENERATED__IPublisher_HPP
#define FAST_DDS_GENERATED__IPublisher_HPP
#include <string>
#include "testPubSubTypes.hpp"
// 定义 PubSubType 模板类
template <typename T>
class PubSubType {
// 可以在这里添加一些通用的成员函数或数据成员
};
// 定义基础模板结构体,用于生成新的类型名称
template <typename T, typename = void>
struct MakePubSubType;
// 默认实现,可以抛出编译错误或提供默认类型
template <typename T>
struct MakePubSubType<T, void> {
using Type = void;
static_assert(std::is_void<Type>::value, "No appropriate MessageSubType found for MessageT");
};
// 特化 MakePubSubType 以关联 HelloSecurity 和 HelloSecurityPubSubType
template <>
struct MakePubSubType<HelloSecurity> {
using Type = HelloSecurityPubSubType;
};
template <>
struct MakePubSubType<OneMessage> {
using Type = OneMessagePubSubType;
};
// 抽象接口类,使用模板参数
template<typename T>
class IPublisher {
public:
virtual ~IPublisher() {}
virtual bool publish(const T& msg) = 0;
std::string topicName_;
std::string getTopic() const {
return topicName_;
}
virtual void stop() = 0;
};
#endif
\ No newline at end of file
// 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.
/*!
* @file testmain.cxx
* This file acts as a main entry point to the application.
*
* This file was generated by the tool fastddsgen.
*/
#include <csignal>
#include <cstring>
#include <functional>
#include <iostream>
#include <stdexcept>
#include <thread>
#include <chrono>
#include "test.hpp"
#include "manager/IPC.h"
using eprosima::fastdds::dds::Log;
volatile sig_atomic_t keep_running = 1;
std::function<void(int)> stop_handler;
void signal_handler(
int signum)
{
keep_running = 0;
stop_handler(signum);
}
std::string parse_signal(
const int& signum)
{
switch (signum)
{
case SIGINT:
return "SIGINT";
case SIGTERM:
return "SIGTERM";
#ifndef _WIN32
case SIGQUIT:
return "SIGQUIT";
case SIGHUP:
return "SIGHUP";
#endif // _WIN32
default:
return "UNKNOWN SIGNAL";
}
}
int main(
int argc,
char** argv)
{
eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Info);
// 获取日志输出的文件句柄,如果需要的话
// eprosima::fastdds::dds::Log::SetCategoryFilter(eprosima::fastdds::dds::Log::Kind::Info, "my_log_file.txt");
//EPROSIMA_LOG_INFO(TEST, "LOG INFO start 1 ...........");
auto ret = EXIT_SUCCESS;
int domain_id = 0;
if (argc != 2 || (strcmp(argv[1], "p") != 0 && strcmp(argv[1], "s") != 0))
{
std::cout << "Error: Incorrect arguments." << std::endl;
std::cout << "Usage: " << std::endl << std::endl;
std::cout << argv[0] << " publisher|subscriber" << std::endl << std::endl;
ret = EXIT_FAILURE;
}
else
{
// 发布者
if(strcmp(argv[1], "p") == 0) {
IPCPublisherInstance.createPublisher<HelloSecurity>("Topic1", 10);
IPCPublisherInstance.createPublisher<OneMessage>("Topic2", 10);
}
// 观察者
if(strcmp(argv[1], "s") == 0) {
auto commandSubscriber = IPCSubscriberInstance.createSubscriber<HelloSecurity>("Topic1", 10);
commandSubscriber->setDataHandler([](const HelloSecurity& sample){
cout << "---------------recv message: "<< sample.securityData() << endl;
});
auto commandSubscriber1 = IPCSubscriberInstance.createSubscriber<OneMessage>("Topic2", 0);
commandSubscriber1->setDataHandler([](const OneMessage& sample){
cout << "-------------recv message: a = " << sample.a() << " b = " << sample.b() <<
" --- vector size = " << sample.sequenceTest().size() << endl;
});
}
stop_handler = [&](int signum)
{
std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1]
<< " execution." << std::endl;
IPCPublisherInstance.stopAll();
IPCSubscriberInstance.stopAll();
};
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGHUP, signal_handler);
//thread.join();
}
while (keep_running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
if(strcmp(argv[1], "p") == 0) {
HelloSecurity msg;
msg.securityData("123456");
IPCPublisherInstance.getPublisherByTopic<HelloSecurity>("Topic1")->publish(msg);
OneMessage msg1;
msg1.a(1);
msg1.b(2);
std::vector<int16_t> vec{1,2,3,4,5};
msg1.sequenceTest(vec);
IPCPublisherInstance.getPublisherByTopic<OneMessage>("Topic2")->publish(msg1);
}
}
Log::Reset();
return ret;
}
/***
* @Description: 单例基类
* @Author: jizhou
* @Date: 2023-07-13 18:38:58
* @LastEditors: jizhou
* @LastEditTime: 2023-07-16 23:43:02
* @FilePath: /EnvironmentAccess/src/manager/BaseManager.h
*/
#ifndef FAST_DDS_GENERATED__BaseManager
#define FAST_DDS_GENERATED__BaseManager
template<class T>
class BaseManager {
public:
/***
* @brief: 默认构造函数
* @return {*}
*/
BaseManager() = default;
/***
* @brief: 默认析构函数
* @return {*}
*/
virtual ~BaseManager() = default;
/***
* @brief: 移动构造函数
* @return {*}
*/
BaseManager(T&&) = delete;
/***
* @brief: 赋值构造函数
* @return {*}
*/
BaseManager &operator=(const T&) = delete;
/***
* @brief: 拷贝构造函数
* @return {*}
*/
BaseManager(const T&) = delete;
/***
* @brief: 接引用函数
* @return {*}
*/
T* operator&() = delete;
/***
* @brief: 对外获取单例接口
* @return {*}
*/
static T& getInstance() {
static T instance;
return instance;
}
};
#endif
\ No newline at end of file
#include "IPCPublisherManager.h"
#include "IPCSubscriberManager.h"
auto& IPCPublisherInstance = IPCPublisherManager::getInstance();
auto& IPCSubscriberInstance = IPCSubscriberManager::getInstance();
\ No newline at end of file
/***
* @Description: 生产者管理类 内含3个不同主题发布者
* @Author: jizhou
* @Date: 2023-07-13 19:13:44
* @LastEditors: jizhou
* @LastEditTime: 2023-07-16 23:57:01
* @FilePath: /EnvironmentAccess/src/manager/IPCPublisherManager.h
*/
#ifndef FAST_DDS_GENERATED__IPCPublisherManager
#define FAST_DDS_GENERATED__IPCPublisherManager
#include <string>
#include "BaseManager.h"
#include "fastdds/IPCPublisher.h"
using namespace std;
class IPCPublisherManager : public BaseManager<IPCPublisherManager> {
private:
/***
* @brief: 构造函数
* @return {*}
*/
IPCPublisherManager() = default;
std::map<std::string, std::shared_ptr<IPCPublisherBase>> publishers_;
public:
/***
* @brief: 析构函数
* @return {*}
*/
~IPCPublisherManager() = default;
friend class BaseManager;
template<typename MessageT>
std::shared_ptr<IPCPublisher<MessageT>> createPublisher(const std::string& topic, size_t qos_profile_depth) {
auto publisher = std::make_shared<IPCPublisher<MessageT>>(0, topic);
publishers_[topic] = publisher;
return publisher;
}
template<typename MessageT>
std::shared_ptr<IPCPublisher<MessageT>> getPublisherByTopic(const std::string& topic) {
auto it = publishers_.find(topic);
if (it != publishers_.end()) {
return std::dynamic_pointer_cast<IPCPublisher<MessageT>>(it->second);
}
return nullptr;
}
//publish("topic",<T>xxxxx)
void stopAll() {
auto iter = publishers_.begin();
for(; iter!= publishers_.end(); iter++) {
iter->second->stop();
}
}
};
#endif
\ No newline at end of file
/***
* @Description: 生产者管理类 内含3个不同主题发布者
* @Author: jizhou
* @Date: 2023-07-13 19:13:44
* @LastEditors: jizhou
* @LastEditTime: 2023-07-16 23:57:01
* @FilePath: /EnvironmentAccess/src/manager/IPCSubscriberManager.h
*/
#ifndef FAST_DDS_GENERATED__IPCSubscriberManager
#define FAST_DDS_GENERATED__IPCSubscriberManager
#include <string>
#include "BaseManager.h"
#include "fastdds/IPCSubscriber.h"
using namespace std;
class IPCSubscriberManager : public BaseManager<IPCSubscriberManager> {
private:
/***
* @brief: 构造函数
* @return {*}
*/
IPCSubscriberManager() = default;
std::map<std::string, std::shared_ptr<IPCSubscriberBase>> subscribers_;
public:
/***
* @brief: 析构函数
* @return {*}
*/
~IPCSubscriberManager() = default;
friend class BaseManager;
template<typename MessageT>
std::shared_ptr<IPCSubscriber<MessageT>> createSubscriber(const std::string& topic, size_t qos_profile_depth) {
auto subscriber = std::make_shared<IPCSubscriber<MessageT>>(0, topic);
subscribers_[topic] = subscriber;
return subscriber;
}
template<typename MessageT>
std::shared_ptr<IPCSubscriber<MessageT>> get_subscriber_by_topic(const std::string& topic) {
auto it = subscribers_.find(topic);
if (it != subscribers_.end()) {
return std::dynamic_pointer_cast<IPCSubscriber<MessageT>>(it->second);
}
return nullptr;
}
void stopAll() {
auto iter = subscribers_.begin();
for(; iter!= subscribers_.end(); iter++) {
iter->second->stop();
}
}
};
#endif
\ No newline at end of file
This diff is collapsed.
// 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.
/*!
* @file testCdrAux.hpp
* This source file contains some definitions of CDR related functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__TESTCDRAUX_HPP
#define FAST_DDS_GENERATED__TESTCDRAUX_HPP
#include "test.hpp"
constexpr uint32_t HelloSecurity_max_cdr_typesize {264UL};
constexpr uint32_t HelloSecurity_max_key_cdr_typesize {0UL};
constexpr uint32_t TwoMessage_max_cdr_typesize {12UL};
constexpr uint32_t TwoMessage_max_key_cdr_typesize {0UL};
constexpr uint32_t OneMessage_max_cdr_typesize {16UL};
constexpr uint32_t OneMessage_max_key_cdr_typesize {0UL};
namespace eprosima {
namespace fastcdr {
class Cdr;
class CdrSizeCalculator;
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const HelloSecurity& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const OneMessage& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const TwoMessage& data);
} // namespace fastcdr
} // namespace eprosima
#endif // FAST_DDS_GENERATED__TESTCDRAUX_HPP
This diff is collapsed.
This diff is collapsed.
// 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.
/*!
* @file testPubSubTypes.hpp
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__TEST_PUBSUBTYPES_HPP
#define FAST_DDS_GENERATED__TEST_PUBSUBTYPES_HPP
#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/dds/topic/TopicDataType.hpp>
#include <fastdds/rtps/common/InstanceHandle.hpp>
#include <fastdds/rtps/common/SerializedPayload.hpp>
#include <fastdds/utils/md5.hpp>
#include "test.hpp"
#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3)
#error \
Generated test is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen.
#endif // FASTDDS_GEN_API_VER
/*!
* @brief This class represents the TopicDataType of the type HelloSecurity defined by the user in the IDL file.
* @ingroup test
*/
class HelloSecurityPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef HelloSecurity type;
eProsima_user_DllExport HelloSecurityPubSubType();
eProsima_user_DllExport ~HelloSecurityPubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
/*!
* @brief This class represents the TopicDataType of the type OneMessage defined by the user in the IDL file.
* @ingroup test
*/
class OneMessagePubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef OneMessage type;
eProsima_user_DllExport OneMessagePubSubType();
eProsima_user_DllExport ~OneMessagePubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
/*!
* @brief This class represents the TopicDataType of the type TwoMessage defined by the user in the IDL file.
* @ingroup test
*/
class TwoMessagePubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef TwoMessage type;
eProsima_user_DllExport TwoMessagePubSubType();
eProsima_user_DllExport ~TwoMessagePubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
#endif // FAST_DDS_GENERATED__TEST_PUBSUBTYPES_HPP
This diff is collapsed.
// 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.
/*!
* @file testTypeObjectSupport.hpp
* Header file containing the API required to register the TypeObject representation of the described types in the IDL file
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__TEST_TYPE_OBJECT_SUPPORT_HPP
#define FAST_DDS_GENERATED__TEST_TYPE_OBJECT_SUPPORT_HPP
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif // EPROSIMA_USER_DLL_EXPORT
#else
#define eProsima_user_DllExport
#endif // _WIN32
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
/**
* @brief Register HelloSecurity related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_HelloSecurity_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register OneMessage related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_OneMessage_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register TwoMessage related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_TwoMessage_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif // FAST_DDS_GENERATED__TEST_TYPE_OBJECT_SUPPORT_HPP
struct HelloSecurity
{
string securityData;
};
struct OneMessage
{
short a;
float b;
sequence<short> sequenceTest;
};
struct TwoMessage
{
sequence<short> sequenceTest;
map<char, unsigned long long> mapTest;
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment