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
// 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 test.hpp
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__TEST_HPP
#define FAST_DDS_GENERATED__TEST_HPP
#include <cstdint>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <fastcdr/cdr/fixed_size_string.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
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(TEST_SOURCE)
#define TEST_DllAPI __declspec( dllexport )
#else
#define TEST_DllAPI __declspec( dllimport )
#endif // TEST_SOURCE
#else
#define TEST_DllAPI
#endif // EPROSIMA_USER_DLL_EXPORT
#else
#define TEST_DllAPI
#endif // _WIN32
/*!
* @brief This class represents the structure HelloSecurity defined by the user in the IDL file.
* @ingroup test
*/
class HelloSecurity
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport HelloSecurity()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~HelloSecurity()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object HelloSecurity that will be copied.
*/
eProsima_user_DllExport HelloSecurity(
const HelloSecurity& x)
{
m_securityData = x.m_securityData;
}
/*!
* @brief Move constructor.
* @param x Reference to the object HelloSecurity that will be copied.
*/
eProsima_user_DllExport HelloSecurity(
HelloSecurity&& x) noexcept
{
m_securityData = std::move(x.m_securityData);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object HelloSecurity that will be copied.
*/
eProsima_user_DllExport HelloSecurity& operator =(
const HelloSecurity& x)
{
m_securityData = x.m_securityData;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object HelloSecurity that will be copied.
*/
eProsima_user_DllExport HelloSecurity& operator =(
HelloSecurity&& x) noexcept
{
m_securityData = std::move(x.m_securityData);
return *this;
}
/*!
* @brief Comparison operator.
* @param x HelloSecurity object to compare.
*/
eProsima_user_DllExport bool operator ==(
const HelloSecurity& x) const
{
return (m_securityData == x.m_securityData);
}
/*!
* @brief Comparison operator.
* @param x HelloSecurity object to compare.
*/
eProsima_user_DllExport bool operator !=(
const HelloSecurity& x) const
{
return !(*this == x);
}
/*!
* @brief This function copies the value in member securityData
* @param _securityData New value to be copied in member securityData
*/
eProsima_user_DllExport void securityData(
const std::string& _securityData)
{
m_securityData = _securityData;
}
/*!
* @brief This function moves the value in member securityData
* @param _securityData New value to be moved in member securityData
*/
eProsima_user_DllExport void securityData(
std::string&& _securityData)
{
m_securityData = std::move(_securityData);
}
/*!
* @brief This function returns a constant reference to member securityData
* @return Constant reference to member securityData
*/
eProsima_user_DllExport const std::string& securityData() const
{
return m_securityData;
}
/*!
* @brief This function returns a reference to member securityData
* @return Reference to member securityData
*/
eProsima_user_DllExport std::string& securityData()
{
return m_securityData;
}
private:
std::string m_securityData;
};
/*!
* @brief This class represents the structure OneMessage defined by the user in the IDL file.
* @ingroup test
*/
class OneMessage
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport OneMessage()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~OneMessage()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object OneMessage that will be copied.
*/
eProsima_user_DllExport OneMessage(
const OneMessage& x)
{
m_a = x.m_a;
m_b = x.m_b;
m_sequenceTest = x.m_sequenceTest;
}
/*!
* @brief Move constructor.
* @param x Reference to the object OneMessage that will be copied.
*/
eProsima_user_DllExport OneMessage(
OneMessage&& x) noexcept
{
m_a = x.m_a;
m_b = x.m_b;
m_sequenceTest = std::move(x.m_sequenceTest);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object OneMessage that will be copied.
*/
eProsima_user_DllExport OneMessage& operator =(
const OneMessage& x)
{
m_a = x.m_a;
m_b = x.m_b;
m_sequenceTest = x.m_sequenceTest;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object OneMessage that will be copied.
*/
eProsima_user_DllExport OneMessage& operator =(
OneMessage&& x) noexcept
{
m_a = x.m_a;
m_b = x.m_b;
m_sequenceTest = std::move(x.m_sequenceTest);
return *this;
}
/*!
* @brief Comparison operator.
* @param x OneMessage object to compare.
*/
eProsima_user_DllExport bool operator ==(
const OneMessage& x) const
{
return (m_a == x.m_a &&
m_b == x.m_b &&
m_sequenceTest == x.m_sequenceTest);
}
/*!
* @brief Comparison operator.
* @param x OneMessage object to compare.
*/
eProsima_user_DllExport bool operator !=(
const OneMessage& x) const
{
return !(*this == x);
}
/*!
* @brief This function sets a value in member a
* @param _a New value for member a
*/
eProsima_user_DllExport void a(
int16_t _a)
{
m_a = _a;
}
/*!
* @brief This function returns the value of member a
* @return Value of member a
*/
eProsima_user_DllExport int16_t a() const
{
return m_a;
}
/*!
* @brief This function returns a reference to member a
* @return Reference to member a
*/
eProsima_user_DllExport int16_t& a()
{
return m_a;
}
/*!
* @brief This function sets a value in member b
* @param _b New value for member b
*/
eProsima_user_DllExport void b(
float _b)
{
m_b = _b;
}
/*!
* @brief This function returns the value of member b
* @return Value of member b
*/
eProsima_user_DllExport float b() const
{
return m_b;
}
/*!
* @brief This function returns a reference to member b
* @return Reference to member b
*/
eProsima_user_DllExport float& b()
{
return m_b;
}
/*!
* @brief This function copies the value in member sequenceTest
* @param _sequenceTest New value to be copied in member sequenceTest
*/
eProsima_user_DllExport void sequenceTest(
const std::vector<int16_t>& _sequenceTest)
{
m_sequenceTest = _sequenceTest;
}
/*!
* @brief This function moves the value in member sequenceTest
* @param _sequenceTest New value to be moved in member sequenceTest
*/
eProsima_user_DllExport void sequenceTest(
std::vector<int16_t>&& _sequenceTest)
{
m_sequenceTest = std::move(_sequenceTest);
}
/*!
* @brief This function returns a constant reference to member sequenceTest
* @return Constant reference to member sequenceTest
*/
eProsima_user_DllExport const std::vector<int16_t>& sequenceTest() const
{
return m_sequenceTest;
}
/*!
* @brief This function returns a reference to member sequenceTest
* @return Reference to member sequenceTest
*/
eProsima_user_DllExport std::vector<int16_t>& sequenceTest()
{
return m_sequenceTest;
}
private:
int16_t m_a{0};
float m_b{0.0};
std::vector<int16_t> m_sequenceTest;
};
/*!
* @brief This class represents the structure TwoMessage defined by the user in the IDL file.
* @ingroup test
*/
class TwoMessage
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport TwoMessage()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~TwoMessage()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object TwoMessage that will be copied.
*/
eProsima_user_DllExport TwoMessage(
const TwoMessage& x)
{
m_sequenceTest = x.m_sequenceTest;
m_mapTest = x.m_mapTest;
}
/*!
* @brief Move constructor.
* @param x Reference to the object TwoMessage that will be copied.
*/
eProsima_user_DllExport TwoMessage(
TwoMessage&& x) noexcept
{
m_sequenceTest = std::move(x.m_sequenceTest);
m_mapTest = std::move(x.m_mapTest);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object TwoMessage that will be copied.
*/
eProsima_user_DllExport TwoMessage& operator =(
const TwoMessage& x)
{
m_sequenceTest = x.m_sequenceTest;
m_mapTest = x.m_mapTest;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object TwoMessage that will be copied.
*/
eProsima_user_DllExport TwoMessage& operator =(
TwoMessage&& x) noexcept
{
m_sequenceTest = std::move(x.m_sequenceTest);
m_mapTest = std::move(x.m_mapTest);
return *this;
}
/*!
* @brief Comparison operator.
* @param x TwoMessage object to compare.
*/
eProsima_user_DllExport bool operator ==(
const TwoMessage& x) const
{
return (m_sequenceTest == x.m_sequenceTest &&
m_mapTest == x.m_mapTest);
}
/*!
* @brief Comparison operator.
* @param x TwoMessage object to compare.
*/
eProsima_user_DllExport bool operator !=(
const TwoMessage& x) const
{
return !(*this == x);
}
/*!
* @brief This function copies the value in member sequenceTest
* @param _sequenceTest New value to be copied in member sequenceTest
*/
eProsima_user_DllExport void sequenceTest(
const std::vector<int16_t>& _sequenceTest)
{
m_sequenceTest = _sequenceTest;
}
/*!
* @brief This function moves the value in member sequenceTest
* @param _sequenceTest New value to be moved in member sequenceTest
*/
eProsima_user_DllExport void sequenceTest(
std::vector<int16_t>&& _sequenceTest)
{
m_sequenceTest = std::move(_sequenceTest);
}
/*!
* @brief This function returns a constant reference to member sequenceTest
* @return Constant reference to member sequenceTest
*/
eProsima_user_DllExport const std::vector<int16_t>& sequenceTest() const
{
return m_sequenceTest;
}
/*!
* @brief This function returns a reference to member sequenceTest
* @return Reference to member sequenceTest
*/
eProsima_user_DllExport std::vector<int16_t>& sequenceTest()
{
return m_sequenceTest;
}
/*!
* @brief This function copies the value in member mapTest
* @param _mapTest New value to be copied in member mapTest
*/
eProsima_user_DllExport void mapTest(
const std::map<char, uint64_t>& _mapTest)
{
m_mapTest = _mapTest;
}
/*!
* @brief This function moves the value in member mapTest
* @param _mapTest New value to be moved in member mapTest
*/
eProsima_user_DllExport void mapTest(
std::map<char, uint64_t>&& _mapTest)
{
m_mapTest = std::move(_mapTest);
}
/*!
* @brief This function returns a constant reference to member mapTest
* @return Constant reference to member mapTest
*/
eProsima_user_DllExport const std::map<char, uint64_t>& mapTest() const
{
return m_mapTest;
}
/*!
* @brief This function returns a reference to member mapTest
* @return Reference to member mapTest
*/
eProsima_user_DllExport std::map<char, uint64_t>& mapTest()
{
return m_mapTest;
}
private:
std::vector<int16_t> m_sequenceTest;
std::map<char, uint64_t> m_mapTest;
};
#endif // _FAST_DDS_GENERATED_TEST_HPP_
// 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
// 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.ipp
* This source file contains some declarations of CDR related functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__TESTCDRAUX_IPP
#define FAST_DDS_GENERATED__TESTCDRAUX_IPP
#include "testCdrAux.hpp"
#include <fastcdr/Cdr.h>
#include <fastcdr/CdrSizeCalculator.hpp>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
namespace eprosima {
namespace fastcdr {
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const HelloSecurity& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.securityData(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const HelloSecurity& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.securityData()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
HelloSecurity& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.securityData();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const HelloSecurity& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.securityData();
}
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const OneMessage& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.a(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.b(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2),
data.sequenceTest(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const OneMessage& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.a()
<< eprosima::fastcdr::MemberId(1) << data.b()
<< eprosima::fastcdr::MemberId(2) << data.sequenceTest()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
OneMessage& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.a();
break;
case 1:
dcdr >> data.b();
break;
case 2:
dcdr >> data.sequenceTest();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const OneMessage& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.a();
scdr << data.b();
scdr << data.sequenceTest();
}
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const TwoMessage& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.sequenceTest(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.mapTest(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const TwoMessage& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.sequenceTest()
<< eprosima::fastcdr::MemberId(1) << data.mapTest()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
TwoMessage& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.sequenceTest();
break;
case 1:
dcdr >> data.mapTest();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const TwoMessage& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.sequenceTest();
scdr << data.mapTest();
}
} // namespace fastcdr
} // namespace eprosima
#endif // FAST_DDS_GENERATED__TESTCDRAUX_IPP
// 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.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastddsgen.
*/
#include "testPubSubTypes.hpp"
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/common/CdrSerialization.hpp>
#include "testCdrAux.hpp"
#include "testTypeObjectSupport.hpp"
using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t;
using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t;
using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t;
HelloSecurityPubSubType::HelloSecurityPubSubType()
{
set_name("HelloSecurity");
uint32_t type_size = HelloSecurity_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = HelloSecurity_max_key_cdr_typesize > 16 ? HelloSecurity_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
HelloSecurityPubSubType::~HelloSecurityPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool HelloSecurityPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const HelloSecurity* p_type = static_cast<const HelloSecurity*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool HelloSecurityPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
HelloSecurity* p_type = static_cast<HelloSecurity*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t HelloSecurityPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const HelloSecurity*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* HelloSecurityPubSubType::create_data()
{
return reinterpret_cast<void*>(new HelloSecurity());
}
void HelloSecurityPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<HelloSecurity*>(data));
}
bool HelloSecurityPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
HelloSecurity data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool HelloSecurityPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const HelloSecurity* p_type = static_cast<const HelloSecurity*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
HelloSecurity_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || HelloSecurity_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void HelloSecurityPubSubType::register_type_object_representation()
{
register_HelloSecurity_type_identifier(type_identifiers_);
}
OneMessagePubSubType::OneMessagePubSubType()
{
set_name("OneMessage");
uint32_t type_size = OneMessage_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = OneMessage_max_key_cdr_typesize > 16 ? OneMessage_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
OneMessagePubSubType::~OneMessagePubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool OneMessagePubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const OneMessage* p_type = static_cast<const OneMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool OneMessagePubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
OneMessage* p_type = static_cast<OneMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t OneMessagePubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const OneMessage*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* OneMessagePubSubType::create_data()
{
return reinterpret_cast<void*>(new OneMessage());
}
void OneMessagePubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<OneMessage*>(data));
}
bool OneMessagePubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
OneMessage data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool OneMessagePubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const OneMessage* p_type = static_cast<const OneMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
OneMessage_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || OneMessage_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void OneMessagePubSubType::register_type_object_representation()
{
register_OneMessage_type_identifier(type_identifiers_);
}
TwoMessagePubSubType::TwoMessagePubSubType()
{
set_name("TwoMessage");
uint32_t type_size = TwoMessage_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = TwoMessage_max_key_cdr_typesize > 16 ? TwoMessage_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
TwoMessagePubSubType::~TwoMessagePubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool TwoMessagePubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const TwoMessage* p_type = static_cast<const TwoMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool TwoMessagePubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
TwoMessage* p_type = static_cast<TwoMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t TwoMessagePubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const TwoMessage*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* TwoMessagePubSubType::create_data()
{
return reinterpret_cast<void*>(new TwoMessage());
}
void TwoMessagePubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<TwoMessage*>(data));
}
bool TwoMessagePubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
TwoMessage data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool TwoMessagePubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const TwoMessage* p_type = static_cast<const TwoMessage*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
TwoMessage_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || TwoMessage_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void TwoMessagePubSubType::register_type_object_representation()
{
register_TwoMessage_type_identifier(type_identifiers_);
}
// Include auxiliary functions like for serializing/deserializing.
#include "testCdrAux.ipp"
// 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
// 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.cxx
* Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
*
* This file was generated by the tool fastddsgen.
*/
#include "testTypeObjectSupport.hpp"
#include <mutex>
#include <string>
#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
#include "test.hpp"
using namespace eprosima::fastdds::dds::xtypes;
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_HelloSecurity_type_identifier(
TypeIdentifierPair& type_ids_HelloSecurity)
{
ReturnCode_t return_code_HelloSecurity {eprosima::fastdds::dds::RETCODE_OK};
return_code_HelloSecurity =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"HelloSecurity", type_ids_HelloSecurity);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloSecurity)
{
StructTypeFlag struct_flags_HelloSecurity = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_HelloSecurity = "HelloSecurity";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_HelloSecurity;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_HelloSecurity;
CompleteTypeDetail detail_HelloSecurity = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloSecurity, ann_custom_HelloSecurity, type_name_HelloSecurity.to_string());
CompleteStructHeader header_HelloSecurity;
header_HelloSecurity = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloSecurity);
CompleteStructMemberSeq member_seq_HelloSecurity;
{
TypeIdentifierPair type_ids_securityData;
ReturnCode_t return_code_securityData {eprosima::fastdds::dds::RETCODE_OK};
return_code_securityData =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_securityData);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_securityData)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_securityData))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_securityData = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_securityData = 0x00000000;
bool common_securityData_ec {false};
CommonStructMember common_securityData {TypeObjectUtils::build_common_struct_member(member_id_securityData, member_flags_securityData, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_securityData, common_securityData_ec))};
if (!common_securityData_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure securityData member TypeIdentifier inconsistent.");
return;
}
MemberName name_securityData = "securityData";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_securityData;
ann_custom_HelloSecurity.reset();
CompleteMemberDetail detail_securityData = TypeObjectUtils::build_complete_member_detail(name_securityData, member_ann_builtin_securityData, ann_custom_HelloSecurity);
CompleteStructMember member_securityData = TypeObjectUtils::build_complete_struct_member(common_securityData, detail_securityData);
TypeObjectUtils::add_complete_struct_member(member_seq_HelloSecurity, member_securityData);
}
CompleteStructType struct_type_HelloSecurity = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloSecurity, header_HelloSecurity, member_seq_HelloSecurity);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloSecurity, type_name_HelloSecurity.to_string(), type_ids_HelloSecurity))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"HelloSecurity already registered in TypeObjectRegistry for a different type.");
}
}
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_OneMessage_type_identifier(
TypeIdentifierPair& type_ids_OneMessage)
{
ReturnCode_t return_code_OneMessage {eprosima::fastdds::dds::RETCODE_OK};
return_code_OneMessage =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"OneMessage", type_ids_OneMessage);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_OneMessage)
{
StructTypeFlag struct_flags_OneMessage = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_OneMessage = "OneMessage";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_OneMessage;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_OneMessage;
CompleteTypeDetail detail_OneMessage = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_OneMessage, ann_custom_OneMessage, type_name_OneMessage.to_string());
CompleteStructHeader header_OneMessage;
header_OneMessage = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_OneMessage);
CompleteStructMemberSeq member_seq_OneMessage;
{
TypeIdentifierPair type_ids_a;
ReturnCode_t return_code_a {eprosima::fastdds::dds::RETCODE_OK};
return_code_a =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_int16_t", type_ids_a);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_a)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"a Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_a = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_a = 0x00000000;
bool common_a_ec {false};
CommonStructMember common_a {TypeObjectUtils::build_common_struct_member(member_id_a, member_flags_a, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_a, common_a_ec))};
if (!common_a_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure a member TypeIdentifier inconsistent.");
return;
}
MemberName name_a = "a";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_a;
ann_custom_OneMessage.reset();
CompleteMemberDetail detail_a = TypeObjectUtils::build_complete_member_detail(name_a, member_ann_builtin_a, ann_custom_OneMessage);
CompleteStructMember member_a = TypeObjectUtils::build_complete_struct_member(common_a, detail_a);
TypeObjectUtils::add_complete_struct_member(member_seq_OneMessage, member_a);
}
{
TypeIdentifierPair type_ids_b;
ReturnCode_t return_code_b {eprosima::fastdds::dds::RETCODE_OK};
return_code_b =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_float", type_ids_b);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_b)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"b Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_b = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_b = 0x00000001;
bool common_b_ec {false};
CommonStructMember common_b {TypeObjectUtils::build_common_struct_member(member_id_b, member_flags_b, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_b, common_b_ec))};
if (!common_b_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure b member TypeIdentifier inconsistent.");
return;
}
MemberName name_b = "b";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_b;
ann_custom_OneMessage.reset();
CompleteMemberDetail detail_b = TypeObjectUtils::build_complete_member_detail(name_b, member_ann_builtin_b, ann_custom_OneMessage);
CompleteStructMember member_b = TypeObjectUtils::build_complete_struct_member(common_b, detail_b);
TypeObjectUtils::add_complete_struct_member(member_seq_OneMessage, member_b);
}
{
TypeIdentifierPair type_ids_sequenceTest;
ReturnCode_t return_code_sequenceTest {eprosima::fastdds::dds::RETCODE_OK};
return_code_sequenceTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_sequence_int16_t_unbounded", type_ids_sequenceTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_sequenceTest)
{
return_code_sequenceTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_int16_t", type_ids_sequenceTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_sequenceTest)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Sequence element TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
bool element_identifier_anonymous_sequence_int16_t_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_sequence_int16_t_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sequenceTest, element_identifier_anonymous_sequence_int16_t_unbounded_ec))};
if (!element_identifier_anonymous_sequence_int16_t_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
return;
}
EquivalenceKind equiv_kind_anonymous_sequence_int16_t_unbounded = EK_COMPLETE;
if (TK_NONE == type_ids_sequenceTest.type_identifier2()._d())
{
equiv_kind_anonymous_sequence_int16_t_unbounded = EK_BOTH;
}
CollectionElementFlag element_flags_anonymous_sequence_int16_t_unbounded = 0;
PlainCollectionHeader header_anonymous_sequence_int16_t_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_int16_t_unbounded, element_flags_anonymous_sequence_int16_t_unbounded);
{
SBound bound = 0;
PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_int16_t_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_int16_t_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_int16_t_unbounded", type_ids_sequenceTest))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_sequence_int16_t_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_sequenceTest = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_sequenceTest = 0x00000002;
bool common_sequenceTest_ec {false};
CommonStructMember common_sequenceTest {TypeObjectUtils::build_common_struct_member(member_id_sequenceTest, member_flags_sequenceTest, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sequenceTest, common_sequenceTest_ec))};
if (!common_sequenceTest_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure sequenceTest member TypeIdentifier inconsistent.");
return;
}
MemberName name_sequenceTest = "sequenceTest";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_sequenceTest;
ann_custom_OneMessage.reset();
CompleteMemberDetail detail_sequenceTest = TypeObjectUtils::build_complete_member_detail(name_sequenceTest, member_ann_builtin_sequenceTest, ann_custom_OneMessage);
CompleteStructMember member_sequenceTest = TypeObjectUtils::build_complete_struct_member(common_sequenceTest, detail_sequenceTest);
TypeObjectUtils::add_complete_struct_member(member_seq_OneMessage, member_sequenceTest);
}
CompleteStructType struct_type_OneMessage = TypeObjectUtils::build_complete_struct_type(struct_flags_OneMessage, header_OneMessage, member_seq_OneMessage);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_OneMessage, type_name_OneMessage.to_string(), type_ids_OneMessage))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"OneMessage already registered in TypeObjectRegistry for a different type.");
}
}
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_TwoMessage_type_identifier(
TypeIdentifierPair& type_ids_TwoMessage)
{
ReturnCode_t return_code_TwoMessage {eprosima::fastdds::dds::RETCODE_OK};
return_code_TwoMessage =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"TwoMessage", type_ids_TwoMessage);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_TwoMessage)
{
StructTypeFlag struct_flags_TwoMessage = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_TwoMessage = "TwoMessage";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_TwoMessage;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_TwoMessage;
CompleteTypeDetail detail_TwoMessage = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_TwoMessage, ann_custom_TwoMessage, type_name_TwoMessage.to_string());
CompleteStructHeader header_TwoMessage;
header_TwoMessage = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_TwoMessage);
CompleteStructMemberSeq member_seq_TwoMessage;
{
TypeIdentifierPair type_ids_sequenceTest;
ReturnCode_t return_code_sequenceTest {eprosima::fastdds::dds::RETCODE_OK};
return_code_sequenceTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_sequence_int16_t_unbounded", type_ids_sequenceTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_sequenceTest)
{
return_code_sequenceTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_int16_t", type_ids_sequenceTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_sequenceTest)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Sequence element TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
bool element_identifier_anonymous_sequence_int16_t_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_sequence_int16_t_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sequenceTest, element_identifier_anonymous_sequence_int16_t_unbounded_ec))};
if (!element_identifier_anonymous_sequence_int16_t_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
return;
}
EquivalenceKind equiv_kind_anonymous_sequence_int16_t_unbounded = EK_COMPLETE;
if (TK_NONE == type_ids_sequenceTest.type_identifier2()._d())
{
equiv_kind_anonymous_sequence_int16_t_unbounded = EK_BOTH;
}
CollectionElementFlag element_flags_anonymous_sequence_int16_t_unbounded = 0;
PlainCollectionHeader header_anonymous_sequence_int16_t_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_int16_t_unbounded, element_flags_anonymous_sequence_int16_t_unbounded);
{
SBound bound = 0;
PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_int16_t_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_int16_t_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_int16_t_unbounded", type_ids_sequenceTest))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_sequence_int16_t_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_sequenceTest = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_sequenceTest = 0x00000000;
bool common_sequenceTest_ec {false};
CommonStructMember common_sequenceTest {TypeObjectUtils::build_common_struct_member(member_id_sequenceTest, member_flags_sequenceTest, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sequenceTest, common_sequenceTest_ec))};
if (!common_sequenceTest_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure sequenceTest member TypeIdentifier inconsistent.");
return;
}
MemberName name_sequenceTest = "sequenceTest";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_sequenceTest;
ann_custom_TwoMessage.reset();
CompleteMemberDetail detail_sequenceTest = TypeObjectUtils::build_complete_member_detail(name_sequenceTest, member_ann_builtin_sequenceTest, ann_custom_TwoMessage);
CompleteStructMember member_sequenceTest = TypeObjectUtils::build_complete_struct_member(common_sequenceTest, detail_sequenceTest);
TypeObjectUtils::add_complete_struct_member(member_seq_TwoMessage, member_sequenceTest);
}
{
TypeIdentifierPair type_ids_mapTest;
ReturnCode_t return_code_mapTest {eprosima::fastdds::dds::RETCODE_OK};
return_code_mapTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_map_char_uint64_t_unbounded", type_ids_mapTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_mapTest)
{
return_code_mapTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint64_t", type_ids_mapTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_mapTest)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Map element TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
bool element_identifier_anonymous_map_char_uint64_t_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_map_char_uint64_t_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_mapTest, element_identifier_anonymous_map_char_uint64_t_unbounded_ec))};
if (!element_identifier_anonymous_map_char_uint64_t_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_char_uint64_t_unbounded inconsistent element TypeIdentifier.");
return;
}
return_code_mapTest =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_char", type_ids_mapTest);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_mapTest)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Map key TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
bool key_identifier_anonymous_map_char_uint64_t_unbounded_ec {false};
TypeIdentifier* key_identifier_anonymous_map_char_uint64_t_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_mapTest, key_identifier_anonymous_map_char_uint64_t_unbounded_ec))};
if (!key_identifier_anonymous_map_char_uint64_t_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_char_uint64_t_unbounded inconsistent key TypeIdentifier.");
return;
}
EquivalenceKind equiv_kind_anonymous_map_char_uint64_t_unbounded = EK_BOTH;
if ((EK_COMPLETE == key_identifier_anonymous_map_char_uint64_t_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->_d()) ||
(TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->map_sdefn().header().equiv_kind())) ||
(TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_char_uint64_t_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_char_uint64_t_unbounded->map_ldefn().header().equiv_kind())))
{
equiv_kind_anonymous_map_char_uint64_t_unbounded = EK_COMPLETE;
}
CollectionElementFlag element_flags_anonymous_map_char_uint64_t_unbounded = 0;
CollectionElementFlag key_flags_anonymous_map_char_uint64_t_unbounded = 0;
PlainCollectionHeader header_anonymous_map_char_uint64_t_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_char_uint64_t_unbounded, element_flags_anonymous_map_char_uint64_t_unbounded);
{
SBound bound = 0;
PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_char_uint64_t_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_map_char_uint64_t_unbounded), key_flags_anonymous_map_char_uint64_t_unbounded,
eprosima::fastcdr::external<TypeIdentifier>(key_identifier_anonymous_map_char_uint64_t_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_char_uint64_t_unbounded", type_ids_mapTest))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_char_uint64_t_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_mapTest = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_mapTest = 0x00000001;
bool common_mapTest_ec {false};
CommonStructMember common_mapTest {TypeObjectUtils::build_common_struct_member(member_id_mapTest, member_flags_mapTest, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_mapTest, common_mapTest_ec))};
if (!common_mapTest_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure mapTest member TypeIdentifier inconsistent.");
return;
}
MemberName name_mapTest = "mapTest";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_mapTest;
ann_custom_TwoMessage.reset();
CompleteMemberDetail detail_mapTest = TypeObjectUtils::build_complete_member_detail(name_mapTest, member_ann_builtin_mapTest, ann_custom_TwoMessage);
CompleteStructMember member_mapTest = TypeObjectUtils::build_complete_struct_member(common_mapTest, detail_mapTest);
TypeObjectUtils::add_complete_struct_member(member_seq_TwoMessage, member_mapTest);
}
CompleteStructType struct_type_TwoMessage = TypeObjectUtils::build_complete_struct_type(struct_flags_TwoMessage, header_TwoMessage, member_seq_TwoMessage);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_TwoMessage, type_name_TwoMessage.to_string(), type_ids_TwoMessage))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"TwoMessage already registered in TypeObjectRegistry for a different type.");
}
}
}
// 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