From 08a6defb825690b0d2ab7b6f3c5ccc92051623c0 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:17:37 +0200 Subject: [PATCH] Added SAttr + -builder to Registration. --- ecal/core/CMakeLists.txt | 11 +++ .../registration_attribute_builder.cpp | 53 ++++++++++++ .../builder/registration_attribute_builder.h | 33 ++++++++ .../src/config/ecal_config_initializer.cpp | 20 ++--- ecal/core/src/ecal_globals.cpp | 7 +- .../attributes/registration_attr.h | 68 +++++++++++++++ .../attributes/sample_applier_attr.h | 42 ++++++++++ .../sample_applier_attribute_builder.cpp | 41 +++++++++ .../sample_applier_attribute_builder.h | 37 ++++++++ .../builder/udp_shm_attribute_builder.cpp | 84 +++++++++++++++++++ .../builder/udp_shm_attribute_builder.h | 33 ++++++++ .../ecal_registration_provider.cpp | 42 ++-------- .../registration/ecal_registration_provider.h | 6 +- .../ecal_registration_receiver.cpp | 46 +++------- .../registration/ecal_registration_receiver.h | 10 +-- .../ecal_registration_sample_applier.cpp | 15 ++-- .../ecal_registration_sample_applier.h | 6 +- .../registration_memfile_broadcast_attr.h | 40 +++++++++ .../shm/ecal_memfile_broadcast.cpp | 12 +-- .../registration/shm/ecal_memfile_broadcast.h | 6 +- .../shm/ecal_registration_receiver_shm.cpp | 4 +- .../shm/ecal_registration_receiver_shm.h | 4 +- .../shm/ecal_registration_sender_shm.cpp | 6 +- .../shm/ecal_registration_sender_shm.h | 4 +- .../attributes/registration_sender_udp_attr.h | 37 ++++++++ 25 files changed, 549 insertions(+), 118 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/registration/attributes/registration_attr.h create mode 100644 ecal/core/src/registration/attributes/sample_applier_attr.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_memfile_broadcast_attr.h create mode 100644 ecal/core/src/registration/udp/attributes/registration_sender_udp_attr.h diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index d8604be651..d40a1b01d1 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -444,6 +444,16 @@ 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 +) + + ###################################### # c interface ###################################### @@ -565,6 +575,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/src/builder/registration_attribute_builder.cpp b/ecal/core/src/builder/registration_attribute_builder.cpp new file mode 100644 index 0000000000..60c90fb83a --- /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::SAttr BuildRegistrationAttr(eCAL::Registration::Configuration reg_config_, eCAL::TransportLayer::UDP::Configuration tl_udp_confi_, int process_id_) + { + Registration::SAttr 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..5eb17316ce --- /dev/null +++ b/ecal/core/src/builder/registration_attribute_builder.h @@ -0,0 +1,33 @@ +/* ========================= 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 ================================= +*/ + +#ifndef REGISTRATION_BUILDER_H +#define REGISTRATION_BUILDER_H + +#include "registration/attributes/registration_attr.h" + +#include + +namespace eCAL +{ + Registration::SAttr BuildRegistrationAttr(eCAL::Registration::Configuration reg_config_, eCAL::TransportLayer::UDP::Configuration tl_udp_confi_, int process_id_); +} + + +#endif // REGISTRATION_BUILDER_H \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 39f3f0dcb3..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,47 +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/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index b221977b0a..248d5a87c6 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 + Registration::SAttr registration_attr = BuildRegistrationAttr(GetConfiguration().registration, GetConfiguration().transport_layer.udp, eCAL::Process::GetProcessID()); ///////////////////// // REGISTRATION PROVIDER ///////////////////// if (registration_provider_instance == nullptr) { - registration_provider_instance = std::make_unique(eCAL::GetRegistrationConfiguration()); + 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(eCAL::GetRegistrationConfiguration()); + registration_receiver_instance = std::make_unique(registration_attr); new_initialization = true; } #endif // ECAL_CORE_REGISTRATION diff --git a/ecal/core/src/registration/attributes/registration_attr.h b/ecal/core/src/registration/attributes/registration_attr.h new file mode 100644 index 0000000000..a912ef013d --- /dev/null +++ b/ecal/core/src/registration/attributes/registration_attr.h @@ -0,0 +1,68 @@ +/* ========================= 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 ================================= +*/ + +#ifndef REGISTRATION_PROVIDER_ATTR_H +#define REGISTRATION_PROVIDER_ATTR_H + +#include +#include + +namespace eCAL +{ + namespace Registration + { + struct SUDPModeAttr + { + std::string group; + int ttl; + }; + + struct SUDPAttr + { + Types::UDPMode mode; + int port; + int sendbuffer; + int receivebuffer; + SUDPModeAttr network; + SUDPModeAttr local; + }; + + struct SSHMAttr + { + std::string domain; + size_t queue_size; + }; + + struct SAttr + { + bool network_enabled; + bool loopback; + bool shm_enabled; + bool udp_enabled; + unsigned int refresh; + std::string host_group_name; + int process_id; + + SUDPAttr udp; + SSHMAttr shm; + }; + } +} + +#endif // REGISTRATION_PROVIDER_ATTR_H \ No newline at end of file diff --git a/ecal/core/src/registration/attributes/sample_applier_attr.h b/ecal/core/src/registration/attributes/sample_applier_attr.h new file mode 100644 index 0000000000..22fbadf1ce --- /dev/null +++ b/ecal/core/src/registration/attributes/sample_applier_attr.h @@ -0,0 +1,42 @@ +/* ========================= 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 ================================= +*/ + +#ifndef SAMPLE_APPLIER_ATTR_H +#define SAMPLE_APPLIER_ATTR_H + +#include + +namespace eCAL +{ + namespace Registration + { + namespace SampleApplier + { + struct SAttr + { + bool network_enabled; + bool loopback; + std::string host_group_name; + int process_id; + }; + } + } +} + +#endif // SAMPLE_APPLIER_ATTR_H \ 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..a6eb934d93 --- /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 + { + SAttr BuildSampleApplierAttr(const Registration::SAttr& attr_) + { + SAttr 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..8f03142ada --- /dev/null +++ b/ecal/core/src/registration/builder/sample_applier_attribute_builder.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 ================================= +*/ + +#ifndef SAMPLE_APPLIER_ATTRIBUTE_BUILDER_H +#define SAMPLE_APPLIER_ATTRIBUTE_BUILDER_H + +#include "registration/attributes/registration_attr.h" +#include "registration/attributes/sample_applier_attr.h" + +namespace eCAL +{ + namespace Registration + { + namespace SampleApplier + { + SAttr BuildSampleApplierAttr(const Registration::SAttr& attr_); + } + } +} + +#endif // SAMPLE_APPLIER_ATTRIBUTE_BUILDER_H \ No newline at end of file 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..09796d9564 --- /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::SSenderAttr BuildUDPSenderAttr(const SAttr& provider_attr_) + { + UDP::SSenderAttr 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::SReceiverAttr BuildUDPReceiverAttr(const SAttr& provider_attr_) + { + UDP::SReceiverAttr 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::SMemfileBroadcastAttr BuildSHMMemfileBroadcastAttr(const SAttr& provider_attr_) + { + SHM::SMemfileBroadcastAttr 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..9d2aee52b1 --- /dev/null +++ b/ecal/core/src/registration/builder/udp_shm_attribute_builder.h @@ -0,0 +1,33 @@ +/* ========================= 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 "io/udp/ecal_udp_sender_attr.h" +#include "io/udp/ecal_udp_receiver_attr.h" +#include "registration/shm/attributes/registration_memfile_broadcast_attr.h" +#include "registration/attributes/registration_attr.h" + +namespace eCAL +{ + namespace Registration + { + UDP::SSenderAttr BuildUDPSenderAttr (const SAttr& provider_attr_); + UDP::SReceiverAttr BuildUDPReceiverAttr (const SAttr& provider_attr_); + SHM::SMemfileBroadcastAttr BuildSHMMemfileBroadcastAttr (const SAttr& 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 bc2cead737..6eabe61ac3 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -37,7 +37,6 @@ #include #include #include "ecal_def.h" -#include "io/udp/ecal_udp_sender_attr.h" #include #include @@ -45,40 +44,15 @@ #include #endif -namespace -{ - using namespace eCAL; - UDP::SSenderAttr CreateUDPSenderAttr(const Registration::Configuration& config_) - { - UDP::SSenderAttr attr; - attr.broadcast = !config_.network_enabled; - attr.port = config_.layer.udp.port; - - auto& config = GetConfiguration(); - attr.loopback = true; - attr.sndbuf = config.transport_layer.udp.send_buffer; - - if (config.transport_layer.udp.mode == Types::UDPMode::NETWORK) - { - attr.address = config.transport_layer.udp.network.group; - attr.ttl = config.transport_layer.udp.network.ttl; - } else - { - attr.address = config.transport_layer.udp.local.group; - attr.ttl = config.transport_layer.udp.local.ttl; - } - - return attr; - } +#include "builder/udp_shm_attribute_builder.h" -} namespace eCAL { std::atomic CRegistrationProvider::m_created; - CRegistrationProvider::CRegistrationProvider(const Registration::Configuration& config_) : - m_config(config_) + CRegistrationProvider::CRegistrationProvider(const Registration::SAttr& attr_) : + m_attributes(attr_) { } @@ -93,14 +67,14 @@ namespace eCAL // TODO Create the registration sender #if ECAL_CORE_REGISTRATION_SHM - if (m_config.layer.shm.enable) + if (m_attributes.shm_enabled) { - m_reg_sender = std::make_unique(m_config.layer.shm); + m_reg_sender = std::make_unique(Registration::BuildSHMMemfileBroadcastAttr(m_attributes)); } else #endif - if (m_config.layer.udp.enable) + if (m_attributes.udp_enabled) { - m_reg_sender = std::make_unique(CreateUDPSenderAttr(m_config)); + m_reg_sender = std::make_unique(Registration::BuildUDPSenderAttr(m_attributes)); } else { @@ -110,7 +84,7 @@ namespace eCAL // 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(m_config.registration_refresh)); + 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 186c74b181..d6fdce7d66 100644 --- a/ecal/core/src/registration/ecal_registration_provider.h +++ b/ecal/core/src/registration/ecal_registration_provider.h @@ -31,7 +31,7 @@ #include "registration/ecal_registration_sender.h" #include "util/ecal_thread.h" -#include +#include "attributes/registration_attr.h" #include #include @@ -41,7 +41,7 @@ namespace eCAL class CRegistrationProvider { public: - CRegistrationProvider(const Registration::Configuration& config_); + CRegistrationProvider(const Registration::SAttr& attr_); ~CRegistrationProvider(); void Start(); @@ -62,6 +62,6 @@ namespace eCAL std::mutex m_applied_sample_list_mtx; Registration::SampleList m_applied_sample_list; - Registration::Configuration m_config; + Registration::SAttr m_attributes; }; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index bafb845c3f..cd08f6deb6 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -35,7 +35,6 @@ #include "registration/shm/ecal_registration_receiver_shm.h" #endif #include "io/udp/ecal_udp_configurations.h" -#include "io/udp/ecal_udp_receiver_attr.h" #include #include #include @@ -43,31 +42,8 @@ #include #include -namespace -{ - using namespace eCAL; - UDP::SReceiverAttr CreateUDPReceiverAttr(const Registration::Configuration& config_) - { - // set network attributes - UDP::SReceiverAttr attr; - attr.port = config_.layer.udp.port; - attr.broadcast = !config_.network_enabled; - - auto& config = GetConfiguration(); - attr.rcvbuf = config.transport_layer.udp.receive_buffer; - attr.loopback = true; - - if (config.transport_layer.udp.mode == Types::UDPMode::NETWORK) - { - attr.address = config.transport_layer.udp.network.group; - } else - { - attr.address = config.transport_layer.udp.local.group; - } - return attr; - } - -} +#include "builder/udp_shm_attribute_builder.h" +#include "builder/sample_applier_attribute_builder.h" namespace eCAL { @@ -76,13 +52,13 @@ namespace eCAL ////////////////////////////////////////////////////////////////// std::atomic CRegistrationReceiver::m_created; - CRegistrationReceiver::CRegistrationReceiver(const Registration::Configuration& config_) + CRegistrationReceiver::CRegistrationReceiver(const Registration::SAttr& attr_) : m_timeout_provider(nullptr) , m_timeout_provider_thread(nullptr) , m_registration_receiver_udp(nullptr) , m_registration_receiver_shm(nullptr) - , m_config(config_) - , m_sample_applier(config_, Process::GetProcessID()) + , m_attributes(attr_) + , m_sample_applier(Registration::SampleApplier::BuildSampleApplierAttr(attr_)) { // Connect User registration callback and gates callback with the sample applier m_sample_applier.SetCustomApplySampleCallback("gates", [](const eCAL::Registration::Sample& sample_) @@ -137,15 +113,15 @@ namespace eCAL m_timeout_provider_thread->start(std::chrono::milliseconds(100)); // Why do we have here different behaviour than in the registration provider? - if (m_config.layer.udp.enable) + if (m_attributes.udp_enabled) { - m_registration_receiver_udp = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_);}, CreateUDPReceiverAttr(m_config)); + m_registration_receiver_udp = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_);}, Registration::BuildUDPReceiverAttr(m_attributes)); } #if ECAL_CORE_REGISTRATION_SHM - if (m_config.layer.shm.enable) + if (m_attributes.shm_enabled) { - m_registration_receiver_shm = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }, m_config.layer.shm); + m_registration_receiver_shm = std::make_unique([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }, Registration::BuildSHMMemfileBroadcastAttr(m_attributes)); } #endif @@ -157,13 +133,13 @@ namespace eCAL if(!m_created) return; // stop network registration receive thread - if (m_config.layer.udp.enable) + if (m_attributes.udp_enabled) { m_registration_receiver_udp = nullptr; } #if ECAL_CORE_REGISTRATION_SHM - if (m_config.layer.shm.enable) + 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 2c1dc6062c..05642de34e 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.h +++ b/ecal/core/src/registration/ecal_registration_receiver.h @@ -34,7 +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 "ecal/config/registration.h" +#include "attributes/registration_attr.h" #include #include @@ -59,7 +59,7 @@ namespace eCAL class CRegistrationReceiver { public: - CRegistrationReceiver(const Registration::Configuration& config_); + CRegistrationReceiver(const Registration::SAttr& attr_); ~CRegistrationReceiver(); //what about the rest of the rule of 5? @@ -90,13 +90,13 @@ namespace eCAL #endif // 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::Configuration m_config; + Registration::SAttr 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 27c41006bc..60b0cb00ab 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.cpp +++ b/ecal/core/src/registration/ecal_registration_sample_applier.cpp @@ -26,15 +26,14 @@ namespace eCAL ////////////////////////////////////////////////////////////////// // CSampleApplier ////////////////////////////////////////////////////////////////// - CSampleApplier::CSampleApplier(const eCAL::Registration::Configuration& config_, uint32_t pid) - : m_config(config_) - , m_pid(pid) + CSampleApplier::CSampleApplier(const SampleApplier::SAttr& attr_) + : m_attributes(attr_) { } void CSampleApplier::EnableLoopback(bool state_) { - m_config.loopback = state_; + m_attributes.loopback = state_; } bool CSampleApplier::ApplySample(const Registration::Sample& sample_) @@ -82,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_config.host_group_name.empty()) + if (sample_host_group_name.empty() || m_attributes.host_group_name.empty()) return false; - if (sample_host_group_name != m_config.host_group_name) + if (sample_host_group_name != m_attributes.host_group_name) return false; return true; @@ -104,12 +103,12 @@ namespace eCAL { // register if the sample is from another process // or if loopback mode is enabled - return !IsSameProcess(sample_) || m_config.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_config.network_enabled; + 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 9eaa0f9491..e8936f65ee 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.h +++ b/ecal/core/src/registration/ecal_registration_sample_applier.h @@ -29,7 +29,7 @@ #include #include "serialization/ecal_struct_sample_registration.h" -#include "ecal/config/registration.h" +#include "attributes/sample_applier_attr.h" #include #include @@ -43,7 +43,7 @@ namespace eCAL class CSampleApplier { public: - CSampleApplier(const eCAL::Registration::Configuration& config_, uint32_t pid); + CSampleApplier(const SampleApplier::SAttr& attr_); // to be removed for eCAL 6, but keep until eCAL 5.14 void EnableLoopback(bool state_); @@ -59,7 +59,7 @@ namespace eCAL bool AcceptRegistrationSample(const Registration::Sample& sample_); - eCAL::Registration::Configuration m_config; + SampleApplier::SAttr m_attributes; int32_t m_pid; std::mutex m_callback_custom_apply_sample_map_mtx; diff --git a/ecal/core/src/registration/shm/attributes/registration_memfile_broadcast_attr.h b/ecal/core/src/registration/shm/attributes/registration_memfile_broadcast_attr.h new file mode 100644 index 0000000000..40f05cddbc --- /dev/null +++ b/ecal/core/src/registration/shm/attributes/registration_memfile_broadcast_attr.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 ================================= +*/ + +#ifndef REGISTRATION_MEMFILE_BROADCAST_ATTR_H +#define REGISTRATION_MEMFILE_BROADCAST_ATTR_H + +#include + +namespace eCAL +{ + namespace Registration + { + namespace SHM + { + struct SMemfileBroadcastAttr + { + std::string domain; + unsigned int queue_size; + }; + } + } +} + +#endif // REGISTRATION_MEMFILE_BROADCAST_ATTR_H \ No newline at end of file diff --git a/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp b/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp index 4552ddbb9f..3522b7a07d 100644 --- a/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp +++ b/ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp @@ -63,16 +63,16 @@ namespace eCAL { } - bool CMemoryFileBroadcast::Create(const Registration::Layer::SHM::Configuration& config_) + bool CMemoryFileBroadcast::Create(const Registration::SHM::SMemfileBroadcastAttr& attr_) { if (m_created) return false; - m_config = config_; + m_attributes = attr_; const auto presumably_memfile_size = - RelocatableCircularQueue::PresumablyOccupiedMemorySize(m_config.queue_size) + + RelocatableCircularQueue::PresumablyOccupiedMemorySize(m_attributes.queue_size) + sizeof(SMemfileBroadcastHeader); - if (!m_broadcast_memfile->Create(m_config.domain.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_config.domain; + 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_config.queue_size); + m_event_queue.Reset(m_attributes.queue_size); #ifndef NDEBUG std::cout << "Broadcast memory file has been resetted" << std::endl; #endif diff --git a/ecal/core/src/registration/shm/ecal_memfile_broadcast.h b/ecal/core/src/registration/shm/ecal_memfile_broadcast.h index 6770fb1f36..950087784e 100644 --- a/ecal/core/src/registration/shm/ecal_memfile_broadcast.h +++ b/ecal/core/src/registration/shm/ecal_memfile_broadcast.h @@ -32,9 +32,9 @@ #include "relocatable_circular_queue.h" #include "io/shm/ecal_memfile.h" +#include "attributes/registration_memfile_broadcast_attr.h" #include -#include namespace eCAL { @@ -80,7 +80,7 @@ namespace eCAL public: CMemoryFileBroadcast(); - bool Create(const Registration::Layer::SHM::Configuration& config_); + bool Create(const Registration::SHM::SMemfileBroadcastAttr& attr_); bool Destroy(); std::string GetName() const; @@ -96,7 +96,7 @@ namespace eCAL void ResetMemfile(void * memfile_address); bool m_created; - Registration::Layer::SHM::Configuration m_config; + Registration::SHM::SMemfileBroadcastAttr 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 cf0dc6ffb3..2fcc899cc9 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, const Registration::Layer::SHM::Configuration& config_) + CRegistrationReceiverSHM::CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::SHM::SMemfileBroadcastAttr& attr_) : m_apply_sample_callback(apply_sample_callback) { m_memfile_broadcast = std::make_unique(); - m_memfile_broadcast->Create(config_); + 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 e0aa5cb59d..2d93803e92 100644 --- a/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h +++ b/ecal/core/src/registration/shm/ecal_registration_receiver_shm.h @@ -29,7 +29,7 @@ #include #include -#include +#include "attributes/registration_memfile_broadcast_attr.h" namespace eCAL { @@ -40,7 +40,7 @@ namespace eCAL class CRegistrationReceiverSHM { public: - CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::Layer::SHM::Configuration& config_); + CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::SHM::SMemfileBroadcastAttr& 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 44b089e9b7..a29554d2a1 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(const Registration::Layer::SHM::Configuration& config_) +eCAL::CRegistrationSenderSHM::CRegistrationSenderSHM(const Registration::SHM::SMemfileBroadcastAttr& attr_) { - std::cout << "Shared memory monitoring is enabled (domain: " << config_.domain << " - queue size: " << config_.queue_size << ")" << '\n'; - m_memfile_broadcast.Create(config_); + 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 2af6913b16..ae88525540 100644 --- a/ecal/core/src/registration/shm/ecal_registration_sender_shm.h +++ b/ecal/core/src/registration/shm/ecal_registration_sender_shm.h @@ -33,14 +33,14 @@ #include "registration/shm/ecal_memfile_broadcast.h" #include "registration/shm/ecal_memfile_broadcast_writer.h" -#include +#include "attributes/registration_memfile_broadcast_attr.h" namespace eCAL { class CRegistrationSenderSHM : public CRegistrationSender { public: - CRegistrationSenderSHM(const Registration::Layer::SHM::Configuration& config_); + CRegistrationSenderSHM(const Registration::SHM::SMemfileBroadcastAttr& attr_); ~CRegistrationSenderSHM() override; // Special member functionss diff --git a/ecal/core/src/registration/udp/attributes/registration_sender_udp_attr.h b/ecal/core/src/registration/udp/attributes/registration_sender_udp_attr.h new file mode 100644 index 0000000000..ce3b936fcc --- /dev/null +++ b/ecal/core/src/registration/udp/attributes/registration_sender_udp_attr.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 ================================= +*/ + +#ifndef REGISTRATION_SENDER_UDP_ATTR_H +#define REGISTRATION_SENDER_UDP_ATTR_H + +namespace eCAL +{ + namespace Registration + { + namespace UDP + { + struct SSenderAttr + { + + }; + } + } +} + +#endif // REGISTRATION_SENDER_UDP_ATTR_H \ No newline at end of file