From fe1fe22c3bee2c2382095e6af147aac4abd4410c Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:39:17 +0200 Subject: [PATCH] [config] Added config object to registration. (#1709) * Added Config object to registration. --- ecal/core/CMakeLists.txt | 13 +++ ecal/core/include/ecal/config/registration.h | 15 ++-- .../include/ecal/config/transport_layer.h | 14 ++++ ecal/core/include/ecal/ecal_config.h | 19 +++-- .../ecal/types/ecal_custom_data_types.h | 2 +- .../registration_attribute_builder.cpp | 53 ++++++++++++ .../builder/registration_attribute_builder.h | 29 +++++++ .../core/src/config/configuration_to_yaml.cpp | 10 ++- .../src/config/ecal_config_initializer.cpp | 44 +++++++++- ecal/core/src/config/transport_layer.cpp | 44 ++++++++++ ecal/core/src/ecal_globals.cpp | 9 +- .../attributes/registration_attributes.h | 65 ++++++++++++++ .../attributes/sample_applier_attributes.h | 39 +++++++++ .../sample_applier_attribute_builder.cpp | 41 +++++++++ .../sample_applier_attribute_builder.h | 34 ++++++++ .../builder/udp_shm_attribute_builder.cpp | 84 +++++++++++++++++++ .../builder/udp_shm_attribute_builder.h | 36 ++++++++ .../ecal_registration_provider.cpp | 29 +++---- .../registration/ecal_registration_provider.h | 9 +- .../ecal_registration_receiver.cpp | 29 ++++--- .../registration/ecal_registration_receiver.h | 12 +-- .../ecal_registration_sample_applier.cpp | 20 ++--- .../ecal_registration_sample_applier.h | 9 +- .../attributes/registration_shm_attributes.h | 37 ++++++++ .../shm/ecal_memfile_broadcast.cpp | 17 ++-- .../registration/shm/ecal_memfile_broadcast.h | 6 +- .../shm/ecal_registration_receiver_shm.cpp | 4 +- .../shm/ecal_registration_receiver_shm.h | 3 +- .../shm/ecal_registration_sender_shm.cpp | 6 +- .../shm/ecal_registration_sender_shm.h | 4 +- .../registration_receiver_udp_attributes.h | 40 +++++++++ .../registration_sender_udp_attributes.h | 41 +++++++++ .../udp/builder/udp_attribute_builder.cpp | 52 ++++++++++++ .../udp/builder/udp_attribute_builder.h | 39 +++++++++ .../udp/ecal_registration_receiver_udp.cpp | 22 +---- .../udp/ecal_registration_receiver_udp.h | 3 +- .../udp/ecal_registration_sender_udp.cpp | 21 +---- .../udp/ecal_registration_sender_udp.h | 3 +- .../core/src/types/ecal_custom_data_types.cpp | 2 +- 39 files changed, 819 insertions(+), 140 deletions(-) create mode 100644 ecal/core/src/builder/registration_attribute_builder.cpp create mode 100644 ecal/core/src/builder/registration_attribute_builder.h create mode 100644 ecal/core/src/config/transport_layer.cpp create mode 100644 ecal/core/src/registration/attributes/registration_attributes.h create mode 100644 ecal/core/src/registration/attributes/sample_applier_attributes.h create mode 100644 ecal/core/src/registration/builder/sample_applier_attribute_builder.cpp create mode 100644 ecal/core/src/registration/builder/sample_applier_attribute_builder.h create mode 100644 ecal/core/src/registration/builder/udp_shm_attribute_builder.cpp create mode 100644 ecal/core/src/registration/builder/udp_shm_attribute_builder.h create mode 100644 ecal/core/src/registration/shm/attributes/registration_shm_attributes.h create mode 100644 ecal/core/src/registration/udp/attributes/registration_receiver_udp_attributes.h create mode 100644 ecal/core/src/registration/udp/attributes/registration_sender_udp_attributes.h create mode 100644 ecal/core/src/registration/udp/builder/udp_attribute_builder.cpp create mode 100644 ecal/core/src/registration/udp/builder/udp_attribute_builder.h diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index b14cffe97e..bda05593ef 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -69,6 +69,7 @@ set(ecal_config_src src/config/ecal_cmd_parser.cpp src/config/ecal_config.cpp src/config/ecal_config_initializer.cpp + src/config/transport_layer.cpp src/types/ecal_custom_data_types.cpp ) if (ECAL_CORE_CONFIGURATION) @@ -443,6 +444,17 @@ if (WIN32) ) endif() +###################################### +# builder +###################################### +set (ecal_builder_src + src/builder/registration_attribute_builder.cpp + src/registration/builder/udp_shm_attribute_builder.cpp + src/registration/builder/sample_applier_attribute_builder.cpp + src/registration/udp/builder/udp_attribute_builder.cpp +) + + ###################################### # c interface ###################################### @@ -564,6 +576,7 @@ set(ecal_sources ${ecal_time_src} ${ecal_util_src} ${ecal_cmn_src} + ${ecal_builder_src} ${ecal_header_cmn} ${ecal_header_msg} ) diff --git a/ecal/core/include/ecal/config/registration.h b/ecal/core/include/ecal/config/registration.h index d01421b564..12b86fab7c 100644 --- a/ecal/core/include/ecal/config/registration.h +++ b/ecal/core/include/ecal/config/registration.h @@ -25,6 +25,7 @@ #pragma once #include "ecal/ecal_os.h" +#include "ecal/ecal_process.h" #include #include @@ -63,14 +64,14 @@ namespace eCAL struct Configuration { - unsigned int registration_timeout { 60000U }; //!< Timeout for topic registration in ms (internal) (Default: 60000) - unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000) + unsigned int registration_timeout { 60000U }; //!< Timeout for topic registration in ms (internal) (Default: 60000) + unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000) - bool network_enabled { false }; /*!< true = all eCAL components communicate over network boundaries - false = local host only communication (Default: false) */ - bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true) - std::string host_group_name { "" }; /*!< Common host group name that enables interprocess mechanisms across - (virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: "") */ + bool network_enabled { false }; /*!< true = all eCAL components communicate over network boundaries + false = local host only communication (Default: false) */ + bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true) + std::string host_group_name { eCAL::Process::GetHostName() }; /*!< Common host group name that enables interprocess mechanisms across + (virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: CurrentHostName) */ Layer::Configuration layer; }; } diff --git a/ecal/core/include/ecal/config/transport_layer.h b/ecal/core/include/ecal/config/transport_layer.h index eb89062e3a..86c93d8123 100644 --- a/ecal/core/include/ecal/config/transport_layer.h +++ b/ecal/core/include/ecal/config/transport_layer.h @@ -25,6 +25,7 @@ #pragma once #include +#include namespace eCAL { @@ -42,6 +43,16 @@ namespace eCAL }; } + namespace Local + { + struct Configuration + { + Types::IpAddressV4 group { "127.255.255.255" }; //!< UDP multicast group base (Default: 127.255.255.255) + unsigned int ttl { 1U }; /*!< UDP ttl value, also known as hop limit, is used in determining + the intermediate routers being traversed towards the destination (Default: 1) */ + }; + } + struct Configuration { Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.) @@ -61,6 +72,9 @@ namespace eCAL bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false) Network::Configuration network; + const Local::Configuration local; + + ECAL_API Configuration& operator=(const Configuration& other); }; } diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 19c5ec0ea1..72a8ecd465 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -30,8 +30,16 @@ //@{ namespace eCAL { - ECAL_API Configuration& GetConfiguration(); - + ECAL_API Configuration& GetConfiguration (); + ECAL_API Registration::Configuration& GetRegistrationConfiguration (); + ECAL_API Monitoring::Configuration& GetMonitoringConfiguration (); + ECAL_API Logging::Configuration& GetLoggingConfiguration (); + ECAL_API Subscriber::Configuration& GetSubscriberConfiguration (); + ECAL_API Publisher::Configuration& GetPublisherConfiguration (); + ECAL_API Time::Configuration& GetTimesyncConfiguration (); + ECAL_API Service::Configuration& GetServiceConfiguration (); + ECAL_API Application::Configuration& GetApplicationConfiguration (); + namespace Config { ///////////////////////////////////// @@ -69,13 +77,6 @@ namespace eCAL ECAL_API size_t GetTcpPubsubWriterThreadpoolSize (); ECAL_API size_t GetTcpPubsubMaxReconnectionAttemps (); - ECAL_API int GetTcpPubReaderThreadpoolSize (); - ECAL_API int GetTcpPubWriterThreadpoolSize (); - - ECAL_API int GetTcpSubReaderThreadpoolSize (); - ECAL_API int GetTcpSubWriterThreadpoolSize (); - ECAL_API int GetTcpSubMaxReconnectionAttemps (); - ECAL_API std::string GetHostGroupName (); ///////////////////////////////////// diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 12218f12d9..00ab7b7cbd 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -52,7 +52,7 @@ namespace eCAL ECAL_API IpAddressV4& operator=(const std::string& ip_string_); ECAL_API IpAddressV4& operator=(const char* ip_string_); - ECAL_API operator std::string(); + ECAL_API operator std::string() const; ECAL_API bool operator==(const eCAL::Types::IpAddressV4& rhs) const; ECAL_API friend bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_); ECAL_API friend bool operator==(const char* ip_string_, eCAL::Types::IpAddressV4 rhs); diff --git a/ecal/core/src/builder/registration_attribute_builder.cpp b/ecal/core/src/builder/registration_attribute_builder.cpp new file mode 100644 index 0000000000..846941f115 --- /dev/null +++ b/ecal/core/src/builder/registration_attribute_builder.cpp @@ -0,0 +1,53 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include "registration_attribute_builder.h" + +namespace eCAL +{ + Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_) + { + Registration::SAttributes attr; + + attr.refresh = reg_config_.registration_refresh; + attr.network_enabled = reg_config_.network_enabled; + attr.loopback = reg_config_.loopback; + attr.host_group_name = reg_config_.host_group_name; + attr.process_id = process_id_; + + attr.shm_enabled = reg_config_.layer.shm.enable; + attr.udp_enabled = reg_config_.layer.udp.enable; + + attr.shm.domain = reg_config_.layer.shm.domain; + attr.shm.queue_size = reg_config_.layer.shm.queue_size; + + attr.udp.port = reg_config_.layer.udp.port; + attr.udp.sendbuffer = tl_udp_confi_.send_buffer; + attr.udp.receivebuffer = tl_udp_confi_.receive_buffer; + attr.udp.mode = tl_udp_confi_.mode; + + attr.udp.network.group = tl_udp_confi_.network.group; + attr.udp.network.ttl = tl_udp_confi_.network.ttl; + + attr.udp.local.group = tl_udp_confi_.local.group; + attr.udp.local.ttl = tl_udp_confi_.local.ttl; + + return attr; + } +} \ No newline at end of file diff --git a/ecal/core/src/builder/registration_attribute_builder.h b/ecal/core/src/builder/registration_attribute_builder.h new file mode 100644 index 0000000000..a2d82853f7 --- /dev/null +++ b/ecal/core/src/builder/registration_attribute_builder.h @@ -0,0 +1,29 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include "registration/attributes/registration_attributes.h" + +#include + +namespace eCAL +{ + Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_); +} diff --git a/ecal/core/src/config/configuration_to_yaml.cpp b/ecal/core/src/config/configuration_to_yaml.cpp index 6067c0ee2a..f3caf6b168 100644 --- a/ecal/core/src/config/configuration_to_yaml.cpp +++ b/ecal/core/src/config/configuration_to_yaml.cpp @@ -165,9 +165,15 @@ namespace YAML AssignValue(config_.registration_timeout, node_, "registration_timeout"); AssignValue(config_.registration_refresh, node_, "registration_refresh"); AssignValue(config_.network_enabled, node_, "network_enabled"); - AssignValue(config_.loopback, node_, "loopback"); - AssignValue(config_.host_group_name, node_, "host_group_name"); + AssignValue(config_.loopback, node_, "loopback"); AssignValue(config_.layer, node_, "layer"); + + // By default the host_group_name is set with the current host name. + // If the user does not specify the host group name in the yaml, leave it like it is. + std::string host_group_name; + AssignValue(host_group_name, node_, "host_group_name"); + if (!host_group_name.empty()) config_.host_group_name = host_group_name; + return true; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 2718470b85..3a78dc4c6a 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -232,7 +232,7 @@ namespace eCAL { eCAL::Logging::Log(log_level_warning, "Specified yaml configuration path not valid:\"" + yaml_path_ + "\". Using default configuration."); } - }; + } Configuration::Configuration(int argc_ , char **argv_) : Configuration(ConvertArgcArgvToVector(argc_, argv_)) @@ -275,7 +275,47 @@ namespace eCAL Configuration& GetConfiguration() { return g_ecal_configuration; - }; + } + + Registration::Configuration& GetRegistrationConfiguration() + { + return GetConfiguration().registration; + } + + Monitoring::Configuration& GetMonitoringConfiguration() + { + return GetConfiguration().monitoring; + } + + Logging::Configuration& GetLoggingConfiguration() + { + return GetConfiguration().logging; + } + + Subscriber::Configuration& GetSubscriberConfiguration() + { + return GetConfiguration().subscriber; + } + + Publisher::Configuration& GetPublisherConfiguration() + { + return GetConfiguration().publisher; + } + + Time::Configuration& GetTimesyncConfiguration() + { + return GetConfiguration().timesync; + } + + Service::Configuration& GetServiceConfiguration() + { + return GetConfiguration().service; + } + + Application::Configuration& GetApplicationConfiguration() + { + return GetConfiguration().application; + } } diff --git a/ecal/core/src/config/transport_layer.cpp b/ecal/core/src/config/transport_layer.cpp new file mode 100644 index 0000000000..1b569e6c8c --- /dev/null +++ b/ecal/core/src/config/transport_layer.cpp @@ -0,0 +1,44 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * =========================== LICENSE ================================= + */ + +#include "ecal/config/transport_layer.h" + +namespace eCAL +{ + namespace TransportLayer + { + namespace UDP + { + Configuration& Configuration::operator=(const Configuration& other) + { + config_version = other.config_version; + join_all_interfaces = other.join_all_interfaces; + mask = other.mask; + mode = other.mode; + network = other.network; + npcap_enabled = other.npcap_enabled; + port = other.port; + receive_buffer = other.receive_buffer; + send_buffer = other.send_buffer; + + return *this; + } + } + } +} \ No newline at end of file diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 95a2ab8d04..88aec3007c 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -33,6 +33,8 @@ #include "service/ecal_service_singleton_manager.h" #endif +#include "builder/registration_attribute_builder.h" + namespace eCAL { CGlobals::CGlobals() : initialized(false), components(0) @@ -49,12 +51,13 @@ namespace eCAL bool new_initialization(false); #if ECAL_CORE_REGISTRATION + const Registration::SAttributes registration_attr = BuildRegistrationAttributes(GetConfiguration().registration, GetConfiguration().transport_layer.udp, eCAL::Process::GetProcessID()); ///////////////////// // REGISTRATION PROVIDER ///////////////////// if (registration_provider_instance == nullptr) { - registration_provider_instance = std::make_unique(); + registration_provider_instance = std::make_unique(registration_attr); new_initialization = true; } @@ -63,7 +66,7 @@ namespace eCAL ///////////////////// if(registration_receiver_instance == nullptr) { - registration_receiver_instance = std::make_unique(); + registration_receiver_instance = std::make_unique(registration_attr); new_initialization = true; } #endif // ECAL_CORE_REGISTRATION @@ -174,7 +177,7 @@ namespace eCAL { if (monitoring_instance == nullptr) { - monitoring_instance = std::make_unique(eCAL::GetConfiguration().monitoring); + monitoring_instance = std::make_unique(eCAL::GetMonitoringConfiguration()); new_initialization = true; } } diff --git a/ecal/core/src/registration/attributes/registration_attributes.h b/ecal/core/src/registration/attributes/registration_attributes.h new file mode 100644 index 0000000000..85268042e2 --- /dev/null +++ b/ecal/core/src/registration/attributes/registration_attributes.h @@ -0,0 +1,65 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include +#include + +namespace eCAL +{ + namespace Registration + { + struct SUDPModeAttrributes + { + std::string group; + int ttl; + }; + + struct SUDPAttributes + { + Types::UDPMode mode; + int port; + int sendbuffer; + int receivebuffer; + SUDPModeAttrributes network; + SUDPModeAttrributes local; + }; + + struct SSHMAttributes + { + std::string domain; + size_t queue_size; + }; + + struct SAttributes + { + bool network_enabled; + bool loopback; + bool shm_enabled; + bool udp_enabled; + unsigned int refresh; + std::string host_group_name; + int process_id; + + SUDPAttributes udp; + SSHMAttributes shm; + }; + } +} diff --git a/ecal/core/src/registration/attributes/sample_applier_attributes.h b/ecal/core/src/registration/attributes/sample_applier_attributes.h new file mode 100644 index 0000000000..efec45de90 --- /dev/null +++ b/ecal/core/src/registration/attributes/sample_applier_attributes.h @@ -0,0 +1,39 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Registration + { + namespace SampleApplier + { + struct SAttributes + { + bool network_enabled; + bool loopback; + std::string host_group_name; + int process_id; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/builder/sample_applier_attribute_builder.cpp b/ecal/core/src/registration/builder/sample_applier_attribute_builder.cpp new file mode 100644 index 0000000000..cab74eef50 --- /dev/null +++ b/ecal/core/src/registration/builder/sample_applier_attribute_builder.cpp @@ -0,0 +1,41 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include "sample_applier_attribute_builder.h" + +namespace eCAL +{ + namespace Registration + { + namespace SampleApplier + { + SAttributes BuildSampleApplierAttributes(const Registration::SAttributes& attr_) + { + SAttributes sample_applier_attr; + + sample_applier_attr.network_enabled = attr_.network_enabled; + sample_applier_attr.loopback = attr_.loopback; + sample_applier_attr.host_group_name = attr_.host_group_name; + sample_applier_attr.process_id = attr_.process_id; + + return sample_applier_attr; + } + } + } +} diff --git a/ecal/core/src/registration/builder/sample_applier_attribute_builder.h b/ecal/core/src/registration/builder/sample_applier_attribute_builder.h new file mode 100644 index 0000000000..e9d4ce337b --- /dev/null +++ b/ecal/core/src/registration/builder/sample_applier_attribute_builder.h @@ -0,0 +1,34 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include "registration/attributes/registration_attributes.h" +#include "registration/attributes/sample_applier_attributes.h" + +namespace eCAL +{ + namespace Registration + { + namespace SampleApplier + { + SAttributes BuildSampleApplierAttributes(const Registration::SAttributes& attr_); + } + } +} diff --git a/ecal/core/src/registration/builder/udp_shm_attribute_builder.cpp b/ecal/core/src/registration/builder/udp_shm_attribute_builder.cpp new file mode 100644 index 0000000000..29965d9c8c --- /dev/null +++ b/ecal/core/src/registration/builder/udp_shm_attribute_builder.cpp @@ -0,0 +1,84 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include "udp_shm_attribute_builder.h" + +namespace eCAL +{ + namespace Registration + { + UDP::SSenderAttributes BuildUDPSenderAttributes(const SAttributes& provider_attr_) + { + UDP::SSenderAttributes sender_attr; + sender_attr.broadcast = !provider_attr_.network_enabled; + sender_attr.loopback = provider_attr_.loopback; + + sender_attr.sndbuf = provider_attr_.udp.sendbuffer; + sender_attr.port = provider_attr_.udp.port; + + switch (provider_attr_.udp.mode) + { + case Types::UDPMode::NETWORK: + sender_attr.address = provider_attr_.udp.network.group; + sender_attr.ttl = provider_attr_.udp.network.ttl; + break; + case Types::UDPMode::LOCAL: + sender_attr.address = provider_attr_.udp.local.group; + sender_attr.ttl = provider_attr_.udp.local.ttl; + break; + default: + break; + } + + return sender_attr; + } + + UDP::SReceiverAttributes BuildUDPReceiverAttributes(const SAttributes& provider_attr_) + { + UDP::SReceiverAttributes receiver_attr; + receiver_attr.broadcast = !provider_attr_.network_enabled; + receiver_attr.loopback = true; + + receiver_attr.rcvbuf = provider_attr_.udp.receivebuffer; + receiver_attr.port = provider_attr_.udp.port; + + switch (provider_attr_.udp.mode) + { + case Types::UDPMode::NETWORK: + receiver_attr.address = provider_attr_.udp.network.group; + break; + case Types::UDPMode::LOCAL: + receiver_attr.address = provider_attr_.udp.local.group; + break; + default: + break; + } + + return receiver_attr; + } + + SHM::SAttributes BuildSHMAttributes(const SAttributes& provider_attr_) + { + SHM::SAttributes sender_attr; + sender_attr.domain = provider_attr_.shm.domain; + sender_attr.queue_size = provider_attr_.shm.queue_size; + return sender_attr; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/builder/udp_shm_attribute_builder.h b/ecal/core/src/registration/builder/udp_shm_attribute_builder.h new file mode 100644 index 0000000000..1fefc8e02b --- /dev/null +++ b/ecal/core/src/registration/builder/udp_shm_attribute_builder.h @@ -0,0 +1,36 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include "registration/udp/attributes/registration_sender_udp_attributes.h" +#include "registration/udp/attributes/registration_receiver_udp_attributes.h" +#include "registration/shm/attributes/registration_shm_attributes.h" +#include "registration/attributes/registration_attributes.h" + + +namespace eCAL +{ + namespace Registration + { + UDP::SSenderAttributes BuildUDPSenderAttributes (const SAttributes& provider_attr_); + UDP::SReceiverAttributes BuildUDPReceiverAttributes (const SAttributes& provider_attr_); + SHM::SAttributes BuildSHMAttributes (const SAttributes& provider_attr_); + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index b8816c2f1a..c953023a40 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -44,13 +44,15 @@ #include #endif +#include "builder/udp_shm_attribute_builder.h" + + namespace eCAL { std::atomic CRegistrationProvider::m_created; - CRegistrationProvider::CRegistrationProvider() : - m_use_registration_udp(false), - m_use_registration_shm(false) + CRegistrationProvider::CRegistrationProvider(const Registration::SAttributes& attr_) : + m_attributes(attr_) { } @@ -63,27 +65,26 @@ namespace eCAL { if(m_created) return; - // send registration over udp or shared memory - m_use_registration_shm = Config::IsShmRegistrationEnabled(); - m_use_registration_udp = !m_use_registration_shm; - // TODO Create the registration sender #if ECAL_CORE_REGISTRATION_SHM - if (m_use_registration_shm) + if (m_attributes.shm_enabled) + { + m_reg_sender = std::make_unique(Registration::BuildSHMAttributes(m_attributes)); + } else +#endif + if (m_attributes.udp_enabled) { - m_reg_sender = std::make_unique(); + m_reg_sender = std::make_unique(Registration::BuildUDPSenderAttributes(m_attributes)); } else { -#endif - m_reg_sender = std::make_unique(); -#if ECAL_CORE_REGISTRATION_SHM + eCAL::Logging::Log(log_level_warning, "[CRegistrationProvider] No registration layer enabled."); + return; } -#endif // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs())); + m_reg_sample_snd_thread->start(std::chrono::milliseconds(m_attributes.refresh)); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_provider.h b/ecal/core/src/registration/ecal_registration_provider.h index 452a1cb0ae..421d46a0e5 100644 --- a/ecal/core/src/registration/ecal_registration_provider.h +++ b/ecal/core/src/registration/ecal_registration_provider.h @@ -30,6 +30,8 @@ #include "registration/ecal_registration_sender.h" +#include "util/ecal_thread.h" +#include "attributes/registration_attributes.h" #include #include @@ -42,7 +44,7 @@ namespace eCAL class CRegistrationProvider { public: - CRegistrationProvider(); + CRegistrationProvider(const Registration::SAttributes& attr_); ~CRegistrationProvider(); void Start(); @@ -62,8 +64,7 @@ namespace eCAL std::mutex m_applied_sample_list_mtx; Registration::SampleList m_applied_sample_list; - - bool m_use_registration_udp; - bool m_use_registration_shm; + + Registration::SAttributes m_attributes; }; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index 70e3d5ce89..4f54540509 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -42,6 +42,9 @@ #include #include +#include "builder/udp_shm_attribute_builder.h" +#include "builder/sample_applier_attribute_builder.h" + namespace eCAL { ////////////////////////////////////////////////////////////////// @@ -49,14 +52,13 @@ namespace eCAL ////////////////////////////////////////////////////////////////// std::atomic CRegistrationReceiver::m_created; - CRegistrationReceiver::CRegistrationReceiver() + CRegistrationReceiver::CRegistrationReceiver(const Registration::SAttributes& attr_) : m_timeout_provider(nullptr) , m_timeout_provider_thread(nullptr) , m_registration_receiver_udp(nullptr) - , m_registration_receiver_shm(nullptr) - , m_use_registration_udp(false) - , m_use_registration_shm(false) - , m_sample_applier(Config::IsNetworkEnabled(), false, Process::GetHostGroupName(), Process::GetProcessID()) + , m_registration_receiver_shm(nullptr) + , m_attributes(attr_) + , m_sample_applier(Registration::SampleApplier::BuildSampleApplierAttributes(attr_)) { // Connect User registration callback and gates callback with the sample applier m_sample_applier.SetCustomApplySampleCallback("gates", [](const eCAL::Registration::Sample& sample_) @@ -96,19 +98,16 @@ namespace eCAL m_timeout_provider_thread = std::make_unique([this]() {m_timeout_provider->CheckForTimeouts(); }); m_timeout_provider_thread->start(std::chrono::milliseconds(100)); - // receive registration via udp or shared memory - m_use_registration_shm = Config::IsShmRegistrationEnabled(); - m_use_registration_udp = !m_use_registration_shm; - - if (m_use_registration_udp) + // Why do we have here different behaviour than in the registration provider? + if (m_attributes.udp_enabled) { - m_registration_receiver_udp = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }); + m_registration_receiver_udp = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_);}, Registration::BuildUDPReceiverAttributes(m_attributes)); } #if ECAL_CORE_REGISTRATION_SHM - if (m_use_registration_shm) + if (m_attributes.shm_enabled) { - m_registration_receiver_shm = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }); + m_registration_receiver_shm = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }, Registration::BuildSHMAttributes(m_attributes)); } #endif @@ -120,13 +119,13 @@ namespace eCAL if(!m_created) return; // stop network registration receive thread - if (m_use_registration_udp) + if (m_attributes.udp_enabled) { m_registration_receiver_udp = nullptr; } #if ECAL_CORE_REGISTRATION_SHM - if (m_use_registration_shm) + if (m_attributes.shm_enabled) { m_registration_receiver_shm = nullptr; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.h b/ecal/core/src/registration/ecal_registration_receiver.h index bf94610070..6803225866 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.h +++ b/ecal/core/src/registration/ecal_registration_receiver.h @@ -34,6 +34,7 @@ #include "registration/ecal_registration_sample_applier.h" #include "registration/ecal_registration_sample_applier_gates.h" #include "registration/ecal_registration_sample_applier_user.h" +#include "attributes/registration_attributes.h" #include #include @@ -58,7 +59,7 @@ namespace eCAL class CRegistrationReceiver { public: - CRegistrationReceiver(); + CRegistrationReceiver(const Registration::SAttributes& attr_); ~CRegistrationReceiver(); //what about the rest of the rule of 5? @@ -88,15 +89,14 @@ namespace eCAL std::unique_ptr m_registration_receiver_shm; #endif - bool m_use_registration_udp; - bool m_use_registration_shm; - // This class distributes samples to all everyone who is interested in being notified about samples - Registration::CSampleApplier m_sample_applier; + Registration::CSampleApplier m_sample_applier; // These classes are interested in being notified about samples // Possibly remove these from this class // The custom user callbacks (who receive serialized samples), e.g. registration events. - Registration::CSampleApplierUser m_user_applier; + Registration::CSampleApplierUser m_user_applier; + + Registration::SAttributes m_attributes; }; } diff --git a/ecal/core/src/registration/ecal_registration_sample_applier.cpp b/ecal/core/src/registration/ecal_registration_sample_applier.cpp index 975cfbc02c..0db73c2030 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.cpp +++ b/ecal/core/src/registration/ecal_registration_sample_applier.cpp @@ -26,18 +26,14 @@ namespace eCAL ////////////////////////////////////////////////////////////////// // CSampleApplier ////////////////////////////////////////////////////////////////// - CSampleApplier::CSampleApplier(bool network, bool loopback, const std::string& host_group_name, uint32_t pid) - : - m_network(network), - m_loopback(loopback), - m_host_group_name(host_group_name), - m_pid(pid) + CSampleApplier::CSampleApplier(const SampleApplier::SAttributes& attr_) + : m_attributes(attr_) { } void CSampleApplier::EnableLoopback(bool state_) { - m_loopback = state_; + m_attributes.loopback = state_; } bool CSampleApplier::ApplySample(const Registration::Sample& sample_) @@ -85,9 +81,9 @@ namespace eCAL const std::string& sample_host_group_name = host_group_name.empty() ? host_name : host_group_name; - if (sample_host_group_name.empty() || m_host_group_name.empty()) + if (sample_host_group_name.empty() || m_attributes.host_group_name.empty()) return false; - if (sample_host_group_name != m_host_group_name) + if (sample_host_group_name != m_attributes.host_group_name) return false; return true; @@ -97,7 +93,7 @@ namespace eCAL { // is this actually sufficient? should we also check host_name? const int32_t pid = sample_.identifier.process_id; - return pid == m_pid; + return pid == m_attributes.process_id; } bool CSampleApplier::AcceptRegistrationSample(const Registration::Sample& sample_) @@ -107,12 +103,12 @@ namespace eCAL { // register if the sample is from another process // or if loopback mode is enabled - return !IsSameProcess(sample_) || m_loopback; + return !IsSameProcess(sample_) || m_attributes.loopback; } else { // if the sample is from an external host, register only if network mode is enabled - return m_network; + return m_attributes.network_enabled; } } diff --git a/ecal/core/src/registration/ecal_registration_sample_applier.h b/ecal/core/src/registration/ecal_registration_sample_applier.h index bd2fcf889e..5007f2e9d8 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.h +++ b/ecal/core/src/registration/ecal_registration_sample_applier.h @@ -29,6 +29,7 @@ #include #include "serialization/ecal_struct_sample_registration.h" +#include "attributes/sample_applier_attributes.h" #include #include @@ -42,8 +43,7 @@ namespace eCAL class CSampleApplier { public: - // to be replaced by config version soon! - CSampleApplier(bool network, bool loopback, const std::string& host_group_name, uint32_t pid); + CSampleApplier(const SampleApplier::SAttributes& attr_); // to be removed for eCAL 6, but keep until eCAL 5.14 void EnableLoopback(bool state_); @@ -59,10 +59,7 @@ namespace eCAL bool AcceptRegistrationSample(const Registration::Sample& sample_); - bool m_network; - bool m_loopback; - std::string m_host_group_name; - int32_t m_pid; + SampleApplier::SAttributes m_attributes; std::mutex m_callback_custom_apply_sample_map_mtx; // We need to check the performance now. Unlike before the pub / subgates also go through the map diff --git a/ecal/core/src/registration/shm/attributes/registration_shm_attributes.h b/ecal/core/src/registration/shm/attributes/registration_shm_attributes.h new file mode 100644 index 0000000000..152772698a --- /dev/null +++ b/ecal/core/src/registration/shm/attributes/registration_shm_attributes.h @@ -0,0 +1,37 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Registration + { + namespace SHM + { + struct SAttributes + { + std::string domain; + unsigned int queue_size; + }; + } + } +} diff --git a/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp b/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp index 18c29834e5..f23622d299 100644 --- a/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp +++ b/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp @@ -59,20 +59,20 @@ namespace eCAL return reinterpret_cast(static_cast(address) + GetMemfileHeader(address)->message_queue_offset); } - CMemoryFileBroadcast::CMemoryFileBroadcast(): m_created(false), m_max_queue_size(0), m_broadcast_memfile(std::make_unique()), m_event_queue(), m_last_timestamp(0) + CMemoryFileBroadcast::CMemoryFileBroadcast(): m_created(false), m_broadcast_memfile(std::make_unique()), m_event_queue(), m_last_timestamp(0) { } - bool CMemoryFileBroadcast::Create(const std::string &name, std::size_t max_queue_size) + bool CMemoryFileBroadcast::Create(const Registration::SHM::SAttributes& attr_) { if (m_created) return false; - m_max_queue_size = max_queue_size; - m_name = name; + m_attributes = attr_; + const auto presumably_memfile_size = - RelocatableCircularQueue::PresumablyOccupiedMemorySize(m_max_queue_size) + + RelocatableCircularQueue::PresumablyOccupiedMemorySize(m_attributes.queue_size) + sizeof(SMemfileBroadcastHeader); - if (!m_broadcast_memfile->Create(name.c_str(), true, presumably_memfile_size, true)) + if (!m_broadcast_memfile->Create(m_attributes.domain.c_str(), true, presumably_memfile_size, true)) { #ifndef NDEBUG std::cerr << "Unable to access broadcast memory file." << std::endl; @@ -136,7 +136,7 @@ namespace eCAL std::string CMemoryFileBroadcast::GetName() const { - return m_name; + return m_attributes.domain; } bool CMemoryFileBroadcast::IsMemfileVersionCompatible(const void *memfile_address) const @@ -150,7 +150,7 @@ namespace eCAL auto *header = GetMemfileHeader(memfile_address); *header = SMemfileBroadcastHeader(); m_event_queue.SetBaseAddress(GetEventQueueAddress(memfile_address)); - m_event_queue.Reset(m_max_queue_size); + m_event_queue.Reset(m_attributes.queue_size); #ifndef NDEBUG std::cout << "Broadcast memory file has been resetted" << std::endl; #endif @@ -246,7 +246,6 @@ namespace eCAL } } - bool CMemoryFileBroadcast::ReceiveEvents(MemfileBroadcastEventListT &event_list, std::int64_t timeout, bool enable_loopback) { if (m_broadcast_memfile->GetReadAccess(EXP_MEMFILE_ACCESS_TIMEOUT)) diff --git a/ecal/core/src/registration/shm/ecal_memfile_broadcast.h b/ecal/core/src/registration/shm/ecal_memfile_broadcast.h index 321a42b704..d8a183d68e 100644 --- a/ecal/core/src/registration/shm/ecal_memfile_broadcast.h +++ b/ecal/core/src/registration/shm/ecal_memfile_broadcast.h @@ -32,6 +32,7 @@ #include "relocatable_circular_queue.h" #include "io/shm/ecal_memfile.h" +#include "attributes/registration_shm_attributes.h" #include @@ -79,7 +80,7 @@ namespace eCAL public: CMemoryFileBroadcast(); - bool Create(const std::string& name, std::size_t max_queue_size); + bool Create(const Registration::SHM::SAttributes& attr_); bool Destroy(); std::string GetName() const; @@ -95,8 +96,7 @@ namespace eCAL void ResetMemfile(void * memfile_address); bool m_created; - std::string m_name; - std::size_t m_max_queue_size; + Registration::SHM::SAttributes m_attributes; std::unique_ptr m_broadcast_memfile; std::vector m_broadcast_memfile_local_buffer; diff --git a/ecal/core/src/registration/shm/ecal_registration_receiver_shm.cpp b/ecal/core/src/registration/shm/ecal_registration_receiver_shm.cpp index 895f67e0a8..c8a51a0153 100644 --- a/ecal/core/src/registration/shm/ecal_registration_receiver_shm.cpp +++ b/ecal/core/src/registration/shm/ecal_registration_receiver_shm.cpp @@ -40,11 +40,11 @@ namespace eCAL // CMemfileRegistrationReceiver ////////////////////////////////////////////////////////////////// - CRegistrationReceiverSHM::CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback) + CRegistrationReceiverSHM::CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::SHM::SAttributes& attr_) : m_apply_sample_callback(apply_sample_callback) { m_memfile_broadcast = std::make_unique(); - m_memfile_broadcast->Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); + m_memfile_broadcast->Create(attr_); m_memfile_broadcast->FlushLocalEventQueue(); m_memfile_broadcast_reader = std::make_unique(); diff --git a/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h b/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h index 968f6af3e6..d34f4d53e1 100644 --- a/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h +++ b/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h @@ -29,6 +29,7 @@ #include #include +#include "attributes/registration_shm_attributes.h" namespace eCAL { @@ -39,7 +40,7 @@ namespace eCAL class CRegistrationReceiverSHM { public: - CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback); + CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::SHM::SAttributes& attr_); ~CRegistrationReceiverSHM(); // default copy constructor diff --git a/ecal/core/src/registration/shm/ecal_registration_sender_shm.cpp b/ecal/core/src/registration/shm/ecal_registration_sender_shm.cpp index c8fed5d3bc..a3f6e05f2b 100644 --- a/ecal/core/src/registration/shm/ecal_registration_sender_shm.cpp +++ b/ecal/core/src/registration/shm/ecal_registration_sender_shm.cpp @@ -30,10 +30,10 @@ #include "serialization/ecal_serialize_sample_registration.h" -eCAL::CRegistrationSenderSHM::CRegistrationSenderSHM() +eCAL::CRegistrationSenderSHM::CRegistrationSenderSHM(const Registration::SHM::SAttributes& attr_) { - std::cout << "Shared memory monitoring is enabled (domain: " << Config::Experimental::GetShmMonitoringDomain() << " - queue size: " << Config::Experimental::GetShmMonitoringQueueSize() << ")" << '\n'; - m_memfile_broadcast.Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); + std::cout << "Shared memory monitoring is enabled (domain: " << attr_.domain << " - queue size: " << attr_.queue_size << ")" << '\n'; + m_memfile_broadcast.Create(attr_); m_memfile_broadcast_writer.Bind(&m_memfile_broadcast); } diff --git a/ecal/core/src/registration/shm/ecal_registration_sender_shm.h b/ecal/core/src/registration/shm/ecal_registration_sender_shm.h index 67f4638b18..8cda6a9e67 100644 --- a/ecal/core/src/registration/shm/ecal_registration_sender_shm.h +++ b/ecal/core/src/registration/shm/ecal_registration_sender_shm.h @@ -33,12 +33,14 @@ #include "registration/shm/ecal_memfile_broadcast.h" #include "registration/shm/ecal_memfile_broadcast_writer.h" +#include "attributes/registration_shm_attributes.h" + namespace eCAL { class CRegistrationSenderSHM : public CRegistrationSender { public: - CRegistrationSenderSHM(); + CRegistrationSenderSHM(const Registration::SHM::SAttributes& attr_); ~CRegistrationSenderSHM() override; // Special member functionss diff --git a/ecal/core/src/registration/udp/attributes/registration_receiver_udp_attributes.h b/ecal/core/src/registration/udp/attributes/registration_receiver_udp_attributes.h new file mode 100644 index 0000000000..96695c675e --- /dev/null +++ b/ecal/core/src/registration/udp/attributes/registration_receiver_udp_attributes.h @@ -0,0 +1,40 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Registration + { + namespace UDP + { + struct SReceiverAttributes + { + std::string address; + int port = 0; + bool broadcast = false; + bool loopback = true; + int rcvbuf = 1024 * 1024; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/udp/attributes/registration_sender_udp_attributes.h b/ecal/core/src/registration/udp/attributes/registration_sender_udp_attributes.h new file mode 100644 index 0000000000..8af5f51acd --- /dev/null +++ b/ecal/core/src/registration/udp/attributes/registration_sender_udp_attributes.h @@ -0,0 +1,41 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Registration + { + namespace UDP + { + struct SSenderAttributes + { + std::string address; + int port; + int ttl; + bool broadcast; + bool loopback; + int sndbuf; + }; + } + } +} diff --git a/ecal/core/src/registration/udp/builder/udp_attribute_builder.cpp b/ecal/core/src/registration/udp/builder/udp_attribute_builder.cpp new file mode 100644 index 0000000000..345229fd19 --- /dev/null +++ b/ecal/core/src/registration/udp/builder/udp_attribute_builder.cpp @@ -0,0 +1,52 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include "udp_attribute_builder.h" + +namespace eCAL +{ + namespace Registration + { + namespace UDP + { + eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes (const Registration::UDP::SSenderAttributes& sender_attr_) + { + eCAL::UDP::SSenderAttr attr; + attr.broadcast = sender_attr_.broadcast; + attr.loopback = sender_attr_.loopback; + attr.sndbuf = sender_attr_.sndbuf; + attr.port = sender_attr_.port; + attr.address = sender_attr_.address; + attr.ttl = sender_attr_.ttl; + return attr; + } + + eCAL::UDP::SReceiverAttr ConvertToIOUDPReceiverAttributes (const Registration::UDP::SReceiverAttributes& receiver_attr_) + { + eCAL::UDP::SReceiverAttr attr; + attr.broadcast = receiver_attr_.broadcast; + attr.loopback = receiver_attr_.loopback; + attr.rcvbuf = receiver_attr_.rcvbuf; + attr.port = receiver_attr_.port; + attr.address = receiver_attr_.address; + return attr; + } + } + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/udp/builder/udp_attribute_builder.h b/ecal/core/src/registration/udp/builder/udp_attribute_builder.h new file mode 100644 index 0000000000..beb1525209 --- /dev/null +++ b/ecal/core/src/registration/udp/builder/udp_attribute_builder.h @@ -0,0 +1,39 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#pragma once + + +#include "io/udp/ecal_udp_receiver_attr.h" +#include "io/udp/ecal_udp_sender_attr.h" + +#include "registration/udp/attributes/registration_sender_udp_attributes.h" +#include "registration/udp/attributes/registration_receiver_udp_attributes.h" + +namespace eCAL +{ + namespace Registration + { + namespace UDP + { + eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes (const Registration::UDP::SSenderAttributes& sender_attr_); + eCAL::UDP::SReceiverAttr ConvertToIOUDPReceiverAttributes (const Registration::UDP::SReceiverAttributes& receiver_attr_); + } + } +} \ No newline at end of file diff --git a/ecal/core/src/registration/udp/ecal_registration_receiver_udp.cpp b/ecal/core/src/registration/udp/ecal_registration_receiver_udp.cpp index 0ec879a0f1..d1f0acd9ad 100644 --- a/ecal/core/src/registration/udp/ecal_registration_receiver_udp.cpp +++ b/ecal/core/src/registration/udp/ecal_registration_receiver_udp.cpp @@ -19,34 +19,18 @@ #include "registration/udp/ecal_registration_receiver_udp.h" -#include "io/udp/ecal_udp_receiver_attr.h" #include "io/udp/ecal_udp_sample_receiver.h" #include "io/udp/ecal_udp_configurations.h" #include "serialization/ecal_serialize_sample_registration.h" #include -namespace -{ - using namespace eCAL; - UDP::SReceiverAttr CreateAttributes() - { - // set network attributes - eCAL::UDP::SReceiverAttr attr; - attr.address = UDP::GetRegistrationAddress(); - attr.port = UDP::GetRegistrationPort(); - attr.broadcast = UDP::IsBroadcast(); - attr.loopback = true; - attr.rcvbuf = UDP::GetReceiveBufferSize(); - return attr; - } - -} +#include "registration/udp/builder/udp_attribute_builder.h" using namespace eCAL; -eCAL::CRegistrationReceiverUDP::CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback) +eCAL::CRegistrationReceiverUDP::CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::UDP::SReceiverAttributes& attr_) : m_registration_receiver(std::make_unique( - CreateAttributes(), + Registration::UDP::ConvertToIOUDPReceiverAttributes(attr_), [](const std::string& sample_name_) {return true; }, [apply_sample_callback](const char* serialized_sample_data_, size_t serialized_sample_size_) { Registration::Sample sample; diff --git a/ecal/core/src/registration/udp/ecal_registration_receiver_udp.h b/ecal/core/src/registration/udp/ecal_registration_receiver_udp.h index d547d2fe1f..bcbe66fa4d 100644 --- a/ecal/core/src/registration/udp/ecal_registration_receiver_udp.h +++ b/ecal/core/src/registration/udp/ecal_registration_receiver_udp.h @@ -26,6 +26,7 @@ #include #include +#include "registration/udp/attributes/registration_receiver_udp_attributes.h" namespace eCAL { @@ -37,7 +38,7 @@ namespace eCAL class CRegistrationReceiverUDP { public: - CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback); + CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::UDP::SReceiverAttributes& attr_); ~CRegistrationReceiverUDP(); // Special member functionss diff --git a/ecal/core/src/registration/udp/ecal_registration_sender_udp.cpp b/ecal/core/src/registration/udp/ecal_registration_sender_udp.cpp index ab8d5feda2..936efead72 100644 --- a/ecal/core/src/registration/udp/ecal_registration_sender_udp.cpp +++ b/ecal/core/src/registration/udp/ecal_registration_sender_udp.cpp @@ -32,27 +32,12 @@ #include "io/udp/ecal_udp_configurations.h" #include -namespace -{ - using namespace eCAL; - UDP::SSenderAttr CreateAttributes() - { - eCAL::UDP::SSenderAttr attr; - attr.address = UDP::GetRegistrationAddress(); - attr.port = UDP::GetRegistrationPort(); - attr.ttl = UDP::GetMulticastTtl(); - attr.broadcast = UDP::IsBroadcast(); - attr.loopback = true; - attr.sndbuf = UDP::GetSendBufferSize(); - return attr; - } - -} +#include "registration/udp/builder/udp_attribute_builder.h" namespace eCAL { - CRegistrationSenderUDP::CRegistrationSenderUDP() - : m_reg_sample_snd(CreateAttributes()) + CRegistrationSenderUDP::CRegistrationSenderUDP(const eCAL::Registration::UDP::SSenderAttributes& attr_) + : m_reg_sample_snd(Registration::UDP::ConvertToIOUDPSenderAttributes(attr_)) { } diff --git a/ecal/core/src/registration/udp/ecal_registration_sender_udp.h b/ecal/core/src/registration/udp/ecal_registration_sender_udp.h index ad49e8edf1..c0a8e12511 100644 --- a/ecal/core/src/registration/udp/ecal_registration_sender_udp.h +++ b/ecal/core/src/registration/udp/ecal_registration_sender_udp.h @@ -29,13 +29,14 @@ #include "registration/ecal_registration_sender.h" #include "io/udp/ecal_udp_sample_sender.h" +#include "registration/udp/attributes/registration_sender_udp_attributes.h" namespace eCAL { class CRegistrationSenderUDP : public CRegistrationSender { public: - CRegistrationSenderUDP(); + CRegistrationSenderUDP(const eCAL::Registration::UDP::SSenderAttributes& attr_); ~CRegistrationSenderUDP() override; // Special member functionss diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 00d1c62260..e6fe22c541 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -79,7 +79,7 @@ namespace eCAL std::string IpAddressV4::Get() const { return m_ip_address; } IpAddressV4& IpAddressV4::operator=(const std::string& ip_string_) { this->validateIpString(ip_string_); return *this; } IpAddressV4& IpAddressV4::operator=(const char* ip_string_) { this->validateIpString(ip_string_); return *this; } - IpAddressV4::operator std::string() { return m_ip_address; } + IpAddressV4::operator std::string() const { return m_ip_address; } std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.Get(); return os; }