From 64c3803607f166a13345e9d8d5be6ff9e3441239 Mon Sep 17 00:00:00 2001 From: baocm Date: Fri, 9 Jan 2026 14:23:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=BB=BAdemo=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + CMakeLists.txt | 45 ++++ demo/Publisher.cxx | 187 ++++++++++++++ demo/Publisher.hpp | 74 ++++++ demo/Subscriber.cxx | 159 ++++++++++++ demo/Subscriber.hpp | 75 ++++++ demo/main.cxx | 161 ++++++++++++ lib/System.hpp | 425 ++++++++++++++++++++++++++++++++ lib/System.idl | 13 + lib/SystemCdrAux.hpp | 53 ++++ lib/SystemCdrAux.ipp | 230 +++++++++++++++++ lib/SystemPubSubTypes.cxx | 400 ++++++++++++++++++++++++++++++ lib/SystemPubSubTypes.hpp | 204 +++++++++++++++ lib/SystemTypeObjectSupport.cxx | 331 +++++++++++++++++++++++++ lib/SystemTypeObjectSupport.hpp | 68 +++++ 15 files changed, 2427 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 demo/Publisher.cxx create mode 100644 demo/Publisher.hpp create mode 100644 demo/Subscriber.cxx create mode 100644 demo/Subscriber.hpp create mode 100644 demo/main.cxx create mode 100644 lib/System.hpp create mode 100644 lib/System.idl create mode 100644 lib/SystemCdrAux.hpp create mode 100644 lib/SystemCdrAux.ipp create mode 100644 lib/SystemPubSubTypes.cxx create mode 100644 lib/SystemPubSubTypes.hpp create mode 100644 lib/SystemTypeObjectSupport.cxx create mode 100644 lib/SystemTypeObjectSupport.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e524d79 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8692f3f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ + +cmake_minimum_required(VERSION 3.20) + +project("system") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(fastcdr_DIR "/opt/fastdds/v3.2.2/lib/cmake/fastcdr") +set(fastdds_DIR "/opt/fastdds/v3.2.2/share/fastdds/cmake") +set(foonathan_memory_DIR "/opt/foonathan_memory/lib/foonathan_memory/cmake") + +# Find requirements +find_package(fastcdr REQUIRED) +find_package(fastdds 3 REQUIRED) + +# Set CMAKE_BUILD_TYPE to Release by default. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +include_directories(common) +include_directories(lib) + +message(STATUS "Configuring System...") +add_library(System_lib lib/SystemTypeObjectSupport.cxx lib/SystemPubSubTypes.cxx) +target_link_libraries(System_lib fastcdr fastdds) + +# Demo Application. +add_executable(Demo + demo/main.cxx + demo/Publisher.cxx + demo/Subscriber.cxx + ) +target_include_directories(Demo PRIVATE demo) +target_link_libraries(Demo fastcdr fastdds + System_lib + ) + + + diff --git a/demo/Publisher.cxx b/demo/Publisher.cxx new file mode 100644 index 0000000..7045623 --- /dev/null +++ b/demo/Publisher.cxx @@ -0,0 +1,187 @@ +// 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 Publisher.cxx + * This file contains the implementation of the publisher functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "Publisher.hpp" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "SystemPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; + +PublisherApp::PublisherApp( + const int& domain_id) + : factory_(nullptr) + , participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , type_(new WeighRspPubSubType()) + , matched_(0) + , samples_sent_(0) + , stop_(false) +{ + // + + // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; + pqos.name("Weigh_pub_participant"); + pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0); + pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0); + factory_ = DomainParticipantFactory::get_shared_instance(); + participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none()); + if (participant_ == nullptr) + { + throw std::runtime_error("WeighRsp 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("WeighRsp Publisher initialization failed"); + } + + // Create the topic + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_ = participant_->create_topic("WeighRspTopic", type_.get_type_name(), topic_qos); + if (topic_ == nullptr) + { + throw std::runtime_error("WeighRsp 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_LAST_HISTORY_QOS; + writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all()); + if (writer_ == nullptr) + { + throw std::runtime_error("WeighRsp DataWriter initialization failed"); + } +} + +PublisherApp::~PublisherApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + factory_->delete_participant(participant_); + } +} + +void PublisherApp::on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + { + std::lock_guard lock(mutex_); + matched_ = info.current_count; + } + std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + { + std::lock_guard lock(mutex_); + matched_ = info.current_count; + } + std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } +} + +void PublisherApp::run() +{ + while (!is_stopped()) + { + if (publish()) + { + std::cout << "Sample '" << std::to_string(++samples_sent_) << "' SENT" << std::endl; + } + // Wait for period or stop event + std::unique_lock period_lock(mutex_); + cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [this]() + { + return is_stopped(); + }); + } +} + + +bool PublisherApp::publish() +{ + bool ret = false; + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ > 0) || is_stopped()); + }); + + if (!is_stopped()) + { + /* Initialize your structure here */ + WeighRsp sample_; + ret = (RETCODE_OK == writer_->write(&sample_)); + } + return ret; +} + +bool PublisherApp::is_stopped() +{ + return stop_.load(); +} + +void PublisherApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} \ No newline at end of file diff --git a/demo/Publisher.hpp b/demo/Publisher.hpp new file mode 100644 index 0000000..ae0baa0 --- /dev/null +++ b/demo/Publisher.hpp @@ -0,0 +1,74 @@ +// 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 PublisherApp.hpp + * This header file contains the declaration of the publisher functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__PUBLISHERAPP_HPP +#define FAST_DDS_GENERATED__PUBLISHERAPP_HPP + +#include + +#include +#include +#include +#include + +class PublisherApp : public eprosima::fastdds::dds::DataWriterListener +{ +public: + + PublisherApp( + const int& domain_id); + + ~PublisherApp(); + + //! Publisher matched method + void on_publication_matched( + eprosima::fastdds::dds::DataWriter* writer, + const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; + + //! Run publisher + void run(); + + //! Trigger the end of execution + void stop(); + +private: + + //! Return the current state of execution + bool is_stopped(); + + //! Publish a sample + bool publish(); + + std::shared_ptr 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 stop_; +}; + +#endif // FAST_DDS_GENERATED__PUBLISHERAPP_HPP \ No newline at end of file diff --git a/demo/Subscriber.cxx b/demo/Subscriber.cxx new file mode 100644 index 0000000..bc10fe1 --- /dev/null +++ b/demo/Subscriber.cxx @@ -0,0 +1,159 @@ +// 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 Subscriber.cxx + * This file contains the implementation of the subscriber functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "Subscriber.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "SystemPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; + +SubscriberApp::SubscriberApp( + const int& domain_id) + : factory_(nullptr) + , participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , type_(new WeighReqPubSubType()) + , samples_received_(0) + , stop_(false) +{ + // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; + pqos.name("Weigh_sub_participant"); + pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0); + pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0); + factory_ = DomainParticipantFactory::get_shared_instance(); + participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none()); + if (participant_ == nullptr) + { + throw std::runtime_error("WeighReq Participant initialization failed"); + } + + // Register the type + 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("WeighReq Subscriber initialization failed"); + } + + // Create the topic + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_ = participant_->create_topic("WeighReqTopic", type_.get_type_name(), topic_qos); + if (topic_ == nullptr) + { + throw std::runtime_error("WeighReq 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_LAST_HISTORY_QOS; + reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all()); + if (reader_ == nullptr) + { + throw std::runtime_error("WeighReq DataReader initialization failed"); + } +} + +SubscriberApp::~SubscriberApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + factory_->delete_participant(participant_); + } +} + +void SubscriberApp::on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl; + } + else if (info.current_count_change == -1) + { + std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + } +} + +void SubscriberApp::on_data_available( + DataReader* reader) +{ + WeighRsp 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" << std::endl; + } + } +} + +void SubscriberApp::run() +{ + std::unique_lock lck(terminate_cv_mtx_); + terminate_cv_.wait(lck, [this] + { + return is_stopped(); + }); +} + +bool SubscriberApp::is_stopped() +{ + return stop_.load(); +} + +void SubscriberApp::stop() +{ + stop_.store(true); + terminate_cv_.notify_all(); +} \ No newline at end of file diff --git a/demo/Subscriber.hpp b/demo/Subscriber.hpp new file mode 100644 index 0000000..81132dc --- /dev/null +++ b/demo/Subscriber.hpp @@ -0,0 +1,75 @@ +// 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 SubscriberApp.hpp + * This header file contains the declaration of the subscriber functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP +#define FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP + +#include + +#include +#include +#include +#include + +#include "System.hpp" + +class SubscriberApp : public eprosima::fastdds::dds::DataReaderListener +{ +public: + + SubscriberApp( + const int& domain_id); + + virtual ~SubscriberApp(); + + //! Subscription callback + void on_data_available( + eprosima::fastdds::dds::DataReader* reader) override; + + //! Subscriber matched method + void on_subscription_matched( + eprosima::fastdds::dds::DataReader* reader, + const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override; + + //! Run subscriber + void run(); + + //! Trigger the end of execution + void stop(); + +private: + + //! Return the current state of execution + bool is_stopped(); + + std::shared_ptr 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_; + uint16_t samples_received_; + std::atomic stop_; + mutable std::mutex terminate_cv_mtx_; + std::condition_variable terminate_cv_; +}; + +#endif // FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP \ No newline at end of file diff --git a/demo/main.cxx b/demo/main.cxx new file mode 100644 index 0000000..b9ba014 --- /dev/null +++ b/demo/main.cxx @@ -0,0 +1,161 @@ +// 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 Systemmain.cxx + * This file acts as a main entry point to the application. + * + * This file was generated by the tool fastddsgen. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "Subscriber.hpp" +#include "Publisher.hpp" + +#define VERSION "v1.0" + +using eprosima::fastdds::dds::Log; + +std::function stop_handler; +void signal_handler( + int signum) +{ + 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) +{ + auto ret = EXIT_SUCCESS; + std::shared_ptr sub; + std::shared_ptr pub; + + int domain_id = 0; + const char* interface = "serial"; + const char* port = "ttyS1"; + const char* baudrate = "9600"; + const char* device = "device"; + + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "--domain") == 0 && i + 1 < argc) + { + domain_id = atoi(argv[++i]); + } + else if (strcmp(argv[i], "--interface") == 0 && i + 1 < argc) + { + interface = argv[++i]; + } + else if (strcmp(argv[i], "--port") == 0 && i + 1 < argc) + { + port = argv[++i]; + } + else if (strcmp(argv[i], "--baudrate") == 0 && i + 1 < argc) + { + baudrate = argv[++i]; + } + else if (strcmp(argv[i], "--device") == 0 && i + 1 < argc) + { + device = argv[++i]; + } + else if (strcmp(argv[i], "--version") == 0) + { + std::cout << "Vesrion: " << VERSION << "\n"; + return EXIT_SUCCESS; + } + else if (strcmp(argv[i], "--help") == 0) + { + std::cout << "Usage: [options]\n" + << "Options:\n" + << " --domain Set domain ID\n" + << " --interface Set interface (e.g., serial)\n" + << " --baudrate Set baudrate (e.g., 9600)\n" + << " --port Set port name (e.g., ttyS1)\n" + << " --device Set device name (e.g., T080)\n" + << " --version Show software Version\n" + << " --help Show this help message\n"; + return EXIT_SUCCESS; + } + else + { + std::cerr << "Unknown option: " << argv[i] << "\n"; + std::cout << "Usage: [options]\n" + << "Options:\n" + << " --domain Set domain ID\n" + << " --interface Set interface (e.g., serial)\n" + << " --baudrate Set baudrate (e.g., 9600)\n" + << " --port Set port name (e.g., ttyS1)\n" + << " --device Set device name (e.g., T080)\n" + << " --version Show software Version\n" + << " --help Show this help message\n"; + return EXIT_FAILURE; + } + } + + sub = std::make_shared(domain_id); + pub = std::make_shared(domain_id); + + std::thread sub_thread(&SubscriberApp::run, sub); + std::thread pub_thread(&PublisherApp::run, pub); + + std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl; + + stop_handler = [&](int signum) + { + std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1] + << " execution." << std::endl; + sub->stop(); + pub->stop(); + }; + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); +#ifndef _WIN32 + signal(SIGQUIT, signal_handler); + signal(SIGHUP, signal_handler); +#endif // _WIN32 + + sub_thread.join(); + pub_thread.join(); + + Log::Reset(); + return ret; +} diff --git a/lib/System.hpp b/lib/System.hpp new file mode 100644 index 0000000..ca3acde --- /dev/null +++ b/lib/System.hpp @@ -0,0 +1,425 @@ +// 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 System.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__SYSTEM_HPP +#define FAST_DDS_GENERATED__SYSTEM_HPP + +#include +#include +#include +#include +#include + +#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(SYSTEM_SOURCE) +#define SYSTEM_DllAPI __declspec( dllexport ) +#else +#define SYSTEM_DllAPI __declspec( dllimport ) +#endif // SYSTEM_SOURCE +#else +#define SYSTEM_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define SYSTEM_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure WeighReq defined by the user in the IDL file. + * @ingroup System + */ +class WeighReq +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport WeighReq() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~WeighReq() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object WeighReq that will be copied. + */ + eProsima_user_DllExport WeighReq( + const WeighReq& x) + { + m_index = x.m_index; + + m_msg = x.m_msg; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object WeighReq that will be copied. + */ + eProsima_user_DllExport WeighReq( + WeighReq&& x) noexcept + { + m_index = x.m_index; + m_msg = std::move(x.m_msg); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object WeighReq that will be copied. + */ + eProsima_user_DllExport WeighReq& operator =( + const WeighReq& x) + { + + m_index = x.m_index; + + m_msg = x.m_msg; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object WeighReq that will be copied. + */ + eProsima_user_DllExport WeighReq& operator =( + WeighReq&& x) noexcept + { + + m_index = x.m_index; + m_msg = std::move(x.m_msg); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x WeighReq object to compare. + */ + eProsima_user_DllExport bool operator ==( + const WeighReq& x) const + { + return (m_index == x.m_index && + m_msg == x.m_msg); + } + + /*! + * @brief Comparison operator. + * @param x WeighReq object to compare. + */ + eProsima_user_DllExport bool operator !=( + const WeighReq& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + + + /*! + * @brief This function copies the value in member msg + * @param _msg New value to be copied in member msg + */ + eProsima_user_DllExport void msg( + const std::map& _msg) + { + m_msg = _msg; + } + + /*! + * @brief This function moves the value in member msg + * @param _msg New value to be moved in member msg + */ + eProsima_user_DllExport void msg( + std::map&& _msg) + { + m_msg = std::move(_msg); + } + + /*! + * @brief This function returns a constant reference to member msg + * @return Constant reference to member msg + */ + eProsima_user_DllExport const std::map& msg() const + { + return m_msg; + } + + /*! + * @brief This function returns a reference to member msg + * @return Reference to member msg + */ + eProsima_user_DllExport std::map& msg() + { + return m_msg; + } + + + +private: + + uint32_t m_index{0}; + std::map m_msg; + +}; +/*! + * @brief This class represents the structure WeighRsp defined by the user in the IDL file. + * @ingroup System + */ +class WeighRsp +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport WeighRsp() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~WeighRsp() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object WeighRsp that will be copied. + */ + eProsima_user_DllExport WeighRsp( + const WeighRsp& x) + { + m_index = x.m_index; + + m_stable_weight = x.m_stable_weight; + + m_instantaneous_weight = x.m_instantaneous_weight; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object WeighRsp that will be copied. + */ + eProsima_user_DllExport WeighRsp( + WeighRsp&& x) noexcept + { + m_index = x.m_index; + m_stable_weight = x.m_stable_weight; + m_instantaneous_weight = x.m_instantaneous_weight; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object WeighRsp that will be copied. + */ + eProsima_user_DllExport WeighRsp& operator =( + const WeighRsp& x) + { + + m_index = x.m_index; + + m_stable_weight = x.m_stable_weight; + + m_instantaneous_weight = x.m_instantaneous_weight; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object WeighRsp that will be copied. + */ + eProsima_user_DllExport WeighRsp& operator =( + WeighRsp&& x) noexcept + { + + m_index = x.m_index; + m_stable_weight = x.m_stable_weight; + m_instantaneous_weight = x.m_instantaneous_weight; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x WeighRsp object to compare. + */ + eProsima_user_DllExport bool operator ==( + const WeighRsp& x) const + { + return (m_index == x.m_index && + m_stable_weight == x.m_stable_weight && + m_instantaneous_weight == x.m_instantaneous_weight); + } + + /*! + * @brief Comparison operator. + * @param x WeighRsp object to compare. + */ + eProsima_user_DllExport bool operator !=( + const WeighRsp& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + + + /*! + * @brief This function sets a value in member stable_weight + * @param _stable_weight New value for member stable_weight + */ + eProsima_user_DllExport void stable_weight( + float _stable_weight) + { + m_stable_weight = _stable_weight; + } + + /*! + * @brief This function returns the value of member stable_weight + * @return Value of member stable_weight + */ + eProsima_user_DllExport float stable_weight() const + { + return m_stable_weight; + } + + /*! + * @brief This function returns a reference to member stable_weight + * @return Reference to member stable_weight + */ + eProsima_user_DllExport float& stable_weight() + { + return m_stable_weight; + } + + + /*! + * @brief This function sets a value in member instantaneous_weight + * @param _instantaneous_weight New value for member instantaneous_weight + */ + eProsima_user_DllExport void instantaneous_weight( + float _instantaneous_weight) + { + m_instantaneous_weight = _instantaneous_weight; + } + + /*! + * @brief This function returns the value of member instantaneous_weight + * @return Value of member instantaneous_weight + */ + eProsima_user_DllExport float instantaneous_weight() const + { + return m_instantaneous_weight; + } + + /*! + * @brief This function returns a reference to member instantaneous_weight + * @return Reference to member instantaneous_weight + */ + eProsima_user_DllExport float& instantaneous_weight() + { + return m_instantaneous_weight; + } + + + +private: + + uint32_t m_index{0}; + float m_stable_weight{0.0}; + float m_instantaneous_weight{0.0}; + +}; + +#endif // _FAST_DDS_GENERATED_SYSTEM_HPP_ + + diff --git a/lib/System.idl b/lib/System.idl new file mode 100644 index 0000000..5a38ee4 --- /dev/null +++ b/lib/System.idl @@ -0,0 +1,13 @@ +@extensibility(APPENDABLE) +struct WeighReq +{ + unsigned long index; + map msg; +}; + +struct WeighRsp +{ + unsigned long index; + float stable_weight; + float instantaneous_weight; +}; diff --git a/lib/SystemCdrAux.hpp b/lib/SystemCdrAux.hpp new file mode 100644 index 0000000..8c26505 --- /dev/null +++ b/lib/SystemCdrAux.hpp @@ -0,0 +1,53 @@ +// 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 SystemCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SYSTEMCDRAUX_HPP +#define FAST_DDS_GENERATED__SYSTEMCDRAUX_HPP + +#include "System.hpp" + +constexpr uint32_t WeighReq_max_cdr_typesize {16UL}; +constexpr uint32_t WeighReq_max_key_cdr_typesize {0UL}; + +constexpr uint32_t WeighRsp_max_cdr_typesize {16UL}; +constexpr uint32_t WeighRsp_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const WeighReq& data); + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const WeighRsp& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__SYSTEMCDRAUX_HPP + diff --git a/lib/SystemCdrAux.ipp b/lib/SystemCdrAux.ipp new file mode 100644 index 0000000..96bdb14 --- /dev/null +++ b/lib/SystemCdrAux.ipp @@ -0,0 +1,230 @@ +// 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 SystemCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__SYSTEMCDRAUX_IPP +#define FAST_DDS_GENERATED__SYSTEMCDRAUX_IPP + +#include "SystemCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const WeighReq& data, + size_t& current_alignment) +{ + static_cast(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.index(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.msg(), 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 WeighReq& 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.index() + << eprosima::fastcdr::MemberId(1) << data.msg() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + WeighReq& 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.index(); + break; + + case 1: + dcdr >> data.msg(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const WeighReq& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.index(); + + scdr << data.msg(); + +} + + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const WeighRsp& data, + size_t& current_alignment) +{ + static_cast(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.index(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.stable_weight(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2), + data.instantaneous_weight(), 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 WeighRsp& 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.index() + << eprosima::fastcdr::MemberId(1) << data.stable_weight() + << eprosima::fastcdr::MemberId(2) << data.instantaneous_weight() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + WeighRsp& 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.index(); + break; + + case 1: + dcdr >> data.stable_weight(); + break; + + case 2: + dcdr >> data.instantaneous_weight(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const WeighRsp& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.index(); + + scdr << data.stable_weight(); + + scdr << data.instantaneous_weight(); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__SYSTEMCDRAUX_IPP + diff --git a/lib/SystemPubSubTypes.cxx b/lib/SystemPubSubTypes.cxx new file mode 100644 index 0000000..7f78d10 --- /dev/null +++ b/lib/SystemPubSubTypes.cxx @@ -0,0 +1,400 @@ +// 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 SystemPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "SystemPubSubTypes.hpp" + +#include +#include + +#include "SystemCdrAux.hpp" +#include "SystemTypeObjectSupport.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; + +WeighReqPubSubType::WeighReqPubSubType() +{ + set_name("WeighReq"); + uint32_t type_size = WeighReq_max_cdr_typesize; + type_size += static_cast(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 = WeighReq_max_key_cdr_typesize > 16 ? WeighReq_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +WeighReqPubSubType::~WeighReqPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool WeighReqPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const WeighReq* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(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(ser.get_serialized_data_length()); + return true; +} + +bool WeighReqPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + WeighReq* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(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 WeighReqPubSubType::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(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* WeighReqPubSubType::create_data() +{ + return reinterpret_cast(new WeighReq()); +} + +void WeighReqPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool WeighReqPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + WeighReq data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool WeighReqPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const WeighReq* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + WeighReq_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 || WeighReq_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(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 WeighReqPubSubType::register_type_object_representation() +{ + register_WeighReq_type_identifier(type_identifiers_); +} + +WeighRspPubSubType::WeighRspPubSubType() +{ + set_name("WeighRsp"); + uint32_t type_size = WeighRsp_max_cdr_typesize; + type_size += static_cast(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 = WeighRsp_max_key_cdr_typesize > 16 ? WeighRsp_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +WeighRspPubSubType::~WeighRspPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool WeighRspPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const WeighRsp* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(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(ser.get_serialized_data_length()); + return true; +} + +bool WeighRspPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + WeighRsp* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(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 WeighRspPubSubType::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(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +} + +void* WeighRspPubSubType::create_data() +{ + return reinterpret_cast(new WeighRsp()); +} + +void WeighRspPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool WeighRspPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + WeighRsp data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool WeighRspPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const WeighRsp* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + WeighRsp_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 || WeighRsp_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(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 WeighRspPubSubType::register_type_object_representation() +{ + register_WeighRsp_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "SystemCdrAux.ipp" diff --git a/lib/SystemPubSubTypes.hpp b/lib/SystemPubSubTypes.hpp new file mode 100644 index 0000000..8a6744e --- /dev/null +++ b/lib/SystemPubSubTypes.hpp @@ -0,0 +1,204 @@ +// 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 SystemPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__SYSTEM_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__SYSTEM_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "System.hpp" + + +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) +#error \ + Generated System 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 WeighReq defined by the user in the IDL file. + * @ingroup System + */ +class WeighReqPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef WeighReq type; + + eProsima_user_DllExport WeighReqPubSubType(); + + eProsima_user_DllExport ~WeighReqPubSubType() 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(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(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 WeighRsp defined by the user in the IDL file. + * @ingroup System + */ +class WeighRspPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef WeighRsp type; + + eProsima_user_DllExport WeighRspPubSubType(); + + eProsima_user_DllExport ~WeighRspPubSubType() 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 true; + } + +#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(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(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + +#endif // FAST_DDS_GENERATED__SYSTEM_PUBSUBTYPES_HPP + diff --git a/lib/SystemTypeObjectSupport.cxx b/lib/SystemTypeObjectSupport.cxx new file mode 100644 index 0000000..50a1263 --- /dev/null +++ b/lib/SystemTypeObjectSupport.cxx @@ -0,0 +1,331 @@ +// 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 SystemTypeObjectSupport.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 "SystemTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "System.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_WeighReq_type_identifier( + TypeIdentifierPair& type_ids_WeighReq) +{ + + ReturnCode_t return_code_WeighReq {eprosima::fastdds::dds::RETCODE_OK}; + return_code_WeighReq = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "WeighReq", type_ids_WeighReq); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_WeighReq) + { + StructTypeFlag struct_flags_WeighReq = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_WeighReq = "WeighReq"; + eprosima::fastcdr::optional type_ann_builtin_WeighReq; + eprosima::fastcdr::optional ann_custom_WeighReq; + AppliedAnnotationSeq tmp_ann_custom_WeighReq; + eprosima::fastcdr::optional verbatim_WeighReq; + if (!tmp_ann_custom_WeighReq.empty()) + { + ann_custom_WeighReq = tmp_ann_custom_WeighReq; + } + + CompleteTypeDetail detail_WeighReq = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_WeighReq, ann_custom_WeighReq, type_name_WeighReq.to_string()); + CompleteStructHeader header_WeighReq; + header_WeighReq = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_WeighReq); + CompleteStructMemberSeq member_seq_WeighReq; + { + TypeIdentifierPair type_ids_index; + ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; + return_code_index = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint32_t", type_ids_index); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_index = 0x00000000; + bool common_index_ec {false}; + CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; + if (!common_index_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); + return; + } + MemberName name_index = "index"; + eprosima::fastcdr::optional member_ann_builtin_index; + ann_custom_WeighReq.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_WeighReq); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_WeighReq, member_index); + } + { + TypeIdentifierPair type_ids_msg; + ReturnCode_t return_code_msg {eprosima::fastdds::dds::RETCODE_OK}; + return_code_msg = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg) + { + return_code_msg = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_msg); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg) + { + { + 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_msg)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + bool element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false}; + TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))}; + if (!element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent element TypeIdentifier."); + return; + } + return_code_msg = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_msg); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg) + { + { + 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_msg)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + bool key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false}; + TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))}; + if (!key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent key TypeIdentifier."); + return; + } + EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_BOTH; + if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d()) || + (TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_sdefn().header().equiv_kind()) || + (TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_ldefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_sdefn().header().equiv_kind()) || + (TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_ldefn().header().equiv_kind()) || + (TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().header().equiv_kind())) || + (TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().header().equiv_kind()))) + { + equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_COMPLETE; + } + CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0; + CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0; + PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded); + { + SBound bound = 0; + PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, bound, + eprosima::fastcdr::external(element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, + eprosima::fastcdr::external(key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_msg = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_msg = 0x00000001; + bool common_msg_ec {false}; + CommonStructMember common_msg {TypeObjectUtils::build_common_struct_member(member_id_msg, member_flags_msg, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, common_msg_ec))}; + if (!common_msg_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure msg member TypeIdentifier inconsistent."); + return; + } + MemberName name_msg = "msg"; + eprosima::fastcdr::optional member_ann_builtin_msg; + ann_custom_WeighReq.reset(); + CompleteMemberDetail detail_msg = TypeObjectUtils::build_complete_member_detail(name_msg, member_ann_builtin_msg, ann_custom_WeighReq); + CompleteStructMember member_msg = TypeObjectUtils::build_complete_struct_member(common_msg, detail_msg); + TypeObjectUtils::add_complete_struct_member(member_seq_WeighReq, member_msg); + } + CompleteStructType struct_type_WeighReq = TypeObjectUtils::build_complete_struct_type(struct_flags_WeighReq, header_WeighReq, member_seq_WeighReq); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_WeighReq, type_name_WeighReq.to_string(), type_ids_WeighReq)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "WeighReq already registered in TypeObjectRegistry for a different type."); + } + } +} +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_WeighRsp_type_identifier( + TypeIdentifierPair& type_ids_WeighRsp) +{ + + ReturnCode_t return_code_WeighRsp {eprosima::fastdds::dds::RETCODE_OK}; + return_code_WeighRsp = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "WeighRsp", type_ids_WeighRsp); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_WeighRsp) + { + StructTypeFlag struct_flags_WeighRsp = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_WeighRsp = "WeighRsp"; + eprosima::fastcdr::optional type_ann_builtin_WeighRsp; + eprosima::fastcdr::optional ann_custom_WeighRsp; + CompleteTypeDetail detail_WeighRsp = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_WeighRsp, ann_custom_WeighRsp, type_name_WeighRsp.to_string()); + CompleteStructHeader header_WeighRsp; + header_WeighRsp = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_WeighRsp); + CompleteStructMemberSeq member_seq_WeighRsp; + { + TypeIdentifierPair type_ids_index; + ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; + return_code_index = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint32_t", type_ids_index); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_index = 0x00000000; + bool common_index_ec {false}; + CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; + if (!common_index_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); + return; + } + MemberName name_index = "index"; + eprosima::fastcdr::optional member_ann_builtin_index; + ann_custom_WeighRsp.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_WeighRsp); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_WeighRsp, member_index); + } + { + TypeIdentifierPair type_ids_stable_weight; + ReturnCode_t return_code_stable_weight {eprosima::fastdds::dds::RETCODE_OK}; + return_code_stable_weight = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_float", type_ids_stable_weight); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_stable_weight) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "stable_weight Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_stable_weight = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_stable_weight = 0x00000001; + bool common_stable_weight_ec {false}; + CommonStructMember common_stable_weight {TypeObjectUtils::build_common_struct_member(member_id_stable_weight, member_flags_stable_weight, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_stable_weight, common_stable_weight_ec))}; + if (!common_stable_weight_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure stable_weight member TypeIdentifier inconsistent."); + return; + } + MemberName name_stable_weight = "stable_weight"; + eprosima::fastcdr::optional member_ann_builtin_stable_weight; + ann_custom_WeighRsp.reset(); + CompleteMemberDetail detail_stable_weight = TypeObjectUtils::build_complete_member_detail(name_stable_weight, member_ann_builtin_stable_weight, ann_custom_WeighRsp); + CompleteStructMember member_stable_weight = TypeObjectUtils::build_complete_struct_member(common_stable_weight, detail_stable_weight); + TypeObjectUtils::add_complete_struct_member(member_seq_WeighRsp, member_stable_weight); + } + { + TypeIdentifierPair type_ids_instantaneous_weight; + ReturnCode_t return_code_instantaneous_weight {eprosima::fastdds::dds::RETCODE_OK}; + return_code_instantaneous_weight = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_float", type_ids_instantaneous_weight); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_instantaneous_weight) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "instantaneous_weight Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_instantaneous_weight = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_instantaneous_weight = 0x00000002; + bool common_instantaneous_weight_ec {false}; + CommonStructMember common_instantaneous_weight {TypeObjectUtils::build_common_struct_member(member_id_instantaneous_weight, member_flags_instantaneous_weight, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_instantaneous_weight, common_instantaneous_weight_ec))}; + if (!common_instantaneous_weight_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure instantaneous_weight member TypeIdentifier inconsistent."); + return; + } + MemberName name_instantaneous_weight = "instantaneous_weight"; + eprosima::fastcdr::optional member_ann_builtin_instantaneous_weight; + ann_custom_WeighRsp.reset(); + CompleteMemberDetail detail_instantaneous_weight = TypeObjectUtils::build_complete_member_detail(name_instantaneous_weight, member_ann_builtin_instantaneous_weight, ann_custom_WeighRsp); + CompleteStructMember member_instantaneous_weight = TypeObjectUtils::build_complete_struct_member(common_instantaneous_weight, detail_instantaneous_weight); + TypeObjectUtils::add_complete_struct_member(member_seq_WeighRsp, member_instantaneous_weight); + } + CompleteStructType struct_type_WeighRsp = TypeObjectUtils::build_complete_struct_type(struct_flags_WeighRsp, header_WeighRsp, member_seq_WeighRsp); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_WeighRsp, type_name_WeighRsp.to_string(), type_ids_WeighRsp)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "WeighRsp already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/lib/SystemTypeObjectSupport.hpp b/lib/SystemTypeObjectSupport.hpp new file mode 100644 index 0000000..6b6fca2 --- /dev/null +++ b/lib/SystemTypeObjectSupport.hpp @@ -0,0 +1,68 @@ +// 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 SystemTypeObjectSupport.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__SYSTEM_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__SYSTEM_TYPE_OBJECT_SUPPORT_HPP + +#include + + +#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 WeighReq 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_WeighReq_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); +/** + * @brief Register WeighRsp 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_WeighRsp_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__SYSTEM_TYPE_OBJECT_SUPPORT_HPP