diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 2400f00848..4f9e7eeeeb 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -425,7 +425,6 @@ endif() # common ###################################### set(ecal_cmn_src - src/config/builder/monitoring_attribute_builder.cpp src/ecal.cpp src/ecal_def.h src/ecal_def_ini.h @@ -456,6 +455,13 @@ set (ecal_builder_src src/config/builder/monitoring_attribute_builder.cpp src/config/builder/registration_attribute_builder.cpp src/logging/config/builder/udp_attribute_builder.cpp + src/pubsub/config/builder/reader_attribute_builder.cpp + src/pubsub/config/builder/writer_attribute_builder.cpp + src/readwrite/config/builder/shm_attribute_builder.cpp + src/readwrite/config/builder/tcp_attribute_builder.cpp + src/readwrite/config/builder/udp_attribute_builder.cpp + src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.cpp + src/readwrite/udp/config/builder/udp_attribute_builder.cpp src/registration/config/builder/udp_shm_attribute_builder.cpp src/registration/config/builder/sample_applier_attribute_builder.cpp src/registration/udp/config/builder/udp_attribute_builder.cpp diff --git a/ecal/core/src/pubsub/config/builder/reader_attribute_builder.cpp b/ecal/core/src/pubsub/config/builder/reader_attribute_builder.cpp new file mode 100644 index 0000000000..5425951fa2 --- /dev/null +++ b/ecal/core/src/pubsub/config/builder/reader_attribute_builder.cpp @@ -0,0 +1,60 @@ +/* ========================= 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 "reader_attribute_builder.h" +#include "ecal/ecal_process.h" + +namespace eCAL +{ + eCALReader::SAttributes BuildReaderAttributes(const std::string& topic_name_, const Subscriber::Configuration& sub_config_, const Publisher::Configuration& pub_config_, const eCAL::TransportLayer::Configuration& tl_config_, const eCAL::Registration::Configuration& reg_config_) + { + eCALReader::SAttributes attributes; + + attributes.network_enabled = reg_config_.network_enabled; + attributes.loopback = reg_config_.loopback; + attributes.drop_out_of_order_messages = sub_config_.drop_out_of_order_messages; + attributes.registation_timeout_ms = reg_config_.registration_timeout; + attributes.topic_name = topic_name_; + attributes.host_name = Process::GetHostName(); + attributes.host_group_name = Process::GetHostGroupName(); + attributes.process_id = Process::GetProcessID(); + attributes.process_name = Process::GetProcessName(); + attributes.share_topic_type = pub_config_.share_topic_type; + attributes.share_topic_description = pub_config_.share_topic_description; + + attributes.udp.enable = sub_config_.layer.udp.enable; + attributes.udp.mode = tl_config_.udp.mode; + attributes.udp.port = tl_config_.udp.port; + attributes.udp.receivebuffer = tl_config_.udp.receive_buffer; + + attributes.udp.local.group = tl_config_.udp.local.group; + + attributes.udp.network.group = tl_config_.udp.network.group; + + attributes.tcp.enable = sub_config_.layer.tcp.enable; + attributes.tcp.thread_pool_size = tl_config_.tcp.number_executor_reader; + attributes.tcp.max_reconnection_attempts = tl_config_.tcp.max_reconnections; + + attributes.shm.enable = sub_config_.layer.shm.enable; + + return attributes; + } +} \ No newline at end of file diff --git a/ecal/core/src/pubsub/config/builder/reader_attribute_builder.h b/ecal/core/src/pubsub/config/builder/reader_attribute_builder.h new file mode 100644 index 0000000000..2aaa48b169 --- /dev/null +++ b/ecal/core/src/pubsub/config/builder/reader_attribute_builder.h @@ -0,0 +1,31 @@ +/* ========================= 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 "readwrite/config/attributes/reader_attributes.h" +#include "ecal/config/subscriber.h" +#include "ecal/config/transport_layer.h" +#include "ecal/config/registration.h" +#include "ecal/config/publisher.h" + +namespace eCAL +{ + eCALReader::SAttributes BuildReaderAttributes(const std::string& topic_name_, const Subscriber::Configuration& sub_config_, const Publisher::Configuration& pub_config_, const eCAL::TransportLayer::Configuration& tl_config_, const eCAL::Registration::Configuration& reg_config_); +} \ No newline at end of file diff --git a/ecal/core/src/pubsub/config/builder/writer_attribute_builder.cpp b/ecal/core/src/pubsub/config/builder/writer_attribute_builder.cpp new file mode 100644 index 0000000000..630d05bad9 --- /dev/null +++ b/ecal/core/src/pubsub/config/builder/writer_attribute_builder.cpp @@ -0,0 +1,70 @@ +/* ========================= 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 "writer_attribute_builder.h" +#include "ecal/ecal_process.h" + +namespace eCAL +{ + eCALWriter::SAttributes BuildWriterAttributes(const std::string& topic_name_, const Publisher::Configuration& pub_config_, const eCAL::TransportLayer::Configuration& tl_config_, const eCAL::Registration::Configuration& reg_config_) + { + eCALWriter::SAttributes attributes; + + attributes.network_enabled = reg_config_.network_enabled; + attributes.loopback = reg_config_.loopback; + + attributes.share_topic_type = pub_config_.share_topic_type; + attributes.share_topic_description = pub_config_.share_topic_description; + attributes.layer_priority_local = pub_config_.layer_priority_local; + attributes.layer_priority_remote = pub_config_.layer_priority_remote; + + attributes.host_name = Process::GetHostName(); + attributes.host_group_name = Process::GetHostGroupName(); + attributes.process_id = Process::GetProcessID(); + attributes.process_name = Process::GetProcessName(); + + attributes.unit_name = Process::GetUnitName(); + attributes.topic_name = topic_name_; + + attributes.shm.enable = pub_config_.layer.shm.enable; + attributes.shm.acknowledge_timeout_ms = pub_config_.layer.shm.acknowledge_timeout_ms; + attributes.shm.memfile_buffer_count = pub_config_.layer.shm.memfile_buffer_count; + attributes.shm.memfile_min_size_bytes = pub_config_.layer.shm.memfile_min_size_bytes; + attributes.shm.memfile_reserve_percent = pub_config_.layer.shm.memfile_reserve_percent; + attributes.shm.zero_copy_mode = pub_config_.layer.shm.zero_copy_mode; + + attributes.udp.enable = pub_config_.layer.udp.enable; + attributes.udp.port = tl_config_.udp.port; + attributes.udp.send_buffer = tl_config_.udp.send_buffer; + attributes.udp.mode = tl_config_.udp.mode; + + attributes.udp.network.group = tl_config_.udp.network.group; + attributes.udp.network.ttl = tl_config_.udp.network.ttl; + + attributes.udp.local.group = tl_config_.udp.local.group; + attributes.udp.local.ttl = tl_config_.udp.local.ttl; + + attributes.tcp.enable = pub_config_.layer.tcp.enable; + attributes.tcp.thread_pool_size = tl_config_.tcp.number_executor_writer; + + return attributes; + } +} \ No newline at end of file diff --git a/ecal/core/src/pubsub/config/builder/writer_attribute_builder.h b/ecal/core/src/pubsub/config/builder/writer_attribute_builder.h new file mode 100644 index 0000000000..dcc54baeb5 --- /dev/null +++ b/ecal/core/src/pubsub/config/builder/writer_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 "readwrite/config/attributes/writer_attributes.h" +#include "ecal/config/publisher.h" +#include "ecal/config/registration.h" + +namespace eCAL +{ + eCALWriter::SAttributes BuildWriterAttributes(const std::string& topic_name_, const Publisher::Configuration& config_, const eCAL::TransportLayer::Configuration& tl_config_, const eCAL::Registration::Configuration& reg_config_); +} \ No newline at end of file diff --git a/ecal/core/src/pubsub/ecal_publisher.cpp b/ecal/core/src/pubsub/ecal_publisher.cpp index 86610c8a12..5dbd7736f6 100644 --- a/ecal/core/src/pubsub/ecal_publisher.cpp +++ b/ecal/core/src/pubsub/ecal_publisher.cpp @@ -27,6 +27,9 @@ #include "readwrite/ecal_writer.h" #include "readwrite/ecal_writer_buffer_payload.h" +#include "config/builder/writer_attribute_builder.h" +#include "ecal/ecal_config.h" + #include #include #include @@ -91,7 +94,7 @@ namespace eCAL if (topic_name_.empty()) return(false); // create datawriter - m_datawriter = std::make_shared(topic_name_, data_type_info_, config_); + m_datawriter = std::make_shared(data_type_info_, BuildWriterAttributes(topic_name_, config_, GetTransportLayerConfiguration(), GetRegistrationConfiguration())); // register datawriter g_pubgate()->Register(topic_name_, m_datawriter); diff --git a/ecal/core/src/pubsub/ecal_subscriber.cpp b/ecal/core/src/pubsub/ecal_subscriber.cpp index 2dac129762..bb2340812f 100644 --- a/ecal/core/src/pubsub/ecal_subscriber.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber.cpp @@ -25,6 +25,7 @@ #include "ecal_globals.h" #include "readwrite/ecal_reader.h" +#include "config/builder/reader_attribute_builder.h" #include #include @@ -81,7 +82,7 @@ namespace eCAL if (topic_name_.empty()) return(false); // create datareader - m_datareader = std::make_shared(topic_name_, data_type_info_, config_); + m_datareader = std::make_shared(data_type_info_, BuildReaderAttributes(topic_name_, config_, GetPublisherConfiguration(), GetTransportLayerConfiguration(), GetRegistrationConfiguration())); // register datareader g_subgate()->Register(topic_name_, m_datareader); diff --git a/ecal/core/src/readwrite/config/attributes/reader_attributes.h b/ecal/core/src/readwrite/config/attributes/reader_attributes.h new file mode 100644 index 0000000000..0d8ad85e1a --- /dev/null +++ b/ecal/core/src/readwrite/config/attributes/reader_attributes.h @@ -0,0 +1,78 @@ +/* ========================= 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 +#include "ecal/types/ecal_custom_data_types.h" + +namespace eCAL +{ + namespace eCALReader + { + struct SUDPModeAttributes + { + std::string group; + }; + + struct SUDPAttributes + { + bool enable; + Types::UDPMode mode; + int port; + int receivebuffer; + SUDPModeAttributes network; + SUDPModeAttributes local; + }; + + struct STCPAttributes + { + bool enable; + size_t thread_pool_size; + int max_reconnection_attempts; + }; + + struct SSHMAttributes + { + bool enable; + }; + + struct SAttributes + { + bool network_enabled; + bool drop_out_of_order_messages; + bool loopback; + unsigned int registation_timeout_ms; + + SUDPAttributes udp; + STCPAttributes tcp; + SSHMAttributes shm; + + std::string topic_name; + std::string host_name; + std::string host_group_name; + int process_id; + std::string process_name; + std::string unit_name; + bool share_topic_type; + bool share_topic_description; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/attributes/writer_attributes.h b/ecal/core/src/readwrite/config/attributes/writer_attributes.h new file mode 100644 index 0000000000..36257241df --- /dev/null +++ b/ecal/core/src/readwrite/config/attributes/writer_attributes.h @@ -0,0 +1,92 @@ +/* ========================= 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 +#include + +#include + +#include "ecal/types/ecal_custom_data_types.h" + +namespace eCAL +{ + namespace eCALWriter + { + struct SUDPModeAttributes + { + std::string group; + int ttl; + }; + + struct SUDPAttributes + { + bool enable; + Types::UDPMode mode; + int port; + int send_buffer; + SUDPModeAttributes network; + SUDPModeAttributes local; + }; + + struct STCPAttributes + { + bool enable; + size_t thread_pool_size; + }; + + struct SSHMAttributes + { + bool enable; + bool zero_copy_mode; + unsigned int acknowledge_timeout_ms; + unsigned int memfile_buffer_count; + unsigned int memfile_min_size_bytes; + unsigned int memfile_reserve_percent; + }; + + + struct SAttributes + { + using LayerPriorityVector = std::vector; + LayerPriorityVector layer_priority_local; + LayerPriorityVector layer_priority_remote; + + bool share_topic_type; + bool share_topic_description; + + bool network_enabled; + bool loopback; + + std::string host_name; + std::string host_group_name; + int process_id; + std::string process_name; + + std::string unit_name; + std::string topic_name; + + SUDPAttributes udp; + STCPAttributes tcp; + SSHMAttributes shm; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/shm_attribute_builder.cpp b/ecal/core/src/readwrite/config/builder/shm_attribute_builder.cpp new file mode 100644 index 0000000000..896df078b3 --- /dev/null +++ b/ecal/core/src/readwrite/config/builder/shm_attribute_builder.cpp @@ -0,0 +1,56 @@ +/* ========================= 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 "shm_attribute_builder.h" + +namespace eCAL +{ + namespace eCALReader + { + SHM::SAttributes BuildSHMAttributes(const eCALReader::SAttributes& attr_) + { + SHM::SAttributes attributes; + + attributes.process_id = attr_.process_id; + attributes.registration_timeout_ms = attr_.registation_timeout_ms; + + return attributes; + } + } + + namespace eCALWriter + { + SHM::SAttributes BuildSHMAttributes(const eCALWriter::SAttributes& attr_) + { + SHM::SAttributes attributes; + + attributes.acknowledge_timeout_ms = attr_.shm.acknowledge_timeout_ms; + attributes.memfile_buffer_count = attr_.shm.memfile_buffer_count; + attributes.memfile_reserve_percent = attr_.shm.memfile_reserve_percent; + attributes.memfile_min_size_bytes = attr_.shm.memfile_min_size_bytes; + + attributes.topic_name = attr_.topic_name; + attributes.host_name = attr_.host_name; + + return attributes; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/shm_attribute_builder.h b/ecal/core/src/readwrite/config/builder/shm_attribute_builder.h new file mode 100644 index 0000000000..b16af644b8 --- /dev/null +++ b/ecal/core/src/readwrite/config/builder/shm_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 "readwrite/shm/config/attributes/reader_shm_attributes.h" +#include "readwrite/config/attributes/reader_attributes.h" + +#include "readwrite/shm/config/attributes/writer_shm_attributes.h" +#include "readwrite/config/attributes/writer_attributes.h" + +namespace eCAL +{ + namespace eCALReader + { + SHM::SAttributes BuildSHMAttributes(const eCALReader::SAttributes& attr_); + } + + namespace eCALWriter + { + SHM::SAttributes BuildSHMAttributes(const eCALWriter::SAttributes& attr_); + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/tcp_attribute_builder.cpp b/ecal/core/src/readwrite/config/builder/tcp_attribute_builder.cpp new file mode 100644 index 0000000000..84727d9990 --- /dev/null +++ b/ecal/core/src/readwrite/config/builder/tcp_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 ================================= +*/ + +#pragma once + +#include "tcp_attribute_builder.h" + +namespace eCAL +{ + namespace eCALReader + { + TCPLayer::SAttributes BuildTCPLayerAttributes(const eCALReader::SAttributes& attr_) + { + TCPLayer::SAttributes attributes; + + attributes.max_reconnection_attempts = attr_.tcp.max_reconnection_attempts; + attributes.thread_pool_size = attr_.tcp.thread_pool_size; + + return attributes; + } + } + + namespace eCALWriter + { + TCP::SAttributes BuildTCPAttributes(const std::string& topic_id_, const eCALWriter::SAttributes& attr_) + { + TCP::SAttributes attributes; + + attributes.topic_name = attr_.topic_name; + attributes.topic_id = topic_id_; + attributes.thread_pool_size = attr_.tcp.thread_pool_size; + + return attributes; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/tcp_attribute_builder.h b/ecal/core/src/readwrite/config/builder/tcp_attribute_builder.h new file mode 100644 index 0000000000..dab81def48 --- /dev/null +++ b/ecal/core/src/readwrite/config/builder/tcp_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 "readwrite/tcp/config/attributes/tcp_reader_layer_attributes.h" +#include "readwrite/config/attributes/reader_attributes.h" + +#include "readwrite/tcp/config/attributes/data_writer_tcp_attributes.h" +#include "readwrite/config/attributes/writer_attributes.h" + +namespace eCAL +{ + namespace eCALReader + { + TCPLayer::SAttributes BuildTCPLayerAttributes(const eCALReader::SAttributes& attr_); + } + + namespace eCALWriter + { + TCP::SAttributes BuildTCPAttributes(const std::string& topic_id_, const eCALWriter::SAttributes& attr_); + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/udp_attribute_builder.cpp b/ecal/core/src/readwrite/config/builder/udp_attribute_builder.cpp new file mode 100644 index 0000000000..a4fdba20fe --- /dev/null +++ b/ecal/core/src/readwrite/config/builder/udp_attribute_builder.cpp @@ -0,0 +1,88 @@ +/* ========================= 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 "udp_attribute_builder.h" +#include "ecal/types/ecal_custom_data_types.h" + +namespace eCAL +{ + namespace eCALReader + { + UDP::SAttributes BuildUDPAttributes(const eCALReader::SAttributes& attr_) + { + UDP::SAttributes attributes; + + attributes.broadcast = !attr_.network_enabled; + attributes.loopback = true; + + attributes.receive_buffer = attr_.udp.receivebuffer; + attributes.port = attr_.udp.port; + + switch (attr_.udp.mode) + { + case Types::UDPMode::NETWORK: + attributes.address = attr_.udp.network.group; + break; + case Types::UDPMode::LOCAL: + attributes.address = attr_.udp.local.group; + break; + default: + break; + } + + return attributes; + } + } + + namespace eCALWriter + { + UDP::SAttributes BuildUDPAttributes(const std::string& topic_id_, const eCALWriter::SAttributes& attr_) + { + UDP::SAttributes attributes; + + attributes.broadcast = !attr_.network_enabled; + attributes.loopback = attr_.loopback; + + attributes.topic_id = topic_id_; + attributes.topic_name = attr_.topic_name; + attributes.host_name = attr_.host_name; + + attributes.send_buffer = attr_.udp.send_buffer; + attributes.port = attr_.udp.port; + + switch (attr_.udp.mode) + { + case Types::UDPMode::NETWORK: + attributes.address = attr_.udp.network.group; + attributes.ttl = attr_.udp.network.ttl; + break; + case Types::UDPMode::LOCAL: + attributes.address = attr_.udp.local.group; + attributes.ttl = attr_.udp.local.ttl; + break; + default: + break; + } + + return attributes; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/config/builder/udp_attribute_builder.h b/ecal/core/src/readwrite/config/builder/udp_attribute_builder.h new file mode 100644 index 0000000000..e9d95c624c --- /dev/null +++ b/ecal/core/src/readwrite/config/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 "readwrite/udp/config/attributes/reader_udp_attributes.h" +#include "readwrite/config/attributes/reader_attributes.h" + +#include "readwrite/udp/config/attributes/writer_udp_attributes.h" +#include "readwrite/config/attributes/writer_attributes.h" + +namespace eCAL +{ + namespace eCALReader + { + UDP::SAttributes BuildUDPAttributes(const eCALReader::SAttributes& attr_); + } + + namespace eCALWriter + { + UDP::SAttributes BuildUDPAttributes(const std::string& topic_id, const eCALWriter::SAttributes& attr_); + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index 1f600e4225..fedd83e29f 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -36,14 +36,17 @@ #if ECAL_CORE_TRANSPORT_UDP #include "udp/ecal_reader_udp.h" +#include "config/builder/udp_attribute_builder.h" #endif #if ECAL_CORE_TRANSPORT_SHM #include "shm/ecal_reader_shm.h" +#include "config/builder/shm_attribute_builder.h" #endif #if ECAL_CORE_TRANSPORT_TCP #include "tcp/ecal_reader_tcp.h" +#include "config/builder/tcp_attribute_builder.h" #endif #include @@ -62,25 +65,18 @@ namespace eCAL //////////////////////////////////////// // CDataReader //////////////////////////////////////// - CDataReader::CDataReader(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Subscriber::Configuration& config_) : - m_host_name(Process::GetHostName()), - m_host_group_name(Process::GetHostGroupName()), - m_pid(Process::GetProcessID()), - m_pname(Process::GetProcessName()), - m_topic_name(topic_name_), + CDataReader::CDataReader(const SDataTypeInformation& topic_info_, const eCAL::eCALReader::SAttributes& attr_) : m_topic_info(topic_info_), m_topic_size(0), - m_config(config_), + m_attributes(attr_), m_receive_time(0), m_clock(0), m_frequency_calculator(3.0f), - m_share_ttype(Config::IsTopicTypeSharingEnabled()), - m_share_tdesc(Config::IsTopicDescriptionSharingEnabled()), m_created(false) { #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataReader::Constructor"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataReader::Constructor"); #endif // build topic id @@ -100,7 +96,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataReader::Destructor"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataReader::Destructor"); #endif Stop(); @@ -111,7 +107,7 @@ namespace eCAL if (!m_created) return false; #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataReader::Stop"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataReader::Stop"); #endif // stop transport layers @@ -162,7 +158,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::Receive"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::Receive"); #endif // copy content to target string buf_.clear(); @@ -188,7 +184,7 @@ namespace eCAL const std::lock_guard lock(m_receive_callback_mtx); #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::AddReceiveCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::AddReceiveCallback"); #endif m_receive_callback = std::move(callback_); } @@ -205,7 +201,7 @@ namespace eCAL const std::lock_guard lock(m_receive_callback_mtx); #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::RemReceiveCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::RemReceiveCallback"); #endif m_receive_callback = nullptr; } @@ -221,7 +217,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::AddEventCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::AddEventCallback"); #endif const std::lock_guard lock(m_event_callback_map_mtx); m_event_callback_map[type_] = std::move(callback_); @@ -238,7 +234,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::RemEventCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::RemEventCallback"); #endif const std::lock_guard lock(m_event_callback_map_mtx); m_event_callback_map[type_] = nullptr; @@ -253,7 +249,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::SetAttribute"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::SetAttribute"); #endif return(true); @@ -265,7 +261,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::ClearAttribute"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataReader::ClearAttribute"); #endif return(true); @@ -340,7 +336,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::ApplyPublication"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::ApplyPublication"); #endif } @@ -366,7 +362,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::RemovePublication"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::RemovePublication"); #endif } @@ -375,7 +371,7 @@ namespace eCAL SReaderLayerPar par; par.host_name = publication_info_.host_name; par.process_id = publication_info_.process_id; - par.topic_name = m_topic_name; + par.topic_name = m_attributes.topic_name; par.topic_id = publication_info_.entity_id; par.parameter = parameter_; @@ -400,25 +396,25 @@ namespace eCAL { // initialize udp layer #if ECAL_CORE_TRANSPORT_UDP - if (m_config.layer.udp.enable) + if (m_attributes.udp.enable) { - CUDPReaderLayer::Get()->Initialize(); + CUDPReaderLayer::Get()->Initialize(eCAL::eCALReader::BuildUDPAttributes(m_attributes)); } #endif // initialize shm layer #if ECAL_CORE_TRANSPORT_SHM - if (m_config.layer.shm.enable) + if (m_attributes.shm.enable) { - CSHMReaderLayer::Get()->Initialize(); + CSHMReaderLayer::Get()->Initialize(eCAL::eCALReader::BuildSHMAttributes(m_attributes)); } #endif // initialize tcp layer #if ECAL_CORE_TRANSPORT_TCP - if (m_config.layer.tcp.enable) + if (m_attributes.tcp.enable) { - CTCPReaderLayer::Get()->Initialize(); + CTCPReaderLayer::Get()->Initialize(eCAL::eCALReader::BuildTCPLayerAttributes(m_attributes)); } #endif } @@ -433,13 +429,13 @@ namespace eCAL switch (layer_) { case tl_ecal_udp: - if (!m_config.layer.udp.enable) return 0; + if (!m_attributes.udp.enable) return 0; break; case tl_ecal_shm: - if (!m_config.layer.shm.enable) return 0; + if (!m_attributes.shm.enable) return 0; break; case tl_ecal_tcp: - if (!m_config.layer.tcp.enable) return 0; + if (!m_attributes.tcp.enable) return 0; break; default: break; @@ -460,7 +456,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::AddSample discard sample because of multiple receive"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::AddSample discard sample because of multiple receive"); #endif return(size_); } @@ -489,7 +485,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::AddSample"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::AddSample"); #endif // increase read clock @@ -516,7 +512,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::AddSample::ReceiveCallback"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::AddSample::ReceiveCallback"); #endif // prepare data struct SReceiveCallbackData cb_data; @@ -558,7 +554,7 @@ namespace eCAL m_read_buf_cv.notify_one(); #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataReader::AddSample::Receive::Buffered"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataReader::AddSample::Receive::Buffered"); #endif } @@ -573,9 +569,9 @@ namespace eCAL out << indent_ << "------------------------------------" << '\n'; out << indent_ << " class CDataReader " << '\n'; out << indent_ << "------------------------------------" << '\n'; - out << indent_ << "m_host_name: " << m_host_name << '\n'; - out << indent_ << "m_host_group_name: " << m_host_group_name << '\n'; - out << indent_ << "m_topic_name: " << m_topic_name << '\n'; + out << indent_ << "m_host_name: " << m_attributes.host_name << '\n'; + out << indent_ << "m_host_group_name: " << m_attributes.host_group_name << '\n'; + out << indent_ << "m_topic_name: " << m_attributes.topic_name << '\n'; out << indent_ << "m_topic_id: " << m_topic_id << '\n'; out << indent_ << "m_topic_info.encoding: " << m_topic_info.encoding << '\n'; out << indent_ << "m_topic_info.name: " << m_topic_info.name << '\n'; @@ -600,7 +596,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug4, m_topic_name + "::CDataReader::Register"); + Logging::Log(log_level_debug4, m_attributes.topic_name + "::CDataReader::Register"); #endif #endif // ECAL_CORE_REGISTRATION } @@ -614,7 +610,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug4, m_topic_name + "::CDataReader::Unregister"); + Logging::Log(log_level_debug4, m_attributes.topic_name + "::CDataReader::Unregister"); #endif #endif // ECAL_CORE_REGISTRATION } @@ -640,22 +636,22 @@ namespace eCAL ecal_reg_sample.cmd_type = bct_reg_subscriber; auto& ecal_reg_sample_identifier = ecal_reg_sample.identifier; - ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.process_id = m_attributes.process_id; ecal_reg_sample_identifier.entity_id = m_topic_id; - ecal_reg_sample_identifier.host_name = m_host_name; + ecal_reg_sample_identifier.host_name = m_attributes.host_name; auto& ecal_reg_sample_topic = ecal_reg_sample.topic; - ecal_reg_sample_topic.hgname = m_host_group_name; - ecal_reg_sample_topic.tname = m_topic_name; + ecal_reg_sample_topic.hgname = m_attributes.host_group_name; + ecal_reg_sample_topic.tname = m_attributes.topic_name; // topic_information { auto& ecal_reg_sample_tdatatype = ecal_reg_sample_topic.tdatatype; - if (m_share_ttype) + if (m_attributes.share_topic_type) { ecal_reg_sample_tdatatype.encoding = m_topic_info.encoding; ecal_reg_sample_tdatatype.name = m_topic_info.name; } - if (m_share_tdesc) + if (m_attributes.share_topic_description) { ecal_reg_sample_tdatatype.descriptor = m_topic_info.descriptor; } @@ -699,8 +695,8 @@ namespace eCAL } #endif - ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.uname = Process::GetUnitName(); + ecal_reg_sample_topic.pname = m_attributes.process_name; + ecal_reg_sample_topic.uname = m_attributes.unit_name; ecal_reg_sample_topic.dclock = m_clock; ecal_reg_sample_topic.dfreq = GetFrequency(); ecal_reg_sample_topic.message_drops = static_cast(m_message_drops); @@ -715,49 +711,49 @@ namespace eCAL ecal_unreg_sample.cmd_type = bct_unreg_subscriber; auto& ecal_reg_sample_identifier = ecal_unreg_sample.identifier; - ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.process_id = m_attributes.process_id; ecal_reg_sample_identifier.entity_id = m_topic_id; - ecal_reg_sample_identifier.host_name = m_host_name; + ecal_reg_sample_identifier.host_name = m_attributes.host_name; auto& ecal_reg_sample_topic = ecal_unreg_sample.topic; - ecal_reg_sample_topic.hgname = m_host_group_name; - ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.uname = Process::GetUnitName(); + ecal_reg_sample_topic.hgname = m_attributes.host_group_name; + ecal_reg_sample_topic.pname = m_attributes.process_name; + ecal_reg_sample_topic.tname = m_attributes.topic_name; + ecal_reg_sample_topic.uname = m_attributes.unit_name; } void CDataReader::StartTransportLayer() { #if ECAL_CORE_TRANSPORT_UDP - if (m_config.layer.udp.enable) + if (m_attributes.udp.enable) { // flag enabled m_layers.udp.read_enabled = true; // subscribe to layer (if supported) - CUDPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); + CUDPReaderLayer::Get()->AddSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif #if ECAL_CORE_TRANSPORT_SHM - if (m_config.layer.shm.enable) + if (m_attributes.shm.enable) { // flag enabled m_layers.shm.read_enabled = true; // subscribe to layer (if supported) - CSHMReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); + CSHMReaderLayer::Get()->AddSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif #if ECAL_CORE_TRANSPORT_TCP - if (m_config.layer.tcp.enable) + if (m_attributes.tcp.enable) { // flag enabled m_layers.tcp.read_enabled = true; // subscribe to layer (if supported) - CTCPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); + CTCPReaderLayer::Get()->AddSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif } @@ -765,35 +761,35 @@ namespace eCAL void CDataReader::StopTransportLayer() { #if ECAL_CORE_TRANSPORT_UDP - if (m_config.layer.udp.enable) + if (m_attributes.udp.enable) { // flag disabled m_layers.udp.read_enabled = false; // unsubscribe from layer (if supported) - CUDPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); + CUDPReaderLayer::Get()->RemSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif #if ECAL_CORE_TRANSPORT_SHM - if (m_config.layer.shm.enable) + if (m_attributes.shm.enable) { // flag disabled m_layers.shm.read_enabled = false; // unsubscribe from layer (if supported) - CSHMReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); + CSHMReaderLayer::Get()->RemSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif #if ECAL_CORE_TRANSPORT_TCP - if (m_config.layer.tcp.enable) + if (m_attributes.tcp.enable) { // flag disabled m_layers.tcp.read_enabled = false; // unsubscribe from layer (if supported) - CTCPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); + CTCPReaderLayer::Get()->RemSubscription(m_attributes.host_name, m_attributes.topic_name, m_topic_id); } #endif } @@ -810,7 +806,7 @@ namespace eCAL data.clock = 0; data.tid = tid_; data.tdatatype = tinfo_; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -826,7 +822,7 @@ namespace eCAL data.clock = 0; data.tid = tid_; data.tdatatype = tinfo_; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -840,7 +836,7 @@ namespace eCAL data.type = sub_event_disconnected; data.time = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); data.clock = 0; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -904,11 +900,11 @@ namespace eCAL // we log this std::string msg = std::to_string(counter_ - counter_last) + " Messages lost ! "; msg += "(Unit: \'"; - msg += Process::GetUnitName(); + msg += m_attributes.unit_name; msg += "@"; - msg += Process::GetHostName(); + msg += m_attributes.host_name; msg += "\' | Subscriber: \'"; - msg += m_topic_name; + msg += m_attributes.topic_name; msg += "\')"; Logging::Log(log_level_warning, msg); #endif @@ -922,7 +918,7 @@ namespace eCAL data.type = sub_event_dropped; data.time = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); data.clock = current_clock_; - (citer->second)(m_topic_name.c_str(), &data); + (citer->second)(m_attributes.topic_name.c_str(), &data); } } @@ -962,7 +958,7 @@ namespace eCAL // but we log this std::string msg = "Subscriber: \'"; - msg += m_topic_name; + msg += m_attributes.topic_name; msg += "\'"; msg += " received a message in the wrong order"; Logging::Log(log_level_warning, msg); diff --git a/ecal/core/src/readwrite/ecal_reader.h b/ecal/core/src/readwrite/ecal_reader.h index e6341295fc..5c01ce4e86 100644 --- a/ecal/core/src/readwrite/ecal_reader.h +++ b/ecal/core/src/readwrite/ecal_reader.h @@ -25,11 +25,11 @@ #include #include -#include #include "serialization/ecal_serialize_sample_payload.h" #include "serialization/ecal_serialize_sample_registration.h" #include "util/frequency_calculator.h" +#include "config/attributes/reader_attributes.h" #include #include @@ -63,7 +63,7 @@ namespace eCAL }; using SPublicationInfo = Registration::SampleIdentifier; - CDataReader(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Subscriber::Configuration& config_); + CDataReader(const SDataTypeInformation& topic_info_, const eCAL::eCALReader::SAttributes& attr_); ~CDataReader(); bool Stop(); @@ -95,14 +95,14 @@ namespace eCAL Registration::STopicId GetId() const { Registration::STopicId id; - id.topic_name = m_topic_name; + id.topic_name = m_attributes.topic_name; id.topic_id.entity_id = m_topic_id; - id.topic_id.host_name = m_host_name; - id.topic_id.process_id = m_pid; + id.topic_id.host_name = m_attributes.host_name; + id.topic_id.process_id = m_attributes.process_id; return id; } - std::string GetTopicName() const { return(m_topic_name); } + std::string GetTopicName() const { return(m_attributes.topic_name); } std::string GetTopicID() const { return(m_topic_id); } SDataTypeInformation GetDataTypeInformation() const { return(m_topic_info); } @@ -131,16 +131,10 @@ namespace eCAL int32_t GetFrequency(); - std::string m_host_name; - std::string m_host_group_name; - int m_pid = 0; - std::string m_pname; - std::string m_topic_name; std::string m_topic_id; SDataTypeInformation m_topic_info; std::map m_attr; std::atomic m_topic_size; - Subscriber::Configuration m_config; struct SConnection { @@ -180,10 +174,9 @@ namespace eCAL WriterCounterMapT m_writer_counter_map; long long m_message_drops = 0; - bool m_share_ttype = false; - bool m_share_tdesc = false; - SLayerStates m_layers; std::atomic m_created; + + eCAL::eCALReader::SAttributes m_attributes; }; } diff --git a/ecal/core/src/readwrite/ecal_reader_layer.h b/ecal/core/src/readwrite/ecal_reader_layer.h index 276a45a663..3ce7dd0bf9 100644 --- a/ecal/core/src/readwrite/ecal_reader_layer.h +++ b/ecal/core/src/readwrite/ecal_reader_layer.h @@ -42,7 +42,7 @@ namespace eCAL }; // ecal data layer base class - template + template class CReaderLayer { public: @@ -52,7 +52,7 @@ namespace eCAL // initialize layer // will be called one time on eCAL initialization - virtual void Initialize() = 0; + virtual void Initialize(const U& attr_) = 0; // activate / create a specific subscription virtual void AddSubscription(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) = 0; @@ -72,6 +72,5 @@ namespace eCAL } return layer; } - }; } diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index eb120a9c3e..e4d9c3b5c3 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -36,6 +36,10 @@ #include "ecal_global_accessors.h" #include "ecal_transport_layer.h" +#include "config/builder/shm_attribute_builder.h" +#include "config/builder/tcp_attribute_builder.h" +#include "config/builder/udp_attribute_builder.h" + #include #include #include @@ -93,20 +97,15 @@ namespace namespace eCAL { - CDataWriter::CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_) : - m_host_name(Process::GetHostName()), - m_host_group_name(Process::GetHostGroupName()), - m_pid(Process::GetProcessID()), - m_pname(Process::GetProcessName()), - m_topic_name(topic_name_), + CDataWriter::CDataWriter(const SDataTypeInformation& topic_info_, const eCAL::eCALWriter::SAttributes& attr_) : m_topic_info(topic_info_), - m_config(config_), + m_attributes(attr_), m_frequency_calculator(3.0f), m_created(false) { #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataWriter::Constructor"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataWriter::Constructor"); #endif // build topic id @@ -122,7 +121,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataWriter::Destructor"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataWriter::Destructor"); #endif Stop(); @@ -133,7 +132,7 @@ namespace eCAL if (!m_created) return false; #ifndef NDEBUG // log it - Logging::Log(log_level_debug1, m_topic_name + "::CDataWriter::Stop"); + Logging::Log(log_level_debug1, m_attributes.topic_name + "::CDataWriter::Stop"); #endif // stop all transport layer @@ -168,7 +167,7 @@ namespace eCAL // are we allowed to perform zero copy writing? bool allow_zero_copy(false); #if ECAL_CORE_TRANSPORT_SHM - allow_zero_copy = m_config.layer.shm.zero_copy_mode; // zero copy mode activated by user + allow_zero_copy = m_attributes.shm.zero_copy_mode; // zero copy mode activated by user #endif #if ECAL_CORE_TRANSPORT_UDP // udp is active -> no zero copy @@ -200,7 +199,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::SHM"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::SHM"); #endif // send it @@ -213,8 +212,8 @@ namespace eCAL wattr.clock = m_clock; wattr.hash = snd_hash; wattr.time = time_; - wattr.zero_copy = m_config.layer.shm.zero_copy_mode; - wattr.acknowledge_timeout_ms = m_config.layer.shm.acknowledge_timeout_ms; + wattr.zero_copy = m_attributes.shm.zero_copy_mode; + wattr.acknowledge_timeout_ms = m_attributes.shm.acknowledge_timeout_ms; // prepare send if (m_writer_shm->PrepareWrite(wattr)) @@ -247,11 +246,11 @@ namespace eCAL // log it if (shm_sent) { - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::SHM - SUCCESS"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::SHM - SUCCESS"); } else { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Send::SHM - FAILED"); + Logging::Log(log_level_error, m_attributes.topic_name + "::CDataWriter::Send::SHM - FAILED"); } #endif } @@ -265,7 +264,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::udp"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::udp"); #endif // send it @@ -278,7 +277,7 @@ namespace eCAL wattr.clock = m_clock; wattr.hash = snd_hash; wattr.time = time_; - wattr.loopback = eCAL::GetConfiguration().registration.loopback; + wattr.loopback = m_attributes.loopback; // prepare send if (m_writer_udp->PrepareWrite(wattr)) @@ -298,11 +297,11 @@ namespace eCAL // log it if (udp_sent) { - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::udp - SUCCESS"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::udp - SUCCESS"); } else { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Send::udp - FAILED"); + Logging::Log(log_level_error, m_attributes.topic_name + "::CDataWriter::Send::udp - FAILED"); } #endif } @@ -316,7 +315,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::TCP"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::TCP"); #endif // send it @@ -340,11 +339,11 @@ namespace eCAL // log it if (tcp_sent) { - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::Send::TCP - SUCCESS"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::Send::TCP - SUCCESS"); } else { - Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Send::TCP - FAILED"); + Logging::Log(log_level_error, m_attributes.topic_name + "::CDataWriter::Send::TCP - FAILED"); } #endif } @@ -361,7 +360,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::SetDescription"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::SetDescription"); #endif return(true); @@ -373,7 +372,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::SetAttribute"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::SetAttribute"); #endif return(true); @@ -385,7 +384,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ClearAttribute"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ClearAttribute"); #endif return(true); @@ -399,7 +398,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::AddEventCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::AddEventCallback"); #endif const std::lock_guard lock(m_event_callback_map_mtx); m_event_callback_map[type_] = std::move(callback_); @@ -416,7 +415,7 @@ namespace eCAL { #ifndef NDEBUG // log it - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::RemEventCallback"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::RemEventCallback"); #endif const std::lock_guard lock(m_event_callback_map_mtx); m_event_callback_map[type_] = nullptr; @@ -431,19 +430,19 @@ namespace eCAL std::vector pub_layers; std::vector sub_layers; #if ECAL_CORE_TRANSPORT_UDP - if (m_config.layer.udp.enable) pub_layers.push_back(tl_ecal_udp); + if (m_attributes.udp.enable) pub_layers.push_back(tl_ecal_udp); if (sub_layer_states_.udp.read_enabled) sub_layers.push_back(tl_ecal_udp); m_layers.udp.read_enabled = sub_layer_states_.udp.read_enabled; // just for debugging/logging #endif #if ECAL_CORE_TRANSPORT_SHM - if (m_config.layer.shm.enable) pub_layers.push_back(tl_ecal_shm); + if (m_attributes.shm.enable) pub_layers.push_back(tl_ecal_shm); if (sub_layer_states_.shm.read_enabled) sub_layers.push_back(tl_ecal_shm); m_layers.shm.read_enabled = sub_layer_states_.shm.read_enabled; // just for debugging/logging #endif #if ECAL_CORE_TRANSPORT_TCP - if (m_config.layer.tcp.enable) pub_layers.push_back(tl_ecal_tcp); + if (m_attributes.tcp.enable) pub_layers.push_back(tl_ecal_tcp); if (sub_layer_states_.tcp.read_enabled) sub_layers.push_back(tl_ecal_tcp); m_layers.tcp.read_enabled = sub_layer_states_.tcp.read_enabled; // just for debugging/logging @@ -452,7 +451,7 @@ namespace eCAL // determine if we need to start a transport layer // if a new layer gets activated, we reregister for SHM and TCP to force the exchange of connection parameter // without this forced registration we would need one additional registration loop for these two layers to establish the connection - const TLayer::eTransportLayer layer2activate = DetermineTransportLayer2Start(pub_layers, sub_layers, m_host_name == subscription_info_.host_name); + const TLayer::eTransportLayer layer2activate = DetermineTransportLayer2Start(pub_layers, sub_layers, m_attributes.host_name == subscription_info_.host_name); switch (layer2activate) { case tl_ecal_udp: @@ -536,7 +535,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::ApplySubscription"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::ApplySubscription"); #endif } @@ -573,7 +572,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug3, m_topic_name + "::CDataWriter::RemoveSubscription"); + Logging::Log(log_level_debug3, m_attributes.topic_name + "::CDataWriter::RemoveSubscription"); #endif } @@ -609,9 +608,9 @@ namespace eCAL out << indent_ << "--------------------------" << '\n'; out << indent_ << " class CDataWriter " << '\n'; out << indent_ << "--------------------------" << '\n'; - out << indent_ << "m_host_name: " << m_host_name << '\n'; - out << indent_ << "m_host_group_name: " << m_host_group_name << '\n'; - out << indent_ << "m_topic_name: " << m_topic_name << '\n'; + out << indent_ << "m_host_name: " << m_attributes.host_name << '\n'; + out << indent_ << "m_host_group_name: " << m_attributes.host_group_name << '\n'; + out << indent_ << "m_topic_name: " << m_attributes.topic_name << '\n'; out << indent_ << "m_topic_id: " << m_topic_id << '\n'; out << indent_ << "m_topic_info.encoding: " << m_topic_info.encoding << '\n'; out << indent_ << "m_topic_info.name: " << m_topic_info.name << '\n'; @@ -634,7 +633,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Register"); + Logging::Log(log_level_debug4, m_attributes.topic_name + "::CDataWriter::Register"); #endif #endif // ECAL_CORE_REGISTRATION } @@ -648,7 +647,7 @@ namespace eCAL #ifndef NDEBUG // log it - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Unregister"); + Logging::Log(log_level_debug4, m_attributes.topic_name + "::CDataWriter::Unregister"); #endif #endif // ECAL_CORE_REGISTRATION } @@ -663,23 +662,23 @@ namespace eCAL ecal_reg_sample.cmd_type = bct_reg_publisher; auto& ecal_reg_sample_identifier = ecal_reg_sample.identifier; - ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.process_id = m_attributes.process_id; ecal_reg_sample_identifier.entity_id = m_topic_id; - ecal_reg_sample_identifier.host_name = m_host_name; + ecal_reg_sample_identifier.host_name = m_attributes.host_name; auto& ecal_reg_sample_topic = ecal_reg_sample.topic; - ecal_reg_sample_topic.hgname = m_host_group_name; - ecal_reg_sample_topic.tname = m_topic_name; + ecal_reg_sample_topic.hgname = m_attributes.host_group_name; + ecal_reg_sample_topic.tname = m_attributes.topic_name; // topic_information { auto& ecal_reg_sample_tdatatype = ecal_reg_sample_topic.tdatatype; - if (m_config.share_topic_type) + if (m_attributes.share_topic_type) { ecal_reg_sample_tdatatype.encoding = m_topic_info.encoding; ecal_reg_sample_tdatatype.name = m_topic_info.name; } - if (m_config.share_topic_description) + if (m_attributes.share_topic_description) { ecal_reg_sample_tdatatype.descriptor = m_topic_info.descriptor; } @@ -729,8 +728,8 @@ namespace eCAL } #endif - ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.uname = Process::GetUnitName(); + ecal_reg_sample_topic.pname = m_attributes.process_name; + ecal_reg_sample_topic.uname = m_attributes.unit_name; ecal_reg_sample_topic.did = m_id; ecal_reg_sample_topic.dclock = m_clock; ecal_reg_sample_topic.dfreq = GetFrequency(); @@ -741,7 +740,7 @@ namespace eCAL const std::lock_guard lock(m_connection_map_mtx); for (const auto& sub : m_connection_map) { - if (sub.first.host_name == m_host_name) + if (sub.first.host_name == m_attributes.host_name) { loc_connections++; } @@ -757,15 +756,15 @@ namespace eCAL ecal_unreg_sample.cmd_type = bct_unreg_publisher; auto& ecal_reg_sample_identifier = ecal_unreg_sample.identifier; - ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.process_id = m_attributes.process_id; ecal_reg_sample_identifier.entity_id = m_topic_id; - ecal_reg_sample_identifier.host_name = m_host_name; + ecal_reg_sample_identifier.host_name = m_attributes.host_name; auto& ecal_reg_sample_topic = ecal_unreg_sample.topic; - ecal_reg_sample_topic.hgname = m_host_group_name; - ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.uname = Process::GetUnitName(); + ecal_reg_sample_topic.hgname = m_attributes.host_group_name; + ecal_reg_sample_topic.pname = m_attributes.process_name; + ecal_reg_sample_topic.tname = m_attributes.topic_name; + ecal_reg_sample_topic.uname = m_attributes.unit_name; } void CDataWriter::FireConnectEvent(const std::string& tid_, const SDataTypeInformation& tinfo_) @@ -780,7 +779,7 @@ namespace eCAL data.clock = 0; data.tid = tid_; data.tdatatype = tinfo_; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -796,7 +795,7 @@ namespace eCAL data.clock = 0; data.tid = tid_; data.tdatatype = tinfo_; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -810,7 +809,7 @@ namespace eCAL data.type = pub_event_disconnected; data.time = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); data.clock = 0; - (iter->second)(m_topic_name.c_str(), &data); + (iter->second)(m_attributes.topic_name.c_str(), &data); } } @@ -837,16 +836,16 @@ namespace eCAL m_layers.udp.write_enabled = true; // log state - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateUdpLayer::ACTIVATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateUdpLayer::ACTIVATED"); // create writer - m_writer_udp = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.udp); + m_writer_udp = std::make_unique(eCAL::eCALWriter::BuildUDPAttributes(m_topic_id, m_attributes)); // register activated layer Register(); #ifndef NDEBUG - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateUdpLayer::WRITER_CREATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateUdpLayer::WRITER_CREATED"); #endif return true; #else // ECAL_CORE_TRANSPORT_UDP @@ -863,16 +862,16 @@ namespace eCAL m_layers.shm.write_enabled = true; // log state - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateShmLayer::ACTIVATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateShmLayer::ACTIVATED"); // create writer - m_writer_shm = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.shm); + m_writer_shm = std::make_unique(eCAL::eCALWriter::BuildSHMAttributes(m_attributes)); // register activated layer Register(); #ifndef NDEBUG - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateShmLayer::WRITER_CREATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateShmLayer::WRITER_CREATED"); #endif return true; #else // ECAL_CORE_TRANSPORT_SHM @@ -889,16 +888,16 @@ namespace eCAL m_layers.tcp.write_enabled = true; // log state - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateTcpLayer::ACTIVATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateTcpLayer::ACTIVATED"); // create writer - m_writer_tcp = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.tcp); + m_writer_tcp = std::make_unique(eCAL::eCALWriter::BuildTCPAttributes(m_topic_id, m_attributes)); // register activated layer Register(); #ifndef NDEBUG - Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateTcpLayer::WRITER_CREATED"); + Logging::Log(log_level_debug2, m_attributes.topic_name + "::CDataWriter::ActivateTcpLayer::WRITER_CREATED"); #endif return true; #else // ECAL_CORE_TRANSPORT_TCP @@ -955,7 +954,7 @@ namespace eCAL TLayer::eTransportLayer CDataWriter::DetermineTransportLayer2Start(const std::vector& enabled_pub_layer_, const std::vector& enabled_sub_layer_, bool same_host_) { // determine the priority list to use - const Publisher::Configuration::LayerPriorityVector& layer_priority_vector = same_host_ ? m_config.layer_priority_local : m_config.layer_priority_remote; + const Publisher::Configuration::LayerPriorityVector& layer_priority_vector = same_host_ ? m_attributes.layer_priority_local : m_attributes.layer_priority_remote; // find the highest priority transport layer that is available in both publisher and subscriber options // TODO: we need to fusion the two layer enum types (eTransportLayer) in ecal_tlayer.h and ecal_struct_sample_common.hf diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index d7590013d7..fae877810e 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -27,10 +27,10 @@ #include #include #include -#include #include "serialization/ecal_serialize_sample_registration.h" #include "util/frequency_calculator.h" +#include "config/attributes/writer_attributes.h" #if ECAL_CORE_TRANSPORT_UDP #include "udp/ecal_writer_udp.h" @@ -74,7 +74,7 @@ namespace eCAL using SSubscriptionInfo = Registration::SampleIdentifier; - CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_); + CDataWriter(const SDataTypeInformation& topic_info_, const eCAL::eCALWriter::SAttributes& attr_); ~CDataWriter(); bool Stop(); @@ -103,14 +103,14 @@ namespace eCAL Registration::STopicId GetId() const { Registration::STopicId id; - id.topic_name = m_topic_name; + id.topic_name = m_attributes.topic_name; id.topic_id.entity_id = m_topic_id; - id.topic_id.host_name = m_host_name; - id.topic_id.process_id = m_pid; + id.topic_id.host_name = m_attributes.host_name; + id.topic_id.process_id = m_attributes.process_id; return id; } - const std::string& GetTopicName() const { return(m_topic_name); } + const std::string& GetTopicName() const { return(m_attributes.topic_name); } const SDataTypeInformation& GetDataTypeInformation() const { return m_topic_info; } std::string Dump(const std::string& indent_ = ""); @@ -140,16 +140,11 @@ namespace eCAL int32_t GetFrequency(); - std::string m_host_name; - std::string m_host_group_name; - int m_pid; - std::string m_pname; - std::string m_topic_name; std::string m_topic_id; SDataTypeInformation m_topic_info; std::map m_attr; size_t m_topic_size = 0; - Publisher::Configuration m_config; + eCAL::eCALWriter::SAttributes m_attributes; std::vector m_payload_buffer; diff --git a/ecal/core/src/readwrite/ecal_writer_base.h b/ecal/core/src/readwrite/ecal_writer_base.h index 48ef9cdec0..747068ce6c 100644 --- a/ecal/core/src/readwrite/ecal_writer_base.h +++ b/ecal/core/src/readwrite/ecal_writer_base.h @@ -50,10 +50,5 @@ namespace eCAL virtual bool PrepareWrite(const SWriterAttr& /*attr_*/) { return false; }; virtual bool Write(CPayloadWriter& /*payload_*/, const SWriterAttr& /*attr_*/) { return false; }; virtual bool Write(const void* /*buf_*/, const SWriterAttr& /*attr_*/) { return false; }; - - protected: - std::string m_host_name; - std::string m_topic_name; - std::string m_topic_id; }; } diff --git a/ecal/core/src/readwrite/shm/config/attributes/reader_shm_attributes.h b/ecal/core/src/readwrite/shm/config/attributes/reader_shm_attributes.h new file mode 100644 index 0000000000..59784568ca --- /dev/null +++ b/ecal/core/src/readwrite/shm/config/attributes/reader_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 eCALReader + { + namespace SHM + { + struct SAttributes + { + int process_id; + unsigned int registration_timeout_ms; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/shm/config/attributes/writer_shm_attributes.h b/ecal/core/src/readwrite/shm/config/attributes/writer_shm_attributes.h new file mode 100644 index 0000000000..3359a84375 --- /dev/null +++ b/ecal/core/src/readwrite/shm/config/attributes/writer_shm_attributes.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 ================================= +*/ + +#pragma once + +#include + +namespace eCAL +{ + namespace eCALWriter + { + namespace SHM + { + struct SAttributes + { + unsigned int acknowledge_timeout_ms; + unsigned int memfile_buffer_count; + unsigned int memfile_min_size_bytes; + unsigned int memfile_reserve_percent; + + std::string host_name; + std::string topic_name; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp index f1d74969ec..1592fb8a1b 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp @@ -38,14 +38,19 @@ namespace eCAL //////////////// // LAYER //////////////// + void CSHMReaderLayer::Initialize(const eCAL::eCALReader::SHM::SAttributes& attr_) + { + m_attributes = attr_; + } + void CSHMReaderLayer::SetConnectionParameter(SReaderLayerPar& par_) { for (const auto& memfile_name : par_.parameter.layer_par_shm.memory_file_list) { // start memory file receive thread if topic is subscribed in this process if (g_memfile_pool() != nullptr) - { - const std::string process_id = std::to_string(Process::GetProcessID()); + { + const std::string process_id = std::to_string(m_attributes.process_id); const std::string memfile_event = memfile_name + "_" + process_id; Payload::TopicInfo topic_info; @@ -58,7 +63,7 @@ namespace eCAL { return OnNewShmFileContent(topic_info, buf_, len_, id_, clock_, time_, hash_); }; - g_memfile_pool()->ObserveFile(memfile_name, memfile_event, Config::GetRegistrationTimeoutMs(), data_callback); + g_memfile_pool()->ObserveFile(memfile_name, memfile_event, m_attributes.registration_timeout_ms, data_callback); } } } diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.h b/ecal/core/src/readwrite/shm/ecal_reader_shm.h index e25593765f..be981a03a5 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.h +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.h @@ -26,6 +26,7 @@ #include "ecal_def.h" #include "readwrite/ecal_reader_layer.h" #include "serialization/ecal_struct_sample_payload.h" +#include "config/attributes/reader_shm_attributes.h" #include #include @@ -36,13 +37,13 @@ namespace eCAL //////////////// // LAYER //////////////// - class CSHMReaderLayer : public CReaderLayer + class CSHMReaderLayer : public CReaderLayer { public: CSHMReaderLayer() = default; ~CSHMReaderLayer() override = default; - void Initialize() override {} + void Initialize(const eCAL::eCALReader::SHM::SAttributes& attr_) override; void AddSubscription(const std::string& /*host_name_*/, const std::string& /*topic_name_*/, const std::string& /*topic_id_*/) override {} void RemSubscription(const std::string& /*host_name_*/, const std::string& /*topic_name_*/, const std::string& /*topic_id_*/) override {} @@ -50,5 +51,7 @@ namespace eCAL private: size_t OnNewShmFileContent(const Payload::TopicInfo& topic_info_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_); + + eCAL::eCALReader::SHM::SAttributes m_attributes; }; } diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 94a404c102..99bd7cc58e 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -25,7 +25,6 @@ #include "ecal_def.h" #include "ecal_writer_shm.h" -#include "ecal/ecal_config.h" #include @@ -33,15 +32,12 @@ namespace eCAL { const std::string CDataWriterSHM::m_memfile_base_name = "ecal_"; - CDataWriterSHM::CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& /*topic_id_*/, const Publisher::Layer::SHM::Configuration& shm_config_) : - m_config(shm_config_) + CDataWriterSHM::CDataWriterSHM(const eCALWriter::SHM::SAttributes& attr_) : + m_attributes(attr_) { - m_host_name = host_name_; - m_topic_name = topic_name_; - // initialize memory file buffer - if (m_config.memfile_buffer_count < 1) m_config.memfile_buffer_count = 1; - SetBufferCount(m_config.memfile_buffer_count); + if (m_attributes.memfile_buffer_count < 1) m_attributes.memfile_buffer_count = 1; + SetBufferCount(m_attributes.memfile_buffer_count); } SWriterInfo CDataWriterSHM::GetInfo() @@ -90,7 +86,7 @@ namespace eCAL void CDataWriterSHM::ApplySubscription(const std::string& host_name_, const int32_t process_id_, const std::string& /*topic_id_*/, const std::string& /*conn_par_*/) { // we accept local connections only - if (host_name_ != m_host_name) return; + if (host_name_ != m_attributes.host_name) return; for (auto& memory_file : m_memory_file_vec) { @@ -119,16 +115,16 @@ namespace eCAL // buffer count zero not allowed if (buffer_count_ < 1) { - Logging::Log(log_level_error, m_topic_name + "::CDataWriterSHM::SetBufferCount minimal number of memory files is 1 !"); + Logging::Log(log_level_error, m_attributes.topic_name + "::CDataWriterSHM::SetBufferCount minimal number of memory files is 1 !"); return false; } // prepare memfile attributes SSyncMemoryFileAttr memory_file_attr = {}; - memory_file_attr.min_size = m_config.memfile_min_size_bytes; - memory_file_attr.reserve = m_config.memfile_reserve_percent; + memory_file_attr.min_size = m_attributes.memfile_min_size_bytes; + memory_file_attr.reserve = m_attributes.memfile_reserve_percent; memory_file_attr.timeout_open_ms = PUB_MEMFILE_OPEN_TO; - memory_file_attr.timeout_ack_ms = m_config.acknowledge_timeout_ms; + memory_file_attr.timeout_ack_ms = m_attributes.acknowledge_timeout_ms; // retrieve the memory file size of existing files size_t memory_file_size(0); diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.h b/ecal/core/src/readwrite/shm/ecal_writer_shm.h index 8126f4992c..2c3c122fda 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.h +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.h @@ -23,7 +23,7 @@ #pragma once -#include +#include "config/attributes/writer_shm_attributes.h" #include "io/shm/ecal_memfile_sync.h" #include "readwrite/ecal_writer_base.h" @@ -38,7 +38,7 @@ namespace eCAL class CDataWriterSHM : public CDataWriterBase { public: - CDataWriterSHM(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const Publisher::Layer::SHM::Configuration& shm_config_); + CDataWriterSHM(const eCALWriter::SHM::SAttributes& attr_); SWriterInfo GetInfo() override; @@ -53,7 +53,7 @@ namespace eCAL protected: bool SetBufferCount(size_t buffer_count_); - Publisher::Layer::SHM::Configuration m_config; + eCALWriter::SHM::SAttributes m_attributes; size_t m_write_idx = 0; std::vector> m_memory_file_vec; diff --git a/ecal/core/src/readwrite/tcp/config/attributes/data_reader_tcp_attributes.h b/ecal/core/src/readwrite/tcp/config/attributes/data_reader_tcp_attributes.h new file mode 100644 index 0000000000..33586b0d8b --- /dev/null +++ b/ecal/core/src/readwrite/tcp/config/attributes/data_reader_tcp_attributes.h @@ -0,0 +1,38 @@ +/* ========================= 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 eCALReader + { + namespace TCP + { + struct SAttributes + { + size_t ecal_magic = (4 * sizeof(char)); + int max_reconnection_attempts; + size_t thread_pool_size; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/tcp/config/attributes/data_writer_tcp_attributes.h b/ecal/core/src/readwrite/tcp/config/attributes/data_writer_tcp_attributes.h new file mode 100644 index 0000000000..8f6657a274 --- /dev/null +++ b/ecal/core/src/readwrite/tcp/config/attributes/data_writer_tcp_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 +#include + +namespace eCAL +{ + namespace eCALWriter + { + namespace TCP + { + struct SAttributes + { + std::string topic_name; + std::string topic_id; + + size_t thread_pool_size; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/tcp/config/attributes/tcp_reader_layer_attributes.h b/ecal/core/src/readwrite/tcp/config/attributes/tcp_reader_layer_attributes.h new file mode 100644 index 0000000000..2bdb2d431e --- /dev/null +++ b/ecal/core/src/readwrite/tcp/config/attributes/tcp_reader_layer_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 eCALReader + { + namespace TCPLayer + { + struct SAttributes + { + size_t thread_pool_size; + int max_reconnection_attempts; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.cpp b/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.cpp new file mode 100644 index 0000000000..cf06d37a99 --- /dev/null +++ b/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_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 ================================= +*/ + +#pragma once + +#include "data_reader_tcp_attribute_builder.h" + +namespace eCAL +{ + namespace eCALReader + { + namespace TCP + { + TCP::SAttributes BuildTCPReaderAttributes(const TCPLayer::SAttributes& attr_) + { + TCP::SAttributes attributes; + + attributes.thread_pool_size = attr_.thread_pool_size; + attributes.max_reconnection_attempts = attr_.max_reconnection_attempts; + + return attributes; + } + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.h b/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.h new file mode 100644 index 0000000000..a74bdc65a4 --- /dev/null +++ b/ecal/core/src/readwrite/tcp/config/builder/data_reader_tcp_attribute_builder.h @@ -0,0 +1,35 @@ +/* ========================= 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 "readwrite/tcp/config/attributes/tcp_reader_layer_attributes.h" +#include "readwrite/tcp/config/attributes/data_reader_tcp_attributes.h" + + +namespace eCAL +{ + namespace eCALReader + { + namespace TCP + { + TCP::SAttributes BuildTCPReaderAttributes(const TCPLayer::SAttributes& attr_); + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp index e1cc41997c..af3893ecd3 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp @@ -22,6 +22,7 @@ **/ #include +#include "config/builder/data_reader_tcp_attribute_builder.h" #include "ecal_global_accessors.h" #include "ecal_reader_tcp.h" @@ -36,7 +37,10 @@ namespace eCAL //////////////// // READER //////////////// - CDataReaderTCP::CDataReaderTCP() : m_callback_active(false) {} + CDataReaderTCP::CDataReaderTCP(const eCAL::eCALReader::TCP::SAttributes& attr_) + : m_callback_active(false) + , m_attributes(attr_) + {} bool CDataReaderTCP::Create(std::shared_ptr& executor_) { @@ -75,7 +79,7 @@ namespace eCAL // add new session and activate callback if we add the first session if (new_session) { - m_subscriber->addSession(host_name_, port_, Config::GetTcpPubsubMaxReconnectionAttemps()); + m_subscriber->addSession(host_name_, port_, m_attributes.max_reconnection_attempts); if (!m_callback_active) { m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1)); @@ -88,11 +92,9 @@ namespace eCAL void CDataReaderTCP::OnTcpMessage(const tcp_pubsub::CallbackData& data_) { - // extract header size - const size_t ecal_magic(4 * sizeof(char)); - // ECAL + header size field - const size_t header_length = ecal_magic + sizeof(uint16_t); - const uint16_t header_size = le16toh(*reinterpret_cast(data_.buffer_->data() + ecal_magic)); + // ECAL + header size field + const size_t header_length = m_attributes.ecal_magic + sizeof(uint16_t); + const uint16_t header_size = le16toh(*reinterpret_cast(data_.buffer_->data() + m_attributes.ecal_magic)); // extract header const char* header_payload = data_.buffer_->data() + header_length; @@ -124,15 +126,18 @@ namespace eCAL //////////////// // LAYER //////////////// - CTCPReaderLayer::CTCPReaderLayer() : m_initialized(false) {} + CTCPReaderLayer::CTCPReaderLayer() + : m_initialized(false) + {} - void CTCPReaderLayer::Initialize() + void CTCPReaderLayer::Initialize(const eCAL::eCALReader::TCPLayer::SAttributes& attr_) { + m_attributes = attr_; if (m_initialized) return; m_initialized = true; const tcp_pubsub::logger::logger_t tcp_pubsub_logger = std::bind(TcpPubsubLogger, std::placeholders::_1, std::placeholders::_2); - m_executor = std::make_shared(Config::GetTcpPubsubReaderThreadpoolSize(), tcp_pubsub_logger); + m_executor = std::make_shared(m_attributes.thread_pool_size, tcp_pubsub_logger); } void CTCPReaderLayer::AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) @@ -142,7 +147,7 @@ namespace eCAL const std::lock_guard lock(m_datareadertcp_sync); if (m_datareadertcp_map.find(map_key) != m_datareadertcp_map.end()) return; - const std::shared_ptr reader = std::make_shared(); + const std::shared_ptr reader = std::make_shared(eCAL::eCALReader::TCP::BuildTCPReaderAttributes(m_attributes)); reader->Create(m_executor); m_datareadertcp_map.insert(std::pair>(map_key, reader)); diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.h b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.h index 2eae0b2a5e..b33264e324 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.h +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.h @@ -24,6 +24,8 @@ #pragma once #include "readwrite/ecal_reader_layer.h" +#include "config/attributes/data_reader_tcp_attributes.h" +#include "config/attributes/tcp_reader_layer_attributes.h" #include #include @@ -42,7 +44,7 @@ namespace eCAL class CDataReaderTCP { public: - CDataReaderTCP(); + CDataReaderTCP(const eCAL::eCALReader::TCP::SAttributes& attr_); bool Create(std::shared_ptr& executor_); bool Destroy(); @@ -56,17 +58,18 @@ namespace eCAL std::shared_ptr m_subscriber; bool m_callback_active; + eCAL::eCALReader::TCP::SAttributes m_attributes; }; //////////////// // LAYER //////////////// - class CTCPReaderLayer : public CReaderLayer + class CTCPReaderLayer : public CReaderLayer { public: CTCPReaderLayer(); - void Initialize() override; + void Initialize(const eCAL::eCALReader::TCPLayer::SAttributes& attr_) override; void AddSubscription(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) override; void RemSubscription(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_) override; @@ -80,5 +83,6 @@ namespace eCAL using DataReaderTCPMapT = std::unordered_map>; std::mutex m_datareadertcp_sync; DataReaderTCPMapT m_datareadertcp_map; + eCAL::eCALReader::TCPLayer::SAttributes m_attributes; }; } diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index aca9b7fa6d..d172891278 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -38,25 +38,20 @@ namespace eCAL std::mutex CDataWriterTCP::g_tcp_writer_executor_mtx; std::shared_ptr CDataWriterTCP::g_tcp_writer_executor; - CDataWriterTCP::CDataWriterTCP(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const Publisher::Layer::TCP::Configuration& tcp_config_) : - m_config(tcp_config_) + CDataWriterTCP::CDataWriterTCP(const eCAL::eCALWriter::TCP::SAttributes& attr_) : + m_attributes(attr_) { { const std::lock_guard lock(g_tcp_writer_executor_mtx); if (!g_tcp_writer_executor) { - g_tcp_writer_executor = std::make_shared(Config::GetTcpPubsubWriterThreadpoolSize(), TcpPubsubLogger); + g_tcp_writer_executor = std::make_shared(m_attributes.thread_pool_size, TcpPubsubLogger); } } // create publisher m_publisher = std::make_shared(g_tcp_writer_executor); m_port = m_publisher->getPort(); - - // writer parameter - m_host_name = host_name_; - m_topic_name = topic_name_; - m_topic_id = topic_id_; } SWriterInfo CDataWriterTCP::GetInfo() @@ -81,8 +76,8 @@ namespace eCAL // create new payload sample (header information only, no payload) Payload::Sample proto_header; auto& proto_header_topic = proto_header.topic_info; - proto_header_topic.tname = m_topic_name; - proto_header_topic.tid = m_topic_id; + proto_header_topic.tname = m_attributes.topic_name; + proto_header_topic.tid = m_attributes.topic_id; // set payload content (without payload) auto& proto_header_content = proto_header.content; diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h index 2aeedf01db..af9ea016e2 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h @@ -23,7 +23,7 @@ #pragma once -#include +#include "config/attributes/data_writer_tcp_attributes.h" #include "readwrite/ecal_writer_base.h" @@ -40,7 +40,7 @@ namespace eCAL class CDataWriterTCP : public CDataWriterBase { public: - CDataWriterTCP(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const Publisher::Layer::TCP::Configuration& tcp_config_); + CDataWriterTCP(const eCAL::eCALWriter::TCP::SAttributes& attr_); SWriterInfo GetInfo() override; @@ -49,7 +49,7 @@ namespace eCAL Registration::ConnectionPar GetConnectionParameter() override; private: - Publisher::Layer::TCP::Configuration m_config; + eCAL::eCALWriter::TCP::SAttributes m_attributes; std::vector m_header_buffer; diff --git a/ecal/core/src/readwrite/udp/config/attributes/reader_udp_attributes.h b/ecal/core/src/readwrite/udp/config/attributes/reader_udp_attributes.h new file mode 100644 index 0000000000..20f958e9b7 --- /dev/null +++ b/ecal/core/src/readwrite/udp/config/attributes/reader_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 eCALReader + { + namespace UDP + { + struct SAttributes + { + std::string address; + int port; + bool broadcast; + bool loopback; + int receive_buffer; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/udp/config/attributes/writer_udp_attributes.h b/ecal/core/src/readwrite/udp/config/attributes/writer_udp_attributes.h new file mode 100644 index 0000000000..c829864e45 --- /dev/null +++ b/ecal/core/src/readwrite/udp/config/attributes/writer_udp_attributes.h @@ -0,0 +1,45 @@ +/* ========================= 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 eCALWriter + { + namespace UDP + { + struct SAttributes + { + std::string address; + int port; + int ttl; + bool broadcast; + bool loopback; + int send_buffer; + + std::string host_name; + std::string topic_name; + std::string topic_id; + }; + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.cpp b/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.cpp new file mode 100644 index 0000000000..da0ae681fe --- /dev/null +++ b/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.cpp @@ -0,0 +1,64 @@ +/* ========================= 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 "udp_attribute_builder.h" + +namespace eCAL +{ + namespace eCALReader + { + namespace UDP + { + eCAL::UDP::SReceiverAttr ConvertToIOUDPReceiverAttributes(const eCAL::eCALReader::UDP::SAttributes& attr_) + { + eCAL::UDP::SReceiverAttr receiver_attr; + receiver_attr.broadcast = attr_.broadcast; + receiver_attr.loopback = attr_.loopback; + + receiver_attr.rcvbuf = attr_.receive_buffer; + receiver_attr.port = attr_.port; + receiver_attr.address = attr_.address; + + return receiver_attr; + } + } + } + + namespace eCALWriter + { + namespace UDP + { + eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes(const SAttributes& attr_) + { + eCAL::UDP::SSenderAttr sender_attr; + sender_attr.broadcast = attr_.broadcast; + sender_attr.loopback = attr_.loopback; + + sender_attr.sndbuf = attr_.send_buffer; + sender_attr.port = attr_.port; + sender_attr.address = attr_.address; + sender_attr.ttl = attr_.ttl; + + return sender_attr; + } + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.h b/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.h new file mode 100644 index 0000000000..176ae2e131 --- /dev/null +++ b/ecal/core/src/readwrite/udp/config/builder/udp_attribute_builder.h @@ -0,0 +1,44 @@ +/* ========================= 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 "readwrite/udp/config/attributes/reader_udp_attributes.h" +#include "readwrite/udp/config/attributes/writer_udp_attributes.h" +#include "io/udp/ecal_udp_receiver_attr.h" +#include "io/udp/ecal_udp_sender_attr.h" + +namespace eCAL +{ + namespace eCALReader + { + namespace UDP + { + eCAL::UDP::SReceiverAttr ConvertToIOUDPReceiverAttributes(const SAttributes& attr_); + } + } + + namespace eCALWriter + { + namespace UDP + { + eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes(const SAttributes& attr_); + } + } +} \ No newline at end of file diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp.cpp b/ecal/core/src/readwrite/udp/ecal_reader_udp.cpp index 2036f6fe01..b4ed915f70 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp.cpp +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp.cpp @@ -28,6 +28,7 @@ #include "io/udp/ecal_udp_configurations.h" #include "pubsub/ecal_subgate.h" +#include "config/builder/udp_attribute_builder.h" #include #include @@ -39,40 +40,32 @@ namespace eCAL //////////////// // LAYER //////////////// - CUDPReaderLayer::CUDPReaderLayer() : - m_started(false), - m_local_mode(false) + CUDPReaderLayer::CUDPReaderLayer() : m_started(false) {} CUDPReaderLayer::~CUDPReaderLayer() = default; - void CUDPReaderLayer::Initialize() + void CUDPReaderLayer::Initialize(const eCAL::eCALReader::UDP::SAttributes& attr_) { + m_attributes = attr_; } void CUDPReaderLayer::AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) { if (!m_started) - { - // set local mode - m_local_mode = UDP::IsBroadcast(); - - // set network attributes - eCAL::UDP::SReceiverAttr attr; - attr.address = UDP::GetPayloadAddress(); - attr.port = UDP::GetPayloadPort(); - attr.broadcast = UDP::IsBroadcast(); - attr.loopback = true; - attr.rcvbuf = UDP::GetReceiveBufferSize(); - + { // start payload sample receiver - m_payload_receiver = std::make_shared(attr, std::bind(&CUDPReaderLayer::HasSample, this, std::placeholders::_1), std::bind(&CUDPReaderLayer::ApplySample, this, std::placeholders::_1, std::placeholders::_2)); + m_payload_receiver = std::make_shared( + eCALReader::UDP::ConvertToIOUDPReceiverAttributes(m_attributes), + std::bind(&CUDPReaderLayer::HasSample, this, std::placeholders::_1), + std::bind(&CUDPReaderLayer::ApplySample, this, std::placeholders::_1, std::placeholders::_2) + ); m_started = true; } // we use udp broadcast in local mode - if (m_local_mode) return; + if (m_attributes.broadcast) return; // add topic name based multicast address const std::string mcast_address = UDP::GetTopicPayloadAddress(topic_name_); @@ -87,7 +80,7 @@ namespace eCAL void CUDPReaderLayer::RemSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) { // we use udp broadcast in local mode - if (m_local_mode) return; + if (m_attributes.broadcast) return; const std::string mcast_address = UDP::GetTopicPayloadAddress(topic_name_); if (m_topic_name_mcast_map.find(mcast_address) == m_topic_name_mcast_map.end()) diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp.h b/ecal/core/src/readwrite/udp/ecal_reader_udp.h index 5360dc5ca3..e0038d99be 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp.h +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp.h @@ -25,6 +25,7 @@ #include "io/udp/ecal_udp_sample_receiver.h" #include "readwrite/ecal_reader_layer.h" +#include "config/attributes/reader_udp_attributes.h" #include #include @@ -36,13 +37,13 @@ namespace eCAL //////////////// // LAYER //////////////// - class CUDPReaderLayer : public CReaderLayer + class CUDPReaderLayer : public CReaderLayer { public: CUDPReaderLayer(); ~CUDPReaderLayer() override; - void Initialize() override; + void Initialize(const eCAL::eCALReader::UDP::SAttributes& attr_) override; void AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) override; void RemSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) override; @@ -54,8 +55,9 @@ namespace eCAL bool ApplySample(const char* serialized_sample_data_, size_t serialized_sample_size_); bool m_started; - bool m_local_mode; std::shared_ptr m_payload_receiver; std::map m_topic_name_mcast_map; + + eCAL::eCALReader::UDP::SAttributes m_attributes; }; } diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp.cpp index ba09c10325..76af9e7ebd 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp.cpp @@ -25,36 +25,24 @@ #include #include "ecal_writer_udp.h" -#include "io/udp/ecal_udp_configurations.h" #include "serialization/ecal_serialize_sample_payload.h" -#include "ecal/ecal_config.h" + +#include "config/builder/udp_attribute_builder.h" #include namespace eCAL { - CDataWriterUdpMC::CDataWriterUdpMC(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const Publisher::Layer::UDP::Configuration& udp_config_) : - m_config(udp_config_) + CDataWriterUdpMC::CDataWriterUdpMC(const eCALWriter::UDP::SAttributes& attr_) : + m_attributes(attr_) { - m_host_name = host_name_; - m_topic_name = topic_name_; - m_topic_id = topic_id_; - - // set network attributes - eCAL::UDP::SSenderAttr attr; - attr.address = UDP::GetTopicPayloadAddress(topic_name_); - attr.port = UDP::GetPayloadPort(); - attr.ttl = UDP::GetMulticastTtl(); - attr.broadcast = UDP::IsBroadcast(); - attr.sndbuf = UDP::GetSendBufferSize(); - // create udp/sample sender with activated loop-back - attr.loopback = true; - m_sample_sender_loopback = std::make_shared(attr); + m_attributes.loopback = true; + m_sample_sender_loopback = std::make_shared(eCAL::eCALWriter::UDP::ConvertToIOUDPSenderAttributes(m_attributes)); // create udp/sample sender without activated loop-back - attr.loopback = false; - m_sample_sender_no_loopback = std::make_shared(attr); + m_attributes.loopback = false; + m_sample_sender_no_loopback = std::make_shared(eCAL::eCALWriter::UDP::ConvertToIOUDPSenderAttributes(m_attributes)); } SWriterInfo CDataWriterUdpMC::GetInfo() @@ -80,9 +68,9 @@ namespace eCAL // fill sample info auto& ecal_sample_topic_info = ecal_sample.topic_info; - ecal_sample_topic_info.hname = m_host_name; - ecal_sample_topic_info.tname = m_topic_name; - ecal_sample_topic_info.tid = m_topic_id; + ecal_sample_topic_info.hname = m_attributes.host_name; + ecal_sample_topic_info.tname = m_attributes.topic_name; + ecal_sample_topic_info.tid = m_attributes.topic_id; // append content auto& ecal_sample_content = ecal_sample.content; diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp.h b/ecal/core/src/readwrite/udp/ecal_writer_udp.h index 8a76cc0489..bfcbbfc6e8 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp.h +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp.h @@ -23,10 +23,9 @@ #pragma once -#include - #include "io/udp/ecal_udp_sample_sender.h" #include "readwrite/ecal_writer_base.h" +#include "config/attributes/writer_udp_attributes.h" #include #include @@ -37,17 +36,17 @@ namespace eCAL class CDataWriterUdpMC : public CDataWriterBase { public: - CDataWriterUdpMC(const std::string& host_name_, const std::string& topic_name_, const std::string& topic_id_, const Publisher::Layer::UDP::Configuration& udp_config_); + CDataWriterUdpMC(const eCALWriter::UDP::SAttributes& attr_); SWriterInfo GetInfo() override; bool Write(const void* buf_, const SWriterAttr& attr_) override; protected: - Publisher::Layer::UDP::Configuration m_config; - std::vector m_sample_buffer; std::shared_ptr m_sample_sender_loopback; std::shared_ptr m_sample_sender_no_loopback; + + eCALWriter::UDP::SAttributes m_attributes; }; } diff --git a/ecal/core/src/registration/config/attributes/registration_attributes.h b/ecal/core/src/registration/config/attributes/registration_attributes.h index f080bbc0c3..f19db2b330 100644 --- a/ecal/core/src/registration/config/attributes/registration_attributes.h +++ b/ecal/core/src/registration/config/attributes/registration_attributes.h @@ -27,7 +27,7 @@ namespace eCAL { namespace Registration { - struct SUDPModeAttrributes + struct SUDPModeAttributes { std::string group; int ttl; @@ -39,8 +39,8 @@ namespace eCAL int port; int sendbuffer; int receivebuffer; - SUDPModeAttrributes network; - SUDPModeAttrributes local; + SUDPModeAttributes network; + SUDPModeAttributes local; }; struct SSHMAttributes diff --git a/ecal/core/src/registration/config/builder/udp_shm_attribute_builder.cpp b/ecal/core/src/registration/config/builder/udp_shm_attribute_builder.cpp index 29965d9c8c..487ecc69e3 100644 --- a/ecal/core/src/registration/config/builder/udp_shm_attribute_builder.cpp +++ b/ecal/core/src/registration/config/builder/udp_shm_attribute_builder.cpp @@ -55,7 +55,7 @@ namespace eCAL receiver_attr.broadcast = !provider_attr_.network_enabled; receiver_attr.loopback = true; - receiver_attr.rcvbuf = provider_attr_.udp.receivebuffer; + receiver_attr.receive_buffer = provider_attr_.udp.receivebuffer; receiver_attr.port = provider_attr_.udp.port; switch (provider_attr_.udp.mode) diff --git a/ecal/core/src/registration/udp/config/attributes/registration_receiver_udp_attributes.h b/ecal/core/src/registration/udp/config/attributes/registration_receiver_udp_attributes.h index 96695c675e..eb6771664a 100644 --- a/ecal/core/src/registration/udp/config/attributes/registration_receiver_udp_attributes.h +++ b/ecal/core/src/registration/udp/config/attributes/registration_receiver_udp_attributes.h @@ -33,7 +33,7 @@ namespace eCAL int port = 0; bool broadcast = false; bool loopback = true; - int rcvbuf = 1024 * 1024; + int receive_buffer = 1024 * 1024; }; } } diff --git a/ecal/core/src/registration/udp/config/builder/udp_attribute_builder.cpp b/ecal/core/src/registration/udp/config/builder/udp_attribute_builder.cpp index 345229fd19..f90e184fa0 100644 --- a/ecal/core/src/registration/udp/config/builder/udp_attribute_builder.cpp +++ b/ecal/core/src/registration/udp/config/builder/udp_attribute_builder.cpp @@ -42,7 +42,7 @@ namespace eCAL eCAL::UDP::SReceiverAttr attr; attr.broadcast = receiver_attr_.broadcast; attr.loopback = receiver_attr_.loopback; - attr.rcvbuf = receiver_attr_.rcvbuf; + attr.rcvbuf = receiver_attr_.receive_buffer; attr.port = receiver_attr_.port; attr.address = receiver_attr_.address; return attr;