From 382d9ef05002d8d44d886b6633afb126bda6b109 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:23:08 +0100 Subject: [PATCH 001/105] First working implementation for config management. --- ecal/core/CMakeLists.txt | 3 + .../src/config/ecal_config_initializer.cpp | 291 ++++++++++++++++++ ecal/core/src/ecal.cpp | 11 +- ecal/core/src/ecal_descgate.cpp | 5 +- ecal/core/src/ecal_global_accessors.cpp | 11 +- ecal/core/src/ecal_global_accessors.h | 6 + ecal/core/src/ecal_globals.cpp | 14 +- ecal/core/src/ecal_globals.h | 10 + ecal/core/src/ecal_process.cpp | 62 ++-- .../src/io/udp/ecal_udp_configurations.cpp | 33 +- ecal/core/src/logging/ecal_log_impl.cpp | 13 +- .../src/monitoring/ecal_monitoring_impl.cpp | 14 +- ecal/core/src/pubsub/ecal_publisher.cpp | 8 +- ecal/core/src/readwrite/ecal_reader.cpp | 20 +- ecal/core/src/readwrite/ecal_writer.cpp | 30 +- .../src/readwrite/shm/ecal_reader_shm.cpp | 2 +- .../src/readwrite/shm/ecal_writer_shm.cpp | 6 +- .../src/readwrite/tcp/ecal_reader_tcp.cpp | 4 +- .../src/readwrite/tcp/ecal_writer_tcp.cpp | 3 +- .../src/readwrite/udp/ecal_reader_udp_mc.cpp | 2 +- .../src/readwrite/udp/ecal_writer_udp_mc.cpp | 4 +- .../ecal_registration_provider.cpp | 14 +- .../ecal_registration_receiver.cpp | 12 +- .../src/service/ecal_service_server_impl.cpp | 8 +- ecal/core/src/time/ecal_timegate.cpp | 2 +- 25 files changed, 465 insertions(+), 123 deletions(-) create mode 100644 ecal/core/src/config/ecal_config_initializer.cpp diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 9a565a3a40..343689ddef 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -60,6 +60,7 @@ set(ecal_config_src src/config/ecal_config_reader.cpp src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h + src/config/ecal_config_initializer.cpp ) ###################################### @@ -335,6 +336,7 @@ set(ecal_cmn_src src/ecal_global_accessors.h src/ecal_globals.h src/ecal_sample_to_topicinfo.h + include/ecal/types/ecal_config_types.h ) if (WIN32) list (APPEND @@ -397,6 +399,7 @@ set(ecal_header_cmn include/ecal/ecalc_types.h include/ecal/ecal_types.h include/ecal/types/monitoring.h + include/ecal/types/ecal_config_types.h ) set(ecal_header_cimpl diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp new file mode 100644 index 0000000000..26aa13dc1c --- /dev/null +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -0,0 +1,291 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 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 ================================= +*/ + +/** + * @brief Functions for setting default config values +**/ + +#include "ecal/types/ecal_config_types.h" +#include "ecal_config_reader.h" + +#include "ecal_global_accessors.h" +#include "config/ecal_config_reader.h" + +#define COMMON "common" +#define MONITORING "monitoring" +#define NETWORK "network" +#define EXPERIMENTAL "experimental" +#define PUBLISHER "publisher" +#define SYS "sys" +#define TIME "time" +#define SERVICE "service" + +namespace { + void tokenize(const std::string& str, std::vector& tokens, + const std::string& delimiters = " ", bool trimEmpty = false) + { + std::string::size_type pos, lastPos = 0; + + for (;;) + { + pos = str.find_first_of(delimiters, lastPos); + if (pos == std::string::npos) + { + pos = str.length(); + if (pos != lastPos || !trimEmpty) + { + tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); + } + break; + } + else + { + if (pos != lastPos || !trimEmpty) + { + tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); + } + } + lastPos = pos + 1; + } + } + + eCAL_Logging_Filter ParseLogLevel(const std::string& filter_) + { + // tokenize it + std::vector token_filter_; + tokenize(filter_, token_filter_, " ,;"); + // create excluding filter list + char filter_mask = log_level_none; + for (auto& it : token_filter_) + { + if (it == "all") filter_mask |= log_level_all; + if (it == "info") filter_mask |= log_level_info; + if (it == "warning") filter_mask |= log_level_warning; + if (it == "error") filter_mask |= log_level_error; + if (it == "fatal") filter_mask |= log_level_fatal; + if (it == "debug1") filter_mask |= log_level_debug1; + if (it == "debug2") filter_mask |= log_level_debug2; + if (it == "debug3") filter_mask |= log_level_debug3; + if (it == "debug4") filter_mask |= log_level_debug4; + } + return(filter_mask); + }; +} + +namespace eCAL +{ + namespace Config + { + eCALConfig GetDefaultConfig() + { + eCALConfig config; + + // transport layer options + auto transportLayerOptions = &config.transport_layer_options; + transportLayerOptions->network_enabled = false; + transportLayerOptions->drop_out_of_order_messages = false; + + auto multicastOptions = &transportLayerOptions->mc_options; + multicastOptions->config_version = UdpConfigVersion::V1; + multicastOptions->group = std::string("239.0.0.1"); + multicastOptions->mask = std::string("0.0.0.15"); + multicastOptions->port = 14000; + multicastOptions->ttl = 2; + multicastOptions->recbuf = (1024 * 1024 * 5); + multicastOptions->sndbuf = (1024 * 1024 * 5); + multicastOptions->join_all_interfaces = false; + multicastOptions->bandwidth_max_udp = -1; + multicastOptions->npcap_enabled = false; + + auto tcpPubSubOptions = &transportLayerOptions->tcp_options; + tcpPubSubOptions->num_executor_reader = 4; + tcpPubSubOptions->num_executor_writer = 4; + tcpPubSubOptions->max_reconnections = 5; + + auto shmOptions = &transportLayerOptions->shm_options; + shmOptions->host_group_name = ""; + shmOptions->memfile_minsize = 4096; + shmOptions->memfile_reserve = 50; + shmOptions->memfile_ack_timeout = 0; + shmOptions->memfile_buffer_count = 1; + shmOptions->drop_out_of_order_messages = false; + shmOptions->memfile_zero_copy = false; + + // registration options + auto registrationOptions = &config.registration_options; + registrationOptions = new RegistrationOptions(RegistrationOptions::MS(60000), RegistrationOptions::MS(1000)); + registrationOptions->share_tdesc = true; + registrationOptions->share_ttype = true; + + // monitoring options + auto monitoringOptions = &config.monitoring_options; + monitoringOptions->monitoring_mode = MonitoringMode::none; + monitoringOptions->monitoring_timeout = 5000; + monitoringOptions->network_monitoring_disabled = false; + monitoringOptions->filter_excl = "__.*"; + monitoringOptions->filter_incl = ""; + monitoringOptions->filter_log_con = log_level_error | log_level_fatal | log_level_warning; + monitoringOptions->filter_log_file = log_level_none; + monitoringOptions->filter_log_udp = log_level_info | log_level_error | log_level_fatal | log_level_warning; + + auto udpMonitoringOptions = &monitoringOptions->udp_options; + // TODO: Nothing here yet + + auto shmMonitoringOptions = &monitoringOptions->shm_options; + shmMonitoringOptions->shm_monitoring_domain = "ecal_monitoring"; + shmMonitoringOptions->shm_monitoring_queue_size = 1024; + + // receiving options + auto receivingOptions = &config.receiving_options; + receivingOptions->inproc_recv_enabled = true; + receivingOptions->shm_recv_enabled = true; + receivingOptions->tcp_recv_enabled = true; + receivingOptions->udp_mc_recv_enabled = true; + + // publisher options + auto publisherOptions = &config.publisher_options; + publisherOptions->use_inproc = TLayer::smode_off; + publisherOptions->use_shm = TLayer::smode_auto; + publisherOptions->use_tcp = TLayer::smode_off; + publisherOptions->use_udp_mc = TLayer::smode_auto; + + // sys options + auto sysOptions = &config.sys_options; + sysOptions->filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; + + // timesync options + auto timesyncOptions = &config.timesync_options; + timesyncOptions->timesync_module = "ecaltime-localtime"; + + // service options + auto serviceOptions = &config.service_options; + serviceOptions->protocol_v0 = true; + serviceOptions->protocol_v1 = true; + + return config; + }; + + eCALConfig GetIniConfig() + { + CConfig iniConfig; + iniConfig.AddFile(g_default_ini_file); + + eCALConfig config; + // transport layer options + auto transportLayerOptions = &config.transport_layer_options; + transportLayerOptions->network_enabled = iniConfig.get(NETWORK, "network_enabled", false); + transportLayerOptions->drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); + + auto multicastOptions = &transportLayerOptions->mc_options; + + const std::string udp_config_version_string = iniConfig.get(NETWORK, "multicast_config_version", "v1"); + if (udp_config_version_string == "v1") + multicastOptions->config_version = UdpConfigVersion::V1; + if (udp_config_version_string == "v2") + multicastOptions->config_version = UdpConfigVersion::V2; + + multicastOptions->group = iniConfig.get(NETWORK, "multicast_group", "239.0.0.0"); + multicastOptions->mask = iniConfig.get(NETWORK, "multicast_mask", "0.0.0.15"); + multicastOptions->port = iniConfig.get(NETWORK, "multicast_port", 14000); + multicastOptions->ttl = iniConfig.get(NETWORK, "multicast_ttl", 3); + multicastOptions->recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", (1024 * 1024 * 5)); + multicastOptions->sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", (1024 * 1024 * 5)); + multicastOptions->join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", false); + multicastOptions->bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", (- 1)); + multicastOptions->npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", false); + + auto tcpPubSubOptions = &transportLayerOptions->tcp_options; + tcpPubSubOptions->num_executor_reader = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_reader", 4); + tcpPubSubOptions->num_executor_writer = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_writer", 4); + tcpPubSubOptions->max_reconnections = iniConfig.get(NETWORK, "tcp_pubsup_max_reconnections", 5); + + auto shmOptions = &transportLayerOptions->shm_options; + shmOptions->host_group_name = iniConfig.get(NETWORK, "host_group_name", ""); + shmOptions->memfile_minsize = iniConfig.get(PUBLISHER, "memfile_minsize", (4 * 1024)); + shmOptions->memfile_reserve = iniConfig.get(PUBLISHER, "memfile_reserve", 50); + shmOptions->memfile_ack_timeout = iniConfig.get(PUBLISHER, "memfile_ack_timeout", 0); + shmOptions->memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", 1); + shmOptions->drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); + shmOptions->memfile_zero_copy = (iniConfig.get(PUBLISHER, "memfile_zero_copy", 0) == 1) ? true : false; + + // registration options + auto registrationOptions = &config.registration_options; + auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", 5000); + auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", 1000); + registrationOptions = new RegistrationOptions(RegistrationOptions::MS(registrationTimeout), RegistrationOptions::MS(registrationRefresh)); + registrationOptions->share_tdesc = (iniConfig.get(PUBLISHER, "share_tdesc", 1) == 1) ? true : false; + registrationOptions->share_ttype = (iniConfig.get(PUBLISHER, "share_ttype", 1) == 1) ? true : false; + + // monitoring options + auto monitoringOptions = &config.monitoring_options; + auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; + monitoringOptions->monitoring_mode = monitoringMode; // What about UDP monitoring? + monitoringOptions->monitoring_timeout = iniConfig.get(MONITORING, "timeout", 5000);; + monitoringOptions->network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", false); + monitoringOptions->filter_excl = iniConfig.get(MONITORING, "filter_excl", "__.*"); + monitoringOptions->filter_incl = iniConfig.get(MONITORING, "filter_incl", ""); + monitoringOptions->filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); + monitoringOptions->filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); + monitoringOptions->filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); + + auto udpMonitoringOptions = &monitoringOptions->udp_options; + // TODO: Nothing here yet + + auto shmMonitoringOptions = &monitoringOptions->shm_options; + shmMonitoringOptions->shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", "ecal_monitoring"); + shmMonitoringOptions->shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", 1024); + + // receiving options + auto receivingOptions = &config.receiving_options; + receivingOptions->inproc_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); + receivingOptions->shm_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); + receivingOptions->tcp_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); + receivingOptions->udp_mc_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); + + // publisher options + auto publisherOptions = &config.publisher_options; + publisherOptions->use_inproc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_inproc", 0)); + publisherOptions->use_shm = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_shm", 0)); + publisherOptions->use_tcp = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_tcp", 0)); + publisherOptions->use_udp_mc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_udp_mc", 0)); + + // sys options + auto sysOptions = &config.sys_options; + sysOptions->filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file + + // timesync options + auto timesyncOptions = &config.timesync_options; + timesyncOptions->timesync_module = iniConfig.get(TIME, "timesync_module_rt", ""); + + // service options + auto serviceOptions = &config.service_options; + serviceOptions->protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; + serviceOptions->protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; + + return config; + + }; + + // after initialization + eCALConfig* GetCurrentConfig() + { + return g_ecal_config(); + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index a4c7ee299d..ae0a10cd6b 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -76,7 +76,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) + int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_, Config::eCALConfig* user_config_) { bool dump_config(false); std::vector config_keys; @@ -164,6 +164,11 @@ namespace eCAL } g_globals_ctx_ref_cnt++; + if (user_config_ != nullptr) + { + g_globals()->SetUserConfig(user_config_); + } + // (post)initialize single components const int success = g_globals()->Initialize(components_, &config_keys); @@ -185,12 +190,12 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - int Initialize(std::vector args_, const char *unit_name_, unsigned int components_) //-V826 + int Initialize(std::vector args_, const char *unit_name_, unsigned int components_, Config::eCALConfig* user_settings_) //-V826 { args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); std::vector argv(args_.size()); std::transform(args_.begin(), args_.end(), argv.begin(), [](std::string& s) {return s.c_str();}); - return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_); + return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_, user_settings_); } /** diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index c805c545fd..8e74f1ff88 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -23,6 +23,7 @@ #include #include +#include "ecal/types/ecal_config_types.h" #include "ecal_descgate.h" #include @@ -32,8 +33,8 @@ namespace eCAL { CDescGate::CDescGate() : - m_topic_info_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), - m_service_info_map(std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())) + m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), + m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())) { } CDescGate::~CDescGate() = default; diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index c2909c6edf..1dccf5a5f2 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -137,4 +137,13 @@ namespace eCAL if (g_globals() == nullptr) return(nullptr); return(g_globals()->memfile_map().get()); } -} + + Config::eCALConfig* g_ecal_config() + { + // TODO PG: discuss the priority + if (g_globals() == nullptr) return(nullptr); + if (g_globals()->user_config() != nullptr) return(g_globals()->user_config().get()); + if (g_globals()->ecal_ini_config() != nullptr) return(g_globals()->ecal_ini_config().get()); + if (g_globals()->ecal_default_config() != nullptr) return(g_globals()->ecal_default_config().get()); + } + } diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 6cb1117501..5455e6c7f1 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -45,6 +45,10 @@ namespace eCAL class CRegistrationReceiver; class CMemFileThreadPool; class CMemFileMap; + namespace Config + { + struct eCALConfig; + } // Declaration of getter functions for globally accessible variable instances CGlobals* g_globals(); @@ -61,6 +65,8 @@ namespace eCAL CRegistrationReceiver* g_registration_receiver(); CMemFileThreadPool* g_memfile_pool(); CMemFileMap* g_memfile_map(); + Config::eCALConfig* g_ecal_config(); + // declaration of globally accessible variables extern CGlobals* g_globals_ctx; diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 69f8906c8b..ebed7bcd93 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -31,7 +31,7 @@ namespace eCAL { - CGlobals::CGlobals() : initialized(false), components(0) + CGlobals::CGlobals() : initialized(false), components(0), ecal_default_config_instance(std::make_unique()) {} CGlobals::~CGlobals() @@ -39,6 +39,12 @@ namespace eCAL Finalize(Init::All); } + void CGlobals::SetUserConfig(Config::eCALConfig* user_config_) + { + user_config_instance = std::make_unique(); + std::memcpy(user_config_instance.get(), user_config_, sizeof(Config::eCALConfig)); + } + int CGlobals::Initialize(unsigned int components_, std::vector* config_keys_ /*= nullptr*/) { // will be set if any new module was initialized @@ -71,6 +77,9 @@ namespace eCAL throw std::runtime_error(emsg.c_str()); } + ecal_ini_config_instance = std::make_unique(Config::GetIniConfig()); + ecal_default_config_instance = std::make_unique(Config::GetDefaultConfig()); + new_initialization = true; } @@ -293,6 +302,9 @@ namespace eCAL memfile_map_instance = nullptr; log_instance = nullptr; config_instance = nullptr; + user_config_instance.reset(); + ecal_ini_config_instance.reset(); + ecal_default_config_instance.reset(); initialized = false; diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index 21a5ecf107..ee1f044892 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -36,6 +36,7 @@ #include "service/ecal_clientgate.h" #include "io/shm/ecal_memfile_pool.h" #include "io/shm/ecal_memfile_db.h" +#include "ecal/types/ecal_config_types.h" #include @@ -50,6 +51,8 @@ namespace eCAL int Initialize ( unsigned int components_, std::vector* config_keys_ = nullptr); int IsInitialized ( unsigned int component_ ); + void SetUserConfig(Config::eCALConfig* user_settings_); + unsigned int GetComponents() { return(components); }; int Finalize(unsigned int components_); @@ -67,6 +70,10 @@ namespace eCAL const std::unique_ptr& registration_receiver() { return registration_receiver_instance; }; const std::unique_ptr& memfile_pool() { return memfile_pool_instance; }; const std::unique_ptr& memfile_map() { return memfile_map_instance; }; + const std::unique_ptr& user_config() { return user_config_instance; }; + const std::unique_ptr& ecal_ini_config() { return ecal_ini_config_instance; }; + const std::unique_ptr& ecal_default_config() { return ecal_default_config_instance; }; + private: bool initialized; @@ -84,5 +91,8 @@ namespace eCAL std::unique_ptr registration_receiver_instance; std::unique_ptr memfile_pool_instance; std::unique_ptr memfile_map_instance; + std::unique_ptr user_config_instance; + std::unique_ptr ecal_ini_config_instance; + std::unique_ptr ecal_default_config_instance; }; } diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 47dfc72fe5..4af38bb746 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -26,6 +26,7 @@ #include "ecal_def.h" #include "config/ecal_config_reader_hlp.h" +#include "ecal/types/ecal_config_types.h" #include "registration/ecal_registration_receiver.h" #include "ecal_globals.h" #include "ecal_process.h" @@ -214,14 +215,14 @@ namespace eCAL } sstream << "------------------------- CONFIGURATION --------------------------" << std::endl; - sstream << "Default INI : " << Config::GetLoadedEcalIniPath() << std::endl; + sstream << "Default INI : " << Config::GetCurrentConfig()->loaded_ecal_ini_file << std::endl; sstream << std::endl; sstream << "------------------------- NETWORK --------------------------------" << std::endl; sstream << "Host name : " << Process::GetHostName() << std::endl; sstream << "Host group name : " << Process::GetHostGroupName() << std::endl; - if (Config::IsNetworkEnabled()) + if (Config::GetCurrentConfig()->transport_layer_options.network_enabled) { sstream << "Network mode : cloud" << std::endl; } @@ -229,16 +230,17 @@ namespace eCAL { sstream << "Network mode : local" << std::endl; } + sstream << "Network ttl : " << UDP::GetMulticastTtl() << std::endl; - sstream << "Network sndbuf : " << GetBufferStr(Config::GetUdpMulticastSndBufSizeBytes()) << std::endl; - sstream << "Network rcvbuf : " << GetBufferStr(Config::GetUdpMulticastRcvBufSizeBytes()) << std::endl; - sstream << "Multicast cfg version : v" << static_cast(Config::GetUdpMulticastConfigVersion()) << std::endl; - sstream << "Multicast group : " << Config::GetUdpMulticastGroup() << std::endl; - sstream << "Multicast mask : " << Config::GetUdpMulticastMask() << std::endl; - const int port = Config::GetUdpMulticastPort(); + sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get()) << std::endl; + sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get()) << std::endl; + sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig()->transport_layer_options.mc_options.config_version) << std::endl; + sstream << "Multicast group : " << Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get() << std::endl; + sstream << "Multicast mask : " << Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get() << std::endl; + const int port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); sstream << "Multicast ports : " << port << " - " << port + 10 << std::endl; - sstream << "Multicast join all IFs : " << (Config::IsUdpMulticastJoinAllIfEnabled() ? "on" : "off") << std::endl; - auto bandwidth = Config::GetMaxUdpBandwidthBytesPerSecond(); + sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig()->transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << std::endl; + auto bandwidth = Config::GetCurrentConfig()->transport_layer_options.mc_options.bandwidth_max_udp; if (bandwidth < 0) { sstream << "Bandwidth limit (udp) : not limited" << std::endl; @@ -250,7 +252,7 @@ namespace eCAL sstream << std::endl; sstream << "------------------------- TIME -----------------------------------" << std::endl; - sstream << "Synchronization realtime : " << Config::GetTimesyncModuleName() << std::endl; + sstream << "Synchronization realtime : " << Config::GetCurrentConfig()->timesync_options.timesync_module << std::endl; sstream << "Synchronization replay : " << eCALPAR(TIME, SYNC_MOD_REPLAY) << std::endl; sstream << "State : "; if (g_timegate()->IsSynchronized()) sstream << " synchronized " << std::endl; @@ -265,34 +267,34 @@ namespace eCAL sstream << std::endl; sstream << "------------------------- PUBLISHER LAYER DEFAULTS ---------------" << std::endl; - sstream << "Layer Mode INPROC : " << LayerMode(Config::GetPublisherInprocMode()) << std::endl; - auto zero_copy = Config::IsMemfileZerocopyEnabled(); + sstream << "Layer Mode INPROC : " << LayerMode(Config::GetCurrentConfig()->publisher_options.use_inproc) << std::endl; + auto zero_copy = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_zero_copy; if (zero_copy) { - sstream << "Layer Mode SHM (ZEROCPY) : " << LayerMode(Config::GetPublisherShmMode()) << std::endl; + sstream << "Layer Mode SHM (ZEROCPY) : " << LayerMode(Config::GetCurrentConfig()->publisher_options.use_shm) << std::endl; } else { - sstream << "Layer Mode SHM : " << LayerMode(Config::GetPublisherShmMode()) << std::endl; + sstream << "Layer Mode SHM : " << LayerMode(Config::GetCurrentConfig()->publisher_options.use_shm) << std::endl; } - sstream << "Layer Mode TCP : " << LayerMode(Config::GetPublisherTcpMode()) << std::endl; - sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetPublisherUdpMulticastMode()) << std::endl; + sstream << "Layer Mode TCP : " << LayerMode(Config::GetCurrentConfig()->publisher_options.use_tcp) << std::endl; + sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig()->publisher_options.use_udp_mc) << std::endl; sstream << std::endl; sstream << "------------------------- SUBSCRIPTION LAYER DEFAULTS ------------" << std::endl; - sstream << "Layer Mode INPROC : " << LayerMode(Config::IsInprocRecEnabled()) << std::endl; - sstream << "Layer Mode SHM : " << LayerMode(Config::IsShmRecEnabled()) << std::endl; - sstream << "Layer Mode TCP : " << LayerMode(Config::IsTcpRecEnabled()) << std::endl; - sstream << "Layer Mode UDP MC : " << LayerMode(Config::IsUdpMulticastRecEnabled()) << std::endl; - sstream << "Npcap UDP Reciever : " << LayerMode(Config::IsNpcapEnabled()); + sstream << "Layer Mode INPROC : " << LayerMode(Config::GetCurrentConfig()->receiving_options.inproc_recv_enabled) << std::endl; + sstream << "Layer Mode SHM : " << LayerMode(Config::GetCurrentConfig()->receiving_options.shm_recv_enabled) << std::endl; + sstream << "Layer Mode TCP : " << LayerMode(Config::GetCurrentConfig()->receiving_options.tcp_recv_enabled) << std::endl; + sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig()->receiving_options.udp_mc_recv_enabled) << std::endl; + sstream << "Npcap UDP Receiver : " << LayerMode(Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled); #ifdef ECAL_NPCAP_SUPPORT - if(Config::IsNpcapEnabled() && !Udpcap::Initialize()) + if(Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled && !Udpcap::Initialize()) { sstream << " (Init FAILED!)"; } #else // ECAL_NPCAP_SUPPORT - if (Config::IsNpcapEnabled()) + if (Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled) { sstream << " (Npcap is enabled, but not configured via CMake!)"; } @@ -303,11 +305,11 @@ namespace eCAL sstream << "------------------------- EXPERIMENTAL ---------------------------" << std::endl; - sstream << "SHM Monitoring : " << (Config::Experimental::IsShmMonitoringEnabled() ? "on" : "off") << std::endl; - sstream << "SHM Monitoring (Domain) : " << Config::Experimental::GetShmMonitoringDomain() << std::endl; - sstream << "SHM Monitoring (Queue) : " << Config::Experimental::GetShmMonitoringQueueSize() << std::endl; - sstream << "Network Monitoring : " << (!Config::Experimental::IsNetworkMonitoringDisabled() ? "on" : "off") << std::endl; - sstream << "Drop out-of-order msgs : " << (Config::Experimental::GetDropOutOfOrderMessages() ? "on" : "off") << std::endl; + sstream << "SHM Monitoring : " << ( static_cast(Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? "on" : "off") << std::endl; + sstream << "SHM Monitoring (Domain) : " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain << std::endl; + sstream << "SHM Monitoring (Queue) : " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size << std::endl; + sstream << "Network Monitoring : " << (!Config::GetCurrentConfig()->monitoring_options.network_monitoring_disabled ? "on" : "off") << std::endl; + sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig()->transport_layer_options.drop_out_of_order_messages ? "on" : "off") << std::endl; sstream << std::endl; // write it into std:string @@ -333,7 +335,7 @@ namespace eCAL std::string GetHostGroupName() { - return Config::GetHostGroupName().empty() ? GetHostName() : Config::GetHostGroupName(); + return Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name.empty() ? GetHostName() : Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name; } int GetHostID() diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index 47919811fe..e8b4cd2e9a 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -21,6 +21,7 @@ #include "ecal_def.h" #include "ecal_udp_topic2mcast.h" +#include "ecal/types/ecal_config_types.h" #include @@ -35,7 +36,7 @@ namespace eCAL */ bool IsBroadcast() { - return !Config::IsNetworkEnabled(); + return !Config::GetCurrentConfig()->transport_layer_options.network_enabled; } /** @@ -45,7 +46,7 @@ namespace eCAL */ bool IsNpcapEnabled() { - return Config::IsNpcapEnabled(); + return Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled; } /** @@ -57,7 +58,7 @@ namespace eCAL */ bool IsUdpMulticastJoinAllIfEnabled() { - return Config::IsUdpMulticastJoinAllIfEnabled(); + return Config::GetCurrentConfig()->transport_layer_options.mc_options.join_all_interfaces; } /** @@ -78,20 +79,20 @@ namespace eCAL std::string GetRegistrationAddress() { // check if the network is disabled - const bool local_only = !Config::IsNetworkEnabled(); + const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; if (local_only) { return GetLocalBroadcastAddress(); } // both in v1 and v2, the multicast group is returned as the adress for the registration layer - return Config::GetUdpMulticastGroup(); + return Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(); } int GetRegistrationPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetUdpMulticastPort(); + const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_REG_OFF, to obtain the registration port return configured_port + NET_UDP_MULTICAST_PORT_REG_OFF; @@ -106,7 +107,7 @@ namespace eCAL int GetLoggingPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetUdpMulticastPort(); + const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_LOG_OFF, to obtain the logging port return configured_port + NET_UDP_MULTICAST_PORT_LOG_OFF; @@ -121,7 +122,7 @@ namespace eCAL std::string GetTopicPayloadAddress(const std::string& topic_name) { // check if the network is disabled - const bool local_only = !Config::IsNetworkEnabled(); + const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; if (local_only) { // if network is disabled, return the local broadcast address @@ -129,23 +130,23 @@ namespace eCAL } // determine the UDP multicast configuration version - if (Config::GetUdpMulticastConfigVersion() == Config::UdpConfigVersion::V1) + if (Config::GetCurrentConfig()->transport_layer_options.mc_options.config_version == Config::UdpConfigVersion::V1) { // retrieve the corresponding multicast address based on the topic name using v1 implementation - return UDP::V1::topic2mcast(topic_name, Config::GetUdpMulticastGroup(), Config::GetUdpMulticastMask()); + return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get()); } // v2 else { // retrieve the corresponding multicast address based on the topic name using v2 implementation - return UDP::V2::topic2mcast(topic_name, Config::GetUdpMulticastGroup(), Config::GetUdpMulticastMask()); + return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get()); } } int GetPayloadPort() { - // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetUdpMulticastPort(); + // retrieve the configured UDP multicat port from the configuration + const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_SAMPLE_OFF, to obtain the payload port return configured_port + NET_UDP_MULTICAST_PORT_SAMPLE_OFF; @@ -154,15 +155,15 @@ namespace eCAL int GetMulticastTtl() { // check if the network is disabled - const bool local_only = !Config::IsNetworkEnabled(); + const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; if (local_only) { // if network is disabled, return a TTL of 0 to restrict multicast packets to the local machine return 1; } - + // if network is enabled, return the configured UDP multicast TTL value - return Config::GetUdpMulticastTtl(); + return Config::GetCurrentConfig()->transport_layer_options.mc_options.ttl; } } } diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index 2ef0f14cc1..bf3ef0fafc 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "ecal_global_accessors.h" #include "ecal_log_impl.h" #include "io/udp/ecal_udp_configurations.h" @@ -128,9 +129,9 @@ namespace eCAL m_level = log_level_info; // parse logging filter strings - m_filter_mask_con = Config::GetConsoleLogFilter(); - m_filter_mask_file = Config::GetFileLogFilter(); - m_filter_mask_udp = Config::GetUdpLogFilter(); + m_filter_mask_con = Config::GetCurrentConfig()->monitoring_options.filter_log_con; + m_filter_mask_file = Config::GetCurrentConfig()->monitoring_options.filter_log_file; + m_filter_mask_udp = Config::GetCurrentConfig()->monitoring_options.filter_log_udp; // create log file if(m_filter_mask_file != 0) @@ -154,7 +155,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); + attr.sndbuf = g_ecal_config()->transport_layer_options.mc_options.sndbuf.get(); // create udp logging sender m_udp_logging_sender = std::make_unique(attr); @@ -166,7 +167,7 @@ namespace eCAL attr.port = UDP::GetLoggingPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); + attr.rcvbuf = g_ecal_config()->transport_layer_options.mc_options.recbuf.get(); // start logging receiver const UDP::CLoggingReceiver::LogMessageCallbackT log_message_callback = std::bind(&CLog::RegisterLogMessage, this, std::placeholders::_1); @@ -349,7 +350,7 @@ namespace eCAL { // in "network mode" we accept all log messages // in "local mode" we accept log messages from this host only - if ((m_hname == log_msg_.hname()) || Config::IsNetworkEnabled()) + if ((m_hname == log_msg_.hname()) || g_ecal_config()->transport_layer_options.network_enabled) { const std::lock_guard lock(m_log_msglist_sync); m_log_msglist.emplace_back(log_msg_); diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp index 1e46f5dcab..30430c71a7 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp @@ -40,11 +40,11 @@ namespace eCAL //////////////////////////////////////// CMonitoringImpl::CMonitoringImpl() : m_init(false), - m_process_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), - m_publisher_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), - m_subscriber_map(std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), - m_server_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), - m_clients_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())) + m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), + m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), + m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), + m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), + m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())) { } @@ -59,8 +59,8 @@ namespace eCAL g_registration_receiver()->SetCustomApplySampleCallback([this](const auto& ecal_sample_){this->ApplySample(ecal_sample_, eCAL::pb::tl_none);}); // setup blacklist and whitelist filter strings# - m_topic_filter_excl_s = Config::GetMonitoringFilterExcludeList(); - m_topic_filter_incl_s = Config::GetMonitoringFilterIncludeList(); + m_topic_filter_excl_s = Config::GetCurrentConfig()->monitoring_options.filter_excl; + m_topic_filter_incl_s = Config::GetCurrentConfig()->monitoring_options.filter_incl; // setup filtering on by default SetFilterState(true); diff --git a/ecal/core/src/pubsub/ecal_publisher.cpp b/ecal/core/src/pubsub/ecal_publisher.cpp index df1b34babb..1d01fcf86b 100644 --- a/ecal/core/src/pubsub/ecal_publisher.cpp +++ b/ecal/core/src/pubsub/ecal_publisher.cpp @@ -134,10 +134,10 @@ namespace eCAL // this can not be done in the constructor because a publisher is allowed // to construct before eCAL::Initialize and so global config is not // existing while construction - if (m_tlayer.sm_udp_mc == TLayer::smode_none) m_tlayer.sm_udp_mc = Config::GetPublisherUdpMulticastMode(); - if (m_tlayer.sm_shm == TLayer::smode_none) m_tlayer.sm_shm = Config::GetPublisherShmMode(); - if (m_tlayer.sm_tcp == TLayer::smode_none) m_tlayer.sm_tcp = Config::GetPublisherTcpMode(); - if (m_tlayer.sm_inproc == TLayer::smode_none) m_tlayer.sm_inproc = Config::GetPublisherInprocMode(); + if (m_tlayer.sm_udp_mc == TLayer::smode_none) m_tlayer.sm_udp_mc = Config::GetCurrentConfig()->publisher_options.use_udp_mc; + if (m_tlayer.sm_shm == TLayer::smode_none) m_tlayer.sm_shm = Config::GetCurrentConfig()->publisher_options.use_shm; + if (m_tlayer.sm_tcp == TLayer::smode_none) m_tlayer.sm_tcp = Config::GetCurrentConfig()->publisher_options.use_tcp; + if (m_tlayer.sm_inproc == TLayer::smode_none) m_tlayer.sm_inproc = Config::GetCurrentConfig()->publisher_options.use_inproc; // create data writer m_datawriter = std::make_shared(); diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index 0b44ca0080..6e85fcf810 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -101,15 +101,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(Config::GetRegistrationTimeoutMs()); + const std::chrono::milliseconds registration_timeout = Config::GetCurrentConfig()->registration_options.getTimeout(); m_loc_pub_map.set_expiration(registration_timeout); m_ext_pub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::IsTopicTypeSharingEnabled(); + m_use_ttype = Config::GetCurrentConfig()->registration_options.share_ttype; // allow to share topic description - m_use_tdesc = Config::IsTopicDescriptionSharingEnabled(); + m_use_tdesc = Config::GetCurrentConfig()->registration_options.share_tdesc; // start transport layers SubscribeToLayers(); @@ -169,13 +169,13 @@ namespace eCAL void CDataReader::InitializeLayers() { // initialize udp multicast layer - if (Config::IsUdpMulticastRecEnabled()) + if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->Initialize(); } // initialize tcp layer - if (Config::IsTcpRecEnabled()) + if (g_ecal_config()->receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->Initialize(); } @@ -184,13 +184,13 @@ namespace eCAL void CDataReader::SubscribeToLayers() { // subscribe topic to udp multicast layer - if (Config::IsUdpMulticastRecEnabled()) + if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id, m_qos); } // subscribe topic to tcp layer - if (Config::IsTcpRecEnabled()) + if (g_ecal_config()->receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id, m_qos); } @@ -199,13 +199,13 @@ namespace eCAL void CDataReader::UnsubscribeFromLayers() { // unsubscribe topic from udp multicast layer - if (Config::IsUdpMulticastRecEnabled()) + if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } // unsubscribe topic from tcp multicast layer - if (Config::IsTcpRecEnabled()) + if (g_ecal_config()->receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -853,7 +853,7 @@ namespace eCAL // ----------------------------------- // drop messages in the wrong order // ----------------------------------- - if (eCAL::Config::Experimental::GetDropOutOfOrderMessages()) + if (Config::GetCurrentConfig()->transport_layer_options.drop_out_of_order_messages) { // do not update the internal clock counter diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index c1502cab32..62a86dc83d 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -90,10 +90,10 @@ namespace eCAL m_created(false) { // initialize layer modes with configuration settings - m_writer.udp_mc_mode.requested = Config::GetPublisherUdpMulticastMode(); - m_writer.shm_mode.requested = Config::GetPublisherShmMode(); - m_writer.tcp_mode.requested = Config::GetPublisherTcpMode(); - m_writer.inproc_mode.requested = Config::GetPublisherInprocMode(); + m_writer.udp_mc_mode.requested = Config::GetCurrentConfig()->publisher_options.use_udp_mc; + m_writer.shm_mode.requested = Config::GetCurrentConfig()->publisher_options.use_shm; + m_writer.tcp_mode.requested = Config::GetCurrentConfig()->publisher_options.use_tcp; + m_writer.inproc_mode.requested = Config::GetCurrentConfig()->publisher_options.use_inproc; } CDataWriter::~CDataWriter() @@ -114,10 +114,10 @@ namespace eCAL m_clock_old = 0; m_snd_time = std::chrono::steady_clock::time_point(); m_freq = 0; - m_bandwidth_max_udp = Config::GetMaxUdpBandwidthBytesPerSecond(); - m_buffering_shm = Config::GetMemfileBufferCount(); - m_zero_copy = Config::IsMemfileZerocopyEnabled(); - m_acknowledge_timeout_ms = Config::GetMemfileAckTimeoutMs(); + m_bandwidth_max_udp = Config::GetCurrentConfig()->transport_layer_options.mc_options.bandwidth_max_udp; + m_buffering_shm = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_buffer_count.get(); + m_zero_copy = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_zero_copy; + m_acknowledge_timeout_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; m_ext_subscribed = false; m_created = false; @@ -128,15 +128,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(Config::GetRegistrationTimeoutMs()); + const std::chrono::milliseconds registration_timeout = g_ecal_config()->registration_options.getTimeout(); m_loc_sub_map.set_expiration(registration_timeout); m_ext_sub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::IsTopicTypeSharingEnabled(); + m_use_ttype = Config::GetCurrentConfig()->registration_options.share_ttype; // allow to share topic description - m_use_tdesc = Config::IsTopicDescriptionSharingEnabled(); + m_use_tdesc = Config::GetCurrentConfig()->registration_options.share_ttype; // register Register(false); @@ -191,10 +191,10 @@ namespace eCAL m_clock_old = 0; m_snd_time = std::chrono::steady_clock::time_point(); m_freq = 0; - m_bandwidth_max_udp = Config::GetMaxUdpBandwidthBytesPerSecond(); - m_buffering_shm = Config::GetMemfileBufferCount(); - m_zero_copy = Config::IsMemfileZerocopyEnabled(); - m_acknowledge_timeout_ms = Config::GetMemfileAckTimeoutMs(); + m_bandwidth_max_udp = g_ecal_config()->transport_layer_options.mc_options.bandwidth_max_udp; + m_buffering_shm = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_buffer_count.get(); + m_zero_copy = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_zero_copy; + m_acknowledge_timeout_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; // reset subscriber maps diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp index cb8b3ab63c..beed6d4da8 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp @@ -96,7 +96,7 @@ namespace eCAL const std::string memfile_event = memfile_name + "_" + process_id; const MemFileDataCallbackT memfile_data_callback = std::bind(&CSHMReaderLayer::OnNewShmFileContent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8); - g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, Config::GetRegistrationTimeoutMs(), memfile_data_callback); + g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config()->registration_options.getTimeout().count(), memfile_data_callback); } } } diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 6851e2d21a..aee7dc3bbf 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -73,10 +73,10 @@ namespace eCAL m_write_idx = 0; // set attributes - m_memory_file_attr.min_size = Config::GetMemfileMinsizeBytes(); - m_memory_file_attr.reserve = Config::GetMemfileOverprovisioningPercentage(); + m_memory_file_attr.min_size = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_minsize.get(); + m_memory_file_attr.reserve = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_reserve.get(); m_memory_file_attr.timeout_open_ms = PUB_MEMFILE_OPEN_TO; - m_memory_file_attr.timeout_ack_ms = Config::GetMemfileAckTimeoutMs(); + m_memory_file_attr.timeout_ack_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; // initialize memory file buffer m_created = SetBufferCount(m_buffer_count);; diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp index ce240dcc3f..b948313834 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp @@ -77,7 +77,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_, Config::GetCurrentConfig()->transport_layer_options.tcp_options.max_reconnections); if (!m_callback_active) { m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1)); @@ -132,7 +132,7 @@ namespace eCAL void CTCPReaderLayer::Initialize() { 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(Config::GetCurrentConfig()->transport_layer_options.tcp_options.num_executor_reader, tcp_pubsub_logger); } void CTCPReaderLayer::AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/, QOS::SReaderQOS /*qos_*/) diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index 13ca9ca582..00acfb9517 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -32,6 +32,7 @@ #include "config/ecal_config_reader_hlp.h" #include +#include "ecal/types/ecal_config_types.h" #include "ecal_writer_tcp.h" #include "ecal_tcp_pubsub_logger.h" @@ -76,7 +77,7 @@ namespace eCAL 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(Config::GetCurrentConfig()->transport_layer_options.tcp_options.num_executor_writer, TcpPubsubLogger); } } diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp index f5133fc10a..1eeb14ffc4 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp @@ -57,7 +57,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); + attr.rcvbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get(); // 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)); diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index c0510f9ff3..639dd5c5c8 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -22,7 +22,7 @@ **/ #include -#include +#include #include "ecal_writer_udp_mc.h" #include "io/udp/ecal_udp_configurations.h" @@ -66,7 +66,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); - attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); + attr.sndbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get(); // create udp/sample sender with activated loop-back attr.loopback = true; diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 22c24950c8..3c88df0495 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -71,14 +71,14 @@ namespace eCAL { if(m_created) return; - m_reg_refresh = Config::GetRegistrationRefreshMs(); + m_reg_refresh = g_ecal_config()->registration_options.getRefresh().count(); m_reg_topics = topics_; m_reg_services = services_; m_reg_process = process_; - m_use_shm_monitoring = Config::Experimental::IsShmMonitoringEnabled(); - m_use_network_monitoring = !Config::Experimental::IsNetworkMonitoringDisabled(); + m_use_shm_monitoring = static_cast(Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring); + m_use_network_monitoring = !Config::GetCurrentConfig()->monitoring_options.network_monitoring_disabled; if (m_use_network_monitoring) { @@ -89,7 +89,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); + attr.sndbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get(); // create udp registration sender m_reg_sample_snd = std::make_shared(attr); @@ -101,14 +101,14 @@ namespace eCAL if (m_use_shm_monitoring) { - std::cout << "Shared memory monitoring is enabled (domain: " << Config::Experimental::GetShmMonitoringDomain() << " - queue size: " << Config::Experimental::GetShmMonitoringQueueSize() << ")" << std::endl; - m_memfile_broadcast.Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); + std::cout << "Shared memory monitoring is enabled (domain: " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain << " - queue size: " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size << ")" << std::endl; + m_memfile_broadcast.Create(Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size); m_memfile_broadcast_writer.Bind(&m_memfile_broadcast); } // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs())); + m_reg_sample_snd_thread->start(g_ecal_config()->registration_options.getRefresh()); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index dd6d07cc23..e996faf0ad 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -50,7 +50,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs()/2)); + m_memfile_broadcast_reader_thread->start(g_ecal_config()->registration_options.getRefresh()); m_created = true; } @@ -117,10 +117,10 @@ namespace eCAL if(m_created) return; // network mode - m_network = Config::IsNetworkEnabled(); + m_network = g_ecal_config()->transport_layer_options.network_enabled; - m_use_shm_monitoring = Config::Experimental::IsShmMonitoringEnabled(); - m_use_network_monitoring = !Config::Experimental::IsNetworkMonitoringDisabled(); + m_use_shm_monitoring = static_cast(Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring); + m_use_network_monitoring = !Config::GetCurrentConfig()->monitoring_options.network_monitoring_disabled; if (m_use_network_monitoring) { @@ -130,7 +130,7 @@ namespace eCAL attr.port = UDP::GetRegistrationPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); + attr.rcvbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get(); // start registration sample receiver m_registration_receiver = std::make_shared(attr, std::bind(&CRegistrationReceiver::HasSample, this, std::placeholders::_1), std::bind(&CRegistrationReceiver::ApplySample, this, std::placeholders::_1)); @@ -138,7 +138,7 @@ namespace eCAL if (m_use_shm_monitoring) { - m_memfile_broadcast.Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); + m_memfile_broadcast.Create(Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size); m_memfile_broadcast.FlushLocalEventQueue(); m_memfile_broadcast_reader.Bind(&m_memfile_broadcast); diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 12571332c2..0e852143b3 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -112,13 +112,13 @@ namespace eCAL }; // start service protocol version 0 - if (Config::IsServiceProtocolV0Enabled()) + if (Config::GetCurrentConfig()->service_options.protocol_v0) { m_tcp_server_v0 = server_manager->create_server(0, 0, service_callback, true, event_callback); } // start service protocol version 1 - if (Config::IsServiceProtocolV1Enabled()) + if (Config::GetCurrentConfig()->service_options.protocol_v1) { m_tcp_server_v1 = server_manager->create_server(1, 0, service_callback, true, event_callback); } @@ -322,10 +322,10 @@ namespace eCAL // might be zero in contruction phase unsigned short const server_tcp_port_v0(m_tcp_server_v0 ? m_tcp_server_v0->get_port() : 0); - if ((Config::IsServiceProtocolV0Enabled()) && (server_tcp_port_v0 == 0)) return; + if ((Config::GetCurrentConfig()->service_options.protocol_v0) && (server_tcp_port_v0 == 0)) return; unsigned short const server_tcp_port_v1(m_tcp_server_v1 ? m_tcp_server_v1->get_port() : 0); - if ((Config::IsServiceProtocolV1Enabled()) && (server_tcp_port_v1 == 0)) return; + if ((Config::GetCurrentConfig()->service_options.protocol_v1) && (server_tcp_port_v1 == 0)) return; // create service registration sample eCAL::pb::Sample sample; diff --git a/ecal/core/src/time/ecal_timegate.cpp b/ecal/core/src/time/ecal_timegate.cpp index cc6c1ebf08..cddc525910 100644 --- a/ecal/core/src/time/ecal_timegate.cpp +++ b/ecal/core/src/time/ecal_timegate.cpp @@ -87,7 +87,7 @@ namespace eCAL case eTimeSyncMode::none: break; case eTimeSyncMode::realtime: - m_time_sync_modname = Config::GetTimesyncModuleName(); + m_time_sync_modname = Config::GetCurrentConfig()->timesync_options.timesync_module; m_successfully_loaded_rt = LoadModule(m_time_sync_modname, m_time_sync_rt); break; case eTimeSyncMode::replay: From 49e8ade82f61b41f7b15e27398d92ec9ba405995 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:00:29 +0100 Subject: [PATCH 002/105] Resolved some merging problems. --- ecal/core/CMakeLists.txt | 1 - ecal/core/include/ecal/ecal.h | 1 + ecal/core/include/ecal/ecal_config.h | 11 +- ecal/core/include/ecal/ecal_core.h | 5 +- .../include/ecal/types/ecal_config_types.h | 372 ++++++++++++++++++ 5 files changed, 382 insertions(+), 8 deletions(-) create mode 100644 ecal/core/include/ecal/types/ecal_config_types.h diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index e9f84090aa..64f9013b16 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -331,7 +331,6 @@ set(ecal_cmn_src src/ecal_global_accessors.h src/ecal_globals.h src/ecal_sample_to_topicinfo.h - include/ecal/types/ecal_config_types.h ) if (WIN32) list (APPEND diff --git a/ecal/core/include/ecal/ecal.h b/ecal/core/include/ecal/ecal.h index db9178819e..ef294c423f 100644 --- a/ecal/core/include/ecal/ecal.h +++ b/ecal/core/include/ecal/ecal.h @@ -43,6 +43,7 @@ #include #include #include +#include /* Legacy namespace to be compatible with eCAL < 4.9 code, will be removed in future eCAL versions*/ namespace eCAL diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 4a25ef6b04..98338619d0 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -22,6 +22,7 @@ #include #include #include +#include "ecal/types/ecal_config_types.h" #include @@ -30,11 +31,11 @@ namespace eCAL { namespace Config { - enum class UdpConfigVersion - { - V1 = 1, // Legacy - V2 = 2 - }; + // enum class UdpConfigVersion + // { + // V1 = 1, // Legacy + // V2 = 2 + // }; ///////////////////////////////////// // common diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index a49a8054c6..36d094879f 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -31,6 +31,7 @@ #include #include +#include "ecal/types/ecal_config_types.h" namespace eCAL { @@ -69,7 +70,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - ECAL_API int Initialize(int argc_ = 0, char **argv_ = nullptr, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); + ECAL_API int Initialize(int argc_ = 0, char** argv_ = nullptr, const char* unit_name_ = nullptr, unsigned int components_ = Init::Default, Config::eCALConfig* = nullptr); /** * @brief Initialize eCAL API. @@ -80,7 +81,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - ECAL_API int Initialize(std::vector args_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); + ECAL_API int Initialize(std::vector args_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default, Config::eCALConfig* user_settings_ = nullptr); /** * @brief Finalize eCAL API. diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h new file mode 100644 index 0000000000..48c76cebcc --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -0,0 +1,372 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 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 ================================= +*/ + +/** + * @file ecal_config_types.h + * @brief eCAL config interface using structs +**/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ecal/ecal_os.h" +#include "ecal/ecal_log_level.h" + +namespace eCAL +{ + namespace Config + { + // Type definitions + class IpAddressV4 + { + public: + IpAddressV4() {}; + IpAddressV4(std::string ip_address_) + { + if (checkIpString(ip_address_)) + { + m_ip_address = ip_address_; + } + else + { + std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; + } + } + + std::string get() { return m_ip_address; } + + private: + bool checkIpString(std::string ip_address_) + { + if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) + { + return true; + } + else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) + { + return true; + } + else + { + return false; + } + + } + std::string m_ip_address; + + }; + + template::max()> + class LimitSize + { + public: + LimitSize(int size_ = 0) + { + if (size_ >= m_size_min && size_ <= m_size_max && size_ % m_size_step == 0) + { + m_size = size_; + } + else + { + std::cout << "LimitSize: faulty size configuration or assignment - using minimum size " << MIN << std::endl; + } + }; + + int get() { return m_size; }; + + private: + int m_size_min = MIN; + long long m_size_max = MAX; + int m_size_step = STEP; + + int m_size = MIN; + }; + + enum class UdpConfigVersion + { + V1 = 1, // Legacy + V2 = 2 + }; + + // ecal config types + struct UdpMulticastOptions + { + UdpConfigVersion config_version; + IpAddressV4 group; + IpAddressV4 mask; + LimitSize<14000, 10> port; + unsigned int ttl; + LimitSize<5242880, 1024> sndbuf; + LimitSize<5242880, 1024> recbuf; + bool join_all_interfaces; + + int bandwidth_max_udp; + bool npcap_enabled; + }; + + struct TCPubsubOptions + { + size_t num_executor_reader; + size_t num_executor_writer; + size_t max_reconnections; + }; + + struct ProcessOptions + { + std::string terminal_emulator; + }; + + struct SHMOptions + { + std::string host_group_name; + LimitSize<4096, 4096> memfile_minsize; + LimitSize<50, 1, 100> memfile_reserve; + int memfile_ack_timeout; + LimitSize<0, 1> memfile_buffer_count; + bool drop_out_of_order_messages; + bool memfile_zero_copy; + }; + + struct TransportLayerOptions + { + bool network_enabled = false; // correct here? + bool drop_out_of_order_messages = false; + UdpMulticastOptions mc_options; + TCPubsubOptions tcp_options; + SHMOptions shm_options; + }; + + enum MonitoringMode + { + none = 0, + udp_monitoring = 1 << 0, + shm_monitoring = 1 << 1 + }; + + typedef char eCAL_MonitoringMode_Filter; + + struct UDPMonitoringOptions + { + + // what is here? + }; + + struct SHMMonitoringOptions + { + std::string shm_monitoring_domain; + size_t shm_monitoring_queue_size; + }; + + struct MonitoringOptions + { + eCAL_MonitoringMode_Filter monitoring_mode; // (int)MonitoringMode::UDP_MONITORING | (int)MonitoringMode::SHM_MONITORING + LimitSize<1000, 1000> monitoring_timeout; // 1000 + (x * 1000) in ms + bool network_monitoring_disabled; // disabled/enabled? + UDPMonitoringOptions udp_options; + SHMMonitoringOptions shm_options; + + std::string filter_excl; // regex for blacklisting, default __.* + std::string filter_incl; // regex for whitelisting, default "" + eCAL_Logging_Filter filter_log_con; // default? options: all, info, warning, error, fatal, debug1, debug2, debug3, debug4 + eCAL_Logging_Filter filter_log_file; // How to use the loglevels? BitOperator? Vector? + eCAL_Logging_Filter filter_log_udp; // enum in ecal_log_level.h + }; + + struct ReceivingOptions // -> sind receiving options + { + bool inproc_recv_enabled; + bool shm_recv_enabled; + bool tcp_recv_enabled; + bool udp_mc_recv_enabled; + }; + + struct PublisherOptions + { + TLayer::eSendMode use_inproc; // 0 = off, 1 = on, 2 = auto, default = 0 + TLayer::eSendMode use_shm; // 0 = off, 1 = on, 2 = auto, default = 2 + TLayer::eSendMode use_tcp; // 0 = off, 1 = on, 2 = auto, default = 0 + TLayer::eSendMode use_udp_mc; // 0 = off, 1 = on, 2 = auto, default = 2 + }; + + struct SysOptions + { + std::string filter_excl; // cloud import blacklists - > regex? + }; + + struct TimesyncOptions + { + std::string timesync_module; // ecaltime-localtime, ecaltime-linuxptp, ecaltime-simtime - what about own implementations? + }; + + struct RegistrationOptions + { + public: + typedef std::chrono::milliseconds MS; + RegistrationOptions() {}; + RegistrationOptions(MS reg_timeout_, MS reg_refresh_) + { + if (reg_refresh_ < reg_timeout_) + { + registration_timeout = reg_timeout_; + registration_refresh = reg_refresh_; + } + else + { + std::cout << "RegistrationOptions: custom registration refresh >= registration timout. Using default values." << std::endl; + } + }; + + MS getTimeout() const { return registration_timeout; } + MS getRefresh() const { return registration_refresh; } + + bool share_ttype = true; + bool share_tdesc = true; + + private: + MS registration_timeout = MS(60000); // + MS registration_refresh = MS(1000); // refresh < registration timeout + }; + + struct ServiceOptions + { + bool protocol_v0; + bool protocol_v1; + }; + + struct eCALConfig + { + TransportLayerOptions transport_layer_options; + RegistrationOptions registration_options; + MonitoringOptions monitoring_options; + ReceivingOptions receiving_options; + PublisherOptions publisher_options; + SysOptions sys_options; + TimesyncOptions timesync_options; + ServiceOptions service_options; + std::string loaded_ecal_ini_file; + }; + + ECAL_API eCALConfig GetDefaultConfig(); + + ECAL_API eCALConfig GetIniConfig(); + + ECAL_API eCALConfig* GetCurrentConfig(); + + } // end namespace Config + + + enum class LayerOptions + { + LAYER_NONE = 0, // needed? + LAYER_UDP_TCP = 1 << 1, + LAYER_UDP_UDP_MC = 1 << 2, + LAYER_SHM = 1 << 3, + LAYER_INMEMORY = 1 << 4 + }; + + constexpr int LAYER_NONE = 0x0000; + constexpr int LAYER_UDP_UDP_MC = 0x0010; + constexpr int LAYER_UDP_TCP = 0x0011; + constexpr int LAYER_SHM = 0x0020; + constexpr int LAYER_INMEMORY = 0x0030; + + enum class NetworkTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP + }; + + enum class LocalTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP, + tlayer_shm = LAYER_SHM + }; + + enum class InprocTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP, + tlayer_shm = LAYER_SHM, + tlayer_inmemory = LAYER_INMEMORY + }; + + struct eCAL_UDP_MC_Publisher_Options + { + long max_bandwidth; // rausschmeißen + // should we go as far as to put the MC address here? + + }; + + struct eCAL_TCP_Publisher_Options + { + // should we go as far as to put the TCP address and port here? - NO only user options + // both pub/sub need to know + }; + + struct eCAL_SHM_Publisher_Options + { + bool enable_zero_copy = false; + + long buffer_count = 1; // 1 .. x + long long acknowledge_timeout_ms = -1; // -1 -> no timeout (or directly std::chrono? + + // should we go as far as to put the memory filename (base) here? - No + // however, part of it will be communicated via the registration layer, invisible to the user + }; + + struct PublisherOptions + { + eCAL_UDP_MC_Publisher_Options udp_mc_options; + eCAL_TCP_Publisher_Options tcp_options; + eCAL_SHM_Publisher_Options shm_options; + + InprocTransportLayer inproc_layer; + LocalTransportLayer local_layer; + NetworkTransportLayer network_layer; + + bool share_topic_information = true; + }; + + struct SubscriberOptions + { + InprocTransportLayer inproc_layer; + LocalTransportLayer local_layer; + NetworkTransportLayer network_layer; + + bool share_topic_information = true; + }; + + // TODO PG: Clarify how to handle these + struct InternalConfig + { + SubscriberOptions subscriber_options; + PublisherOptions publisher_options; + }; +} // end namespace eCAL \ No newline at end of file From 70366d5345566237462e47e97a9ed9b2cae5c211 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:21:56 +0100 Subject: [PATCH 003/105] Fixed copy paste issue values for receivingOptions in ecal_config_initializer.cpp --- ecal/core/src/config/ecal_config_initializer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 26aa13dc1c..32eed30349 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -254,9 +254,9 @@ namespace eCAL // receiving options auto receivingOptions = &config.receiving_options; receivingOptions->inproc_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); - receivingOptions->shm_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); - receivingOptions->tcp_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); - receivingOptions->udp_mc_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); + receivingOptions->shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", true); + receivingOptions->tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", true); + receivingOptions->udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", true); // publisher options auto publisherOptions = &config.publisher_options; From 00b2ec1f0fa55352812324a4df2401ba4fa1228c Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:02:14 +0100 Subject: [PATCH 004/105] Config Adaptions: Set LimitSize default paramaeter to template MIN value. --- ecal/core/include/ecal/types/ecal_config_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 48c76cebcc..d169f98097 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -83,7 +83,7 @@ namespace eCAL class LimitSize { public: - LimitSize(int size_ = 0) + LimitSize(int size_ = MIN) { if (size_ >= m_size_min && size_ <= m_size_max && size_ % m_size_step == 0) { @@ -319,7 +319,7 @@ namespace eCAL struct eCAL_UDP_MC_Publisher_Options { - long max_bandwidth; // rausschmeißen + long max_bandwidth; // rausschmei�en // should we go as far as to put the MC address here? }; From eb31c72bc8ad81978267c0f585b17713aea70963 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:11:34 +0100 Subject: [PATCH 005/105] Refactored options and config access. --- .../ecal/types/ecal_application_options.h | 43 ++ .../include/ecal/types/ecal_config_types.h | 375 ++----------- .../ecal/types/ecal_custom_data_types.h | 105 ++++ .../ecal/types/ecal_internal_options.h | 108 ++++ .../ecal/types/ecal_monitoring_options.h | 70 +++ .../ecal/types/ecal_publisher_options.h | 41 ++ .../ecal/types/ecal_receiving_options.h | 38 ++ .../ecal/types/ecal_registration_options.h | 63 +++ .../include/ecal/types/ecal_service_options.h | 44 ++ .../ecal/types/ecal_transport_layer_options.h | 75 +++ .../src/config/ecal_config_initializer.cpp | 495 +++++++++--------- ecal/core/src/ecal.cpp | 2 +- ecal/core/src/ecal_global_accessors.cpp | 6 +- ecal/core/src/ecal_global_accessors.h | 2 +- ecal/core/src/ecal_globals.cpp | 40 +- ecal/core/src/ecal_globals.h | 10 +- 16 files changed, 883 insertions(+), 634 deletions(-) create mode 100644 ecal/core/include/ecal/types/ecal_application_options.h create mode 100644 ecal/core/include/ecal/types/ecal_custom_data_types.h create mode 100644 ecal/core/include/ecal/types/ecal_internal_options.h create mode 100644 ecal/core/include/ecal/types/ecal_monitoring_options.h create mode 100644 ecal/core/include/ecal/types/ecal_publisher_options.h create mode 100644 ecal/core/include/ecal/types/ecal_receiving_options.h create mode 100644 ecal/core/include/ecal/types/ecal_registration_options.h create mode 100644 ecal/core/include/ecal/types/ecal_service_options.h create mode 100644 ecal/core/include/ecal/types/ecal_transport_layer_options.h diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h new file mode 100644 index 0000000000..7cf621a5ab --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -0,0 +1,43 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_application_options.h + * @brief eCAL options for configuration of applications +**/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Config + { + struct SysOptions + { + std::string filter_excl; + }; + + struct ProcessOptions + { + std::string terminal_emulator; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index d169f98097..6712d2dd8e 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -1,6 +1,6 @@ -/* ========================= eCAL LICENSE ================================= +/* =========================== LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ========================= eCAL LICENSE ================================= -*/ + * =========================== LICENSE ================================= + */ /** * @file ecal_config_types.h @@ -24,349 +24,46 @@ #pragma once +#include "ecal_application_options.h" +#include "ecal_custom_data_types.h" +#include "ecal_monitoring_options.h" +#include "ecal_publisher_options.h" +#include "ecal_receiving_options.h" +#include "ecal_registration_options.h" +#include "ecal_service_options.h" +#include "ecal_internal_options.h" +#include "ecal_transport_layer_options.h" + +#include "ecal/ecal_os.h" +#include "ecal/ecal_log_level.h" + #include #include -#include -#include #include #include #include -#include -#include "ecal/ecal_os.h" -#include "ecal/ecal_log_level.h" namespace eCAL { - namespace Config + namespace Config + { + struct eCALConfig { - // Type definitions - class IpAddressV4 - { - public: - IpAddressV4() {}; - IpAddressV4(std::string ip_address_) - { - if (checkIpString(ip_address_)) - { - m_ip_address = ip_address_; - } - else - { - std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; - } - } - - std::string get() { return m_ip_address; } - - private: - bool checkIpString(std::string ip_address_) - { - if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) - { - return true; - } - else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) - { - return true; - } - else - { - return false; - } - - } - std::string m_ip_address; - - }; - - template::max()> - class LimitSize - { - public: - LimitSize(int size_ = MIN) - { - if (size_ >= m_size_min && size_ <= m_size_max && size_ % m_size_step == 0) - { - m_size = size_; - } - else - { - std::cout << "LimitSize: faulty size configuration or assignment - using minimum size " << MIN << std::endl; - } - }; - - int get() { return m_size; }; - - private: - int m_size_min = MIN; - long long m_size_max = MAX; - int m_size_step = STEP; - - int m_size = MIN; - }; - - enum class UdpConfigVersion - { - V1 = 1, // Legacy - V2 = 2 - }; - - // ecal config types - struct UdpMulticastOptions - { - UdpConfigVersion config_version; - IpAddressV4 group; - IpAddressV4 mask; - LimitSize<14000, 10> port; - unsigned int ttl; - LimitSize<5242880, 1024> sndbuf; - LimitSize<5242880, 1024> recbuf; - bool join_all_interfaces; - - int bandwidth_max_udp; - bool npcap_enabled; - }; - - struct TCPubsubOptions - { - size_t num_executor_reader; - size_t num_executor_writer; - size_t max_reconnections; - }; - - struct ProcessOptions - { - std::string terminal_emulator; - }; - - struct SHMOptions - { - std::string host_group_name; - LimitSize<4096, 4096> memfile_minsize; - LimitSize<50, 1, 100> memfile_reserve; - int memfile_ack_timeout; - LimitSize<0, 1> memfile_buffer_count; - bool drop_out_of_order_messages; - bool memfile_zero_copy; - }; - - struct TransportLayerOptions - { - bool network_enabled = false; // correct here? - bool drop_out_of_order_messages = false; - UdpMulticastOptions mc_options; - TCPubsubOptions tcp_options; - SHMOptions shm_options; - }; - - enum MonitoringMode - { - none = 0, - udp_monitoring = 1 << 0, - shm_monitoring = 1 << 1 - }; - - typedef char eCAL_MonitoringMode_Filter; - - struct UDPMonitoringOptions - { - - // what is here? - }; - - struct SHMMonitoringOptions - { - std::string shm_monitoring_domain; - size_t shm_monitoring_queue_size; - }; - - struct MonitoringOptions - { - eCAL_MonitoringMode_Filter monitoring_mode; // (int)MonitoringMode::UDP_MONITORING | (int)MonitoringMode::SHM_MONITORING - LimitSize<1000, 1000> monitoring_timeout; // 1000 + (x * 1000) in ms - bool network_monitoring_disabled; // disabled/enabled? - UDPMonitoringOptions udp_options; - SHMMonitoringOptions shm_options; - - std::string filter_excl; // regex for blacklisting, default __.* - std::string filter_incl; // regex for whitelisting, default "" - eCAL_Logging_Filter filter_log_con; // default? options: all, info, warning, error, fatal, debug1, debug2, debug3, debug4 - eCAL_Logging_Filter filter_log_file; // How to use the loglevels? BitOperator? Vector? - eCAL_Logging_Filter filter_log_udp; // enum in ecal_log_level.h - }; - - struct ReceivingOptions // -> sind receiving options - { - bool inproc_recv_enabled; - bool shm_recv_enabled; - bool tcp_recv_enabled; - bool udp_mc_recv_enabled; - }; - - struct PublisherOptions - { - TLayer::eSendMode use_inproc; // 0 = off, 1 = on, 2 = auto, default = 0 - TLayer::eSendMode use_shm; // 0 = off, 1 = on, 2 = auto, default = 2 - TLayer::eSendMode use_tcp; // 0 = off, 1 = on, 2 = auto, default = 0 - TLayer::eSendMode use_udp_mc; // 0 = off, 1 = on, 2 = auto, default = 2 - }; - - struct SysOptions - { - std::string filter_excl; // cloud import blacklists - > regex? - }; - - struct TimesyncOptions - { - std::string timesync_module; // ecaltime-localtime, ecaltime-linuxptp, ecaltime-simtime - what about own implementations? - }; - - struct RegistrationOptions - { - public: - typedef std::chrono::milliseconds MS; - RegistrationOptions() {}; - RegistrationOptions(MS reg_timeout_, MS reg_refresh_) - { - if (reg_refresh_ < reg_timeout_) - { - registration_timeout = reg_timeout_; - registration_refresh = reg_refresh_; - } - else - { - std::cout << "RegistrationOptions: custom registration refresh >= registration timout. Using default values." << std::endl; - } - }; - - MS getTimeout() const { return registration_timeout; } - MS getRefresh() const { return registration_refresh; } - - bool share_ttype = true; - bool share_tdesc = true; - - private: - MS registration_timeout = MS(60000); // - MS registration_refresh = MS(1000); // refresh < registration timeout - }; - - struct ServiceOptions - { - bool protocol_v0; - bool protocol_v1; - }; - - struct eCALConfig - { - TransportLayerOptions transport_layer_options; - RegistrationOptions registration_options; - MonitoringOptions monitoring_options; - ReceivingOptions receiving_options; - PublisherOptions publisher_options; - SysOptions sys_options; - TimesyncOptions timesync_options; - ServiceOptions service_options; - std::string loaded_ecal_ini_file; - }; - - ECAL_API eCALConfig GetDefaultConfig(); - - ECAL_API eCALConfig GetIniConfig(); - - ECAL_API eCALConfig* GetCurrentConfig(); - - } // end namespace Config - - - enum class LayerOptions - { - LAYER_NONE = 0, // needed? - LAYER_UDP_TCP = 1 << 1, - LAYER_UDP_UDP_MC = 1 << 2, - LAYER_SHM = 1 << 3, - LAYER_INMEMORY = 1 << 4 - }; - - constexpr int LAYER_NONE = 0x0000; - constexpr int LAYER_UDP_UDP_MC = 0x0010; - constexpr int LAYER_UDP_TCP = 0x0011; - constexpr int LAYER_SHM = 0x0020; - constexpr int LAYER_INMEMORY = 0x0030; - - enum class NetworkTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP - }; - - enum class LocalTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP, - tlayer_shm = LAYER_SHM - }; - - enum class InprocTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP, - tlayer_shm = LAYER_SHM, - tlayer_inmemory = LAYER_INMEMORY - }; - - struct eCAL_UDP_MC_Publisher_Options - { - long max_bandwidth; // rausschmei�en - // should we go as far as to put the MC address here? - + public: + TransportLayerOptions transport_layer_options; + RegistrationOptions registration_options; + MonitoringOptions monitoring_options; + ReceivingOptions receiving_options; + PublisherOptions publisher_options; + SysOptions sys_options; + TimesyncOptions timesync_options; + ServiceOptions service_options; + std::string loaded_ecal_ini_file; + + eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; + eCALConfig(); }; - struct eCAL_TCP_Publisher_Options - { - // should we go as far as to put the TCP address and port here? - NO only user options - // both pub/sub need to know - }; - - struct eCAL_SHM_Publisher_Options - { - bool enable_zero_copy = false; - - long buffer_count = 1; // 1 .. x - long long acknowledge_timeout_ms = -1; // -1 -> no timeout (or directly std::chrono? - - // should we go as far as to put the memory filename (base) here? - No - // however, part of it will be communicated via the registration layer, invisible to the user - }; - - struct PublisherOptions - { - eCAL_UDP_MC_Publisher_Options udp_mc_options; - eCAL_TCP_Publisher_Options tcp_options; - eCAL_SHM_Publisher_Options shm_options; - - InprocTransportLayer inproc_layer; - LocalTransportLayer local_layer; - NetworkTransportLayer network_layer; - - bool share_topic_information = true; - }; - - struct SubscriberOptions - { - InprocTransportLayer inproc_layer; - LocalTransportLayer local_layer; - NetworkTransportLayer network_layer; - - bool share_topic_information = true; - }; - - // TODO PG: Clarify how to handle these - struct InternalConfig - { - SubscriberOptions subscriber_options; - PublisherOptions publisher_options; - }; -} // end namespace eCAL \ No newline at end of file + ECAL_API eCALConfig* GetCurrentConfig(); + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h new file mode 100644 index 0000000000..e39d98fe6e --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -0,0 +1,105 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_custom_types.h + * @brief eCAL custom types for configuration declarations +**/ + +#pragma once + +#include +#include +#include + +namespace eCAL +{ + namespace Config + { + class IpAddressV4 + { + public: + IpAddressV4() = default; + IpAddressV4(const std::string ip_address_) + { + if (checkIpString(ip_address_)) + { + m_ip_address = ip_address_; + } + else + { + std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; + } + } + + const std::string get() { return m_ip_address; } + + private: + static bool checkIpString(std::string ip_address_) + { + if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) + { + return true; + } + else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) + { + return true; + } + else + { + return false; + } + } + + std::string m_ip_address; + }; + + template::max()> + class LimitSize + { + public: + LimitSize(int size_ = MIN) + { + if (size_ >= m_size_min && size_ <= m_size_max && size_ % m_size_step == 0) + { + m_size = size_; + } + else + { + std::cout << "LimitSize: faulty size configuration or assignment - using minimum size " << m_size_min << std::endl; + } + }; + + int get() { return m_size; }; + + private: + int m_size_min = MIN; + long long m_size_max = MAX; + int m_size_step = STEP; + + int m_size = MIN; + }; + + enum class UdpConfigVersion + { + V1 = 1, + V2 = 2 + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_internal_options.h b/ecal/core/include/ecal/types/ecal_internal_options.h new file mode 100644 index 0000000000..8c5c21910c --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_internal_options.h @@ -0,0 +1,108 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_internal_options.h + * @brief eCAL options for internal configuration +**/ + +namespace eCAL +{ + constexpr int LAYER_NONE = 0x0000; + constexpr int LAYER_UDP_UDP_MC = 0x0010; + constexpr int LAYER_UDP_TCP = 0x0011; + constexpr int LAYER_SHM = 0x0020; + constexpr int LAYER_INMEMORY = 0x0030; + + enum class NetworkTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP + }; + + enum class LocalTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP, + tlayer_shm = LAYER_SHM + }; + + enum class InprocTransportLayer + { + tlayer_none = LAYER_NONE, + tlayer_udp_mc = LAYER_UDP_UDP_MC, + tlayer_tcp = LAYER_UDP_TCP, + tlayer_shm = LAYER_SHM, + tlayer_inmemory = LAYER_INMEMORY + }; + + struct eCAL_UDP_MC_Publisher_Options + { + long max_bandwidth; // rausschmeissen + // should we go as far as to put the MC address here? + }; + + struct eCAL_TCP_Publisher_Options + { + // should we go as far as to put the TCP address and port here? - NO only user options + // both pub/sub need to know + }; + + struct eCAL_SHM_Publisher_Options + { + bool enable_zero_copy = false; + + long buffer_count = 1; // 1 .. x + long long acknowledge_timeout_ms = -1; // -1 -> no timeout (or directly std::chrono? + + // should we go as far as to put the memory filename (base) here? - No + // however, part of it will be communicated via the registration layer, invisible to the user + }; + + struct PublisherOptions + { + eCAL_UDP_MC_Publisher_Options udp_mc_options; + eCAL_TCP_Publisher_Options tcp_options; + eCAL_SHM_Publisher_Options shm_options; + + InprocTransportLayer inproc_layer; + LocalTransportLayer local_layer; + NetworkTransportLayer network_layer; + + bool share_topic_information = true; + }; + + struct SubscriberOptions + { + InprocTransportLayer inproc_layer; + LocalTransportLayer local_layer; + NetworkTransportLayer network_layer; + + bool share_topic_information = true; + }; + + // TODO PG: Clarify how to handle these + struct InternalConfig + { + SubscriberOptions subscriber_options; + PublisherOptions publisher_options; + }; +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h new file mode 100644 index 0000000000..30a66f61b7 --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -0,0 +1,70 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_monitoring_options.h + * @brief eCAL options for monitoring configuration +**/ + +#pragma once + +#include "ecal_custom_data_types.h" + +#include "../ecal_log_level.h" + +namespace eCAL +{ + namespace Config + { + enum MonitoringMode + { + none = 0, + udp_monitoring = 1 << 0, + shm_monitoring = 1 << 1 + }; + + using eCAL_MonitoringMode_Filter = char; + + struct UDPMonitoringOptions + { + // Here? + }; + + struct SHMMonitoringOptions + { + std::string shm_monitoring_domain; + size_t shm_monitoring_queue_size; + }; + + struct MonitoringOptions + { + eCAL_MonitoringMode_Filter monitoring_mode; + LimitSize<1000, 1000> monitoring_timeout; + bool network_monitoring_disabled; + UDPMonitoringOptions udp_options; + SHMMonitoringOptions shm_options; + + std::string filter_excl; + std::string filter_incl; + eCAL_Logging_Filter filter_log_con; + eCAL_Logging_Filter filter_log_file; + eCAL_Logging_Filter filter_log_udp; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_publisher_options.h b/ecal/core/include/ecal/types/ecal_publisher_options.h new file mode 100644 index 0000000000..774dc2f285 --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_publisher_options.h @@ -0,0 +1,41 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_publisher_options.h + * @brief eCAL options for configuration of the publisher +**/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Config + { + struct PublisherOptions + { + TLayer::eSendMode use_inproc; + TLayer::eSendMode use_shm; + TLayer::eSendMode use_tcp; + TLayer::eSendMode use_udp_mc; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_receiving_options.h b/ecal/core/include/ecal/types/ecal_receiving_options.h new file mode 100644 index 0000000000..122744fa02 --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_receiving_options.h @@ -0,0 +1,38 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_receiving_options.h + * @brief eCAL options for receiving configuration +**/ + +#pragma once + +namespace eCAL +{ + namespace Config + { + struct ReceivingOptions + { + bool shm_recv_enabled; + bool tcp_recv_enabled; + bool udp_mc_recv_enabled; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h new file mode 100644 index 0000000000..475f64fc8a --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -0,0 +1,63 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_registration_options.h + * @brief eCAL options for configuration of the registration layer +**/ + +#pragma once + +#include +#include + +namespace eCAL +{ + namespace Config + { + struct RegistrationOptions + { + public: + using ms_t = std::chrono::milliseconds; + RegistrationOptions() = default; + RegistrationOptions(ms_t reg_timeout_, ms_t reg_refresh_) + { + if (reg_refresh_ < reg_timeout_) + { + registration_timeout = reg_timeout_; + registration_refresh = reg_refresh_; + } + else + { + std::cout << "RegistrationOptions: custom registration refresh >= registration timout. Using default values." << "\n"; + } + }; + + ms_t getTimeout() const { return registration_timeout; } + ms_t getRefresh() const { return registration_refresh; } + + bool share_ttype = true; + bool share_tdesc = true; + + private: + ms_t registration_timeout = ms_t(60000); + ms_t registration_refresh = ms_t(1000); + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_service_options.h b/ecal/core/include/ecal/types/ecal_service_options.h new file mode 100644 index 0000000000..4eb2dcb15f --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_service_options.h @@ -0,0 +1,44 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_service_options.h + * @brief eCAL options for configuration of services +**/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Config + { + struct ServiceOptions + { + bool protocol_v0; + bool protocol_v1; + }; + + struct TimesyncOptions + { + std::string timesync_module; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h new file mode 100644 index 0000000000..09e3e85830 --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -0,0 +1,75 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_transport_layer_options.h + * @brief eCAL options for configuration of the transport layer +**/ + +#pragma once + +#include "ecal_custom_data_types.h" + +namespace eCAL +{ + namespace Config + { + struct TCPubsubOptions + { + size_t num_executor_reader; + size_t num_executor_writer; + size_t max_reconnections; + }; + + struct SHMOptions + { + std::string host_group_name; + LimitSize<4096, 4096> memfile_minsize; + LimitSize<50, 1, 100> memfile_reserve; + int memfile_ack_timeout; + LimitSize<0, 1> memfile_buffer_count; + bool drop_out_of_order_messages; + bool memfile_zero_copy; + }; + + struct UdpMulticastOptions + { + UdpConfigVersion config_version; + IpAddressV4 group; + IpAddressV4 mask; + LimitSize<14000, 10> port; + unsigned int ttl; + LimitSize<5242880, 1024> sndbuf; + LimitSize<5242880, 1024> recbuf; + bool join_all_interfaces; + + int bandwidth_max_udp; + bool npcap_enabled; + }; + + struct TransportLayerOptions + { + bool network_enabled = false; + bool drop_out_of_order_messages = false; + UdpMulticastOptions mc_options; + TCPubsubOptions tcp_options; + SHMOptions shm_options; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 32eed30349..6d3a5b9d44 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -27,265 +27,264 @@ #include "ecal_global_accessors.h" #include "config/ecal_config_reader.h" -#define COMMON "common" -#define MONITORING "monitoring" -#define NETWORK "network" -#define EXPERIMENTAL "experimental" -#define PUBLISHER "publisher" -#define SYS "sys" -#define TIME "time" -#define SERVICE "service" +constexpr char COMMON[] = "common"; +constexpr char MONITORING[] = "monitoring"; +constexpr char NETWORK[] = "network"; +constexpr char EXPERIMENTAL[] = "experimental"; +constexpr char PUBLISHER[] = "publisher"; +constexpr char SYS[] = "sys"; +constexpr char TIME[] = "time"; +constexpr char SERVICE[] = "service"; namespace { - void tokenize(const std::string& str, std::vector& tokens, - const std::string& delimiters = " ", bool trimEmpty = false) - { - std::string::size_type pos, lastPos = 0; + void tokenize(const std::string& str, std::vector& tokens, + const std::string& delimiters = " ", bool trimEmpty = false) + { + std::string::size_type pos, lastPos = 0; - for (;;) + for (;;) + { + pos = str.find_first_of(delimiters, lastPos); + if (pos == std::string::npos) + { + pos = str.length(); + if (pos != lastPos || !trimEmpty) { - pos = str.find_first_of(delimiters, lastPos); - if (pos == std::string::npos) - { - pos = str.length(); - if (pos != lastPos || !trimEmpty) - { - tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); - } - break; - } - else - { - if (pos != lastPos || !trimEmpty) - { - tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); - } - } - lastPos = pos + 1; + tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); } - } - - eCAL_Logging_Filter ParseLogLevel(const std::string& filter_) - { - // tokenize it - std::vector token_filter_; - tokenize(filter_, token_filter_, " ,;"); - // create excluding filter list - char filter_mask = log_level_none; - for (auto& it : token_filter_) + break; + } + else + { + if (pos != lastPos || !trimEmpty) { - if (it == "all") filter_mask |= log_level_all; - if (it == "info") filter_mask |= log_level_info; - if (it == "warning") filter_mask |= log_level_warning; - if (it == "error") filter_mask |= log_level_error; - if (it == "fatal") filter_mask |= log_level_fatal; - if (it == "debug1") filter_mask |= log_level_debug1; - if (it == "debug2") filter_mask |= log_level_debug2; - if (it == "debug3") filter_mask |= log_level_debug3; - if (it == "debug4") filter_mask |= log_level_debug4; + tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); } - return(filter_mask); - }; + } + lastPos = pos + 1; + } + } + + eCAL_Logging_Filter ParseLogLevel(const std::string& filter_) + { + // tokenize it + std::vector token_filter_; + tokenize(filter_, token_filter_, " ,;"); + // create excluding filter list + char filter_mask = log_level_none; + for (auto& it : token_filter_) + { + if (it == "all") filter_mask |= log_level_all; + if (it == "info") filter_mask |= log_level_info; + if (it == "warning") filter_mask |= log_level_warning; + if (it == "error") filter_mask |= log_level_error; + if (it == "fatal") filter_mask |= log_level_fatal; + if (it == "debug1") filter_mask |= log_level_debug1; + if (it == "debug2") filter_mask |= log_level_debug2; + if (it == "debug3") filter_mask |= log_level_debug3; + if (it == "debug4") filter_mask |= log_level_debug4; + } + return(filter_mask); + }; } namespace eCAL { - namespace Config + namespace Config + { + eCALConfig GetDefaultConfig(eCALConfig& config) { - eCALConfig GetDefaultConfig() - { - eCALConfig config; - - // transport layer options - auto transportLayerOptions = &config.transport_layer_options; - transportLayerOptions->network_enabled = false; - transportLayerOptions->drop_out_of_order_messages = false; - - auto multicastOptions = &transportLayerOptions->mc_options; - multicastOptions->config_version = UdpConfigVersion::V1; - multicastOptions->group = std::string("239.0.0.1"); - multicastOptions->mask = std::string("0.0.0.15"); - multicastOptions->port = 14000; - multicastOptions->ttl = 2; - multicastOptions->recbuf = (1024 * 1024 * 5); - multicastOptions->sndbuf = (1024 * 1024 * 5); - multicastOptions->join_all_interfaces = false; - multicastOptions->bandwidth_max_udp = -1; - multicastOptions->npcap_enabled = false; - - auto tcpPubSubOptions = &transportLayerOptions->tcp_options; - tcpPubSubOptions->num_executor_reader = 4; - tcpPubSubOptions->num_executor_writer = 4; - tcpPubSubOptions->max_reconnections = 5; - - auto shmOptions = &transportLayerOptions->shm_options; - shmOptions->host_group_name = ""; - shmOptions->memfile_minsize = 4096; - shmOptions->memfile_reserve = 50; - shmOptions->memfile_ack_timeout = 0; - shmOptions->memfile_buffer_count = 1; - shmOptions->drop_out_of_order_messages = false; - shmOptions->memfile_zero_copy = false; - - // registration options - auto registrationOptions = &config.registration_options; - registrationOptions = new RegistrationOptions(RegistrationOptions::MS(60000), RegistrationOptions::MS(1000)); - registrationOptions->share_tdesc = true; - registrationOptions->share_ttype = true; - - // monitoring options - auto monitoringOptions = &config.monitoring_options; - monitoringOptions->monitoring_mode = MonitoringMode::none; - monitoringOptions->monitoring_timeout = 5000; - monitoringOptions->network_monitoring_disabled = false; - monitoringOptions->filter_excl = "__.*"; - monitoringOptions->filter_incl = ""; - monitoringOptions->filter_log_con = log_level_error | log_level_fatal | log_level_warning; - monitoringOptions->filter_log_file = log_level_none; - monitoringOptions->filter_log_udp = log_level_info | log_level_error | log_level_fatal | log_level_warning; - - auto udpMonitoringOptions = &monitoringOptions->udp_options; - // TODO: Nothing here yet - - auto shmMonitoringOptions = &monitoringOptions->shm_options; - shmMonitoringOptions->shm_monitoring_domain = "ecal_monitoring"; - shmMonitoringOptions->shm_monitoring_queue_size = 1024; - - // receiving options - auto receivingOptions = &config.receiving_options; - receivingOptions->inproc_recv_enabled = true; - receivingOptions->shm_recv_enabled = true; - receivingOptions->tcp_recv_enabled = true; - receivingOptions->udp_mc_recv_enabled = true; - - // publisher options - auto publisherOptions = &config.publisher_options; - publisherOptions->use_inproc = TLayer::smode_off; - publisherOptions->use_shm = TLayer::smode_auto; - publisherOptions->use_tcp = TLayer::smode_off; - publisherOptions->use_udp_mc = TLayer::smode_auto; - - // sys options - auto sysOptions = &config.sys_options; - sysOptions->filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; - - // timesync options - auto timesyncOptions = &config.timesync_options; - timesyncOptions->timesync_module = "ecaltime-localtime"; - - // service options - auto serviceOptions = &config.service_options; - serviceOptions->protocol_v0 = true; - serviceOptions->protocol_v1 = true; - - return config; - }; - - eCALConfig GetIniConfig() - { - CConfig iniConfig; - iniConfig.AddFile(g_default_ini_file); - - eCALConfig config; - // transport layer options - auto transportLayerOptions = &config.transport_layer_options; - transportLayerOptions->network_enabled = iniConfig.get(NETWORK, "network_enabled", false); - transportLayerOptions->drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); - - auto multicastOptions = &transportLayerOptions->mc_options; - - const std::string udp_config_version_string = iniConfig.get(NETWORK, "multicast_config_version", "v1"); - if (udp_config_version_string == "v1") - multicastOptions->config_version = UdpConfigVersion::V1; - if (udp_config_version_string == "v2") - multicastOptions->config_version = UdpConfigVersion::V2; - - multicastOptions->group = iniConfig.get(NETWORK, "multicast_group", "239.0.0.0"); - multicastOptions->mask = iniConfig.get(NETWORK, "multicast_mask", "0.0.0.15"); - multicastOptions->port = iniConfig.get(NETWORK, "multicast_port", 14000); - multicastOptions->ttl = iniConfig.get(NETWORK, "multicast_ttl", 3); - multicastOptions->recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", (1024 * 1024 * 5)); - multicastOptions->sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", (1024 * 1024 * 5)); - multicastOptions->join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", false); - multicastOptions->bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", (- 1)); - multicastOptions->npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", false); - - auto tcpPubSubOptions = &transportLayerOptions->tcp_options; - tcpPubSubOptions->num_executor_reader = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_reader", 4); - tcpPubSubOptions->num_executor_writer = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_writer", 4); - tcpPubSubOptions->max_reconnections = iniConfig.get(NETWORK, "tcp_pubsup_max_reconnections", 5); - - auto shmOptions = &transportLayerOptions->shm_options; - shmOptions->host_group_name = iniConfig.get(NETWORK, "host_group_name", ""); - shmOptions->memfile_minsize = iniConfig.get(PUBLISHER, "memfile_minsize", (4 * 1024)); - shmOptions->memfile_reserve = iniConfig.get(PUBLISHER, "memfile_reserve", 50); - shmOptions->memfile_ack_timeout = iniConfig.get(PUBLISHER, "memfile_ack_timeout", 0); - shmOptions->memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", 1); - shmOptions->drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); - shmOptions->memfile_zero_copy = (iniConfig.get(PUBLISHER, "memfile_zero_copy", 0) == 1) ? true : false; - - // registration options - auto registrationOptions = &config.registration_options; - auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", 5000); - auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", 1000); - registrationOptions = new RegistrationOptions(RegistrationOptions::MS(registrationTimeout), RegistrationOptions::MS(registrationRefresh)); - registrationOptions->share_tdesc = (iniConfig.get(PUBLISHER, "share_tdesc", 1) == 1) ? true : false; - registrationOptions->share_ttype = (iniConfig.get(PUBLISHER, "share_ttype", 1) == 1) ? true : false; - - // monitoring options - auto monitoringOptions = &config.monitoring_options; - auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; - monitoringOptions->monitoring_mode = monitoringMode; // What about UDP monitoring? - monitoringOptions->monitoring_timeout = iniConfig.get(MONITORING, "timeout", 5000);; - monitoringOptions->network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", false); - monitoringOptions->filter_excl = iniConfig.get(MONITORING, "filter_excl", "__.*"); - monitoringOptions->filter_incl = iniConfig.get(MONITORING, "filter_incl", ""); - monitoringOptions->filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); - monitoringOptions->filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); - monitoringOptions->filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); - - auto udpMonitoringOptions = &monitoringOptions->udp_options; - // TODO: Nothing here yet - - auto shmMonitoringOptions = &monitoringOptions->shm_options; - shmMonitoringOptions->shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", "ecal_monitoring"); - shmMonitoringOptions->shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", 1024); - - // receiving options - auto receivingOptions = &config.receiving_options; - receivingOptions->inproc_recv_enabled = iniConfig.get(NETWORK, "inproc_rec_enabled", true); - receivingOptions->shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", true); - receivingOptions->tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", true); - receivingOptions->udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", true); - - // publisher options - auto publisherOptions = &config.publisher_options; - publisherOptions->use_inproc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_inproc", 0)); - publisherOptions->use_shm = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_shm", 0)); - publisherOptions->use_tcp = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_tcp", 0)); - publisherOptions->use_udp_mc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_udp_mc", 0)); - - // sys options - auto sysOptions = &config.sys_options; - sysOptions->filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file - - // timesync options - auto timesyncOptions = &config.timesync_options; - timesyncOptions->timesync_module = iniConfig.get(TIME, "timesync_module_rt", ""); - - // service options - auto serviceOptions = &config.service_options; - serviceOptions->protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; - serviceOptions->protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; - - return config; - - }; - - // after initialization - eCALConfig* GetCurrentConfig() - { - return g_ecal_config(); - }; + // transport layer options + auto& transportLayerOptions = config.transport_layer_options; + transportLayerOptions.network_enabled = false; + transportLayerOptions.drop_out_of_order_messages = false; + + auto& multicastOptions = transportLayerOptions.mc_options; + multicastOptions.config_version = UdpConfigVersion::V1; + multicastOptions.group = std::string("239.0.0.1"); + multicastOptions.mask = std::string("0.0.0.15"); + multicastOptions.port = 14000; + multicastOptions.ttl = 2; + multicastOptions.recbuf = (1024 * 1024 * 5); + multicastOptions.sndbuf = (1024 * 1024 * 5); + multicastOptions.join_all_interfaces = false; + multicastOptions.bandwidth_max_udp = -1; + multicastOptions.npcap_enabled = false; + + auto& tcpPubSubOptions = transportLayerOptions.tcp_options; + tcpPubSubOptions.num_executor_reader = 4; + tcpPubSubOptions.num_executor_writer = 4; + tcpPubSubOptions.max_reconnections = 5; + + auto& shmOptions = transportLayerOptions.shm_options; + shmOptions.host_group_name = ""; + shmOptions.memfile_minsize = 4096; + shmOptions.memfile_reserve = 50; + shmOptions.memfile_ack_timeout = 0; + shmOptions.memfile_buffer_count = 1; + shmOptions.drop_out_of_order_messages = false; + shmOptions.memfile_zero_copy = false; + + // registration options + auto& registrationOptions = config.registration_options; + registrationOptions = RegistrationOptions(RegistrationOptions::ms_t(60000), RegistrationOptions::ms_t(1000)); + registrationOptions.share_tdesc = true; + registrationOptions.share_ttype = true; + + // monitoring options + auto& monitoringOptions = config.monitoring_options; + monitoringOptions.monitoring_mode = MonitoringMode::none; + monitoringOptions.monitoring_timeout = 5000; + monitoringOptions.network_monitoring_disabled = false; + monitoringOptions.filter_excl = "__.*"; + monitoringOptions.filter_incl = ""; + monitoringOptions.filter_log_con = log_level_error | log_level_fatal | log_level_warning; + monitoringOptions.filter_log_file = log_level_none; + monitoringOptions.filter_log_udp = log_level_info | log_level_error | log_level_fatal | log_level_warning; + + auto& udpMonitoringOptions = monitoringOptions.udp_options; + // TODO: Nothing here yet + + auto& shmMonitoringOptions = monitoringOptions.shm_options; + shmMonitoringOptions.shm_monitoring_domain = "ecal_monitoring"; + shmMonitoringOptions.shm_monitoring_queue_size = 1024; + + // receiving options + auto& receivingOptions = config.receiving_options; + receivingOptions.shm_recv_enabled = true; + receivingOptions.tcp_recv_enabled = true; + receivingOptions.udp_mc_recv_enabled = true; + + // publisher options + auto& publisherOptions = config.publisher_options; + publisherOptions.use_inproc = TLayer::smode_off; + publisherOptions.use_shm = TLayer::smode_auto; + publisherOptions.use_tcp = TLayer::smode_off; + publisherOptions.use_udp_mc = TLayer::smode_auto; + + // sys options + auto& sysOptions = config.sys_options; + sysOptions.filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; + + // timesync options + auto& timesyncOptions = config.timesync_options; + timesyncOptions.timesync_module = "ecaltime-localtime"; + + // service options + auto& serviceOptions = config.service_options; + serviceOptions.protocol_v0 = true; + serviceOptions.protocol_v1 = true; + + return config; + }; + + eCALConfig GetIniConfig(eCALConfig& config) + { + CConfig iniConfig; + iniConfig.AddFile(g_default_ini_file); + + // transport layer options + auto& transportLayerOptions = config.transport_layer_options; + transportLayerOptions.network_enabled = iniConfig.get(NETWORK, "network_enabled", false); + transportLayerOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); + + auto& multicastOptions = transportLayerOptions.mc_options; + + const std::string udp_config_version_string = iniConfig.get(NETWORK, "multicast_config_version", "v1"); + if (udp_config_version_string == "v1") + multicastOptions.config_version = UdpConfigVersion::V1; + if (udp_config_version_string == "v2") + multicastOptions.config_version = UdpConfigVersion::V2; + + multicastOptions.group = iniConfig.get(NETWORK, "multicast_group", "239.0.0.0"); + multicastOptions.mask = iniConfig.get(NETWORK, "multicast_mask", "0.0.0.15"); + multicastOptions.port = iniConfig.get(NETWORK, "multicast_port", 14000); + multicastOptions.ttl = iniConfig.get(NETWORK, "multicast_ttl", 3); + multicastOptions.recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", (1024 * 1024 * 5)); + multicastOptions.sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", (1024 * 1024 * 5)); + multicastOptions.join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", false); + multicastOptions.bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", (- 1)); + multicastOptions.npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", false); + + auto& tcpPubSubOptions = transportLayerOptions.tcp_options; + tcpPubSubOptions.num_executor_reader = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_reader", 4); + tcpPubSubOptions.num_executor_writer = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_writer", 4); + tcpPubSubOptions.max_reconnections = iniConfig.get(NETWORK, "tcp_pubsup_max_reconnections", 5); + + auto& shmOptions = transportLayerOptions.shm_options; + shmOptions.host_group_name = iniConfig.get(NETWORK, "host_group_name", ""); + shmOptions.memfile_minsize = iniConfig.get(PUBLISHER, "memfile_minsize", (4 * 1024)); + shmOptions.memfile_reserve = iniConfig.get(PUBLISHER, "memfile_reserve", 50); + shmOptions.memfile_ack_timeout = iniConfig.get(PUBLISHER, "memfile_ack_timeout", 0); + shmOptions.memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", 1); + shmOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); + shmOptions.memfile_zero_copy = (iniConfig.get(PUBLISHER, "memfile_zero_copy", 0) == 1) ? true : false; + + // registration options + auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", 5000); + auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", 1000); + config.registration_options = RegistrationOptions(RegistrationOptions::ms_t(registrationTimeout), RegistrationOptions::ms_t(registrationRefresh)); + auto& registrationOptions = config.registration_options; + registrationOptions.share_tdesc = (iniConfig.get(PUBLISHER, "share_tdesc", 1) == 1) ? true : false; + registrationOptions.share_ttype = (iniConfig.get(PUBLISHER, "share_ttype", 1) == 1) ? true : false; + + // monitoring options + auto& monitoringOptions = config.monitoring_options; + auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; + monitoringOptions.monitoring_mode = monitoringMode; + monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", 5000);; + monitoringOptions.network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", false); + monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", "__.*"); + monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", ""); + monitoringOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); + monitoringOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); + monitoringOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); + + auto& udpMonitoringOptions = monitoringOptions.udp_options; + // TODO: Nothing here yet + + auto& shmMonitoringOptions = monitoringOptions.shm_options; + shmMonitoringOptions.shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", "ecal_monitoring"); + shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", 1024); + + // receiving options + auto& receivingOptions = config.receiving_options; + receivingOptions.shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", true); + receivingOptions.tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", true); + receivingOptions.udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", true); + + // publisher options + auto& publisherOptions = config.publisher_options; + publisherOptions.use_inproc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_inproc", 0)); + publisherOptions.use_shm = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_shm", 0)); + publisherOptions.use_tcp = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_tcp", 0)); + publisherOptions.use_udp_mc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_udp_mc", 0)); + + // sys options + auto& sysOptions = config.sys_options; + sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file + + // timesync options + auto& timesyncOptions = config.timesync_options; + timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", ""); + + // service options + auto& serviceOptions = config.service_options; + serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; + serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; + + return config; + }; + + eCALConfig::eCALConfig() + { + GetIniConfig(*this); } + + // after initialization + eCALConfig* GetCurrentConfig() + { + return g_ecal_config(); + }; + } } \ No newline at end of file diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index ae0a10cd6b..c0458c598e 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -166,7 +166,7 @@ namespace eCAL if (user_config_ != nullptr) { - g_globals()->SetUserConfig(user_config_); + g_globals()->SetUserConfig(*user_config_); } // (post)initialize single components diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index 1dccf5a5f2..54858c9316 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -142,8 +142,6 @@ namespace eCAL { // TODO PG: discuss the priority if (g_globals() == nullptr) return(nullptr); - if (g_globals()->user_config() != nullptr) return(g_globals()->user_config().get()); - if (g_globals()->ecal_ini_config() != nullptr) return(g_globals()->ecal_ini_config().get()); - if (g_globals()->ecal_default_config() != nullptr) return(g_globals()->ecal_default_config().get()); - } + if (g_globals()->ecal_config() != nullptr) return(g_globals()->ecal_config().get()); } +} diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 5455e6c7f1..04b43bc33c 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -65,7 +65,7 @@ namespace eCAL CRegistrationReceiver* g_registration_receiver(); CMemFileThreadPool* g_memfile_pool(); CMemFileMap* g_memfile_map(); - Config::eCALConfig* g_ecal_config(); + Config::eCALConfig* g_ecal_config(); // declaration of globally accessible variables diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index ebed7bcd93..d15aeff258 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -31,7 +31,7 @@ namespace eCAL { - CGlobals::CGlobals() : initialized(false), components(0), ecal_default_config_instance(std::make_unique()) + CGlobals::CGlobals() : initialized(false), components(0) {} CGlobals::~CGlobals() @@ -39,10 +39,9 @@ namespace eCAL Finalize(Init::All); } - void CGlobals::SetUserConfig(Config::eCALConfig* user_config_) + void CGlobals::SetUserConfig(Config::eCALConfig& user_config_) { - user_config_instance = std::make_unique(); - std::memcpy(user_config_instance.get(), user_config_, sizeof(Config::eCALConfig)); + ecal_config_instance = std::make_unique(user_config_); } int CGlobals::Initialize(unsigned int components_, std::vector* config_keys_ /*= nullptr*/) @@ -53,34 +52,9 @@ namespace eCAL ///////////////////// // CONFIG ///////////////////// - if (config_instance == nullptr) + if (ecal_config_instance == nullptr) { - config_instance = std::make_unique(); - if (config_keys_) - { - config_instance->OverwriteKeys(*config_keys_); - } - config_instance->AddFile(g_default_ini_file); - - if (!config_instance->Validate()) - { - const std::string emsg("Core initialization failed cause by a configuration error."); - - std::cerr << std::endl; - std::cerr << "----------------------------------------------------------" << std::endl; - std::cerr << "eCAL CORE PANIC :-(" << std::endl; - std::cerr << std::endl; - std::cerr << emsg << std::endl; - std::cerr << "----------------------------------------------------------" << std::endl; - std::cerr << std::endl; - - throw std::runtime_error(emsg.c_str()); - } - - ecal_ini_config_instance = std::make_unique(Config::GetIniConfig()); - ecal_default_config_instance = std::make_unique(Config::GetDefaultConfig()); - - new_initialization = true; + ecal_config_instance = std::make_unique(); } ///////////////////// @@ -302,9 +276,7 @@ namespace eCAL memfile_map_instance = nullptr; log_instance = nullptr; config_instance = nullptr; - user_config_instance.reset(); - ecal_ini_config_instance.reset(); - ecal_default_config_instance.reset(); + ecal_config_instance.reset(); initialized = false; diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index ee1f044892..6de86357b5 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -51,7 +51,7 @@ namespace eCAL int Initialize ( unsigned int components_, std::vector* config_keys_ = nullptr); int IsInitialized ( unsigned int component_ ); - void SetUserConfig(Config::eCALConfig* user_settings_); + void SetUserConfig(Config::eCALConfig& user_config_); unsigned int GetComponents() { return(components); }; @@ -70,9 +70,7 @@ namespace eCAL const std::unique_ptr& registration_receiver() { return registration_receiver_instance; }; const std::unique_ptr& memfile_pool() { return memfile_pool_instance; }; const std::unique_ptr& memfile_map() { return memfile_map_instance; }; - const std::unique_ptr& user_config() { return user_config_instance; }; - const std::unique_ptr& ecal_ini_config() { return ecal_ini_config_instance; }; - const std::unique_ptr& ecal_default_config() { return ecal_default_config_instance; }; + const std::unique_ptr& ecal_config() { return ecal_config_instance; }; private: @@ -91,8 +89,6 @@ namespace eCAL std::unique_ptr registration_receiver_instance; std::unique_ptr memfile_pool_instance; std::unique_ptr memfile_map_instance; - std::unique_ptr user_config_instance; - std::unique_ptr ecal_ini_config_instance; - std::unique_ptr ecal_default_config_instance; + std::unique_ptr ecal_config_instance; }; } From 548037fe0c0eab2da8c3812ad52747ff0d59c4a6 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:11:57 +0100 Subject: [PATCH 006/105] Changed defines to constexpr in ecal_dev_ini.h --- ecal/core/src/ecal_def.h | 130 ++++++++++++++++++----------------- ecal/core/src/ecal_def_ini.h | 2 +- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index d65905faf5..b7013983e4 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -23,107 +23,109 @@ #pragma once +#include #include /**********************************************************************************************/ /* config settings */ /**********************************************************************************************/ /* base data path name */ -#define ECAL_HOME_PATH_WINDOWS "" -#define ECAL_HOME_PATH_LINUX ".ecal" -#define ECAL_LOG_PATH "logs" -#define ECAL_SETTINGS_PATH "cfg" +constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; +constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; +constexpr char ECAL_HOME_PATH_LINUX[] = ".ecal"; +constexpr char ECAL_LOG_PATH[] = "logs"; +constexpr char ECAL_SETTINGS_PATH[] = "cfg"; /* ini file name */ -#define ECAL_DEFAULT_CFG "ecal.ini" +constexpr char ECAL_DEFAULT_CFG[] = "ecal.ini"; /**********************************************************************************************/ /* monitor settings */ /**********************************************************************************************/ /* timeout for automatic removing monitoring topics in ms */ -#define MON_TIMEOUT 5000 +constexpr unsigned int MON_TIMEOUT = 5000U; /* topics blacklist as regular expression (will not be monitored) */ -#define MON_FILTER_EXCL "^__.*$" +constexpr char MON_FILTER_EXCL[] = "^__.*$"; /* topics whitelist as regular expression (will be monitored only) */ -#define MON_FILTER_INCL "" +constexpr char MON_FILTER_INCL[] = ""; /* logging filter settings */ -#define MON_LOG_FILTER_CON "info,warning,error,fatal" -#define MON_LOG_FILTER_FILE "" -#define MON_LOG_FILTER_UDP "info,warning,error,fatal" +constexpr char MON_LOG_FILTER_CON[] = "info,warning,error,fatal"; +constexpr char MON_LOG_FILTER_FILE[] = ""; +constexpr char MON_LOG_FILTER_UDP[] = "info,warning,error,fatal"; /**********************************************************************************************/ /* sys settings */ /**********************************************************************************************/ /* sys app witch will not be imported from cloud */ -#define SYS_FILTER_EXCL "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*" +constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"; /**********************************************************************************************/ /* network settings */ /**********************************************************************************************/ /* network switch */ -#define NET_ENABLED false +constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -#define NET_UDP_MULTICAST_CONFIG_VERSION "v1" -#define NET_UDP_MULTICAST_GROUP "239.0.0.1" -#define NET_UDP_MULTICAST_MASK "0.0.0.15" -#define NET_UDP_MULTICAST_PORT 14000 -#define NET_UDP_MULTICAST_TTL 3 -#define NET_UDP_MULTICAST_PORT_REG_OFF 0 -#define NET_UDP_MULTICAST_PORT_LOG_OFF 1 -#define NET_UDP_MULTICAST_PORT_SAMPLE_OFF 2 -#define NET_UDP_MULTICAST_SNDBUF (5*1024*1024) /* 5 MByte */ -#define NET_UDP_MULTICAST_RCVBUF (5*1024*1024) /* 5 MByte */ -#define NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED false - -#define NET_UDP_RECBUFFER_TIMEOUT 1000 /* ms */ -#define NET_UDP_RECBUFFER_CLEANUP 10 /* ms */ +constexpr char NET_UDP_MULTICAST_CONFIG_VERSION[] = "v1"; +constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; +constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; +constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; +constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; +constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; +constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; +constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; +constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ +constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; + +constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10; /* ms */ /* overall udp multicast bandwidth limitation in bytes/s, -1 == no limitation*/ -#define NET_BANDWIDTH_MAX_UDP (-1) +constexpr int NET_BANDWIDTH_MAX_UDP = (-1); -#define NET_TCP_REC_ENABLED true -#define NET_SHM_REC_ENABLED true +constexpr bool NET_TCP_REC_ENABLED = true; +constexpr bool NET_SHM_REC_ENABLED = true; -#define NET_UDP_MC_REC_ENABLED true +constexpr bool NET_UDP_MC_REC_ENABLED = true; -#define NET_NPCAP_ENABLED false +constexpr bool NET_NPCAP_ENABLED = false; -#define NET_TCP_PUBSUB_NUM_EXECUTOR_READER 4 -#define NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER 4 -#define NET_TCP_PUBSUB_MAX_RECONNECTIONS 5 +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4; +constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5; /* common host group name that enables interprocess mechanisms across (virtual) host borders (e.g, Docker); by default equivalent to local host name */ -#define NET_HOST_GROUP_NAME "" +constexpr char NET_HOST_GROUP_NAME[] = ""; /**********************************************************************************************/ /* publisher settings */ /**********************************************************************************************/ /* use shared memory transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_SHM 2 +constexpr unsigned int PUB_USE_SHM = 2; /* use tcp transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_TCP 0 +constexpr unsigned int PUB_USE_TCP = 0; /* use udp multicast transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_UDP_MC 2 +constexpr unsigned int PUB_USE_UDP_MC = 2; /* share topic type [ on = 1, off = 0] */ -#define PUB_SHARE_TTYPE 1 +constexpr unsigned int PUB_SHARE_TTYPE = 1; /* share topic description [ on = 1, off = 0] */ -#define PUB_SHARE_TDESC 1 +constexpr unsigned int PUB_SHARE_TDESC = 1; /* minimum size for created shared memory files */ -#define PUB_MEMFILE_MINSIZE (4*1024) +constexpr unsigned int PUB_MEMFILE_MINSIZE = (4*1024); /* reserve buffer size before reallocation in % */ -#define PUB_MEMFILE_RESERVE 50 +constexpr unsigned int PUB_MEMFILE_RESERVE = 50; /* timeout for create / open a memory file using mutex lock in ms */ -#define PUB_MEMFILE_CREATE_TO 200 -#define PUB_MEMFILE_OPEN_TO 200 +constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200; +constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200; /* timeout for memory read acknowledge signal from data reader in ms */ -#define PUB_MEMFILE_ACK_TO 0 /* ms */ +constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ /* defines number of memory files handle by the publisher for a 1:n connection a higher number will increase data throughput, but will also increase the size of used memory, number of semaphores @@ -131,68 +133,68 @@ higher values than 3 are not recommended values > 1 will break local IPC compatibility to eCAL 5.9 and older */ -#define PUB_MEMFILE_BUF_COUNT 1 +constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1; /* allow subscriber to access memory file without copying content in advance (zero copy) this memory file is blocked for other readers wihle processed by the user callback function this option is fully IPC compatible to all eCAL 5.x versions */ -#define PUB_MEMFILE_ZERO_COPY 0 +constexpr unsigned int PUB_MEMFILE_ZERO_COPY = 0; /**********************************************************************************************/ /* service settings */ /**********************************************************************************************/ /* support service protocol v0, eCAL 5.11 and older (0 = off, 1 = on) */ -#define SERVICE_PROTOCOL_V0 1 +constexpr unsigned int SERVICE_PROTOCOL_V0 = 1; /* support service protocol v1, eCAL 5.12 and newer (0 = off, 1 = on) */ -#define SERVICE_PROTOCOL_V1 1 +constexpr unsigned int SERVICE_PROTOCOL_V1 = 1; /**********************************************************************************************/ /* time settings */ /**********************************************************************************************/ -#define TIME_SYNC_MOD_RT "" -#define TIME_SYNC_MOD_REPLAY "" +constexpr char TIME_SYNC_MOD_RT[] = ""; +constexpr char TIME_SYNC_MOD_REPLAY[] = ""; /**********************************************************************************************/ /* process settings */ /**********************************************************************************************/ -#define PROCESS_TERMINAL_EMULATOR "" +constexpr char PROCESS_TERMINAL_EMULATOR[] = ""; /**********************************************************************************************/ /* ecal internal timings */ /**********************************************************************************************/ /* timeout for automatic removing registered topics and memory files in global database in ms */ -#define CMN_REGISTRATION_TO (60*1000) +constexpr unsigned int CMN_REGISTRATION_TO = (60*1000); /* time for resend registration info from publisher/subscriber in ms */ -#define CMN_REGISTRATION_REFRESH 1000 +constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000; /* delta time to check timeout for data readers in ms */ -#define CMN_DATAREADER_TIMEOUT_RESOLUTION_MS 100 +constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100; /* cylce time udp receive threads in ms */ -#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000 +constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000; /**********************************************************************************************/ /* events */ /**********************************************************************************************/ /* common stop event prefix to shut down a local user process */ -#define EVENT_SHUTDOWN_PROC "ecal_shutdown_process" +constexpr char EVENT_SHUTDOWN_PROC[] = "ecal_shutdown_process"; /**********************************************************************************************/ /* experimental */ /**********************************************************************************************/ /* enable distribution of monitoring/registration information via shared memory */ -#define EXP_SHM_MONITORING_ENABLED false +constexpr bool EXP_SHM_MONITORING_ENABLED = false; /* disable distribution of monitoring/registration information via network (default) */ -#define EXP_NETWORK_MONITORING_DISABLED false +constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; /* queue size of monitoring/registration events */ -#define EXP_SHM_MONITORING_QUEUE_SIZE 1024 +constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024; /* domain name for shared memory based monitoring/registration */ -#define EXP_SHM_MONITORING_DOMAIN "ecal_monitoring" +constexpr char EXP_SHM_MONITORING_DOMAIN[] = "ecal_monitoring"; /* memory file access timeout */ -#define EXP_MEMFILE_ACCESS_TIMEOUT 100 +constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100; /* enable dropping of payload messages that arrive out of order */ -#define EXP_DROP_OUT_OF_ORDER_MESSAGES false +constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; diff --git a/ecal/core/src/ecal_def_ini.h b/ecal/core/src/ecal_def_ini.h index 71e8968669..08f8fcba1a 100644 --- a/ecal/core/src/ecal_def_ini.h +++ b/ecal/core/src/ecal_def_ini.h @@ -20,7 +20,7 @@ /** * @brief eCAL ini file keys **/ - +// TODO PG: Delete - deprecated #pragma once ///////////////////////////////////// From 5b07971829d284408ebc8890ef79757ca73a3e38 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:23:12 +0100 Subject: [PATCH 007/105] Removed doubled constexpr. --- ecal/core/src/ecal_def.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index b7013983e4..78958e2932 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -31,7 +31,6 @@ /**********************************************************************************************/ /* base data path name */ constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; -constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; constexpr char ECAL_HOME_PATH_LINUX[] = ".ecal"; constexpr char ECAL_LOG_PATH[] = "logs"; constexpr char ECAL_SETTINGS_PATH[] = "cfg"; From 9cd3594099957ef3bc3d10a9801fcc943dfdcf2d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 08:36:03 +0100 Subject: [PATCH 008/105] Removed former ecal_config cpp and h from core/CMakesLists --- ecal/core/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 64f9013b16..2b81ab1946 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -56,7 +56,6 @@ endif() # config ###################################### set(ecal_config_src - src/config/ecal_config.cpp src/config/ecal_config_reader.cpp src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h @@ -364,7 +363,6 @@ set(ecal_header_cmn include/ecal/ecal_callback.h include/ecal/ecal_clang.h include/ecal/ecal_client.h - include/ecal/ecal_config.h include/ecal/ecal_core.h include/ecal/ecal_deprecate.h include/ecal/ecal_event.h From 9e1be9a6ee1c5c57b63256d8c678aaa169e1c9a8 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 08:37:30 +0100 Subject: [PATCH 009/105] Removed ms_t from registration_options and handling in using functions. --- .../include/ecal/types/ecal_registration_options.h | 11 +++++------ ecal/core/src/config/ecal_config_initializer.cpp | 4 ++-- ecal/core/src/readwrite/ecal_reader.cpp | 2 +- ecal/core/src/readwrite/ecal_writer.cpp | 2 +- ecal/core/src/readwrite/shm/ecal_reader_shm.cpp | 2 +- .../src/registration/ecal_registration_provider.cpp | 4 ++-- .../src/registration/ecal_registration_receiver.cpp | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h index 475f64fc8a..0d2af7f973 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -34,9 +34,8 @@ namespace eCAL struct RegistrationOptions { public: - using ms_t = std::chrono::milliseconds; RegistrationOptions() = default; - RegistrationOptions(ms_t reg_timeout_, ms_t reg_refresh_) + RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_) { if (reg_refresh_ < reg_timeout_) { @@ -49,15 +48,15 @@ namespace eCAL } }; - ms_t getTimeout() const { return registration_timeout; } - ms_t getRefresh() const { return registration_refresh; } + unsigned int getTimeoutMS() const { return registration_timeout; } + unsigned int getRefreshMS() const { return registration_refresh; } bool share_ttype = true; bool share_tdesc = true; private: - ms_t registration_timeout = ms_t(60000); - ms_t registration_refresh = ms_t(1000); + unsigned int registration_timeout = unsigned int(60000); + unsigned int registration_refresh = unsigned int(1000); }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 6d3a5b9d44..253c457320 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -127,7 +127,7 @@ namespace eCAL // registration options auto& registrationOptions = config.registration_options; - registrationOptions = RegistrationOptions(RegistrationOptions::ms_t(60000), RegistrationOptions::ms_t(1000)); + registrationOptions = RegistrationOptions(60000U, 1000U); registrationOptions.share_tdesc = true; registrationOptions.share_ttype = true; @@ -223,7 +223,7 @@ namespace eCAL // registration options auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", 5000); auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", 1000); - config.registration_options = RegistrationOptions(RegistrationOptions::ms_t(registrationTimeout), RegistrationOptions::ms_t(registrationRefresh)); + config.registration_options = RegistrationOptions(registrationTimeout, registrationRefresh); auto& registrationOptions = config.registration_options; registrationOptions.share_tdesc = (iniConfig.get(PUBLISHER, "share_tdesc", 1) == 1) ? true : false; registrationOptions.share_ttype = (iniConfig.get(PUBLISHER, "share_ttype", 1) == 1) ? true : false; diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index 6ba0b9b750..823d6e75a6 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -100,7 +100,7 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout = Config::GetCurrentConfig()->registration_options.getTimeout(); + const std::chrono::milliseconds registration_timeout(Config::GetCurrentConfig()->registration_options.getTimeoutMS()); m_loc_pub_map.set_expiration(registration_timeout); m_ext_pub_map.set_expiration(registration_timeout); diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 5ef5c88e04..3ab77d08e3 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -127,7 +127,7 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout = g_ecal_config()->registration_options.getTimeout(); + const std::chrono::milliseconds registration_timeout(g_ecal_config()->registration_options.getTimeoutMS()); m_loc_sub_map.set_expiration(registration_timeout); m_ext_sub_map.set_expiration(registration_timeout); diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp index beed6d4da8..1819035594 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp @@ -96,7 +96,7 @@ namespace eCAL const std::string memfile_event = memfile_name + "_" + process_id; const MemFileDataCallbackT memfile_data_callback = std::bind(&CSHMReaderLayer::OnNewShmFileContent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8); - g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config()->registration_options.getTimeout().count(), memfile_data_callback); + g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config()->registration_options.getTimeoutMS(), memfile_data_callback); } } } diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 2e4d7341a5..9815b261c7 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -71,7 +71,7 @@ namespace eCAL { if(m_created) return; - m_reg_refresh = g_ecal_config()->registration_options.getRefresh().count(); + m_reg_refresh = g_ecal_config()->registration_options.getRefreshMS(); m_reg_topics = topics_; m_reg_services = services_; @@ -108,7 +108,7 @@ namespace eCAL // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(g_ecal_config()->registration_options.getRefresh()); + m_reg_sample_snd_thread->start(g_ecal_config()->registration_options.getRefreshMS()); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index 57c89b32b1..498edb2aa7 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -58,7 +58,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(g_ecal_config()->registration_options.getRefresh()); + m_memfile_broadcast_reader_thread->start(g_ecal_config()->registration_options.getRefreshMS()); m_created = true; } From c5ab1dcb724afd95d84375d0e68b2afd73aa9257 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:33:12 +0100 Subject: [PATCH 010/105] Fixed ecal_registration cpp time config import. --- ecal/core/src/registration/ecal_registration_provider.cpp | 2 +- ecal/core/src/registration/ecal_registration_receiver.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 9815b261c7..353fe879a1 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -108,7 +108,7 @@ namespace eCAL // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(g_ecal_config()->registration_options.getRefreshMS()); + m_reg_sample_snd_thread->start(std::chrono::milliseconds(g_ecal_config()->registration_options.getRefreshMS())); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index 498edb2aa7..4c296fe880 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -58,7 +58,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(g_ecal_config()->registration_options.getRefreshMS()); + m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(g_ecal_config()->registration_options.getRefreshMS()/2)); m_created = true; } From 05ec616073d7dc0deb65a2c8216d0245120ff09d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:41:53 +0100 Subject: [PATCH 011/105] Refactored config options in application. --- app/mon/mon_gui/src/ecalmon.cpp | 4 ++-- .../mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp | 4 ++-- app/mon/mon_tui/src/tui/viewmodel/command_line.hpp | 2 +- app/rec/rec_client_core/src/job/record_job.cpp | 3 ++- .../import_from_cloud_widget/import_from_cloud_widget.cpp | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/mon/mon_gui/src/ecalmon.cpp b/app/mon/mon_gui/src/ecalmon.cpp index 2abed6fd10..d2d72446bc 100644 --- a/app/mon/mon_gui/src/ecalmon.cpp +++ b/app/mon/mon_gui/src/ecalmon.cpp @@ -93,8 +93,8 @@ Ecalmon::Ecalmon(QWidget *parent) network_mode_warning_icon_->setPixmap(warning_icon); network_mode_warning_icon_->setVisible(false); - bool network_mode = eCAL::Config::IsNetworkEnabled(); - int multicast_ttl = eCAL::Config::GetUdpMulticastTtl(); + bool network_mode = eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled; + int multicast_ttl = eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.ttl; if (network_mode) { diff --git a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp index 1767da389f..79f8cb9d70 100644 --- a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp +++ b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp @@ -187,9 +187,9 @@ void TopicWidget::loadRegExpLists() QString exclude_string; QString include_string; - exclude_string = QString::fromStdString(eCAL::Config::GetMonitoringFilterExcludeList()); //ini.GetValue(MON_SECTION_S, MON_FILTER_EXCL_S); + exclude_string = QString::fromStdString(eCAL::Config::GetCurrentConfig()->monitoring_options.filter_excl); - include_string = QString::fromStdString(eCAL::Config::GetMonitoringFilterIncludeList()); //ini.GetValue(MON_SECTION_S, MON_FILTER_INCL_S); + include_string = QString::fromStdString(eCAL::Config::GetCurrentConfig()->monitoring_options.filter_incl); // The ecal.ini defines a very strange regex format: A filter consists of diff --git a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp index b796bfedbf..3d081935e3 100644 --- a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp +++ b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp @@ -115,7 +115,7 @@ class CommandLineViewModel : public ViewModel { using namespace std::placeholders; - network_mode = eCAL::Config::IsNetworkEnabled() ? "cloud" : "local"; + network_mode = eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled ? "cloud" : "local"; is_polling_time = true; time_updater = std::thread(std::bind(&CommandLineViewModel::UpdateCurrentEcalTime, this)); diff --git a/app/rec/rec_client_core/src/job/record_job.cpp b/app/rec/rec_client_core/src/job/record_job.cpp index b0715a568a..fa4c0a1704 100644 --- a/app/rec/rec_client_core/src/job/record_job.cpp +++ b/app/rec/rec_client_core/src/job/record_job.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "hdf5_writer_thread.h" @@ -170,7 +171,7 @@ namespace eCAL #undef CopyFile #endif // CopyFile { - std::string ecal_ini_original_path = eCAL::Config::GetLoadedEcalIniPath(); + std::string ecal_ini_original_path = Config::GetCurrentConfig()->loaded_ecal_ini_file; if (ecal_ini_original_path.empty()) { diff --git a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp index e2882fd2c3..787661e8c3 100644 --- a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp +++ b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp @@ -927,8 +927,8 @@ void ImportFromCloudWidget::loadExcludeTasksFilter() QFile default_cfg_file(default_cfg_file_path.c_str()); if (default_cfg_file.exists()) { - std::regex reg(eCAL::Config::GetEcalSysFilterExcludeList(), std::regex::icase); - exclude_tasks_regex_valid_ = !eCAL::Config::GetEcalSysFilterExcludeList().empty(); + std::regex reg(eCAL::Config::GetCurrentConfig()->sys_options.filter_excl, std::regex::icase); + exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig()->sys_options.filter_excl.empty(); exclude_tasks_regex_ = reg; } } From a861b01853a395dcc0d4151b8626f6539903d74a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:42:52 +0100 Subject: [PATCH 012/105] Added process_options.terminal_emulator to config. --- ecal/core/include/ecal/types/ecal_config_types.h | 1 + ecal/core/src/config/ecal_config_initializer.cpp | 9 +++++++++ ecal/core/src/ecal_process.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 6712d2dd8e..3b520ff7b1 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -58,6 +58,7 @@ namespace eCAL SysOptions sys_options; TimesyncOptions timesync_options; ServiceOptions service_options; + ProcessOptions process_options; std::string loaded_ecal_ini_file; eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 253c457320..ccdfcae622 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -35,6 +35,7 @@ constexpr char PUBLISHER[] = "publisher"; constexpr char SYS[] = "sys"; constexpr char TIME[] = "time"; constexpr char SERVICE[] = "service"; +constexpr char PROCESS[] = "process"; namespace { void tokenize(const std::string& str, std::vector& tokens, @@ -175,6 +176,10 @@ namespace eCAL serviceOptions.protocol_v0 = true; serviceOptions.protocol_v1 = true; + // process options + auto& processOptions = config.process_options; + processOptions.terminal_emulator = ""; + return config; }; @@ -273,6 +278,10 @@ namespace eCAL serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; + // process options + auto& processOptions = config.process_options; + processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", ""); + return config; }; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 648ab01fab..a35ecf114e 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -798,7 +798,7 @@ namespace // -------------------- terminal_emulator command check -------------------- - const std::string terminal_emulator_command = eCAL::Config::GetTerminalEmulatorCommand(); + const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->process_options.terminal_emulator; if (!terminal_emulator_command.empty()) { STD_COUT_DEBUG("[PID " << getpid() << "]: " << "ecal.ini terminal emulator command is: " << terminal_emulator_command << std::endl); From e35df5ae185bfa4794a45dc99cdc565e6b61fd14 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:49:50 +0100 Subject: [PATCH 013/105] Refactored sys- and processoptions as sub to application options. --- .../ecal/types/ecal_application_options.h | 6 ++++++ .../include/ecal/types/ecal_config_types.h | 3 +-- .../src/config/ecal_config_initializer.cpp | 20 +++++++++---------- ecal/core/src/ecal_process.cpp | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h index 7cf621a5ab..0dda3b4787 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -39,5 +39,11 @@ namespace eCAL { std::string terminal_emulator; }; + + struct ApplicationOptions + { + SysOptions sys_options; + ProcessOptions process_options; + }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 3b520ff7b1..39ccf7c0a8 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -55,10 +55,9 @@ namespace eCAL MonitoringOptions monitoring_options; ReceivingOptions receiving_options; PublisherOptions publisher_options; - SysOptions sys_options; TimesyncOptions timesync_options; ServiceOptions service_options; - ProcessOptions process_options; + ApplicationOptions application_options; std::string loaded_ecal_ini_file; eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index ccdfcae622..3ffe1ccdf6 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -163,10 +163,6 @@ namespace eCAL publisherOptions.use_tcp = TLayer::smode_off; publisherOptions.use_udp_mc = TLayer::smode_auto; - // sys options - auto& sysOptions = config.sys_options; - sysOptions.filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; - // timesync options auto& timesyncOptions = config.timesync_options; timesyncOptions.timesync_module = "ecaltime-localtime"; @@ -176,8 +172,12 @@ namespace eCAL serviceOptions.protocol_v0 = true; serviceOptions.protocol_v1 = true; + // sys options + auto& sysOptions = config.application_options.sys_options; + sysOptions.filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; + // process options - auto& processOptions = config.process_options; + auto& processOptions = config.application_options.process_options; processOptions.terminal_emulator = ""; return config; @@ -265,10 +265,6 @@ namespace eCAL publisherOptions.use_tcp = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_tcp", 0)); publisherOptions.use_udp_mc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_udp_mc", 0)); - // sys options - auto& sysOptions = config.sys_options; - sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file - // timesync options auto& timesyncOptions = config.timesync_options; timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", ""); @@ -278,8 +274,12 @@ namespace eCAL serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; + // sys options + auto& sysOptions = config.application_options.sys_options; + sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file + // process options - auto& processOptions = config.process_options; + auto& processOptions = config.application_options.process_options; processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", ""); return config; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index a35ecf114e..080232b9b0 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -798,7 +798,7 @@ namespace // -------------------- terminal_emulator command check -------------------- - const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->process_options.terminal_emulator; + const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->application_options.process_options.terminal_emulator; if (!terminal_emulator_command.empty()) { STD_COUT_DEBUG("[PID " << getpid() << "]: " << "ecal.ini terminal emulator command is: " << terminal_emulator_command << std::endl); From 4a0ce135bb6a00191fcad3476da6518a4fa17c9e Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:44:16 +0100 Subject: [PATCH 014/105] Refactored default config to use ecal_def.h defines. --- .../ecal/types/ecal_monitoring_options.h | 2 +- .../src/config/ecal_config_initializer.cpp | 98 +++++++++---------- ecal/core/src/ecal_def.h | 50 +++++----- 3 files changed, 77 insertions(+), 73 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index 30a66f61b7..46236215d7 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -26,7 +26,7 @@ #include "ecal_custom_data_types.h" -#include "../ecal_log_level.h" +#include namespace eCAL { diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 3ffe1ccdf6..f4326f7b24 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -25,6 +25,7 @@ #include "ecal_config_reader.h" #include "ecal_global_accessors.h" +#include "ecal_def.h" #include "config/ecal_config_reader.h" constexpr char COMMON[] = "common"; @@ -97,88 +98,87 @@ namespace eCAL { // transport layer options auto& transportLayerOptions = config.transport_layer_options; - transportLayerOptions.network_enabled = false; - transportLayerOptions.drop_out_of_order_messages = false; + transportLayerOptions.network_enabled = NET_ENABLED; + transportLayerOptions.drop_out_of_order_messages = EXP_DROP_OUT_OF_ORDER_MESSAGES; auto& multicastOptions = transportLayerOptions.mc_options; - multicastOptions.config_version = UdpConfigVersion::V1; - multicastOptions.group = std::string("239.0.0.1"); - multicastOptions.mask = std::string("0.0.0.15"); - multicastOptions.port = 14000; - multicastOptions.ttl = 2; - multicastOptions.recbuf = (1024 * 1024 * 5); - multicastOptions.sndbuf = (1024 * 1024 * 5); - multicastOptions.join_all_interfaces = false; - multicastOptions.bandwidth_max_udp = -1; - multicastOptions.npcap_enabled = false; + multicastOptions.config_version = NET_UDP_MULTICAST_CONFIG_VERSION; + multicastOptions.group = std::string(NET_UDP_MULTICAST_GROUP); + multicastOptions.mask = std::string(NET_UDP_MULTICAST_MASK); + multicastOptions.port = NET_UDP_MULTICAST_PORT; + multicastOptions.ttl = NET_UDP_MULTICAST_TTL; + multicastOptions.recbuf = NET_UDP_MULTICAST_RCVBUF; + multicastOptions.sndbuf = NET_UDP_MULTICAST_SNDBUF; + multicastOptions.join_all_interfaces = NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED; + multicastOptions.bandwidth_max_udp = NET_BANDWIDTH_MAX_UDP; + multicastOptions.npcap_enabled = NET_NPCAP_ENABLED; auto& tcpPubSubOptions = transportLayerOptions.tcp_options; - tcpPubSubOptions.num_executor_reader = 4; - tcpPubSubOptions.num_executor_writer = 4; - tcpPubSubOptions.max_reconnections = 5; + tcpPubSubOptions.num_executor_reader = NET_TCP_PUBSUB_NUM_EXECUTOR_READER; + tcpPubSubOptions.num_executor_writer = NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER; + tcpPubSubOptions.max_reconnections = NET_TCP_PUBSUB_MAX_RECONNECTIONS; auto& shmOptions = transportLayerOptions.shm_options; - shmOptions.host_group_name = ""; - shmOptions.memfile_minsize = 4096; - shmOptions.memfile_reserve = 50; - shmOptions.memfile_ack_timeout = 0; - shmOptions.memfile_buffer_count = 1; - shmOptions.drop_out_of_order_messages = false; - shmOptions.memfile_zero_copy = false; + shmOptions.host_group_name = NET_HOST_GROUP_NAME; + shmOptions.memfile_minsize = PUB_MEMFILE_MINSIZE; + shmOptions.memfile_reserve = PUB_MEMFILE_RESERVE; + shmOptions.memfile_ack_timeout = PUB_MEMFILE_ACK_TO; + shmOptions.memfile_buffer_count = PUB_MEMFILE_BUF_COUNT; + shmOptions.drop_out_of_order_messages = EXP_DROP_OUT_OF_ORDER_MESSAGES; + shmOptions.memfile_zero_copy = PUB_MEMFILE_ZERO_COPY; // registration options auto& registrationOptions = config.registration_options; - registrationOptions = RegistrationOptions(60000U, 1000U); - registrationOptions.share_tdesc = true; - registrationOptions.share_ttype = true; + registrationOptions = RegistrationOptions(CMN_REGISTRATION_TO, CMN_REGISTRATION_REFRESH); + registrationOptions.share_tdesc = PUB_SHARE_TDESC; + registrationOptions.share_ttype = PUB_SHARE_TTYPE; // monitoring options auto& monitoringOptions = config.monitoring_options; - monitoringOptions.monitoring_mode = MonitoringMode::none; - monitoringOptions.monitoring_timeout = 5000; - monitoringOptions.network_monitoring_disabled = false; - monitoringOptions.filter_excl = "__.*"; - monitoringOptions.filter_incl = ""; - monitoringOptions.filter_log_con = log_level_error | log_level_fatal | log_level_warning; - monitoringOptions.filter_log_file = log_level_none; - monitoringOptions.filter_log_udp = log_level_info | log_level_error | log_level_fatal | log_level_warning; - - auto& udpMonitoringOptions = monitoringOptions.udp_options; + monitoringOptions.monitoring_mode = EXP_MONITORING_MODE; + monitoringOptions.monitoring_timeout = MON_TIMEOUT; + monitoringOptions.network_monitoring_disabled = EXP_NETWORK_MONITORING_DISABLED; + monitoringOptions.filter_excl = MON_FILTER_EXCL; + monitoringOptions.filter_incl = MON_FILTER_INCL; + monitoringOptions.filter_log_con = MON_LOG_FILTER_CON; + monitoringOptions.filter_log_file = MON_LOG_FILTER_FILE; + monitoringOptions.filter_log_udp = MON_LOG_FILTER_UDP; + + // auto& udpMonitoringOptions = monitoringOptions.udp_options; // TODO: Nothing here yet auto& shmMonitoringOptions = monitoringOptions.shm_options; - shmMonitoringOptions.shm_monitoring_domain = "ecal_monitoring"; - shmMonitoringOptions.shm_monitoring_queue_size = 1024; + shmMonitoringOptions.shm_monitoring_domain = std::string(EXP_SHM_MONITORING_DOMAIN); + shmMonitoringOptions.shm_monitoring_queue_size = EXP_SHM_MONITORING_QUEUE_SIZE; // receiving options auto& receivingOptions = config.receiving_options; - receivingOptions.shm_recv_enabled = true; - receivingOptions.tcp_recv_enabled = true; - receivingOptions.udp_mc_recv_enabled = true; + receivingOptions.shm_recv_enabled = NET_SHM_REC_ENABLED; + receivingOptions.tcp_recv_enabled = NET_TCP_REC_ENABLED; + receivingOptions.udp_mc_recv_enabled = NET_UDP_MC_REC_ENABLED; // publisher options auto& publisherOptions = config.publisher_options; - publisherOptions.use_inproc = TLayer::smode_off; - publisherOptions.use_shm = TLayer::smode_auto; - publisherOptions.use_tcp = TLayer::smode_off; - publisherOptions.use_udp_mc = TLayer::smode_auto; + publisherOptions.use_shm = PUB_USE_SHM; + publisherOptions.use_tcp = PUB_USE_TCP; + publisherOptions.use_udp_mc = PUB_USE_UDP_MC; // timesync options auto& timesyncOptions = config.timesync_options; - timesyncOptions.timesync_module = "ecaltime-localtime"; + timesyncOptions.timesync_module = TIME_SYNC_MODULE; // service options auto& serviceOptions = config.service_options; - serviceOptions.protocol_v0 = true; - serviceOptions.protocol_v1 = true; + serviceOptions.protocol_v0 = SERVICE_PROTOCOL_V0; + serviceOptions.protocol_v1 = SERVICE_PROTOCOL_V1; // sys options auto& sysOptions = config.application_options.sys_options; - sysOptions.filter_excl = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; + sysOptions.filter_excl = SYS_FILTER_EXCL; // process options auto& processOptions = config.application_options.process_options; - processOptions.terminal_emulator = ""; + processOptions.terminal_emulator = PROCESS_TERMINAL_EMULATOR; return config; }; diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 78958e2932..e2f7761c2e 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -24,6 +24,7 @@ #pragma once #include +#include #include /**********************************************************************************************/ @@ -49,9 +50,9 @@ constexpr char MON_FILTER_EXCL[] = "^__.*$"; constexpr char MON_FILTER_INCL[] = ""; /* logging filter settings */ -constexpr char MON_LOG_FILTER_CON[] = "info,warning,error,fatal"; -constexpr char MON_LOG_FILTER_FILE[] = ""; -constexpr char MON_LOG_FILTER_UDP[] = "info,warning,error,fatal"; +constexpr eCAL_Logging_Filter MON_LOG_FILTER_CON = (log_level_info | log_level_warning | log_level_error | log_level_fatal); +constexpr eCAL_Logging_Filter MON_LOG_FILTER_FILE = log_level_none; +constexpr eCAL_Logging_Filter MON_LOG_FILTER_UDP = (log_level_info | log_level_warning | log_level_error | log_level_fatal); /**********************************************************************************************/ @@ -67,17 +68,17 @@ constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -constexpr char NET_UDP_MULTICAST_CONFIG_VERSION[] = "v1"; -constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; -constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; -constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; -constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; -constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; -constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; -constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; -constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ -constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ -constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; +constexpr eCAL::Config::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = eCAL::Config::UdpConfigVersion::V1; +constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; +constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; +constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; +constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; +constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; +constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; +constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; +constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ +constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000; /* ms */ constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10; /* ms */ @@ -103,16 +104,16 @@ constexpr char NET_HOST_GROUP_NAME[] = ""; /* publisher settings */ /**********************************************************************************************/ /* use shared memory transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_SHM = 2; +constexpr eCAL::TLayer::eSendMode PUB_USE_SHM = eCAL::TLayer::eSendMode::smode_auto; /* use tcp transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_TCP = 0; +constexpr eCAL::TLayer::eSendMode PUB_USE_TCP = eCAL::TLayer::eSendMode::smode_off; /* use udp multicast transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_UDP_MC = 2; +constexpr eCAL::TLayer::eSendMode PUB_USE_UDP_MC = eCAL::TLayer::eSendMode::smode_auto; /* share topic type [ on = 1, off = 0] */ -constexpr unsigned int PUB_SHARE_TTYPE = 1; +constexpr bool PUB_SHARE_TTYPE = true; /* share topic description [ on = 1, off = 0] */ -constexpr unsigned int PUB_SHARE_TDESC = 1; +constexpr bool PUB_SHARE_TDESC = true; /* minimum size for created shared memory files */ constexpr unsigned int PUB_MEMFILE_MINSIZE = (4*1024); @@ -138,22 +139,23 @@ constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1; this memory file is blocked for other readers wihle processed by the user callback function this option is fully IPC compatible to all eCAL 5.x versions */ -constexpr unsigned int PUB_MEMFILE_ZERO_COPY = 0; +constexpr bool PUB_MEMFILE_ZERO_COPY = false; /**********************************************************************************************/ /* service settings */ /**********************************************************************************************/ /* support service protocol v0, eCAL 5.11 and older (0 = off, 1 = on) */ -constexpr unsigned int SERVICE_PROTOCOL_V0 = 1; +constexpr bool SERVICE_PROTOCOL_V0 = true; /* support service protocol v1, eCAL 5.12 and newer (0 = off, 1 = on) */ -constexpr unsigned int SERVICE_PROTOCOL_V1 = 1; +constexpr bool SERVICE_PROTOCOL_V1 = true; /**********************************************************************************************/ /* time settings */ /**********************************************************************************************/ constexpr char TIME_SYNC_MOD_RT[] = ""; constexpr char TIME_SYNC_MOD_REPLAY[] = ""; +constexpr char TIME_SYNC_MODULE[] = "ecaltime-localtime"; /**********************************************************************************************/ /* process settings */ @@ -189,7 +191,7 @@ constexpr bool EXP_SHM_MONITORING_ENABLED = false; /* disable distribution of monitoring/registration information via network (default) */ constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; /* queue size of monitoring/registration events */ -constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024; +constexpr size_t EXP_SHM_MONITORING_QUEUE_SIZE = 1024; /* domain name for shared memory based monitoring/registration */ constexpr char EXP_SHM_MONITORING_DOMAIN[] = "ecal_monitoring"; /* memory file access timeout */ @@ -197,3 +199,5 @@ constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100; /* enable dropping of payload messages that arrive out of order */ constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; + +constexpr eCAL::Config::MonitoringMode EXP_MONITORING_MODE = eCAL::Config::MonitoringMode::none; From 153ee9e33190c21133be6bbb059b6b90257a6bfb Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:17:05 +0100 Subject: [PATCH 015/105] Refactored ini config to use ecal_def.h --- .../import_from_cloud_widget.cpp | 4 +- ecal/core/include/ecal/ecal_config.h | 2 +- .../src/config/ecal_config_initializer.cpp | 87 +++++++++---------- ecal/core/src/config/ecal_config_reader.cpp | 10 +++ ecal/core/src/config/ecal_config_reader.h | 10 ++- ecal/core/src/ecal_def.h | 2 +- 6 files changed, 63 insertions(+), 52 deletions(-) diff --git a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp index 787661e8c3..cdabeb82a8 100644 --- a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp +++ b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp @@ -927,8 +927,8 @@ void ImportFromCloudWidget::loadExcludeTasksFilter() QFile default_cfg_file(default_cfg_file_path.c_str()); if (default_cfg_file.exists()) { - std::regex reg(eCAL::Config::GetCurrentConfig()->sys_options.filter_excl, std::regex::icase); - exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig()->sys_options.filter_excl.empty(); + std::regex reg(eCAL::Config::GetCurrentConfig()->application_options.sys_options.filter_excl, std::regex::icase); + exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig()->application_options.sys_options.filter_excl.empty(); exclude_tasks_regex_ = reg; } } diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 98338619d0..8b236d437e 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -16,7 +16,7 @@ * * ========================= eCAL LICENSE ================================= */ - +// TODO PG: Remove, deprecated #pragma once #include diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index f4326f7b24..86a9f598e7 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -190,8 +190,8 @@ namespace eCAL // transport layer options auto& transportLayerOptions = config.transport_layer_options; - transportLayerOptions.network_enabled = iniConfig.get(NETWORK, "network_enabled", false); - transportLayerOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); + transportLayerOptions.network_enabled = iniConfig.get(NETWORK, "network_enabled", NET_ENABLED); + transportLayerOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", EXP_DROP_OUT_OF_ORDER_MESSAGES); auto& multicastOptions = transportLayerOptions.mc_options; @@ -201,86 +201,85 @@ namespace eCAL if (udp_config_version_string == "v2") multicastOptions.config_version = UdpConfigVersion::V2; - multicastOptions.group = iniConfig.get(NETWORK, "multicast_group", "239.0.0.0"); - multicastOptions.mask = iniConfig.get(NETWORK, "multicast_mask", "0.0.0.15"); - multicastOptions.port = iniConfig.get(NETWORK, "multicast_port", 14000); - multicastOptions.ttl = iniConfig.get(NETWORK, "multicast_ttl", 3); - multicastOptions.recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", (1024 * 1024 * 5)); - multicastOptions.sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", (1024 * 1024 * 5)); - multicastOptions.join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", false); - multicastOptions.bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", (- 1)); - multicastOptions.npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", false); + multicastOptions.group = iniConfig.get(NETWORK, "multicast_group", NET_UDP_MULTICAST_GROUP); + multicastOptions.mask = iniConfig.get(NETWORK, "multicast_mask", NET_UDP_MULTICAST_MASK); + multicastOptions.port = iniConfig.get(NETWORK, "multicast_port", NET_UDP_MULTICAST_PORT); + multicastOptions.ttl = iniConfig.get(NETWORK, "multicast_ttl", NET_UDP_MULTICAST_TTL); + multicastOptions.recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", NET_UDP_MULTICAST_RCVBUF); + multicastOptions.sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", NET_UDP_MULTICAST_SNDBUF); + multicastOptions.join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED); + multicastOptions.bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", NET_BANDWIDTH_MAX_UDP); + multicastOptions.npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", NET_NPCAP_ENABLED); auto& tcpPubSubOptions = transportLayerOptions.tcp_options; - tcpPubSubOptions.num_executor_reader = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_reader", 4); - tcpPubSubOptions.num_executor_writer = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_writer", 4); - tcpPubSubOptions.max_reconnections = iniConfig.get(NETWORK, "tcp_pubsup_max_reconnections", 5); + tcpPubSubOptions.num_executor_reader = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_reader", NET_TCP_PUBSUB_NUM_EXECUTOR_READER); + tcpPubSubOptions.num_executor_writer = iniConfig.get(NETWORK, "tcp_pubsup_num_executor_writer", NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER); + tcpPubSubOptions.max_reconnections = iniConfig.get(NETWORK, "tcp_pubsup_max_reconnections", NET_TCP_PUBSUB_MAX_RECONNECTIONS); auto& shmOptions = transportLayerOptions.shm_options; - shmOptions.host_group_name = iniConfig.get(NETWORK, "host_group_name", ""); - shmOptions.memfile_minsize = iniConfig.get(PUBLISHER, "memfile_minsize", (4 * 1024)); - shmOptions.memfile_reserve = iniConfig.get(PUBLISHER, "memfile_reserve", 50); - shmOptions.memfile_ack_timeout = iniConfig.get(PUBLISHER, "memfile_ack_timeout", 0); - shmOptions.memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", 1); - shmOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", false); - shmOptions.memfile_zero_copy = (iniConfig.get(PUBLISHER, "memfile_zero_copy", 0) == 1) ? true : false; + shmOptions.host_group_name = iniConfig.get(NETWORK, "host_group_name", NET_HOST_GROUP_NAME); + shmOptions.memfile_minsize = iniConfig.get(PUBLISHER, "memfile_minsize", PUB_MEMFILE_MINSIZE); + shmOptions.memfile_reserve = iniConfig.get(PUBLISHER, "memfile_reserve", PUB_MEMFILE_RESERVE); + shmOptions.memfile_ack_timeout = iniConfig.get(PUBLISHER, "memfile_ack_timeout", PUB_MEMFILE_ACK_TO); + shmOptions.memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", PUB_MEMFILE_BUF_COUNT); + shmOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", EXP_DROP_OUT_OF_ORDER_MESSAGES); + shmOptions.memfile_zero_copy = iniConfig.get(PUBLISHER, "memfile_zero_copy", PUB_MEMFILE_ZERO_COPY); // registration options - auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", 5000); - auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", 1000); + auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", CMN_REGISTRATION_TO); + auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", CMN_REGISTRATION_REFRESH); config.registration_options = RegistrationOptions(registrationTimeout, registrationRefresh); auto& registrationOptions = config.registration_options; - registrationOptions.share_tdesc = (iniConfig.get(PUBLISHER, "share_tdesc", 1) == 1) ? true : false; - registrationOptions.share_ttype = (iniConfig.get(PUBLISHER, "share_ttype", 1) == 1) ? true : false; + registrationOptions.share_tdesc = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); + registrationOptions.share_ttype = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); // monitoring options auto& monitoringOptions = config.monitoring_options; auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; monitoringOptions.monitoring_mode = monitoringMode; - monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", 5000);; - monitoringOptions.network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", false); - monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", "__.*"); - monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", ""); + monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; + monitoringOptions.network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", EXP_NETWORK_MONITORING_DISABLED); + monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); + monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", MON_FILTER_INCL); monitoringOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); monitoringOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); monitoringOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); - auto& udpMonitoringOptions = monitoringOptions.udp_options; + // auto& udpMonitoringOptions = monitoringOptions.udp_options; // TODO: Nothing here yet auto& shmMonitoringOptions = monitoringOptions.shm_options; - shmMonitoringOptions.shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", "ecal_monitoring"); - shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", 1024); + shmMonitoringOptions.shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", EXP_SHM_MONITORING_DOMAIN); + shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", EXP_SHM_MONITORING_QUEUE_SIZE); // receiving options auto& receivingOptions = config.receiving_options; - receivingOptions.shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", true); - receivingOptions.tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", true); - receivingOptions.udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", true); + receivingOptions.shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED); + receivingOptions.tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED); + receivingOptions.udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", NET_UDP_MC_REC_ENABLED); // publisher options auto& publisherOptions = config.publisher_options; - publisherOptions.use_inproc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_inproc", 0)); - publisherOptions.use_shm = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_shm", 0)); - publisherOptions.use_tcp = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_tcp", 0)); - publisherOptions.use_udp_mc = TLayer::eSendMode(iniConfig.get(PUBLISHER, "use_udp_mc", 0)); + publisherOptions.use_shm = static_cast(iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM))); + publisherOptions.use_tcp = static_cast(iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP))); + publisherOptions.use_udp_mc = static_cast(iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC))); // timesync options auto& timesyncOptions = config.timesync_options; - timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", ""); + timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", TIME_SYNC_MODULE); // service options auto& serviceOptions = config.service_options; - serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", 1) != 0; - serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", 1) != 0; + serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", SERVICE_PROTOCOL_V0); + serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", SERVICE_PROTOCOL_V1); // sys options auto& sysOptions = config.application_options.sys_options; - sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"); // default different than ini file + sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); // process options auto& processOptions = config.application_options.process_options; - processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", ""); + processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); return config; }; diff --git a/ecal/core/src/config/ecal_config_reader.cpp b/ecal/core/src/config/ecal_config_reader.cpp index 78c64369c8..6eac24055f 100644 --- a/ecal/core/src/config/ecal_config_reader.cpp +++ b/ecal/core/src/config/ecal_config_reader.cpp @@ -408,6 +408,16 @@ namespace eCAL return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); } + unsigned int CConfig::get(const std::string& section_, const std::string& key_, unsigned int default_) + { + return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); + } + + size_t CConfig::get(const std::string& section_, const std::string& key_, size_t default_) + { + return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); + } + double CConfig::get(const std::string& section_, const std::string& key_, double default_) { return m_impl->GetDoubleValue(section_.c_str(), key_.c_str(), default_); diff --git a/ecal/core/src/config/ecal_config_reader.h b/ecal/core/src/config/ecal_config_reader.h index ab5d13ae4c..fdd9b5809c 100644 --- a/ecal/core/src/config/ecal_config_reader.h +++ b/ecal/core/src/config/ecal_config_reader.h @@ -44,10 +44,12 @@ namespace eCAL bool Validate(); // common getter - bool get(const std::string& section_, const std::string& key_, bool default_); - int get(const std::string& section_, const std::string& key_, int default_); - double get(const std::string& section_, const std::string& key_, double default_); - std::string get(const std::string& section_, const std::string& key_, const char* default_); + bool get(const std::string& section_, const std::string& key_, bool default_); + int get(const std::string& section_, const std::string& key_, int default_); + double get(const std::string& section_, const std::string& key_, double default_); + std::string get(const std::string& section_, const std::string& key_, const char* default_); + unsigned int get(const std::string& section_, const std::string& key_, unsigned int default_); + size_t get(const std::string& section_, const std::string& key_, size_t default_); private: std::unique_ptr m_impl; diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index e2f7761c2e..59401262c1 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -59,7 +59,7 @@ constexpr eCAL_Logging_Filter MON_LOG_FILTER_UDP = (log_level_info | log_level_ /* sys settings */ /**********************************************************************************************/ /* sys app witch will not be imported from cloud */ -constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"; +constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$"; /**********************************************************************************************/ /* network settings */ From 94f91aeeced738043c66e93d786f5ef6c8ccbc7a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:35:07 +0100 Subject: [PATCH 016/105] Moved IpAddressV4 definitions to private space. --- ecal/core/CMakeLists.txt | 1 + .../include/ecal/types/ecal_config_types.h | 3 +- .../ecal/types/ecal_custom_data_types.h | 52 +++++++--------- .../ecal/types/ecal_transport_layer_options.h | 4 +- .../src/config/ecal_config_initializer.cpp | 2 +- .../core/src/types/ecal_custom_data_types.cpp | 61 +++++++++++++++++++ 6 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 ecal/core/src/types/ecal_custom_data_types.cpp diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 2b81ab1946..795320542e 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -60,6 +60,7 @@ set(ecal_config_src src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h src/config/ecal_config_initializer.cpp + src/types/ecal_custom_data_types.cpp ) ###################################### diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 39ccf7c0a8..06840e0eb8 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -49,7 +49,6 @@ namespace eCAL { struct eCALConfig { - public: TransportLayerOptions transport_layer_options; RegistrationOptions registration_options; MonitoringOptions monitoring_options; @@ -60,8 +59,8 @@ namespace eCAL ApplicationOptions application_options; std::string loaded_ecal_ini_file; - eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; eCALConfig(); + eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; }; ECAL_API eCALConfig* GetCurrentConfig(); diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index e39d98fe6e..05d722f222 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -32,45 +32,35 @@ namespace eCAL { namespace Config { + /** + * @brief Class for evaluation and storing IP addresses. + * + * @param ip_adress_ The IP address as std::string. + **/ class IpAddressV4 { public: IpAddressV4() = default; - IpAddressV4(const std::string ip_address_) - { - if (checkIpString(ip_address_)) - { - m_ip_address = ip_address_; - } - else - { - std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; - } - } - + IpAddressV4(const std::string ip_address_); + const std::string get() { return m_ip_address; } private: - static bool checkIpString(std::string ip_address_) - { - if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) - { - return true; - } - else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) - { - return true; - } - else - { - return false; - } - } - - std::string m_ip_address; + static bool checkIpString(std::string ip_address_); + + std::string m_ip_address{}; }; - template::max()> + /** + * @brief Template class to specify sizes with a concrete minimum, maximum and step size definition. + * + * @tparam MIN Optional minimum possible size. Default: 0 + * @tparam STEP Optional step size. Default: 1 + * @tparam MAX Optional maximum possible size. Default: std::numeric_limits::max() + * + * @param size_ Optional size value. If not set, LimitSize::get() will return the MIN value. + **/ + template::max()> class LimitSize { public: @@ -90,7 +80,7 @@ namespace eCAL private: int m_size_min = MIN; - long long m_size_max = MAX; + int m_size_max = MAX; int m_size_step = STEP; int m_size = MIN; diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 09e3e85830..0b92144423 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -65,8 +65,8 @@ namespace eCAL struct TransportLayerOptions { - bool network_enabled = false; - bool drop_out_of_order_messages = false; + bool network_enabled; + bool drop_out_of_order_messages; UdpMulticastOptions mc_options; TCPubsubOptions tcp_options; SHMOptions shm_options; diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 86a9f598e7..6a604d199c 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -18,7 +18,7 @@ */ /** - * @brief Functions for setting default config values + * @brief Function definitions for setting default config values **/ #include "ecal/types/ecal_config_types.h" diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp new file mode 100644 index 0000000000..f77f847fb8 --- /dev/null +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -0,0 +1,61 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 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 ================================= +*/ + +/** + * @brief Definition of custom data types. +**/ + +#include "ecal/types/ecal_custom_data_types.h" + +namespace eCAL +{ + namespace Config + { + + // IpAddressV4 definitions + + IpAddressV4::IpAddressV4(const std::string ip_address_) + { + if (checkIpString(ip_address_)) + { + m_ip_address = ip_address_; + } + else + { + std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; + } + } + + bool IpAddressV4::checkIpString(std::string ip_address_) + { + if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) + { + return true; + } + else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) + { + return true; + } + else + { + return false; + } + } + } +} From b196ab464df0fa22f5562bf69b55e94e03ca9069 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:51:31 +0100 Subject: [PATCH 017/105] Removed unused fields. --- ecal/core/include/ecal/types/ecal_internal_options.h | 3 +-- ecal/core/include/ecal/types/ecal_publisher_options.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_internal_options.h b/ecal/core/include/ecal/types/ecal_internal_options.h index 8c5c21910c..abdbf7e92e 100644 --- a/ecal/core/include/ecal/types/ecal_internal_options.h +++ b/ecal/core/include/ecal/types/ecal_internal_options.h @@ -56,8 +56,7 @@ namespace eCAL struct eCAL_UDP_MC_Publisher_Options { - long max_bandwidth; // rausschmeissen - // should we go as far as to put the MC address here? + }; struct eCAL_TCP_Publisher_Options diff --git a/ecal/core/include/ecal/types/ecal_publisher_options.h b/ecal/core/include/ecal/types/ecal_publisher_options.h index 774dc2f285..fb6f3b0b2c 100644 --- a/ecal/core/include/ecal/types/ecal_publisher_options.h +++ b/ecal/core/include/ecal/types/ecal_publisher_options.h @@ -32,7 +32,6 @@ namespace eCAL { struct PublisherOptions { - TLayer::eSendMode use_inproc; TLayer::eSendMode use_shm; TLayer::eSendMode use_tcp; TLayer::eSendMode use_udp_mc; From afe2332844bcb3bbc64d6ce26a39575a029c3a2b Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:20:03 +0100 Subject: [PATCH 018/105] Fixed some GH actions compiling issues. --- .../include/ecal/types/ecal_config_types.h | 2 +- .../ecal/types/ecal_internal_options.h | 6 +-- .../ecal/types/ecal_registration_options.h | 4 +- ecal/core/src/ecal_def.h | 48 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 06840e0eb8..1a29999678 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -60,7 +60,7 @@ namespace eCAL std::string loaded_ecal_ini_file; eCALConfig(); - eCALConfig(const eCALConfig& ecal_config) { *this = ecal_config; }; + // eCALConfig& operator=(const eCALConfig& ecal_config) { *this = ecal_config; }; }; ECAL_API eCALConfig* GetCurrentConfig(); diff --git a/ecal/core/include/ecal/types/ecal_internal_options.h b/ecal/core/include/ecal/types/ecal_internal_options.h index abdbf7e92e..39f38a5127 100644 --- a/ecal/core/include/ecal/types/ecal_internal_options.h +++ b/ecal/core/include/ecal/types/ecal_internal_options.h @@ -67,10 +67,10 @@ namespace eCAL struct eCAL_SHM_Publisher_Options { - bool enable_zero_copy = false; + bool enable_zero_copy; - long buffer_count = 1; // 1 .. x - long long acknowledge_timeout_ms = -1; // -1 -> no timeout (or directly std::chrono? + long buffer_count; // 1 .. x + long long acknowledge_timeout_ms; // -1 -> no timeout (or directly std::chrono? // should we go as far as to put the memory filename (base) here? - No // however, part of it will be communicated via the registration layer, invisible to the user diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h index 0d2af7f973..be2c95b77d 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -55,8 +55,8 @@ namespace eCAL bool share_tdesc = true; private: - unsigned int registration_timeout = unsigned int(60000); - unsigned int registration_refresh = unsigned int(1000); + unsigned int registration_timeout = 60000U; + unsigned int registration_refresh = 1000U; }; } } \ No newline at end of file diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 59401262c1..42534d8f35 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -71,17 +71,17 @@ constexpr bool NET_ENABLED = false; constexpr eCAL::Config::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = eCAL::Config::UdpConfigVersion::V1; constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; -constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; -constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; -constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; -constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; -constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; -constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ -constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000U; +constexpr unsigned int NET_UDP_MULTICAST_TTL = 3U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2U; +constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5U*1024U*1024U); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5U*1024U*1024U); /* 5 MByte */ constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; -constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000; /* ms */ -constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000U; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10U; /* ms */ /* overall udp multicast bandwidth limitation in bytes/s, -1 == no limitation*/ constexpr int NET_BANDWIDTH_MAX_UDP = (-1); @@ -93,9 +93,9 @@ constexpr bool NET_UDP_MC_REC_ENABLED = true; constexpr bool NET_NPCAP_ENABLED = false; -constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4; -constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4; -constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4U; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4U; +constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5U; /* common host group name that enables interprocess mechanisms across (virtual) host borders (e.g, Docker); by default equivalent to local host name */ constexpr char NET_HOST_GROUP_NAME[] = ""; @@ -116,16 +116,16 @@ constexpr bool PUB_SHARE_TTYPE = true; constexpr bool PUB_SHARE_TDESC = true; /* minimum size for created shared memory files */ -constexpr unsigned int PUB_MEMFILE_MINSIZE = (4*1024); +constexpr unsigned int PUB_MEMFILE_MINSIZE = (4U*1024U); /* reserve buffer size before reallocation in % */ -constexpr unsigned int PUB_MEMFILE_RESERVE = 50; +constexpr unsigned int PUB_MEMFILE_RESERVE = 50U; /* timeout for create / open a memory file using mutex lock in ms */ -constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200; -constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200; +constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200U; +constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200U; /* timeout for memory read acknowledge signal from data reader in ms */ -constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ +constexpr unsigned int PUB_MEMFILE_ACK_TO = 0U; /* ms */ /* defines number of memory files handle by the publisher for a 1:n connection a higher number will increase data throughput, but will also increase the size of used memory, number of semaphores @@ -133,7 +133,7 @@ constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ higher values than 3 are not recommended values > 1 will break local IPC compatibility to eCAL 5.9 and older */ -constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1; +constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1U; /* allow subscriber to access memory file without copying content in advance (zero copy) this memory file is blocked for other readers wihle processed by the user callback function @@ -166,16 +166,16 @@ constexpr char PROCESS_TERMINAL_EMULATOR[] = ""; /* ecal internal timings */ /**********************************************************************************************/ /* timeout for automatic removing registered topics and memory files in global database in ms */ -constexpr unsigned int CMN_REGISTRATION_TO = (60*1000); +constexpr unsigned int CMN_REGISTRATION_TO = (60U*1000U); /* time for resend registration info from publisher/subscriber in ms */ -constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000; +constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000U; /* delta time to check timeout for data readers in ms */ -constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100; +constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100U; /* cylce time udp receive threads in ms */ -constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000; +constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000U; /**********************************************************************************************/ /* events */ @@ -191,11 +191,11 @@ constexpr bool EXP_SHM_MONITORING_ENABLED = false; /* disable distribution of monitoring/registration information via network (default) */ constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; /* queue size of monitoring/registration events */ -constexpr size_t EXP_SHM_MONITORING_QUEUE_SIZE = 1024; +constexpr size_t EXP_SHM_MONITORING_QUEUE_SIZE = 1024U; /* domain name for shared memory based monitoring/registration */ constexpr char EXP_SHM_MONITORING_DOMAIN[] = "ecal_monitoring"; /* memory file access timeout */ -constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100; +constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100U; /* enable dropping of payload messages that arrive out of order */ constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; From 4887b02a9df606e24ffbf26e38a550f1baa759f6 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:23:24 +0100 Subject: [PATCH 019/105] Removed unnecessary comments in header files. --- ecal/core/include/ecal/types/ecal_config_types.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 1a29999678..d375b595f6 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -60,7 +60,6 @@ namespace eCAL std::string loaded_ecal_ini_file; eCALConfig(); - // eCALConfig& operator=(const eCALConfig& ecal_config) { *this = ecal_config; }; }; ECAL_API eCALConfig* GetCurrentConfig(); From c768ba9da352768166917484bc8a4d953cf1cbad Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:53:42 +0200 Subject: [PATCH 020/105] Changed #include to correct header. --- ecal/core/include/ecal/types/ecal_config_types.h | 1 - ecal/core/include/ecal/types/ecal_custom_data_types.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index d375b595f6..57e642d7f7 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -41,7 +41,6 @@ #include #include #include -#include namespace eCAL { diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 05d722f222..cec2898e92 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace eCAL { From b4690a09621b8e4d01486124021997b967b3db83 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:00:39 +0200 Subject: [PATCH 021/105] Some updates regarding new configuration management to ecal_core. --- CMakePresets.json | 1 + ecal/core/cfg/ecal.ini | 4 ++-- ecal/core/include/ecal/types/ecal_monitoring_options.h | 2 +- ecal/core/src/config/ecal_config_initializer.cpp | 4 ++-- ecal/core/src/ecal_def.h | 5 ++--- ecal/core/src/ecal_process.cpp | 5 +++-- ecal/core/src/registration/ecal_registration_provider.cpp | 5 ++--- ecal/core/src/registration/ecal_registration_receiver.cpp | 4 ++-- .../core/src/registration/ecal_registration_receiver_shm.cpp | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index d983a2c137..afadd2defc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -89,6 +89,7 @@ "HAS_CURL": "ON", "HAS_FTXUI": "ON", "BUILD_APPS": "ON", + "BUILD_SAMPLES": "ON", "ECAL_THIRDPARTY_BUILD_FINEFTP": "ON", "ECAL_THIRDPARTY_BUILD_FTXUI": "ON", "ECAL_THIRDPARTY_BUILD_SPDLOG": "ON", diff --git a/ecal/core/cfg/ecal.ini b/ecal/core/cfg/ecal.ini index f474579552..1fb5a73896 100644 --- a/ecal/core/cfg/ecal.ini +++ b/ecal/core/cfg/ecal.ini @@ -178,7 +178,7 @@ filter_excl = ^eCALSysClient$|^eCALSysGUI$|^eCALSys$ ; shm_monitoring_enabled = false Enable distribution of monitoring/registration information via shared memory ; shm_monitoring_domain = ecal_monitoring Domain name for shared memory based monitoring/registration ; shm_monitoring_queue_size = 1024 Queue size of monitoring/registration events -; network_monitoring_disabled = false Disable distribution of monitoring/registration information via network +; network_monitoring_enabled = true Enable distribution of monitoring/registration information via network ; ; drop_out_of_order_messages = false Enable dropping of payload messages that arrive out of order ; -------------------------------------------------- @@ -186,5 +186,5 @@ filter_excl = ^eCALSysClient$|^eCALSysGUI$|^eCALSys$ shm_monitoring_enabled = false shm_monitoring_domain = ecal_mon shm_monitoring_queue_size = 1024 -network_monitoring_disabled = false +network_monitoring_enabled = true drop_out_of_order_messages = false diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index 46236215d7..b3f3ccbd62 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -56,7 +56,7 @@ namespace eCAL { eCAL_MonitoringMode_Filter monitoring_mode; LimitSize<1000, 1000> monitoring_timeout; - bool network_monitoring_disabled; + bool network_monitoring; UDPMonitoringOptions udp_options; SHMMonitoringOptions shm_options; diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 6a604d199c..d92d857793 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -137,7 +137,7 @@ namespace eCAL auto& monitoringOptions = config.monitoring_options; monitoringOptions.monitoring_mode = EXP_MONITORING_MODE; monitoringOptions.monitoring_timeout = MON_TIMEOUT; - monitoringOptions.network_monitoring_disabled = EXP_NETWORK_MONITORING_DISABLED; + monitoringOptions.network_monitoring = EXP_NETWORK_MONITORING_ENABLED; monitoringOptions.filter_excl = MON_FILTER_EXCL; monitoringOptions.filter_incl = MON_FILTER_INCL; monitoringOptions.filter_log_con = MON_LOG_FILTER_CON; @@ -238,7 +238,7 @@ namespace eCAL auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; monitoringOptions.monitoring_mode = monitoringMode; monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; - monitoringOptions.network_monitoring_disabled = iniConfig.get(EXPERIMENTAL, "network_monitoring_disabled", EXP_NETWORK_MONITORING_DISABLED); + monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", MON_FILTER_INCL); monitoringOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 496e47ba33..cc2df2570b 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -74,7 +74,6 @@ constexpr char NET_UDP_MULTICAST_MASK[] = "0.0 constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000U; constexpr unsigned int NET_UDP_MULTICAST_TTL = 3U; constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0U; -constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1U; constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2U; constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 4U; constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5U*1024U*1024U); /* 5 MByte */ @@ -189,8 +188,8 @@ constexpr char EVENT_SHUTDOWN_PROC[] = "ecal_shutdown_pro /**********************************************************************************************/ /* enable distribution of monitoring/registration information via shared memory */ constexpr bool EXP_SHM_MONITORING_ENABLED = false; -/* disable distribution of monitoring/registration information via network (default) */ -constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; +/* enable distribution of monitoring/registration information via network (default) */ +constexpr bool EXP_NETWORK_MONITORING_ENABLED = true; /* queue size of monitoring/registration events */ constexpr size_t EXP_SHM_MONITORING_QUEUE_SIZE = 1024U; /* domain name for shared memory based monitoring/registration */ diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index bec74b5b38..372b3223ef 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -35,6 +35,7 @@ #include "config/ecal_config_reader_hlp.h" #include "io/udp/ecal_udp_configurations.h" +#include "ecal/types/ecal_config_types.h" #include #include @@ -211,7 +212,7 @@ namespace eCAL #if ECAL_CORE_SUBSCRIBER sstream << "------------------------- SUBSCRIPTION LAYER DEFAULTS ------------" << '\n'; sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig()->receiving_options.udp_mc_recv_enabled) << '\n'; - sstream << "Drop out-of-order msgs : " << (Config::Experimental::GetDropOutOfOrderMessages() ? "on" : "off") << '\n'; + sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig()->transport_layer_options.drop_out_of_order_messages ? "on" : "off") << '\n'; #endif #ifdef ECAL_NPCAP_SUPPORT if(Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled && !Udpcap::Initialize()) @@ -249,7 +250,7 @@ namespace eCAL std::string GetHostGroupName() { - return Config::GetHostGroupName().empty() ? GetHostName() : Config::GetHostGroupName(); + return Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name.empty() ? GetHostName() : Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name; } std::string GetUnitName() diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 4541657931..12f38d7712 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -63,9 +63,8 @@ namespace eCAL if(m_created) return; // send registration to shared memory and to udp - // TODO PG: Check for new config - m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled(); - m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled(); + m_use_registration_udp = Config::GetCurrentConfig()->monitoring_options.network_monitoring; + m_use_registration_shm = (Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; if (m_use_registration_udp) { diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index f12e265373..f38746ab36 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -74,8 +74,8 @@ namespace eCAL // receive registration from shared memory and or udp // TODO PG: Adapt to new config management - m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled(); - m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled(); + m_use_registration_udp = Config::GetCurrentConfig()->monitoring_options.network_monitoring; + m_use_registration_shm = (Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; if (m_use_registration_udp) { diff --git a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp index 7ac78263cf..561874445d 100644 --- a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp @@ -51,7 +51,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs()/2)); + m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetCurrentConfig()->registration_options.getRefreshMS()/2)); m_created = true; } From 4694927290b2ce0914ab6f3f34fafa8dd231bbcc Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:08:16 +0200 Subject: [PATCH 022/105] Updated submodules --- thirdparty/asio/asio | 2 +- thirdparty/curl/curl | 2 +- thirdparty/fineftp/fineftp-server | 2 +- thirdparty/ftxui/ftxui | 2 +- thirdparty/gtest/googletest | 2 +- thirdparty/hdf5/hdf5 | 2 +- thirdparty/libssh2/libssh2 | 2 +- thirdparty/protobuf/protobuf | 2 +- thirdparty/qwt/qwt | 2 +- thirdparty/recycle/recycle | 2 +- thirdparty/simpleini/simpleini | 2 +- thirdparty/spdlog/spdlog | 2 +- thirdparty/tcp_pubsub/tcp_pubsub | 2 +- thirdparty/tinyxml2/tinyxml2 | 2 +- thirdparty/udpcap/udpcap | 2 +- thirdparty/yaml-cpp/yaml-cpp | 2 +- thirdparty/zlib/zlib | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/thirdparty/asio/asio b/thirdparty/asio/asio index 147f7225a9..ed5db1b501 160000 --- a/thirdparty/asio/asio +++ b/thirdparty/asio/asio @@ -1 +1 @@ -Subproject commit 147f7225a96d45a2807a64e443177f621844e51c +Subproject commit ed5db1b50136bace796062c1a6eab0df9a74f8fa diff --git a/thirdparty/curl/curl b/thirdparty/curl/curl index 801bd5138c..df3d5ef25e 160000 --- a/thirdparty/curl/curl +++ b/thirdparty/curl/curl @@ -1 +1 @@ -Subproject commit 801bd5138ce31aa0d906fa4e2eabfc599d74e793 +Subproject commit df3d5ef25e3d5df8a0a2cadf3914b8861e5af3e5 diff --git a/thirdparty/fineftp/fineftp-server b/thirdparty/fineftp/fineftp-server index 7ed82e4503..3668eda2b2 160000 --- a/thirdparty/fineftp/fineftp-server +++ b/thirdparty/fineftp/fineftp-server @@ -1 +1 @@ -Subproject commit 7ed82e4503c90faeacb7b98e10bc07304adc78d6 +Subproject commit 3668eda2b27bbf9e4f66b049f4e22b16e8482489 diff --git a/thirdparty/ftxui/ftxui b/thirdparty/ftxui/ftxui index d301fab1f4..f609c12846 160000 --- a/thirdparty/ftxui/ftxui +++ b/thirdparty/ftxui/ftxui @@ -1 +1 @@ -Subproject commit d301fab1f4ecdd3544ed99b9c98e647d5804c341 +Subproject commit f609c128461e0a51762152f6883e316dafb26c79 diff --git a/thirdparty/gtest/googletest b/thirdparty/gtest/googletest index e2239ee604..a2f106c7e2 160000 --- a/thirdparty/gtest/googletest +++ b/thirdparty/gtest/googletest @@ -1 +1 @@ -Subproject commit e2239ee6043f73722e7aa812a459f54a28552929 +Subproject commit a2f106c7e262be997b147b09d32e254eb336f071 diff --git a/thirdparty/hdf5/hdf5 b/thirdparty/hdf5/hdf5 index 55565382d2..c6e26a1da9 160000 --- a/thirdparty/hdf5/hdf5 +++ b/thirdparty/hdf5/hdf5 @@ -1 +1 @@ -Subproject commit 55565382d2a6ae444ec5bc039f83b6b3bfb6730c +Subproject commit c6e26a1da9b39c17bdb4550c5c72dd5efbeb4666 diff --git a/thirdparty/libssh2/libssh2 b/thirdparty/libssh2/libssh2 index 159d4c8138..43983f8709 160000 --- a/thirdparty/libssh2/libssh2 +++ b/thirdparty/libssh2/libssh2 @@ -1 +1 @@ -Subproject commit 159d4c813809238ed96c65e1ea01e7d0c0b375a5 +Subproject commit 43983f870921edc90c337d739ccd4e627e56ea99 diff --git a/thirdparty/protobuf/protobuf b/thirdparty/protobuf/protobuf index d0bfd52211..dc5053acc4 160000 --- a/thirdparty/protobuf/protobuf +++ b/thirdparty/protobuf/protobuf @@ -1 +1 @@ -Subproject commit d0bfd5221182da1a7cc280f3337b5e41a89539cf +Subproject commit dc5053acc44d16c0a10d5ba3130476bdfcc43dcc diff --git a/thirdparty/qwt/qwt b/thirdparty/qwt/qwt index 6dc6c146c0..2cb8a3cf39 160000 --- a/thirdparty/qwt/qwt +++ b/thirdparty/qwt/qwt @@ -1 +1 @@ -Subproject commit 6dc6c146c0e9ef2b51f4001e787702bacb729002 +Subproject commit 2cb8a3cf394fae85a4272da73cab6f7206263f70 diff --git a/thirdparty/recycle/recycle b/thirdparty/recycle/recycle index c5425709b2..a20d211776 160000 --- a/thirdparty/recycle/recycle +++ b/thirdparty/recycle/recycle @@ -1 +1 @@ -Subproject commit c5425709b2273ef6371647247d1a1d86aa75c2e6 +Subproject commit a20d211776e30edd64a49d21157a522424352980 diff --git a/thirdparty/simpleini/simpleini b/thirdparty/simpleini/simpleini index 9b3ed7ec81..f7862c3dd7 160000 --- a/thirdparty/simpleini/simpleini +++ b/thirdparty/simpleini/simpleini @@ -1 +1 @@ -Subproject commit 9b3ed7ec815997bc8c5b9edf140d6bde653e1458 +Subproject commit f7862c3dd7ad35becc2741f268e3402e89a37666 diff --git a/thirdparty/spdlog/spdlog b/thirdparty/spdlog/spdlog index 7e635fca68..8fed530bdf 160000 --- a/thirdparty/spdlog/spdlog +++ b/thirdparty/spdlog/spdlog @@ -1 +1 @@ -Subproject commit 7e635fca68d014934b4af8a1cf874f63989352b7 +Subproject commit 8fed530bdffbe69304a330be2096c65793b722c2 diff --git a/thirdparty/tcp_pubsub/tcp_pubsub b/thirdparty/tcp_pubsub/tcp_pubsub index f59da789dd..b0393e4895 160000 --- a/thirdparty/tcp_pubsub/tcp_pubsub +++ b/thirdparty/tcp_pubsub/tcp_pubsub @@ -1 +1 @@ -Subproject commit f59da789dd11d2ceec7a4d89894053b141caf72d +Subproject commit b0393e4895164c2e2ea7e9e62198e07b98cb78bd diff --git a/thirdparty/tinyxml2/tinyxml2 b/thirdparty/tinyxml2/tinyxml2 index 1dee28e51f..321ea883b7 160000 --- a/thirdparty/tinyxml2/tinyxml2 +++ b/thirdparty/tinyxml2/tinyxml2 @@ -1 +1 @@ -Subproject commit 1dee28e51f9175a31955b9791c74c430fe13dc82 +Subproject commit 321ea883b7190d4e85cae5512a12e5eaa8f8731f diff --git a/thirdparty/udpcap/udpcap b/thirdparty/udpcap/udpcap index 07bede4143..6b7622c6ba 160000 --- a/thirdparty/udpcap/udpcap +++ b/thirdparty/udpcap/udpcap @@ -1 +1 @@ -Subproject commit 07bede4143912f26e5a52e9ef5ac98341fb1f53b +Subproject commit 6b7622c6ba51ddbbedd89b07e1b61d515a52d718 diff --git a/thirdparty/yaml-cpp/yaml-cpp b/thirdparty/yaml-cpp/yaml-cpp index c73ee34704..76dc671573 160000 --- a/thirdparty/yaml-cpp/yaml-cpp +++ b/thirdparty/yaml-cpp/yaml-cpp @@ -1 +1 @@ -Subproject commit c73ee34704c512ebe915b283645aefa9f424a22f +Subproject commit 76dc6715734295ff1866bfc32872ff2278258fc8 diff --git a/thirdparty/zlib/zlib b/thirdparty/zlib/zlib index cacf7f1d4e..0f51fb4933 160000 --- a/thirdparty/zlib/zlib +++ b/thirdparty/zlib/zlib @@ -1 +1 @@ -Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f +Subproject commit 0f51fb4933fc9ce18199cb2554dacea8033e7fd3 From 388f5bcda57b61ad370bef123f65c4dd3aa217e9 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:22:56 +0200 Subject: [PATCH 023/105] Checked out versions of thirdparty modules equal to master branch. --- thirdparty/asio/asio | 2 +- thirdparty/curl/curl | 2 +- thirdparty/ftxui/ftxui | 2 +- thirdparty/gtest/googletest | 2 +- thirdparty/hdf5/hdf5 | 2 +- thirdparty/libssh2/libssh2 | 2 +- thirdparty/protobuf/protobuf | 2 +- thirdparty/qwt/qwt | 2 +- thirdparty/recycle/recycle | 2 +- thirdparty/simpleini/simpleini | 2 +- thirdparty/spdlog/spdlog | 2 +- thirdparty/tinyxml2/tinyxml2 | 2 +- thirdparty/udpcap/udpcap | 2 +- thirdparty/yaml-cpp/yaml-cpp | 2 +- thirdparty/zlib/zlib | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/thirdparty/asio/asio b/thirdparty/asio/asio index ed5db1b501..147f7225a9 160000 --- a/thirdparty/asio/asio +++ b/thirdparty/asio/asio @@ -1 +1 @@ -Subproject commit ed5db1b50136bace796062c1a6eab0df9a74f8fa +Subproject commit 147f7225a96d45a2807a64e443177f621844e51c diff --git a/thirdparty/curl/curl b/thirdparty/curl/curl index df3d5ef25e..801bd5138c 160000 --- a/thirdparty/curl/curl +++ b/thirdparty/curl/curl @@ -1 +1 @@ -Subproject commit df3d5ef25e3d5df8a0a2cadf3914b8861e5af3e5 +Subproject commit 801bd5138ce31aa0d906fa4e2eabfc599d74e793 diff --git a/thirdparty/ftxui/ftxui b/thirdparty/ftxui/ftxui index f609c12846..d301fab1f4 160000 --- a/thirdparty/ftxui/ftxui +++ b/thirdparty/ftxui/ftxui @@ -1 +1 @@ -Subproject commit f609c128461e0a51762152f6883e316dafb26c79 +Subproject commit d301fab1f4ecdd3544ed99b9c98e647d5804c341 diff --git a/thirdparty/gtest/googletest b/thirdparty/gtest/googletest index a2f106c7e2..f8d7d77c06 160000 --- a/thirdparty/gtest/googletest +++ b/thirdparty/gtest/googletest @@ -1 +1 @@ -Subproject commit a2f106c7e262be997b147b09d32e254eb336f071 +Subproject commit f8d7d77c06936315286eb55f8de22cd23c188571 diff --git a/thirdparty/hdf5/hdf5 b/thirdparty/hdf5/hdf5 index c6e26a1da9..55565382d2 160000 --- a/thirdparty/hdf5/hdf5 +++ b/thirdparty/hdf5/hdf5 @@ -1 +1 @@ -Subproject commit c6e26a1da9b39c17bdb4550c5c72dd5efbeb4666 +Subproject commit 55565382d2a6ae444ec5bc039f83b6b3bfb6730c diff --git a/thirdparty/libssh2/libssh2 b/thirdparty/libssh2/libssh2 index 43983f8709..159d4c8138 160000 --- a/thirdparty/libssh2/libssh2 +++ b/thirdparty/libssh2/libssh2 @@ -1 +1 @@ -Subproject commit 43983f870921edc90c337d739ccd4e627e56ea99 +Subproject commit 159d4c813809238ed96c65e1ea01e7d0c0b375a5 diff --git a/thirdparty/protobuf/protobuf b/thirdparty/protobuf/protobuf index dc5053acc4..d0bfd52211 160000 --- a/thirdparty/protobuf/protobuf +++ b/thirdparty/protobuf/protobuf @@ -1 +1 @@ -Subproject commit dc5053acc44d16c0a10d5ba3130476bdfcc43dcc +Subproject commit d0bfd5221182da1a7cc280f3337b5e41a89539cf diff --git a/thirdparty/qwt/qwt b/thirdparty/qwt/qwt index 2cb8a3cf39..6dc6c146c0 160000 --- a/thirdparty/qwt/qwt +++ b/thirdparty/qwt/qwt @@ -1 +1 @@ -Subproject commit 2cb8a3cf394fae85a4272da73cab6f7206263f70 +Subproject commit 6dc6c146c0e9ef2b51f4001e787702bacb729002 diff --git a/thirdparty/recycle/recycle b/thirdparty/recycle/recycle index a20d211776..c5425709b2 160000 --- a/thirdparty/recycle/recycle +++ b/thirdparty/recycle/recycle @@ -1 +1 @@ -Subproject commit a20d211776e30edd64a49d21157a522424352980 +Subproject commit c5425709b2273ef6371647247d1a1d86aa75c2e6 diff --git a/thirdparty/simpleini/simpleini b/thirdparty/simpleini/simpleini index f7862c3dd7..9b3ed7ec81 160000 --- a/thirdparty/simpleini/simpleini +++ b/thirdparty/simpleini/simpleini @@ -1 +1 @@ -Subproject commit f7862c3dd7ad35becc2741f268e3402e89a37666 +Subproject commit 9b3ed7ec815997bc8c5b9edf140d6bde653e1458 diff --git a/thirdparty/spdlog/spdlog b/thirdparty/spdlog/spdlog index 8fed530bdf..7e635fca68 160000 --- a/thirdparty/spdlog/spdlog +++ b/thirdparty/spdlog/spdlog @@ -1 +1 @@ -Subproject commit 8fed530bdffbe69304a330be2096c65793b722c2 +Subproject commit 7e635fca68d014934b4af8a1cf874f63989352b7 diff --git a/thirdparty/tinyxml2/tinyxml2 b/thirdparty/tinyxml2/tinyxml2 index 321ea883b7..1dee28e51f 160000 --- a/thirdparty/tinyxml2/tinyxml2 +++ b/thirdparty/tinyxml2/tinyxml2 @@ -1 +1 @@ -Subproject commit 321ea883b7190d4e85cae5512a12e5eaa8f8731f +Subproject commit 1dee28e51f9175a31955b9791c74c430fe13dc82 diff --git a/thirdparty/udpcap/udpcap b/thirdparty/udpcap/udpcap index 6b7622c6ba..da6d758c3c 160000 --- a/thirdparty/udpcap/udpcap +++ b/thirdparty/udpcap/udpcap @@ -1 +1 @@ -Subproject commit 6b7622c6ba51ddbbedd89b07e1b61d515a52d718 +Subproject commit da6d758c3ce368734ad5c1c59ff99e5f0ad27a4e diff --git a/thirdparty/yaml-cpp/yaml-cpp b/thirdparty/yaml-cpp/yaml-cpp index 76dc671573..c73ee34704 160000 --- a/thirdparty/yaml-cpp/yaml-cpp +++ b/thirdparty/yaml-cpp/yaml-cpp @@ -1 +1 @@ -Subproject commit 76dc6715734295ff1866bfc32872ff2278258fc8 +Subproject commit c73ee34704c512ebe915b283645aefa9f424a22f diff --git a/thirdparty/zlib/zlib b/thirdparty/zlib/zlib index 0f51fb4933..cacf7f1d4e 160000 --- a/thirdparty/zlib/zlib +++ b/thirdparty/zlib/zlib @@ -1 +1 @@ -Subproject commit 0f51fb4933fc9ce18199cb2554dacea8033e7fd3 +Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f From 930379525a72a648e6142430aa33d5b8e7c53b49 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:53:01 +0200 Subject: [PATCH 024/105] Implemented termination, when wrong values are assigned to custom data types. --- ecal/core/include/ecal/types/ecal_config_types.h | 2 +- .../include/ecal/types/ecal_custom_data_types.h | 13 +++++-------- .../include/ecal/types/ecal_registration_options.h | 3 ++- ecal/core/src/types/ecal_custom_data_types.cpp | 3 ++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 57e642d7f7..f4a5e7d9b5 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -58,7 +58,7 @@ namespace eCAL ApplicationOptions application_options; std::string loaded_ecal_ini_file; - eCALConfig(); + eCALConfig(const std::vector* config_keys_ = nullptr); }; ECAL_API eCALConfig* GetCurrentConfig(); diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index cec2898e92..3426fd5c27 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -34,7 +34,7 @@ namespace eCAL namespace Config { /** - * @brief Class for evaluation and storing IP addresses. + * @brief Class for evaluation and storing an IP address. * * @param ip_adress_ The IP address as std::string. **/ @@ -67,24 +67,21 @@ namespace eCAL public: LimitSize(int size_ = MIN) { - if (size_ >= m_size_min && size_ <= m_size_max && size_ % m_size_step == 0) + if (size_ >= MIN && size_ <= MAX && size_ % STEP == 0) { m_size = size_; } else { - std::cout << "LimitSize: faulty size configuration or assignment - using minimum size " << m_size_min << std::endl; + std::cerr << "[LimitSize] Faulty size configuration or assignment. MIN: " << MIN << " MAX: " << MAX << " STEP: " << STEP << " VALUE:" << size_ << "\n"; + exit(EXIT_FAILURE); } }; int get() { return m_size; }; private: - int m_size_min = MIN; - int m_size_max = MAX; - int m_size_step = STEP; - - int m_size = MIN; + int m_size; }; enum class UdpConfigVersion diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h index be2c95b77d..6e4005f924 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -44,7 +44,8 @@ namespace eCAL } else { - std::cout << "RegistrationOptions: custom registration refresh >= registration timout. Using default values." << "\n"; + std::cerr << "[RegistrationOptions] Refresh(" << reg_refresh_ << ") >= registration timeout (" << reg_timeout_ << ")." << "\n"; + exit(EXIT_FAILURE); } }; diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index f77f847fb8..c21d26f49c 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -38,7 +38,8 @@ namespace eCAL } else { - std::cout << "IpAddressV4 error: check your IpAddress settings." << std::endl; + std::cerr << "[IpAddressV4] No valid IPv4 address: " << ip_address_ << "\n"; + exit(EXIT_FAILURE); } } From 848c5727d142797655be9d19b04a4d2eaf520228 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:28:32 +0200 Subject: [PATCH 025/105] Changed g_ecal_config() return value (PathWarning) --- ecal/core/src/ecal_global_accessors.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index b580f7ac3b..2a03313819 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -66,9 +66,8 @@ namespace eCAL Config::eCALConfig* g_ecal_config() { - // TODO PG: discuss the priority if (g_globals() == nullptr) return(nullptr); - if (g_globals()->ecal_config() != nullptr) return(g_globals()->ecal_config().get()); + return(g_globals()->ecal_config().get()); } #if ECAL_CORE_MONITORING From 23708146e35f4af49366e02385492a63db0dab99 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:00:29 +0200 Subject: [PATCH 026/105] Added basic configuration tests. --- ecal/tests/CMakeLists.txt | 2 +- ecal/tests/cpp/config_test/CMakeLists.txt | 45 ++++++++++++++ .../tests/cpp/config_test/src/config_test.cpp | 59 +++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 ecal/tests/cpp/config_test/CMakeLists.txt create mode 100644 ecal/tests/cpp/config_test/src/config_test.cpp diff --git a/ecal/tests/CMakeLists.txt b/ecal/tests/CMakeLists.txt index 36a8a7f771..3146a408ec 100644 --- a/ecal/tests/CMakeLists.txt +++ b/ecal/tests/CMakeLists.txt @@ -30,7 +30,7 @@ add_subdirectory(cpp/core_test) - +add_subdirectory(cpp/config_test) add_subdirectory(cpp/event_test) add_subdirectory(cpp/expmap_test) add_subdirectory(cpp/serialization_test) diff --git a/ecal/tests/cpp/config_test/CMakeLists.txt b/ecal/tests/cpp/config_test/CMakeLists.txt new file mode 100644 index 0000000000..5c0ac7e8c0 --- /dev/null +++ b/ecal/tests/cpp/config_test/CMakeLists.txt @@ -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 ================================= + +project(test_config) + +find_package(Threads REQUIRED) +find_package(GTest REQUIRED) + +set(config_test_src + src/config_test.cpp +) + +ecal_add_gtest(${PROJECT_NAME} ${config_test_src}) + +target_include_directories(${PROJECT_NAME} PRIVATE $) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + eCAL::core + Threads::Threads) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) + +ecal_install_gtest(${PROJECT_NAME}) + +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER tests/cpp/config) + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES + ${${PROJECT_NAME}_src} +) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp new file mode 100644 index 0000000000..f05c09c203 --- /dev/null +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -0,0 +1,59 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include +#include + +#include + +template +void SetValue(MEMBER& member, VALUE value) +{ + member = value; +} + +TEST(core_cpp_config, user_config_passing) +{ + eCAL::Config::eCALConfig custom_config; + + custom_config.transport_layer_options.network_enabled = true; + // initialize ecal api with custom config + EXPECT_EQ(0, eCAL::Initialize(0, nullptr, "user_config_passing test", eCAL::Init::Default, &custom_config)); + + // test if created value is accessible, default was false + EXPECT_EQ(true, eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled); + + // finalize eCAL API + EXPECT_EQ(0, eCAL::Finalize()); +} + +TEST(ConfigDeathTest, user_config_death_test) +{ + eCAL::Config::eCALConfig custom_config; + + // Test the IpAddressV4 class with wrong values + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("42")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + + // Test the LimitSize class with wrong values. Default are MIN = 5242880, STEP = 1024 + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.sndbuf, 42), + ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); +} \ No newline at end of file From e20d5103a868e0ad3be6c8cb84987ecc9fd14bd4 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:01:30 +0200 Subject: [PATCH 027/105] Added ECAL_API macro for config calls. --- ecal/core/include/ecal/types/ecal_config_types.h | 2 +- ecal/core/include/ecal/types/ecal_custom_data_types.h | 6 ++++-- ecal/core/src/ecal_globals.cpp | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index f4a5e7d9b5..5fa54f3a77 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -58,7 +58,7 @@ namespace eCAL ApplicationOptions application_options; std::string loaded_ecal_ini_file; - eCALConfig(const std::vector* config_keys_ = nullptr); + ECAL_API eCALConfig(); }; ECAL_API eCALConfig* GetCurrentConfig(); diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 3426fd5c27..550b6ef7c7 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -24,6 +24,8 @@ #pragma once +#include "ecal/ecal_os.h" + #include #include #include @@ -40,9 +42,9 @@ namespace eCAL **/ class IpAddressV4 { - public: + public: IpAddressV4() = default; - IpAddressV4(const std::string ip_address_); + ECAL_API IpAddressV4(const std::string ip_address_); const std::string get() { return m_ip_address; } diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index d6027b8938..1e79b8f0e6 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -61,6 +61,11 @@ namespace eCAL if (ecal_config_instance == nullptr) { ecal_config_instance = std::make_unique(); + + if (config_keys_) + { + // Config key handling here + } } #if ECAL_CORE_REGISTRATION From 7cafa3ee9f9018f7baf7e5ee5c7e92934adf755d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:54:51 +0200 Subject: [PATCH 028/105] Added operator overloading of == for LimitSize(LS), LS == int, LS == unsigned int. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 550b6ef7c7..40f44f425c 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -80,8 +80,14 @@ namespace eCAL } }; - int get() { return m_size; }; - + const int get() const { return m_size; }; + + bool operator==(const LimitSize& other) const { return this->m_size == other.get(); }; + friend bool operator==(const LimitSize& lhs, const int& rhs) { return lhs.get() == rhs; }; + friend bool operator==(const int& lhs, const LimitSize& rhs) { return rhs == lhs; }; + friend bool operator==(const LimitSize& lhs, const unsigned int& rhs) { return lhs.get() == static_cast(rhs); }; + friend bool operator==(const unsigned int& lhs, const LimitSize& rhs) { return rhs == lhs; }; + private: int m_size; }; From a6936d140084065610137473f155c555b3ed7be2 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:00:54 +0200 Subject: [PATCH 029/105] Fixed warnings because of implicit types conversions by implementing a static_cast in config_initializer and ecal_reader_tcp --- ecal/core/src/config/ecal_config_initializer.cpp | 2 +- ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index d92d857793..fcf50e905a 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -236,7 +236,7 @@ namespace eCAL // monitoring options auto& monitoringOptions = config.monitoring_options; auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; - monitoringOptions.monitoring_mode = monitoringMode; + monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp index 3289186352..aa46444569 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp @@ -76,7 +76,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::GetCurrentConfig()->transport_layer_options.tcp_options.max_reconnections); + m_subscriber->addSession(host_name_, port_, static_cast(Config::GetCurrentConfig()->transport_layer_options.tcp_options.max_reconnections)); if (!m_callback_active) { m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1)); From ca428d17f5473773b42baa446a6b263732f1fc39 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:01:40 +0200 Subject: [PATCH 030/105] Created deathtests and more type tests for configuration tests. --- .../tests/cpp/config_test/src/config_test.cpp | 81 +++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index f05c09c203..ab9435e117 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -32,14 +32,74 @@ TEST(core_cpp_config, user_config_passing) { eCAL::Config::eCALConfig custom_config; - custom_config.transport_layer_options.network_enabled = true; - // initialize ecal api with custom config + // Test value assignments from each category + // How the user would utilize it + + // Transport layer options + bool network_enabled = true; + std::string ip_address = "238.200.100.2"; + int upd_snd_buff = (5242880 + 1024); + + custom_config.transport_layer_options.network_enabled = network_enabled; + custom_config.transport_layer_options.mc_options.group = ip_address; + custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; + + // Monitoring options + unsigned int mon_timeout = 6000U; + std::string mon_filter_excl = "_A.*"; + eCAL_Logging_Filter mon_log_filter_con = log_level_warning; + eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; + + custom_config.monitoring_options.monitoring_timeout = mon_timeout; + custom_config.monitoring_options.filter_excl = mon_filter_excl; + custom_config.monitoring_options.filter_log_con = mon_log_filter_con; + custom_config.monitoring_options.monitoring_mode = monitoring_mode; + + // Publisher options + eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; + + custom_config.publisher_options.use_shm = pub_use_shm; + + // Registration options + unsigned int registration_timeout = 80000U; + unsigned int registration_refresh = 2000U; + eCAL::Config::RegistrationOptions registration_options = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); + + custom_config.registration_options = registration_options; + + + // Initialize ecal api with custom config EXPECT_EQ(0, eCAL::Initialize(0, nullptr, "user_config_passing test", eCAL::Init::Default, &custom_config)); - // test if created value is accessible, default was false - EXPECT_EQ(true, eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled); + // Test boolean assignment, default is false + EXPECT_EQ(network_enabled, eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled); + + // Test IP address assignment, default is 239.0.0.1 + EXPECT_EQ(ip_address, eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get()); + + // Test UDP send buffer assignment, default is 5242880 + EXPECT_EQ(upd_snd_buff, eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf); + + // Test monitoring timeout assignment, default is 5000U + EXPECT_EQ(mon_timeout, eCAL::Config::GetCurrentConfig()->monitoring_options.monitoring_timeout); - // finalize eCAL API + // Test monitoring filter exclude assignment, default is "_.*" + EXPECT_EQ(mon_filter_excl, eCAL::Config::GetCurrentConfig()->monitoring_options.filter_excl); + + // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) + EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig()->monitoring_options.filter_log_con); + + // Test monitoring mode assignment, default iseCAL::Config::MonitoringMode::none + EXPECT_EQ(monitoring_mode, eCAL::Config::GetCurrentConfig()->monitoring_options.monitoring_mode); + + // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto + EXPECT_EQ(pub_use_shm, eCAL::Config::GetCurrentConfig()->publisher_options.use_shm); + + // Test registration option assignment, default timeout is 60000U and default refresh is 1000U + EXPECT_EQ(registration_timeout, eCAL::Config::GetCurrentConfig()->registration_options.getTimeoutMS()); + EXPECT_EQ(registration_refresh, eCAL::Config::GetCurrentConfig()->registration_options.getRefreshMS()); + + // Finalize eCAL API EXPECT_EQ(0, eCAL::Finalize()); } @@ -53,7 +113,18 @@ TEST(ConfigDeathTest, user_config_death_test) ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); // Test the LimitSize class with wrong values. Default are MIN = 5242880, STEP = 1024 + // Value below MIN EXPECT_EXIT( SetValue(custom_config.transport_layer_options.mc_options.sndbuf, 42), ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); + + // Wrong step. Default STEP = 1024 + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.sndbuf, (5242880 + 512)), + ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); + + // Value exceeds MAX. Default MAX = 100 + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), + ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); } \ No newline at end of file From 0370d477d343e1b42cd2ec98c9f102b5c1a27817 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:57:18 +0200 Subject: [PATCH 031/105] Removed GetDefaultConfig(). --- .../src/config/ecal_config_initializer.cpp | 89 ------------------- 1 file changed, 89 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index fcf50e905a..b6fec459d7 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -94,95 +94,6 @@ namespace eCAL { namespace Config { - eCALConfig GetDefaultConfig(eCALConfig& config) - { - // transport layer options - auto& transportLayerOptions = config.transport_layer_options; - transportLayerOptions.network_enabled = NET_ENABLED; - transportLayerOptions.drop_out_of_order_messages = EXP_DROP_OUT_OF_ORDER_MESSAGES; - - auto& multicastOptions = transportLayerOptions.mc_options; - multicastOptions.config_version = NET_UDP_MULTICAST_CONFIG_VERSION; - multicastOptions.group = std::string(NET_UDP_MULTICAST_GROUP); - multicastOptions.mask = std::string(NET_UDP_MULTICAST_MASK); - multicastOptions.port = NET_UDP_MULTICAST_PORT; - multicastOptions.ttl = NET_UDP_MULTICAST_TTL; - multicastOptions.recbuf = NET_UDP_MULTICAST_RCVBUF; - multicastOptions.sndbuf = NET_UDP_MULTICAST_SNDBUF; - multicastOptions.join_all_interfaces = NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED; - multicastOptions.bandwidth_max_udp = NET_BANDWIDTH_MAX_UDP; - multicastOptions.npcap_enabled = NET_NPCAP_ENABLED; - - auto& tcpPubSubOptions = transportLayerOptions.tcp_options; - tcpPubSubOptions.num_executor_reader = NET_TCP_PUBSUB_NUM_EXECUTOR_READER; - tcpPubSubOptions.num_executor_writer = NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER; - tcpPubSubOptions.max_reconnections = NET_TCP_PUBSUB_MAX_RECONNECTIONS; - - auto& shmOptions = transportLayerOptions.shm_options; - shmOptions.host_group_name = NET_HOST_GROUP_NAME; - shmOptions.memfile_minsize = PUB_MEMFILE_MINSIZE; - shmOptions.memfile_reserve = PUB_MEMFILE_RESERVE; - shmOptions.memfile_ack_timeout = PUB_MEMFILE_ACK_TO; - shmOptions.memfile_buffer_count = PUB_MEMFILE_BUF_COUNT; - shmOptions.drop_out_of_order_messages = EXP_DROP_OUT_OF_ORDER_MESSAGES; - shmOptions.memfile_zero_copy = PUB_MEMFILE_ZERO_COPY; - - // registration options - auto& registrationOptions = config.registration_options; - registrationOptions = RegistrationOptions(CMN_REGISTRATION_TO, CMN_REGISTRATION_REFRESH); - registrationOptions.share_tdesc = PUB_SHARE_TDESC; - registrationOptions.share_ttype = PUB_SHARE_TTYPE; - - // monitoring options - auto& monitoringOptions = config.monitoring_options; - monitoringOptions.monitoring_mode = EXP_MONITORING_MODE; - monitoringOptions.monitoring_timeout = MON_TIMEOUT; - monitoringOptions.network_monitoring = EXP_NETWORK_MONITORING_ENABLED; - monitoringOptions.filter_excl = MON_FILTER_EXCL; - monitoringOptions.filter_incl = MON_FILTER_INCL; - monitoringOptions.filter_log_con = MON_LOG_FILTER_CON; - monitoringOptions.filter_log_file = MON_LOG_FILTER_FILE; - monitoringOptions.filter_log_udp = MON_LOG_FILTER_UDP; - - // auto& udpMonitoringOptions = monitoringOptions.udp_options; - // TODO: Nothing here yet - - auto& shmMonitoringOptions = monitoringOptions.shm_options; - shmMonitoringOptions.shm_monitoring_domain = std::string(EXP_SHM_MONITORING_DOMAIN); - shmMonitoringOptions.shm_monitoring_queue_size = EXP_SHM_MONITORING_QUEUE_SIZE; - - // receiving options - auto& receivingOptions = config.receiving_options; - receivingOptions.shm_recv_enabled = NET_SHM_REC_ENABLED; - receivingOptions.tcp_recv_enabled = NET_TCP_REC_ENABLED; - receivingOptions.udp_mc_recv_enabled = NET_UDP_MC_REC_ENABLED; - - // publisher options - auto& publisherOptions = config.publisher_options; - publisherOptions.use_shm = PUB_USE_SHM; - publisherOptions.use_tcp = PUB_USE_TCP; - publisherOptions.use_udp_mc = PUB_USE_UDP_MC; - - // timesync options - auto& timesyncOptions = config.timesync_options; - timesyncOptions.timesync_module = TIME_SYNC_MODULE; - - // service options - auto& serviceOptions = config.service_options; - serviceOptions.protocol_v0 = SERVICE_PROTOCOL_V0; - serviceOptions.protocol_v1 = SERVICE_PROTOCOL_V1; - - // sys options - auto& sysOptions = config.application_options.sys_options; - sysOptions.filter_excl = SYS_FILTER_EXCL; - - // process options - auto& processOptions = config.application_options.process_options; - processOptions.terminal_emulator = PROCESS_TERMINAL_EMULATOR; - - return config; - }; - eCALConfig GetIniConfig(eCALConfig& config) { CConfig iniConfig; From ae7e608667c7fcdce04db9e6aa99d281a004c6bd Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 5 Apr 2024 07:39:39 +0200 Subject: [PATCH 032/105] Setting new_initialization to true in ecal_globals when ecal_config gets initialized. --- ecal/core/src/ecal_globals.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 1e79b8f0e6..7e3035d299 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -66,6 +66,8 @@ namespace eCAL { // Config key handling here } + + new_initialization = true; } #if ECAL_CORE_REGISTRATION From 6530bec4a5f20446e0d071b7142a761fd2b72310 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:12:30 +0200 Subject: [PATCH 033/105] Removed const from custom_data_types as recommended. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 40f44f425c..4726bd16c5 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -46,7 +46,7 @@ namespace eCAL IpAddressV4() = default; ECAL_API IpAddressV4(const std::string ip_address_); - const std::string get() { return m_ip_address; } + std::string get() const { return m_ip_address; } private: static bool checkIpString(std::string ip_address_); @@ -80,7 +80,7 @@ namespace eCAL } }; - const int get() const { return m_size; }; + int get() const { return m_size; }; bool operator==(const LimitSize& other) const { return this->m_size == other.get(); }; friend bool operator==(const LimitSize& lhs, const int& rhs) { return lhs.get() == rhs; }; From 3f95473903ba556c79671aceee3f400372021d56 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 8 Apr 2024 09:22:32 +0200 Subject: [PATCH 034/105] Review 1: Moved GetCurrentConfig to config.h. --- ecal/core/include/ecal/ecal_config.h | 10 +++------- ecal/core/include/ecal/types/ecal_config_types.h | 2 -- ecal/core/include/ecal/types/ecal_custom_data_types.h | 4 ++-- ecal/core/src/config/ecal_config_initializer.cpp | 2 +- ecal/core/src/ecal_descgate.cpp | 1 - ecal/core/src/ecal_process.cpp | 3 +-- ecal/core/src/io/udp/ecal_udp_configurations.cpp | 2 +- ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp | 2 +- ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp | 2 +- ecal/core/src/types/ecal_custom_data_types.cpp | 4 +++- ecal/tests/cpp/config_test/src/config_test.cpp | 2 +- 11 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 010554f47d..14daa4e3b0 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -16,14 +16,13 @@ * * ========================= eCAL LICENSE ================================= */ -// TODO PG: Remove, deprecated + #pragma once #include #include #include #include -#include #include "ecal/types/ecal_config_types.h" #include @@ -33,11 +32,8 @@ namespace eCAL { namespace Config { - // enum class UdpConfigVersion - // { - // V1 = 1, // Legacy - // V2 = 2 - // }; + + ECAL_API eCALConfig* GetCurrentConfig(); ///////////////////////////////////// // common diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 5fa54f3a77..5d35ee1e67 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -60,7 +60,5 @@ namespace eCAL ECAL_API eCALConfig(); }; - - ECAL_API eCALConfig* GetCurrentConfig(); } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 4726bd16c5..f20a8321c2 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -43,8 +43,8 @@ namespace eCAL class IpAddressV4 { public: - IpAddressV4() = default; - ECAL_API IpAddressV4(const std::string ip_address_); + ECAL_API IpAddressV4(); + ECAL_API IpAddressV4(const std::string& ip_address_); std::string get() const { return m_ip_address; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index b6fec459d7..bd11a8b90b 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -21,7 +21,7 @@ * @brief Function definitions for setting default config values **/ -#include "ecal/types/ecal_config_types.h" +#include "ecal/ecal_config.h" #include "ecal_config_reader.h" #include "ecal_global_accessors.h" diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index cbcba3861b..0eae2f6c3c 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -23,7 +23,6 @@ #include #include -#include "ecal/types/ecal_config_types.h" #include "ecal_globals.h" #include "ecal_descgate.h" diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 372b3223ef..f86943de39 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -25,7 +25,7 @@ #include #include "ecal_def.h" -#include "ecal/types/ecal_config_types.h" +#include "ecal/ecal_config.h" #include "ecal_globals.h" #include "ecal_process_stub.h" @@ -35,7 +35,6 @@ #include "config/ecal_config_reader_hlp.h" #include "io/udp/ecal_udp_configurations.h" -#include "ecal/types/ecal_config_types.h" #include #include diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index ebf2b5a3ea..f7cbfa4498 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -21,7 +21,7 @@ #include "ecal_def.h" #include "ecal_udp_topic2mcast.h" -#include "ecal/types/ecal_config_types.h" +#include "ecal/ecal_config.h" #include #include diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index 6d18782015..85401d1d7e 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -25,7 +25,7 @@ #include "serialization/ecal_serialize_sample_payload.h" #include -#include "ecal/types/ecal_config_types.h" +#include "ecal/ecal_config.h" #include "ecal_writer_tcp.h" #include "ecal_tcp_pubsub_logger.h" diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index c7ad33e3d5..41ac2ccebb 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -22,7 +22,7 @@ **/ #include -#include +#include #include #include #include diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index c21d26f49c..42217249ee 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -30,7 +30,9 @@ namespace eCAL // IpAddressV4 definitions - IpAddressV4::IpAddressV4(const std::string ip_address_) + IpAddressV4::IpAddressV4() = default; + + IpAddressV4::IpAddressV4(const std::string& ip_address_) { if (checkIpString(ip_address_)) { diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index ab9435e117..cc23efb9cc 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -18,7 +18,7 @@ */ #include -#include +#include #include From a435621bdfe93eb2ec42f1e07ff040e184c7fbd3 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:11:57 +0100 Subject: [PATCH 035/105] Changed defines to constexpr in ecal_dev_ini.h --- ecal/core/src/ecal_def.h | 138 ++++++++++++++++++----------------- ecal/core/src/ecal_def_ini.h | 2 +- 2 files changed, 73 insertions(+), 67 deletions(-) diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 679947e401..b7013983e4 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -23,103 +23,109 @@ #pragma once +#include #include /**********************************************************************************************/ /* config settings */ /**********************************************************************************************/ /* base data path name */ -#define ECAL_HOME_PATH_WINDOWS "" -#define ECAL_HOME_PATH_LINUX ".ecal" -#define ECAL_LOG_PATH "logs" -#define ECAL_SETTINGS_PATH "cfg" +constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; +constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; +constexpr char ECAL_HOME_PATH_LINUX[] = ".ecal"; +constexpr char ECAL_LOG_PATH[] = "logs"; +constexpr char ECAL_SETTINGS_PATH[] = "cfg"; /* ini file name */ -#define ECAL_DEFAULT_CFG "ecal.ini" +constexpr char ECAL_DEFAULT_CFG[] = "ecal.ini"; /**********************************************************************************************/ /* monitor settings */ /**********************************************************************************************/ /* timeout for automatic removing monitoring topics in ms */ -#define MON_TIMEOUT 5000 +constexpr unsigned int MON_TIMEOUT = 5000U; /* topics blacklist as regular expression (will not be monitored) */ -#define MON_FILTER_EXCL "_.*" +constexpr char MON_FILTER_EXCL[] = "^__.*$"; /* topics whitelist as regular expression (will be monitored only) */ -#define MON_FILTER_INCL "" +constexpr char MON_FILTER_INCL[] = ""; /* logging filter settings */ -#define MON_LOG_FILTER_CON "info,warning,error,fatal" -#define MON_LOG_FILTER_FILE "" -#define MON_LOG_FILTER_UDP "info,warning,error,fatal" +constexpr char MON_LOG_FILTER_CON[] = "info,warning,error,fatal"; +constexpr char MON_LOG_FILTER_FILE[] = ""; +constexpr char MON_LOG_FILTER_UDP[] = "info,warning,error,fatal"; /**********************************************************************************************/ /* sys settings */ /**********************************************************************************************/ /* sys app witch will not be imported from cloud */ -#define SYS_FILTER_EXCL "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*" +constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"; /**********************************************************************************************/ /* network settings */ /**********************************************************************************************/ /* network switch */ -#define NET_ENABLED false +constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -#define NET_UDP_MULTICAST_CONFIG_VERSION "v1" -#define NET_UDP_MULTICAST_GROUP "239.0.0.1" -#define NET_UDP_MULTICAST_MASK "0.0.0.15" -#define NET_UDP_MULTICAST_PORT 14000 -#define NET_UDP_MULTICAST_TTL 3 -#define NET_UDP_MULTICAST_PORT_REG_OFF 0 -#define NET_UDP_MULTICAST_PORT_SAMPLE_OFF 2 -#define NET_UDP_MULTICAST_PORT_LOG_OFF 4 -#define NET_UDP_MULTICAST_SNDBUF (5*1024*1024) /* 5 MByte */ -#define NET_UDP_MULTICAST_RCVBUF (5*1024*1024) /* 5 MByte */ -#define NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED false - -#define NET_UDP_RECBUFFER_TIMEOUT 1000 /* ms */ -#define NET_UDP_RECBUFFER_CLEANUP 10 /* ms */ - -#define NET_TCP_REC_ENABLED true -#define NET_SHM_REC_ENABLED true -#define NET_UDP_MC_REC_ENABLED true - -#define NET_NPCAP_ENABLED false - -#define NET_TCP_PUBSUB_NUM_EXECUTOR_READER 4 -#define NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER 4 -#define NET_TCP_PUBSUB_MAX_RECONNECTIONS 5 +constexpr char NET_UDP_MULTICAST_CONFIG_VERSION[] = "v1"; +constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; +constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; +constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; +constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; +constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; +constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; +constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; +constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ +constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; + +constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10; /* ms */ + +/* overall udp multicast bandwidth limitation in bytes/s, -1 == no limitation*/ +constexpr int NET_BANDWIDTH_MAX_UDP = (-1); + +constexpr bool NET_TCP_REC_ENABLED = true; +constexpr bool NET_SHM_REC_ENABLED = true; + +constexpr bool NET_UDP_MC_REC_ENABLED = true; + +constexpr bool NET_NPCAP_ENABLED = false; + +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4; +constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5; /* common host group name that enables interprocess mechanisms across (virtual) host borders (e.g, Docker); by default equivalent to local host name */ -#define NET_HOST_GROUP_NAME "" +constexpr char NET_HOST_GROUP_NAME[] = ""; /**********************************************************************************************/ /* publisher settings */ /**********************************************************************************************/ /* use shared memory transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_SHM 2 +constexpr unsigned int PUB_USE_SHM = 2; /* use tcp transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_TCP 0 +constexpr unsigned int PUB_USE_TCP = 0; /* use udp multicast transport layer [auto = 2, on = 1, off = 0] */ -#define PUB_USE_UDP_MC 2 +constexpr unsigned int PUB_USE_UDP_MC = 2; /* share topic type [ on = 1, off = 0] */ -#define PUB_SHARE_TTYPE 1 +constexpr unsigned int PUB_SHARE_TTYPE = 1; /* share topic description [ on = 1, off = 0] */ -#define PUB_SHARE_TDESC 1 +constexpr unsigned int PUB_SHARE_TDESC = 1; /* minimum size for created shared memory files */ -#define PUB_MEMFILE_MINSIZE (4*1024) +constexpr unsigned int PUB_MEMFILE_MINSIZE = (4*1024); /* reserve buffer size before reallocation in % */ -#define PUB_MEMFILE_RESERVE 50 +constexpr unsigned int PUB_MEMFILE_RESERVE = 50; /* timeout for create / open a memory file using mutex lock in ms */ -#define PUB_MEMFILE_CREATE_TO 200 -#define PUB_MEMFILE_OPEN_TO 200 +constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200; +constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200; /* timeout for memory read acknowledge signal from data reader in ms */ -#define PUB_MEMFILE_ACK_TO 0 /* ms */ +constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ /* defines number of memory files handle by the publisher for a 1:n connection a higher number will increase data throughput, but will also increase the size of used memory, number of semaphores @@ -127,68 +133,68 @@ higher values than 3 are not recommended values > 1 will break local IPC compatibility to eCAL 5.9 and older */ -#define PUB_MEMFILE_BUF_COUNT 1 +constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1; /* allow subscriber to access memory file without copying content in advance (zero copy) this memory file is blocked for other readers wihle processed by the user callback function this option is fully IPC compatible to all eCAL 5.x versions */ -#define PUB_MEMFILE_ZERO_COPY 0 +constexpr unsigned int PUB_MEMFILE_ZERO_COPY = 0; /**********************************************************************************************/ /* service settings */ /**********************************************************************************************/ /* support service protocol v0, eCAL 5.11 and older (0 = off, 1 = on) */ -#define SERVICE_PROTOCOL_V0 1 +constexpr unsigned int SERVICE_PROTOCOL_V0 = 1; /* support service protocol v1, eCAL 5.12 and newer (0 = off, 1 = on) */ -#define SERVICE_PROTOCOL_V1 1 +constexpr unsigned int SERVICE_PROTOCOL_V1 = 1; /**********************************************************************************************/ /* time settings */ /**********************************************************************************************/ -#define TIME_SYNC_MOD_RT "" -#define TIME_SYNC_MOD_REPLAY "" +constexpr char TIME_SYNC_MOD_RT[] = ""; +constexpr char TIME_SYNC_MOD_REPLAY[] = ""; /**********************************************************************************************/ /* process settings */ /**********************************************************************************************/ -#define PROCESS_TERMINAL_EMULATOR "" +constexpr char PROCESS_TERMINAL_EMULATOR[] = ""; /**********************************************************************************************/ /* ecal internal timings */ /**********************************************************************************************/ /* timeout for automatic removing registered topics and memory files in global database in ms */ -#define CMN_REGISTRATION_TO (60*1000) +constexpr unsigned int CMN_REGISTRATION_TO = (60*1000); /* time for resend registration info from publisher/subscriber in ms */ -#define CMN_REGISTRATION_REFRESH 1000 +constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000; /* delta time to check timeout for data readers in ms */ -#define CMN_DATAREADER_TIMEOUT_RESOLUTION_MS 100 +constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100; /* cylce time udp receive threads in ms */ -#define CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS 1000 +constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000; /**********************************************************************************************/ /* events */ /**********************************************************************************************/ /* common stop event prefix to shut down a local user process */ -#define EVENT_SHUTDOWN_PROC "ecal_shutdown_process" +constexpr char EVENT_SHUTDOWN_PROC[] = "ecal_shutdown_process"; /**********************************************************************************************/ /* experimental */ /**********************************************************************************************/ /* enable distribution of monitoring/registration information via shared memory */ -#define EXP_SHM_MONITORING_ENABLED false +constexpr bool EXP_SHM_MONITORING_ENABLED = false; /* disable distribution of monitoring/registration information via network (default) */ -#define EXP_NETWORK_MONITORING_DISABLED false +constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; /* queue size of monitoring/registration events */ -#define EXP_SHM_MONITORING_QUEUE_SIZE 1024 +constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024; /* domain name for shared memory based monitoring/registration */ -#define EXP_SHM_MONITORING_DOMAIN "ecal_monitoring" +constexpr char EXP_SHM_MONITORING_DOMAIN[] = "ecal_monitoring"; /* memory file access timeout */ -#define EXP_MEMFILE_ACCESS_TIMEOUT 100 +constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100; /* enable dropping of payload messages that arrive out of order */ -#define EXP_DROP_OUT_OF_ORDER_MESSAGES false +constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; diff --git a/ecal/core/src/ecal_def_ini.h b/ecal/core/src/ecal_def_ini.h index ee4718f2d8..8911b7b52f 100644 --- a/ecal/core/src/ecal_def_ini.h +++ b/ecal/core/src/ecal_def_ini.h @@ -20,7 +20,7 @@ /** * @brief eCAL ini file keys **/ - +// TODO PG: Delete - deprecated #pragma once ///////////////////////////////////// From 832c8110d830c99e4d7cfae9c1103b3004a93bc6 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 8 Apr 2024 13:34:39 +0200 Subject: [PATCH 036/105] Changed defines to constexpr in ecal_def, ecal_def_ini + added uint and size_t reading in ecal_config_reader. --- ecal/core/src/config/ecal_config_reader.cpp | 10 ++ ecal/core/src/config/ecal_config_reader.h | 10 +- ecal/core/src/ecal_def.h | 108 +++++++++---------- ecal/core/src/ecal_def_ini.h | 112 ++++++++++---------- 4 files changed, 125 insertions(+), 115 deletions(-) diff --git a/ecal/core/src/config/ecal_config_reader.cpp b/ecal/core/src/config/ecal_config_reader.cpp index e5990982d3..cefe229658 100644 --- a/ecal/core/src/config/ecal_config_reader.cpp +++ b/ecal/core/src/config/ecal_config_reader.cpp @@ -425,6 +425,16 @@ namespace eCAL return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); } + unsigned int CConfig::get(const std::string& section_, const std::string& key_, unsigned int default_) + { + return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); + } + + size_t CConfig::get(const std::string& section_, const std::string& key_, size_t default_) + { + return static_cast(m_impl->GetLongValue(section_.c_str(), key_.c_str(), static_cast(default_))); + } + double CConfig::get(const std::string& section_, const std::string& key_, double default_) { return m_impl->GetDoubleValue(section_.c_str(), key_.c_str(), default_); diff --git a/ecal/core/src/config/ecal_config_reader.h b/ecal/core/src/config/ecal_config_reader.h index ab5d13ae4c..d1bbca0a45 100644 --- a/ecal/core/src/config/ecal_config_reader.h +++ b/ecal/core/src/config/ecal_config_reader.h @@ -44,10 +44,12 @@ namespace eCAL bool Validate(); // common getter - bool get(const std::string& section_, const std::string& key_, bool default_); - int get(const std::string& section_, const std::string& key_, int default_); - double get(const std::string& section_, const std::string& key_, double default_); - std::string get(const std::string& section_, const std::string& key_, const char* default_); + bool get(const std::string& section_, const std::string& key_, bool default_); + int get(const std::string& section_, const std::string& key_, int default_); + double get(const std::string& section_, const std::string& key_, double default_); + std::string get(const std::string& section_, const std::string& key_, const char* default_); + unsigned int get(const std::string& section_, const std::string& key_, unsigned int default_); + size_t get(const std::string& section_, const std::string& key_, size_t default_); private: std::unique_ptr m_impl; diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index b7013983e4..ada5beb82e 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -23,43 +23,41 @@ #pragma once -#include #include /**********************************************************************************************/ /* config settings */ /**********************************************************************************************/ /* base data path name */ -constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; -constexpr char ECAL_HOME_PATH_WINDOWS[] = ""; -constexpr char ECAL_HOME_PATH_LINUX[] = ".ecal"; -constexpr char ECAL_LOG_PATH[] = "logs"; -constexpr char ECAL_SETTINGS_PATH[] = "cfg"; +constexpr const char* ECAL_HOME_PATH_WINDOWS = ""; +constexpr const char* ECAL_HOME_PATH_LINUX = ".ecal"; +constexpr const char* ECAL_LOG_PATH = "logs"; +constexpr const char* ECAL_SETTINGS_PATH = "cfg"; /* ini file name */ -constexpr char ECAL_DEFAULT_CFG[] = "ecal.ini"; +constexpr const char* ECAL_DEFAULT_CFG = "ecal.ini"; /**********************************************************************************************/ /* monitor settings */ /**********************************************************************************************/ /* timeout for automatic removing monitoring topics in ms */ -constexpr unsigned int MON_TIMEOUT = 5000U; +constexpr unsigned int MON_TIMEOUT = 5000U; /* topics blacklist as regular expression (will not be monitored) */ -constexpr char MON_FILTER_EXCL[] = "^__.*$"; +constexpr const char* MON_FILTER_EXCL = "^__.*$"; /* topics whitelist as regular expression (will be monitored only) */ -constexpr char MON_FILTER_INCL[] = ""; +constexpr const char* MON_FILTER_INCL = ""; /* logging filter settings */ -constexpr char MON_LOG_FILTER_CON[] = "info,warning,error,fatal"; -constexpr char MON_LOG_FILTER_FILE[] = ""; -constexpr char MON_LOG_FILTER_UDP[] = "info,warning,error,fatal"; +constexpr const char* MON_LOG_FILTER_CON = "info,warning,error,fatal"; +constexpr const char* MON_LOG_FILTER_FILE = ""; +constexpr const char* MON_LOG_FILTER_UDP = "info,warning,error,fatal"; /**********************************************************************************************/ /* sys settings */ /**********************************************************************************************/ /* sys app witch will not be imported from cloud */ -constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"; +constexpr const char* SYS_FILTER_EXCL = "^eCALSysClient$|^eCALSysGUI$|^eCALSys$*"; /**********************************************************************************************/ /* network settings */ @@ -68,20 +66,20 @@ constexpr char SYS_FILTER_EXCL[] = "^eCALSysClient$|^eCALSysGUI$|^eCALSys constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -constexpr char NET_UDP_MULTICAST_CONFIG_VERSION[] = "v1"; -constexpr char NET_UDP_MULTICAST_GROUP[] = "239.0.0.1"; -constexpr char NET_UDP_MULTICAST_MASK[] = "0.0.0.15"; -constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000; -constexpr unsigned int NET_UDP_MULTICAST_TTL = 3; -constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0; -constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1; -constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2; -constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5*1024*1024); /* 5 MByte */ -constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5*1024*1024); /* 5 MByte */ +constexpr const char* NET_UDP_MULTICAST_CONFIG_VERSION = "v1"; +constexpr const char* NET_UDP_MULTICAST_GROUP = "239.0.0.1"; +constexpr const char* NET_UDP_MULTICAST_MASK = "0.0.0.15"; +constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000U; +constexpr unsigned int NET_UDP_MULTICAST_TTL = 3U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_REG_OFF = 0U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_LOG_OFF = 1U; +constexpr unsigned int NET_UDP_MULTICAST_PORT_SAMPLE_OFF = 2U; +constexpr unsigned int NET_UDP_MULTICAST_SNDBUF = (5U*1024U*1024U); /* 5 MByte */ +constexpr unsigned int NET_UDP_MULTICAST_RCVBUF = (5U*1024U*1024U); /* 5 MByte */ constexpr bool NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED = false; -constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000; /* ms */ -constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_TIMEOUT = 1000U; /* ms */ +constexpr unsigned int NET_UDP_RECBUFFER_CLEANUP = 10U; /* ms */ /* overall udp multicast bandwidth limitation in bytes/s, -1 == no limitation*/ constexpr int NET_BANDWIDTH_MAX_UDP = (-1); @@ -93,39 +91,39 @@ constexpr bool NET_UDP_MC_REC_ENABLED = true; constexpr bool NET_NPCAP_ENABLED = false; -constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4; -constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4; -constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_READER = 4U; +constexpr unsigned int NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER = 4U; +constexpr unsigned int NET_TCP_PUBSUB_MAX_RECONNECTIONS = 5U; /* common host group name that enables interprocess mechanisms across (virtual) host borders (e.g, Docker); by default equivalent to local host name */ -constexpr char NET_HOST_GROUP_NAME[] = ""; +constexpr const char* NET_HOST_GROUP_NAME = ""; /**********************************************************************************************/ /* publisher settings */ /**********************************************************************************************/ /* use shared memory transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_SHM = 2; +constexpr unsigned int PUB_USE_SHM = 2U; /* use tcp transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_TCP = 0; +constexpr unsigned int PUB_USE_TCP = 0U; /* use udp multicast transport layer [auto = 2, on = 1, off = 0] */ -constexpr unsigned int PUB_USE_UDP_MC = 2; +constexpr unsigned int PUB_USE_UDP_MC = 2U; /* share topic type [ on = 1, off = 0] */ -constexpr unsigned int PUB_SHARE_TTYPE = 1; +constexpr unsigned int PUB_SHARE_TTYPE = 1U; /* share topic description [ on = 1, off = 0] */ -constexpr unsigned int PUB_SHARE_TDESC = 1; +constexpr unsigned int PUB_SHARE_TDESC = 1U; /* minimum size for created shared memory files */ -constexpr unsigned int PUB_MEMFILE_MINSIZE = (4*1024); +constexpr unsigned int PUB_MEMFILE_MINSIZE = (4U*1024U); /* reserve buffer size before reallocation in % */ -constexpr unsigned int PUB_MEMFILE_RESERVE = 50; +constexpr unsigned int PUB_MEMFILE_RESERVE = 50U; /* timeout for create / open a memory file using mutex lock in ms */ -constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200; -constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200; +constexpr unsigned int PUB_MEMFILE_CREATE_TO = 200U; +constexpr unsigned int PUB_MEMFILE_OPEN_TO = 200U; /* timeout for memory read acknowledge signal from data reader in ms */ -constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ +constexpr unsigned int PUB_MEMFILE_ACK_TO = 0U; /* ms */ /* defines number of memory files handle by the publisher for a 1:n connection a higher number will increase data throughput, but will also increase the size of used memory, number of semaphores @@ -133,54 +131,54 @@ constexpr unsigned int PUB_MEMFILE_ACK_TO = 0; /* ms */ higher values than 3 are not recommended values > 1 will break local IPC compatibility to eCAL 5.9 and older */ -constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1; +constexpr unsigned int PUB_MEMFILE_BUF_COUNT = 1U; /* allow subscriber to access memory file without copying content in advance (zero copy) this memory file is blocked for other readers wihle processed by the user callback function this option is fully IPC compatible to all eCAL 5.x versions */ -constexpr unsigned int PUB_MEMFILE_ZERO_COPY = 0; +constexpr unsigned int PUB_MEMFILE_ZERO_COPY = 0U; /**********************************************************************************************/ /* service settings */ /**********************************************************************************************/ /* support service protocol v0, eCAL 5.11 and older (0 = off, 1 = on) */ -constexpr unsigned int SERVICE_PROTOCOL_V0 = 1; +constexpr unsigned int SERVICE_PROTOCOL_V0 = 1U; /* support service protocol v1, eCAL 5.12 and newer (0 = off, 1 = on) */ -constexpr unsigned int SERVICE_PROTOCOL_V1 = 1; +constexpr unsigned int SERVICE_PROTOCOL_V1 = 1U; /**********************************************************************************************/ /* time settings */ /**********************************************************************************************/ -constexpr char TIME_SYNC_MOD_RT[] = ""; -constexpr char TIME_SYNC_MOD_REPLAY[] = ""; +constexpr const char* TIME_SYNC_MOD_RT = ""; +constexpr const char* TIME_SYNC_MOD_REPLAY = ""; /**********************************************************************************************/ /* process settings */ /**********************************************************************************************/ -constexpr char PROCESS_TERMINAL_EMULATOR[] = ""; +constexpr const char* PROCESS_TERMINAL_EMULATOR = ""; /**********************************************************************************************/ /* ecal internal timings */ /**********************************************************************************************/ /* timeout for automatic removing registered topics and memory files in global database in ms */ -constexpr unsigned int CMN_REGISTRATION_TO = (60*1000); +constexpr unsigned int CMN_REGISTRATION_TO = (60U*1000U); /* time for resend registration info from publisher/subscriber in ms */ -constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000; +constexpr unsigned int CMN_REGISTRATION_REFRESH = 1000U; /* delta time to check timeout for data readers in ms */ -constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100; +constexpr unsigned int CMN_DATAREADER_TIMEOUT_RESOLUTION_MS = 100U; /* cylce time udp receive threads in ms */ -constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000; +constexpr unsigned int CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS = 1000U; /**********************************************************************************************/ /* events */ /**********************************************************************************************/ /* common stop event prefix to shut down a local user process */ -constexpr char EVENT_SHUTDOWN_PROC[] = "ecal_shutdown_process"; +constexpr const char* EVENT_SHUTDOWN_PROC = "ecal_shutdown_process"; /**********************************************************************************************/ /* experimental */ @@ -190,11 +188,11 @@ constexpr bool EXP_SHM_MONITORING_ENABLED = false; /* disable distribution of monitoring/registration information via network (default) */ constexpr bool EXP_NETWORK_MONITORING_DISABLED = false; /* queue size of monitoring/registration events */ -constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024; +constexpr unsigned int EXP_SHM_MONITORING_QUEUE_SIZE = 1024U; /* domain name for shared memory based monitoring/registration */ -constexpr char EXP_SHM_MONITORING_DOMAIN[] = "ecal_monitoring"; +constexpr const char* EXP_SHM_MONITORING_DOMAIN = "ecal_monitoring"; /* memory file access timeout */ -constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100; +constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100U; /* enable dropping of payload messages that arrive out of order */ constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; diff --git a/ecal/core/src/ecal_def_ini.h b/ecal/core/src/ecal_def_ini.h index 8911b7b52f..6bc65331e8 100644 --- a/ecal/core/src/ecal_def_ini.h +++ b/ecal/core/src/ecal_def_ini.h @@ -20,111 +20,111 @@ /** * @brief eCAL ini file keys **/ -// TODO PG: Delete - deprecated + #pragma once ///////////////////////////////////// // common ///////////////////////////////////// -#define CMN_SECTION_S "common" -#define CMN_REGISTRATION_TO_S "registration_timeout" -#define CMN_REGISTRATION_REFRESH_S "registration_refresh" +constexpr const char* CMN_SECTION_S = "common"; +constexpr const char* CMN_REGISTRATION_TO_S = "registration_timeout"; +constexpr const char* CMN_REGISTRATION_REFRESH_S = "registration_refresh"; ///////////////////////////////////// // network ///////////////////////////////////// -#define NET_SECTION_S "network" +constexpr const char* NET_SECTION_S = "network"; -#define NET_ENABLED_S "network_enabled" +constexpr const char* NET_ENABLED_S = "network_enabled"; -#define NET_UDP_MULTICAST_CONFIG_VERSION_S "multicast_config_version" -#define NET_UDP_MULTICAST_GROUP_S "multicast_group" -#define NET_UDP_MULTICAST_MASK_S "multicast_mask" -#define NET_UDP_MULTICAST_PORT_S "multicast_port" -#define NET_UDP_MULTICAST_TTL_S "multicast_ttl" +constexpr const char* NET_UDP_MULTICAST_CONFIG_VERSION_S = "multicast_config_version"; +constexpr const char* NET_UDP_MULTICAST_GROUP_S = "multicast_group"; +constexpr const char* NET_UDP_MULTICAST_MASK_S = "multicast_mask"; +constexpr const char* NET_UDP_MULTICAST_PORT_S = "multicast_port"; +constexpr const char* NET_UDP_MULTICAST_TTL_S = "multicast_ttl"; -#define NET_UDP_MULTICAST_SNDBUF_S "multicast_sndbuf" -#define NET_UDP_MULTICAST_RCVBUF_S "multicast_rcvbuf" +constexpr const char* NET_UDP_MULTICAST_SNDBUF_S = "multicast_sndbuf"; +constexpr const char* NET_UDP_MULTICAST_RCVBUF_S = "multicast_rcvbuf"; -#define NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED_S "multicast_join_all_if" +constexpr const char* NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED_S = "multicast_join_all_if"; -#define NET_UDP_MC_REC_ENABLED_S "udp_mc_rec_enabled" -#define NET_SHM_REC_ENABLED_S "shm_rec_enabled" -#define NET_TCP_REC_ENABLED_S "tcp_rec_enabled" +constexpr const char* NET_UDP_MC_REC_ENABLED_S = "udp_mc_rec_enabled"; +constexpr const char* NET_SHM_REC_ENABLED_S = "shm_rec_enabled"; +constexpr const char* NET_TCP_REC_ENABLED_S = "tcp_rec_enabled"; -#define NET_NPCAP_ENABLED_S "npcap_enabled" +constexpr const char* NET_NPCAP_ENABLED_S = "npcap_enabled"; -#define NET_TCP_PUBSUB_NUM_EXECUTOR_READER_S "tcp_pubsub_num_executor_reader" -#define NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER_S "tcp_pubsub_num_executor_writer" -#define NET_TCP_PUBSUB_MAX_RECONNECTIONS_S "tcp_pubsub_max_reconnections" +constexpr const char* NET_TCP_PUBSUB_NUM_EXECUTOR_READER_S = "tcp_pubsub_num_executor_reader"; +constexpr const char* NET_TCP_PUBSUB_NUM_EXECUTOR_WRITER_S = "tcp_pubsub_num_executor_writer"; +constexpr const char* NET_TCP_PUBSUB_MAX_RECONNECTIONS_S = "tcp_pubsub_max_reconnections"; -#define NET_HOST_GROUP_NAME_S "host_group_name" +constexpr const char* NET_HOST_GROUP_NAME_S = "host_group_name"; ///////////////////////////////////// // time ///////////////////////////////////// -#define TIME_SECTION_S "time" -#define TIME_SYNC_MOD_RT_S "timesync_module_rt" -#define TIME_SYNC_MOD_REPLAY_S "timesync_module_replay" +constexpr const char* TIME_SECTION_S = "time"; +constexpr const char* TIME_SYNC_MOD_RT_S = "timesync_module_rt"; +constexpr const char* TIME_SYNC_MOD_REPLAY_S = "timesync_module_replay"; ///////////////////////////////////// // process ///////////////////////////////////// -#define PROCESS_SECTION_S "process" -#define PROCESS_TERMINAL_EMULATOR_S "terminal_emulator" +constexpr const char* PROCESS_SECTION_S = "process"; +constexpr const char* PROCESS_TERMINAL_EMULATOR_S = "terminal_emulator"; ///////////////////////////////////// // monitoring ///////////////////////////////////// -#define MON_SECTION_S "monitoring" +constexpr const char* MON_SECTION_S = "monitoring"; -#define MON_TIMEOUT_S "timeout" -#define MON_FILTER_EXCL_S "filter_excl" -#define MON_FILTER_INCL_S "filter_incl" +constexpr const char* MON_TIMEOUT_S = "timeout"; +constexpr const char* MON_FILTER_EXCL_S = "filter_excl"; +constexpr const char* MON_FILTER_INCL_S = "filter_incl"; -#define MON_LOG_FILTER_CON_S "filter_log_con" -#define MON_LOG_FILTER_FILE_S "filter_log_file" -#define MON_LOG_FILTER_UDP_S "filter_log_udp" +constexpr const char* MON_LOG_FILTER_CON_S = "filter_log_con"; +constexpr const char* MON_LOG_FILTER_FILE_S = "filter_log_file"; +constexpr const char* MON_LOG_FILTER_UDP_S = "filter_log_udp"; ///////////////////////////////////// // sys ///////////////////////////////////// -#define SYS_SECTION_S "sys" -#define SYS_FILTER_EXCL_S "filter_excl" +constexpr const char* SYS_SECTION_S = "sys"; +constexpr const char* SYS_FILTER_EXCL_S = "filter_excl"; ///////////////////////////////////// // publisher ///////////////////////////////////// -#define PUB_SECTION_S "publisher" +constexpr const char* PUB_SECTION_S = "publisher"; -#define PUB_USE_UDP_MC_S "use_udp_mc" -#define PUB_USE_SHM_S "use_shm" -#define PUB_USE_TCP_S "use_tcp" +constexpr const char* PUB_USE_UDP_MC_S = "use_udp_mc"; +constexpr const char* PUB_USE_SHM_S = "use_shm"; +constexpr const char* PUB_USE_TCP_S = "use_tcp"; -#define PUB_MEMFILE_MINSIZE_S "memfile_minsize" -#define PUB_MEMFILE_RESERVE_S "memfile_reserve" -#define PUB_MEMFILE_ACK_TO_S "memfile_ack_timeout" -#define PUB_MEMFILE_ZERO_COPY_S "memfile_zero_copy" -#define PUB_MEMFILE_BUF_COUNT_S "memfile_buffer_count" +constexpr const char* PUB_MEMFILE_MINSIZE_S = "memfile_minsize"; +constexpr const char* PUB_MEMFILE_RESERVE_S = "memfile_reserve"; +constexpr const char* PUB_MEMFILE_ACK_TO_S = "memfile_ack_timeout"; +constexpr const char* PUB_MEMFILE_ZERO_COPY_S = "memfile_zero_copy"; +constexpr const char* PUB_MEMFILE_BUF_COUNT_S = "memfile_buffer_count"; -#define PUB_SHARE_TTYPE_S "share_ttype" -#define PUB_SHARE_TDESC_S "share_tdesc" +constexpr const char* PUB_SHARE_TTYPE_S = "share_ttype"; +constexpr const char* PUB_SHARE_TDESC_S = "share_tdesc"; ///////////////////////////////////// // service ///////////////////////////////////// -#define SERVICE_SECTION_S "service" +constexpr const char* SERVICE_SECTION_S = "service"; -#define SERVICE_PROTOCOL_V0_S "protocol_v0" -#define SERVICE_PROTOCOL_V1_S "protocol_v1" +constexpr const char* SERVICE_PROTOCOL_V0_S = "protocol_v0"; +constexpr const char* SERVICE_PROTOCOL_V1_S = "protocol_v1"; ///////////////////////////////////// // experimental ///////////////////////////////////// -#define EXP_SECTION_S "experimental" +constexpr const char* EXP_SECTION_S = "experimental"; -#define EXP_SHM_MONITORING_ENABLED_S "shm_monitoring_enabled" -#define EXP_NETWORK_MONITORING_DISABLED_S "network_monitoring_disabled" -#define EXP_SHM_MONITORING_QUEUE_SIZE_S "shm_monitoring_queue_size" -#define EXP_SHM_MONITORING_DOMAIN_S "shm_monitoring_domain" -#define EXP_DROP_OUT_OF_ORDER_MESSAGES_S "drop_out_of_order_messages" +constexpr const char* EXP_SHM_MONITORING_ENABLED_S = "shm_monitoring_enabled"; +constexpr const char* EXP_NETWORK_MONITORING_DISABLED_S = "network_monitoring_disabled"; +constexpr const char* EXP_SHM_MONITORING_QUEUE_SIZE_S = "shm_monitoring_queue_size"; +constexpr const char* EXP_SHM_MONITORING_DOMAIN_S = "shm_monitoring_domain"; +constexpr const char* EXP_DROP_OUT_OF_ORDER_MESSAGES_S = "drop_out_of_order_messages"; From e05f39881e1bdf4933204af065dfab49557de839 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:23:38 +0200 Subject: [PATCH 037/105] Removed ecal_internal_options.h. --- .../ecal/types/ecal_internal_options.h | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 ecal/core/include/ecal/types/ecal_internal_options.h diff --git a/ecal/core/include/ecal/types/ecal_internal_options.h b/ecal/core/include/ecal/types/ecal_internal_options.h deleted file mode 100644 index 8e134ebd83..0000000000 --- a/ecal/core/include/ecal/types/ecal_internal_options.h +++ /dev/null @@ -1,107 +0,0 @@ -/* =========================== LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * =========================== LICENSE ================================= - */ - -/** - * @file ecal_internal_options.h - * @brief eCAL options for internal configuration -**/ - -namespace eCAL -{ - constexpr int LAYER_NONE = 0x0000; - constexpr int LAYER_UDP_UDP_MC = 0x0010; - constexpr int LAYER_UDP_TCP = 0x0011; - constexpr int LAYER_SHM = 0x0020; - constexpr int LAYER_INMEMORY = 0x0030; - - enum class NetworkTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP - }; - - enum class LocalTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP, - tlayer_shm = LAYER_SHM - }; - - enum class InprocTransportLayer - { - tlayer_none = LAYER_NONE, - tlayer_udp_mc = LAYER_UDP_UDP_MC, - tlayer_tcp = LAYER_UDP_TCP, - tlayer_shm = LAYER_SHM, - tlayer_inmemory = LAYER_INMEMORY - }; - - struct eCAL_UDP_MC_Publisher_Options - { - - }; - - struct eCAL_TCP_Publisher_Options - { - // should we go as far as to put the TCP address and port here? - NO only user options - // both pub/sub need to know - }; - - struct eCAL_SHM_Publisher_Options - { - bool enable_zero_copy; - - long buffer_count; // 1 .. x - long long acknowledge_timeout_ms; // -1 -> no timeout (or directly std::chrono? - - // should we go as far as to put the memory filename (base) here? - No - // however, part of it will be communicated via the registration layer, invisible to the user - }; - - struct PublisherOptions - { - eCAL_UDP_MC_Publisher_Options udp_mc_options; - eCAL_TCP_Publisher_Options tcp_options; - eCAL_SHM_Publisher_Options shm_options; - - InprocTransportLayer inproc_layer; - LocalTransportLayer local_layer; - NetworkTransportLayer network_layer; - - bool share_topic_information = true; - }; - - struct SubscriberOptions - { - InprocTransportLayer inproc_layer; - LocalTransportLayer local_layer; - NetworkTransportLayer network_layer; - - bool share_topic_information = true; - }; - - // TODO PG: Clarify how to handle these - struct InternalConfig - { - SubscriberOptions subscriber_options; - PublisherOptions publisher_options; - }; -} \ No newline at end of file From a8da1ce545b5e2bccd527920905da581abb33911 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:18:24 +0200 Subject: [PATCH 038/105] Introduced logging options. --- .../include/ecal/types/ecal_config_types.h | 3 +- .../include/ecal/types/ecal_logging_options.h | 40 +++++++++++++++++++ .../ecal/types/ecal_monitoring_options.h | 5 --- .../src/config/ecal_config_initializer.cpp | 8 ++-- ecal/core/src/ecal_def.h | 5 +-- ecal/core/src/logging/ecal_log_impl.cpp | 6 +-- .../tests/cpp/config_test/src/config_test.cpp | 4 +- 7 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 ecal/core/include/ecal/types/ecal_logging_options.h diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 5d35ee1e67..a5647e9103 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -31,7 +31,7 @@ #include "ecal_receiving_options.h" #include "ecal_registration_options.h" #include "ecal_service_options.h" -#include "ecal_internal_options.h" +#include "ecal_logging_options.h" #include "ecal_transport_layer_options.h" #include "ecal/ecal_os.h" @@ -56,6 +56,7 @@ namespace eCAL TimesyncOptions timesync_options; ServiceOptions service_options; ApplicationOptions application_options; + LoggingOptions logging_options; std::string loaded_ecal_ini_file; ECAL_API eCALConfig(); diff --git a/ecal/core/include/ecal/types/ecal_logging_options.h b/ecal/core/include/ecal/types/ecal_logging_options.h new file mode 100644 index 0000000000..cf0798cb4e --- /dev/null +++ b/ecal/core/include/ecal/types/ecal_logging_options.h @@ -0,0 +1,40 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_logging_options.h + * @brief eCAL options for logging configuration +**/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Config + { + struct LoggingOptions + { + eCAL_Logging_Filter filter_log_con; + eCAL_Logging_Filter filter_log_file; + eCAL_Logging_Filter filter_log_udp; + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index b3f3ccbd62..cbe297c6e9 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -26,8 +26,6 @@ #include "ecal_custom_data_types.h" -#include - namespace eCAL { namespace Config @@ -62,9 +60,6 @@ namespace eCAL std::string filter_excl; std::string filter_incl; - eCAL_Logging_Filter filter_log_con; - eCAL_Logging_Filter filter_log_file; - eCAL_Logging_Filter filter_log_udp; }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index bd11a8b90b..02aefba938 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -152,9 +152,6 @@ namespace eCAL monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); monitoringOptions.filter_incl = iniConfig.get(MONITORING, "filter_incl", MON_FILTER_INCL); - monitoringOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); - monitoringOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); - monitoringOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); // auto& udpMonitoringOptions = monitoringOptions.udp_options; // TODO: Nothing here yet @@ -192,6 +189,11 @@ namespace eCAL auto& processOptions = config.application_options.process_options; processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); + auto& loggingOptions = config.logging_options; + loggingOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); + loggingOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); + loggingOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); + return config; }; diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index cfc23f85be..50b6ba29f7 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -50,9 +50,6 @@ constexpr const char* MON_FILTER_EXCL = "^__.*$"; constexpr const char* MON_FILTER_INCL = ""; /* logging filter settings */ -constexpr const char* MON_LOG_FILTER_CON = "info,warning,error,fatal"; -constexpr const char* MON_LOG_FILTER_FILE = ""; -constexpr const char* MON_LOG_FILTER_UDP = "info,warning,error,fatal"; constexpr eCAL_Logging_Filter MON_LOG_FILTER_CON = (log_level_info | log_level_warning | log_level_error | log_level_fatal); constexpr eCAL_Logging_Filter MON_LOG_FILTER_FILE = log_level_none; constexpr eCAL_Logging_Filter MON_LOG_FILTER_UDP = (log_level_info | log_level_warning | log_level_error | log_level_fatal); @@ -71,7 +68,7 @@ constexpr const char* SYS_FILTER_EXCL = "^eCALSysClient$|^eCALSysGUI$|^eCALS constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -constexpr eCAL::Config::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = "v1"; +constexpr eCAL::Config::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = eCAL::Config::UdpConfigVersion::V1; constexpr const char* NET_UDP_MULTICAST_GROUP = "239.0.0.1"; constexpr const char* NET_UDP_MULTICAST_MASK = "0.0.0.15"; constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000U; diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index 6f3516fc27..c26af35828 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -120,9 +120,9 @@ namespace eCAL m_level = log_level_info; // parse logging filter strings - m_filter_mask_con = Config::GetCurrentConfig()->monitoring_options.filter_log_con; - m_filter_mask_file = Config::GetCurrentConfig()->monitoring_options.filter_log_file; - m_filter_mask_udp = Config::GetCurrentConfig()->monitoring_options.filter_log_udp; + m_filter_mask_con = Config::GetCurrentConfig()->logging_options.filter_log_con; + m_filter_mask_file = Config::GetCurrentConfig()->logging_options.filter_log_file; + m_filter_mask_udp = Config::GetCurrentConfig()->logging_options.filter_log_udp; // create log file if(m_filter_mask_file != 0) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index cc23efb9cc..27dee8a22f 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -52,8 +52,8 @@ TEST(core_cpp_config, user_config_passing) custom_config.monitoring_options.monitoring_timeout = mon_timeout; custom_config.monitoring_options.filter_excl = mon_filter_excl; - custom_config.monitoring_options.filter_log_con = mon_log_filter_con; custom_config.monitoring_options.monitoring_mode = monitoring_mode; + custom_config.logging_options.filter_log_con = mon_log_filter_con; // Publisher options eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; @@ -87,7 +87,7 @@ TEST(core_cpp_config, user_config_passing) EXPECT_EQ(mon_filter_excl, eCAL::Config::GetCurrentConfig()->monitoring_options.filter_excl); // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) - EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig()->monitoring_options.filter_log_con); + EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig()->logging_options.filter_log_con); // Test monitoring mode assignment, default iseCAL::Config::MonitoringMode::none EXPECT_EQ(monitoring_mode, eCAL::Config::GetCurrentConfig()->monitoring_options.monitoring_mode); From 2dc3cbcc9c643a6925888648fcec78d3378a4f1f Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:26:38 +0200 Subject: [PATCH 039/105] Renamed ProcessOptions to StartupOptions. --- ecal/core/src/config/ecal_config_initializer.cpp | 2 +- ecal/core/src/ecal_process.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 02aefba938..b89db94900 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -186,7 +186,7 @@ namespace eCAL sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); // process options - auto& processOptions = config.application_options.process_options; + auto& processOptions = config.application_options.startup_options; processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); auto& loggingOptions = config.logging_options; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index f86943de39..f3cce66e11 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -649,7 +649,7 @@ namespace // -------------------- terminal_emulator command check -------------------- - const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->application_options.process_options.terminal_emulator; + const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->application_options.startup_options.terminal_emulator; if (!terminal_emulator_command.empty()) { STD_COUT_DEBUG("[PID " << getpid() << "]: " << "ecal.ini terminal emulator command is: " << terminal_emulator_command << std::endl); From b2af134a865ee03f4152a8fe736a6c97897d8a12 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 9 Apr 2024 09:51:33 +0200 Subject: [PATCH 040/105] Renamed ProcessOptions to StartupOptions in application_options.h. --- ecal/core/include/ecal/types/ecal_application_options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h index 0dda3b4787..c2a0bb821e 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -35,7 +35,7 @@ namespace eCAL std::string filter_excl; }; - struct ProcessOptions + struct StartupOptions { std::string terminal_emulator; }; @@ -43,7 +43,7 @@ namespace eCAL struct ApplicationOptions { SysOptions sys_options; - ProcessOptions process_options; + StartupOptions startup_options; }; } } \ No newline at end of file From 71cc7e523a8f2d420516fdb8363832c4234ec8ea Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 9 Apr 2024 09:52:18 +0200 Subject: [PATCH 041/105] Adapted IpAddressV4 to exclude some addresses. Added test cases. --- .../ecal/types/ecal_custom_data_types.h | 8 ++-- .../core/src/types/ecal_custom_data_types.cpp | 42 +++++++++++++------ .../tests/cpp/config_test/src/config_test.cpp | 40 +++++++++++++++++- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index f20a8321c2..5c138fed5e 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -28,7 +28,6 @@ #include #include -#include #include namespace eCAL @@ -36,7 +35,8 @@ namespace eCAL namespace Config { /** - * @brief Class for evaluation and storing an IP address. + * @brief Class for evaluation and storing an IPv4/IPv6 address. + * Invalid addresses: 255.255.255.255, 127.0.0.1, 0.0.0.0 * * @param ip_adress_ The IP address as std::string. **/ @@ -49,9 +49,9 @@ namespace eCAL std::string get() const { return m_ip_address; } private: - static bool checkIpString(std::string ip_address_); + static bool validateIpString(std::string ip_address_); - std::string m_ip_address{}; + std::string m_ip_address{}; }; /** diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 42217249ee..3e55fa6088 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -22,6 +22,20 @@ **/ #include "ecal/types/ecal_custom_data_types.h" +#include +#include +#include +#include + +namespace{ + static const std::array INVALID_IPV4_ADDRESSES = { + std::regex("((255|[fF][fF])\\.){3}(255|[fF][fF])"), // 255.255.255.255 + std::regex("((127|7[fF]).((0|00|000)\\.){2}(1|01|001))"), // 127.0.0.1 + std::regex("((0|00|000)\\.){3}(0|00|000)") // 0.0.0.0 + }; + static const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"); + static const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"); +} namespace eCAL { @@ -34,31 +48,35 @@ namespace eCAL IpAddressV4::IpAddressV4(const std::string& ip_address_) { - if (checkIpString(ip_address_)) + if (validateIpString(ip_address_)) { m_ip_address = ip_address_; } else { - std::cerr << "[IpAddressV4] No valid IPv4 address: " << ip_address_ << "\n"; + std::cerr << "[IpAddressV4] No valid IP address: " << ip_address_ << "\n"; exit(EXIT_FAILURE); } } - bool IpAddressV4::checkIpString(std::string ip_address_) + bool IpAddressV4::validateIpString(std::string ip_address_) { - if (std::regex_match(ip_address_, std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"))) - { - return true; - } - else if (std::regex_match(ip_address_, std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"))) + if ( std::regex_match(ip_address_, IPV4_DEC_REGEX) + || std::regex_match(ip_address_, IPV4_HEX_REGEX) + ) { + for (auto& inv_ip_regex : INVALID_IPV4_ADDRESSES) + { + if (std::regex_match(ip_address_, inv_ip_regex)) + { + return false; + } + } + return true; } - else - { - return false; - } + + return false; } } } diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 27dee8a22f..d4b34e1efc 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -53,7 +53,7 @@ TEST(core_cpp_config, user_config_passing) custom_config.monitoring_options.monitoring_timeout = mon_timeout; custom_config.monitoring_options.filter_excl = mon_filter_excl; custom_config.monitoring_options.monitoring_mode = monitoring_mode; - custom_config.logging_options.filter_log_con = mon_log_filter_con; + custom_config.logging_options.filter_log_con = mon_log_filter_con; // Publisher options eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; @@ -112,6 +112,44 @@ TEST(ConfigDeathTest, user_config_death_test) SetValue(custom_config.transport_layer_options.mc_options.group, std::string("42")), ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + // Test the IpAddressV4 class with invalid addresses + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("256.0.0.0")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("127.0.0.1")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("255.255.255.255")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FFF.FF.FF.FF")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FF.FF.FF.FF")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("Ff.fF.ff.Ff")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("7f.0.0.1")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.0.0.0")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("00.00.00.00")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("000.000.000.000")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + EXPECT_EXIT( + SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.00.000.0")), + ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + + // Test the LimitSize class with wrong values. Default are MIN = 5242880, STEP = 1024 // Value below MIN EXPECT_EXIT( From 3c7b05d6ea55b9f8d03043c18eaedd467d3424df Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:25:13 +0200 Subject: [PATCH 042/105] Reverted changes to ecal.cpp and ecal_globals.cpp. --- ecal/core/include/ecal/ecal_core.h | 5 ++- ecal/core/src/ecal.cpp | 11 ++----- ecal/core/src/ecal_globals.cpp | 31 ++++++++++++------- .../tests/cpp/config_test/src/config_test.cpp | 7 ++--- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index 36d094879f..a49a8054c6 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -31,7 +31,6 @@ #include #include -#include "ecal/types/ecal_config_types.h" namespace eCAL { @@ -70,7 +69,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - ECAL_API int Initialize(int argc_ = 0, char** argv_ = nullptr, const char* unit_name_ = nullptr, unsigned int components_ = Init::Default, Config::eCALConfig* = nullptr); + ECAL_API int Initialize(int argc_ = 0, char **argv_ = nullptr, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); /** * @brief Initialize eCAL API. @@ -81,7 +80,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - ECAL_API int Initialize(std::vector args_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default, Config::eCALConfig* user_settings_ = nullptr); + ECAL_API int Initialize(std::vector args_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); /** * @brief Finalize eCAL API. diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 2d89ed0e4f..6e11a674ec 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -97,7 +97,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_, Config::eCALConfig* user_config_) + int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) { bool dump_config(false); std::vector config_keys; @@ -180,11 +180,6 @@ namespace eCAL } g_globals_ctx_ref_cnt++; - if (user_config_ != nullptr) - { - g_globals()->SetUserConfig(*user_config_); - } - // (post)initialize single components const int success = g_globals()->Initialize(components_, &config_keys); @@ -206,12 +201,12 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - int Initialize(std::vector args_, const char *unit_name_, unsigned int components_, Config::eCALConfig* user_settings_) //-V826 + int Initialize(std::vector args_, const char *unit_name_, unsigned int components_) //-V826 { args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); std::vector argv(args_.size()); std::transform(args_.begin(), args_.end(), argv.begin(), [](std::string& s) {return s.c_str();}); - return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_, user_settings_); + return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_); } /** diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 7e3035d299..634fdfc3b2 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -45,11 +45,6 @@ namespace eCAL Finalize(Init::All); } - void CGlobals::SetUserConfig(Config::eCALConfig& user_config_) - { - ecal_config_instance = std::make_unique(user_config_); - } - int CGlobals::Initialize(unsigned int components_, std::vector* config_keys_ /*= nullptr*/) { // will be set if any new module was initialized @@ -58,13 +53,28 @@ namespace eCAL ///////////////////// // CONFIG ///////////////////// - if (ecal_config_instance == nullptr) + if (config_instance == nullptr) { - ecal_config_instance = std::make_unique(); - - if (config_keys_) + config_instance = std::make_unique(); + if (config_keys_ != nullptr) + { + config_instance->OverwriteKeys(*config_keys_); + } + config_instance->AddFile(g_default_ini_file); + + if (!config_instance->Validate()) { - // Config key handling here + const std::string emsg("Core initialization failed cause by a configuration error."); + + std::cerr << '\n'; + std::cerr << "----------------------------------------------------------" << '\n'; + std::cerr << "eCAL CORE PANIC :-(" << '\n'; + std::cerr << '\n'; + std::cerr << emsg << '\n'; + std::cerr << "----------------------------------------------------------" << '\n'; + std::cerr << '\n'; + + throw std::runtime_error(emsg.c_str()); } new_initialization = true; @@ -353,7 +363,6 @@ namespace eCAL #endif log_instance = nullptr; config_instance = nullptr; - ecal_config_instance.reset(); initialized = false; diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index d4b34e1efc..46b50ad53b 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -45,8 +45,8 @@ TEST(core_cpp_config, user_config_passing) custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; // Monitoring options - unsigned int mon_timeout = 6000U; - std::string mon_filter_excl = "_A.*"; + unsigned int mon_timeout = 6000U; + std::string mon_filter_excl = "_A.*"; eCAL_Logging_Filter mon_log_filter_con = log_level_warning; eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; @@ -145,11 +145,10 @@ TEST(ConfigDeathTest, user_config_death_test) EXPECT_EXIT( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("000.000.000.000")), ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + EXPECT_EXIT( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.00.000.0")), ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - // Test the LimitSize class with wrong values. Default are MIN = 5242880, STEP = 1024 // Value below MIN EXPECT_EXIT( From 3db1f9d0e4c597ba89ee0a04b2ad41e862d1c932 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:41:15 +0200 Subject: [PATCH 043/105] ecal_config as reference, not pointer. --- ecal/core/src/ecal_global_accessors.cpp | 5 ++--- ecal/core/src/ecal_global_accessors.h | 2 +- ecal/core/src/ecal_globals.h | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index 2a03313819..55d1d67a5e 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -64,10 +64,9 @@ namespace eCAL return(g_globals()->log().get()); } - Config::eCALConfig* g_ecal_config() + Config::eCALConfig& g_ecal_config() { - if (g_globals() == nullptr) return(nullptr); - return(g_globals()->ecal_config().get()); + return(g_globals()->ecal_config()); } #if ECAL_CORE_MONITORING diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 002867feed..707504c3cd 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -68,7 +68,7 @@ namespace eCAL CGlobals* g_globals(); CConfig* g_config(); CLog* g_log(); - Config::eCALConfig* g_ecal_config(); + Config::eCALConfig& g_ecal_config(); #if ECAL_CORE_MONITORING CMonitoring* g_monitoring(); #endif diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index 5fa2dc5ad1..dc9bb1a053 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -73,7 +73,7 @@ namespace eCAL const std::unique_ptr& config() { return config_instance; }; const std::unique_ptr& log() { return log_instance; }; - const std::unique_ptr& ecal_config() { return ecal_config_instance; }; + Config::eCALConfig& ecal_config() { return ecal_config_instance; }; #if ECAL_CORE_MONITORING const std::unique_ptr& monitoring() { return monitoring_instance; }; @@ -133,6 +133,6 @@ namespace eCAL #endif std::unique_ptr descgate_instance; - std::unique_ptr ecal_config_instance; + Config::eCALConfig ecal_config_instance; }; } From f3bbc964aa659fee2c5213152fb284b60d365278 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:56:07 +0200 Subject: [PATCH 044/105] Review 1: Config not as ptr. Optimized handling. Clangtidy happiness. --- app/mon/mon_gui/src/ecalmon.cpp | 4 +- .../ecalmon_tree_widget/topic_widget.cpp | 4 +- .../src/tui/viewmodel/command_line.hpp | 2 +- .../rec_client_core/src/job/record_job.cpp | 2 +- .../import_from_cloud_widget.cpp | 4 +- ecal/core/CMakeLists.txt | 1 + ecal/core/include/ecal/ecal_config.h | 2 +- ecal/core/include/ecal/ecal_core.h | 11 ++ .../ecal/types/ecal_application_options.h | 8 +- .../include/ecal/types/ecal_config_types.h | 26 ++-- .../ecal/types/ecal_custom_data_types.h | 9 +- .../include/ecal/types/ecal_logging_options.h | 6 +- .../ecal/types/ecal_monitoring_options.h | 18 +-- .../ecal/types/ecal_publisher_options.h | 6 +- .../ecal/types/ecal_receiving_options.h | 6 +- .../include/ecal/types/ecal_service_options.h | 6 +- .../ecal/types/ecal_transport_layer_options.h | 50 ++++---- ecal/core/src/config/ecal_cmd_parser.cpp | 69 +++++++++++ ecal/core/src/config/ecal_cmd_parser.h | 47 ++++++++ .../src/config/ecal_config_initializer.cpp | 54 ++++++--- ecal/core/src/ecal.cpp | 114 ++++++------------ ecal/core/src/ecal_descgate.cpp | 4 +- ecal/core/src/ecal_global_accessors.cpp | 31 +++++ ecal/core/src/ecal_global_accessors.h | 2 + ecal/core/src/ecal_globals.cpp | 37 +----- ecal/core/src/ecal_globals.h | 2 +- ecal/core/src/ecal_process.cpp | 32 ++--- .../src/io/udp/ecal_udp_configurations.cpp | 28 ++--- ecal/core/src/logging/ecal_log_impl.cpp | 12 +- .../src/monitoring/ecal_monitoring_impl.cpp | 14 +-- ecal/core/src/readwrite/ecal_reader.cpp | 20 +-- ecal/core/src/readwrite/ecal_writer.cpp | 24 ++-- .../src/readwrite/shm/ecal_reader_shm.cpp | 2 +- .../src/readwrite/shm/ecal_writer_shm.cpp | 6 +- .../src/readwrite/tcp/ecal_reader_tcp.cpp | 4 +- .../src/readwrite/tcp/ecal_writer_tcp.cpp | 2 +- .../src/readwrite/udp/ecal_reader_udp_mc.cpp | 2 +- .../src/readwrite/udp/ecal_writer_udp_mc.cpp | 2 +- .../ecal_registration_provider.cpp | 12 +- .../ecal_registration_receiver.cpp | 10 +- .../ecal_registration_receiver_shm.cpp | 2 +- .../src/service/ecal_service_server_impl.cpp | 8 +- ecal/core/src/time/ecal_timegate.cpp | 2 +- .../core/src/types/ecal_custom_data_types.cpp | 32 ++--- .../tests/cpp/config_test/src/config_test.cpp | 56 +++++++-- 45 files changed, 478 insertions(+), 317 deletions(-) create mode 100644 ecal/core/src/config/ecal_cmd_parser.cpp create mode 100644 ecal/core/src/config/ecal_cmd_parser.h diff --git a/app/mon/mon_gui/src/ecalmon.cpp b/app/mon/mon_gui/src/ecalmon.cpp index d2d72446bc..4978f23fa4 100644 --- a/app/mon/mon_gui/src/ecalmon.cpp +++ b/app/mon/mon_gui/src/ecalmon.cpp @@ -93,8 +93,8 @@ Ecalmon::Ecalmon(QWidget *parent) network_mode_warning_icon_->setPixmap(warning_icon); network_mode_warning_icon_->setVisible(false); - bool network_mode = eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled; - int multicast_ttl = eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.ttl; + bool network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled; + int multicast_ttl = eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; if (network_mode) { diff --git a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp index 42fe13710a..1f3d738f48 100644 --- a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp +++ b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp @@ -187,9 +187,9 @@ void TopicWidget::loadRegExpLists() QString exclude_string; QString include_string; - exclude_string = QString::fromStdString(eCAL::Config::GetCurrentConfig()->monitoring_options.filter_excl); + exclude_string = QString::fromStdString(eCAL::Config::GetCurrentConfig().monitoring_options.filter_excl); - include_string = QString::fromStdString(eCAL::Config::GetCurrentConfig()->monitoring_options.filter_incl); + include_string = QString::fromStdString(eCAL::Config::GetCurrentConfig().monitoring_options.filter_incl); // The ecal.ini defines a very strange regex format: A filter consists of diff --git a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp index 3d081935e3..665cbd9df0 100644 --- a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp +++ b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp @@ -115,7 +115,7 @@ class CommandLineViewModel : public ViewModel { using namespace std::placeholders; - network_mode = eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled ? "cloud" : "local"; + network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled ? "cloud" : "local"; is_polling_time = true; time_updater = std::thread(std::bind(&CommandLineViewModel::UpdateCurrentEcalTime, this)); diff --git a/app/rec/rec_client_core/src/job/record_job.cpp b/app/rec/rec_client_core/src/job/record_job.cpp index fa4c0a1704..8bbd285d70 100644 --- a/app/rec/rec_client_core/src/job/record_job.cpp +++ b/app/rec/rec_client_core/src/job/record_job.cpp @@ -171,7 +171,7 @@ namespace eCAL #undef CopyFile #endif // CopyFile { - std::string ecal_ini_original_path = Config::GetCurrentConfig()->loaded_ecal_ini_file; + std::string ecal_ini_original_path = Config::GetCurrentConfig().loaded_ecal_ini_file; if (ecal_ini_original_path.empty()) { diff --git a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp index cdabeb82a8..b8e0cda663 100644 --- a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp +++ b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp @@ -927,8 +927,8 @@ void ImportFromCloudWidget::loadExcludeTasksFilter() QFile default_cfg_file(default_cfg_file_path.c_str()); if (default_cfg_file.exists()) { - std::regex reg(eCAL::Config::GetCurrentConfig()->application_options.sys_options.filter_excl, std::regex::icase); - exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig()->application_options.sys_options.filter_excl.empty(); + std::regex reg(eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl, std::regex::icase); + exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl.empty(); exclude_tasks_regex_ = reg; } } diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 95ee793558..b57bae99cc 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -70,6 +70,7 @@ set(ecal_config_src src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h src/config/ecal_config_initializer.cpp + src/config/ecal_cmd_parser.cpp src/types/ecal_custom_data_types.cpp ) diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 14daa4e3b0..c35cdd0ba4 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -33,7 +33,7 @@ namespace eCAL namespace Config { - ECAL_API eCALConfig* GetCurrentConfig(); + ECAL_API eCALConfig& GetCurrentConfig(); ///////////////////////////////////// // common diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index a49a8054c6..0fea741f6e 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -31,6 +31,7 @@ #include #include +#include namespace eCAL { @@ -82,6 +83,16 @@ namespace eCAL **/ ECAL_API int Initialize(std::vector args_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); + /** + * @brief Initialize eCAL API. + * + * @param config_ User defined configuration object. + * @param components_ Defines which component to initialize. + * + * @return Zero if succeeded, 1 if already initialized, -1 if failed. + **/ + ECAL_API int Initialize(eCAL::Config::eCALConfig& config_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); + /** * @brief Finalize eCAL API. * diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h index c2a0bb821e..d1270de4e7 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -32,18 +32,18 @@ namespace eCAL { struct SysOptions { - std::string filter_excl; + std::string filter_excl{}; }; struct StartupOptions { - std::string terminal_emulator; + std::string terminal_emulator{}; }; struct ApplicationOptions { - SysOptions sys_options; - StartupOptions startup_options; + SysOptions sys_options{}; + StartupOptions startup_options{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index a5647e9103..2a6de54dd7 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -48,18 +48,22 @@ namespace eCAL { struct eCALConfig { - TransportLayerOptions transport_layer_options; - RegistrationOptions registration_options; - MonitoringOptions monitoring_options; - ReceivingOptions receiving_options; - PublisherOptions publisher_options; - TimesyncOptions timesync_options; - ServiceOptions service_options; - ApplicationOptions application_options; - LoggingOptions logging_options; - std::string loaded_ecal_ini_file; + TransportLayerOptions transport_layer_options{}; + RegistrationOptions registration_options{}; + MonitoringOptions monitoring_options{}; + ReceivingOptions receiving_options{}; + PublisherOptions publisher_options{}; + TimesyncOptions timesync_options{}; + ServiceOptions service_options{}; + ApplicationOptions application_options{}; + LoggingOptions logging_options{}; + std::string loaded_ecal_ini_file{}; + std::vector config_keys{}; + + ECAL_API eCALConfig(int argc_ , char **argv_); - ECAL_API eCALConfig(); + private: + void InitConfig(); }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 5c138fed5e..275dfc9d46 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -47,11 +47,15 @@ namespace eCAL ECAL_API IpAddressV4(const std::string& ip_address_); std::string get() const { return m_ip_address; } + + void operator=(IpAddressV4& other) { this->m_ip_address = other.get(); }; + void operator=(const std::string& other) { this->validateIpString(other); }; private: - static bool validateIpString(std::string ip_address_); + ECAL_API void validateIpString(const std::string& ip_address_); + void exitApp(const std::string& ip_adress_ = std::string("")); - std::string m_ip_address{}; + std::string m_ip_address; }; /** @@ -83,6 +87,7 @@ namespace eCAL int get() const { return m_size; }; bool operator==(const LimitSize& other) const { return this->m_size == other.get(); }; + void operator=(const LimitSize& other) { this->m_size = other.get(); }; friend bool operator==(const LimitSize& lhs, const int& rhs) { return lhs.get() == rhs; }; friend bool operator==(const int& lhs, const LimitSize& rhs) { return rhs == lhs; }; friend bool operator==(const LimitSize& lhs, const unsigned int& rhs) { return lhs.get() == static_cast(rhs); }; diff --git a/ecal/core/include/ecal/types/ecal_logging_options.h b/ecal/core/include/ecal/types/ecal_logging_options.h index cf0798cb4e..e48c9a70a3 100644 --- a/ecal/core/include/ecal/types/ecal_logging_options.h +++ b/ecal/core/include/ecal/types/ecal_logging_options.h @@ -32,9 +32,9 @@ namespace eCAL { struct LoggingOptions { - eCAL_Logging_Filter filter_log_con; - eCAL_Logging_Filter filter_log_file; - eCAL_Logging_Filter filter_log_udp; + eCAL_Logging_Filter filter_log_con{}; + eCAL_Logging_Filter filter_log_file{}; + eCAL_Logging_Filter filter_log_udp{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index cbe297c6e9..a31e29062b 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -46,20 +46,20 @@ namespace eCAL struct SHMMonitoringOptions { - std::string shm_monitoring_domain; - size_t shm_monitoring_queue_size; + std::string shm_monitoring_domain{}; + size_t shm_monitoring_queue_size{}; }; struct MonitoringOptions { - eCAL_MonitoringMode_Filter monitoring_mode; - LimitSize<1000, 1000> monitoring_timeout; - bool network_monitoring; - UDPMonitoringOptions udp_options; - SHMMonitoringOptions shm_options; + eCAL_MonitoringMode_Filter monitoring_mode{}; + LimitSize<1000, 1000> monitoring_timeout{}; + bool network_monitoring{}; + UDPMonitoringOptions udp_options{}; + SHMMonitoringOptions shm_options{}; - std::string filter_excl; - std::string filter_incl; + std::string filter_excl{}; + std::string filter_incl{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_publisher_options.h b/ecal/core/include/ecal/types/ecal_publisher_options.h index fb6f3b0b2c..9d3a24f86d 100644 --- a/ecal/core/include/ecal/types/ecal_publisher_options.h +++ b/ecal/core/include/ecal/types/ecal_publisher_options.h @@ -32,9 +32,9 @@ namespace eCAL { struct PublisherOptions { - TLayer::eSendMode use_shm; - TLayer::eSendMode use_tcp; - TLayer::eSendMode use_udp_mc; + TLayer::eSendMode use_shm{}; + TLayer::eSendMode use_tcp{}; + TLayer::eSendMode use_udp_mc{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_receiving_options.h b/ecal/core/include/ecal/types/ecal_receiving_options.h index 122744fa02..f2ec6da035 100644 --- a/ecal/core/include/ecal/types/ecal_receiving_options.h +++ b/ecal/core/include/ecal/types/ecal_receiving_options.h @@ -30,9 +30,9 @@ namespace eCAL { struct ReceivingOptions { - bool shm_recv_enabled; - bool tcp_recv_enabled; - bool udp_mc_recv_enabled; + bool shm_recv_enabled{}; + bool tcp_recv_enabled{}; + bool udp_mc_recv_enabled{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_service_options.h b/ecal/core/include/ecal/types/ecal_service_options.h index 4eb2dcb15f..e7b3457713 100644 --- a/ecal/core/include/ecal/types/ecal_service_options.h +++ b/ecal/core/include/ecal/types/ecal_service_options.h @@ -32,13 +32,13 @@ namespace eCAL { struct ServiceOptions { - bool protocol_v0; - bool protocol_v1; + bool protocol_v0{}; + bool protocol_v1{}; }; struct TimesyncOptions { - std::string timesync_module; + std::string timesync_module{}; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 0b92144423..0f7e1b9e35 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -32,44 +32,44 @@ namespace eCAL { struct TCPubsubOptions { - size_t num_executor_reader; - size_t num_executor_writer; - size_t max_reconnections; + size_t num_executor_reader{}; + size_t num_executor_writer{}; + size_t max_reconnections{}; }; struct SHMOptions { - std::string host_group_name; - LimitSize<4096, 4096> memfile_minsize; - LimitSize<50, 1, 100> memfile_reserve; - int memfile_ack_timeout; - LimitSize<0, 1> memfile_buffer_count; - bool drop_out_of_order_messages; - bool memfile_zero_copy; + std::string host_group_name{}; + LimitSize<4096, 4096> memfile_minsize{}; + LimitSize<50, 1, 100> memfile_reserve{}; + int memfile_ack_timeout{}; + LimitSize<0, 1> memfile_buffer_count{}; + bool drop_out_of_order_messages{}; + bool memfile_zero_copy{}; }; struct UdpMulticastOptions { - UdpConfigVersion config_version; - IpAddressV4 group; - IpAddressV4 mask; - LimitSize<14000, 10> port; - unsigned int ttl; - LimitSize<5242880, 1024> sndbuf; - LimitSize<5242880, 1024> recbuf; - bool join_all_interfaces; + UdpConfigVersion config_version{}; + IpAddressV4 group{}; + IpAddressV4 mask{}; + LimitSize<14000, 10> port{}; + unsigned int ttl{}; + LimitSize<5242880, 1024> sndbuf{}; + LimitSize<5242880, 1024> recbuf{}; + bool join_all_interfaces{}; - int bandwidth_max_udp; - bool npcap_enabled; + int bandwidth_max_udp{}; + bool npcap_enabled{}; }; struct TransportLayerOptions { - bool network_enabled; - bool drop_out_of_order_messages; - UdpMulticastOptions mc_options; - TCPubsubOptions tcp_options; - SHMOptions shm_options; + bool network_enabled{}; + bool drop_out_of_order_messages{}; + UdpMulticastOptions mc_options{}; + TCPubsubOptions tcp_options{}; + SHMOptions shm_options{}; }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp new file mode 100644 index 0000000000..26cbcd00fd --- /dev/null +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -0,0 +1,69 @@ +#include "config/ecal_cmd_parser.h" + +#include "ecal/ecal_defs.h" +#include "ecal_def.h" +#if ECAL_CORE_COMMAND_LINE + #include "util/advanced_tclap_output.h" +#endif + +#include "ecal_global_accessors.h" + +namespace eCAL +{ + namespace Config + { + CmdParser::CmdParser(int argc_ , char **argv_) + : m_dump_config{false} + , m_config_keys{std::vector()} + { +#if ECAL_CORE_COMMAND_LINE + if ((argc_ > 0) && (argv_ != nullptr)) + { + // define command line object + TCLAP::CmdLine cmd("", ' ', ECAL_VERSION); + + // define command line arguments + TCLAP::SwitchArg dump_config_arg ("", "ecal-dump-config", "Dump current configuration.", false); + TCLAP::ValueArg default_ini_file_arg("", "ecal-ini-file", "Load default configuration from that file.", false, ECAL_DEFAULT_CFG, "string"); + TCLAP::MultiArg set_config_key_arg ("", "ecal-set-config-key", "Overwrite a specific configuration key (ecal-set-config-key \"section/key:value\".", false, "string"); + + TCLAP::UnlabeledMultiArg dummy_arg("__dummy__", "Dummy", false, ""); // Dummy arg to eat all unrecognized arguments + + cmd.add(dump_config_arg); + cmd.add(default_ini_file_arg); + cmd.add(set_config_key_arg); + cmd.add(dummy_arg); + + CustomTclap::AdvancedTclapOutput advanced_tclap_output(&std::cout, 75); + advanced_tclap_output.setArgumentHidden(&dummy_arg, true); + cmd.setOutput(&advanced_tclap_output); + + // parse command line + cmd.parse(argc_, argv_); + + // set globals + if (dump_config_arg.isSet()) + { + m_dump_config = true; + } + if (default_ini_file_arg.isSet()) + { + g_default_ini_file = default_ini_file_arg.getValue(); + } + if (set_config_key_arg.isSet()) + { + m_config_keys = set_config_key_arg.getValue(); + } + } +#endif + if (argv_ != nullptr) + { + for (size_t i = 0; i < static_cast(argc_); ++i) if (argv_[i] != nullptr) m_task_parameter.emplace_back(argv_[i]); + } + } + + CmdParser::~CmdParser() + { + } + } +} diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h new file mode 100644 index 0000000000..ac84f18e61 --- /dev/null +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -0,0 +1,47 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 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 ================================= +*/ + +/** + * @brief Utility class for parsing cmd line arguments into eCAL useful structures. +**/ + +#include +#include + +namespace eCAL +{ + namespace Config + { + class CmdParser + { + public: + CmdParser(int argc_ , char **argv_); + ~CmdParser(); + + bool dumpConfig() const { return m_dump_config; }; + std::vector& getConfigKeys() { return m_config_keys; }; + std::vector& getTaskParameter() { return m_task_parameter; }; + + private: + std::vector m_config_keys; + bool m_dump_config; + std::vector m_task_parameter; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index b89db94900..629dcf58ee 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -22,12 +22,14 @@ **/ #include "ecal/ecal_config.h" -#include "ecal_config_reader.h" #include "ecal_global_accessors.h" #include "ecal_def.h" #include "config/ecal_config_reader.h" +#include "ecal/ecal_process.h" +#include "config/ecal_cmd_parser.h" + constexpr char COMMON[] = "common"; constexpr char MONITORING[] = "monitoring"; constexpr char NETWORK[] = "network"; @@ -94,13 +96,21 @@ namespace eCAL { namespace Config { - eCALConfig GetIniConfig(eCALConfig& config) + void eCALConfig::InitConfig() { CConfig iniConfig; + iniConfig.OverwriteKeys(config_keys); iniConfig.AddFile(g_default_ini_file); + // g_default_ini_file will be altered in case the loading is successful + // otherwise config.loaded_ecal_ini_file will stay empty + if (g_default_ini_file != ECAL_DEFAULT_CFG) + { + loaded_ecal_ini_file = g_default_ini_file; + } + // transport layer options - auto& transportLayerOptions = config.transport_layer_options; + auto& transportLayerOptions = transport_layer_options; transportLayerOptions.network_enabled = iniConfig.get(NETWORK, "network_enabled", NET_ENABLED); transportLayerOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", EXP_DROP_OUT_OF_ORDER_MESSAGES); @@ -139,13 +149,13 @@ namespace eCAL // registration options auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", CMN_REGISTRATION_TO); auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", CMN_REGISTRATION_REFRESH); - config.registration_options = RegistrationOptions(registrationTimeout, registrationRefresh); - auto& registrationOptions = config.registration_options; + registration_options = RegistrationOptions(registrationTimeout, registrationRefresh); + auto& registrationOptions = registration_options; registrationOptions.share_tdesc = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); registrationOptions.share_ttype = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); // monitoring options - auto& monitoringOptions = config.monitoring_options; + auto& monitoringOptions = monitoring_options; auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; @@ -161,49 +171,57 @@ namespace eCAL shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", EXP_SHM_MONITORING_QUEUE_SIZE); // receiving options - auto& receivingOptions = config.receiving_options; + auto& receivingOptions = receiving_options; receivingOptions.shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED); receivingOptions.tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED); receivingOptions.udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", NET_UDP_MC_REC_ENABLED); // publisher options - auto& publisherOptions = config.publisher_options; + auto& publisherOptions = publisher_options; publisherOptions.use_shm = static_cast(iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM))); publisherOptions.use_tcp = static_cast(iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP))); publisherOptions.use_udp_mc = static_cast(iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC))); // timesync options - auto& timesyncOptions = config.timesync_options; + auto& timesyncOptions = timesync_options; timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", TIME_SYNC_MODULE); // service options - auto& serviceOptions = config.service_options; + auto& serviceOptions = service_options; serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", SERVICE_PROTOCOL_V0); serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", SERVICE_PROTOCOL_V1); // sys options - auto& sysOptions = config.application_options.sys_options; + auto& sysOptions = application_options.sys_options; sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); // process options - auto& processOptions = config.application_options.startup_options; + auto& processOptions = application_options.startup_options; processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); - auto& loggingOptions = config.logging_options; + auto& loggingOptions = logging_options; + // needs to be adapted when switching from simpleini loggingOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); loggingOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); loggingOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); - - return config; }; - eCALConfig::eCALConfig() + eCALConfig::eCALConfig(int argc_ , char **argv_) { - GetIniConfig(*this); + CmdParser cmd_parser(argc_, argv_); + + config_keys = cmd_parser.getConfigKeys(); + + InitConfig(); + + if (cmd_parser.dumpConfig()) + { + Process::DumpConfig(); + } } // after initialization - eCALConfig* GetCurrentConfig() + eCALConfig& GetCurrentConfig() { return g_ecal_config(); }; diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 6e11a674ec..393064ebcd 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -24,6 +24,7 @@ #include "ecal_def.h" #include "ecal_event.h" #include "ecal_globals.h" +#include "config/ecal_cmd_parser.h" #include #include @@ -99,92 +100,32 @@ namespace eCAL **/ int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) { - bool dump_config(false); - std::vector config_keys; + eCAL::Config::CmdParser cmd_parser(argc_, argv_); -#if ECAL_CORE_COMMAND_LINE - if ((argc_ > 0) && (argv_ != nullptr)) + // in case of first call + if (g_globals_ctx == nullptr) { - // define command line object - TCLAP::CmdLine cmd("", ' ', ECAL_VERSION); - - // define command line arguments - TCLAP::SwitchArg dump_config_arg ("", "ecal-dump-config", "Dump current configuration.", false); - TCLAP::ValueArg default_ini_file_arg("", "ecal-ini-file", "Load default configuration from that file.", false, ECAL_DEFAULT_CFG, "string"); - TCLAP::MultiArg set_config_key_arg ("", "ecal-set-config-key", "Overwrite a specific configuration key (ecal-set-config-key \"section/key:value\".", false, "string"); - - TCLAP::UnlabeledMultiArg dummy_arg("__dummy__", "Dummy", false, ""); // Dummy arg to eat all unrecognized arguments - - cmd.add(dump_config_arg); - cmd.add(default_ini_file_arg); - cmd.add(set_config_key_arg); - cmd.add(dummy_arg); - - CustomTclap::AdvancedTclapOutput advanced_tclap_output(&std::cout, 75); - advanced_tclap_output.setArgumentHidden(&dummy_arg, true); - cmd.setOutput(&advanced_tclap_output); - - // parse command line - cmd.parse(argc_, argv_); - - // set globals - if (dump_config_arg.isSet()) - { - dump_config = true; - } - if (default_ini_file_arg.isSet()) - { - g_default_ini_file = default_ini_file_arg.getValue(); - } - if (set_config_key_arg.isSet()) - { - config_keys = set_config_key_arg.getValue(); - } + g_globals_ctx = new CGlobals(); } -#endif - // first call - if (g_globals_ctx == nullptr) + if (argc_ > 0 && argv_ != nullptr) { - g_globals_ctx = new CGlobals; + eCAL::Config::eCALConfig config(argc_, argv_); + g_globals()->SetEcalConfig(config); + } - if(unit_name_ != nullptr) g_unit_name = unit_name_; - if (g_unit_name.empty()) - { - g_unit_name = Process::GetProcessName(); -#ifdef ECAL_OS_WINDOWS - size_t p = g_unit_name.rfind('\\'); - if (p != std::string::npos) - { - g_unit_name = g_unit_name.substr(p+1); - } - p = g_unit_name.rfind('.'); - if (p != std::string::npos) - { - g_unit_name = g_unit_name.substr(0, p); - } -#endif -#ifdef ECAL_OS_LINUX - size_t p = g_unit_name.rfind('/'); - if (p != std::string::npos) - { - g_unit_name = g_unit_name.substr(p + 1); - } -#endif - } + if (unit_name_ != nullptr) + { + SetGlobalUnitName(unit_name_); + } - if (argv_ != nullptr) - { - for (size_t i = 0; i < static_cast(argc_); ++i) if (argv_[i] != nullptr) g_task_parameter.emplace_back(argv_[i]); - } - } g_globals_ctx_ref_cnt++; // (post)initialize single components - const int success = g_globals()->Initialize(components_, &config_keys); + const int success = g_globals()->Initialize(components_, &cmd_parser.getConfigKeys()); // print out configuration - if (dump_config) + if (cmd_parser.dumpConfig()) { Process::DumpConfig(); } @@ -209,6 +150,31 @@ namespace eCAL return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_); } + /** + * @brief Initialize eCAL API. + * + * @param config_ User defined configuration object. + * @param components_ Defines which component to initialize. + * + * @return Zero if succeeded, 1 if already initialized, -1 if failed. + **/ + int Initialize(eCAL::Config::eCALConfig& config_, const char *unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/) + { + if (g_globals() == nullptr) + { + g_globals_ctx = new CGlobals(); + } + + g_globals()->SetEcalConfig(config_); + + if (unit_name_ != nullptr) + { + SetGlobalUnitName(unit_name_); + } + + return Initialize(0, nullptr, unit_name_, components_); + } + /** * @brief Check eCAL initialize state. * diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index 0eae2f6c3c..bb5a084bd3 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -72,8 +72,8 @@ namespace namespace eCAL { CDescGate::CDescGate() : - m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), - m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())) + m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), + m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())) { } CDescGate::~CDescGate() = default; diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index 55d1d67a5e..a387d6b89c 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -47,6 +47,37 @@ namespace eCAL eCAL_Process_eSeverity g_process_severity(eCAL_Process_eSeverity::proc_sev_unknown); eCAL_Process_eSeverity_Level g_process_severity_level(eCAL_Process_eSeverity_Level::proc_sev_level1); + void SetGlobalUnitName(const char *unit_name_) + { + // There is a function already "SetUnitName" which sets the g_unit_name just as string. + // Used in global API. It does not have the following logic -> should that be added/removed/combined? + // For previous consistency this function is added here for the time being. + if(unit_name_ != nullptr) g_unit_name = unit_name_; + if (g_unit_name.empty()) + { + g_unit_name = Process::GetProcessName(); +#ifdef ECAL_OS_WINDOWS + size_t p = g_unit_name.rfind('\\'); + if (p != std::string::npos) + { + g_unit_name = g_unit_name.substr(p+1); + } + p = g_unit_name.rfind('.'); + if (p != std::string::npos) + { + g_unit_name = g_unit_name.substr(0, p); + } +#endif +#ifdef ECAL_OS_LINUX + size_t p = g_unit_name.rfind('/'); + if (p != std::string::npos) + { + g_unit_name = g_unit_name.substr(p + 1); + } +#endif + } + }; + CGlobals* g_globals() { return g_globals_ctx; diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 707504c3cd..9676c01f97 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -64,6 +64,8 @@ namespace eCAL class CMemFileMap; #endif + void SetGlobalUnitName(const char *unit_name_); + // Declaration of getter functions for globally accessible variable instances CGlobals* g_globals(); CConfig* g_config(); diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 634fdfc3b2..08591160b6 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -37,7 +37,7 @@ namespace eCAL { - CGlobals::CGlobals() : initialized(false), components(0) + CGlobals::CGlobals() : initialized(false), components(0), ecal_config_instance(0, nullptr) {} CGlobals::~CGlobals() @@ -45,41 +45,16 @@ namespace eCAL Finalize(Init::All); } + void CGlobals::SetEcalConfig(Config::eCALConfig& ecal_config_) + { + ecal_config_instance = ecal_config_; + } + int CGlobals::Initialize(unsigned int components_, std::vector* config_keys_ /*= nullptr*/) { // will be set if any new module was initialized bool new_initialization(false); - ///////////////////// - // CONFIG - ///////////////////// - if (config_instance == nullptr) - { - config_instance = std::make_unique(); - if (config_keys_ != nullptr) - { - config_instance->OverwriteKeys(*config_keys_); - } - config_instance->AddFile(g_default_ini_file); - - if (!config_instance->Validate()) - { - const std::string emsg("Core initialization failed cause by a configuration error."); - - std::cerr << '\n'; - std::cerr << "----------------------------------------------------------" << '\n'; - std::cerr << "eCAL CORE PANIC :-(" << '\n'; - std::cerr << '\n'; - std::cerr << emsg << '\n'; - std::cerr << "----------------------------------------------------------" << '\n'; - std::cerr << '\n'; - - throw std::runtime_error(emsg.c_str()); - } - - new_initialization = true; - } - #if ECAL_CORE_REGISTRATION ///////////////////// // REGISTRATION PROVIDER diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index dc9bb1a053..2078bde8c7 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -65,7 +65,7 @@ namespace eCAL int Initialize ( unsigned int components_, std::vector* config_keys_ = nullptr); bool IsInitialized ( unsigned int component_ ); - void SetUserConfig(Config::eCALConfig& user_config_); + void SetEcalConfig(Config::eCALConfig& ecal_config_); unsigned int GetComponents() const { return(components); }; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index f3cce66e11..ec86949ab0 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -165,14 +165,14 @@ namespace eCAL } sstream << "------------------------- CONFIGURATION --------------------------" << '\n'; - sstream << "Default INI : " << Config::GetCurrentConfig()->loaded_ecal_ini_file << '\n'; + sstream << "Default INI : " << Config::GetCurrentConfig().loaded_ecal_ini_file << '\n'; sstream << '\n'; sstream << "------------------------- NETWORK --------------------------------" << '\n'; sstream << "Host name : " << Process::GetHostName() << '\n'; sstream << "Host group name : " << Process::GetHostGroupName() << '\n'; - if (Config::GetCurrentConfig()->transport_layer_options.network_enabled) + if (Config::GetCurrentConfig().transport_layer_options.network_enabled) { sstream << "Network mode : cloud" << '\n'; } @@ -182,19 +182,19 @@ namespace eCAL } sstream << "Network ttl : " << UDP::GetMulticastTtl() << '\n'; - sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get()) << '\n'; - sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get()) << '\n'; - sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig()->transport_layer_options.mc_options.config_version) << '\n'; - sstream << "Multicast group : " << Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get() << '\n'; - sstream << "Multicast mask : " << Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get() << '\n'; - const int port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); + sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get()) << '\n'; + sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get()) << '\n'; + sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig().transport_layer_options.mc_options.config_version) << '\n'; + sstream << "Multicast group : " << Config::GetCurrentConfig().transport_layer_options.mc_options.group.get() << '\n'; + sstream << "Multicast mask : " << Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get() << '\n'; + const int port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); sstream << "Multicast ports : " << port << " - " << port + 10 << '\n'; - sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig()->transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << '\n'; + sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << '\n'; #if ECAL_CORE_TIMEPLUGIN sstream << "------------------------- TIME -----------------------------------" << '\n'; - sstream << "Synchronization realtime : " << Config::GetCurrentConfig()->timesync_options.timesync_module << '\n'; + sstream << "Synchronization realtime : " << Config::GetCurrentConfig().timesync_options.timesync_module << '\n'; sstream << "Synchronization replay : " << eCALPAR(TIME, SYNC_MOD_REPLAY) << '\n'; sstream << "State : "; if (g_timegate()->IsSynchronized()) sstream << " synchronized " << '\n'; @@ -210,16 +210,16 @@ namespace eCAL #endif #if ECAL_CORE_SUBSCRIBER sstream << "------------------------- SUBSCRIPTION LAYER DEFAULTS ------------" << '\n'; - sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig()->receiving_options.udp_mc_recv_enabled) << '\n'; - sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig()->transport_layer_options.drop_out_of_order_messages ? "on" : "off") << '\n'; + sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig().receiving_options.udp_mc_recv_enabled) << '\n'; + sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig().transport_layer_options.drop_out_of_order_messages ? "on" : "off") << '\n'; #endif #ifdef ECAL_NPCAP_SUPPORT - if(Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled && !Udpcap::Initialize()) + if(Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled && !Udpcap::Initialize()) { sstream << " (Init FAILED!)"; } #else // ECAL_CORE_NPCAP_SUPPORT - if (Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled) + if (Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled) { sstream << " (Npcap is enabled, but not configured via CMake!)"; } @@ -249,7 +249,7 @@ namespace eCAL std::string GetHostGroupName() { - return Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name.empty() ? GetHostName() : Config::GetCurrentConfig()->transport_layer_options.shm_options.host_group_name; + return Config::GetCurrentConfig().transport_layer_options.shm_options.host_group_name.empty() ? GetHostName() : Config::GetCurrentConfig().transport_layer_options.shm_options.host_group_name; } std::string GetUnitName() @@ -649,7 +649,7 @@ namespace // -------------------- terminal_emulator command check -------------------- - const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig()->application_options.startup_options.terminal_emulator; + const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig().application_options.startup_options.terminal_emulator; if (!terminal_emulator_command.empty()) { STD_COUT_DEBUG("[PID " << getpid() << "]: " << "ecal.ini terminal emulator command is: " << terminal_emulator_command << std::endl); diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index f7cbfa4498..bd692f74d5 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -37,7 +37,7 @@ namespace eCAL */ bool IsBroadcast() { - return !Config::GetCurrentConfig()->transport_layer_options.network_enabled; + return !Config::GetCurrentConfig().transport_layer_options.network_enabled; } /** @@ -47,7 +47,7 @@ namespace eCAL */ bool IsNpcapEnabled() { - return Config::GetCurrentConfig()->transport_layer_options.mc_options.npcap_enabled; + return Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled; } /** @@ -59,7 +59,7 @@ namespace eCAL */ bool IsUdpMulticastJoinAllIfEnabled() { - return Config::GetCurrentConfig()->transport_layer_options.mc_options.join_all_interfaces; + return Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces; } /** @@ -80,20 +80,20 @@ namespace eCAL std::string GetRegistrationAddress() { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; + const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; if (local_only) { return GetLocalBroadcastAddress(); } // both in v1 and v2, the multicast group is returned as the adress for the registration layer - return Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(); + return Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(); } int GetRegistrationPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_REG_OFF, to obtain the registration port return configured_port + NET_UDP_MULTICAST_PORT_REG_OFF; @@ -108,7 +108,7 @@ namespace eCAL int GetLoggingPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_LOG_OFF, to obtain the logging port return configured_port + NET_UDP_MULTICAST_PORT_LOG_OFF; @@ -123,7 +123,7 @@ namespace eCAL std::string GetTopicPayloadAddress(const std::string& topic_name) { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; + const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; if (local_only) { // if network is disabled, return the local broadcast address @@ -131,23 +131,23 @@ namespace eCAL } // determine the UDP multicast configuration version - if (Config::GetCurrentConfig()->transport_layer_options.mc_options.config_version == Config::UdpConfigVersion::V1) + if (Config::GetCurrentConfig().transport_layer_options.mc_options.config_version == Config::UdpConfigVersion::V1) { // retrieve the corresponding multicast address based on the topic name using v1 implementation - return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get()); + return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get()); } // v2 else { // retrieve the corresponding multicast address based on the topic name using v2 implementation - return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig()->transport_layer_options.mc_options.mask.get()); + return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get()); } } int GetPayloadPort() { // retrieve the configured UDP multicat port from the configuration - const int configured_port = Config::GetCurrentConfig()->transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); // add the specific offset, NET_UDP_MULTICAST_PORT_SAMPLE_OFF, to obtain the payload port return configured_port + NET_UDP_MULTICAST_PORT_SAMPLE_OFF; @@ -156,7 +156,7 @@ namespace eCAL int GetMulticastTtl() { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig()->transport_layer_options.network_enabled; + const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; if (local_only) { // if network is disabled, return a TTL of 0 to restrict multicast packets to the local machine @@ -164,7 +164,7 @@ namespace eCAL } // if network is enabled, return the configured UDP multicast TTL value - return Config::GetCurrentConfig()->transport_layer_options.mc_options.ttl; + return Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; } } } diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index c26af35828..610c76cb4b 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -120,9 +120,9 @@ namespace eCAL m_level = log_level_info; // parse logging filter strings - m_filter_mask_con = Config::GetCurrentConfig()->logging_options.filter_log_con; - m_filter_mask_file = Config::GetCurrentConfig()->logging_options.filter_log_file; - m_filter_mask_udp = Config::GetCurrentConfig()->logging_options.filter_log_udp; + m_filter_mask_con = Config::GetCurrentConfig().logging_options.filter_log_con; + m_filter_mask_file = Config::GetCurrentConfig().logging_options.filter_log_file; + m_filter_mask_udp = Config::GetCurrentConfig().logging_options.filter_log_udp; // create log file if(m_filter_mask_file != 0) @@ -146,7 +146,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = g_ecal_config()->transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = g_ecal_config().transport_layer_options.mc_options.sndbuf.get(); // create udp logging sender m_udp_logging_sender = std::make_unique(attr); @@ -158,7 +158,7 @@ namespace eCAL attr.port = UDP::GetLoggingPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = g_ecal_config()->transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = g_ecal_config().transport_layer_options.mc_options.recbuf.get(); // start logging receiver m_log_receiver = std::make_shared(attr, std::bind(&CLog::HasSample, this, std::placeholders::_1), std::bind(&CLog::ApplySample, this, std::placeholders::_1, std::placeholders::_2)); @@ -323,7 +323,7 @@ namespace eCAL { // in "network mode" we accept all log messages // in "local mode" we accept log messages from this host only - if ((m_hname == log_message.hname) || g_ecal_config()->transport_layer_options.network_enabled) + if ((m_hname == log_message.hname) || g_ecal_config().transport_layer_options.network_enabled) { const std::lock_guard lock(m_log_mtx); m_log_msglist.log_messages.emplace_back(log_message); diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp index d4294e2bc1..9fa524e246 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp @@ -43,11 +43,11 @@ namespace eCAL //////////////////////////////////////// CMonitoringImpl::CMonitoringImpl() : m_init(false), - m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), - m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), - m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), - m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())), - m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig()->monitoring_options.monitoring_timeout.get())) + m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), + m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), + m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), + m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), + m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())) { } @@ -63,8 +63,8 @@ namespace eCAL g_registration_receiver()->SetCustomApplySampleCallback("monitoring", [this](const auto& sample_){this->ApplySample(sample_, tl_none);}); // setup blacklist and whitelist filter strings# - m_topic_filter_excl_s = Config::GetCurrentConfig()->monitoring_options.filter_excl; - m_topic_filter_incl_s = Config::GetCurrentConfig()->monitoring_options.filter_incl; + m_topic_filter_excl_s = Config::GetCurrentConfig().monitoring_options.filter_excl; + m_topic_filter_incl_s = Config::GetCurrentConfig().monitoring_options.filter_incl; // setup filtering on by default SetFilterState(true); diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index eef333eeff..8c0ab4fd25 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -109,15 +109,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(Config::GetCurrentConfig()->registration_options.getTimeoutMS()); + const std::chrono::milliseconds registration_timeout(Config::GetCurrentConfig().registration_options.getTimeoutMS()); m_loc_pub_map.set_expiration(registration_timeout); m_ext_pub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::GetCurrentConfig()->registration_options.share_ttype; + m_use_ttype = Config::GetCurrentConfig().registration_options.share_ttype; // allow to share topic description - m_use_tdesc = Config::GetCurrentConfig()->registration_options.share_tdesc; + m_use_tdesc = Config::GetCurrentConfig().registration_options.share_tdesc; // start transport layers SubscribeToLayers(); @@ -176,7 +176,7 @@ namespace eCAL { // initialize udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) + if (g_ecal_config().receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->Initialize(); } @@ -184,7 +184,7 @@ namespace eCAL // initialize tcp layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config()->receiving_options.tcp_recv_enabled) + if (g_ecal_config().receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->Initialize(); } @@ -195,7 +195,7 @@ namespace eCAL { // subscribe topic to udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) + if (g_ecal_config().receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -203,7 +203,7 @@ namespace eCAL // subscribe topic to tcp layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config()->receiving_options.tcp_recv_enabled) + if (g_ecal_config().receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -214,7 +214,7 @@ namespace eCAL { // unsubscribe topic from udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config()->receiving_options.udp_mc_recv_enabled) + if (g_ecal_config().receiving_options.udp_mc_recv_enabled) { CUDPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -222,7 +222,7 @@ namespace eCAL // unsubscribe topic from tcp multicast layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config()->receiving_options.tcp_recv_enabled) + if (g_ecal_config().receiving_options.tcp_recv_enabled) { CTCPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -860,7 +860,7 @@ namespace eCAL // ----------------------------------- // drop messages in the wrong order // ----------------------------------- - if (Config::GetCurrentConfig()->transport_layer_options.drop_out_of_order_messages) + if (Config::GetCurrentConfig().transport_layer_options.drop_out_of_order_messages) { // do not update the internal clock counter diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index e35c35d34c..92fecac8b1 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -91,13 +91,13 @@ namespace eCAL { // initialize layer modes with configuration settings #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc_mode.requested = Config::GetCurrentConfig()->publisher_options.use_udp_mc; + m_writer.udp_mc_mode.requested = Config::GetCurrentConfig().publisher_options.use_udp_mc; #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm_mode.requested = Config::GetCurrentConfig()->publisher_options.use_shm; + m_writer.shm_mode.requested = Config::GetCurrentConfig().publisher_options.use_shm; #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp_mode.requested = Config::GetCurrentConfig()->publisher_options.use_tcp; + m_writer.tcp_mode.requested = Config::GetCurrentConfig().publisher_options.use_tcp; #endif } @@ -116,9 +116,9 @@ namespace eCAL m_topic_info = topic_info_; m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_buffer_count.get(); - m_zero_copy = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_zero_copy; - m_acknowledge_timeout_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; + m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count.get(); + m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; + m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; m_ext_subscribed = false; m_created = false; @@ -129,15 +129,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(g_ecal_config()->registration_options.getTimeoutMS()); + const std::chrono::milliseconds registration_timeout(g_ecal_config().registration_options.getTimeoutMS()); m_loc_sub_map.set_expiration(registration_timeout); m_ext_sub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::GetCurrentConfig()->registration_options.share_ttype; + m_use_ttype = Config::GetCurrentConfig().registration_options.share_ttype; // allow to share topic description - m_use_tdesc = Config::GetCurrentConfig()->registration_options.share_ttype; + m_use_tdesc = Config::GetCurrentConfig().registration_options.share_ttype; // mark as created m_created = true; @@ -192,9 +192,9 @@ namespace eCAL // reset defaults m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_buffer_count.get(); - m_zero_copy = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_zero_copy; - m_acknowledge_timeout_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; + m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count.get(); + m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; + m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; // reset subscriber maps diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp index 773e1451a1..2608f4804d 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp @@ -53,7 +53,7 @@ namespace eCAL std::placeholders::_6, std::placeholders::_7, std::placeholders::_8); - g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config()->registration_options.getTimeoutMS(), memfile_data_callback); + g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config().registration_options.getTimeoutMS(), memfile_data_callback); } } } diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 4f293edba8..81e15dd1cc 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -62,10 +62,10 @@ namespace eCAL m_write_idx = 0; // set attributes - m_memory_file_attr.min_size = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_minsize.get(); - m_memory_file_attr.reserve = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_reserve.get(); + m_memory_file_attr.min_size = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize.get(); + m_memory_file_attr.reserve = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve.get(); m_memory_file_attr.timeout_open_ms = PUB_MEMFILE_OPEN_TO; - m_memory_file_attr.timeout_ack_ms = Config::GetCurrentConfig()->transport_layer_options.shm_options.memfile_ack_timeout; + m_memory_file_attr.timeout_ack_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; // initialize memory file buffer m_created = SetBufferCount(m_buffer_count); diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp index aa46444569..b1e0edd06d 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp @@ -76,7 +76,7 @@ namespace eCAL // add new session and activate callback if we add the first session if (new_session) { - m_subscriber->addSession(host_name_, port_, static_cast(Config::GetCurrentConfig()->transport_layer_options.tcp_options.max_reconnections)); + m_subscriber->addSession(host_name_, port_, static_cast(Config::GetCurrentConfig().transport_layer_options.tcp_options.max_reconnections)); if (!m_callback_active) { m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1)); @@ -131,7 +131,7 @@ namespace eCAL void CTCPReaderLayer::Initialize() { const tcp_pubsub::logger::logger_t tcp_pubsub_logger = std::bind(TcpPubsubLogger, std::placeholders::_1, std::placeholders::_2); - m_executor = std::make_shared(Config::GetCurrentConfig()->transport_layer_options.tcp_options.num_executor_reader, tcp_pubsub_logger); + m_executor = std::make_shared(Config::GetCurrentConfig().transport_layer_options.tcp_options.num_executor_reader, tcp_pubsub_logger); } void CTCPReaderLayer::AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index 85401d1d7e..ed860e368b 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -69,7 +69,7 @@ namespace eCAL const std::lock_guard lock(g_tcp_writer_executor_mtx); if (!g_tcp_writer_executor) { - g_tcp_writer_executor = std::make_shared(Config::GetCurrentConfig()->transport_layer_options.tcp_options.num_executor_writer, TcpPubsubLogger); + g_tcp_writer_executor = std::make_shared(Config::GetCurrentConfig().transport_layer_options.tcp_options.num_executor_writer, TcpPubsubLogger); } } diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp index d7fe6e0ed2..6e54eacd25 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp @@ -61,7 +61,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get(); // 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)); diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index 41ac2ccebb..ca4874b51d 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -67,7 +67,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); - attr.sndbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get(); // create udp/sample sender with activated loop-back attr.loopback = true; diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 12f38d7712..1f4a919709 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -63,8 +63,8 @@ namespace eCAL if(m_created) return; // send registration to shared memory and to udp - m_use_registration_udp = Config::GetCurrentConfig()->monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; + m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; + m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; if (m_use_registration_udp) { @@ -75,7 +75,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get(); // create udp registration sender m_reg_sample_snd = std::make_shared(attr); @@ -84,15 +84,15 @@ namespace eCAL #if ECAL_CORE_REGISTRATION_SHM if (m_use_registration_shm) { - std::cout << "Shared memory monitoring is enabled (domain: " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain << " - queue size: " << Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size << ")" << '\n'; - m_memfile_broadcast.Create(Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size); + std::cout << "Shared memory monitoring is enabled (domain: " << Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain << " - queue size: " << Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size << ")" << '\n'; + m_memfile_broadcast.Create(Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size); m_memfile_broadcast_writer.Bind(&m_memfile_broadcast); } #endif // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(std::chrono::milliseconds(g_ecal_config()->registration_options.getRefreshMS())); + m_reg_sample_snd_thread->start(std::chrono::milliseconds(g_ecal_config().registration_options.getRefreshMS())); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index f38746ab36..ea8e0e47c6 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -70,12 +70,12 @@ namespace eCAL if(m_created) return; // network mode - m_network = g_ecal_config()->transport_layer_options.network_enabled; + m_network = g_ecal_config().transport_layer_options.network_enabled; // receive registration from shared memory and or udp // TODO PG: Adapt to new config management - m_use_registration_udp = Config::GetCurrentConfig()->monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig()->monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; + m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; + m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; if (m_use_registration_udp) { @@ -85,7 +85,7 @@ namespace eCAL attr.port = UDP::GetRegistrationPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig()->transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get(); // start registration sample receiver m_registration_receiver = std::make_shared(attr, std::bind(&CRegistrationReceiver::HasSample, this, std::placeholders::_1), std::bind(&CRegistrationReceiver::ApplySerializedSample, this, std::placeholders::_1, std::placeholders::_2)); @@ -94,7 +94,7 @@ namespace eCAL #if ECAL_CORE_REGISTRATION_SHM if (m_use_registration_shm) { - m_memfile_broadcast.Create(Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig()->monitoring_options.shm_options.shm_monitoring_queue_size); + m_memfile_broadcast.Create(Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size); m_memfile_broadcast.FlushLocalEventQueue(); m_memfile_broadcast_reader.Bind(&m_memfile_broadcast); diff --git a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp index 561874445d..0e70881b40 100644 --- a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp @@ -51,7 +51,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetCurrentConfig()->registration_options.getRefreshMS()/2)); + m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetCurrentConfig().registration_options.getRefreshMS()/2)); m_created = true; } diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index a8a2461915..18e11d23e6 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -114,13 +114,13 @@ namespace eCAL }; // start service protocol version 0 - if (Config::GetCurrentConfig()->service_options.protocol_v0) + if (Config::GetCurrentConfig().service_options.protocol_v0) { m_tcp_server_v0 = server_manager->create_server(0, 0, service_callback, true, event_callback); } // start service protocol version 1 - if (Config::GetCurrentConfig()->service_options.protocol_v1) + if (Config::GetCurrentConfig().service_options.protocol_v1) { m_tcp_server_v1 = server_manager->create_server(1, 0, service_callback, true, event_callback); } @@ -322,10 +322,10 @@ namespace eCAL // might be zero in contruction phase unsigned short const server_tcp_port_v0(m_tcp_server_v0 ? m_tcp_server_v0->get_port() : 0); - if ((Config::GetCurrentConfig()->service_options.protocol_v0) && (server_tcp_port_v0 == 0)) return; + if ((Config::GetCurrentConfig().service_options.protocol_v0) && (server_tcp_port_v0 == 0)) return; unsigned short const server_tcp_port_v1(m_tcp_server_v1 ? m_tcp_server_v1->get_port() : 0); - if ((Config::GetCurrentConfig()->service_options.protocol_v1) && (server_tcp_port_v1 == 0)) return; + if ((Config::GetCurrentConfig().service_options.protocol_v1) && (server_tcp_port_v1 == 0)) return; // create service registration sample Registration::Sample sample; diff --git a/ecal/core/src/time/ecal_timegate.cpp b/ecal/core/src/time/ecal_timegate.cpp index cc068677a6..1b11a03af6 100644 --- a/ecal/core/src/time/ecal_timegate.cpp +++ b/ecal/core/src/time/ecal_timegate.cpp @@ -85,7 +85,7 @@ namespace eCAL case eTimeSyncMode::none: break; case eTimeSyncMode::realtime: - m_time_sync_modname = Config::GetCurrentConfig()->timesync_options.timesync_module; + m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module; m_successfully_loaded_rt = LoadModule(m_time_sync_modname, m_time_sync_rt); break; case eTimeSyncMode::replay: diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 3e55fa6088..9b981ed99c 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace{ static const std::array INVALID_IPV4_ADDRESSES = { @@ -43,23 +44,15 @@ namespace eCAL { // IpAddressV4 definitions - - IpAddressV4::IpAddressV4() = default; + // TODO PG: Discuss default initialization + IpAddressV4::IpAddressV4() : IpAddressV4(NET_UDP_MULTICAST_GROUP) {}; IpAddressV4::IpAddressV4(const std::string& ip_address_) { - if (validateIpString(ip_address_)) - { - m_ip_address = ip_address_; - } - else - { - std::cerr << "[IpAddressV4] No valid IP address: " << ip_address_ << "\n"; - exit(EXIT_FAILURE); - } + validateIpString(ip_address_); } - bool IpAddressV4::validateIpString(std::string ip_address_) + void IpAddressV4::validateIpString(const std::string& ip_address_) { if ( std::regex_match(ip_address_, IPV4_DEC_REGEX) || std::regex_match(ip_address_, IPV4_HEX_REGEX) @@ -69,14 +62,23 @@ namespace eCAL { if (std::regex_match(ip_address_, inv_ip_regex)) { - return false; + exitApp(ip_address_); + return; } } - return true; + m_ip_address = ip_address_; + } + else + { + exitApp(ip_address_); } + } - return false; + void IpAddressV4::exitApp(const std::string& ip_address_ /*std::string("")*/) + { + std::cerr << "[IpAddressV4] No valid IP address: " << ip_address_ << "\n"; + exit(EXIT_FAILURE); } } } diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 46b50ad53b..b5a12bc1c9 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -30,7 +30,7 @@ void SetValue(MEMBER& member, VALUE value) TEST(core_cpp_config, user_config_passing) { - eCAL::Config::eCALConfig custom_config; + eCAL::Config::eCALConfig custom_config(0, nullptr); // Test value assignments from each category // How the user would utilize it @@ -69,35 +69,35 @@ TEST(core_cpp_config, user_config_passing) // Initialize ecal api with custom config - EXPECT_EQ(0, eCAL::Initialize(0, nullptr, "user_config_passing test", eCAL::Init::Default, &custom_config)); + EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); // Test boolean assignment, default is false - EXPECT_EQ(network_enabled, eCAL::Config::GetCurrentConfig()->transport_layer_options.network_enabled); + EXPECT_EQ(network_enabled, eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled); // Test IP address assignment, default is 239.0.0.1 - EXPECT_EQ(ip_address, eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.group.get()); + EXPECT_EQ(ip_address, eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.group.get()); // Test UDP send buffer assignment, default is 5242880 - EXPECT_EQ(upd_snd_buff, eCAL::Config::GetCurrentConfig()->transport_layer_options.mc_options.sndbuf); + EXPECT_EQ(upd_snd_buff, eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf); // Test monitoring timeout assignment, default is 5000U - EXPECT_EQ(mon_timeout, eCAL::Config::GetCurrentConfig()->monitoring_options.monitoring_timeout); + EXPECT_EQ(mon_timeout, eCAL::Config::GetCurrentConfig().monitoring_options.monitoring_timeout); // Test monitoring filter exclude assignment, default is "_.*" - EXPECT_EQ(mon_filter_excl, eCAL::Config::GetCurrentConfig()->monitoring_options.filter_excl); + EXPECT_EQ(mon_filter_excl, eCAL::Config::GetCurrentConfig().monitoring_options.filter_excl); // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) - EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig()->logging_options.filter_log_con); + EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig().logging_options.filter_log_con); // Test monitoring mode assignment, default iseCAL::Config::MonitoringMode::none - EXPECT_EQ(monitoring_mode, eCAL::Config::GetCurrentConfig()->monitoring_options.monitoring_mode); + EXPECT_EQ(monitoring_mode, eCAL::Config::GetCurrentConfig().monitoring_options.monitoring_mode); // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto - EXPECT_EQ(pub_use_shm, eCAL::Config::GetCurrentConfig()->publisher_options.use_shm); + EXPECT_EQ(pub_use_shm, eCAL::Config::GetCurrentConfig().publisher_options.use_shm); // Test registration option assignment, default timeout is 60000U and default refresh is 1000U - EXPECT_EQ(registration_timeout, eCAL::Config::GetCurrentConfig()->registration_options.getTimeoutMS()); - EXPECT_EQ(registration_refresh, eCAL::Config::GetCurrentConfig()->registration_options.getRefreshMS()); + EXPECT_EQ(registration_timeout, eCAL::Config::GetCurrentConfig().registration_options.getTimeoutMS()); + EXPECT_EQ(registration_refresh, eCAL::Config::GetCurrentConfig().registration_options.getRefreshMS()); // Finalize eCAL API EXPECT_EQ(0, eCAL::Finalize()); @@ -105,7 +105,7 @@ TEST(core_cpp_config, user_config_passing) TEST(ConfigDeathTest, user_config_death_test) { - eCAL::Config::eCALConfig custom_config; + eCAL::Config::eCALConfig custom_config(0, nullptr); // Test the IpAddressV4 class with wrong values EXPECT_EXIT( @@ -164,4 +164,34 @@ TEST(ConfigDeathTest, user_config_death_test) EXPECT_EXIT( SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); +} + +TEST(core_cpp_config, config_custom_datatypes) +{ + // test custom datatype assignment operators + eCAL::Config::IpAddressV4 ip1; + eCAL::Config::IpAddressV4 ip2; + EXPECT_EQ(ip1.get(), ip2.get()); + + ip1 = "192.168.0.2"; + ip2 = ip1; + EXPECT_EQ(ip1.get(), ip2.get()); + + eCAL::Config::LimitSize<0,1,10> s1; + eCAL::Config::LimitSize<0,1,10> s2; + EXPECT_EQ(s1.get(), s2.get()); + + s1 = 5; + s2 = s1; + EXPECT_EQ(s1.get(), s2.get()); + + // test copy method for config structure + eCAL::Config::eCALConfig config1(0, nullptr); + eCAL::Config::eCALConfig config2(0, nullptr); + std::string testValue = std::string("234.0.3.2"); + config2.transport_layer_options.mc_options.group = testValue; + auto& config2ref = config2; + config1 = config2ref; + + EXPECT_EQ(config1.transport_layer_options.mc_options.group.get(), testValue); } \ No newline at end of file From e0a1656101a8d22252dd9759604279efa4ff403d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:06:43 +0200 Subject: [PATCH 045/105] Changed constexpr in ecal_config_initializer.cpp --- .../src/config/ecal_config_initializer.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 629dcf58ee..bed6e4b00a 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -30,15 +30,15 @@ #include "ecal/ecal_process.h" #include "config/ecal_cmd_parser.h" -constexpr char COMMON[] = "common"; -constexpr char MONITORING[] = "monitoring"; -constexpr char NETWORK[] = "network"; -constexpr char EXPERIMENTAL[] = "experimental"; -constexpr char PUBLISHER[] = "publisher"; -constexpr char SYS[] = "sys"; -constexpr char TIME[] = "time"; -constexpr char SERVICE[] = "service"; -constexpr char PROCESS[] = "process"; +constexpr const char* COMMON = "common"; +constexpr const char* MONITORING = "monitoring"; +constexpr const char* NETWORK = "network"; +constexpr const char* EXPERIMENTAL = "experimental"; +constexpr const char* PUBLISHER = "publisher"; +constexpr const char* SYS = "sys"; +constexpr const char* TIME = "time"; +constexpr const char* SERVICE = "service"; +constexpr const char* PROCESS = "process"; namespace { void tokenize(const std::string& str, std::vector& tokens, From 063b4847fbf6899f2045d80868d0bceb3c3c040a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:24:41 +0200 Subject: [PATCH 046/105] Added some clang tidy improvements (e.g. usage of const) --- app/mon/mon_gui/src/ecalmon.cpp | 4 ++-- app/rec/rec_client_core/src/job/record_job.cpp | 2 +- .../import_from_cloud_widget.cpp | 2 +- ecal/core/include/ecal/types/ecal_custom_data_types.h | 2 +- ecal/core/src/config/ecal_cmd_parser.cpp | 4 +--- ecal/core/src/config/ecal_config_initializer.cpp | 9 +++++---- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/mon/mon_gui/src/ecalmon.cpp b/app/mon/mon_gui/src/ecalmon.cpp index 4978f23fa4..801de081cf 100644 --- a/app/mon/mon_gui/src/ecalmon.cpp +++ b/app/mon/mon_gui/src/ecalmon.cpp @@ -93,8 +93,8 @@ Ecalmon::Ecalmon(QWidget *parent) network_mode_warning_icon_->setPixmap(warning_icon); network_mode_warning_icon_->setVisible(false); - bool network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled; - int multicast_ttl = eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; + const bool network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled; + const int multicast_ttl = eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; if (network_mode) { diff --git a/app/rec/rec_client_core/src/job/record_job.cpp b/app/rec/rec_client_core/src/job/record_job.cpp index 8bbd285d70..b8443943dd 100644 --- a/app/rec/rec_client_core/src/job/record_job.cpp +++ b/app/rec/rec_client_core/src/job/record_job.cpp @@ -171,7 +171,7 @@ namespace eCAL #undef CopyFile #endif // CopyFile { - std::string ecal_ini_original_path = Config::GetCurrentConfig().loaded_ecal_ini_file; + const std::string ecal_ini_original_path = Config::GetCurrentConfig().loaded_ecal_ini_file; if (ecal_ini_original_path.empty()) { diff --git a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp index b8e0cda663..86fc04dd44 100644 --- a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp +++ b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp @@ -927,7 +927,7 @@ void ImportFromCloudWidget::loadExcludeTasksFilter() QFile default_cfg_file(default_cfg_file_path.c_str()); if (default_cfg_file.exists()) { - std::regex reg(eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl, std::regex::icase); + const std::regex reg(eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl, std::regex::icase); exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl.empty(); exclude_tasks_regex_ = reg; } diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 275dfc9d46..47eadf4158 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -53,7 +53,7 @@ namespace eCAL private: ECAL_API void validateIpString(const std::string& ip_address_); - void exitApp(const std::string& ip_adress_ = std::string("")); + void exitApp(const std::string& ip_address_ = std::string("")); std::string m_ip_address; }; diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 26cbcd00fd..ac6c895efb 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -62,8 +62,6 @@ namespace eCAL } } - CmdParser::~CmdParser() - { - } + CmdParser::~CmdParser() = default; } } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index bed6e4b00a..13d7fb361b 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -44,7 +44,8 @@ namespace { void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = " ", bool trimEmpty = false) { - std::string::size_type pos, lastPos = 0; + std::string::size_type pos = 0; + std::string::size_type lastPos = 0; for (;;) { @@ -54,7 +55,7 @@ namespace { pos = str.length(); if (pos != lastPos || !trimEmpty) { - tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); + tokens.emplace_back(str.data() + lastPos, pos - lastPos); } break; } @@ -62,7 +63,7 @@ namespace { { if (pos != lastPos || !trimEmpty) { - tokens.emplace_back(std::string(str.data() + lastPos, pos - lastPos)); + tokens.emplace_back(str.data() + lastPos, pos - lastPos); } } lastPos = pos + 1; @@ -156,7 +157,7 @@ namespace eCAL // monitoring options auto& monitoringOptions = monitoring_options; - auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) == true ? MonitoringMode::shm_monitoring : MonitoringMode::none; + auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? MonitoringMode::shm_monitoring : MonitoringMode::none; monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); From ceb4419d39f38845b12ec1a0935ed94ffe0e5eb0 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:06:25 +0200 Subject: [PATCH 047/105] Added operator int() to LimitSize. --- .../include/ecal/types/ecal_custom_data_types.h | 15 +++++---------- ecal/core/src/ecal_descgate.cpp | 4 ++-- ecal/core/src/ecal_process.cpp | 6 +++--- ecal/core/src/io/udp/ecal_udp_configurations.cpp | 6 +++--- ecal/core/src/logging/ecal_log_impl.cpp | 4 ++-- ecal/core/src/monitoring/ecal_monitoring_impl.cpp | 10 +++++----- ecal/core/src/readwrite/ecal_writer.cpp | 4 ++-- ecal/core/src/readwrite/shm/ecal_writer_shm.cpp | 4 ++-- .../core/src/readwrite/udp/ecal_reader_udp_mc.cpp | 2 +- .../core/src/readwrite/udp/ecal_writer_udp_mc.cpp | 2 +- .../registration/ecal_registration_provider.cpp | 2 +- .../registration/ecal_registration_receiver.cpp | 2 +- ecal/tests/cpp/config_test/src/config_test.cpp | 6 +++--- 13 files changed, 31 insertions(+), 36 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 47eadf4158..ecd001c483 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -48,7 +48,7 @@ namespace eCAL std::string get() const { return m_ip_address; } - void operator=(IpAddressV4& other) { this->m_ip_address = other.get(); }; + IpAddressV4(IpAddressV4& other) { this->m_ip_address = other.get(); }; void operator=(const std::string& other) { this->validateIpString(other); }; private: @@ -83,15 +83,10 @@ namespace eCAL exit(EXIT_FAILURE); } }; - - int get() const { return m_size; }; - - bool operator==(const LimitSize& other) const { return this->m_size == other.get(); }; - void operator=(const LimitSize& other) { this->m_size = other.get(); }; - friend bool operator==(const LimitSize& lhs, const int& rhs) { return lhs.get() == rhs; }; - friend bool operator==(const int& lhs, const LimitSize& rhs) { return rhs == lhs; }; - friend bool operator==(const LimitSize& lhs, const unsigned int& rhs) { return lhs.get() == static_cast(rhs); }; - friend bool operator==(const unsigned int& lhs, const LimitSize& rhs) { return rhs == lhs; }; + + LimitSize(const LimitSize& other) { this->m_size = other; }; + operator int() const { return m_size; }; + bool operator==(const LimitSize& other) const { return this->m_size == other; }; private: int m_size; diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index bb5a084bd3..b71e48e99f 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -72,8 +72,8 @@ namespace namespace eCAL { CDescGate::CDescGate() : - m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), - m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())) + m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), + m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)) { } CDescGate::~CDescGate() = default; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index ec86949ab0..21df84ca83 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -182,12 +182,12 @@ namespace eCAL } sstream << "Network ttl : " << UDP::GetMulticastTtl() << '\n'; - sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get()) << '\n'; - sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get()) << '\n'; + sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf) << '\n'; + sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf) << '\n'; sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig().transport_layer_options.mc_options.config_version) << '\n'; sstream << "Multicast group : " << Config::GetCurrentConfig().transport_layer_options.mc_options.group.get() << '\n'; sstream << "Multicast mask : " << Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get() << '\n'; - const int port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); + const int port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; sstream << "Multicast ports : " << port << " - " << port + 10 << '\n'; sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << '\n'; diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index bd692f74d5..07af20f940 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -93,7 +93,7 @@ namespace eCAL int GetRegistrationPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; // add the specific offset, NET_UDP_MULTICAST_PORT_REG_OFF, to obtain the registration port return configured_port + NET_UDP_MULTICAST_PORT_REG_OFF; @@ -108,7 +108,7 @@ namespace eCAL int GetLoggingPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; // add the specific offset, NET_UDP_MULTICAST_PORT_LOG_OFF, to obtain the logging port return configured_port + NET_UDP_MULTICAST_PORT_LOG_OFF; @@ -147,7 +147,7 @@ namespace eCAL int GetPayloadPort() { // retrieve the configured UDP multicat port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port.get(); + const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; // add the specific offset, NET_UDP_MULTICAST_PORT_SAMPLE_OFF, to obtain the payload port return configured_port + NET_UDP_MULTICAST_PORT_SAMPLE_OFF; diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index 610c76cb4b..815f80123b 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -146,7 +146,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = g_ecal_config().transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = g_ecal_config().transport_layer_options.mc_options.sndbuf; // create udp logging sender m_udp_logging_sender = std::make_unique(attr); @@ -158,7 +158,7 @@ namespace eCAL attr.port = UDP::GetLoggingPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = g_ecal_config().transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = g_ecal_config().transport_layer_options.mc_options.recbuf; // start logging receiver m_log_receiver = std::make_shared(attr, std::bind(&CLog::HasSample, this, std::placeholders::_1), std::bind(&CLog::ApplySample, this, std::placeholders::_1, std::placeholders::_2)); diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp index 9fa524e246..907d34d1d7 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp @@ -43,11 +43,11 @@ namespace eCAL //////////////////////////////////////// CMonitoringImpl::CMonitoringImpl() : m_init(false), - m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), - m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), - m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), - m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())), - m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout.get())) + m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), + m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), + m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), + m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), + m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)) { } diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 92fecac8b1..8eb8aee87f 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -116,7 +116,7 @@ namespace eCAL m_topic_info = topic_info_; m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count.get(); + m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; @@ -192,7 +192,7 @@ namespace eCAL // reset defaults m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count.get(); + m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; m_connected = false; diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 81e15dd1cc..48d17a9004 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -62,8 +62,8 @@ namespace eCAL m_write_idx = 0; // set attributes - m_memory_file_attr.min_size = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize.get(); - m_memory_file_attr.reserve = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve.get(); + m_memory_file_attr.min_size = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize; + m_memory_file_attr.reserve = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve; m_memory_file_attr.timeout_open_ms = PUB_MEMFILE_OPEN_TO; m_memory_file_attr.timeout_ack_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp index 6e54eacd25..a21fdad5e4 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp @@ -61,7 +61,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf; // 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)); diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index ca4874b51d..741dcdb371 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -67,7 +67,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); - attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf; // create udp/sample sender with activated loop-back attr.loopback = true; diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 1f4a919709..9cd792efd2 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -75,7 +75,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf.get(); + attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf; // create udp registration sender m_reg_sample_snd = std::make_shared(attr); diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index ea8e0e47c6..1bfcfbd869 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -85,7 +85,7 @@ namespace eCAL attr.port = UDP::GetRegistrationPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf.get(); + attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf; // start registration sample receiver m_registration_receiver = std::make_shared(attr, std::bind(&CRegistrationReceiver::HasSample, this, std::placeholders::_1), std::bind(&CRegistrationReceiver::ApplySerializedSample, this, std::placeholders::_1, std::placeholders::_2)); diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index b5a12bc1c9..123a79d973 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -78,7 +78,7 @@ TEST(core_cpp_config, user_config_passing) EXPECT_EQ(ip_address, eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.group.get()); // Test UDP send buffer assignment, default is 5242880 - EXPECT_EQ(upd_snd_buff, eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf); + EXPECT_EQ(upd_snd_buff, static_cast(eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf)); // Test monitoring timeout assignment, default is 5000U EXPECT_EQ(mon_timeout, eCAL::Config::GetCurrentConfig().monitoring_options.monitoring_timeout); @@ -179,11 +179,11 @@ TEST(core_cpp_config, config_custom_datatypes) eCAL::Config::LimitSize<0,1,10> s1; eCAL::Config::LimitSize<0,1,10> s2; - EXPECT_EQ(s1.get(), s2.get()); + EXPECT_EQ(static_cast(s1), static_cast(s2)); s1 = 5; s2 = s1; - EXPECT_EQ(s1.get(), s2.get()); + EXPECT_EQ(static_cast(s1), static_cast(s2)); // test copy method for config structure eCAL::Config::eCALConfig config1(0, nullptr); From 3a811a400201c3a77012bd6092284cec73d7bcda Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:30:44 +0200 Subject: [PATCH 048/105] Added operator std::string() to IpV4Address. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 9 +++++---- ecal/core/src/ecal_process.cpp | 4 ++-- ecal/core/src/io/udp/ecal_udp_configurations.cpp | 6 +++--- ecal/tests/cpp/config_test/src/config_test.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index ecd001c483..7e59a083a2 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -45,11 +45,12 @@ namespace eCAL public: ECAL_API IpAddressV4(); ECAL_API IpAddressV4(const std::string& ip_address_); - - std::string get() const { return m_ip_address; } + + IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; + IpAddressV4& operator=(const std::string& other) { this->validateIpString(other); return *this; }; + operator std::string() { return m_ip_address; }; - IpAddressV4(IpAddressV4& other) { this->m_ip_address = other.get(); }; - void operator=(const std::string& other) { this->validateIpString(other); }; + friend std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.m_ip_address; return os; }; private: ECAL_API void validateIpString(const std::string& ip_address_); diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 21df84ca83..693f7522f0 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -185,8 +185,8 @@ namespace eCAL sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf) << '\n'; sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf) << '\n'; sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig().transport_layer_options.mc_options.config_version) << '\n'; - sstream << "Multicast group : " << Config::GetCurrentConfig().transport_layer_options.mc_options.group.get() << '\n'; - sstream << "Multicast mask : " << Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get() << '\n'; + sstream << "Multicast group : " << Config::GetCurrentConfig().transport_layer_options.mc_options.group << '\n'; + sstream << "Multicast mask : " << Config::GetCurrentConfig().transport_layer_options.mc_options.mask << '\n'; const int port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; sstream << "Multicast ports : " << port << " - " << port + 10 << '\n'; sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << '\n'; diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index 07af20f940..72d75088ed 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -87,7 +87,7 @@ namespace eCAL } // both in v1 and v2, the multicast group is returned as the adress for the registration layer - return Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(); + return Config::GetCurrentConfig().transport_layer_options.mc_options.group; } int GetRegistrationPort() @@ -134,13 +134,13 @@ namespace eCAL if (Config::GetCurrentConfig().transport_layer_options.mc_options.config_version == Config::UdpConfigVersion::V1) { // retrieve the corresponding multicast address based on the topic name using v1 implementation - return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get()); + return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group, Config::GetCurrentConfig().transport_layer_options.mc_options.mask); } // v2 else { // retrieve the corresponding multicast address based on the topic name using v2 implementation - return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group.get(), Config::GetCurrentConfig().transport_layer_options.mc_options.mask.get()); + return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group, Config::GetCurrentConfig().transport_layer_options.mc_options.mask); } } diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 123a79d973..9e0574831b 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -75,7 +75,7 @@ TEST(core_cpp_config, user_config_passing) EXPECT_EQ(network_enabled, eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled); // Test IP address assignment, default is 239.0.0.1 - EXPECT_EQ(ip_address, eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.group.get()); + EXPECT_EQ(ip_address, static_cast(eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.group)); // Test UDP send buffer assignment, default is 5242880 EXPECT_EQ(upd_snd_buff, static_cast(eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf)); @@ -171,11 +171,11 @@ TEST(core_cpp_config, config_custom_datatypes) // test custom datatype assignment operators eCAL::Config::IpAddressV4 ip1; eCAL::Config::IpAddressV4 ip2; - EXPECT_EQ(ip1.get(), ip2.get()); + EXPECT_EQ(static_cast(ip1), static_cast(ip2)); ip1 = "192.168.0.2"; ip2 = ip1; - EXPECT_EQ(ip1.get(), ip2.get()); + EXPECT_EQ(static_cast(ip1), static_cast(ip2)); eCAL::Config::LimitSize<0,1,10> s1; eCAL::Config::LimitSize<0,1,10> s2; @@ -193,5 +193,5 @@ TEST(core_cpp_config, config_custom_datatypes) auto& config2ref = config2; config1 = config2ref; - EXPECT_EQ(config1.transport_layer_options.mc_options.group.get(), testValue); + EXPECT_EQ(static_cast(config1.transport_layer_options.mc_options.group), testValue); } \ No newline at end of file From 4893564e53723c26465349f4d2ec4bd5873194ac Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:11:58 +0200 Subject: [PATCH 049/105] Added default constructors to custom types classes. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 3 ++- ecal/core/src/types/ecal_custom_data_types.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 7e59a083a2..7740163f9d 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -44,7 +44,8 @@ namespace eCAL { public: ECAL_API IpAddressV4(); - ECAL_API IpAddressV4(const std::string& ip_address_); + ECAL_API IpAddressV4(const std::string& ip_address_); + ECAL_API ~IpAddressV4(); IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; IpAddressV4& operator=(const std::string& other) { this->validateIpString(other); return *this; }; diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 9b981ed99c..fb54006e6a 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -52,6 +52,8 @@ namespace eCAL validateIpString(ip_address_); } + IpAddressV4::~IpAddressV4() = default; + void IpAddressV4::validateIpString(const std::string& ip_address_) { if ( std::regex_match(ip_address_, IPV4_DEC_REGEX) From 32dfc18a84059092fcff13554621ca50c53eb20a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:13:47 +0200 Subject: [PATCH 050/105] ... also for Limitsize. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 7740163f9d..00636564c3 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -85,6 +85,8 @@ namespace eCAL exit(EXIT_FAILURE); } }; + + ~LimitSize() = default; LimitSize(const LimitSize& other) { this->m_size = other; }; operator int() const { return m_size; }; From 9395da538180edd1ee4a5abacb85c95efd630007 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:51:26 +0200 Subject: [PATCH 051/105] Added config example. --- .../ecal/types/ecal_custom_data_types.h | 2 +- ecal/samples/CMakeLists.txt | 1 + ecal/samples/cpp/misc/config/CMakeLists.txt | 44 +++++++++++++++ ecal/samples/cpp/misc/config/src/config.cpp | 53 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 ecal/samples/cpp/misc/config/CMakeLists.txt create mode 100644 ecal/samples/cpp/misc/config/src/config.cpp diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 00636564c3..585f658cda 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -38,7 +38,7 @@ namespace eCAL * @brief Class for evaluation and storing an IPv4/IPv6 address. * Invalid addresses: 255.255.255.255, 127.0.0.1, 0.0.0.0 * - * @param ip_adress_ The IP address as std::string. + * @param ip_address_ The IP address as std::string. **/ class IpAddressV4 { diff --git a/ecal/samples/CMakeLists.txt b/ecal/samples/CMakeLists.txt index 2ee63b3091..2a7be27e15 100644 --- a/ecal/samples/CMakeLists.txt +++ b/ecal/samples/CMakeLists.txt @@ -71,6 +71,7 @@ endif() # misc add_subdirectory(cpp/misc/process) add_subdirectory(cpp/misc/time) +add_subdirectory(cpp/misc/config) if(ECAL_CORE_PUBLISHER) add_subdirectory(cpp/misc/timer) endif() diff --git a/ecal/samples/cpp/misc/config/CMakeLists.txt b/ecal/samples/cpp/misc/config/CMakeLists.txt new file mode 100644 index 0000000000..8682a46616 --- /dev/null +++ b/ecal/samples/cpp/misc/config/CMakeLists.txt @@ -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 ================================= + +cmake_minimum_required(VERSION 3.10) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +project(config) + +find_package(eCAL REQUIRED) + +set(config_src + src/config.cpp +) + +ecal_add_sample(${PROJECT_NAME} ${config_src}) + +target_include_directories(${PROJECT_NAME} PRIVATE .) + +target_link_libraries (${PROJECT_NAME} + eCAL::core +) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) + +ecal_install_sample(${PROJECT_NAME}) + +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/misc) + diff --git a/ecal/samples/cpp/misc/config/src/config.cpp b/ecal/samples/cpp/misc/config/src/config.cpp new file mode 100644 index 0000000000..9956765d80 --- /dev/null +++ b/ecal/samples/cpp/misc/config/src/config.cpp @@ -0,0 +1,53 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include +#include + +#include + +int main(int argc, char **argv) +{ + // creating config object + eCAL::Config::eCALConfig my_config(argc, argv); + + // setting configuration + my_config.monitoring_options.network_monitoring = true; + // initialize eCAL API + eCAL::Initialize(my_config, "config sample"); + + unsigned int counter = 0; + // enter main loop + while(eCAL::Ok()) + { + // sleep 500 ms + eCAL::Process::SleepMS(500); + if (counter >= 10) + { + break; + } + + std::cout << "Finished loop " << ++counter << "\n"; + } + + // finalize eCAL API + eCAL::Finalize(); + + return(0); +} \ No newline at end of file From 482ae050358b3739f56ff638deed70c984790ec2 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:52:22 +0200 Subject: [PATCH 052/105] CGlobals initializing in global space. --- ecal/core/src/ecal.cpp | 4 ++-- ecal/core/src/ecal_global_accessors.cpp | 5 +++++ ecal/core/src/ecal_global_accessors.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 393064ebcd..9ad1254c72 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -105,7 +105,7 @@ namespace eCAL // in case of first call if (g_globals_ctx == nullptr) { - g_globals_ctx = new CGlobals(); + InitGlobals(); } if (argc_ > 0 && argv_ != nullptr) @@ -162,7 +162,7 @@ namespace eCAL { if (g_globals() == nullptr) { - g_globals_ctx = new CGlobals(); + InitGlobals(); } g_globals()->SetEcalConfig(config_); diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index a387d6b89c..d4122c0a5f 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -47,6 +47,11 @@ namespace eCAL eCAL_Process_eSeverity g_process_severity(eCAL_Process_eSeverity::proc_sev_unknown); eCAL_Process_eSeverity_Level g_process_severity_level(eCAL_Process_eSeverity_Level::proc_sev_level1); + void InitGlobals() + { + g_globals_ctx = new CGlobals; + } + void SetGlobalUnitName(const char *unit_name_) { // There is a function already "SetUnitName" which sets the g_unit_name just as string. diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 9676c01f97..18aa526640 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -65,6 +65,7 @@ namespace eCAL #endif void SetGlobalUnitName(const char *unit_name_); + void InitGlobals(); // Declaration of getter functions for globally accessible variable instances CGlobals* g_globals(); From 284f8733283d69d8d85f568b4f60cbf439f445e3 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:03:10 +0200 Subject: [PATCH 053/105] Adapted config sample. --- ecal/samples/cpp/misc/config/CMakeLists.txt | 4 ++-- .../cpp/misc/config/src/{config.cpp => config_sample.cpp} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename ecal/samples/cpp/misc/config/src/{config.cpp => config_sample.cpp} (100%) diff --git a/ecal/samples/cpp/misc/config/CMakeLists.txt b/ecal/samples/cpp/misc/config/CMakeLists.txt index 8682a46616..2aa52c6391 100644 --- a/ecal/samples/cpp/misc/config/CMakeLists.txt +++ b/ecal/samples/cpp/misc/config/CMakeLists.txt @@ -20,12 +20,12 @@ cmake_minimum_required(VERSION 3.10) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) -project(config) +project(config_sample) find_package(eCAL REQUIRED) set(config_src - src/config.cpp + src/config_sample.cpp ) ecal_add_sample(${PROJECT_NAME} ${config_src}) diff --git a/ecal/samples/cpp/misc/config/src/config.cpp b/ecal/samples/cpp/misc/config/src/config_sample.cpp similarity index 100% rename from ecal/samples/cpp/misc/config/src/config.cpp rename to ecal/samples/cpp/misc/config/src/config_sample.cpp From a18e9dee8edc060ccabc2048479bd93032846cc3 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:09:00 +0200 Subject: [PATCH 054/105] config_test.cpp const happiness for clangtidy. --- ecal/tests/cpp/config_test/src/config_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 9e0574831b..5ee15fce23 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -36,19 +36,19 @@ TEST(core_cpp_config, user_config_passing) // How the user would utilize it // Transport layer options - bool network_enabled = true; + const bool network_enabled = true; std::string ip_address = "238.200.100.2"; - int upd_snd_buff = (5242880 + 1024); + const int upd_snd_buff = (5242880 + 1024); custom_config.transport_layer_options.network_enabled = network_enabled; custom_config.transport_layer_options.mc_options.group = ip_address; custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; // Monitoring options - unsigned int mon_timeout = 6000U; - std::string mon_filter_excl = "_A.*"; - eCAL_Logging_Filter mon_log_filter_con = log_level_warning; - eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; + const unsigned int mon_timeout = 6000U; + const std::string mon_filter_excl = "_A.*"; + const eCAL_Logging_Filter mon_log_filter_con = log_level_warning; + const eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; custom_config.monitoring_options.monitoring_timeout = mon_timeout; custom_config.monitoring_options.filter_excl = mon_filter_excl; From 8da505e7d87d7e381a15bd97db9ebfe1308d020b Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:27:18 +0200 Subject: [PATCH 055/105] Added timesync_module_replay to config and removed eCALPar from timegate/process. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 3 ++- ecal/core/include/ecal/types/ecal_service_options.h | 3 ++- ecal/core/src/config/ecal_config_initializer.cpp | 3 ++- ecal/core/src/ecal_process.cpp | 4 ++-- ecal/core/src/time/ecal_timegate.cpp | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 585f658cda..4ab4d05a9f 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -91,9 +91,10 @@ namespace eCAL LimitSize(const LimitSize& other) { this->m_size = other; }; operator int() const { return m_size; }; bool operator==(const LimitSize& other) const { return this->m_size == other; }; + void operator=(const LimitSize& other) { this->m_size = other; }; private: - int m_size; + int m_size{}; }; enum class UdpConfigVersion diff --git a/ecal/core/include/ecal/types/ecal_service_options.h b/ecal/core/include/ecal/types/ecal_service_options.h index e7b3457713..802eecc17a 100644 --- a/ecal/core/include/ecal/types/ecal_service_options.h +++ b/ecal/core/include/ecal/types/ecal_service_options.h @@ -38,7 +38,8 @@ namespace eCAL struct TimesyncOptions { - std::string timesync_module{}; + std::string timesync_module_rt{}; + std::string timesync_module_replay{}; }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 13d7fb361b..9862a0aabd 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -185,7 +185,8 @@ namespace eCAL // timesync options auto& timesyncOptions = timesync_options; - timesyncOptions.timesync_module = iniConfig.get(TIME, "timesync_module_rt", TIME_SYNC_MODULE); + timesyncOptions.timesync_module_rt = iniConfig.get(TIME, "timesync_module_rt", TIME_SYNC_MODULE); + timesyncOptions.timesync_module_replay = iniConfig.get(TIME, "timesync_module_replay", TIME_SYNC_MOD_REPLAY); // service options auto& serviceOptions = service_options; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 693f7522f0..7ff88a3049 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -194,8 +194,8 @@ namespace eCAL #if ECAL_CORE_TIMEPLUGIN sstream << "------------------------- TIME -----------------------------------" << '\n'; - sstream << "Synchronization realtime : " << Config::GetCurrentConfig().timesync_options.timesync_module << '\n'; - sstream << "Synchronization replay : " << eCALPAR(TIME, SYNC_MOD_REPLAY) << '\n'; + sstream << "Synchronization realtime : " << Config::GetCurrentConfig().timesync_options.timesync_module_rt << '\n'; + sstream << "Synchronization replay : " << Config::GetCurrentConfig().timesync_options.timesync_module_replay << '\n'; sstream << "State : "; if (g_timegate()->IsSynchronized()) sstream << " synchronized " << '\n'; else sstream << " not synchronized " << '\n'; diff --git a/ecal/core/src/time/ecal_timegate.cpp b/ecal/core/src/time/ecal_timegate.cpp index 1b11a03af6..e97b8c989f 100644 --- a/ecal/core/src/time/ecal_timegate.cpp +++ b/ecal/core/src/time/ecal_timegate.cpp @@ -85,11 +85,11 @@ namespace eCAL case eTimeSyncMode::none: break; case eTimeSyncMode::realtime: - m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module; + m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module_rt; m_successfully_loaded_rt = LoadModule(m_time_sync_modname, m_time_sync_rt); break; case eTimeSyncMode::replay: - m_time_sync_modname = eCALPAR(TIME, SYNC_MOD_REPLAY); + m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module_replay; m_successfully_loaded_replay = LoadModule(m_time_sync_modname, m_time_sync_replay); break; } From 2e8b9d4c639a3b8b90a1086440d068cc704b4423 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:22:46 +0200 Subject: [PATCH 056/105] Made github-actions bot a bit happier. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 5 +++-- ecal/core/src/config/ecal_cmd_parser.cpp | 1 - ecal/core/src/config/ecal_cmd_parser.h | 1 - ecal/core/src/ecal_global_accessors.cpp | 2 +- ecal/core/src/ecal_process.cpp | 1 + ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp | 1 - ecal/core/src/registration/ecal_registration_provider.cpp | 2 +- ecal/core/src/registration/ecal_registration_receiver.cpp | 2 +- ecal/core/src/types/ecal_custom_data_types.cpp | 8 ++++---- ecal/tests/cpp/config_test/src/config_test.cpp | 8 ++++---- 10 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 4ab4d05a9f..de6172a108 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -48,6 +48,7 @@ namespace eCAL ECAL_API ~IpAddressV4(); IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; + IpAddressV4& operator=(IpAddressV4& other) { this->m_ip_address = other; return *this; }; IpAddressV4& operator=(const std::string& other) { this->validateIpString(other); return *this; }; operator std::string() { return m_ip_address; }; @@ -55,7 +56,7 @@ namespace eCAL private: ECAL_API void validateIpString(const std::string& ip_address_); - void exitApp(const std::string& ip_address_ = std::string("")); + static void exitApp(const std::string& ip_address_ = std::string("")); std::string m_ip_address; }; @@ -89,9 +90,9 @@ namespace eCAL ~LimitSize() = default; LimitSize(const LimitSize& other) { this->m_size = other; }; + LimitSize& operator=(const LimitSize& other) { this->m_size = other; return *this; }; operator int() const { return m_size; }; bool operator==(const LimitSize& other) const { return this->m_size == other; }; - void operator=(const LimitSize& other) { this->m_size = other; }; private: int m_size{}; diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index ac6c895efb..14910312a0 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -62,6 +62,5 @@ namespace eCAL } } - CmdParser::~CmdParser() = default; } } diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index ac84f18e61..5993b88c62 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -32,7 +32,6 @@ namespace eCAL { public: CmdParser(int argc_ , char **argv_); - ~CmdParser(); bool dumpConfig() const { return m_dump_config; }; std::vector& getConfigKeys() { return m_config_keys; }; diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index d4122c0a5f..efe17fee48 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -74,7 +74,7 @@ namespace eCAL } #endif #ifdef ECAL_OS_LINUX - size_t p = g_unit_name.rfind('/'); + const size_t p = g_unit_name.rfind('/'); if (p != std::string::npos) { g_unit_name = g_unit_name.substr(p + 1); diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 7ff88a3049..1995cca3c8 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -210,6 +210,7 @@ namespace eCAL #endif #if ECAL_CORE_SUBSCRIBER sstream << "------------------------- SUBSCRIPTION LAYER DEFAULTS ------------" << '\n'; + // TODO PG: This is probably the wrong struct and member. Which one is correct? sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig().receiving_options.udp_mc_recv_enabled) << '\n'; sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig().transport_layer_options.drop_out_of_order_messages ? "on" : "off") << '\n'; #endif diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index ed860e368b..ad78711648 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -25,7 +25,6 @@ #include "serialization/ecal_serialize_sample_payload.h" #include -#include "ecal/ecal_config.h" #include "ecal_writer_tcp.h" #include "ecal_tcp_pubsub_logger.h" diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 9cd792efd2..c168c3dc16 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -64,7 +64,7 @@ namespace eCAL // send registration to shared memory and to udp m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; + m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) != 0; if (m_use_registration_udp) { diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index 1bfcfbd869..bc2d63b2e8 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -75,7 +75,7 @@ namespace eCAL // receive registration from shared memory and or udp // TODO PG: Adapt to new config management m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) ? true : false; + m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) != 0; if (m_use_registration_udp) { diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index fb54006e6a..ca43c82359 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -29,13 +29,13 @@ #include namespace{ - static const std::array INVALID_IPV4_ADDRESSES = { + const std::array INVALID_IPV4_ADDRESSES = { std::regex("((255|[fF][fF])\\.){3}(255|[fF][fF])"), // 255.255.255.255 std::regex("((127|7[fF]).((0|00|000)\\.){2}(1|01|001))"), // 127.0.0.1 std::regex("((0|00|000)\\.){3}(0|00|000)") // 0.0.0.0 }; - static const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"); - static const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"); + const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"); + const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"); } namespace eCAL @@ -60,7 +60,7 @@ namespace eCAL || std::regex_match(ip_address_, IPV4_HEX_REGEX) ) { - for (auto& inv_ip_regex : INVALID_IPV4_ADDRESSES) + for (const auto& inv_ip_regex : INVALID_IPV4_ADDRESSES) { if (std::regex_match(ip_address_, inv_ip_regex)) { diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 5ee15fce23..c7cb41b359 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -56,14 +56,14 @@ TEST(core_cpp_config, user_config_passing) custom_config.logging_options.filter_log_con = mon_log_filter_con; // Publisher options - eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; + const eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; custom_config.publisher_options.use_shm = pub_use_shm; // Registration options - unsigned int registration_timeout = 80000U; - unsigned int registration_refresh = 2000U; - eCAL::Config::RegistrationOptions registration_options = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); + const unsigned int registration_timeout = 80000U; + const unsigned int registration_refresh = 2000U; + const eCAL::Config::RegistrationOptions registration_options = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); custom_config.registration_options = registration_options; From e7a96425dde918f6af9eab68a54e136060b23359 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:07:40 +0200 Subject: [PATCH 057/105] IpAddressV4 operator= improvement. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index de6172a108..8e814dd496 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -48,7 +48,7 @@ namespace eCAL ECAL_API ~IpAddressV4(); IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; - IpAddressV4& operator=(IpAddressV4& other) { this->m_ip_address = other; return *this; }; + IpAddressV4& operator=(IpAddressV4& const other) { this->m_ip_address = other; return *this; }; IpAddressV4& operator=(const std::string& other) { this->validateIpString(other); return *this; }; operator std::string() { return m_ip_address; }; From ddbbc99ba748dbe1db887c2a05a5cc01ca1815d2 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:56:21 +0200 Subject: [PATCH 058/105] Removed some PG TODOS. --- ecal/core/src/ecal_def_ini.h | 2 +- ecal/core/src/registration/ecal_registration_receiver.cpp | 1 - ecal/core/src/types/ecal_custom_data_types.cpp | 1 - ecal/samples/cpp/misc/config/src/config_sample.cpp | 1 + 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ecal/core/src/ecal_def_ini.h b/ecal/core/src/ecal_def_ini.h index 4beba06243..6bc65331e8 100644 --- a/ecal/core/src/ecal_def_ini.h +++ b/ecal/core/src/ecal_def_ini.h @@ -20,7 +20,7 @@ /** * @brief eCAL ini file keys **/ -// TODO PG: Delete - deprecated + #pragma once ///////////////////////////////////// diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index bc2d63b2e8..e4c3e245d4 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -73,7 +73,6 @@ namespace eCAL m_network = g_ecal_config().transport_layer_options.network_enabled; // receive registration from shared memory and or udp - // TODO PG: Adapt to new config management m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) != 0; diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index ca43c82359..34bbfe6b96 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -44,7 +44,6 @@ namespace eCAL { // IpAddressV4 definitions - // TODO PG: Discuss default initialization IpAddressV4::IpAddressV4() : IpAddressV4(NET_UDP_MULTICAST_GROUP) {}; IpAddressV4::IpAddressV4(const std::string& ip_address_) diff --git a/ecal/samples/cpp/misc/config/src/config_sample.cpp b/ecal/samples/cpp/misc/config/src/config_sample.cpp index 9956765d80..503802951d 100644 --- a/ecal/samples/cpp/misc/config/src/config_sample.cpp +++ b/ecal/samples/cpp/misc/config/src/config_sample.cpp @@ -29,6 +29,7 @@ int main(int argc, char **argv) // setting configuration my_config.monitoring_options.network_monitoring = true; + // initialize eCAL API eCAL::Initialize(my_config, "config sample"); From 10a3835c06e9e1afc283bcbb3b35712bce398358 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:09:53 +0200 Subject: [PATCH 059/105] Started with documentation adaptions for config. --- doc/rst/configuration.rst | 1 + .../configuration/runtime_configuration.rst | 21 +++++++++++++++++++ .../src/hello_config/CMakeLists.txt | 19 +++++++++++++++++ .../configuration/src/hello_config/main.cpp | 20 ++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 doc/rst/configuration/runtime_configuration.rst create mode 100644 doc/rst/configuration/src/hello_config/CMakeLists.txt create mode 100644 doc/rst/configuration/src/hello_config/main.cpp diff --git a/doc/rst/configuration.rst b/doc/rst/configuration.rst index 1b169bb224..3c361e3db9 100644 --- a/doc/rst/configuration.rst +++ b/doc/rst/configuration.rst @@ -14,3 +14,4 @@ Configuration configuration/npcap configuration/player configuration/options + configuration/runtime_configuration diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst new file mode 100644 index 0000000000..1a83ca8869 --- /dev/null +++ b/doc/rst/configuration/runtime_configuration.rst @@ -0,0 +1,21 @@ +.. include:: /include.txt + +.. __configuration_runtime_configuration: + +===================== +Runtime configuration +===================== + +eCAL provides an interface to access and modify its options before initialization. The corresponding structure reflects the configuration file (:ref:`configuration_options`). + +Initialization of the configuration +=================================== + +The configuration will be first initialized with the default .ini file found in the system. In case the .ini to use is specified vial command line parameter, this one is chosen instead. +If it cannot find any .ini file, default values will be used for the first initialization of the configuration. + +* |fa-file-alt| :file:`main.cpp`: + + .. literalinclude:: src/hello_config/main.cpp + :language: cpp + :linenos: \ No newline at end of file diff --git a/doc/rst/configuration/src/hello_config/CMakeLists.txt b/doc/rst/configuration/src/hello_config/CMakeLists.txt new file mode 100644 index 0000000000..dd21b4264e --- /dev/null +++ b/doc/rst/configuration/src/hello_config/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.0) +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +project(hello_config) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(eCAL REQUIRED) + +set(source_files + main.cpp +) + +add_executable(${PROJECT_NAME} ${source_files}) + +target_link_libraries(${PROJECT_NAME} + eCAL::core +) \ No newline at end of file diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp new file mode 100644 index 0000000000..287d33f45f --- /dev/null +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -0,0 +1,20 @@ +#include + +int main(int argc, char** argv) +{ + // Create a configuration object with the command line arguments + eCAL::Config::eCALConfig custom_config(argc, argv); + + // Set the communication layer to network + custom_config.transport_layer_options.network_enabled = true; + + // Initialize eCAL with the config + eCAL::Initialize(custom_config, "UserConfig", eCAL::Init::Default); + + // ... + // Use eCAL for your needs + // ... + + // Finalize eCAL API + eCAL::Finalize(); +} \ No newline at end of file From d19e55e71025fe5770ba8e2fcb6dbefa0c65ced1 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:15:00 +0200 Subject: [PATCH 060/105] Updated docu for config with types. --- .../configuration/runtime_configuration.rst | 39 ++++++++++++++++--- .../configuration/src/hello_config/main.cpp | 13 +++++-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 1a83ca8869..387dc5988e 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -1,21 +1,50 @@ .. include:: /include.txt -.. __configuration_runtime_configuration: +.. _configuration_runtime_configuration: ===================== Runtime configuration ===================== -eCAL provides an interface to access and modify its options before initialization. The corresponding structure reflects the configuration file (:ref:`configuration_options`). +eCAL provides an interface to access and modify its options before initialization. +The corresponding structure reflects the configuration file (:ref:`configuration_options`). + +Custom types +============ + +In order to exclude configuration errors, custom datatypes for IP addresses and sizes are introduced. + +For assigning an ip address simply assign a string with the desired address. +Decimal and hexadecimal format is supported. +In case the ip address is not valid, the application will exit with an error message. + +You can use the ip address like a normal string object. For example: + +.. code-block:: c++ + + eCAL::Config::IpAddressV4 ip_address = std::string("192.168.7.1"); // in hex: "C0.A8.7.1" + std::cout << ip_address << "\n"; + +Sizes are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. +In case the assigned value does not fit into the specified limitation, the application will exit with an error message. + +.. code-block:: c++ + + eCAL::Config::LimitSize<1024, 512, 8192> size_4mb = 1024 + 6 * 512; + std::cout << size_4mb << "\n"; + +For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/types/ecal_config_types.h" for the limitations. Initialization of the configuration =================================== -The configuration will be first initialized with the default .ini file found in the system. In case the .ini to use is specified vial command line parameter, this one is chosen instead. +The configuration will be first initialized with the default .ini file found in the system. +In case the .ini to use is specified vial command line parameter, this one is chosen instead. If it cannot find any .ini file, default values will be used for the first initialization of the configuration. -* |fa-file-alt| :file:`main.cpp`: +* |fa-file-alt| :file:`hello_config/main.cpp`: .. literalinclude:: src/hello_config/main.cpp :language: cpp - :linenos: \ No newline at end of file + :linenos: + diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 287d33f45f..7b7acf2282 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -1,3 +1,4 @@ +#include #include int main(int argc, char** argv) @@ -7,9 +8,15 @@ int main(int argc, char** argv) // Set the communication layer to network custom_config.transport_layer_options.network_enabled = true; - - // Initialize eCAL with the config - eCAL::Initialize(custom_config, "UserConfig", eCAL::Init::Default); + + // Set a custom udp multicast group, correct IP address necessary + custom_config.transport_layer_options.mc_options.group = std::string("239.0.1.1"); + + // Increase the send buffer, size increase in 1024 bytes steps + custom_config.transport_layer_options.mc_options.sndbuf = (5242880 + 10 * 1024); + + // Initialize eCAL with the prepared configuration object + eCAL::Initialize(custom_config, "UserConfigExample", eCAL::Init::Default); // ... // Use eCAL for your needs From 733d4c6d14129c7f8d921c393c23c151c4a8a042 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:17:52 +0200 Subject: [PATCH 061/105] TODO comment. --- ecal/core/include/ecal/types/ecal_transport_layer_options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 0f7e1b9e35..9900f16f12 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -55,6 +55,7 @@ namespace eCAL IpAddressV4 mask{}; LimitSize<14000, 10> port{}; unsigned int ttl{}; + // TODO PG: are these minimum limits correct? LimitSize<5242880, 1024> sndbuf{}; LimitSize<5242880, 1024> recbuf{}; bool join_all_interfaces{}; From a7072fc4854dca94cd346e6fb5ec99b53629f38a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:21:08 +0200 Subject: [PATCH 062/105] Small update to config doc. --- doc/rst/configuration/runtime_configuration.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 387dc5988e..a27b122915 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -28,6 +28,8 @@ You can use the ip address like a normal string object. For example: Sizes are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. In case the assigned value does not fit into the specified limitation, the application will exit with an error message. +You can use the size object like a normal integer. + .. code-block:: c++ eCAL::Config::LimitSize<1024, 512, 8192> size_4mb = 1024 + 6 * 512; From c946cc685241fe236af9a5cdebee88529bc19f9b Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:22:41 +0200 Subject: [PATCH 063/105] Small update to config example. --- doc/rst/configuration/src/hello_config/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 7b7acf2282..aa61ee953a 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -1,5 +1,6 @@ #include #include +#include int main(int argc, char** argv) { From 19512cfdbfae98512de1617068ce91ba81556cbe Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:23:12 +0200 Subject: [PATCH 064/105] Small update to config example._2 --- doc/rst/configuration/src/hello_config/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index aa61ee953a..2bd7b5cd93 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char** argv) eCAL::Config::eCALConfig custom_config(argc, argv); // Set the communication layer to network - custom_config.transport_layer_options.network_enabled = true; + custom_config.transport_layer_options.network_enabled = true; // Set a custom udp multicast group, correct IP address necessary custom_config.transport_layer_options.mc_options.group = std::string("239.0.1.1"); From 8df8937f064e8cfb72317a41ca076446b8a2898a Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:40:24 +0200 Subject: [PATCH 065/105] Renamed LimitSize to ConstrainedInteger. --- .../ecal/types/ecal_custom_data_types.h | 30 ++++++++++--------- .../ecal/types/ecal_monitoring_options.h | 2 +- .../ecal/types/ecal_transport_layer_options.h | 12 ++++---- .../tests/cpp/config_test/src/config_test.cpp | 12 ++++---- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 8e814dd496..7c0edae85c 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -46,12 +46,14 @@ namespace eCAL ECAL_API IpAddressV4(); ECAL_API IpAddressV4(const std::string& ip_address_); ECAL_API ~IpAddressV4(); - - IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; - IpAddressV4& operator=(IpAddressV4& const other) { this->m_ip_address = other; return *this; }; - IpAddressV4& operator=(const std::string& other) { this->validateIpString(other); return *this; }; - operator std::string() { return m_ip_address; }; - + + std::string GetIpString() const { return m_ip_address; }; + + IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; + IpAddressV4& operator=(const IpAddressV4& other) { this->m_ip_address = other.GetIpString(); return *this; }; + IpAddressV4& operator=(const std::string& ip_string) { this->validateIpString(ip_string); return *this; }; + operator std::string() { return m_ip_address; }; + friend std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.m_ip_address; return os; }; private: @@ -68,13 +70,13 @@ namespace eCAL * @tparam STEP Optional step size. Default: 1 * @tparam MAX Optional maximum possible size. Default: std::numeric_limits::max() * - * @param size_ Optional size value. If not set, LimitSize::get() will return the MIN value. + * @param size_ Optional size value. If not set, ConstrainedInteger::get() will return the MIN value. **/ template::max()> - class LimitSize + class ConstrainedInteger { public: - LimitSize(int size_ = MIN) + ConstrainedInteger(int size_ = MIN) { if (size_ >= MIN && size_ <= MAX && size_ % STEP == 0) { @@ -82,17 +84,17 @@ namespace eCAL } else { - std::cerr << "[LimitSize] Faulty size configuration or assignment. MIN: " << MIN << " MAX: " << MAX << " STEP: " << STEP << " VALUE:" << size_ << "\n"; + std::cerr << "[ConstrainedInteger] Faulty size configuration or assignment. MIN: " << MIN << " MAX: " << MAX << " STEP: " << STEP << " VALUE:" << size_ << "\n"; exit(EXIT_FAILURE); } }; - ~LimitSize() = default; + ~ConstrainedInteger() = default; - LimitSize(const LimitSize& other) { this->m_size = other; }; - LimitSize& operator=(const LimitSize& other) { this->m_size = other; return *this; }; + ConstrainedInteger(const ConstrainedInteger& other) { this->m_size = other; }; + ConstrainedInteger& operator=(const ConstrainedInteger& other) { this->m_size = other; return *this; }; operator int() const { return m_size; }; - bool operator==(const LimitSize& other) const { return this->m_size == other; }; + bool operator==(const ConstrainedInteger& other) const { return this->m_size == other; }; private: int m_size{}; diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index a31e29062b..43af648158 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -53,7 +53,7 @@ namespace eCAL struct MonitoringOptions { eCAL_MonitoringMode_Filter monitoring_mode{}; - LimitSize<1000, 1000> monitoring_timeout{}; + ConstrainedInteger<1000, 1000> monitoring_timeout{}; bool network_monitoring{}; UDPMonitoringOptions udp_options{}; SHMMonitoringOptions shm_options{}; diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 9900f16f12..0f0c89ce23 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -40,10 +40,10 @@ namespace eCAL struct SHMOptions { std::string host_group_name{}; - LimitSize<4096, 4096> memfile_minsize{}; - LimitSize<50, 1, 100> memfile_reserve{}; + ConstrainedInteger<4096, 4096> memfile_minsize{}; + ConstrainedInteger<50, 1, 100> memfile_reserve{}; int memfile_ack_timeout{}; - LimitSize<0, 1> memfile_buffer_count{}; + ConstrainedInteger<0, 1> memfile_buffer_count{}; bool drop_out_of_order_messages{}; bool memfile_zero_copy{}; }; @@ -53,11 +53,11 @@ namespace eCAL UdpConfigVersion config_version{}; IpAddressV4 group{}; IpAddressV4 mask{}; - LimitSize<14000, 10> port{}; + ConstrainedInteger<14000, 10> port{}; unsigned int ttl{}; // TODO PG: are these minimum limits correct? - LimitSize<5242880, 1024> sndbuf{}; - LimitSize<5242880, 1024> recbuf{}; + ConstrainedInteger<5242880, 1024> sndbuf{}; + ConstrainedInteger<5242880, 1024> recbuf{}; bool join_all_interfaces{}; int bandwidth_max_udp{}; diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index c7cb41b359..1585bd8530 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -149,21 +149,21 @@ TEST(ConfigDeathTest, user_config_death_test) SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.00.000.0")), ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - // Test the LimitSize class with wrong values. Default are MIN = 5242880, STEP = 1024 + // Test the ConstrainedInteger class with wrong values. Default are MIN = 5242880, STEP = 1024 // Value below MIN EXPECT_EXIT( SetValue(custom_config.transport_layer_options.mc_options.sndbuf, 42), - ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); + ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); // Wrong step. Default STEP = 1024 EXPECT_EXIT( SetValue(custom_config.transport_layer_options.mc_options.sndbuf, (5242880 + 512)), - ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); + ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); // Value exceeds MAX. Default MAX = 100 EXPECT_EXIT( SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), - ::testing::ExitedWithCode(EXIT_FAILURE), "LimitSize"); + ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); } TEST(core_cpp_config, config_custom_datatypes) @@ -177,8 +177,8 @@ TEST(core_cpp_config, config_custom_datatypes) ip2 = ip1; EXPECT_EQ(static_cast(ip1), static_cast(ip2)); - eCAL::Config::LimitSize<0,1,10> s1; - eCAL::Config::LimitSize<0,1,10> s2; + eCAL::Config::ConstrainedInteger<0,1,10> s1; + eCAL::Config::ConstrainedInteger<0,1,10> s2; EXPECT_EQ(static_cast(s1), static_cast(s2)); s1 = 5; From 4e049db94138a397dc574773c965fa024fef1bf2 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 18 Apr 2024 08:52:36 +0200 Subject: [PATCH 066/105] Changed behaviour of custom types: throwing invalid_argument exception instead of simply exit. --- .../configuration/runtime_configuration.rst | 4 +- .../configuration/src/hello_config/main.cpp | 21 +++-- .../ecal/types/ecal_custom_data_types.h | 12 ++- .../core/src/types/ecal_custom_data_types.cpp | 13 ++- .../tests/cpp/config_test/src/config_test.cpp | 94 ++++++++++--------- 5 files changed, 83 insertions(+), 61 deletions(-) diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index a27b122915..3123df503c 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -16,7 +16,7 @@ In order to exclude configuration errors, custom datatypes for IP addresses and For assigning an ip address simply assign a string with the desired address. Decimal and hexadecimal format is supported. -In case the ip address is not valid, the application will exit with an error message. +In case the ip address is not valid, the type will throw a std::invalid_argument exception. You can use the ip address like a normal string object. For example: @@ -26,7 +26,7 @@ You can use the ip address like a normal string object. For example: std::cout << ip_address << "\n"; Sizes are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. -In case the assigned value does not fit into the specified limitation, the application will exit with an error message. +In case the assigned value does not fit into the specified limitation, the type will throw a std::invalid_argument exception. You can use the size object like a normal integer. diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 2bd7b5cd93..5cf693d5f9 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -1,20 +1,29 @@ #include #include #include +#include int main(int argc, char** argv) { // Create a configuration object with the command line arguments eCAL::Config::eCALConfig custom_config(argc, argv); - // Set the communication layer to network - custom_config.transport_layer_options.network_enabled = true; + // Set the values in a try/catch block, as wrong configuration leads to exceptions + try + { + // Set the communication layer to network + custom_config.transport_layer_options.network_enabled = true; - // Set a custom udp multicast group, correct IP address necessary - custom_config.transport_layer_options.mc_options.group = std::string("239.0.1.1"); + // Set a custom udp multicast group, correct IP address necessary + custom_config.transport_layer_options.mc_options.group = std::string("239.0.1.1"); - // Increase the send buffer, size increase in 1024 bytes steps - custom_config.transport_layer_options.mc_options.sndbuf = (5242880 + 10 * 1024); + // Increase the send buffer, size increase in 1024 bytes steps + custom_config.transport_layer_options.mc_options.sndbuf = (5242880 + 10 * 1024); + } + catch (std::invalid_argument e) + { + throw std::runtime_error("Error while configuring eCALConfig: " + std::string(e.what())); + } // Initialize eCAL with the prepared configuration object eCAL::Initialize(custom_config, "UserConfigExample", eCAL::Init::Default); diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 7c0edae85c..c6b519db18 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace eCAL { @@ -39,6 +40,8 @@ namespace eCAL * Invalid addresses: 255.255.255.255, 127.0.0.1, 0.0.0.0 * * @param ip_address_ The IP address as std::string. + * + * @throws std::invalid_argument exception. **/ class IpAddressV4 { @@ -58,7 +61,7 @@ namespace eCAL private: ECAL_API void validateIpString(const std::string& ip_address_); - static void exitApp(const std::string& ip_address_ = std::string("")); + static void throwException(const std::string& ip_address_ = std::string("")); std::string m_ip_address; }; @@ -70,7 +73,9 @@ namespace eCAL * @tparam STEP Optional step size. Default: 1 * @tparam MAX Optional maximum possible size. Default: std::numeric_limits::max() * - * @param size_ Optional size value. If not set, ConstrainedInteger::get() will return the MIN value. + * @param size_ Optional size value. If not set, ConstrainedInteger will return the MIN value. + * + * @throws std::invalid_argument exception. **/ template::max()> class ConstrainedInteger @@ -84,8 +89,7 @@ namespace eCAL } else { - std::cerr << "[ConstrainedInteger] Faulty size configuration or assignment. MIN: " << MIN << " MAX: " << MAX << " STEP: " << STEP << " VALUE:" << size_ << "\n"; - exit(EXIT_FAILURE); + throw std::invalid_argument("[ConstrainedInteger] Faulty size configuration or assignment. MIN: " + std::to_string(MIN) + " MAX: " + std::to_string(MAX) + " STEP: " + std::to_string(STEP) + " VALUE:" + std::to_string(size_)); } }; diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 34bbfe6b96..86e6f7a117 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -34,8 +34,8 @@ namespace{ std::regex("((127|7[fF]).((0|00|000)\\.){2}(1|01|001))"), // 127.0.0.1 std::regex("((0|00|000)\\.){3}(0|00|000)") // 0.0.0.0 }; - const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"); - const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"); + const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"); + const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])"); } namespace eCAL @@ -63,7 +63,7 @@ namespace eCAL { if (std::regex_match(ip_address_, inv_ip_regex)) { - exitApp(ip_address_); + throwException(ip_address_); return; } } @@ -72,14 +72,13 @@ namespace eCAL } else { - exitApp(ip_address_); + throwException(ip_address_); } } - void IpAddressV4::exitApp(const std::string& ip_address_ /*std::string("")*/) + void IpAddressV4::throwException(const std::string& ip_address_ /*std::string("")*/) { - std::cerr << "[IpAddressV4] No valid IP address: " << ip_address_ << "\n"; - exit(EXIT_FAILURE); + throw std::invalid_argument("[IpAddressV4] No valid IP address: " + ip_address_); } } } diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 1585bd8530..1e374a7173 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -22,6 +22,8 @@ #include +#include + template void SetValue(MEMBER& member, VALUE value) { @@ -40,33 +42,41 @@ TEST(core_cpp_config, user_config_passing) std::string ip_address = "238.200.100.2"; const int upd_snd_buff = (5242880 + 1024); - custom_config.transport_layer_options.network_enabled = network_enabled; - custom_config.transport_layer_options.mc_options.group = ip_address; - custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; - // Monitoring options const unsigned int mon_timeout = 6000U; const std::string mon_filter_excl = "_A.*"; const eCAL_Logging_Filter mon_log_filter_con = log_level_warning; const eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; - custom_config.monitoring_options.monitoring_timeout = mon_timeout; - custom_config.monitoring_options.filter_excl = mon_filter_excl; - custom_config.monitoring_options.monitoring_mode = monitoring_mode; - custom_config.logging_options.filter_log_con = mon_log_filter_con; - // Publisher options const eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; - custom_config.publisher_options.use_shm = pub_use_shm; - // Registration options const unsigned int registration_timeout = 80000U; const unsigned int registration_refresh = 2000U; const eCAL::Config::RegistrationOptions registration_options = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); - custom_config.registration_options = registration_options; + try{ + custom_config.transport_layer_options.network_enabled = network_enabled; + custom_config.transport_layer_options.mc_options.group = ip_address; + custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; + + + custom_config.monitoring_options.monitoring_timeout = mon_timeout; + custom_config.monitoring_options.filter_excl = mon_filter_excl; + custom_config.monitoring_options.monitoring_mode = monitoring_mode; + custom_config.logging_options.filter_log_con = mon_log_filter_con; + + + custom_config.publisher_options.use_shm = pub_use_shm; + + custom_config.registration_options = registration_options; + } + catch (std::invalid_argument e) + { + throw std::runtime_error("Error while configuring eCALConfig: " + std::string(e.what())); + } // Initialize ecal api with custom config EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); @@ -108,62 +118,62 @@ TEST(ConfigDeathTest, user_config_death_test) eCAL::Config::eCALConfig custom_config(0, nullptr); // Test the IpAddressV4 class with wrong values - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("42")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + std::invalid_argument); // Test the IpAddressV4 class with invalid addresses - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("256.0.0.0")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("127.0.0.1")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("255.255.255.255")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + std::invalid_argument); - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FFF.FF.FF.FF")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FF.FF.FF.FF")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("Ff.fF.ff.Ff")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("7f.0.0.1")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + std::invalid_argument); - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.0.0.0")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("00.00.00.00")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("000.000.000.000")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); - EXPECT_EXIT( + std::invalid_argument); + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.00.000.0")), - ::testing::ExitedWithCode(EXIT_FAILURE), "IpAddressV4"); + std::invalid_argument); // Test the ConstrainedInteger class with wrong values. Default are MIN = 5242880, STEP = 1024 // Value below MIN - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.sndbuf, 42), - ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); + std::invalid_argument); // Wrong step. Default STEP = 1024 - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.mc_options.sndbuf, (5242880 + 512)), - ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); + std::invalid_argument); // Value exceeds MAX. Default MAX = 100 - EXPECT_EXIT( + ASSERT_THROW( SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), - ::testing::ExitedWithCode(EXIT_FAILURE), "ConstrainedInteger"); + std::invalid_argument); } TEST(core_cpp_config, config_custom_datatypes) From 0511bed3627255a05680e7c73acffae902322536 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:33:40 +0200 Subject: [PATCH 067/105] Reverted Config Getters to previous integration. --- app/mon/mon_gui/src/ecalmon.cpp | 4 +- .../ecalmon_tree_widget/topic_widget.cpp | 4 +- .../src/tui/viewmodel/command_line.hpp | 2 +- .../rec_client_core/src/job/record_job.cpp | 3 +- .../import_from_cloud_widget.cpp | 4 +- ecal/core/CMakeLists.txt | 5 +- ecal/core/include/ecal/ecal_config.h | 3 +- ecal/core/src/config/ecal_config.cpp | 102 ++++++++---------- ecal/core/src/ecal_descgate.cpp | 4 +- ecal/core/src/ecal_process.cpp | 42 ++++---- .../src/io/udp/ecal_udp_configurations.cpp | 33 +++--- ecal/core/src/logging/ecal_log_impl.cpp | 13 ++- .../src/monitoring/ecal_monitoring_impl.cpp | 14 +-- ecal/core/src/readwrite/ecal_reader.cpp | 20 ++-- ecal/core/src/readwrite/ecal_writer.cpp | 24 ++--- .../src/readwrite/shm/ecal_reader_shm.cpp | 2 +- .../src/readwrite/shm/ecal_writer_shm.cpp | 6 +- .../src/readwrite/tcp/ecal_reader_tcp.cpp | 4 +- .../src/readwrite/tcp/ecal_writer_tcp.cpp | 2 +- .../src/readwrite/udp/ecal_reader_udp_mc.cpp | 2 +- .../src/readwrite/udp/ecal_writer_udp_mc.cpp | 2 +- .../ecal_registration_provider.cpp | 12 +-- .../ecal_registration_receiver.cpp | 10 +- .../ecal_registration_receiver_shm.cpp | 2 +- .../src/service/ecal_service_server_impl.cpp | 8 +- ecal/core/src/time/ecal_timegate.cpp | 4 +- 26 files changed, 160 insertions(+), 171 deletions(-) diff --git a/app/mon/mon_gui/src/ecalmon.cpp b/app/mon/mon_gui/src/ecalmon.cpp index 801de081cf..2abed6fd10 100644 --- a/app/mon/mon_gui/src/ecalmon.cpp +++ b/app/mon/mon_gui/src/ecalmon.cpp @@ -93,8 +93,8 @@ Ecalmon::Ecalmon(QWidget *parent) network_mode_warning_icon_->setPixmap(warning_icon); network_mode_warning_icon_->setVisible(false); - const bool network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled; - const int multicast_ttl = eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; + bool network_mode = eCAL::Config::IsNetworkEnabled(); + int multicast_ttl = eCAL::Config::GetUdpMulticastTtl(); if (network_mode) { diff --git a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp index 1f3d738f48..5f2d2741f6 100644 --- a/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp +++ b/app/mon/mon_gui/src/widgets/ecalmon_tree_widget/topic_widget.cpp @@ -187,9 +187,9 @@ void TopicWidget::loadRegExpLists() QString exclude_string; QString include_string; - exclude_string = QString::fromStdString(eCAL::Config::GetCurrentConfig().monitoring_options.filter_excl); + exclude_string = QString::fromStdString(eCAL::Config::GetMonitoringFilterExcludeList()); //ini.GetValue(MON_SECTION_S, MON_FILTER_EXCL_S); - include_string = QString::fromStdString(eCAL::Config::GetCurrentConfig().monitoring_options.filter_incl); + include_string = QString::fromStdString(eCAL::Config::GetMonitoringFilterIncludeList()); //ini.GetValue(MON_SECTION_S, MON_FILTER_INCL_S); // The ecal.ini defines a very strange regex format: A filter consists of diff --git a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp index 665cbd9df0..b796bfedbf 100644 --- a/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp +++ b/app/mon/mon_tui/src/tui/viewmodel/command_line.hpp @@ -115,7 +115,7 @@ class CommandLineViewModel : public ViewModel { using namespace std::placeholders; - network_mode = eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled ? "cloud" : "local"; + network_mode = eCAL::Config::IsNetworkEnabled() ? "cloud" : "local"; is_polling_time = true; time_updater = std::thread(std::bind(&CommandLineViewModel::UpdateCurrentEcalTime, this)); diff --git a/app/rec/rec_client_core/src/job/record_job.cpp b/app/rec/rec_client_core/src/job/record_job.cpp index b8443943dd..b0715a568a 100644 --- a/app/rec/rec_client_core/src/job/record_job.cpp +++ b/app/rec/rec_client_core/src/job/record_job.cpp @@ -21,7 +21,6 @@ #include #include -#include #include "hdf5_writer_thread.h" @@ -171,7 +170,7 @@ namespace eCAL #undef CopyFile #endif // CopyFile { - const std::string ecal_ini_original_path = Config::GetCurrentConfig().loaded_ecal_ini_file; + std::string ecal_ini_original_path = eCAL::Config::GetLoadedEcalIniPath(); if (ecal_ini_original_path.empty()) { diff --git a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp index 86fc04dd44..e2882fd2c3 100644 --- a/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp +++ b/app/sys/sys_gui/src/widgets/import_from_cloud_widget/import_from_cloud_widget.cpp @@ -927,8 +927,8 @@ void ImportFromCloudWidget::loadExcludeTasksFilter() QFile default_cfg_file(default_cfg_file_path.c_str()); if (default_cfg_file.exists()) { - const std::regex reg(eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl, std::regex::icase); - exclude_tasks_regex_valid_ = !eCAL::Config::GetCurrentConfig().application_options.sys_options.filter_excl.empty(); + std::regex reg(eCAL::Config::GetEcalSysFilterExcludeList(), std::regex::icase); + exclude_tasks_regex_valid_ = !eCAL::Config::GetEcalSysFilterExcludeList().empty(); exclude_tasks_regex_ = reg; } } diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index adcd7b390c..b08d86bc08 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -66,11 +66,12 @@ endif() # config ###################################### set(ecal_config_src + src/config/ecal_cmd_parser.cpp + src/config/ecal_config.cpp + src/config/ecal_config_initializer.cpp src/config/ecal_config_reader.cpp src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h - src/config/ecal_config_initializer.cpp - src/config/ecal_cmd_parser.cpp src/types/ecal_custom_data_types.cpp ) diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index c35cdd0ba4..1019984143 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -76,7 +76,8 @@ namespace eCAL ///////////////////////////////////// ECAL_API std::string GetTimesyncModuleName (); - + ECAL_API std::string GetTimesyncModuleReplay (); + ///////////////////////////////////// // process ///////////////////////////////////// diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index ffb4543dcf..ecb15a0d7a 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -89,99 +89,91 @@ namespace eCAL // common ///////////////////////////////////// - ECAL_API std::string GetLoadedEcalIniPath () { return g_default_ini_file; } - ECAL_API int GetRegistrationTimeoutMs () { return eCALPAR(CMN, REGISTRATION_TO); } - ECAL_API int GetRegistrationRefreshMs () { return eCALPAR(CMN, REGISTRATION_REFRESH); } + ECAL_API std::string GetLoadedEcalIniPath () { return GetCurrentConfig().loaded_ecal_ini_file; } + ECAL_API int GetRegistrationTimeoutMs () { return GetCurrentConfig().registration_options.getTimeoutMS(); } + ECAL_API int GetRegistrationRefreshMs () { return GetCurrentConfig().registration_options.getRefreshMS(); } ///////////////////////////////////// // network ///////////////////////////////////// - ECAL_API bool IsNetworkEnabled () { return eCALPAR(NET, ENABLED); } + ECAL_API bool IsNetworkEnabled () { return GetCurrentConfig().transport_layer_options.network_enabled; } - ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion() - { - const std::string udp_config_version_string = eCALPAR(NET, UDP_MULTICAST_CONFIG_VERSION); - if (udp_config_version_string == "v1") - return UdpConfigVersion::V1; - if (udp_config_version_string == "v2") - return UdpConfigVersion::V2; - // TODO: Log error. However not sure if logging is initialized at this place. - return UdpConfigVersion::V1; - } + ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetCurrentConfig().transport_layer_options.mc_options.config_version; } - ECAL_API std::string GetUdpMulticastGroup () { return eCALPAR(NET, UDP_MULTICAST_GROUP); } - ECAL_API std::string GetUdpMulticastMask () { return eCALPAR(NET, UDP_MULTICAST_MASK); } - ECAL_API int GetUdpMulticastPort () { return eCALPAR(NET, UDP_MULTICAST_PORT); } - ECAL_API int GetUdpMulticastTtl () { return eCALPAR(NET, UDP_MULTICAST_TTL); } + ECAL_API std::string GetUdpMulticastGroup () { return GetCurrentConfig().transport_layer_options.mc_options.group; } + ECAL_API std::string GetUdpMulticastMask () { return GetCurrentConfig().transport_layer_options.mc_options.mask; } + ECAL_API int GetUdpMulticastPort () { return GetCurrentConfig().transport_layer_options.mc_options.port; } + ECAL_API int GetUdpMulticastTtl () { return GetCurrentConfig().transport_layer_options.mc_options.ttl; } - ECAL_API int GetUdpMulticastSndBufSizeBytes () { return eCALPAR(NET, UDP_MULTICAST_SNDBUF); } - ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return eCALPAR(NET, UDP_MULTICAST_RCVBUF); } - ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return eCALPAR(NET, UDP_MULTICAST_JOIN_ALL_IF_ENABLED); } + ECAL_API int GetUdpMulticastSndBufSizeBytes () { return GetCurrentConfig().transport_layer_options.mc_options.sndbuf; } + ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetCurrentConfig().transport_layer_options.mc_options.recbuf; } + ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces; } - ECAL_API bool IsUdpMulticastRecEnabled () { return eCALPAR(NET, UDP_MC_REC_ENABLED); } - ECAL_API bool IsShmRecEnabled () { return eCALPAR(NET, SHM_REC_ENABLED); } - ECAL_API bool IsTcpRecEnabled () { return eCALPAR(NET, TCP_REC_ENABLED); } + ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().receiving_options.udp_mc_recv_enabled; } + ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().receiving_options.shm_recv_enabled; } + ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().receiving_options.tcp_recv_enabled; } - ECAL_API bool IsNpcapEnabled () { return eCALPAR(NET, NPCAP_ENABLED); } + ECAL_API bool IsNpcapEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled; } - ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return eCALPAR(NET, TCP_PUBSUB_NUM_EXECUTOR_READER); } - ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return eCALPAR(NET, TCP_PUBSUB_NUM_EXECUTOR_WRITER); } - ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return eCALPAR(NET, TCP_PUBSUB_MAX_RECONNECTIONS); } + ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.num_executor_reader); } + ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.num_executor_writer); } + ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.max_reconnections); } - ECAL_API std::string GetHostGroupName () { return eCALPAR(NET, HOST_GROUP_NAME); } + ECAL_API std::string GetHostGroupName () { return GetCurrentConfig().transport_layer_options.shm_options.host_group_name; } ///////////////////////////////////// // time ///////////////////////////////////// - ECAL_API std::string GetTimesyncModuleName () { return eCALPAR(TIME, SYNC_MOD_RT); } + ECAL_API std::string GetTimesyncModuleName () { return GetCurrentConfig().timesync_options.timesync_module_rt; } + ECAL_API std::string GetTimesyncModuleReplay () { return GetCurrentConfig().timesync_options.timesync_module_replay; } ///////////////////////////////////// // process ///////////////////////////////////// - ECAL_API std::string GetTerminalEmulatorCommand () { return eCALPAR(PROCESS, TERMINAL_EMULATOR); } + ECAL_API std::string GetTerminalEmulatorCommand () { return GetCurrentConfig().application_options.startup_options.terminal_emulator; } ///////////////////////////////////// // monitoring ///////////////////////////////////// - ECAL_API int GetMonitoringTimeoutMs () { return eCALPAR(MON, TIMEOUT); } - ECAL_API std::string GetMonitoringFilterExcludeList () { return eCALPAR(MON, FILTER_EXCL); } - ECAL_API std::string GetMonitoringFilterIncludeList () { return eCALPAR(MON, FILTER_INCL); } - ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return ParseLogLevel(eCALPAR(MON, LOG_FILTER_CON)); } - ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return ParseLogLevel(eCALPAR(MON, LOG_FILTER_FILE)); } - ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return ParseLogLevel(eCALPAR(MON, LOG_FILTER_UDP)); } + ECAL_API int GetMonitoringTimeoutMs () { return GetCurrentConfig().monitoring_options.monitoring_timeout; } + ECAL_API std::string GetMonitoringFilterExcludeList () { return GetCurrentConfig().monitoring_options.filter_excl; } + ECAL_API std::string GetMonitoringFilterIncludeList () { return GetCurrentConfig().monitoring_options.filter_incl; } + ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return GetCurrentConfig().logging_options.filter_log_con; } + ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return GetCurrentConfig().logging_options.filter_log_file; } + ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return GetCurrentConfig().logging_options.filter_log_udp; } ///////////////////////////////////// // sys ///////////////////////////////////// - ECAL_API std::string GetEcalSysFilterExcludeList () { return eCALPAR(SYS, FILTER_EXCL); } + ECAL_API std::string GetEcalSysFilterExcludeList () { return GetCurrentConfig().application_options.sys_options.filter_excl; } ///////////////////////////////////// // publisher ///////////////////////////////////// - ECAL_API TLayer::eSendMode GetPublisherUdpMulticastMode () { return TLayer::eSendMode(eCALPAR(PUB, USE_UDP_MC)); } - ECAL_API TLayer::eSendMode GetPublisherShmMode () { return TLayer::eSendMode(eCALPAR(PUB, USE_SHM)); } - ECAL_API TLayer::eSendMode GetPublisherTcpMode () { return TLayer::eSendMode(eCALPAR(PUB, USE_TCP)); } + ECAL_API TLayer::eSendMode GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher_options.use_udp_mc; } + ECAL_API TLayer::eSendMode GetPublisherShmMode () { return GetCurrentConfig().publisher_options.use_shm; } + ECAL_API TLayer::eSendMode GetPublisherTcpMode () { return GetCurrentConfig().publisher_options.use_tcp; } - ECAL_API size_t GetMemfileMinsizeBytes () { return static_cast(eCALPAR(PUB, MEMFILE_MINSIZE)); } - ECAL_API size_t GetMemfileOverprovisioningPercentage () { return static_cast(eCALPAR(PUB, MEMFILE_RESERVE)); } - ECAL_API int GetMemfileAckTimeoutMs () { return eCALPAR(PUB, MEMFILE_ACK_TO); } - ECAL_API bool IsMemfileZerocopyEnabled () { return (eCALPAR(PUB, MEMFILE_ZERO_COPY) != 0); } - ECAL_API size_t GetMemfileBufferCount () { return static_cast(eCALPAR(PUB, MEMFILE_BUF_COUNT)); } + ECAL_API size_t GetMemfileMinsizeBytes () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize; } + ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve; } + ECAL_API int GetMemfileAckTimeoutMs () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; } + ECAL_API bool IsMemfileZerocopyEnabled () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; } + ECAL_API size_t GetMemfileBufferCount () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; } - ECAL_API bool IsTopicTypeSharingEnabled () { return (eCALPAR(PUB, SHARE_TTYPE) != 0); } - ECAL_API bool IsTopicDescriptionSharingEnabled () { return (eCALPAR(PUB, SHARE_TDESC) != 0); } + ECAL_API bool IsTopicTypeSharingEnabled () { return GetCurrentConfig().registration_options.share_ttype; } + ECAL_API bool IsTopicDescriptionSharingEnabled () { return GetCurrentConfig().registration_options.share_tdesc; } ///////////////////////////////////// // service ///////////////////////////////////// - ECAL_API bool IsServiceProtocolV0Enabled () { return (eCALPAR(SERVICE, PROTOCOL_V0) != 0); } - ECAL_API bool IsServiceProtocolV1Enabled () { return (eCALPAR(SERVICE, PROTOCOL_V1) != 0); } + ECAL_API bool IsServiceProtocolV0Enabled () { return GetCurrentConfig().service_options.protocol_v0; } + ECAL_API bool IsServiceProtocolV1Enabled () { return GetCurrentConfig().service_options.protocol_v1; } ///////////////////////////////////// // experimemtal @@ -189,11 +181,11 @@ namespace eCAL namespace Experimental { - ECAL_API bool IsShmMonitoringEnabled () { return eCALPAR(EXP, SHM_MONITORING_ENABLED); } - ECAL_API bool IsNetworkMonitoringDisabled () { return eCALPAR(EXP, NETWORK_MONITORING_DISABLED); } - ECAL_API size_t GetShmMonitoringQueueSize () { return static_cast(eCALPAR(EXP, SHM_MONITORING_QUEUE_SIZE)); } - ECAL_API std::string GetShmMonitoringDomain () { return eCALPAR(EXP, SHM_MONITORING_DOMAIN);} - ECAL_API bool GetDropOutOfOrderMessages () { return eCALPAR(EXP, DROP_OUT_OF_ORDER_MESSAGES); } + ECAL_API bool IsShmMonitoringEnabled () { return (GetCurrentConfig().monitoring_options.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } + ECAL_API bool IsNetworkMonitoringDisabled () { return !GetCurrentConfig().monitoring_options.network_monitoring; } + ECAL_API size_t GetShmMonitoringQueueSize () { return GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size; } + ECAL_API std::string GetShmMonitoringDomain () { return GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain;} + ECAL_API bool GetDropOutOfOrderMessages () { return GetCurrentConfig().transport_layer_options.drop_out_of_order_messages; } } } } diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index b71e48e99f..a10d996197 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -72,8 +72,8 @@ namespace namespace eCAL { CDescGate::CDescGate() : - m_topic_info_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), - m_service_info_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)) + m_topic_info_map(std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), + m_service_info_map(std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())) { } CDescGate::~CDescGate() = default; diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 1995cca3c8..e2f6ecc74d 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -25,7 +25,6 @@ #include #include "ecal_def.h" -#include "ecal/ecal_config.h" #include "ecal_globals.h" #include "ecal_process_stub.h" @@ -165,14 +164,14 @@ namespace eCAL } sstream << "------------------------- CONFIGURATION --------------------------" << '\n'; - sstream << "Default INI : " << Config::GetCurrentConfig().loaded_ecal_ini_file << '\n'; + sstream << "Default INI : " << Config::GetLoadedEcalIniPath() << '\n'; sstream << '\n'; sstream << "------------------------- NETWORK --------------------------------" << '\n'; sstream << "Host name : " << Process::GetHostName() << '\n'; sstream << "Host group name : " << Process::GetHostGroupName() << '\n'; - if (Config::GetCurrentConfig().transport_layer_options.network_enabled) + if (Config::IsNetworkEnabled()) { sstream << "Network mode : cloud" << '\n'; } @@ -180,22 +179,21 @@ namespace eCAL { sstream << "Network mode : local" << '\n'; } - sstream << "Network ttl : " << UDP::GetMulticastTtl() << '\n'; - sstream << "Network sndbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf) << '\n'; - sstream << "Network rcvbuf : " << GetBufferStr(Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf) << '\n'; - sstream << "Multicast cfg version : v" << static_cast(Config::GetCurrentConfig().transport_layer_options.mc_options.config_version) << '\n'; - sstream << "Multicast group : " << Config::GetCurrentConfig().transport_layer_options.mc_options.group << '\n'; - sstream << "Multicast mask : " << Config::GetCurrentConfig().transport_layer_options.mc_options.mask << '\n'; - const int port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; + sstream << "Network sndbuf : " << GetBufferStr(Config::GetUdpMulticastSndBufSizeBytes()) << '\n'; + sstream << "Network rcvbuf : " << GetBufferStr(Config::GetUdpMulticastRcvBufSizeBytes()) << '\n'; + sstream << "Multicast cfg version : v" << static_cast(Config::GetUdpMulticastConfigVersion()) << '\n'; + sstream << "Multicast group : " << Config::GetUdpMulticastGroup() << '\n'; + sstream << "Multicast mask : " << Config::GetUdpMulticastMask() << '\n'; + const int port = Config::GetUdpMulticastPort(); sstream << "Multicast ports : " << port << " - " << port + 10 << '\n'; - sstream << "Multicast join all IFs : " << (Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces ? "on" : "off") << '\n'; - + sstream << "Multicast join all IFs : " << (Config::IsUdpMulticastJoinAllIfEnabled() ? "on" : "off") << '\n'; + sstream << '\n'; #if ECAL_CORE_TIMEPLUGIN sstream << "------------------------- TIME -----------------------------------" << '\n'; - sstream << "Synchronization realtime : " << Config::GetCurrentConfig().timesync_options.timesync_module_rt << '\n'; - sstream << "Synchronization replay : " << Config::GetCurrentConfig().timesync_options.timesync_module_replay << '\n'; + sstream << "Synchronization realtime : " << Config::GetTimesyncModuleName() << '\n'; + sstream << "Synchronization replay : " << Config::GetTimesyncModuleReplay() << '\n'; sstream << "State : "; if (g_timegate()->IsSynchronized()) sstream << " synchronized " << '\n'; else sstream << " not synchronized " << '\n'; @@ -210,17 +208,17 @@ namespace eCAL #endif #if ECAL_CORE_SUBSCRIBER sstream << "------------------------- SUBSCRIPTION LAYER DEFAULTS ------------" << '\n'; - // TODO PG: This is probably the wrong struct and member. Which one is correct? - sstream << "Layer Mode UDP MC : " << LayerMode(Config::GetCurrentConfig().receiving_options.udp_mc_recv_enabled) << '\n'; - sstream << "Drop out-of-order msgs : " << (Config::GetCurrentConfig().transport_layer_options.drop_out_of_order_messages ? "on" : "off") << '\n'; + sstream << "Layer Mode UDP MC : " << LayerMode(Config::IsUdpMulticastRecEnabled()) << '\n'; + sstream << "Drop out-of-order msgs : " << (Config::Experimental::GetDropOutOfOrderMessages() ? "on" : "off") << '\n'; #endif -#ifdef ECAL_NPCAP_SUPPORT - if(Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled && !Udpcap::Initialize()) +#ifdef ECAL_CORE_NPCAP_SUPPORT + sstream << "Npcap UDP Reciever : " << LayerMode(Config::IsNpcapEnabled()); + if(Config::IsNpcapEnabled() && !Udpcap::Initialize()) { sstream << " (Init FAILED!)"; } #else // ECAL_CORE_NPCAP_SUPPORT - if (Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled) + if (Config::IsNpcapEnabled()) { sstream << " (Npcap is enabled, but not configured via CMake!)"; } @@ -250,7 +248,7 @@ namespace eCAL std::string GetHostGroupName() { - return Config::GetCurrentConfig().transport_layer_options.shm_options.host_group_name.empty() ? GetHostName() : Config::GetCurrentConfig().transport_layer_options.shm_options.host_group_name; + return Config::GetHostGroupName().empty() ? GetHostName() : Config::GetHostGroupName(); } std::string GetUnitName() @@ -650,7 +648,7 @@ namespace // -------------------- terminal_emulator command check -------------------- - const std::string terminal_emulator_command = eCAL::Config::GetCurrentConfig().application_options.startup_options.terminal_emulator; + const std::string terminal_emulator_command = eCAL::Config::GetTerminalEmulatorCommand(); if (!terminal_emulator_command.empty()) { STD_COUT_DEBUG("[PID " << getpid() << "]: " << "ecal.ini terminal emulator command is: " << terminal_emulator_command << std::endl); diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index 72d75088ed..20c24168f1 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -21,7 +21,6 @@ #include "ecal_def.h" #include "ecal_udp_topic2mcast.h" -#include "ecal/ecal_config.h" #include #include @@ -37,7 +36,7 @@ namespace eCAL */ bool IsBroadcast() { - return !Config::GetCurrentConfig().transport_layer_options.network_enabled; + return !Config::IsNetworkEnabled(); } /** @@ -47,7 +46,7 @@ namespace eCAL */ bool IsNpcapEnabled() { - return Config::GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled; + return Config::IsNpcapEnabled(); } /** @@ -59,7 +58,7 @@ namespace eCAL */ bool IsUdpMulticastJoinAllIfEnabled() { - return Config::GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces; + return Config::IsUdpMulticastJoinAllIfEnabled(); } /** @@ -80,20 +79,20 @@ namespace eCAL std::string GetRegistrationAddress() { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; + const bool local_only = !Config::IsNetworkEnabled(); if (local_only) { return GetLocalBroadcastAddress(); } // both in v1 and v2, the multicast group is returned as the adress for the registration layer - return Config::GetCurrentConfig().transport_layer_options.mc_options.group; + return Config::GetUdpMulticastGroup(); } int GetRegistrationPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; + const int configured_port = Config::GetUdpMulticastPort(); // add the specific offset, NET_UDP_MULTICAST_PORT_REG_OFF, to obtain the registration port return configured_port + NET_UDP_MULTICAST_PORT_REG_OFF; @@ -108,7 +107,7 @@ namespace eCAL int GetLoggingPort() { // retrieve the configured UDP multicast port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; + const int configured_port = Config::GetUdpMulticastPort(); // add the specific offset, NET_UDP_MULTICAST_PORT_LOG_OFF, to obtain the logging port return configured_port + NET_UDP_MULTICAST_PORT_LOG_OFF; @@ -123,7 +122,7 @@ namespace eCAL std::string GetTopicPayloadAddress(const std::string& topic_name) { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; + const bool local_only = !Config::IsNetworkEnabled(); if (local_only) { // if network is disabled, return the local broadcast address @@ -131,23 +130,23 @@ namespace eCAL } // determine the UDP multicast configuration version - if (Config::GetCurrentConfig().transport_layer_options.mc_options.config_version == Config::UdpConfigVersion::V1) + if (Config::GetUdpMulticastConfigVersion() == Config::UdpConfigVersion::V1) { // retrieve the corresponding multicast address based on the topic name using v1 implementation - return UDP::V1::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group, Config::GetCurrentConfig().transport_layer_options.mc_options.mask); + return UDP::V1::topic2mcast(topic_name, Config::GetUdpMulticastGroup(), Config::GetUdpMulticastMask()); } // v2 else { // retrieve the corresponding multicast address based on the topic name using v2 implementation - return UDP::V2::topic2mcast(topic_name, Config::GetCurrentConfig().transport_layer_options.mc_options.group, Config::GetCurrentConfig().transport_layer_options.mc_options.mask); + return UDP::V2::topic2mcast(topic_name, Config::GetUdpMulticastGroup(), Config::GetUdpMulticastMask()); } } int GetPayloadPort() { - // retrieve the configured UDP multicat port from the configuration - const int configured_port = Config::GetCurrentConfig().transport_layer_options.mc_options.port; + // retrieve the configured UDP multicast port from the configuration + const int configured_port = Config::GetUdpMulticastPort(); // add the specific offset, NET_UDP_MULTICAST_PORT_SAMPLE_OFF, to obtain the payload port return configured_port + NET_UDP_MULTICAST_PORT_SAMPLE_OFF; @@ -156,15 +155,15 @@ namespace eCAL int GetMulticastTtl() { // check if the network is disabled - const bool local_only = !Config::GetCurrentConfig().transport_layer_options.network_enabled; + const bool local_only = !Config::IsNetworkEnabled(); if (local_only) { // if network is disabled, return a TTL of 0 to restrict multicast packets to the local machine return 1; } - + // if network is enabled, return the configured UDP multicast TTL value - return Config::GetCurrentConfig().transport_layer_options.mc_options.ttl; + return Config::GetUdpMulticastTtl(); } } } diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index 815f80123b..33d9801c20 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -24,7 +24,6 @@ #include #include #include -#include "ecal_global_accessors.h" #include "ecal_log_impl.h" #include "io/udp/ecal_udp_configurations.h" @@ -120,9 +119,9 @@ namespace eCAL m_level = log_level_info; // parse logging filter strings - m_filter_mask_con = Config::GetCurrentConfig().logging_options.filter_log_con; - m_filter_mask_file = Config::GetCurrentConfig().logging_options.filter_log_file; - m_filter_mask_udp = Config::GetCurrentConfig().logging_options.filter_log_udp; + m_filter_mask_con = Config::GetConsoleLogFilter(); + m_filter_mask_file = Config::GetFileLogFilter(); + m_filter_mask_udp = Config::GetUdpLogFilter(); // create log file if(m_filter_mask_file != 0) @@ -146,7 +145,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = g_ecal_config().transport_layer_options.mc_options.sndbuf; + attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); // create udp logging sender m_udp_logging_sender = std::make_unique(attr); @@ -158,7 +157,7 @@ namespace eCAL attr.port = UDP::GetLoggingPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = g_ecal_config().transport_layer_options.mc_options.recbuf; + attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); // start logging receiver m_log_receiver = std::make_shared(attr, std::bind(&CLog::HasSample, this, std::placeholders::_1), std::bind(&CLog::ApplySample, this, std::placeholders::_1, std::placeholders::_2)); @@ -323,7 +322,7 @@ namespace eCAL { // in "network mode" we accept all log messages // in "local mode" we accept log messages from this host only - if ((m_hname == log_message.hname) || g_ecal_config().transport_layer_options.network_enabled) + if ((m_hname == log_message.hname) || Config::IsNetworkEnabled()) { const std::lock_guard lock(m_log_mtx); m_log_msglist.log_messages.emplace_back(log_message); diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp index 907d34d1d7..928c4e28fd 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp @@ -43,11 +43,11 @@ namespace eCAL //////////////////////////////////////// CMonitoringImpl::CMonitoringImpl() : m_init(false), - m_process_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), - m_publisher_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), - m_subscriber_map(std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), - m_server_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)), - m_clients_map (std::chrono::milliseconds(Config::GetCurrentConfig().monitoring_options.monitoring_timeout)) + m_process_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), + m_publisher_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), + m_subscriber_map(std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), + m_server_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())), + m_clients_map (std::chrono::milliseconds(Config::GetMonitoringTimeoutMs())) { } @@ -63,8 +63,8 @@ namespace eCAL g_registration_receiver()->SetCustomApplySampleCallback("monitoring", [this](const auto& sample_){this->ApplySample(sample_, tl_none);}); // setup blacklist and whitelist filter strings# - m_topic_filter_excl_s = Config::GetCurrentConfig().monitoring_options.filter_excl; - m_topic_filter_incl_s = Config::GetCurrentConfig().monitoring_options.filter_incl; + m_topic_filter_excl_s = Config::GetMonitoringFilterExcludeList(); + m_topic_filter_incl_s = Config::GetMonitoringFilterIncludeList(); // setup filtering on by default SetFilterState(true); diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index 8c0ab4fd25..71ad234d0e 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -109,15 +109,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(Config::GetCurrentConfig().registration_options.getTimeoutMS()); + const std::chrono::milliseconds registration_timeout(Config::GetRegistrationTimeoutMs()); m_loc_pub_map.set_expiration(registration_timeout); m_ext_pub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::GetCurrentConfig().registration_options.share_ttype; + m_use_ttype = Config::IsTopicTypeSharingEnabled(); // allow to share topic description - m_use_tdesc = Config::GetCurrentConfig().registration_options.share_tdesc; + m_use_tdesc = Config::IsTopicDescriptionSharingEnabled(); // start transport layers SubscribeToLayers(); @@ -176,7 +176,7 @@ namespace eCAL { // initialize udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config().receiving_options.udp_mc_recv_enabled) + if (Config::IsUdpMulticastRecEnabled()) { CUDPReaderLayer::Get()->Initialize(); } @@ -184,7 +184,7 @@ namespace eCAL // initialize tcp layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config().receiving_options.tcp_recv_enabled) + if (Config::IsTcpRecEnabled()) { CTCPReaderLayer::Get()->Initialize(); } @@ -195,7 +195,7 @@ namespace eCAL { // subscribe topic to udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config().receiving_options.udp_mc_recv_enabled) + if (Config::IsUdpMulticastRecEnabled()) { CUDPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -203,7 +203,7 @@ namespace eCAL // subscribe topic to tcp layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config().receiving_options.tcp_recv_enabled) + if (Config::IsTcpRecEnabled()) { CTCPReaderLayer::Get()->AddSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -214,7 +214,7 @@ namespace eCAL { // unsubscribe topic from udp multicast layer #if ECAL_CORE_TRANSPORT_UDP - if (g_ecal_config().receiving_options.udp_mc_recv_enabled) + if (Config::IsUdpMulticastRecEnabled()) { CUDPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -222,7 +222,7 @@ namespace eCAL // unsubscribe topic from tcp multicast layer #if ECAL_CORE_TRANSPORT_TCP - if (g_ecal_config().receiving_options.tcp_recv_enabled) + if (Config::IsTcpRecEnabled()) { CTCPReaderLayer::Get()->RemSubscription(m_host_name, m_topic_name, m_topic_id); } @@ -860,7 +860,7 @@ namespace eCAL // ----------------------------------- // drop messages in the wrong order // ----------------------------------- - if (Config::GetCurrentConfig().transport_layer_options.drop_out_of_order_messages) + if (Config::Experimental::GetDropOutOfOrderMessages()) { // do not update the internal clock counter diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 8eb8aee87f..806dedab4a 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -91,13 +91,13 @@ namespace eCAL { // initialize layer modes with configuration settings #if ECAL_CORE_TRANSPORT_UDP - m_writer.udp_mc_mode.requested = Config::GetCurrentConfig().publisher_options.use_udp_mc; + m_writer.udp_mc_mode.requested = Config::GetPublisherUdpMulticastMode(); #endif #if ECAL_CORE_TRANSPORT_SHM - m_writer.shm_mode.requested = Config::GetCurrentConfig().publisher_options.use_shm; + m_writer.shm_mode.requested = Config::GetPublisherShmMode(); #endif #if ECAL_CORE_TRANSPORT_TCP - m_writer.tcp_mode.requested = Config::GetCurrentConfig().publisher_options.use_tcp; + m_writer.tcp_mode.requested = Config::GetPublisherTcpMode(); #endif } @@ -116,9 +116,9 @@ namespace eCAL m_topic_info = topic_info_; m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; - m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; - m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; + m_buffering_shm = Config::GetMemfileBufferCount(); + m_zero_copy = Config::IsMemfileZerocopyEnabled(); + m_acknowledge_timeout_ms = Config::GetMemfileAckTimeoutMs(); m_connected = false; m_ext_subscribed = false; m_created = false; @@ -129,15 +129,15 @@ namespace eCAL m_topic_id = counter.str(); // set registration expiration - const std::chrono::milliseconds registration_timeout(g_ecal_config().registration_options.getTimeoutMS()); + const std::chrono::milliseconds registration_timeout(Config::GetRegistrationTimeoutMs()); m_loc_sub_map.set_expiration(registration_timeout); m_ext_sub_map.set_expiration(registration_timeout); // allow to share topic type - m_use_ttype = Config::GetCurrentConfig().registration_options.share_ttype; + m_use_ttype = Config::IsTopicTypeSharingEnabled(); // allow to share topic description - m_use_tdesc = Config::GetCurrentConfig().registration_options.share_ttype; + m_use_tdesc = Config::IsTopicDescriptionSharingEnabled(); // mark as created m_created = true; @@ -192,9 +192,9 @@ namespace eCAL // reset defaults m_id = 0; m_clock = 0; - m_buffering_shm = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; - m_zero_copy = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; - m_acknowledge_timeout_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; + m_buffering_shm = Config::GetMemfileBufferCount(); + m_zero_copy = Config::IsMemfileZerocopyEnabled(); + m_acknowledge_timeout_ms = Config::GetMemfileAckTimeoutMs(); m_connected = false; // reset subscriber maps diff --git a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp index 2608f4804d..244460f1eb 100644 --- a/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_reader_shm.cpp @@ -53,7 +53,7 @@ namespace eCAL std::placeholders::_6, std::placeholders::_7, std::placeholders::_8); - g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, g_ecal_config().registration_options.getTimeoutMS(), memfile_data_callback); + g_memfile_pool()->ObserveFile(memfile_name, memfile_event, par_.topic_name, par_.topic_id, Config::GetRegistrationTimeoutMs(), memfile_data_callback); } } } diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp index 48d17a9004..9ee4cd48df 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.cpp @@ -62,10 +62,10 @@ namespace eCAL m_write_idx = 0; // set attributes - m_memory_file_attr.min_size = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize; - m_memory_file_attr.reserve = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve; + m_memory_file_attr.min_size = Config::GetMemfileMinsizeBytes(); + m_memory_file_attr.reserve = Config::GetMemfileOverprovisioningPercentage(); m_memory_file_attr.timeout_open_ms = PUB_MEMFILE_OPEN_TO; - m_memory_file_attr.timeout_ack_ms = Config::GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; + m_memory_file_attr.timeout_ack_ms = Config::GetMemfileAckTimeoutMs(); // initialize memory file buffer m_created = SetBufferCount(m_buffer_count); diff --git a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp index b1e0edd06d..ffbfbae0af 100644 --- a/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp @@ -76,7 +76,7 @@ namespace eCAL // add new session and activate callback if we add the first session if (new_session) { - m_subscriber->addSession(host_name_, port_, static_cast(Config::GetCurrentConfig().transport_layer_options.tcp_options.max_reconnections)); + m_subscriber->addSession(host_name_, port_, Config::GetTcpPubsubMaxReconnectionAttemps()); if (!m_callback_active) { m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1)); @@ -131,7 +131,7 @@ namespace eCAL void CTCPReaderLayer::Initialize() { const tcp_pubsub::logger::logger_t tcp_pubsub_logger = std::bind(TcpPubsubLogger, std::placeholders::_1, std::placeholders::_2); - m_executor = std::make_shared(Config::GetCurrentConfig().transport_layer_options.tcp_options.num_executor_reader, tcp_pubsub_logger); + m_executor = std::make_shared(Config::GetTcpPubsubReaderThreadpoolSize(), tcp_pubsub_logger); } void CTCPReaderLayer::AddSubscription(const std::string& /*host_name_*/, const std::string& topic_name_, const std::string& /*topic_id_*/) diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp index ad78711648..59dabf9586 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp @@ -68,7 +68,7 @@ namespace eCAL const std::lock_guard lock(g_tcp_writer_executor_mtx); if (!g_tcp_writer_executor) { - g_tcp_writer_executor = std::make_shared(Config::GetCurrentConfig().transport_layer_options.tcp_options.num_executor_writer, TcpPubsubLogger); + g_tcp_writer_executor = std::make_shared(Config::GetTcpPubsubWriterThreadpoolSize(), TcpPubsubLogger); } } diff --git a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp index a21fdad5e4..9a200b43d3 100644 --- a/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_reader_udp_mc.cpp @@ -61,7 +61,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf; + attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); // 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)); diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp index 741dcdb371..063ed701a4 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp @@ -67,7 +67,7 @@ namespace eCAL attr.port = UDP::GetPayloadPort(); attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); - attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf; + attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); // create udp/sample sender with activated loop-back attr.loopback = true; diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index c168c3dc16..3a8e8fc250 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -63,8 +63,8 @@ namespace eCAL if(m_created) return; // send registration to shared memory and to udp - m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) != 0; + m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled(); + m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled(); if (m_use_registration_udp) { @@ -75,7 +75,7 @@ namespace eCAL attr.ttl = UDP::GetMulticastTtl(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.sndbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf; + attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes(); // create udp registration sender m_reg_sample_snd = std::make_shared(attr); @@ -84,15 +84,15 @@ namespace eCAL #if ECAL_CORE_REGISTRATION_SHM if (m_use_registration_shm) { - std::cout << "Shared memory monitoring is enabled (domain: " << Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain << " - queue size: " << Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size << ")" << '\n'; - m_memfile_broadcast.Create(Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size); + std::cout << "Shared memory monitoring is enabled (domain: " << Config::Experimental::GetShmMonitoringDomain() << " - queue size: " << Config::Experimental::GetShmMonitoringQueueSize() << ")" << '\n'; + m_memfile_broadcast.Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); m_memfile_broadcast_writer.Bind(&m_memfile_broadcast); } #endif // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(std::chrono::milliseconds(g_ecal_config().registration_options.getRefreshMS())); + m_reg_sample_snd_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs())); m_created = true; } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index e4c3e245d4..2bade0bea8 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -70,11 +70,11 @@ namespace eCAL if(m_created) return; // network mode - m_network = g_ecal_config().transport_layer_options.network_enabled; + m_network = Config::IsNetworkEnabled(); // receive registration from shared memory and or udp - m_use_registration_udp = Config::GetCurrentConfig().monitoring_options.network_monitoring; - m_use_registration_shm = (Config::GetCurrentConfig().monitoring_options.monitoring_mode & Config::MonitoringMode::shm_monitoring) != 0; + m_use_registration_udp = !Config::Experimental::IsNetworkMonitoringDisabled(); + m_use_registration_shm = Config::Experimental::IsShmMonitoringEnabled(); if (m_use_registration_udp) { @@ -84,7 +84,7 @@ namespace eCAL attr.port = UDP::GetRegistrationPort(); attr.broadcast = UDP::IsBroadcast(); attr.loopback = true; - attr.rcvbuf = Config::GetCurrentConfig().transport_layer_options.mc_options.recbuf; + attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); // start registration sample receiver m_registration_receiver = std::make_shared(attr, std::bind(&CRegistrationReceiver::HasSample, this, std::placeholders::_1), std::bind(&CRegistrationReceiver::ApplySerializedSample, this, std::placeholders::_1, std::placeholders::_2)); @@ -93,7 +93,7 @@ namespace eCAL #if ECAL_CORE_REGISTRATION_SHM if (m_use_registration_shm) { - m_memfile_broadcast.Create(Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain, Config::GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size); + m_memfile_broadcast.Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize()); m_memfile_broadcast.FlushLocalEventQueue(); m_memfile_broadcast_reader.Bind(&m_memfile_broadcast); diff --git a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp index 0e70881b40..7ac78263cf 100644 --- a/ecal/core/src/registration/ecal_registration_receiver_shm.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver_shm.cpp @@ -51,7 +51,7 @@ namespace eCAL // start memfile broadcast receive thread m_memfile_broadcast_reader = memfile_broadcast_reader_; m_memfile_broadcast_reader_thread = std::make_shared(std::bind(&CMemfileRegistrationReceiver::Receive, this)); - m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetCurrentConfig().registration_options.getRefreshMS()/2)); + m_memfile_broadcast_reader_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs()/2)); m_created = true; } diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 18e11d23e6..bb61c979a3 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -114,13 +114,13 @@ namespace eCAL }; // start service protocol version 0 - if (Config::GetCurrentConfig().service_options.protocol_v0) + if (Config::IsServiceProtocolV0Enabled()) { m_tcp_server_v0 = server_manager->create_server(0, 0, service_callback, true, event_callback); } // start service protocol version 1 - if (Config::GetCurrentConfig().service_options.protocol_v1) + if (Config::IsServiceProtocolV1Enabled()) { m_tcp_server_v1 = server_manager->create_server(1, 0, service_callback, true, event_callback); } @@ -322,10 +322,10 @@ namespace eCAL // might be zero in contruction phase unsigned short const server_tcp_port_v0(m_tcp_server_v0 ? m_tcp_server_v0->get_port() : 0); - if ((Config::GetCurrentConfig().service_options.protocol_v0) && (server_tcp_port_v0 == 0)) return; + if ((Config::IsServiceProtocolV0Enabled()) && (server_tcp_port_v0 == 0)) return; unsigned short const server_tcp_port_v1(m_tcp_server_v1 ? m_tcp_server_v1->get_port() : 0); - if ((Config::GetCurrentConfig().service_options.protocol_v1) && (server_tcp_port_v1 == 0)) return; + if ((Config::IsServiceProtocolV1Enabled()) && (server_tcp_port_v1 == 0)) return; // create service registration sample Registration::Sample sample; diff --git a/ecal/core/src/time/ecal_timegate.cpp b/ecal/core/src/time/ecal_timegate.cpp index e97b8c989f..bd3fee8b6d 100644 --- a/ecal/core/src/time/ecal_timegate.cpp +++ b/ecal/core/src/time/ecal_timegate.cpp @@ -85,11 +85,11 @@ namespace eCAL case eTimeSyncMode::none: break; case eTimeSyncMode::realtime: - m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module_rt; + m_time_sync_modname = Config::GetTimesyncModuleName(); m_successfully_loaded_rt = LoadModule(m_time_sync_modname, m_time_sync_rt); break; case eTimeSyncMode::replay: - m_time_sync_modname = Config::GetCurrentConfig().timesync_options.timesync_module_replay; + m_time_sync_modname = Config::GetTimesyncModuleReplay(); m_successfully_loaded_replay = LoadModule(m_time_sync_modname, m_time_sync_replay); break; } From da0a991cc5a0dfd310c3a646370620135fd8c92b Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:55:01 +0200 Subject: [PATCH 068/105] Added user_args to config file. --- .../include/ecal/types/ecal_config_types.h | 9 +- .../ecal/types/ecal_custom_data_types.h | 18 +- .../include/ecal/types/user_arg_options.h | 42 ++++ ecal/core/src/config/ecal_cmd_parser.cpp | 183 +++++++++++++++++- ecal/core/src/config/ecal_cmd_parser.h | 28 ++- .../src/config/ecal_config_initializer.cpp | 40 +++- ecal/core/src/config/ecal_config_reader.cpp | 8 +- ecal/core/src/config/ecal_config_reader.h | 2 +- ecal/core/src/ecal.cpp | 2 +- .../core/src/types/ecal_custom_data_types.cpp | 8 + 10 files changed, 303 insertions(+), 37 deletions(-) create mode 100644 ecal/core/include/ecal/types/user_arg_options.h diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 2a6de54dd7..9da296665c 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -33,6 +33,7 @@ #include "ecal_service_options.h" #include "ecal_logging_options.h" #include "ecal_transport_layer_options.h" +#include "user_arg_options.h" #include "ecal/ecal_os.h" #include "ecal/ecal_log_level.h" @@ -57,13 +58,15 @@ namespace eCAL ServiceOptions service_options{}; ApplicationOptions application_options{}; LoggingOptions logging_options{}; - std::string loaded_ecal_ini_file{}; - std::vector config_keys{}; + ClArguments command_line_arguments{}; + std::string loaded_ecal_ini_file{}; ECAL_API eCALConfig(int argc_ , char **argv_); + ECAL_API eCALConfig(std::vector args_); private: - void InitConfig(); + ECAL_API void InitConfig(); + ECAL_API void Init(int argc_ , char **argv_); }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index c6b519db18..bf7ffb0d57 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -50,20 +50,18 @@ namespace eCAL ECAL_API IpAddressV4(const std::string& ip_address_); ECAL_API ~IpAddressV4(); - std::string GetIpString() const { return m_ip_address; }; + std::string GetIpString() const; - IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; - IpAddressV4& operator=(const IpAddressV4& other) { this->m_ip_address = other.GetIpString(); return *this; }; - IpAddressV4& operator=(const std::string& ip_string) { this->validateIpString(ip_string); return *this; }; - operator std::string() { return m_ip_address; }; - - friend std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.m_ip_address; return os; }; + ECAL_API IpAddressV4(IpAddressV4& other); + ECAL_API IpAddressV4& operator=(const IpAddressV4& other); + ECAL_API IpAddressV4& operator=(const std::string& ip_string); + ECAL_API operator std::string(); private: ECAL_API void validateIpString(const std::string& ip_address_); - static void throwException(const std::string& ip_address_ = std::string("")); + ECAL_API static void throwException(const std::string& ip_address_ = std::string("")); - std::string m_ip_address; + std::string m_ip_address{}; }; /** @@ -83,7 +81,7 @@ namespace eCAL public: ConstrainedInteger(int size_ = MIN) { - if (size_ >= MIN && size_ <= MAX && size_ % STEP == 0) + if (size_ >= MIN && size_ <= MAX && size_ % STEP == 0 && MAX >= MIN) { m_size = size_; } diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/types/user_arg_options.h new file mode 100644 index 0000000000..4a7831f108 --- /dev/null +++ b/ecal/core/include/ecal/types/user_arg_options.h @@ -0,0 +1,42 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file user_arg_options.h + * @brief Options specified by the user via command line +**/ + +#pragma once + +#include +#include + +namespace eCAL +{ + namespace Config + { + struct ClArguments + { + std::vector config_keys{}; + std::string specified_config{}; + std::string found_config_file{}; + bool dump_config{}; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 14910312a0..f49020a6a5 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -2,19 +2,143 @@ #include "ecal/ecal_defs.h" #include "ecal_def.h" +#include "ecal_utils/filesystem.h" +#include "util/getenvvar.h" + #if ECAL_CORE_COMMAND_LINE #include "util/advanced_tclap_output.h" #endif -#include "ecal_global_accessors.h" +#include + +// for cwd +#ifdef ECAL_OS_WINDOWS + #include + // to get rid of deprecated warning + #define getcwd _getcwd +#endif +#ifdef ECAL_OS_LINUX + #include +#endif + +namespace +{ + // things stolen and adapted from ecal_config_reader.cpp +#ifdef ECAL_OS_WINDOWS + const char path_separator('\\'); +#endif /* ECAL_OS_WINDOWS */ +#ifdef ECAL_OS_LINUX + const char path_sep_bla('/'); +#endif /* ECAL_OS_LINUX */ + + bool SetPathSep(std::string file_path_) + { + if (!file_path_.empty()) + { + if (file_path_.back() != path_separator) + { + file_path_ += path_separator; + } + return true; + } + + return false; + } + + std::string eCALDataEnvPath() + { + std::string ecal_data_path = getEnvVar("ECAL_DATA"); + SetPathSep(ecal_data_path); + return ecal_data_path; + } + + std::string cwdPath() + { + std::string cwd_path = {}; + char* buffer; + + if ( (buffer = getcwd(NULL, 0)) == NULL ) + throw std::runtime_error("getcwd() : cannot read current working directory."); + else + { + cwd_path = std::string(buffer); + free(buffer); + } + + SetPathSep(cwd_path); + return cwd_path; + } + + std::string eCALDataCMakePath() + { + std::string cmake_data_path; +#ifdef ECAL_OS_LINUX + std::string ecal_install_config_dir(ECAL_INSTALL_CONFIG_DIR); + std::string ecal_install_prefix(ECAL_INSTALL_PREFIX); + + if ((!ecal_install_config_dir.empty() && (ecal_install_config_dir[0] == path_separator)) + || ecal_install_prefix.empty()) + { + cmake_data_path = ecal_install_config_dir; + } + else if (!ecal_install_prefix.empty()) + { + cmake_data_path = ecal_install_prefix + path_separator + ecal_install_config_dir; + } + SetPathSep(cmake_data_path); +#endif /* ECAL_OS_LINUX */ + return cmake_data_path; + } + + std::string eCALDataSystemPath() + { + std::string system_data_path; +#ifdef ECAL_OS_WINDOWS + system_data_path = getEnvVar("ProgramData"); + if(SetPathSep(system_data_path)) + system_data_path += std::string("eCAL") + path_separator; +#endif /* ECAL_OS_WINDOWS */ + +#ifdef ECAL_OS_LINUX + system_data_path = "/etc/ecal/"; +#endif /* ECAL_OS_LINUX */ + return system_data_path; + } + + bool isValidConfigFile(std::string file_path_) + { + if (file_path_.empty()) { return false; } + + // check existence of user defined file + const EcalUtils::Filesystem::FileStatus ecal_ini_status(file_path_, EcalUtils::Filesystem::Current); + if (ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile)) + { + return true; + } + + return false; + } +} namespace eCAL { namespace Config { - CmdParser::CmdParser(int argc_ , char **argv_) + CmdParser::CmdParser() : m_dump_config{false} - , m_config_keys{std::vector()} + , m_config_keys{} + , m_task_parameter{} + , m_user_ini{} + , m_valid_ini{} + {} + + CmdParser::CmdParser(int argc_ , char **argv_) + : CmdParser() + { + parseArguments(argc_, argv_); + } + + void CmdParser::parseArguments(int argc_, char **argv_) { #if ECAL_CORE_COMMAND_LINE if ((argc_ > 0) && (argv_ != nullptr)) @@ -48,7 +172,8 @@ namespace eCAL } if (default_ini_file_arg.isSet()) { - g_default_ini_file = default_ini_file_arg.getValue(); + m_user_ini = default_ini_file_arg.getValue(); + m_valid_ini = checkForValidConfigFilePath(default_ini_file_arg.getValue()); } if (set_config_key_arg.isSet()) { @@ -60,7 +185,55 @@ namespace eCAL { for (size_t i = 0; i < static_cast(argc_); ++i) if (argv_[i] != nullptr) m_task_parameter.emplace_back(argv_[i]); } + } - + + std::string CmdParser::checkForValidConfigFilePath(std::string config_file_) + { + // differences to ecal_config_reader implementation are: + // 1. it does not use the default ini file name, instead uses the specified file + // 2. it searches relative to the executable path and takes it as highest priority + + // ----------------------------------------------------------- + // precedence 1: relative path to executable + // ----------------------------------------------------------- + const std::string cwd_directory_path{ cwdPath() + config_file_}; + // ----------------------------------------------------------- + // precedence 2: ECAL_DATA variable (windows and linux) + // ----------------------------------------------------------- + const std::string ecal_data_path{ eCALDataEnvPath() + config_file_}; + + // ----------------------------------------------------------- + // precedence 3: cmake configured data paths (linux only) + // ----------------------------------------------------------- + const std::string cmake_data_path{ eCALDataCMakePath() + config_file_}; + + // ----------------------------------------------------------- + // precedence 4: system data path + // ----------------------------------------------------------- + const std::string system_data_path(eCALDataSystemPath() + config_file_); + + // Check for first directory which contains the ini file. + std::vector search_directories{ cwd_directory_path, ecal_data_path, cmake_data_path, system_data_path }; + + auto it = std::find_if(search_directories.begin(), search_directories.end(), isValidConfigFile); + // We should have encountered a valid path + if (it != search_directories.end()) + return (*it); + + // If valid path is not encountered, defaults should be used + return std::string(""); + } + + void CmdParser::setUserIni(const std::string& ini_) + { + m_user_ini = ini_; + } + + bool CmdParser::getDumpConfig() const { return m_dump_config; }; + std::vector& CmdParser::getConfigKeys() { return m_config_keys; }; + std::vector& CmdParser::getTaskParameter() { return m_task_parameter; }; + std::string& CmdParser::getUserIni() { return m_user_ini; }; + std::string& CmdParser::getValidIni() { return m_valid_ini; }; } } diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index 5993b88c62..6ea155d78a 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -21,6 +21,8 @@ * @brief Utility class for parsing cmd line arguments into eCAL useful structures. **/ +#pragma once + #include #include @@ -28,19 +30,37 @@ namespace eCAL { namespace Config { + /** + * @brief Class for parsing and storing command line arguments and their values. + * Defaults as empty strings, vectors and false booleans. + * + * @param argc_ Number of arguments + * @param argv_ Array of arguments + * + **/ class CmdParser { public: CmdParser(int argc_ , char **argv_); + CmdParser(); + + void parseArguments(int argc_, char **argv_); + void setUserIni(const std::string& ini_); - bool dumpConfig() const { return m_dump_config; }; - std::vector& getConfigKeys() { return m_config_keys; }; - std::vector& getTaskParameter() { return m_task_parameter; }; + bool getDumpConfig() const; + std::vector& getConfigKeys(); + std::vector& getTaskParameter(); + std::string& getUserIni(); + std::string& getValidIni(); private: + std::string checkForValidConfigFilePath(std::string config_file_); + std::vector m_config_keys; bool m_dump_config; std::vector m_task_parameter; + std::string m_user_ini; + std::string m_valid_ini; }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 9862a0aabd..c492353cc5 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -30,6 +30,8 @@ #include "ecal/ecal_process.h" #include "config/ecal_cmd_parser.h" +#include + constexpr const char* COMMON = "common"; constexpr const char* MONITORING = "monitoring"; constexpr const char* NETWORK = "network"; @@ -100,14 +102,16 @@ namespace eCAL void eCALConfig::InitConfig() { CConfig iniConfig; - iniConfig.OverwriteKeys(config_keys); - iniConfig.AddFile(g_default_ini_file); + iniConfig.OverwriteKeys(command_line_arguments.config_keys); + std::string ini_to_load; + if (command_line_arguments.found_config_file.empty()) + ini_to_load = g_default_ini_file; + else + ini_to_load = command_line_arguments.found_config_file; - // g_default_ini_file will be altered in case the loading is successful - // otherwise config.loaded_ecal_ini_file will stay empty - if (g_default_ini_file != ECAL_DEFAULT_CFG) + if (iniConfig.AddFile(ini_to_load)) { - loaded_ecal_ini_file = g_default_ini_file; + loaded_ecal_ini_file = ini_to_load; } // transport layer options @@ -210,19 +214,35 @@ namespace eCAL eCALConfig::eCALConfig(int argc_ , char **argv_) { - CmdParser cmd_parser(argc_, argv_); + Init(argc_, argv_); + } - config_keys = cmd_parser.getConfigKeys(); + eCALConfig::eCALConfig(std::vector args_) + { + args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); + std::vector argv(args_.size()); + std::transform(args_.begin(), args_.end(), argv.begin(), [](std::string& s) {return s.c_str();}); + Init(static_cast(argv.size()), const_cast(argv.data())); + } + + void eCALConfig::Init(int argc_ , char **argv_) + { + CmdParser parser(argc_, argv_); + + command_line_arguments.config_keys = parser.getConfigKeys(); + command_line_arguments.specified_config = parser.getUserIni(); + command_line_arguments.dump_config = parser.getDumpConfig(); + command_line_arguments.found_config_file = parser.getValidIni(); + InitConfig(); - if (cmd_parser.dumpConfig()) + if (command_line_arguments.dump_config) { Process::DumpConfig(); } } - // after initialization eCALConfig& GetCurrentConfig() { return g_ecal_config(); diff --git a/ecal/core/src/config/ecal_config_reader.cpp b/ecal/core/src/config/ecal_config_reader.cpp index cefe229658..9f82adacf2 100644 --- a/ecal/core/src/config/ecal_config_reader.cpp +++ b/ecal/core/src/config/ecal_config_reader.cpp @@ -294,7 +294,7 @@ namespace eCAL m_overwrite_keys = key_vec_; } - void AddFile(std::string& file_name_) + bool AddFile(std::string& file_name_) { std::string cfg_fname = file_name_; if (!fileexists(cfg_fname)) @@ -340,6 +340,8 @@ namespace eCAL std::cout << "Error: Could not overwrite key " << key << " in section " << section << "."; } } + + return loaded; } protected: std::vector m_overwrite_keys; @@ -379,9 +381,9 @@ namespace eCAL m_impl->OverwriteKeys(key_vec_); } - void CConfig::AddFile(std::string& ini_file_) + bool CConfig::AddFile(std::string& ini_file_) { - m_impl->AddFile(ini_file_); + return m_impl->AddFile(ini_file_); } bool CConfig::Validate() diff --git a/ecal/core/src/config/ecal_config_reader.h b/ecal/core/src/config/ecal_config_reader.h index d1bbca0a45..22c4fed1a5 100644 --- a/ecal/core/src/config/ecal_config_reader.h +++ b/ecal/core/src/config/ecal_config_reader.h @@ -39,7 +39,7 @@ namespace eCAL virtual ~CConfig(); void OverwriteKeys(const std::vector& key_vec_); - void AddFile(std::string& ini_file_); + bool AddFile(std::string& ini_file_); bool Validate(); diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 9ad1254c72..fd2102c45b 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -125,7 +125,7 @@ namespace eCAL const int success = g_globals()->Initialize(components_, &cmd_parser.getConfigKeys()); // print out configuration - if (cmd_parser.dumpConfig()) + if (cmd_parser.getDumpConfig()) { Process::DumpConfig(); } diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index 86e6f7a117..ae462fae6b 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -80,5 +80,13 @@ namespace eCAL { throw std::invalid_argument("[IpAddressV4] No valid IP address: " + ip_address_); } + + std::string IpAddressV4::GetIpString() const { return m_ip_address; }; + IpAddressV4::IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; + IpAddressV4& IpAddressV4::operator=(const IpAddressV4& other) { this->m_ip_address = other.GetIpString(); return *this; }; + IpAddressV4& IpAddressV4::operator=(const std::string& ip_string) { this->validateIpString(ip_string); return *this; }; + IpAddressV4::operator std::string() { return m_ip_address; }; + + std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.GetIpString(); return os; }; } } From 543949e17c09fc56d148779237be49e3411eb8f4 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:32:41 +0200 Subject: [PATCH 069/105] Refactored ecal Initialize with the config handling. --- ecal/core/src/ecal.cpp | 46 ++++++++++-------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index fd2102c45b..5c0ab05e25 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -100,37 +100,9 @@ namespace eCAL **/ int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) { - eCAL::Config::CmdParser cmd_parser(argc_, argv_); + eCAL::Config::eCALConfig config(argc_, argv_); - // in case of first call - if (g_globals_ctx == nullptr) - { - InitGlobals(); - } - - if (argc_ > 0 && argv_ != nullptr) - { - eCAL::Config::eCALConfig config(argc_, argv_); - g_globals()->SetEcalConfig(config); - } - - if (unit_name_ != nullptr) - { - SetGlobalUnitName(unit_name_); - } - - g_globals_ctx_ref_cnt++; - - // (post)initialize single components - const int success = g_globals()->Initialize(components_, &cmd_parser.getConfigKeys()); - - // print out configuration - if (cmd_parser.getDumpConfig()) - { - Process::DumpConfig(); - } - - return success; + return Initialize(config, unit_name_, components_); } /** @@ -144,10 +116,8 @@ namespace eCAL **/ int Initialize(std::vector args_, const char *unit_name_, unsigned int components_) //-V826 { - args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); - std::vector argv(args_.size()); - std::transform(args_.begin(), args_.end(), argv.begin(), [](std::string& s) {return s.c_str();}); - return Initialize(static_cast(argv.size()), const_cast(argv.data()), unit_name_, components_); + eCAL::Config::eCALConfig config(args_); + return Initialize(config, unit_name_, components_); } /** @@ -171,8 +141,14 @@ namespace eCAL { SetGlobalUnitName(unit_name_); } + + g_globals_ctx_ref_cnt++; + + // (post)initialize single components + const int success = g_globals()->Initialize(components_, &Config::GetCurrentConfig().command_line_arguments.config_keys); + - return Initialize(0, nullptr, unit_name_, components_); + return success; } /** From eb1a4ee802a4886425da656d2d36a265246b7565 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:47:59 +0200 Subject: [PATCH 070/105] Throw exception for ecal registration options. --- ecal/core/include/ecal/ecal_core.h | 1 + ecal/core/include/ecal/types/ecal_registration_options.h | 6 ++---- ecal/core/src/ecal.cpp | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index 0fea741f6e..4bf03cc2b2 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -87,6 +87,7 @@ namespace eCAL * @brief Initialize eCAL API. * * @param config_ User defined configuration object. + * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * * @return Zero if succeeded, 1 if already initialized, -1 if failed. diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h index 6e4005f924..a4eaafea1e 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -24,8 +24,7 @@ #pragma once -#include -#include +#include namespace eCAL { @@ -44,8 +43,7 @@ namespace eCAL } else { - std::cerr << "[RegistrationOptions] Refresh(" << reg_refresh_ << ") >= registration timeout (" << reg_timeout_ << ")." << "\n"; - exit(EXIT_FAILURE); + throw std::invalid_argument("[RegistrationOptions] Refresh(" + std::to_string(reg_refresh_) + ") >= registration timeout (" + std::to_string(reg_timeout_) + ")."); } }; diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 5c0ab05e25..733b946e2c 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -124,6 +124,7 @@ namespace eCAL * @brief Initialize eCAL API. * * @param config_ User defined configuration object. + * @param unit_name_ Defines the name of the eCAL unit. * @param components_ Defines which component to initialize. * * @return Zero if succeeded, 1 if already initialized, -1 if failed. From a362f268dd39ae3475a93ad89d2d39d235a0fa3e Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:35:50 +0200 Subject: [PATCH 071/105] Refactored ecal_registration_options. --- ecal/core/CMakeLists.txt | 1 + .../ecal/types/ecal_registration_options.h | 45 ++++++++------- .../src/types/ecal_registration_options.cpp | 56 +++++++++++++++++++ 3 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 ecal/core/src/types/ecal_registration_options.cpp diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index b08d86bc08..c32ec24c91 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -73,6 +73,7 @@ set(ecal_config_src src/config/ecal_config_reader.h src/config/ecal_config_reader_hlp.h src/types/ecal_custom_data_types.cpp + src/types/ecal_registration_options.cpp ) ###################################### diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/types/ecal_registration_options.h index a4eaafea1e..131fff26bb 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/types/ecal_registration_options.h @@ -24,38 +24,41 @@ #pragma once +#include "ecal/ecal_os.h" + #include +#include namespace eCAL { namespace Config { + /** + * @brief Struct for storing RegistrationOptions. + * If not specified, registration timeout and refresh times from eCAL predefines will be used. + * When specifying: reg_timeout >= reg_refresh. If not, an invalid_argument exception will be thrown. + * By default, share_ttype and share_tdesc is true based on eCAL predefines. + * + * @param reg_timeout_ Timeout for topic registration in ms + * @param reg_refresh_ Topic registration refresh cylce in ms + * + * @throws std::invalid_argument exception. + **/ struct RegistrationOptions { public: - RegistrationOptions() = default; - RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_) - { - if (reg_refresh_ < reg_timeout_) - { - registration_timeout = reg_timeout_; - registration_refresh = reg_refresh_; - } - else - { - throw std::invalid_argument("[RegistrationOptions] Refresh(" + std::to_string(reg_refresh_) + ") >= registration timeout (" + std::to_string(reg_timeout_) + ")."); - } - }; - - unsigned int getTimeoutMS() const { return registration_timeout; } - unsigned int getRefreshMS() const { return registration_refresh; } - - bool share_ttype = true; - bool share_tdesc = true; + ECAL_API RegistrationOptions(); + ECAL_API RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_); + + ECAL_API unsigned int getTimeoutMS() const; + ECAL_API unsigned int getRefreshMS() const; + + bool share_ttype; + bool share_tdesc; private: - unsigned int registration_timeout = 60000U; - unsigned int registration_refresh = 1000U; + unsigned int m_registration_timeout; + unsigned int m_registration_refresh; }; } } \ No newline at end of file diff --git a/ecal/core/src/types/ecal_registration_options.cpp b/ecal/core/src/types/ecal_registration_options.cpp new file mode 100644 index 0000000000..b3ddec7b1b --- /dev/null +++ b/ecal/core/src/types/ecal_registration_options.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 ================================= +*/ + +/** + * @brief Definition of custom data types. +**/ + +#include "ecal/types/ecal_registration_options.h" +#include "ecal_def.h" + +namespace eCAL +{ + namespace Config + { + RegistrationOptions::RegistrationOptions() + : share_ttype(PUB_SHARE_TTYPE) + , share_tdesc(PUB_SHARE_TDESC) + , m_registration_timeout(CMN_REGISTRATION_TO) + , m_registration_refresh(CMN_REGISTRATION_REFRESH) + {} + + RegistrationOptions::RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_) + : share_ttype(PUB_SHARE_TTYPE) + , share_tdesc(PUB_SHARE_TDESC) + { + if (reg_refresh_ < reg_timeout_) + { + m_registration_timeout = reg_timeout_; + m_registration_refresh = reg_refresh_; + } + else + { + throw std::invalid_argument("[RegistrationOptions] Refresh(" + std::to_string(reg_refresh_) + ") >= registration timeout (" + std::to_string(reg_timeout_) + ")."); + } + } + + unsigned int RegistrationOptions::getTimeoutMS() const { return m_registration_timeout; } + unsigned int RegistrationOptions::getRefreshMS() const { return m_registration_refresh; } + } +} \ No newline at end of file From ba0a6c1012a3f49ea9649f60e927b751ccd43766 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:37:37 +0200 Subject: [PATCH 072/105] cmd parser: path sep renaming. --- ecal/core/src/config/ecal_cmd_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index f49020a6a5..45005ede2f 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -28,7 +28,7 @@ namespace const char path_separator('\\'); #endif /* ECAL_OS_WINDOWS */ #ifdef ECAL_OS_LINUX - const char path_sep_bla('/'); + const char path_separator('/'); #endif /* ECAL_OS_LINUX */ bool SetPathSep(std::string file_path_) From 51308c04d4ec3317416c740f8f0bcdc846b9367e Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:18:55 +0200 Subject: [PATCH 073/105] Cmd parser: throw error message, when cmd line ini file was not found. --- ecal/core/include/ecal/types/user_arg_options.h | 1 - ecal/core/src/config/ecal_cmd_parser.cpp | 15 ++++----------- ecal/core/src/config/ecal_cmd_parser.h | 5 +---- ecal/core/src/config/ecal_config_initializer.cpp | 6 +++--- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/types/user_arg_options.h index 4a7831f108..73566d2a9b 100644 --- a/ecal/core/include/ecal/types/user_arg_options.h +++ b/ecal/core/include/ecal/types/user_arg_options.h @@ -35,7 +35,6 @@ namespace eCAL { std::vector config_keys{}; std::string specified_config{}; - std::string found_config_file{}; bool dump_config{}; }; } diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 45005ede2f..7837fbae2f 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -129,7 +129,6 @@ namespace eCAL , m_config_keys{} , m_task_parameter{} , m_user_ini{} - , m_valid_ini{} {} CmdParser::CmdParser(int argc_ , char **argv_) @@ -172,8 +171,7 @@ namespace eCAL } if (default_ini_file_arg.isSet()) { - m_user_ini = default_ini_file_arg.getValue(); - m_valid_ini = checkForValidConfigFilePath(default_ini_file_arg.getValue()); + m_user_ini = checkForValidConfigFilePath(default_ini_file_arg.getValue()); } if (set_config_key_arg.isSet()) { @@ -193,6 +191,7 @@ namespace eCAL // differences to ecal_config_reader implementation are: // 1. it does not use the default ini file name, instead uses the specified file // 2. it searches relative to the executable path and takes it as highest priority + // 3. it throws a runtime error, if it cannot find the specified file // ----------------------------------------------------------- // precedence 1: relative path to executable @@ -221,19 +220,13 @@ namespace eCAL if (it != search_directories.end()) return (*it); - // If valid path is not encountered, defaults should be used - return std::string(""); - } - - void CmdParser::setUserIni(const std::string& ini_) - { - m_user_ini = ini_; + // If valid path is not encountered, throw error + throw std::runtime_error("[CMD Parser] Specified config file: \"" + config_file_ + "\" not found."); } bool CmdParser::getDumpConfig() const { return m_dump_config; }; std::vector& CmdParser::getConfigKeys() { return m_config_keys; }; std::vector& CmdParser::getTaskParameter() { return m_task_parameter; }; std::string& CmdParser::getUserIni() { return m_user_ini; }; - std::string& CmdParser::getValidIni() { return m_valid_ini; }; } } diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index 6ea155d78a..5f51ea7604 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -44,14 +44,12 @@ namespace eCAL CmdParser(int argc_ , char **argv_); CmdParser(); - void parseArguments(int argc_, char **argv_); - void setUserIni(const std::string& ini_); + void parseArguments(int argc_, char **argv_); bool getDumpConfig() const; std::vector& getConfigKeys(); std::vector& getTaskParameter(); std::string& getUserIni(); - std::string& getValidIni(); private: std::string checkForValidConfigFilePath(std::string config_file_); @@ -60,7 +58,6 @@ namespace eCAL bool m_dump_config; std::vector m_task_parameter; std::string m_user_ini; - std::string m_valid_ini; }; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index c492353cc5..968b6bbd29 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -104,11 +104,12 @@ namespace eCAL CConfig iniConfig; iniConfig.OverwriteKeys(command_line_arguments.config_keys); std::string ini_to_load; - if (command_line_arguments.found_config_file.empty()) + if (command_line_arguments.specified_config.empty()) ini_to_load = g_default_ini_file; else - ini_to_load = command_line_arguments.found_config_file; + ini_to_load = command_line_arguments.specified_config; + // Can here go something wrong at all, in case the cmd line ini was used? if (iniConfig.AddFile(ini_to_load)) { loaded_ecal_ini_file = ini_to_load; @@ -233,7 +234,6 @@ namespace eCAL command_line_arguments.config_keys = parser.getConfigKeys(); command_line_arguments.specified_config = parser.getUserIni(); command_line_arguments.dump_config = parser.getDumpConfig(); - command_line_arguments.found_config_file = parser.getValidIni(); InitConfig(); From aca5d69bf6f43e78892eaabafda50355f531bc47 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:53:12 +0200 Subject: [PATCH 074/105] Changed ini handling for config file. --- .../include/ecal/types/ecal_config_types.h | 4 +- .../src/config/ecal_config_initializer.cpp | 23 +++++----- ecal/core/src/config/ecal_config_reader.cpp | 44 +++++++++++-------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 9da296665c..fba1d7ea20 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -64,8 +64,10 @@ namespace eCAL ECAL_API eCALConfig(int argc_ , char **argv_); ECAL_API eCALConfig(std::vector args_); + ECAL_API void InitWithDefaultIni(); + private: - ECAL_API void InitConfig(); + ECAL_API void InitConfig(std::string ini_path_ = std::string("")); ECAL_API void Init(int argc_ , char **argv_); }; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 968b6bbd29..a63aaa8bfd 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -99,20 +99,16 @@ namespace eCAL { namespace Config { - void eCALConfig::InitConfig() + void eCALConfig::InitConfig(std::string ini_path_ /*= std::string("")*/) { CConfig iniConfig; - iniConfig.OverwriteKeys(command_line_arguments.config_keys); - std::string ini_to_load; - if (command_line_arguments.specified_config.empty()) - ini_to_load = g_default_ini_file; - else - ini_to_load = command_line_arguments.specified_config; + if (!command_line_arguments.config_keys.empty()) + iniConfig.OverwriteKeys(command_line_arguments.config_keys); - // Can here go something wrong at all, in case the cmd line ini was used? - if (iniConfig.AddFile(ini_to_load)) + if (!ini_path_.empty()) { - loaded_ecal_ini_file = ini_to_load; + iniConfig.AddFile(ini_path_); + loaded_ecal_ini_file = ini_path_; } // transport layer options @@ -235,7 +231,7 @@ namespace eCAL command_line_arguments.specified_config = parser.getUserIni(); command_line_arguments.dump_config = parser.getDumpConfig(); - InitConfig(); + InitConfig(command_line_arguments.specified_config); if (command_line_arguments.dump_config) { @@ -243,6 +239,11 @@ namespace eCAL } } + void eCALConfig::InitWithDefaultIni() + { + InitConfig(g_default_ini_file); + } + eCALConfig& GetCurrentConfig() { return g_ecal_config(); diff --git a/ecal/core/src/config/ecal_config_reader.cpp b/ecal/core/src/config/ecal_config_reader.cpp index 9f82adacf2..c3d796b79b 100644 --- a/ecal/core/src/config/ecal_config_reader.cpp +++ b/ecal/core/src/config/ecal_config_reader.cpp @@ -292,6 +292,30 @@ namespace eCAL void OverwriteKeys(const std::vector& key_vec_) { m_overwrite_keys = key_vec_; + OverwriteKeysNow(); + } + + void OverwriteKeysNow() + { + // update command line keys + for (const auto& full_key : m_overwrite_keys) + { + auto sec_pos = full_key.find_last_of('/'); + if (sec_pos == std::string::npos) continue; + const std::string section = full_key.substr(0, sec_pos); + std::string key = full_key.substr(sec_pos+1); + + auto val_pos = key.find_first_of(':'); + if (val_pos == std::string::npos) continue; + const std::string value = key.substr(val_pos+1); + key = key.substr(0, val_pos); + + const SI_Error err = SetValue(section.c_str(), key.c_str(), value.c_str()); + if (err == SI_FAIL) + { + std::cout << "Error: Could not overwrite key " << key << " in section " << section << "."; + } + } } bool AddFile(std::string& file_name_) @@ -321,25 +345,7 @@ namespace eCAL file_name_ = cfg_fname; } - // update command line keys - for (const auto& full_key : m_overwrite_keys) - { - auto sec_pos = full_key.find_last_of('/'); - if (sec_pos == std::string::npos) continue; - const std::string section = full_key.substr(0, sec_pos); - std::string key = full_key.substr(sec_pos+1); - - auto val_pos = key.find_first_of(':'); - if (val_pos == std::string::npos) continue; - const std::string value = key.substr(val_pos+1); - key = key.substr(0, val_pos); - - const SI_Error err = SetValue(section.c_str(), key.c_str(), value.c_str()); - if (err == SI_FAIL) - { - std::cout << "Error: Could not overwrite key " << key << " in section " << section << "."; - } - } + OverwriteKeysNow(); return loaded; } From 557637afbd5b59ada0a5f9031da3323627ba218d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:18:41 +0200 Subject: [PATCH 075/105] Updated docu for config and example. --- .../configuration/runtime_configuration.rst | 20 +++++++++++-------- .../configuration/src/hello_config/main.cpp | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 3123df503c..5a05eed558 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -12,27 +12,27 @@ The corresponding structure reflects the configuration file (:ref:`configuration Custom types ============ -In order to exclude configuration errors, custom datatypes for IP addresses and sizes are introduced. +In order to exclude configuration errors, custom datatypes for IP addresses and sizes (constrained integer) are introduced. For assigning an ip address simply assign a string with the desired address. Decimal and hexadecimal format is supported. In case the ip address is not valid, the type will throw a std::invalid_argument exception. -You can use the ip address like a normal string object. For example: +The ip address can be used like a normal string object. For example: .. code-block:: c++ eCAL::Config::IpAddressV4 ip_address = std::string("192.168.7.1"); // in hex: "C0.A8.7.1" std::cout << ip_address << "\n"; -Sizes are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. +ConstrainedInteger are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. In case the assigned value does not fit into the specified limitation, the type will throw a std::invalid_argument exception. -You can use the size object like a normal integer. +The size object can be used like a normal integer. .. code-block:: c++ - eCAL::Config::LimitSize<1024, 512, 8192> size_4mb = 1024 + 6 * 512; + eCAL::Config::ConstrainedInteger<1024, 512, 8192> size_4mb = 1024 + 6 * 512; std::cout << size_4mb << "\n"; For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/types/ecal_config_types.h" for the limitations. @@ -40,9 +40,13 @@ For specifying sizes in the ecal configuration object, refer to the .ini file or Initialization of the configuration =================================== -The configuration will be first initialized with the default .ini file found in the system. -In case the .ini to use is specified vial command line parameter, this one is chosen instead. -If it cannot find any .ini file, default values will be used for the first initialization of the configuration. +The configuration will be first initialized with the default values specified by eCAL. +If you want to use the systems eCAL .ini file, call the InitConfigWithDefaultIni() function of the config object. + +In case the .ini to use is specified via command line parameter, this one is chosen instead. +The object will throw an error, in case the specified .ini file cannot be found. + +It is also possible to specify the .ini by calling the function InitConfig(std::string _ini_path) of the config object. * |fa-file-alt| :file:`hello_config/main.cpp`: diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 5cf693d5f9..e487131843 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -8,6 +8,12 @@ int main(int argc, char** argv) // Create a configuration object with the command line arguments eCAL::Config::eCALConfig custom_config(argc, argv); + // Use the .ini file of the system ... + custom_config.InitConfigWithDefaultIni(); + + // .. or specify an own .ini file to use + custom_conig.InitConfig("C:\\eCAL_local.ini"); + // Set the values in a try/catch block, as wrong configuration leads to exceptions try { From d910ef2bdd3b469dfa44ea969dda00c4913c80c9 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:19:02 +0200 Subject: [PATCH 076/105] give user the freedom to initialize with specified ini file. --- ecal/core/include/ecal/types/ecal_config_types.h | 4 ++-- ecal/core/src/config/ecal_config_initializer.cpp | 7 +------ ecal/core/src/ecal.cpp | 4 ++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index fba1d7ea20..cfd0a0dbf9 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -64,10 +64,10 @@ namespace eCAL ECAL_API eCALConfig(int argc_ , char **argv_); ECAL_API eCALConfig(std::vector args_); - ECAL_API void InitWithDefaultIni(); + ECAL_API void InitConfigWithDefaultIni(); + ECAL_API void InitConfig(std::string ini_path_); private: - ECAL_API void InitConfig(std::string ini_path_ = std::string("")); ECAL_API void Init(int argc_ , char **argv_); }; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index a63aaa8bfd..f2cc9ef744 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -232,14 +232,9 @@ namespace eCAL command_line_arguments.dump_config = parser.getDumpConfig(); InitConfig(command_line_arguments.specified_config); - - if (command_line_arguments.dump_config) - { - Process::DumpConfig(); - } } - void eCALConfig::InitWithDefaultIni() + void eCALConfig::InitConfigWithDefaultIni() { InitConfig(g_default_ini_file); } diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 733b946e2c..365d29ee2e 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -148,6 +148,10 @@ namespace eCAL // (post)initialize single components const int success = g_globals()->Initialize(components_, &Config::GetCurrentConfig().command_line_arguments.config_keys); + if (config_.command_line_arguments.dump_config) + { + Process::DumpConfig(); + } return success; } From 5476f0414db08a9b0408a999b87947eb7898babb Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 15 May 2024 08:51:35 +0200 Subject: [PATCH 077/105] Some whitespaces. --- .../ecal/types/ecal_monitoring_options.h | 10 +++++----- .../ecal/types/ecal_transport_layer_options.h | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/types/ecal_monitoring_options.h index 43af648158..9b196c6b14 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/types/ecal_monitoring_options.h @@ -52,11 +52,11 @@ namespace eCAL struct MonitoringOptions { - eCAL_MonitoringMode_Filter monitoring_mode{}; - ConstrainedInteger<1000, 1000> monitoring_timeout{}; - bool network_monitoring{}; - UDPMonitoringOptions udp_options{}; - SHMMonitoringOptions shm_options{}; + eCAL_MonitoringMode_Filter monitoring_mode{}; + ConstrainedInteger<1000, 1000> monitoring_timeout{}; + bool network_monitoring{}; + UDPMonitoringOptions udp_options{}; + SHMMonitoringOptions shm_options{}; std::string filter_excl{}; std::string filter_incl{}; diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 0f0c89ce23..0db36d00d1 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -39,26 +39,26 @@ namespace eCAL struct SHMOptions { - std::string host_group_name{}; + std::string host_group_name{}; ConstrainedInteger<4096, 4096> memfile_minsize{}; ConstrainedInteger<50, 1, 100> memfile_reserve{}; - int memfile_ack_timeout{}; + int memfile_ack_timeout{}; ConstrainedInteger<0, 1> memfile_buffer_count{}; - bool drop_out_of_order_messages{}; - bool memfile_zero_copy{}; + bool drop_out_of_order_messages{}; + bool memfile_zero_copy{}; }; struct UdpMulticastOptions { - UdpConfigVersion config_version{}; - IpAddressV4 group{}; - IpAddressV4 mask{}; + UdpConfigVersion config_version{}; + IpAddressV4 group{}; + IpAddressV4 mask{}; ConstrainedInteger<14000, 10> port{}; - unsigned int ttl{}; + unsigned int ttl{}; // TODO PG: are these minimum limits correct? ConstrainedInteger<5242880, 1024> sndbuf{}; ConstrainedInteger<5242880, 1024> recbuf{}; - bool join_all_interfaces{}; + bool join_all_interfaces{}; int bandwidth_max_udp{}; bool npcap_enabled{}; From 1435ee8225e78d53290c9d2d215a94e59156e119 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 15 May 2024 09:46:29 +0200 Subject: [PATCH 078/105] Added RegistrationOptions test. --- .../tests/cpp/config_test/src/config_test.cpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 1e374a7173..240c2fa615 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -61,19 +61,16 @@ TEST(core_cpp_config, user_config_passing) custom_config.transport_layer_options.mc_options.group = ip_address; custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; - custom_config.monitoring_options.monitoring_timeout = mon_timeout; custom_config.monitoring_options.filter_excl = mon_filter_excl; custom_config.monitoring_options.monitoring_mode = monitoring_mode; custom_config.logging_options.filter_log_con = mon_log_filter_con; - custom_config.publisher_options.use_shm = pub_use_shm; - custom_config.registration_options = registration_options; } - catch (std::invalid_argument e) + catch (std::invalid_argument& e) { throw std::runtime_error("Error while configuring eCALConfig: " + std::string(e.what())); } @@ -174,9 +171,18 @@ TEST(ConfigDeathTest, user_config_death_test) ASSERT_THROW( SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), std::invalid_argument); + + // Test the registration option limits + // Refresh timeout > registration timeout + ASSERT_THROW( + eCAL::Config::RegistrationOptions(2000U, 3000U), std::invalid_argument); + + // Refresh timeout = registration timeout + ASSERT_THROW( + eCAL::Config::RegistrationOptions(2000U, 2000U), std::invalid_argument); } -TEST(core_cpp_config, config_custom_datatypes) +TEST(core_cpp_config, config_custom_datatypes_tests) { // test custom datatype assignment operators eCAL::Config::IpAddressV4 ip1; @@ -204,4 +210,9 @@ TEST(core_cpp_config, config_custom_datatypes) config1 = config2ref; EXPECT_EQ(static_cast(config1.transport_layer_options.mc_options.group), testValue); +} + +TEST(core_cpp_config, config_cmd_parser) +{ + } \ No newline at end of file From 602212fc2f62fb5efbbc84f6edd5b94e8dfb0eb1 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 16 May 2024 08:43:45 +0200 Subject: [PATCH 079/105] Changed ini file handling for cmd parser -> return complete path in every scenario. --- ecal/core/src/config/ecal_cmd_parser.cpp | 35 ++++++++++++++++-------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 7837fbae2f..3323980f28 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -96,19 +96,17 @@ namespace #ifdef ECAL_OS_WINDOWS system_data_path = getEnvVar("ProgramData"); if(SetPathSep(system_data_path)) - system_data_path += std::string("eCAL") + path_separator; + system_data_path += path_separator + std::string("eCAL"); #endif /* ECAL_OS_WINDOWS */ #ifdef ECAL_OS_LINUX - system_data_path = "/etc/ecal/"; + system_data_path = "/etc/ecal"; #endif /* ECAL_OS_LINUX */ return system_data_path; } - bool isValidConfigFile(std::string file_path_) + bool isValidConfigFilePath(std::string file_path_) { - if (file_path_.empty()) { return false; } - // check existence of user defined file const EcalUtils::Filesystem::FileStatus ecal_ini_status(file_path_, EcalUtils::Filesystem::Current); if (ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile)) @@ -118,6 +116,14 @@ namespace return false; } + + std::string appendFileNameToPathIfPathIsValid(std::string path_, std::string file_name_) + { + if (path_.empty()) + return path_; + else + return path_ + path_separator + file_name_; + } } namespace eCAL @@ -196,30 +202,37 @@ namespace eCAL // ----------------------------------------------------------- // precedence 1: relative path to executable // ----------------------------------------------------------- - const std::string cwd_directory_path{ cwdPath() + config_file_}; + const std::string cwd_directory_path{ appendFileNameToPathIfPathIsValid(cwdPath(), config_file_) }; + // ----------------------------------------------------------- // precedence 2: ECAL_DATA variable (windows and linux) // ----------------------------------------------------------- - const std::string ecal_data_path{ eCALDataEnvPath() + config_file_}; + const std::string ecal_data_path{ appendFileNameToPathIfPathIsValid(eCALDataEnvPath(), config_file_) }; // ----------------------------------------------------------- // precedence 3: cmake configured data paths (linux only) // ----------------------------------------------------------- - const std::string cmake_data_path{ eCALDataCMakePath() + config_file_}; + const std::string cmake_data_path{ appendFileNameToPathIfPathIsValid(eCALDataCMakePath(), config_file_) }; // ----------------------------------------------------------- // precedence 4: system data path // ----------------------------------------------------------- - const std::string system_data_path(eCALDataSystemPath() + config_file_); + const std::string system_data_path( appendFileNameToPathIfPathIsValid(eCALDataSystemPath(), config_file_) ); // Check for first directory which contains the ini file. - std::vector search_directories{ cwd_directory_path, ecal_data_path, cmake_data_path, system_data_path }; + std::vector search_directories{ config_file_, cwd_directory_path, ecal_data_path, cmake_data_path, system_data_path }; - auto it = std::find_if(search_directories.begin(), search_directories.end(), isValidConfigFile); + auto it = std::find_if(search_directories.begin(), search_directories.end(), isValidConfigFilePath); // We should have encountered a valid path if (it != search_directories.end()) return (*it); + // Check if user specified complete path, in case all other precedence paths exist + if (isValidConfigFilePath(config_file_)) + { + return config_file_; + } + // If valid path is not encountered, throw error throw std::runtime_error("[CMD Parser] Specified config file: \"" + config_file_ + "\" not found."); } From 0dc73982fdaf090eed127e86cf00a084e15e1ab1 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 16 May 2024 08:44:28 +0200 Subject: [PATCH 080/105] Added cmd parser ini test and death test. --- ecal/tests/cpp/config_test/CMakeLists.txt | 21 +- .../tests/cpp/config_test/src/config_test.cpp | 50 +++++ ecal/tests/cpp/config_test/src/ini_file.h | 194 ++++++++++++++++++ 3 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 ecal/tests/cpp/config_test/src/ini_file.h diff --git a/ecal/tests/cpp/config_test/CMakeLists.txt b/ecal/tests/cpp/config_test/CMakeLists.txt index 5c0ac7e8c0..70947dab68 100644 --- a/ecal/tests/cpp/config_test/CMakeLists.txt +++ b/ecal/tests/cpp/config_test/CMakeLists.txt @@ -20,22 +20,39 @@ project(test_config) find_package(Threads REQUIRED) find_package(GTest REQUIRED) +find_package(tclap REQUIRED) + +set(cmd_parser_src + ${CMAKE_SOURCE_DIR}/ecal/core/src/config/ecal_cmd_parser.cpp + ${CMAKE_SOURCE_DIR}/lib/ecal_utils/src/filesystem.cpp + ${CMAKE_SOURCE_DIR}/lib/ecal_utils/src/str_convert.cpp +) set(config_test_src src/config_test.cpp + ${cmd_parser_src} ) ecal_add_gtest(${PROJECT_NAME} ${config_test_src}) -target_include_directories(${PROJECT_NAME} PRIVATE $) +target_include_directories(${PROJECT_NAME} PRIVATE + $ + ${CMAKE_CURRENT_LIST_DIR}/src + ${CMAKE_SOURCE_DIR}/ecal/core/src/config +) target_link_libraries(${PROJECT_NAME} PRIVATE eCAL::core - Threads::Threads) + Threads::Threads + tclap::tclap + CustomTclap +) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) +target_compile_definitions(${PROJECT_NAME} PRIVATE ECAL_CORE_COMMAND_LINE) + ecal_install_gtest(${PROJECT_NAME}) set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER tests/cpp/config) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 240c2fa615..c955c4d245 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -19,10 +19,15 @@ #include #include +#include #include #include +#include +#include + +#include "ecal_cmd_parser.h" template void SetValue(MEMBER& member, VALUE value) @@ -214,5 +219,50 @@ TEST(core_cpp_config, config_custom_datatypes_tests) TEST(core_cpp_config, config_cmd_parser) { + // create a custom ini file + std::ofstream custom_ini_file("customIni.ini"); + + if (custom_ini_file.is_open()) + { + custom_ini_file << ini_file_as_string; + custom_ini_file.close(); + } + else + { + std::cerr << "Error opening file for ini writing" << "\n"; + return; + } + + eCAL::Config::CmdParser parser; + + std::vector arguments; + + arguments.push_back("test_config_cmd_parser"); + arguments.push_back("--ecal-ini-file customIni.ini"); + + try + { + parser.parseArguments(static_cast(arguments.size()), const_cast(arguments.data())); + } + catch(const std::runtime_error& e) + { + std::cerr << e.what() << '\n'; + } + EXPECT_NE(parser.getUserIni(), std::string("")); +} + +TEST(CmdParserDeathTest, config_cmd_parser_death_test) +{ + eCAL::Config::CmdParser parser; + + std::vector arguments; + + arguments.push_back("test_config_cmd_parser_death_test"); + arguments.push_back("--ecal-ini-file someNotValidFileName.ini"); + + ASSERT_THROW( + parser.parseArguments(static_cast(arguments.size()), const_cast(arguments.data())), + std::runtime_error + ); } \ No newline at end of file diff --git a/ecal/tests/cpp/config_test/src/ini_file.h b/ecal/tests/cpp/config_test/src/ini_file.h new file mode 100644 index 0000000000..60ab98c00b --- /dev/null +++ b/ecal/tests/cpp/config_test/src/ini_file.h @@ -0,0 +1,194 @@ +#include + +std::string ini_file_as_string = +"; --------------------------------------------------\n" +"; NETWORK SETTINGS\n" +"; --------------------------------------------------\n" +"; network_enabled = true / false true = all eCAL components communicate over network boundaries\n" +"; false = local host only communication\n" +";\n" +"; multicast_config_version = v1 / v2 UDP configuration version (Since eCAL 5.12.)\n" +"; v1: default behavior\n" +"; v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups\n" +"; multicast_group = 239.0.0.1 UDP multicast group base\n" +"; All registration and logging is sent on this address\n" +"; multicast_mask = 0.0.0.1-0.0.0.255 v1: Mask maximum number of dynamic multicast group\n" +"; 255.0.0.0-255.255.255.255 v2: masks are now considered like routes masking\n" +";\n" +"; multicast_port = 14000 + x UDP multicast port number (eCAL will use at least the 2 following port\n" +"; numbers too, so please modify in steps of 10 (e.g. 1010, 1020 ...)\n" +";\n" +"; multicast_ttl = 0 + x UDP ttl value, also known as hop limit, is used in determining \n" +"; the intermediate routers being traversed towards the destination\n" +";\n" +"; multicast_sndbuf = 1024 * x UDP send buffer in bytes\n" +"; \n" +"; multicast_rcvbuf = 1024 * x UDP receive buffer in bytes\n" +";\n" +"; multicast_join_all_if = false Linux specific setting to enable joining multicast groups on all network interfacs\n" +"; independent of their link state. Enabling this makes sure that eCAL processes\n" +"; receive data if they are started before network devices are up and running.\n" +"; \n" +"; shm_rec_enabled = true Enable to receive on eCAL shared memory layer\n" +"; tcp_rec_enabled = true Enable to receive on eCAL tcp layer\n" +"; udp_mc_rec_enabled = true Enable to receive on eCAL udp multicast layer\n" +";\n" +"; npcap_enabled = false Enable to receive UDP traffic with the Npcap based receiver\n" +";\n" +"; tcp_pubsub_num_executor_reader = 4 Tcp_pubsub reader amount of threads that shall execute workload\n" +"; tcp_pubsub_num_executor_writer = 4 Tcp_pubsub writer amount of threads that shall execute workload\n" +"; tcp_pubsub_max_reconnections = 5 Tcp_pubsub reconnection attemps the session will try to reconnect in \n" +"; case of an issue (a negative value means infinite reconnection attemps)\n" +";\n" +"; host_group_name = Common host group name that enables interprocess mechanisms across \n" +"; (virtual) host borders (e.g, Docker); by default equivalent to local host name\n" +"; --------------------------------------------------\n" +"\n" +"[network]\n" +"network_enabled = false\n" +"multicast_config_version = v1\n" +"multicast_group = 239.0.0.1\n" +"multicast_mask = 0.0.0.15\n" +"multicast_port = 14000\n" +"multicast_ttl = 2\n" +"multicast_sndbuf = 5242880\n" +"multicast_rcvbuf = 5242880\n" +"\n" +"multicast_join_all_if = false\n" +"\n" +"shm_rec_enabled = true\n" +"tcp_rec_enabled = true\n" +"udp_mc_rec_enabled = true\n" +"\n" +"npcap_enabled = false\n" +"\n" +"tcp_pubsub_num_executor_reader = 4\n" +"tcp_pubsub_num_executor_writer = 4\n" +"tcp_pubsub_max_reconnections = 5\n" +"\n" +"host_group_name =\n" +"\n" +"; --------------------------------------------------\n" +"; COMMON SETTINGS\n" +"; --------------------------------------------------\n" +"; registration_timeout = 60000 Timeout for topic registration in ms (internal)\n" +"; registration_refresh = 1000 Topic registration refresh cylce (has to be smaller then registration timeout !)\n" +"\n" +"; --------------------------------------------------\n" +"[common]\n" +"registration_timeout = 60000\n" +"registration_refresh = 1000\n" +"\n" +"; --------------------------------------------------\n" +"; TIME SETTINGS\n" +"; --------------------------------------------------\n" +"; timesync_module_rt = ecaltime-localtime Time synchronisation interface name (dynamic library)\n" +"; The name will be extended with platform suffix (32|64), debug suffix (d) and platform extension (.dll|.so)\n" +";\n" +"; Available modules are:\n" +"; - ecaltime-localtime local system time without synchronization \n" +"; - ecaltime-linuxptp For PTP / gPTP synchronization over ethernet on Linux\n" +"; (device configuration in ecaltime.ini)\n" +"; --------------------------------------------------\n" +"[time]\n" +"timesync_module_rt = ecaltime-localtime\n" +"\n" +"; ---------------------------------------------\n" +"; PROCESS SETTINGS\n" +"; ---------------------------------------------\n" +";\n" +"; terminal_emulator = /usr/bin/x-terminal-emulator -e command for starting applications with an external terminal emulator. If empty, the command will be ignored. Ignored on Windows.\n" +"; e.g. /usr/bin/x-terminal-emulator -e\n" +"; /usr/bin/gnome-terminal -x\n" +"; /usr/bin/xterm -e\n" +";\n" +"; ---------------------------------------------\n" +"[process]\n" +"terminal_emulator = \n" +"\n" +"; --------------------------------------------------\n" +"; PUBLISHER SETTINGS\n" +"; --------------------------------------------------\n" +"; use_shm = 0, 1, 2 Use shared memory transport layer (0 = off, 1 = on, 2 = auto, default = 2)\n" +"; use_tcp = 0, 1, 2 Use tcp transport layer (0 = off, 1 = on, 2 = auto, default = 0)\n" +"; use_udp_mc = 0, 1, 2 Use udp multicast transport layer (0 = off, 1 = on, 2 = auto, default = 2)\n" +";\n" +"; memfile_minsize = x * 4096 kB Default memory file size for new publisher\n" +";\n" +"; memfile_reserve = 50 .. x % Dynamic file size reserve before recreating memory file if topic size changes\n" +";\n" +"; memfile_ack_timeout = 0 .. x ms Publisher timeout for ack event from subscriber that memory file content is processed\n" +";\n" +"; memfile_buffer_count = 1 .. x Number of parallel used memory file buffers for 1:n publish/subscribe ipc connections (default = 1)\n" +"; memfile_zero_copy = 0, 1 Allow matching subscriber to access memory file without copying its content in advance (blocking mode)\n" +";\n" +"; share_ttype = 0, 1 Share topic type via registration layer\n" +"; share_tdesc = 0, 1 Share topic description via registration layer (switch off to disable reflection)\n" +"; --------------------------------------------------\n" +"[publisher]\n" +"use_shm = 2\n" +"use_tcp = 0\n" +"use_udp_mc = 2\n" +"\n" +"memfile_minsize = 4096\n" +"memfile_reserve = 50\n" +"memfile_ack_timeout = 0\n" +"memfile_buffer_count = 1\n" +"memfile_zero_copy = 0\n" +"\n" +"share_ttype = 1\n" +"share_tdesc = 1\n" +"\n" +"; --------------------------------------------------\n" +"; SERVICE SETTINGS\n" +"; --------------------------------------------------\n" +"; protocol_v0 = 0, 1 Support service protocol v0, eCAL 5.11 and older (0 = off, 1 = on)\n" +"; protocol_v1 = 0, 1 Support service protocol v1, eCAL 5.12 and newer (0 = off, 1 = on)\n" +"; --------------------------------------------------\n" +"[service]\n" +"protocol_v0 = 1\n" +"protocol_v1 = 1\n" +"\n" +"; --------------------------------------------------\n" +"; MONITORING SETTINGS\n" +"; --------------------------------------------------\n" +"; timeout = 1000 + (x * 1000) Timeout for topic monitoring in ms\n" +"; filter_excl = __.* Topics blacklist as regular expression (will not be monitored)\n" +"; filter_incl = Topics whitelist as regular expression (will be monitored only)\n" +"; filter_log_con = info, warning, error, fatal Log messages logged to console (all, info, warning, error, fatal, debug1, debug2, debug3, debug4)\n" +"; filter_log_file = Log messages to logged into file system\n" +"; filter_log_udp = info, warning, error, fatal Log messages logged via udp network\n" +"; --------------------------------------------------\n" +"[monitoring]\n" +"timeout = 5000\n" +"filter_excl = __.*\n" +"filter_incl =\n" +"filter_log_con = info, warning, error, fatal\n" +"filter_log_file =\n" +"filter_log_udp = info, warning, error, fatal\n" +"\n" +"; --------------------------------------------------\n" +"; SYS SETTINGS\n" +"; --------------------------------------------------\n" +"; filter_excl = App1,App2 Apps blacklist to be excluded when importing tasks from cloud\n" +"; --------------------------------------------------\n" +"[sys]\n" +"filter_excl = ^eCALSysClient$|^eCALSysGUI$|^eCALSys$\n" +"\n" +"; --------------------------------------------------\n" +"; EXPERIMENTAL SETTINGS\n" +"; --------------------------------------------------\n" +"; shm_monitoring_enabled = false Enable distribution of monitoring/registration information via shared memory\n" +"; shm_monitoring_domain = ecal_monitoring Domain name for shared memory based monitoring/registration\n" +"; shm_monitoring_queue_size = 1024 Queue size of monitoring/registration events\n" +"; network_monitoring_enabled = true Enable distribution of monitoring/registration information via network\n" +";\n" +"; drop_out_of_order_messages = false Enable dropping of payload messages that arrive out of order\n" +"; --------------------------------------------------\n" +"[experimental]\n" +"shm_monitoring_enabled = false\n" +"shm_monitoring_domain = ecal_mon\n" +"shm_monitoring_queue_size = 1024\n" +"network_monitoring_enabled = true\n" +"drop_out_of_order_messages = false\n" +; \ No newline at end of file From e4543680873ed481c364615c0e13e57aaf1e2e29 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 16 May 2024 11:24:12 +0200 Subject: [PATCH 081/105] Added cmd parser config key test + store config keys in map. --- .../include/ecal/types/user_arg_options.h | 4 +++ ecal/core/src/config/ecal_cmd_parser.cpp | 21 +++++++++++++ ecal/core/src/config/ecal_cmd_parser.h | 4 +++ .../tests/cpp/config_test/src/config_test.cpp | 31 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/types/user_arg_options.h index 73566d2a9b..5d174dde82 100644 --- a/ecal/core/include/ecal/types/user_arg_options.h +++ b/ecal/core/include/ecal/types/user_arg_options.h @@ -26,6 +26,7 @@ #include #include +#include namespace eCAL { @@ -37,5 +38,8 @@ namespace eCAL std::string specified_config{}; bool dump_config{}; }; + + // Map[Section][Option] = Value + using ConfigKey2DMap = std::map>; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 3323980f28..0058d890e2 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -124,6 +124,25 @@ namespace else return path_ + path_separator + file_name_; } + + void parseConfigKeysToMap(std::vector config_keys_, eCAL::Config::ConfigKey2DMap& map_) + { + // each string has the format "section/key:value" + for (const auto& full_key : config_keys_) + { + auto sec_pos = full_key.find_last_of('/'); + if (sec_pos == std::string::npos) continue; + const std::string section = full_key.substr(0, sec_pos); + std::string key = full_key.substr(sec_pos+1); + + auto val_pos = key.find_first_of(':'); + if (val_pos == std::string::npos) continue; + const std::string value = key.substr(val_pos+1); + key = key.substr(0, val_pos); + + map_[section][key] = value; + } + } } namespace eCAL @@ -182,6 +201,7 @@ namespace eCAL if (set_config_key_arg.isSet()) { m_config_keys = set_config_key_arg.getValue(); + parseConfigKeysToMap(set_config_key_arg.getValue(), m_config_key_map); } } #endif @@ -241,5 +261,6 @@ namespace eCAL std::vector& CmdParser::getConfigKeys() { return m_config_keys; }; std::vector& CmdParser::getTaskParameter() { return m_task_parameter; }; std::string& CmdParser::getUserIni() { return m_user_ini; }; + ConfigKey2DMap& CmdParser::getConfigKeysMap() { return m_config_key_map; }; } } diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index 5f51ea7604..25b5fbf25a 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -25,6 +25,7 @@ #include #include +#include namespace eCAL { @@ -41,6 +42,7 @@ namespace eCAL class CmdParser { public: + using ConfigKey2DMap = std::map>; CmdParser(int argc_ , char **argv_); CmdParser(); @@ -50,11 +52,13 @@ namespace eCAL std::vector& getConfigKeys(); std::vector& getTaskParameter(); std::string& getUserIni(); + ConfigKey2DMap& getConfigKeysMap(); private: std::string checkForValidConfigFilePath(std::string config_file_); std::vector m_config_keys; + ConfigKey2DMap m_config_key_map; bool m_dump_config; std::vector m_task_parameter; std::string m_user_ini; diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index c955c4d245..9add48de91 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -237,8 +237,32 @@ TEST(core_cpp_config, config_cmd_parser) std::vector arguments; + const std::string set_config_key = "--ecal-set-config-key "; + const std::string sep_slash = "/"; + const std::string sep_col = ":"; + + const std::string network = "network"; + const std::string host_group_name = "host_group_name"; + const std::string config_test_machine = "ConfigTestMachine"; + const std::string network_enabled = "network_enabled"; + const std::string is_network_enabled = "true"; + + const std::string common = "common"; + const std::string registration_timeout = "registration_timeout"; + const std::string registration_refresh = "registration_refresh"; + const std::string reg_to_value = "6000"; + const std::string reg_rf_value = "1000"; + arguments.push_back("test_config_cmd_parser"); arguments.push_back("--ecal-ini-file customIni.ini"); + std::string host_group_string = set_config_key + network + sep_slash + host_group_name + sep_col + config_test_machine; + arguments.push_back(host_group_string.data()); + std::string network_enabled_string = set_config_key + network + sep_slash + network_enabled + sep_col + is_network_enabled; + arguments.push_back(network_enabled_string.data()); + std::string registration_to_string = set_config_key + common + sep_slash + registration_timeout + sep_col + reg_to_value; + arguments.push_back(registration_to_string.data()); + std::string registration_rf_string = set_config_key + common + sep_slash + registration_refresh + sep_col + reg_rf_value; + arguments.push_back(registration_rf_string.data()); try { @@ -249,7 +273,14 @@ TEST(core_cpp_config, config_cmd_parser) std::cerr << e.what() << '\n'; } + // Expect a valid ini file EXPECT_NE(parser.getUserIni(), std::string("")); + + // Expect a proper key-value map in the config key map + EXPECT_EQ(parser.getConfigKeysMap()[network][host_group_name], config_test_machine); + EXPECT_EQ(parser.getConfigKeysMap()[network][network_enabled], is_network_enabled); + EXPECT_EQ(parser.getConfigKeysMap()[common][registration_timeout], reg_to_value); + EXPECT_EQ(parser.getConfigKeysMap()[common][registration_refresh], reg_rf_value); } TEST(CmdParserDeathTest, config_cmd_parser_death_test) From d72adbcf77ac3f21c8d2f5b33e12907e5843929f Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 16 May 2024 13:41:34 +0200 Subject: [PATCH 082/105] Removed generated ini file in test after usage. --- ecal/tests/cpp/config_test/src/config_test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 9add48de91..d82b31a3e7 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "ecal_cmd_parser.h" @@ -220,7 +221,8 @@ TEST(core_cpp_config, config_custom_datatypes_tests) TEST(core_cpp_config, config_cmd_parser) { // create a custom ini file - std::ofstream custom_ini_file("customIni.ini"); + std::string ini_file_name = "customIni.ini"; + std::ofstream custom_ini_file(ini_file_name); if (custom_ini_file.is_open()) { @@ -281,6 +283,8 @@ TEST(core_cpp_config, config_cmd_parser) EXPECT_EQ(parser.getConfigKeysMap()[network][network_enabled], is_network_enabled); EXPECT_EQ(parser.getConfigKeysMap()[common][registration_timeout], reg_to_value); EXPECT_EQ(parser.getConfigKeysMap()[common][registration_refresh], reg_rf_value); + + remove(ini_file_name.data()); } TEST(CmdParserDeathTest, config_cmd_parser_death_test) From 82d8d117619eab4eb29f23ac87a2f8781788085d Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 16 May 2024 14:48:41 +0200 Subject: [PATCH 083/105] Added config keys map to user cli arguments and provided the struct to config. --- ecal/core/include/ecal/types/ecal_config_types.h | 2 +- ecal/core/include/ecal/types/user_arg_options.h | 9 +++++---- ecal/core/src/config/ecal_config_initializer.cpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index cfd0a0dbf9..abbba65cb3 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -58,7 +58,7 @@ namespace eCAL ServiceOptions service_options{}; ApplicationOptions application_options{}; LoggingOptions logging_options{}; - ClArguments command_line_arguments{}; + CliArguments command_line_arguments{}; std::string loaded_ecal_ini_file{}; ECAL_API eCALConfig(int argc_ , char **argv_); diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/types/user_arg_options.h index 5d174dde82..ace1f0c349 100644 --- a/ecal/core/include/ecal/types/user_arg_options.h +++ b/ecal/core/include/ecal/types/user_arg_options.h @@ -32,14 +32,15 @@ namespace eCAL { namespace Config { - struct ClArguments + // Map[Section][Option] = Value + using ConfigKey2DMap = std::map>; + + struct CliArguments { std::vector config_keys{}; + ConfigKey2DMap config_keys_map; std::string specified_config{}; bool dump_config{}; }; - - // Map[Section][Option] = Value - using ConfigKey2DMap = std::map>; } } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index f2cc9ef744..a119c27968 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -230,6 +230,7 @@ namespace eCAL command_line_arguments.config_keys = parser.getConfigKeys(); command_line_arguments.specified_config = parser.getUserIni(); command_line_arguments.dump_config = parser.getDumpConfig(); + command_line_arguments.config_keys_map = parser.getConfigKeysMap(); InitConfig(command_line_arguments.specified_config); } From 287c24fa31083d780571f48be3e274698e61a7b3 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 17 May 2024 10:10:04 +0200 Subject: [PATCH 084/105] Clean up code and make clangtidy happy. --- .../configuration/src/hello_config/main.cpp | 4 +- ecal/core/src/config/ecal_cmd_parser.cpp | 135 ++++++++---------- ecal/core/src/config/ecal_cmd_parser.h | 2 - .../tests/cpp/config_test/src/config_test.cpp | 8 +- ecal/tests/cpp/config_test/src/ini_file.h | 2 +- 5 files changed, 68 insertions(+), 83 deletions(-) diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index e487131843..0100e5fb46 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -12,7 +12,7 @@ int main(int argc, char** argv) custom_config.InitConfigWithDefaultIni(); // .. or specify an own .ini file to use - custom_conig.InitConfig("C:\\eCAL_local.ini"); + custom_config.InitConfig("C:\\eCAL_local.ini"); // Set the values in a try/catch block, as wrong configuration leads to exceptions try @@ -26,7 +26,7 @@ int main(int argc, char** argv) // Increase the send buffer, size increase in 1024 bytes steps custom_config.transport_layer_options.mc_options.sndbuf = (5242880 + 10 * 1024); } - catch (std::invalid_argument e) + catch (std::invalid_argument& e) { throw std::runtime_error("Error while configuring eCALConfig: " + std::string(e.what())); } diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 0058d890e2..88f21c1d61 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -54,17 +54,11 @@ namespace std::string cwdPath() { - std::string cwd_path = {}; - char* buffer; - - if ( (buffer = getcwd(NULL, 0)) == NULL ) - throw std::runtime_error("getcwd() : cannot read current working directory."); - else - { - cwd_path = std::string(buffer); - free(buffer); - } + std::string cwd_path = { getcwd(nullptr, 0) }; + if (cwd_path.empty()) + throw std::runtime_error("getcwd() : cannot read current working directory."); + SetPathSep(cwd_path); return cwd_path; } @@ -73,8 +67,8 @@ namespace { std::string cmake_data_path; #ifdef ECAL_OS_LINUX - std::string ecal_install_config_dir(ECAL_INSTALL_CONFIG_DIR); - std::string ecal_install_prefix(ECAL_INSTALL_PREFIX); + const std::string ecal_install_config_dir(ECAL_INSTALL_CONFIG_DIR); + const std::string ecal_install_prefix(ECAL_INSTALL_PREFIX); if ((!ecal_install_config_dir.empty() && (ecal_install_config_dir[0] == path_separator)) || ecal_install_prefix.empty()) @@ -105,27 +99,20 @@ namespace return system_data_path; } - bool isValidConfigFilePath(std::string file_path_) + bool isValidConfigFilePath(const std::string& file_path_) { // check existence of user defined file const EcalUtils::Filesystem::FileStatus ecal_ini_status(file_path_, EcalUtils::Filesystem::Current); - if (ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile)) - { - return true; - } - - return false; + return ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile); } - std::string appendFileNameToPathIfPathIsValid(std::string path_, std::string file_name_) + void appendFileNameToPathIfPathIsValid(std::string& path_, const std::string& file_name_) { - if (path_.empty()) - return path_; - else - return path_ + path_separator + file_name_; + if (!path_.empty()) + path_ += path_separator + file_name_; } - void parseConfigKeysToMap(std::vector config_keys_, eCAL::Config::ConfigKey2DMap& map_) + void parseConfigKeysToMap(const std::vector& config_keys_, eCAL::Config::ConfigKey2DMap& map_) { // each string has the format "section/key:value" for (const auto& full_key : config_keys_) @@ -143,6 +130,55 @@ namespace map_[section][key] = value; } } + + std::string checkForValidConfigFilePath(const std::string config_file_) + { + // differences to ecal_config_reader implementation are: + // 1. it does not use the default ini file name, instead uses the specified file + // 2. it searches relative to the executable path and takes it as highest priority + // 3. it throws a runtime error, if it cannot find the specified file + + // ----------------------------------------------------------- + // precedence 1: relative path to executable + // ----------------------------------------------------------- + std::string cwd_directory_path = cwdPath(); + appendFileNameToPathIfPathIsValid(cwd_directory_path, config_file_); + + // ----------------------------------------------------------- + // precedence 2: ECAL_DATA variable (windows and linux) + // ----------------------------------------------------------- + std::string ecal_data_path = eCALDataEnvPath(); + appendFileNameToPathIfPathIsValid(ecal_data_path, config_file_); + + // ----------------------------------------------------------- + // precedence 3: cmake configured data paths (linux only) + // ----------------------------------------------------------- + std::string cmake_data_path = eCALDataCMakePath(); + appendFileNameToPathIfPathIsValid(cmake_data_path, config_file_); + + // ----------------------------------------------------------- + // precedence 4: system data path + // ----------------------------------------------------------- + std::string system_data_path = eCALDataSystemPath(); + appendFileNameToPathIfPathIsValid(system_data_path, config_file_); + + // Check for first directory which contains the ini file. + std::vector search_directories{ cwd_directory_path, ecal_data_path, cmake_data_path, system_data_path }; + + auto it = std::find_if(search_directories.begin(), search_directories.end(), isValidConfigFilePath); + // We should have encountered a valid path + if (it != search_directories.end()) + return (*it); + + // Check if user specified complete path, in case all other precedence paths exist + if (isValidConfigFilePath(config_file_)) + { + return config_file_; + } + + // If valid path is not encountered, throw error + throw std::runtime_error("[CMD Parser] Specified config file: \"" + config_file_ + "\" not found."); + } } namespace eCAL @@ -151,9 +187,6 @@ namespace eCAL { CmdParser::CmdParser() : m_dump_config{false} - , m_config_keys{} - , m_task_parameter{} - , m_user_ini{} {} CmdParser::CmdParser(int argc_ , char **argv_) @@ -209,52 +242,6 @@ namespace eCAL { for (size_t i = 0; i < static_cast(argc_); ++i) if (argv_[i] != nullptr) m_task_parameter.emplace_back(argv_[i]); } - - } - - std::string CmdParser::checkForValidConfigFilePath(std::string config_file_) - { - // differences to ecal_config_reader implementation are: - // 1. it does not use the default ini file name, instead uses the specified file - // 2. it searches relative to the executable path and takes it as highest priority - // 3. it throws a runtime error, if it cannot find the specified file - - // ----------------------------------------------------------- - // precedence 1: relative path to executable - // ----------------------------------------------------------- - const std::string cwd_directory_path{ appendFileNameToPathIfPathIsValid(cwdPath(), config_file_) }; - - // ----------------------------------------------------------- - // precedence 2: ECAL_DATA variable (windows and linux) - // ----------------------------------------------------------- - const std::string ecal_data_path{ appendFileNameToPathIfPathIsValid(eCALDataEnvPath(), config_file_) }; - - // ----------------------------------------------------------- - // precedence 3: cmake configured data paths (linux only) - // ----------------------------------------------------------- - const std::string cmake_data_path{ appendFileNameToPathIfPathIsValid(eCALDataCMakePath(), config_file_) }; - - // ----------------------------------------------------------- - // precedence 4: system data path - // ----------------------------------------------------------- - const std::string system_data_path( appendFileNameToPathIfPathIsValid(eCALDataSystemPath(), config_file_) ); - - // Check for first directory which contains the ini file. - std::vector search_directories{ config_file_, cwd_directory_path, ecal_data_path, cmake_data_path, system_data_path }; - - auto it = std::find_if(search_directories.begin(), search_directories.end(), isValidConfigFilePath); - // We should have encountered a valid path - if (it != search_directories.end()) - return (*it); - - // Check if user specified complete path, in case all other precedence paths exist - if (isValidConfigFilePath(config_file_)) - { - return config_file_; - } - - // If valid path is not encountered, throw error - throw std::runtime_error("[CMD Parser] Specified config file: \"" + config_file_ + "\" not found."); } bool CmdParser::getDumpConfig() const { return m_dump_config; }; diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index 25b5fbf25a..3d4e611989 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -55,8 +55,6 @@ namespace eCAL ConfigKey2DMap& getConfigKeysMap(); private: - std::string checkForValidConfigFilePath(std::string config_file_); - std::vector m_config_keys; ConfigKey2DMap m_config_key_map; bool m_dump_config; diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index d82b31a3e7..279411ed2f 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include "ini_file.h" #include @@ -237,7 +237,7 @@ TEST(core_cpp_config, config_cmd_parser) eCAL::Config::CmdParser parser; - std::vector arguments; + std::vector arguments{}; const std::string set_config_key = "--ecal-set-config-key "; const std::string sep_slash = "/"; @@ -289,9 +289,9 @@ TEST(core_cpp_config, config_cmd_parser) TEST(CmdParserDeathTest, config_cmd_parser_death_test) { - eCAL::Config::CmdParser parser; + eCAL::Config::CmdParser parser{}; - std::vector arguments; + std::vector arguments{}; arguments.push_back("test_config_cmd_parser_death_test"); arguments.push_back("--ecal-ini-file someNotValidFileName.ini"); diff --git a/ecal/tests/cpp/config_test/src/ini_file.h b/ecal/tests/cpp/config_test/src/ini_file.h index 60ab98c00b..fafd498d88 100644 --- a/ecal/tests/cpp/config_test/src/ini_file.h +++ b/ecal/tests/cpp/config_test/src/ini_file.h @@ -1,6 +1,6 @@ #include -std::string ini_file_as_string = +static const std::string ini_file_as_string = "; --------------------------------------------------\n" "; NETWORK SETTINGS\n" "; --------------------------------------------------\n" From fed863bd7992e685afc1ecc40d8c83b69bd322ec Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 17 May 2024 16:14:17 +0200 Subject: [PATCH 085/105] Refactored to current publisher options. TimeoutAcknowledge test not passing. --- ecal/core/CMakeLists.txt | 4 +- .../ecal/{ => config}/ecal_publisher_config.h | 2 +- .../{ => config}/ecal_subscriber_config.h | 0 ecal/core/include/ecal/ecal_config.h | 13 +++--- ecal/core/include/ecal/ecal_core.h | 4 +- ecal/core/include/ecal/ecal_publisher.h | 11 ++--- ecal/core/include/ecal/ecal_subscriber.h | 2 +- .../include/ecal/msg/capnproto/publisher.h | 6 +-- .../include/ecal/msg/flatbuffers/publisher.h | 6 +-- .../include/ecal/msg/messagepack/publisher.h | 6 +-- .../ecal/msg/protobuf/dynamic_publisher.h | 4 +- .../include/ecal/msg/protobuf/publisher.h | 6 +-- ecal/core/include/ecal/msg/publisher.h | 8 ++-- ecal/core/include/ecal/msg/string/publisher.h | 6 +-- .../ecal/types/ecal_application_options.h | 2 +- .../include/ecal/types/ecal_config_types.h | 32 +++++++------- .../ecal/types/ecal_transport_layer_options.h | 34 +++++++-------- .../include/ecal/types/user_arg_options.h | 4 +- ecal/core/src/config/ecal_cmd_parser.cpp | 8 ++-- ecal/core/src/config/ecal_cmd_parser.h | 7 ++-- ecal/core/src/config/ecal_config.cpp | 8 ++-- .../src/config/ecal_config_initializer.cpp | 35 +++++++--------- ecal/core/src/ecal.cpp | 10 ++--- ecal/core/src/ecal_global_accessors.cpp | 4 +- ecal/core/src/ecal_global_accessors.h | 10 ++--- ecal/core/src/ecal_globals.cpp | 2 +- ecal/core/src/ecal_globals.h | 8 ++-- .../core/src/pubsub/ecal_publisher_config.cpp | 40 +++++++++--------- .../src/pubsub/ecal_subscriber_config.cpp | 2 +- ecal/core/src/readwrite/ecal_writer.h | 7 ++-- ecal/core/src/readwrite/shm/ecal_writer_shm.h | 4 +- ecal/core/src/readwrite/tcp/ecal_writer_tcp.h | 4 +- ecal/core/src/readwrite/udp/ecal_writer_udp.h | 4 +- .../cpp/misc/config/src/config_sample.cpp | 2 +- .../tests/cpp/config_test/src/config_test.cpp | 42 +++++++++---------- 35 files changed, 171 insertions(+), 176 deletions(-) rename ecal/core/include/ecal/{ => config}/ecal_publisher_config.h (99%) rename ecal/core/include/ecal/{ => config}/ecal_subscriber_config.h (100%) diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 24225bc548..5492549390 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -454,6 +454,8 @@ endif() set(ecal_header_cmn include/ecal/types/logging.h include/ecal/types/monitoring.h + include/ecal/config/ecal_publisher_config.h + include/ecal/config/ecal_subscriber_config.h include/ecal/ecal.h include/ecal/ecal_callback.h include/ecal/ecal_client.h @@ -468,11 +470,9 @@ set(ecal_header_cmn include/ecal/ecal_process.h include/ecal/ecal_process_severity.h include/ecal/ecal_publisher.h - include/ecal/ecal_publisher_config.h include/ecal/ecal_server.h include/ecal/ecal_service_info.h include/ecal/ecal_subscriber.h - include/ecal/ecal_subscriber_config.h include/ecal/ecal_time.h include/ecal/ecal_timer.h include/ecal/ecal_tlayer.h diff --git a/ecal/core/include/ecal/ecal_publisher_config.h b/ecal/core/include/ecal/config/ecal_publisher_config.h similarity index 99% rename from ecal/core/include/ecal/ecal_publisher_config.h rename to ecal/core/include/ecal/config/ecal_publisher_config.h index a54cf62a29..42da95b237 100644 --- a/ecal/core/include/ecal/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/ecal_publisher_config.h @@ -130,7 +130,7 @@ namespace eCAL struct ECAL_API Configuration { - Configuration(); + // Configuration(); SHM::Configuration shm; UDP::Configuration udp; diff --git a/ecal/core/include/ecal/ecal_subscriber_config.h b/ecal/core/include/ecal/config/ecal_subscriber_config.h similarity index 100% rename from ecal/core/include/ecal/ecal_subscriber_config.h rename to ecal/core/include/ecal/config/ecal_subscriber_config.h diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 1019984143..14dd0359c0 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -30,11 +30,10 @@ //@{ namespace eCAL { + ECAL_API Configuration& GetCurrentConfig(); + namespace Config { - - ECAL_API eCALConfig& GetCurrentConfig(); - ///////////////////////////////////// // common ///////////////////////////////////// @@ -104,9 +103,9 @@ namespace eCAL ///////////////////////////////////// // publisher ///////////////////////////////////// - ECAL_API TLayer::eSendMode GetPublisherShmMode (); - ECAL_API TLayer::eSendMode GetPublisherTcpMode (); - ECAL_API TLayer::eSendMode GetPublisherUdpMulticastMode (); + ECAL_API bool GetPublisherShmMode (); + ECAL_API bool GetPublisherTcpMode (); + ECAL_API bool GetPublisherUdpMulticastMode (); ECAL_API size_t GetMemfileMinsizeBytes (); ECAL_API size_t GetMemfileOverprovisioningPercentage (); diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index 735c60a009..743e5d82a1 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -92,7 +92,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - ECAL_API int Initialize(eCAL::Config::eCALConfig& config_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); + ECAL_API int Initialize(eCAL::Configuration& config_, const char *unit_name_ = nullptr, unsigned int components_ = Init::Default); /** * @brief Finalize eCAL API. diff --git a/ecal/core/include/ecal/ecal_publisher.h b/ecal/core/include/ecal/ecal_publisher.h index 80c651434f..6753e051e4 100644 --- a/ecal/core/include/ecal/ecal_publisher.h +++ b/ecal/core/include/ecal/ecal_publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -29,7 +29,8 @@ #include #include #include -#include +#include +#include #include #include @@ -84,7 +85,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}); + ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); /** * @brief Constructor. @@ -92,7 +93,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = {}); + ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); /** * @brief Destructor. @@ -128,7 +129,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index 0ed5ea9f80..a47584d6f6 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/ecal/core/include/ecal/msg/capnproto/publisher.h b/ecal/core/include/ecal/msg/capnproto/publisher.h index bf6b3d6ef1..6afc98bc3f 100644 --- a/ecal/core/include/ecal/msg/capnproto/publisher.h +++ b/ecal/core/include/ecal/msg/capnproto/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -101,7 +101,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_) , builder(std::make_unique()) , root_builder(builder->initRoot()) @@ -150,7 +150,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/flatbuffers/publisher.h b/ecal/core/include/ecal/msg/flatbuffers/publisher.h index 6e9e836715..0ca1558f30 100644 --- a/ecal/core/include/ecal/msg/flatbuffers/publisher.h +++ b/ecal/core/include/ecal/msg/flatbuffers/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -53,7 +53,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -85,7 +85,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/messagepack/publisher.h b/ecal/core/include/ecal/msg/messagepack/publisher.h index 70a7298a2f..e2bcbf628a 100644 --- a/ecal/core/include/ecal/msg/messagepack/publisher.h +++ b/ecal/core/include/ecal/msg/messagepack/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -56,7 +56,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -88,7 +88,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h index 1a7ca4f2a1..1333cbd543 100644 --- a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -62,7 +62,7 @@ namespace eCAL * @param msg_ Protobuf message object. * @param config_ Optional configuration parameters. **/ - CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = {}) + CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_) , m_msg{ msg_ } {} diff --git a/ecal/core/include/ecal/msg/protobuf/publisher.h b/ecal/core/include/ecal/msg/protobuf/publisher.h index e583292877..41b44bd5d7 100644 --- a/ecal/core/include/ecal/msg/protobuf/publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -107,7 +107,7 @@ namespace eCAL // where the vtable is not created yet, or it's destructed. // Probably we can handle the Message publishers differently. One message publisher class and then one class for payloads and getting type // descriptor information. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) { } @@ -144,7 +144,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/publisher.h b/ecal/core/include/ecal/msg/publisher.h index 5f3b0625f2..57677a9126 100644 --- a/ecal/core/include/ecal/msg/publisher.h +++ b/ecal/core/include/ecal/msg/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -63,7 +63,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}) : CPublisher(topic_name_, data_type_info_, config_) + CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CPublisher(topic_name_, data_type_info_, config_) { } @@ -74,7 +74,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -109,7 +109,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(CPublisher::Create(topic_name_, data_type_info_, config_)); } diff --git a/ecal/core/include/ecal/msg/string/publisher.h b/ecal/core/include/ecal/msg/string/publisher.h index f1d45d58af..623cad688a 100644 --- a/ecal/core/include/ecal/msg/string/publisher.h +++ b/ecal/core/include/ecal/msg/string/publisher.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -60,7 +60,7 @@ namespace eCAL // call the function via its class because it's a virtual function that is called in constructor/destructor,- // where the vtable is not created yet, or it's destructed. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -92,7 +92,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h index d1270de4e7..b4088a5df8 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -32,7 +32,7 @@ namespace eCAL { struct SysOptions { - std::string filter_excl{}; + std::string filter_excl{}; // mama }; struct StartupOptions diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index abbba65cb3..ab90fc2ba1 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -34,6 +34,7 @@ #include "ecal_logging_options.h" #include "ecal_transport_layer_options.h" #include "user_arg_options.h" +#include "ecal/config/ecal_publisher_config.h" #include "ecal/ecal_os.h" #include "ecal/ecal_log_level.h" @@ -45,24 +46,22 @@ namespace eCAL { - namespace Config - { - struct eCALConfig + struct Configuration { - TransportLayerOptions transport_layer_options{}; - RegistrationOptions registration_options{}; - MonitoringOptions monitoring_options{}; - ReceivingOptions receiving_options{}; - PublisherOptions publisher_options{}; - TimesyncOptions timesync_options{}; - ServiceOptions service_options{}; - ApplicationOptions application_options{}; - LoggingOptions logging_options{}; - CliArguments command_line_arguments{}; - std::string loaded_ecal_ini_file{}; + TransportLayer::Configuration transport_layer_options{}; + Config::RegistrationOptions registration_options{}; + Config::MonitoringOptions monitoring_options{}; + Config::ReceivingOptions receiving_options{}; + Publisher::Configuration publisher_options{}; + Config::TimesyncOptions timesync_options{}; + Config::ServiceOptions service_options{}; + Config::ApplicationOptions application_options{}; + Config::LoggingOptions logging_options{}; + Cli::Configuration command_line_arguments{}; + std::string loaded_ecal_ini_file{}; - ECAL_API eCALConfig(int argc_ , char **argv_); - ECAL_API eCALConfig(std::vector args_); + ECAL_API Configuration(int argc_ , char **argv_); + ECAL_API Configuration(std::vector args_); ECAL_API void InitConfigWithDefaultIni(); ECAL_API void InitConfig(std::string ini_path_); @@ -70,5 +69,4 @@ namespace eCAL private: ECAL_API void Init(int argc_ , char **argv_); }; - } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/types/ecal_transport_layer_options.h index 0db36d00d1..72cc2b9d65 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/types/ecal_transport_layer_options.h @@ -28,7 +28,7 @@ namespace eCAL { - namespace Config + namespace TransportLayer { struct TCPubsubOptions { @@ -39,32 +39,32 @@ namespace eCAL struct SHMOptions { - std::string host_group_name{}; - ConstrainedInteger<4096, 4096> memfile_minsize{}; - ConstrainedInteger<50, 1, 100> memfile_reserve{}; - int memfile_ack_timeout{}; - ConstrainedInteger<0, 1> memfile_buffer_count{}; - bool drop_out_of_order_messages{}; - bool memfile_zero_copy{}; + std::string host_group_name{}; + Config::ConstrainedInteger<4096, 4096> memfile_minsize{}; + Config::ConstrainedInteger<50, 1, 100> memfile_reserve{}; + int memfile_ack_timeout{}; + Config::ConstrainedInteger<0, 1> memfile_buffer_count{}; + bool drop_out_of_order_messages{}; + bool memfile_zero_copy{}; }; struct UdpMulticastOptions { - UdpConfigVersion config_version{}; - IpAddressV4 group{}; - IpAddressV4 mask{}; - ConstrainedInteger<14000, 10> port{}; - unsigned int ttl{}; + Config::UdpConfigVersion config_version{}; + Config::IpAddressV4 group{}; + Config::IpAddressV4 mask{}; + Config::ConstrainedInteger<14000, 10> port{}; + unsigned int ttl{}; // TODO PG: are these minimum limits correct? - ConstrainedInteger<5242880, 1024> sndbuf{}; - ConstrainedInteger<5242880, 1024> recbuf{}; - bool join_all_interfaces{}; + Config::ConstrainedInteger<5242880, 1024> sndbuf{}; + Config::ConstrainedInteger<5242880, 1024> recbuf{}; + bool join_all_interfaces{}; int bandwidth_max_udp{}; bool npcap_enabled{}; }; - struct TransportLayerOptions + struct Configuration { bool network_enabled{}; bool drop_out_of_order_messages{}; diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/types/user_arg_options.h index ace1f0c349..591f847f15 100644 --- a/ecal/core/include/ecal/types/user_arg_options.h +++ b/ecal/core/include/ecal/types/user_arg_options.h @@ -30,12 +30,12 @@ namespace eCAL { - namespace Config + namespace Cli { // Map[Section][Option] = Value using ConfigKey2DMap = std::map>; - struct CliArguments + struct Configuration { std::vector config_keys{}; ConfigKey2DMap config_keys_map; diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 88f21c1d61..0666a731a2 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -112,7 +112,7 @@ namespace path_ += path_separator + file_name_; } - void parseConfigKeysToMap(const std::vector& config_keys_, eCAL::Config::ConfigKey2DMap& map_) + void parseConfigKeysToMap(const std::vector& config_keys_, eCAL::Cli::ConfigKey2DMap& map_) { // each string has the format "section/key:value" for (const auto& full_key : config_keys_) @@ -131,7 +131,7 @@ namespace } } - std::string checkForValidConfigFilePath(const std::string config_file_) + std::string checkForValidConfigFilePath(const std::string& config_file_) { // differences to ecal_config_reader implementation are: // 1. it does not use the default ini file name, instead uses the specified file @@ -173,7 +173,7 @@ namespace // Check if user specified complete path, in case all other precedence paths exist if (isValidConfigFilePath(config_file_)) { - return config_file_; + return std::string(config_file_); } // If valid path is not encountered, throw error @@ -248,6 +248,6 @@ namespace eCAL std::vector& CmdParser::getConfigKeys() { return m_config_keys; }; std::vector& CmdParser::getTaskParameter() { return m_task_parameter; }; std::string& CmdParser::getUserIni() { return m_user_ini; }; - ConfigKey2DMap& CmdParser::getConfigKeysMap() { return m_config_key_map; }; + Cli::ConfigKey2DMap& CmdParser::getConfigKeysMap() { return m_config_key_map; }; } } diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index 3d4e611989..e723083b8c 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -23,6 +23,8 @@ #pragma once +#include "ecal/types/user_arg_options.h" + #include #include #include @@ -42,7 +44,6 @@ namespace eCAL class CmdParser { public: - using ConfigKey2DMap = std::map>; CmdParser(int argc_ , char **argv_); CmdParser(); @@ -52,11 +53,11 @@ namespace eCAL std::vector& getConfigKeys(); std::vector& getTaskParameter(); std::string& getUserIni(); - ConfigKey2DMap& getConfigKeysMap(); + Cli::ConfigKey2DMap& getConfigKeysMap(); private: std::vector m_config_keys; - ConfigKey2DMap m_config_key_map; + Cli::ConfigKey2DMap m_config_key_map; bool m_dump_config; std::vector m_task_parameter; std::string m_user_ini; diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index ecb15a0d7a..97d24244fd 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -156,9 +156,9 @@ namespace eCAL // publisher ///////////////////////////////////// - ECAL_API TLayer::eSendMode GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher_options.use_udp_mc; } - ECAL_API TLayer::eSendMode GetPublisherShmMode () { return GetCurrentConfig().publisher_options.use_shm; } - ECAL_API TLayer::eSendMode GetPublisherTcpMode () { return GetCurrentConfig().publisher_options.use_tcp; } + ECAL_API bool GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher_options.udp.enable; } + ECAL_API bool GetPublisherShmMode () { return GetCurrentConfig().publisher_options.shm.enable; } + ECAL_API bool GetPublisherTcpMode () { return GetCurrentConfig().publisher_options.tcp.enable; } ECAL_API size_t GetMemfileMinsizeBytes () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize; } ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index a119c27968..1f60e96aa0 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -97,9 +97,7 @@ namespace { namespace eCAL { - namespace Config - { - void eCALConfig::InitConfig(std::string ini_path_ /*= std::string("")*/) + void Configuration::InitConfig(std::string ini_path_ /*= std::string("")*/) { CConfig iniConfig; if (!command_line_arguments.config_keys.empty()) @@ -120,9 +118,9 @@ namespace eCAL const std::string udp_config_version_string = iniConfig.get(NETWORK, "multicast_config_version", "v1"); if (udp_config_version_string == "v1") - multicastOptions.config_version = UdpConfigVersion::V1; + multicastOptions.config_version = Config::UdpConfigVersion::V1; if (udp_config_version_string == "v2") - multicastOptions.config_version = UdpConfigVersion::V2; + multicastOptions.config_version = Config::UdpConfigVersion::V2; multicastOptions.group = iniConfig.get(NETWORK, "multicast_group", NET_UDP_MULTICAST_GROUP); multicastOptions.mask = iniConfig.get(NETWORK, "multicast_mask", NET_UDP_MULTICAST_MASK); @@ -151,15 +149,15 @@ namespace eCAL // registration options auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", CMN_REGISTRATION_TO); auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", CMN_REGISTRATION_REFRESH); - registration_options = RegistrationOptions(registrationTimeout, registrationRefresh); + registration_options = Config::RegistrationOptions(registrationTimeout, registrationRefresh); auto& registrationOptions = registration_options; registrationOptions.share_tdesc = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); registrationOptions.share_ttype = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); // monitoring options auto& monitoringOptions = monitoring_options; - auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? MonitoringMode::shm_monitoring : MonitoringMode::none; - monitoringOptions.monitoring_mode = static_cast(monitoringMode); + auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? Config::MonitoringMode::shm_monitoring : Config::MonitoringMode::none; + monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); @@ -180,9 +178,9 @@ namespace eCAL // publisher options auto& publisherOptions = publisher_options; - publisherOptions.use_shm = static_cast(iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM))); - publisherOptions.use_tcp = static_cast(iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP))); - publisherOptions.use_udp_mc = static_cast(iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC))); + publisherOptions.shm.enable = (iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) == 0) ? false : true; + publisherOptions.tcp.enable = (iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) == 0) ? false : true; + publisherOptions.udp.enable = (iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) == 0) ? false : true; // timesync options auto& timesyncOptions = timesync_options; @@ -209,12 +207,12 @@ namespace eCAL loggingOptions.filter_log_udp = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_udp", "info,warning,error,fatal")); }; - eCALConfig::eCALConfig(int argc_ , char **argv_) + Configuration::Configuration(int argc_ , char **argv_) { Init(argc_, argv_); } - eCALConfig::eCALConfig(std::vector args_) + Configuration::Configuration(std::vector args_) { args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); std::vector argv(args_.size()); @@ -223,9 +221,9 @@ namespace eCAL Init(static_cast(argv.size()), const_cast(argv.data())); } - void eCALConfig::Init(int argc_ , char **argv_) + void Configuration::Init(int argc_ , char **argv_) { - CmdParser parser(argc_, argv_); + Config::CmdParser parser(argc_, argv_); command_line_arguments.config_keys = parser.getConfigKeys(); command_line_arguments.specified_config = parser.getUserIni(); @@ -235,14 +233,13 @@ namespace eCAL InitConfig(command_line_arguments.specified_config); } - void eCALConfig::InitConfigWithDefaultIni() + void Configuration::InitConfigWithDefaultIni() { InitConfig(g_default_ini_file); } - eCALConfig& GetCurrentConfig() + Configuration& GetCurrentConfig() { return g_ecal_config(); }; - } } \ No newline at end of file diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 4da3d25a1f..0d6c11ecaf 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -100,7 +100,7 @@ namespace eCAL **/ int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) { - eCAL::Config::eCALConfig config(argc_, argv_); + eCAL::Configuration config(argc_, argv_); return Initialize(config, unit_name_, components_); } @@ -116,7 +116,7 @@ namespace eCAL **/ int Initialize(std::vector args_, const char *unit_name_, unsigned int components_) //-V826 { - eCAL::Config::eCALConfig config(args_); + eCAL::Configuration config(args_); return Initialize(config, unit_name_, components_); } @@ -129,7 +129,7 @@ namespace eCAL * * @return Zero if succeeded, 1 if already initialized, -1 if failed. **/ - int Initialize(eCAL::Config::eCALConfig& config_, const char *unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/) + int Initialize(eCAL::Configuration& config_, const char *unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/) { if (g_globals() == nullptr) { @@ -146,7 +146,7 @@ namespace eCAL g_globals_ctx_ref_cnt++; // (post)initialize single components - const int success = g_globals()->Initialize(components_, &Config::GetCurrentConfig().command_line_arguments.config_keys); + const int success = g_globals()->Initialize(components_, &GetCurrentConfig().command_line_arguments.config_keys); if (config_.command_line_arguments.dump_config) { diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index efe17fee48..2710c36a0c 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -100,7 +100,7 @@ namespace eCAL return(g_globals()->log().get()); } - Config::eCALConfig& g_ecal_config() + Configuration& g_ecal_config() { return(g_globals()->ecal_config()); } diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 18aa526640..6b84bf241a 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -34,10 +34,8 @@ namespace eCAL class CGlobals; class CConfig; class CLog; - namespace Config - { - struct eCALConfig; - } + struct Configuration; + #if ECAL_CORE_MONITORING class CMonitoring; #endif @@ -71,7 +69,7 @@ namespace eCAL CGlobals* g_globals(); CConfig* g_config(); CLog* g_log(); - Config::eCALConfig& g_ecal_config(); + Configuration& g_ecal_config(); #if ECAL_CORE_MONITORING CMonitoring* g_monitoring(); #endif diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index f8c51d6a9b..8438597627 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -45,7 +45,7 @@ namespace eCAL Finalize(); } - void CGlobals::SetEcalConfig(Config::eCALConfig& ecal_config_) + void CGlobals::SetEcalConfig(Configuration& ecal_config_) { ecal_config_instance = ecal_config_; } diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index 48bca65cc5..0fa329feae 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -65,7 +65,7 @@ namespace eCAL int Initialize ( unsigned int components_, std::vector* config_keys_ = nullptr); bool IsInitialized ( unsigned int component_ ); - void SetEcalConfig(Config::eCALConfig& ecal_config_); + void SetEcalConfig(Configuration& ecal_config_); unsigned int GetComponents() const { return(components); }; @@ -73,7 +73,7 @@ namespace eCAL const std::unique_ptr& config() { return config_instance; }; const std::unique_ptr& log() { return log_instance; }; - Config::eCALConfig& ecal_config() { return ecal_config_instance; }; + Configuration& ecal_config() { return ecal_config_instance; }; #if ECAL_CORE_MONITORING const std::unique_ptr& monitoring() { return monitoring_instance; }; @@ -133,6 +133,6 @@ namespace eCAL #endif std::unique_ptr descgate_instance; - Config::eCALConfig ecal_config_instance; + Configuration ecal_config_instance; }; } diff --git a/ecal/core/src/pubsub/ecal_publisher_config.cpp b/ecal/core/src/pubsub/ecal_publisher_config.cpp index 949980e690..34be0e3361 100644 --- a/ecal/core/src/pubsub/ecal_publisher_config.cpp +++ b/ecal/core/src/pubsub/ecal_publisher_config.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -22,32 +22,32 @@ **/ #include -#include +#include namespace eCAL { namespace Publisher { - Configuration::Configuration() : - share_topic_type(eCAL::Config::IsTopicTypeSharingEnabled()), - share_topic_description(eCAL::Config::IsTopicDescriptionSharingEnabled()) - { - // shm config - shm.enable = eCAL::Config::GetPublisherShmMode() != TLayer::eSendMode::smode_off; - shm.zero_copy_mode = eCAL::Config::IsMemfileZerocopyEnabled(); - shm.acknowledge_timeout_ms = eCAL::Config::GetMemfileAckTimeoutMs(); + // Configuration::Configuration() : + // share_topic_type(eCAL::Config::IsTopicTypeSharingEnabled()), + // share_topic_description(eCAL::Config::IsTopicDescriptionSharingEnabled()) + // { + // // shm config + // shm.enable = eCAL::Config::GetPublisherShmMode(); + // shm.zero_copy_mode = eCAL::Config::IsMemfileZerocopyEnabled(); + // shm.acknowledge_timeout_ms = eCAL::Config::GetMemfileAckTimeoutMs(); - shm.memfile_min_size_bytes = eCAL::Config::GetMemfileMinsizeBytes(); - shm.memfile_reserve_percent = eCAL::Config::GetMemfileOverprovisioningPercentage(); - shm.memfile_buffer_count = eCAL::Config::GetMemfileBufferCount(); + // shm.memfile_min_size_bytes = eCAL::Config::GetMemfileMinsizeBytes(); + // shm.memfile_reserve_percent = eCAL::Config::GetMemfileOverprovisioningPercentage(); + // shm.memfile_buffer_count = eCAL::Config::GetMemfileBufferCount(); - // udp config - udp.enable = eCAL::Config::GetPublisherUdpMulticastMode() != TLayer::eSendMode::smode_off; - udp.loopback = false; // TODO: make this configurable - udp.sndbuf_size_bytes = eCAL::Config::GetUdpMulticastSndBufSizeBytes(); + // // udp config + // udp.enable = eCAL::Config::GetPublisherUdpMulticastMode(); + // udp.loopback = false; // TODO: make this configurable + // udp.sndbuf_size_bytes = eCAL::Config::GetUdpMulticastSndBufSizeBytes(); - // tcp config - tcp.enable = eCAL::Config::GetPublisherTcpMode() != TLayer::eSendMode::smode_off; - } + // // tcp config + // tcp.enable = eCAL::Config::GetPublisherTcpMode(); + // } } } diff --git a/ecal/core/src/pubsub/ecal_subscriber_config.cpp b/ecal/core/src/pubsub/ecal_subscriber_config.cpp index 45a7becd78..aa2647e97f 100644 --- a/ecal/core/src/pubsub/ecal_subscriber_config.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber_config.cpp @@ -22,7 +22,7 @@ **/ #include -#include +#include namespace eCAL { diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 019c06fd26..245154fb3f 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -25,7 +25,8 @@ #include #include -#include +#include +#include #include #include "util/ecal_expmap.h" @@ -78,7 +79,7 @@ namespace eCAL } }; - CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = {}); + CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); ~CDataWriter(); bool Stop(); diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.h b/ecal/core/src/readwrite/shm/ecal_writer_shm.h index 01517db79a..b76acda891 100644 --- a/ecal/core/src/readwrite/shm/ecal_writer_shm.h +++ b/ecal/core/src/readwrite/shm/ecal_writer_shm.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -23,7 +23,7 @@ #pragma once -#include +#include #include "readwrite/ecal_writer_base.h" #include "io/shm/ecal_memfile_sync.h" diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h index 6258ae280c..0b12aa40d9 100644 --- a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h +++ b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -23,7 +23,7 @@ #pragma once -#include +#include #include "readwrite/ecal_writer_base.h" diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp.h b/ecal/core/src/readwrite/udp/ecal_writer_udp.h index a9b2d4eabc..dc5846eddf 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp.h +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -23,7 +23,7 @@ #pragma once -#include +#include #include "io/udp/ecal_udp_sample_sender.h" #include "readwrite/ecal_writer_base.h" diff --git a/ecal/samples/cpp/misc/config/src/config_sample.cpp b/ecal/samples/cpp/misc/config/src/config_sample.cpp index 503802951d..afe05df5ae 100644 --- a/ecal/samples/cpp/misc/config/src/config_sample.cpp +++ b/ecal/samples/cpp/misc/config/src/config_sample.cpp @@ -25,7 +25,7 @@ int main(int argc, char **argv) { // creating config object - eCAL::Config::eCALConfig my_config(argc, argv); + eCAL::Configuration my_config(argc, argv); // setting configuration my_config.monitoring_options.network_monitoring = true; diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 279411ed2f..5d82062cf1 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -38,7 +38,7 @@ void SetValue(MEMBER& member, VALUE value) TEST(core_cpp_config, user_config_passing) { - eCAL::Config::eCALConfig custom_config(0, nullptr); + eCAL::Configuration custom_config(0, nullptr); // Test value assignments from each category // How the user would utilize it @@ -55,7 +55,7 @@ TEST(core_cpp_config, user_config_passing) const eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; // Publisher options - const eCAL::TLayer::eSendMode pub_use_shm = eCAL::TLayer::eSendMode::smode_off; + const bool pub_use_shm = true; // Registration options const unsigned int registration_timeout = 80000U; @@ -72,45 +72,45 @@ TEST(core_cpp_config, user_config_passing) custom_config.monitoring_options.monitoring_mode = monitoring_mode; custom_config.logging_options.filter_log_con = mon_log_filter_con; - custom_config.publisher_options.use_shm = pub_use_shm; + custom_config.publisher_options.shm.enable = pub_use_shm; custom_config.registration_options = registration_options; } catch (std::invalid_argument& e) { - throw std::runtime_error("Error while configuring eCALConfig: " + std::string(e.what())); + throw std::runtime_error("Error while configuring Configuration: " + std::string(e.what())); } // Initialize ecal api with custom config EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); // Test boolean assignment, default is false - EXPECT_EQ(network_enabled, eCAL::Config::GetCurrentConfig().transport_layer_options.network_enabled); + EXPECT_EQ(network_enabled, eCAL::GetCurrentConfig().transport_layer_options.network_enabled); // Test IP address assignment, default is 239.0.0.1 - EXPECT_EQ(ip_address, static_cast(eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.group)); + EXPECT_EQ(ip_address, static_cast(eCAL::GetCurrentConfig().transport_layer_options.mc_options.group)); // Test UDP send buffer assignment, default is 5242880 - EXPECT_EQ(upd_snd_buff, static_cast(eCAL::Config::GetCurrentConfig().transport_layer_options.mc_options.sndbuf)); + EXPECT_EQ(upd_snd_buff, static_cast(eCAL::GetCurrentConfig().transport_layer_options.mc_options.sndbuf)); // Test monitoring timeout assignment, default is 5000U - EXPECT_EQ(mon_timeout, eCAL::Config::GetCurrentConfig().monitoring_options.monitoring_timeout); + EXPECT_EQ(mon_timeout, eCAL::GetCurrentConfig().monitoring_options.monitoring_timeout); // Test monitoring filter exclude assignment, default is "_.*" - EXPECT_EQ(mon_filter_excl, eCAL::Config::GetCurrentConfig().monitoring_options.filter_excl); + EXPECT_EQ(mon_filter_excl, eCAL::GetCurrentConfig().monitoring_options.filter_excl); // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) - EXPECT_EQ(mon_log_filter_con, eCAL::Config::GetCurrentConfig().logging_options.filter_log_con); + EXPECT_EQ(mon_log_filter_con, eCAL::GetCurrentConfig().logging_options.filter_log_con); - // Test monitoring mode assignment, default iseCAL::Config::MonitoringMode::none - EXPECT_EQ(monitoring_mode, eCAL::Config::GetCurrentConfig().monitoring_options.monitoring_mode); + // Test monitoring mode assignment, default is eCAL::Config::MonitoringMode::none + EXPECT_EQ(monitoring_mode, eCAL::GetCurrentConfig().monitoring_options.monitoring_mode); // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto - EXPECT_EQ(pub_use_shm, eCAL::Config::GetCurrentConfig().publisher_options.use_shm); + EXPECT_EQ(pub_use_shm, eCAL::GetCurrentConfig().publisher_options.shm.enable); // Test registration option assignment, default timeout is 60000U and default refresh is 1000U - EXPECT_EQ(registration_timeout, eCAL::Config::GetCurrentConfig().registration_options.getTimeoutMS()); - EXPECT_EQ(registration_refresh, eCAL::Config::GetCurrentConfig().registration_options.getRefreshMS()); + EXPECT_EQ(registration_timeout, eCAL::GetCurrentConfig().registration_options.getTimeoutMS()); + EXPECT_EQ(registration_refresh, eCAL::GetCurrentConfig().registration_options.getRefreshMS()); // Finalize eCAL API EXPECT_EQ(0, eCAL::Finalize()); @@ -118,7 +118,7 @@ TEST(core_cpp_config, user_config_passing) TEST(ConfigDeathTest, user_config_death_test) { - eCAL::Config::eCALConfig custom_config(0, nullptr); + eCAL::Configuration custom_config(0, nullptr); // Test the IpAddressV4 class with wrong values ASSERT_THROW( @@ -208,8 +208,8 @@ TEST(core_cpp_config, config_custom_datatypes_tests) EXPECT_EQ(static_cast(s1), static_cast(s2)); // test copy method for config structure - eCAL::Config::eCALConfig config1(0, nullptr); - eCAL::Config::eCALConfig config2(0, nullptr); + eCAL::Configuration config1(0, nullptr); + eCAL::Configuration config2(0, nullptr); std::string testValue = std::string("234.0.3.2"); config2.transport_layer_options.mc_options.group = testValue; auto& config2ref = config2; @@ -237,7 +237,7 @@ TEST(core_cpp_config, config_cmd_parser) eCAL::Config::CmdParser parser; - std::vector arguments{}; + std::vector arguments; const std::string set_config_key = "--ecal-set-config-key "; const std::string sep_slash = "/"; @@ -289,9 +289,9 @@ TEST(core_cpp_config, config_cmd_parser) TEST(CmdParserDeathTest, config_cmd_parser_death_test) { - eCAL::Config::CmdParser parser{}; + eCAL::Config::CmdParser parser; - std::vector arguments{}; + std::vector arguments; arguments.push_back("test_config_cmd_parser_death_test"); arguments.push_back("--ecal-ini-file someNotValidFileName.ini"); From 31b0c6ec0bfa799feeb4452517c4e87ca7233036 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 21 May 2024 09:00:52 +0200 Subject: [PATCH 086/105] Make clang tidy a bit more happy. --- ecal/core/src/config/ecal_config_initializer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 1f60e96aa0..8cc70723bc 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -178,9 +178,9 @@ namespace eCAL // publisher options auto& publisherOptions = publisher_options; - publisherOptions.shm.enable = (iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) == 0) ? false : true; - publisherOptions.tcp.enable = (iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) == 0) ? false : true; - publisherOptions.udp.enable = (iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) == 0) ? false : true; + publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; + publisherOptions.tcp.enable = iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) != 0; + publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; // timesync options auto& timesyncOptions = timesync_options; From 295f9980fd9fb5ed17ef88c8275bbfaedf6a7e14 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 21 May 2024 09:01:17 +0200 Subject: [PATCH 087/105] Enable shm for pubsub acknowledge test. --- ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp index 903854a18c..0bb5db8e4e 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -56,6 +56,7 @@ TEST(core_cpp_pubsub, TimeoutAcknowledgment) // create publisher config eCAL::Publisher::Configuration pub_config; pub_config.shm.acknowledge_timeout_ms = 500; + pub_config.shm.enable = true; // create publisher eCAL::string::CPublisher pub("topic", pub_config); From 915a7f7536bb81c900e14f573add450134d7fd92 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 21 May 2024 12:49:47 +0200 Subject: [PATCH 088/105] Included ecal_subscriber_config --- .../ecal/config/ecal_subscriber_config.h | 2 +- ecal/core/include/ecal/ecal_subscriber.h | 6 +-- .../include/ecal/types/ecal_config_types.h | 4 +- .../ecal/types/ecal_receiving_options.h | 38 ------------------- ecal/core/src/config/ecal_config.cpp | 6 +-- .../src/config/ecal_config_initializer.cpp | 14 +++---- .../src/pubsub/ecal_subscriber_config.cpp | 18 ++++----- 7 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 ecal/core/include/ecal/types/ecal_receiving_options.h diff --git a/ecal/core/include/ecal/config/ecal_subscriber_config.h b/ecal/core/include/ecal/config/ecal_subscriber_config.h index 5e2221c820..b5930931f4 100644 --- a/ecal/core/include/ecal/config/ecal_subscriber_config.h +++ b/ecal/core/include/ecal/config/ecal_subscriber_config.h @@ -58,7 +58,7 @@ namespace eCAL struct ECAL_API Configuration { - Configuration(); + // Configuration(); SHM::Configuration shm; UDP::Configuration udp; diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index a47584d6f6..88ed644bc2 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -97,7 +97,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {}); + ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); /** * @brief Constructor. @@ -105,7 +105,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param data_type_info_ Topic data type information (encoding, type, descriptor). **/ - ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = {}); + ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); /** * @brief Destructor. @@ -141,7 +141,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {}); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index ab90fc2ba1..21ff55633f 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -28,13 +28,13 @@ #include "ecal_custom_data_types.h" #include "ecal_monitoring_options.h" #include "ecal_publisher_options.h" -#include "ecal_receiving_options.h" #include "ecal_registration_options.h" #include "ecal_service_options.h" #include "ecal_logging_options.h" #include "ecal_transport_layer_options.h" #include "user_arg_options.h" #include "ecal/config/ecal_publisher_config.h" +#include "ecal/config/ecal_subscriber_config.h" #include "ecal/ecal_os.h" #include "ecal/ecal_log_level.h" @@ -51,7 +51,7 @@ namespace eCAL TransportLayer::Configuration transport_layer_options{}; Config::RegistrationOptions registration_options{}; Config::MonitoringOptions monitoring_options{}; - Config::ReceivingOptions receiving_options{}; + Subscriber::Configuration subscriber_options{}; Publisher::Configuration publisher_options{}; Config::TimesyncOptions timesync_options{}; Config::ServiceOptions service_options{}; diff --git a/ecal/core/include/ecal/types/ecal_receiving_options.h b/ecal/core/include/ecal/types/ecal_receiving_options.h deleted file mode 100644 index f2ec6da035..0000000000 --- a/ecal/core/include/ecal/types/ecal_receiving_options.h +++ /dev/null @@ -1,38 +0,0 @@ -/* =========================== LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * =========================== LICENSE ================================= - */ - -/** - * @file ecal_receiving_options.h - * @brief eCAL options for receiving configuration -**/ - -#pragma once - -namespace eCAL -{ - namespace Config - { - struct ReceivingOptions - { - bool shm_recv_enabled{}; - bool tcp_recv_enabled{}; - bool udp_mc_recv_enabled{}; - }; - } -} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index 97d24244fd..b7dd021e0d 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -110,9 +110,9 @@ namespace eCAL ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetCurrentConfig().transport_layer_options.mc_options.recbuf; } ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces; } - ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().receiving_options.udp_mc_recv_enabled; } - ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().receiving_options.shm_recv_enabled; } - ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().receiving_options.tcp_recv_enabled; } + ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().subscriber_options.udp.enable; } + ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().subscriber_options.shm.enable; } + ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().subscriber_options.tcp.enable; } ECAL_API bool IsNpcapEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled; } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 8cc70723bc..da2f79430e 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -171,16 +171,16 @@ namespace eCAL shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", EXP_SHM_MONITORING_QUEUE_SIZE); // receiving options - auto& receivingOptions = receiving_options; - receivingOptions.shm_recv_enabled = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED); - receivingOptions.tcp_recv_enabled = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED); - receivingOptions.udp_mc_recv_enabled = iniConfig.get(NETWORK, "udp_mc_rec_enabled", NET_UDP_MC_REC_ENABLED); + auto& subscriberOptions = subscriber_options; + subscriberOptions.shm.enable = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED) != 0; + subscriberOptions.tcp.enable = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED) != 0; + subscriberOptions.udp.enable = iniConfig.get(NETWORK, "udp_mc_rec_enabled", NET_UDP_MC_REC_ENABLED) != 0; // publisher options auto& publisherOptions = publisher_options; - publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; - publisherOptions.tcp.enable = iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) != 0; - publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; + publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; + publisherOptions.tcp.enable = iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) != 0; + publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; // timesync options auto& timesyncOptions = timesync_options; diff --git a/ecal/core/src/pubsub/ecal_subscriber_config.cpp b/ecal/core/src/pubsub/ecal_subscriber_config.cpp index aa2647e97f..6a12180ea6 100644 --- a/ecal/core/src/pubsub/ecal_subscriber_config.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber_config.cpp @@ -28,16 +28,16 @@ namespace eCAL { namespace Subscriber { - Configuration::Configuration() - { - // shm config - shm.enable = eCAL::Config::IsShmRecEnabled(); + // Configuration::Configuration() + // { + // // shm config + // shm.enable = eCAL::Config::IsShmRecEnabled(); - // udp config - udp.enable = eCAL::Config::IsUdpMulticastRecEnabled(); + // // udp config + // udp.enable = eCAL::Config::IsUdpMulticastRecEnabled(); - // tcp config - tcp.enable = eCAL::Config::IsTcpRecEnabled(); - } + // // tcp config + // tcp.enable = eCAL::Config::IsTcpRecEnabled(); + // } } } From a2aca3ef2d869b66350a39b37be03ae282222bcb Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 21 May 2024 13:28:26 +0200 Subject: [PATCH 089/105] Renamend Configuration member. --- .../configuration/src/hello_config/main.cpp | 6 +- ecal/core/include/ecal/ecal_publisher.h | 6 +- ecal/core/include/ecal/ecal_subscriber.h | 8 +- .../include/ecal/msg/capnproto/publisher.h | 4 +- .../include/ecal/msg/flatbuffers/publisher.h | 4 +- .../include/ecal/msg/messagepack/publisher.h | 4 +- .../ecal/msg/protobuf/dynamic_publisher.h | 2 +- .../include/ecal/msg/protobuf/publisher.h | 4 +- ecal/core/include/ecal/msg/publisher.h | 6 +- ecal/core/include/ecal/msg/string/publisher.h | 4 +- .../include/ecal/types/ecal_config_types.h | 20 ++-- ecal/core/src/config/ecal_config.cpp | 94 +++++++++---------- .../src/config/ecal_config_initializer.cpp | 24 ++--- ecal/core/src/readwrite/ecal_writer.h | 2 +- .../counter_rec/src/counter_rec.cpp | 6 +- .../cpp/misc/config/src/config_sample.cpp | 2 +- .../tests/cpp/config_test/src/config_test.cpp | 74 +++++++-------- 17 files changed, 136 insertions(+), 134 deletions(-) diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 0100e5fb46..17b3d37af5 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -18,13 +18,13 @@ int main(int argc, char** argv) try { // Set the communication layer to network - custom_config.transport_layer_options.network_enabled = true; + custom_config.transport_layer.network_enabled = true; // Set a custom udp multicast group, correct IP address necessary - custom_config.transport_layer_options.mc_options.group = std::string("239.0.1.1"); + custom_config.transport_layer.mc_options.group = std::string("239.0.1.1"); // Increase the send buffer, size increase in 1024 bytes steps - custom_config.transport_layer_options.mc_options.sndbuf = (5242880 + 10 * 1024); + custom_config.transport_layer.mc_options.sndbuf = (5242880 + 10 * 1024); } catch (std::invalid_argument& e) { diff --git a/ecal/core/include/ecal/ecal_publisher.h b/ecal/core/include/ecal/ecal_publisher.h index 6753e051e4..0111af48d2 100644 --- a/ecal/core/include/ecal/ecal_publisher.h +++ b/ecal/core/include/ecal/ecal_publisher.h @@ -85,7 +85,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); + ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); /** * @brief Constructor. @@ -93,7 +93,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); + ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); /** * @brief Destructor. @@ -129,7 +129,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index 88ed644bc2..2bc05d1d05 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -97,7 +97,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); + ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); /** * @brief Constructor. @@ -105,7 +105,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param data_type_info_ Topic data type information (encoding, type, descriptor). **/ - ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); + ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); /** * @brief Destructor. @@ -141,7 +141,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber_options); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/msg/capnproto/publisher.h b/ecal/core/include/ecal/msg/capnproto/publisher.h index 6afc98bc3f..df729a4225 100644 --- a/ecal/core/include/ecal/msg/capnproto/publisher.h +++ b/ecal/core/include/ecal/msg/capnproto/publisher.h @@ -101,7 +101,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_) , builder(std::make_unique()) , root_builder(builder->initRoot()) @@ -150,7 +150,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/flatbuffers/publisher.h b/ecal/core/include/ecal/msg/flatbuffers/publisher.h index 0ca1558f30..59ae579e2e 100644 --- a/ecal/core/include/ecal/msg/flatbuffers/publisher.h +++ b/ecal/core/include/ecal/msg/flatbuffers/publisher.h @@ -53,7 +53,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -85,7 +85,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/messagepack/publisher.h b/ecal/core/include/ecal/msg/messagepack/publisher.h index e2bcbf628a..6a84e3113c 100644 --- a/ecal/core/include/ecal/msg/messagepack/publisher.h +++ b/ecal/core/include/ecal/msg/messagepack/publisher.h @@ -56,7 +56,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -88,7 +88,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h index 1333cbd543..41053d0e8b 100644 --- a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h @@ -62,7 +62,7 @@ namespace eCAL * @param msg_ Protobuf message object. * @param config_ Optional configuration parameters. **/ - CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_) , m_msg{ msg_ } {} diff --git a/ecal/core/include/ecal/msg/protobuf/publisher.h b/ecal/core/include/ecal/msg/protobuf/publisher.h index 41b44bd5d7..965fc9dfbf 100644 --- a/ecal/core/include/ecal/msg/protobuf/publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/publisher.h @@ -107,7 +107,7 @@ namespace eCAL // where the vtable is not created yet, or it's destructed. // Probably we can handle the Message publishers differently. One message publisher class and then one class for payloads and getting type // descriptor information. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) { } @@ -144,7 +144,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/publisher.h b/ecal/core/include/ecal/msg/publisher.h index 57677a9126..2c087acaf7 100644 --- a/ecal/core/include/ecal/msg/publisher.h +++ b/ecal/core/include/ecal/msg/publisher.h @@ -63,7 +63,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CPublisher(topic_name_, data_type_info_, config_) + CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CPublisher(topic_name_, data_type_info_, config_) { } @@ -74,7 +74,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -109,7 +109,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(CPublisher::Create(topic_name_, data_type_info_, config_)); } diff --git a/ecal/core/include/ecal/msg/string/publisher.h b/ecal/core/include/ecal/msg/string/publisher.h index 623cad688a..93d17d5404 100644 --- a/ecal/core/include/ecal/msg/string/publisher.h +++ b/ecal/core/include/ecal/msg/string/publisher.h @@ -60,7 +60,7 @@ namespace eCAL // call the function via its class because it's a virtual function that is called in constructor/destructor,- // where the vtable is not created yet, or it's destructed. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -92,7 +92,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 21ff55633f..55026dbc3c 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -48,17 +48,17 @@ namespace eCAL { struct Configuration { - TransportLayer::Configuration transport_layer_options{}; - Config::RegistrationOptions registration_options{}; - Config::MonitoringOptions monitoring_options{}; - Subscriber::Configuration subscriber_options{}; - Publisher::Configuration publisher_options{}; - Config::TimesyncOptions timesync_options{}; - Config::ServiceOptions service_options{}; - Config::ApplicationOptions application_options{}; - Config::LoggingOptions logging_options{}; + TransportLayer::Configuration transport_layer{}; + Config::RegistrationOptions registration{}; + Config::MonitoringOptions monitoring{}; + Subscriber::Configuration subscriber{}; + Publisher::Configuration publisher{}; + Config::TimesyncOptions timesync{}; + Config::ServiceOptions service{}; + Config::ApplicationOptions application{}; + Config::LoggingOptions logging{}; Cli::Configuration command_line_arguments{}; - std::string loaded_ecal_ini_file{}; + std::string ecal_ini_file_path{}; ECAL_API Configuration(int argc_ , char **argv_); ECAL_API Configuration(std::vector args_); diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index b7dd021e0d..4501d90aa0 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -89,91 +89,91 @@ namespace eCAL // common ///////////////////////////////////// - ECAL_API std::string GetLoadedEcalIniPath () { return GetCurrentConfig().loaded_ecal_ini_file; } - ECAL_API int GetRegistrationTimeoutMs () { return GetCurrentConfig().registration_options.getTimeoutMS(); } - ECAL_API int GetRegistrationRefreshMs () { return GetCurrentConfig().registration_options.getRefreshMS(); } + ECAL_API std::string GetLoadedEcalIniPath () { return GetCurrentConfig().ecal_ini_file_path; } + ECAL_API int GetRegistrationTimeoutMs () { return GetCurrentConfig().registration.getTimeoutMS(); } + ECAL_API int GetRegistrationRefreshMs () { return GetCurrentConfig().registration.getRefreshMS(); } ///////////////////////////////////// // network ///////////////////////////////////// - ECAL_API bool IsNetworkEnabled () { return GetCurrentConfig().transport_layer_options.network_enabled; } + ECAL_API bool IsNetworkEnabled () { return GetCurrentConfig().transport_layer.network_enabled; } - ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetCurrentConfig().transport_layer_options.mc_options.config_version; } + ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetCurrentConfig().transport_layer.mc_options.config_version; } - ECAL_API std::string GetUdpMulticastGroup () { return GetCurrentConfig().transport_layer_options.mc_options.group; } - ECAL_API std::string GetUdpMulticastMask () { return GetCurrentConfig().transport_layer_options.mc_options.mask; } - ECAL_API int GetUdpMulticastPort () { return GetCurrentConfig().transport_layer_options.mc_options.port; } - ECAL_API int GetUdpMulticastTtl () { return GetCurrentConfig().transport_layer_options.mc_options.ttl; } + ECAL_API std::string GetUdpMulticastGroup () { return GetCurrentConfig().transport_layer.mc_options.group; } + ECAL_API std::string GetUdpMulticastMask () { return GetCurrentConfig().transport_layer.mc_options.mask; } + ECAL_API int GetUdpMulticastPort () { return GetCurrentConfig().transport_layer.mc_options.port; } + ECAL_API int GetUdpMulticastTtl () { return GetCurrentConfig().transport_layer.mc_options.ttl; } - ECAL_API int GetUdpMulticastSndBufSizeBytes () { return GetCurrentConfig().transport_layer_options.mc_options.sndbuf; } - ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetCurrentConfig().transport_layer_options.mc_options.recbuf; } - ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.join_all_interfaces; } + ECAL_API int GetUdpMulticastSndBufSizeBytes () { return GetCurrentConfig().transport_layer.mc_options.sndbuf; } + ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetCurrentConfig().transport_layer.mc_options.recbuf; } + ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetCurrentConfig().transport_layer.mc_options.join_all_interfaces; } - ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().subscriber_options.udp.enable; } - ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().subscriber_options.shm.enable; } - ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().subscriber_options.tcp.enable; } + ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().subscriber.udp.enable; } + ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().subscriber.shm.enable; } + ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().subscriber.tcp.enable; } - ECAL_API bool IsNpcapEnabled () { return GetCurrentConfig().transport_layer_options.mc_options.npcap_enabled; } + ECAL_API bool IsNpcapEnabled () { return GetCurrentConfig().transport_layer.mc_options.npcap_enabled; } - ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.num_executor_reader); } - ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.num_executor_writer); } - ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return static_cast(GetCurrentConfig().transport_layer_options.tcp_options.max_reconnections); } + ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.num_executor_reader); } + ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.num_executor_writer); } + ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.max_reconnections); } - ECAL_API std::string GetHostGroupName () { return GetCurrentConfig().transport_layer_options.shm_options.host_group_name; } + ECAL_API std::string GetHostGroupName () { return GetCurrentConfig().transport_layer.shm_options.host_group_name; } ///////////////////////////////////// // time ///////////////////////////////////// - ECAL_API std::string GetTimesyncModuleName () { return GetCurrentConfig().timesync_options.timesync_module_rt; } - ECAL_API std::string GetTimesyncModuleReplay () { return GetCurrentConfig().timesync_options.timesync_module_replay; } + ECAL_API std::string GetTimesyncModuleName () { return GetCurrentConfig().timesync.timesync_module_rt; } + ECAL_API std::string GetTimesyncModuleReplay () { return GetCurrentConfig().timesync.timesync_module_replay; } ///////////////////////////////////// // process ///////////////////////////////////// - ECAL_API std::string GetTerminalEmulatorCommand () { return GetCurrentConfig().application_options.startup_options.terminal_emulator; } + ECAL_API std::string GetTerminalEmulatorCommand () { return GetCurrentConfig().application.startup_options.terminal_emulator; } ///////////////////////////////////// // monitoring ///////////////////////////////////// - ECAL_API int GetMonitoringTimeoutMs () { return GetCurrentConfig().monitoring_options.monitoring_timeout; } - ECAL_API std::string GetMonitoringFilterExcludeList () { return GetCurrentConfig().monitoring_options.filter_excl; } - ECAL_API std::string GetMonitoringFilterIncludeList () { return GetCurrentConfig().monitoring_options.filter_incl; } - ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return GetCurrentConfig().logging_options.filter_log_con; } - ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return GetCurrentConfig().logging_options.filter_log_file; } - ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return GetCurrentConfig().logging_options.filter_log_udp; } + ECAL_API int GetMonitoringTimeoutMs () { return GetCurrentConfig().monitoring.monitoring_timeout; } + ECAL_API std::string GetMonitoringFilterExcludeList () { return GetCurrentConfig().monitoring.filter_excl; } + ECAL_API std::string GetMonitoringFilterIncludeList () { return GetCurrentConfig().monitoring.filter_incl; } + ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return GetCurrentConfig().logging.filter_log_con; } + ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return GetCurrentConfig().logging.filter_log_file; } + ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return GetCurrentConfig().logging.filter_log_udp; } ///////////////////////////////////// // sys ///////////////////////////////////// - ECAL_API std::string GetEcalSysFilterExcludeList () { return GetCurrentConfig().application_options.sys_options.filter_excl; } + ECAL_API std::string GetEcalSysFilterExcludeList () { return GetCurrentConfig().application.sys_options.filter_excl; } ///////////////////////////////////// // publisher ///////////////////////////////////// - ECAL_API bool GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher_options.udp.enable; } - ECAL_API bool GetPublisherShmMode () { return GetCurrentConfig().publisher_options.shm.enable; } - ECAL_API bool GetPublisherTcpMode () { return GetCurrentConfig().publisher_options.tcp.enable; } + ECAL_API bool GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher.udp.enable; } + ECAL_API bool GetPublisherShmMode () { return GetCurrentConfig().publisher.shm.enable; } + ECAL_API bool GetPublisherTcpMode () { return GetCurrentConfig().publisher.tcp.enable; } - ECAL_API size_t GetMemfileMinsizeBytes () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_minsize; } - ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_reserve; } - ECAL_API int GetMemfileAckTimeoutMs () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_ack_timeout; } - ECAL_API bool IsMemfileZerocopyEnabled () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_zero_copy; } - ECAL_API size_t GetMemfileBufferCount () { return GetCurrentConfig().transport_layer_options.shm_options.memfile_buffer_count; } + ECAL_API size_t GetMemfileMinsizeBytes () { return GetCurrentConfig().transport_layer.shm_options.memfile_minsize; } + ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetCurrentConfig().transport_layer.shm_options.memfile_reserve; } + ECAL_API int GetMemfileAckTimeoutMs () { return GetCurrentConfig().transport_layer.shm_options.memfile_ack_timeout; } + ECAL_API bool IsMemfileZerocopyEnabled () { return GetCurrentConfig().transport_layer.shm_options.memfile_zero_copy; } + ECAL_API size_t GetMemfileBufferCount () { return GetCurrentConfig().transport_layer.shm_options.memfile_buffer_count; } - ECAL_API bool IsTopicTypeSharingEnabled () { return GetCurrentConfig().registration_options.share_ttype; } - ECAL_API bool IsTopicDescriptionSharingEnabled () { return GetCurrentConfig().registration_options.share_tdesc; } + ECAL_API bool IsTopicTypeSharingEnabled () { return GetCurrentConfig().registration.share_ttype; } + ECAL_API bool IsTopicDescriptionSharingEnabled () { return GetCurrentConfig().registration.share_tdesc; } ///////////////////////////////////// // service ///////////////////////////////////// - ECAL_API bool IsServiceProtocolV0Enabled () { return GetCurrentConfig().service_options.protocol_v0; } - ECAL_API bool IsServiceProtocolV1Enabled () { return GetCurrentConfig().service_options.protocol_v1; } + ECAL_API bool IsServiceProtocolV0Enabled () { return GetCurrentConfig().service.protocol_v0; } + ECAL_API bool IsServiceProtocolV1Enabled () { return GetCurrentConfig().service.protocol_v1; } ///////////////////////////////////// // experimemtal @@ -181,11 +181,11 @@ namespace eCAL namespace Experimental { - ECAL_API bool IsShmMonitoringEnabled () { return (GetCurrentConfig().monitoring_options.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } - ECAL_API bool IsNetworkMonitoringDisabled () { return !GetCurrentConfig().monitoring_options.network_monitoring; } - ECAL_API size_t GetShmMonitoringQueueSize () { return GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_queue_size; } - ECAL_API std::string GetShmMonitoringDomain () { return GetCurrentConfig().monitoring_options.shm_options.shm_monitoring_domain;} - ECAL_API bool GetDropOutOfOrderMessages () { return GetCurrentConfig().transport_layer_options.drop_out_of_order_messages; } + ECAL_API bool IsShmMonitoringEnabled () { return (GetCurrentConfig().monitoring.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } + ECAL_API bool IsNetworkMonitoringDisabled () { return !GetCurrentConfig().monitoring.network_monitoring; } + ECAL_API size_t GetShmMonitoringQueueSize () { return GetCurrentConfig().monitoring.shm_options.shm_monitoring_queue_size; } + ECAL_API std::string GetShmMonitoringDomain () { return GetCurrentConfig().monitoring.shm_options.shm_monitoring_domain;} + ECAL_API bool GetDropOutOfOrderMessages () { return GetCurrentConfig().transport_layer.drop_out_of_order_messages; } } } } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index da2f79430e..130be804bf 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -106,11 +106,11 @@ namespace eCAL if (!ini_path_.empty()) { iniConfig.AddFile(ini_path_); - loaded_ecal_ini_file = ini_path_; + ecal_ini_file_path = ini_path_; } // transport layer options - auto& transportLayerOptions = transport_layer_options; + auto& transportLayerOptions = transport_layer; transportLayerOptions.network_enabled = iniConfig.get(NETWORK, "network_enabled", NET_ENABLED); transportLayerOptions.drop_out_of_order_messages = iniConfig.get(EXPERIMENTAL, "drop_out_of_order_messages", EXP_DROP_OUT_OF_ORDER_MESSAGES); @@ -149,13 +149,13 @@ namespace eCAL // registration options auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", CMN_REGISTRATION_TO); auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", CMN_REGISTRATION_REFRESH); - registration_options = Config::RegistrationOptions(registrationTimeout, registrationRefresh); - auto& registrationOptions = registration_options; + registration = Config::RegistrationOptions(registrationTimeout, registrationRefresh); + auto& registrationOptions = registration; registrationOptions.share_tdesc = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); registrationOptions.share_ttype = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); // monitoring options - auto& monitoringOptions = monitoring_options; + auto& monitoringOptions = monitoring; auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? Config::MonitoringMode::shm_monitoring : Config::MonitoringMode::none; monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; @@ -171,36 +171,36 @@ namespace eCAL shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", EXP_SHM_MONITORING_QUEUE_SIZE); // receiving options - auto& subscriberOptions = subscriber_options; + auto& subscriberOptions = subscriber; subscriberOptions.shm.enable = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED) != 0; subscriberOptions.tcp.enable = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED) != 0; subscriberOptions.udp.enable = iniConfig.get(NETWORK, "udp_mc_rec_enabled", NET_UDP_MC_REC_ENABLED) != 0; // publisher options - auto& publisherOptions = publisher_options; + auto& publisherOptions = publisher; publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; publisherOptions.tcp.enable = iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) != 0; publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; // timesync options - auto& timesyncOptions = timesync_options; + auto& timesyncOptions = timesync; timesyncOptions.timesync_module_rt = iniConfig.get(TIME, "timesync_module_rt", TIME_SYNC_MODULE); timesyncOptions.timesync_module_replay = iniConfig.get(TIME, "timesync_module_replay", TIME_SYNC_MOD_REPLAY); // service options - auto& serviceOptions = service_options; + auto& serviceOptions = service; serviceOptions.protocol_v0 = iniConfig.get(SERVICE, "protocol_v0", SERVICE_PROTOCOL_V0); serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", SERVICE_PROTOCOL_V1); // sys options - auto& sysOptions = application_options.sys_options; + auto& sysOptions = application.sys_options; sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); // process options - auto& processOptions = application_options.startup_options; + auto& processOptions = application.startup_options; processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); - auto& loggingOptions = logging_options; + auto& loggingOptions = logging; // needs to be adapted when switching from simpleini loggingOptions.filter_log_con = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_con", "info,warning,error,fatal")); loggingOptions.filter_log_file = ParseLogLevel(iniConfig.get(MONITORING, "filter_log_file", "")); diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 245154fb3f..a2d4d357eb 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -79,7 +79,7 @@ namespace eCAL } }; - CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher_options); + CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); ~CDataWriter(); bool Stop(); diff --git a/ecal/samples/cpp/benchmarks/counter_rec/src/counter_rec.cpp b/ecal/samples/cpp/benchmarks/counter_rec/src/counter_rec.cpp index 3a323f100a..986371abfc 100644 --- a/ecal/samples/cpp/benchmarks/counter_rec/src/counter_rec.cpp +++ b/ecal/samples/cpp/benchmarks/counter_rec/src/counter_rec.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -27,7 +27,9 @@ int main(int argc, char **argv) eCAL::Initialize(argc, argv, "counter_rec_cb"); // create subscriber for topic "Counter" - eCAL::CSubscriber sub("Counter", { "", "long long", "" }); + eCAL::SDataTypeInformation datatype_information; + datatype_information.encoding = "long long"; + eCAL::CSubscriber sub("Counter", datatype_information); // counter long long g_clock(0); diff --git a/ecal/samples/cpp/misc/config/src/config_sample.cpp b/ecal/samples/cpp/misc/config/src/config_sample.cpp index afe05df5ae..42ad2f27f0 100644 --- a/ecal/samples/cpp/misc/config/src/config_sample.cpp +++ b/ecal/samples/cpp/misc/config/src/config_sample.cpp @@ -28,7 +28,7 @@ int main(int argc, char **argv) eCAL::Configuration my_config(argc, argv); // setting configuration - my_config.monitoring_options.network_monitoring = true; + my_config.monitoring.network_monitoring = true; // initialize eCAL API eCAL::Initialize(my_config, "config sample"); diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 5d82062cf1..9ee676b947 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -60,21 +60,21 @@ TEST(core_cpp_config, user_config_passing) // Registration options const unsigned int registration_timeout = 80000U; const unsigned int registration_refresh = 2000U; - const eCAL::Config::RegistrationOptions registration_options = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); + const eCAL::Config::RegistrationOptions registration = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); try{ - custom_config.transport_layer_options.network_enabled = network_enabled; - custom_config.transport_layer_options.mc_options.group = ip_address; - custom_config.transport_layer_options.mc_options.sndbuf = upd_snd_buff; + custom_config.transport_layer.network_enabled = network_enabled; + custom_config.transport_layer.mc_options.group = ip_address; + custom_config.transport_layer.mc_options.sndbuf = upd_snd_buff; - custom_config.monitoring_options.monitoring_timeout = mon_timeout; - custom_config.monitoring_options.filter_excl = mon_filter_excl; - custom_config.monitoring_options.monitoring_mode = monitoring_mode; - custom_config.logging_options.filter_log_con = mon_log_filter_con; + custom_config.monitoring.monitoring_timeout = mon_timeout; + custom_config.monitoring.filter_excl = mon_filter_excl; + custom_config.monitoring.monitoring_mode = monitoring_mode; + custom_config.logging.filter_log_con = mon_log_filter_con; - custom_config.publisher_options.shm.enable = pub_use_shm; + custom_config.publisher.shm.enable = pub_use_shm; - custom_config.registration_options = registration_options; + custom_config.registration = registration; } catch (std::invalid_argument& e) { @@ -85,32 +85,32 @@ TEST(core_cpp_config, user_config_passing) EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); // Test boolean assignment, default is false - EXPECT_EQ(network_enabled, eCAL::GetCurrentConfig().transport_layer_options.network_enabled); + EXPECT_EQ(network_enabled, eCAL::GetCurrentConfig().transport_layer.network_enabled); // Test IP address assignment, default is 239.0.0.1 - EXPECT_EQ(ip_address, static_cast(eCAL::GetCurrentConfig().transport_layer_options.mc_options.group)); + EXPECT_EQ(ip_address, static_cast(eCAL::GetCurrentConfig().transport_layer.mc_options.group)); // Test UDP send buffer assignment, default is 5242880 - EXPECT_EQ(upd_snd_buff, static_cast(eCAL::GetCurrentConfig().transport_layer_options.mc_options.sndbuf)); + EXPECT_EQ(upd_snd_buff, static_cast(eCAL::GetCurrentConfig().transport_layer.mc_options.sndbuf)); // Test monitoring timeout assignment, default is 5000U - EXPECT_EQ(mon_timeout, eCAL::GetCurrentConfig().monitoring_options.monitoring_timeout); + EXPECT_EQ(mon_timeout, eCAL::GetCurrentConfig().monitoring.monitoring_timeout); // Test monitoring filter exclude assignment, default is "_.*" - EXPECT_EQ(mon_filter_excl, eCAL::GetCurrentConfig().monitoring_options.filter_excl); + EXPECT_EQ(mon_filter_excl, eCAL::GetCurrentConfig().monitoring.filter_excl); // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) - EXPECT_EQ(mon_log_filter_con, eCAL::GetCurrentConfig().logging_options.filter_log_con); + EXPECT_EQ(mon_log_filter_con, eCAL::GetCurrentConfig().logging.filter_log_con); // Test monitoring mode assignment, default is eCAL::Config::MonitoringMode::none - EXPECT_EQ(monitoring_mode, eCAL::GetCurrentConfig().monitoring_options.monitoring_mode); + EXPECT_EQ(monitoring_mode, eCAL::GetCurrentConfig().monitoring.monitoring_mode); // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto - EXPECT_EQ(pub_use_shm, eCAL::GetCurrentConfig().publisher_options.shm.enable); + EXPECT_EQ(pub_use_shm, eCAL::GetCurrentConfig().publisher.shm.enable); // Test registration option assignment, default timeout is 60000U and default refresh is 1000U - EXPECT_EQ(registration_timeout, eCAL::GetCurrentConfig().registration_options.getTimeoutMS()); - EXPECT_EQ(registration_refresh, eCAL::GetCurrentConfig().registration_options.getRefreshMS()); + EXPECT_EQ(registration_timeout, eCAL::GetCurrentConfig().registration.getTimeoutMS()); + EXPECT_EQ(registration_refresh, eCAL::GetCurrentConfig().registration.getRefreshMS()); // Finalize eCAL API EXPECT_EQ(0, eCAL::Finalize()); @@ -122,60 +122,60 @@ TEST(ConfigDeathTest, user_config_death_test) // Test the IpAddressV4 class with wrong values ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("42")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("42")), std::invalid_argument); // Test the IpAddressV4 class with invalid addresses ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("256.0.0.0")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("256.0.0.0")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("127.0.0.1")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("127.0.0.1")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("255.255.255.255")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("255.255.255.255")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FFF.FF.FF.FF")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("FFF.FF.FF.FF")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("FF.FF.FF.FF")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("FF.FF.FF.FF")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("Ff.fF.ff.Ff")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("Ff.fF.ff.Ff")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("7f.0.0.1")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("7f.0.0.1")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.0.0.0")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("0.0.0.0")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("00.00.00.00")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("00.00.00.00")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("000.000.000.000")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("000.000.000.000")), std::invalid_argument); ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.group, std::string("0.00.000.0")), + SetValue(custom_config.transport_layer.mc_options.group, std::string("0.00.000.0")), std::invalid_argument); // Test the ConstrainedInteger class with wrong values. Default are MIN = 5242880, STEP = 1024 // Value below MIN ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.sndbuf, 42), + SetValue(custom_config.transport_layer.mc_options.sndbuf, 42), std::invalid_argument); // Wrong step. Default STEP = 1024 ASSERT_THROW( - SetValue(custom_config.transport_layer_options.mc_options.sndbuf, (5242880 + 512)), + SetValue(custom_config.transport_layer.mc_options.sndbuf, (5242880 + 512)), std::invalid_argument); // Value exceeds MAX. Default MAX = 100 ASSERT_THROW( - SetValue(custom_config.transport_layer_options.shm_options.memfile_reserve, 150), + SetValue(custom_config.transport_layer.shm_options.memfile_reserve, 150), std::invalid_argument); // Test the registration option limits @@ -211,11 +211,11 @@ TEST(core_cpp_config, config_custom_datatypes_tests) eCAL::Configuration config1(0, nullptr); eCAL::Configuration config2(0, nullptr); std::string testValue = std::string("234.0.3.2"); - config2.transport_layer_options.mc_options.group = testValue; + config2.transport_layer.mc_options.group = testValue; auto& config2ref = config2; config1 = config2ref; - EXPECT_EQ(static_cast(config1.transport_layer_options.mc_options.group), testValue); + EXPECT_EQ(static_cast(config1.transport_layer.mc_options.group), testValue); } TEST(core_cpp_config, config_cmd_parser) From cf2148ca2054ad2a37f63582a0cf38f10d538595 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 21 May 2024 15:44:58 +0200 Subject: [PATCH 090/105] Moved config to globalgalactic space. Implemented default config constructor. Some renaming. --- .../ecal/config/ecal_publisher_config.h | 26 ++--- .../ecal/config/ecal_subscriber_config.h | 8 +- ecal/core/include/ecal/ecal_config.h | 2 +- ecal/core/include/ecal/ecal_subscriber.h | 6 +- .../include/ecal/msg/capnproto/publisher.h | 4 +- .../include/ecal/msg/flatbuffers/publisher.h | 4 +- .../include/ecal/msg/messagepack/publisher.h | 4 +- .../ecal/msg/protobuf/dynamic_publisher.h | 2 +- .../include/ecal/msg/protobuf/publisher.h | 4 +- ecal/core/include/ecal/msg/publisher.h | 6 +- ecal/core/include/ecal/msg/string/publisher.h | 4 +- .../include/ecal/types/ecal_config_types.h | 13 ++- ecal/core/src/config/ecal_config.cpp | 94 +++++++++---------- .../src/config/ecal_config_initializer.cpp | 15 ++- ecal/core/src/config/ecal_config_reader.cpp | 22 +---- ecal/core/src/config/ecal_config_reader.h | 7 +- ecal/core/src/ecal.cpp | 4 +- ecal/core/src/ecal_global_accessors.cpp | 10 +- ecal/core/src/ecal_global_accessors.h | 10 +- ecal/core/src/ecal_globals.cpp | 9 +- ecal/core/src/ecal_globals.h | 7 -- .../core/src/pubsub/ecal_publisher_config.cpp | 25 +---- .../src/pubsub/ecal_subscriber_config.cpp | 15 +-- ecal/core/src/readwrite/ecal_writer.h | 2 +- .../tests/cpp/config_test/src/config_test.cpp | 20 ++-- 25 files changed, 136 insertions(+), 187 deletions(-) diff --git a/ecal/core/include/ecal/config/ecal_publisher_config.h b/ecal/core/include/ecal/config/ecal_publisher_config.h index 42da95b237..d4b3a04ad6 100644 --- a/ecal/core/include/ecal/config/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/ecal_publisher_config.h @@ -100,13 +100,13 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer - bool zero_copy_mode = false; //!< enable zero copy shared memory transport mode - int acknowledge_timeout_ms = 0; /*!< force connected subscribers to send acknowledge event after processing the message + bool enable; //!< enable layer + bool zero_copy_mode; //!< enable zero copy shared memory transport mode + int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message the publisher send call is blocked on this event with this timeout (0 == no handshake) */ - size_t memfile_min_size_bytes = 4096; //!< default memory file size for new publisher - size_t memfile_reserve_percent = 50; //!< dynamic file size reserve before recreating memory file if topic size changes - size_t memfile_buffer_count = 1; //!< maximum number of used buffers (needs to be greater than 1, default = 1) + size_t memfile_min_size_bytes; //!< default memory file size for new publisher + size_t memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes + size_t memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) }; } @@ -114,9 +114,9 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer - bool loopback = false; //!< enable to receive udp messages on the same local machine - int sndbuf_size_bytes = (5*1024*1024); //!< udp send buffer size in bytes (default 5MB) + bool enable; //!< enable layer + bool loopback; //!< enable to receive udp messages on the same local machine + int sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) }; } @@ -124,20 +124,20 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer + bool enable; //!< enable layer }; } struct ECAL_API Configuration { - // Configuration(); + Configuration(); SHM::Configuration shm; UDP::Configuration udp; TCP::Configuration tcp; - bool share_topic_type = true; //!< share topic type via registration - bool share_topic_description = true; //!< share topic description via registration + bool share_topic_type; //!< share topic type via registration + bool share_topic_description; //!< share topic description via registration }; } } diff --git a/ecal/core/include/ecal/config/ecal_subscriber_config.h b/ecal/core/include/ecal/config/ecal_subscriber_config.h index b5930931f4..e885b5382b 100644 --- a/ecal/core/include/ecal/config/ecal_subscriber_config.h +++ b/ecal/core/include/ecal/config/ecal_subscriber_config.h @@ -36,7 +36,7 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer + bool enable; //!< enable layer }; } @@ -44,7 +44,7 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer + bool enable; //!< enable layer }; } @@ -52,13 +52,13 @@ namespace eCAL { struct ECAL_API Configuration { - bool enable = false; //!< enable layer + bool enable; //!< enable layer }; } struct ECAL_API Configuration { - // Configuration(); + Configuration(); SHM::Configuration shm; UDP::Configuration udp; diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 14dd0359c0..d86f7ee3ca 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -30,7 +30,7 @@ //@{ namespace eCAL { - ECAL_API Configuration& GetCurrentConfig(); + ECAL_API Configuration& GetConfiguration(); namespace Config { diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index 2bc05d1d05..1f10e002a0 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -97,7 +97,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); + ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); /** * @brief Constructor. @@ -105,7 +105,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param data_type_info_ Topic data type information (encoding, type, descriptor). **/ - ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); + ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); /** * @brief Destructor. @@ -141,7 +141,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetCurrentConfig().subscriber); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/msg/capnproto/publisher.h b/ecal/core/include/ecal/msg/capnproto/publisher.h index df729a4225..46b4b718e1 100644 --- a/ecal/core/include/ecal/msg/capnproto/publisher.h +++ b/ecal/core/include/ecal/msg/capnproto/publisher.h @@ -101,7 +101,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_) , builder(std::make_unique()) , root_builder(builder->initRoot()) @@ -150,7 +150,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/flatbuffers/publisher.h b/ecal/core/include/ecal/msg/flatbuffers/publisher.h index 59ae579e2e..faf50afa14 100644 --- a/ecal/core/include/ecal/msg/flatbuffers/publisher.h +++ b/ecal/core/include/ecal/msg/flatbuffers/publisher.h @@ -53,7 +53,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -85,7 +85,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/messagepack/publisher.h b/ecal/core/include/ecal/msg/messagepack/publisher.h index 6a84e3113c..5be1676ee3 100644 --- a/ecal/core/include/ecal/msg/messagepack/publisher.h +++ b/ecal/core/include/ecal/msg/messagepack/publisher.h @@ -56,7 +56,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -88,7 +88,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h index 41053d0e8b..d79db88468 100644 --- a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h @@ -62,7 +62,7 @@ namespace eCAL * @param msg_ Protobuf message object. * @param config_ Optional configuration parameters. **/ - CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_) , m_msg{ msg_ } {} diff --git a/ecal/core/include/ecal/msg/protobuf/publisher.h b/ecal/core/include/ecal/msg/protobuf/publisher.h index 965fc9dfbf..f316b079a2 100644 --- a/ecal/core/include/ecal/msg/protobuf/publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/publisher.h @@ -107,7 +107,7 @@ namespace eCAL // where the vtable is not created yet, or it's destructed. // Probably we can handle the Message publishers differently. One message publisher class and then one class for payloads and getting type // descriptor information. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) { } @@ -144,7 +144,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/publisher.h b/ecal/core/include/ecal/msg/publisher.h index 2c087acaf7..08c25a6043 100644 --- a/ecal/core/include/ecal/msg/publisher.h +++ b/ecal/core/include/ecal/msg/publisher.h @@ -63,7 +63,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CPublisher(topic_name_, data_type_info_, config_) + CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CPublisher(topic_name_, data_type_info_, config_) { } @@ -74,7 +74,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -109,7 +109,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(CPublisher::Create(topic_name_, data_type_info_, config_)); } diff --git a/ecal/core/include/ecal/msg/string/publisher.h b/ecal/core/include/ecal/msg/string/publisher.h index 93d17d5404..0ea9f36b0d 100644 --- a/ecal/core/include/ecal/msg/string/publisher.h +++ b/ecal/core/include/ecal/msg/string/publisher.h @@ -60,7 +60,7 @@ namespace eCAL // call the function via its class because it's a virtual function that is called in constructor/destructor,- // where the vtable is not created yet, or it's destructed. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -92,7 +92,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 55026dbc3c..486086a79a 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -57,15 +57,22 @@ namespace eCAL Config::ServiceOptions service{}; Config::ApplicationOptions application{}; Config::LoggingOptions logging{}; - Cli::Configuration command_line_arguments{}; - std::string ecal_ini_file_path{}; + Cli::Configuration command_line_arguments{}; + ECAL_API Configuration(); ECAL_API Configuration(int argc_ , char **argv_); ECAL_API Configuration(std::vector args_); ECAL_API void InitConfigWithDefaultIni(); - ECAL_API void InitConfig(std::string ini_path_); + ECAL_API void InitConfig(std::string ini_path_ = std::string("")); + ECAL_API std::string GetIniFilePath(); + + friend class CmdParser; + + protected: + std::string ecal_ini_file_path{}; + private: ECAL_API void Init(int argc_ , char **argv_); }; diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index 4501d90aa0..642acce42c 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -89,91 +89,91 @@ namespace eCAL // common ///////////////////////////////////// - ECAL_API std::string GetLoadedEcalIniPath () { return GetCurrentConfig().ecal_ini_file_path; } - ECAL_API int GetRegistrationTimeoutMs () { return GetCurrentConfig().registration.getTimeoutMS(); } - ECAL_API int GetRegistrationRefreshMs () { return GetCurrentConfig().registration.getRefreshMS(); } + ECAL_API std::string GetLoadedEcalIniPath () { return GetConfiguration().GetIniFilePath(); } + ECAL_API int GetRegistrationTimeoutMs () { return GetConfiguration().registration.getTimeoutMS(); } + ECAL_API int GetRegistrationRefreshMs () { return GetConfiguration().registration.getRefreshMS(); } ///////////////////////////////////// // network ///////////////////////////////////// - ECAL_API bool IsNetworkEnabled () { return GetCurrentConfig().transport_layer.network_enabled; } + ECAL_API bool IsNetworkEnabled () { return GetConfiguration().transport_layer.network_enabled; } - ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetCurrentConfig().transport_layer.mc_options.config_version; } + ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetConfiguration().transport_layer.mc_options.config_version; } - ECAL_API std::string GetUdpMulticastGroup () { return GetCurrentConfig().transport_layer.mc_options.group; } - ECAL_API std::string GetUdpMulticastMask () { return GetCurrentConfig().transport_layer.mc_options.mask; } - ECAL_API int GetUdpMulticastPort () { return GetCurrentConfig().transport_layer.mc_options.port; } - ECAL_API int GetUdpMulticastTtl () { return GetCurrentConfig().transport_layer.mc_options.ttl; } + ECAL_API std::string GetUdpMulticastGroup () { return GetConfiguration().transport_layer.mc_options.group; } + ECAL_API std::string GetUdpMulticastMask () { return GetConfiguration().transport_layer.mc_options.mask; } + ECAL_API int GetUdpMulticastPort () { return GetConfiguration().transport_layer.mc_options.port; } + ECAL_API int GetUdpMulticastTtl () { return GetConfiguration().transport_layer.mc_options.ttl; } - ECAL_API int GetUdpMulticastSndBufSizeBytes () { return GetCurrentConfig().transport_layer.mc_options.sndbuf; } - ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetCurrentConfig().transport_layer.mc_options.recbuf; } - ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetCurrentConfig().transport_layer.mc_options.join_all_interfaces; } + ECAL_API int GetUdpMulticastSndBufSizeBytes () { return GetConfiguration().transport_layer.mc_options.sndbuf; } + ECAL_API int GetUdpMulticastRcvBufSizeBytes () { return GetConfiguration().transport_layer.mc_options.recbuf; } + ECAL_API bool IsUdpMulticastJoinAllIfEnabled () { return GetConfiguration().transport_layer.mc_options.join_all_interfaces; } - ECAL_API bool IsUdpMulticastRecEnabled () { return GetCurrentConfig().subscriber.udp.enable; } - ECAL_API bool IsShmRecEnabled () { return GetCurrentConfig().subscriber.shm.enable; } - ECAL_API bool IsTcpRecEnabled () { return GetCurrentConfig().subscriber.tcp.enable; } + ECAL_API bool IsUdpMulticastRecEnabled () { return GetConfiguration().subscriber.udp.enable; } + ECAL_API bool IsShmRecEnabled () { return GetConfiguration().subscriber.shm.enable; } + ECAL_API bool IsTcpRecEnabled () { return GetConfiguration().subscriber.tcp.enable; } - ECAL_API bool IsNpcapEnabled () { return GetCurrentConfig().transport_layer.mc_options.npcap_enabled; } + ECAL_API bool IsNpcapEnabled () { return GetConfiguration().transport_layer.mc_options.npcap_enabled; } - ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.num_executor_reader); } - ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.num_executor_writer); } - ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return static_cast(GetCurrentConfig().transport_layer.tcp_options.max_reconnections); } + ECAL_API int GetTcpPubsubReaderThreadpoolSize () { return static_cast(GetConfiguration().transport_layer.tcp_options.num_executor_reader); } + ECAL_API int GetTcpPubsubWriterThreadpoolSize () { return static_cast(GetConfiguration().transport_layer.tcp_options.num_executor_writer); } + ECAL_API int GetTcpPubsubMaxReconnectionAttemps () { return static_cast(GetConfiguration().transport_layer.tcp_options.max_reconnections); } - ECAL_API std::string GetHostGroupName () { return GetCurrentConfig().transport_layer.shm_options.host_group_name; } + ECAL_API std::string GetHostGroupName () { return GetConfiguration().transport_layer.shm_options.host_group_name; } ///////////////////////////////////// // time ///////////////////////////////////// - ECAL_API std::string GetTimesyncModuleName () { return GetCurrentConfig().timesync.timesync_module_rt; } - ECAL_API std::string GetTimesyncModuleReplay () { return GetCurrentConfig().timesync.timesync_module_replay; } + ECAL_API std::string GetTimesyncModuleName () { return GetConfiguration().timesync.timesync_module_rt; } + ECAL_API std::string GetTimesyncModuleReplay () { return GetConfiguration().timesync.timesync_module_replay; } ///////////////////////////////////// // process ///////////////////////////////////// - ECAL_API std::string GetTerminalEmulatorCommand () { return GetCurrentConfig().application.startup_options.terminal_emulator; } + ECAL_API std::string GetTerminalEmulatorCommand () { return GetConfiguration().application.startup_options.terminal_emulator; } ///////////////////////////////////// // monitoring ///////////////////////////////////// - ECAL_API int GetMonitoringTimeoutMs () { return GetCurrentConfig().monitoring.monitoring_timeout; } - ECAL_API std::string GetMonitoringFilterExcludeList () { return GetCurrentConfig().monitoring.filter_excl; } - ECAL_API std::string GetMonitoringFilterIncludeList () { return GetCurrentConfig().monitoring.filter_incl; } - ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return GetCurrentConfig().logging.filter_log_con; } - ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return GetCurrentConfig().logging.filter_log_file; } - ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return GetCurrentConfig().logging.filter_log_udp; } + ECAL_API int GetMonitoringTimeoutMs () { return GetConfiguration().monitoring.monitoring_timeout; } + ECAL_API std::string GetMonitoringFilterExcludeList () { return GetConfiguration().monitoring.filter_excl; } + ECAL_API std::string GetMonitoringFilterIncludeList () { return GetConfiguration().monitoring.filter_incl; } + ECAL_API eCAL_Logging_Filter GetConsoleLogFilter () { return GetConfiguration().logging.filter_log_con; } + ECAL_API eCAL_Logging_Filter GetFileLogFilter () { return GetConfiguration().logging.filter_log_file; } + ECAL_API eCAL_Logging_Filter GetUdpLogFilter () { return GetConfiguration().logging.filter_log_udp; } ///////////////////////////////////// // sys ///////////////////////////////////// - ECAL_API std::string GetEcalSysFilterExcludeList () { return GetCurrentConfig().application.sys_options.filter_excl; } + ECAL_API std::string GetEcalSysFilterExcludeList () { return GetConfiguration().application.sys_options.filter_excl; } ///////////////////////////////////// // publisher ///////////////////////////////////// - ECAL_API bool GetPublisherUdpMulticastMode () { return GetCurrentConfig().publisher.udp.enable; } - ECAL_API bool GetPublisherShmMode () { return GetCurrentConfig().publisher.shm.enable; } - ECAL_API bool GetPublisherTcpMode () { return GetCurrentConfig().publisher.tcp.enable; } + ECAL_API bool GetPublisherUdpMulticastMode () { return GetConfiguration().publisher.udp.enable; } + ECAL_API bool GetPublisherShmMode () { return GetConfiguration().publisher.shm.enable; } + ECAL_API bool GetPublisherTcpMode () { return GetConfiguration().publisher.tcp.enable; } - ECAL_API size_t GetMemfileMinsizeBytes () { return GetCurrentConfig().transport_layer.shm_options.memfile_minsize; } - ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetCurrentConfig().transport_layer.shm_options.memfile_reserve; } - ECAL_API int GetMemfileAckTimeoutMs () { return GetCurrentConfig().transport_layer.shm_options.memfile_ack_timeout; } - ECAL_API bool IsMemfileZerocopyEnabled () { return GetCurrentConfig().transport_layer.shm_options.memfile_zero_copy; } - ECAL_API size_t GetMemfileBufferCount () { return GetCurrentConfig().transport_layer.shm_options.memfile_buffer_count; } + ECAL_API size_t GetMemfileMinsizeBytes () { return GetConfiguration().transport_layer.shm_options.memfile_minsize; } + ECAL_API size_t GetMemfileOverprovisioningPercentage () { return GetConfiguration().transport_layer.shm_options.memfile_reserve; } + ECAL_API int GetMemfileAckTimeoutMs () { return GetConfiguration().transport_layer.shm_options.memfile_ack_timeout; } + ECAL_API bool IsMemfileZerocopyEnabled () { return GetConfiguration().transport_layer.shm_options.memfile_zero_copy; } + ECAL_API size_t GetMemfileBufferCount () { return GetConfiguration().transport_layer.shm_options.memfile_buffer_count; } - ECAL_API bool IsTopicTypeSharingEnabled () { return GetCurrentConfig().registration.share_ttype; } - ECAL_API bool IsTopicDescriptionSharingEnabled () { return GetCurrentConfig().registration.share_tdesc; } + ECAL_API bool IsTopicTypeSharingEnabled () { return GetConfiguration().registration.share_ttype; } + ECAL_API bool IsTopicDescriptionSharingEnabled () { return GetConfiguration().registration.share_tdesc; } ///////////////////////////////////// // service ///////////////////////////////////// - ECAL_API bool IsServiceProtocolV0Enabled () { return GetCurrentConfig().service.protocol_v0; } - ECAL_API bool IsServiceProtocolV1Enabled () { return GetCurrentConfig().service.protocol_v1; } + ECAL_API bool IsServiceProtocolV0Enabled () { return GetConfiguration().service.protocol_v0; } + ECAL_API bool IsServiceProtocolV1Enabled () { return GetConfiguration().service.protocol_v1; } ///////////////////////////////////// // experimemtal @@ -181,11 +181,11 @@ namespace eCAL namespace Experimental { - ECAL_API bool IsShmMonitoringEnabled () { return (GetCurrentConfig().monitoring.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } - ECAL_API bool IsNetworkMonitoringDisabled () { return !GetCurrentConfig().monitoring.network_monitoring; } - ECAL_API size_t GetShmMonitoringQueueSize () { return GetCurrentConfig().monitoring.shm_options.shm_monitoring_queue_size; } - ECAL_API std::string GetShmMonitoringDomain () { return GetCurrentConfig().monitoring.shm_options.shm_monitoring_domain;} - ECAL_API bool GetDropOutOfOrderMessages () { return GetCurrentConfig().transport_layer.drop_out_of_order_messages; } + ECAL_API bool IsShmMonitoringEnabled () { return (GetConfiguration().monitoring.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } + ECAL_API bool IsNetworkMonitoringDisabled () { return !GetConfiguration().monitoring.network_monitoring; } + ECAL_API size_t GetShmMonitoringQueueSize () { return GetConfiguration().monitoring.shm_options.shm_monitoring_queue_size; } + ECAL_API std::string GetShmMonitoringDomain () { return GetConfiguration().monitoring.shm_options.shm_monitoring_domain;} + ECAL_API bool GetDropOutOfOrderMessages () { return GetConfiguration().transport_layer.drop_out_of_order_messages; } } } } diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 130be804bf..5029caa4d0 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -238,8 +238,19 @@ namespace eCAL InitConfig(g_default_ini_file); } - Configuration& GetCurrentConfig() + Configuration::Configuration() + : Configuration(0, nullptr) { - return g_ecal_config(); + InitConfig(); + } + + std::string Configuration::GetIniFilePath() + { + return ecal_ini_file_path; + } + + Configuration& GetConfiguration() + { + return g_ecal_configuration; }; } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_reader.cpp b/ecal/core/src/config/ecal_config_reader.cpp index c3d796b79b..7b4be4de19 100644 --- a/ecal/core/src/config/ecal_config_reader.cpp +++ b/ecal/core/src/config/ecal_config_reader.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -452,24 +452,4 @@ namespace eCAL { return m_impl->GetValue(section_.c_str(), key_.c_str(), default_); } - - bool CfgGetBool(const std::string& section_, const std::string& key_, bool default_ /*= false*/) - { - return g_config()->get(section_, key_, default_); - } - - int CfgGetInt(const std::string& section_, const std::string& key_, int default_ /*= 0*/) - { - return g_config()->get(section_, key_, default_); - } - - double CfgGetDouble(const std::string& section_, const std::string& key_, double default_ /*= 0.0*/) - { - return g_config()->get(section_, key_, default_); - } - - std::string CfgGetString(const std::string& section_, const std::string& key_, const char* default_ /*= ""*/) - { - return g_config()->get(section_, key_, default_); - } } diff --git a/ecal/core/src/config/ecal_config_reader.h b/ecal/core/src/config/ecal_config_reader.h index 22c4fed1a5..a08fbea310 100644 --- a/ecal/core/src/config/ecal_config_reader.h +++ b/ecal/core/src/config/ecal_config_reader.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -54,9 +54,4 @@ namespace eCAL private: std::unique_ptr m_impl; }; - - ECAL_API bool CfgGetBool (const std::string& section_, const std::string& key_, bool default_ = false); - ECAL_API int CfgGetInt (const std::string& section_, const std::string& key_, int default_ = 0); - ECAL_API double CfgGetDouble(const std::string& section_, const std::string& key_, double default_ = 0.0); - ECAL_API std::string CfgGetString(const std::string& section_, const std::string& key_, const char* default_ = ""); } diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 0d6c11ecaf..9a9559485a 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -136,7 +136,7 @@ namespace eCAL InitGlobals(); } - g_globals()->SetEcalConfig(config_); + g_ecal_configuration = config_; if (unit_name_ != nullptr) { @@ -146,7 +146,7 @@ namespace eCAL g_globals_ctx_ref_cnt++; // (post)initialize single components - const int success = g_globals()->Initialize(components_, &GetCurrentConfig().command_line_arguments.config_keys); + const int success = g_globals()->Initialize(components_, &GetConfiguration().command_line_arguments.config_keys); if (config_.command_line_arguments.dump_config) { diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index 2710c36a0c..c85f33d416 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -24,6 +24,7 @@ #include "ecal_global_accessors.h" #include "ecal_def.h" #include "ecal_globals.h" +#include "ecal/types/ecal_config_types.h" #include #include @@ -33,6 +34,7 @@ namespace eCAL std::atomic g_globals_ctx_ref_cnt; std::string g_default_ini_file(ECAL_DEFAULT_CFG); + Configuration g_ecal_configuration{}; std::string g_host_name; std::string g_unit_name; @@ -88,12 +90,6 @@ namespace eCAL return g_globals_ctx; } - CConfig* g_config() - { - if (g_globals() == nullptr) return(nullptr); - return(g_globals()->config().get()); - } - CLog* g_log() { if (g_globals() == nullptr) return(nullptr); @@ -102,7 +98,7 @@ namespace eCAL Configuration& g_ecal_config() { - return(g_globals()->ecal_config()); + return(g_ecal_configuration); } #if ECAL_CORE_MONITORING diff --git a/ecal/core/src/ecal_global_accessors.h b/ecal/core/src/ecal_global_accessors.h index 6b84bf241a..a0d3516e1c 100644 --- a/ecal/core/src/ecal_global_accessors.h +++ b/ecal/core/src/ecal_global_accessors.h @@ -31,10 +31,9 @@ // Forward declaration of global accessible classes namespace eCAL { - class CGlobals; - class CConfig; - class CLog; - struct Configuration; + class CGlobals; + class CLog; + struct Configuration; #if ECAL_CORE_MONITORING class CMonitoring; @@ -67,9 +66,7 @@ namespace eCAL // Declaration of getter functions for globally accessible variable instances CGlobals* g_globals(); - CConfig* g_config(); CLog* g_log(); - Configuration& g_ecal_config(); #if ECAL_CORE_MONITORING CMonitoring* g_monitoring(); #endif @@ -102,6 +99,7 @@ namespace eCAL extern std::atomic g_globals_ctx_ref_cnt; extern std::string g_default_ini_file; + extern Configuration g_ecal_configuration; extern std::string g_host_name; extern std::string g_unit_name; diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index 8438597627..088bfc60ec 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -37,7 +37,7 @@ namespace eCAL { - CGlobals::CGlobals() : initialized(false), components(0), ecal_config_instance(0, nullptr) + CGlobals::CGlobals() : initialized(false), components(0) {} CGlobals::~CGlobals() @@ -45,11 +45,6 @@ namespace eCAL Finalize(); } - void CGlobals::SetEcalConfig(Configuration& ecal_config_) - { - ecal_config_instance = ecal_config_; - } - int CGlobals::Initialize(unsigned int components_, std::vector* config_keys_ /*= nullptr*/) { // will be set if any new module was initialized @@ -352,8 +347,6 @@ namespace eCAL memfile_map_instance = nullptr; #endif log_instance = nullptr; - config_instance = nullptr; - initialized = false; return(0); diff --git a/ecal/core/src/ecal_globals.h b/ecal/core/src/ecal_globals.h index 0fa329feae..dc5eaed714 100644 --- a/ecal/core/src/ecal_globals.h +++ b/ecal/core/src/ecal_globals.h @@ -50,7 +50,6 @@ #include "service/ecal_clientgate.h" #endif #include "ecal_descgate.h" -#include "ecal/types/ecal_config_types.h" #include @@ -64,16 +63,12 @@ namespace eCAL int Initialize ( unsigned int components_, std::vector* config_keys_ = nullptr); bool IsInitialized ( unsigned int component_ ); - - void SetEcalConfig(Configuration& ecal_config_); unsigned int GetComponents() const { return(components); }; int Finalize(); - const std::unique_ptr& config() { return config_instance; }; const std::unique_ptr& log() { return log_instance; }; - Configuration& ecal_config() { return ecal_config_instance; }; #if ECAL_CORE_MONITORING const std::unique_ptr& monitoring() { return monitoring_instance; }; @@ -105,7 +100,6 @@ namespace eCAL private: bool initialized; unsigned int components; - std::unique_ptr config_instance; std::unique_ptr log_instance; #if ECAL_CORE_MONITORING std::unique_ptr monitoring_instance; @@ -133,6 +127,5 @@ namespace eCAL #endif std::unique_ptr descgate_instance; - Configuration ecal_config_instance; }; } diff --git a/ecal/core/src/pubsub/ecal_publisher_config.cpp b/ecal/core/src/pubsub/ecal_publisher_config.cpp index 34be0e3361..2449709fd3 100644 --- a/ecal/core/src/pubsub/ecal_publisher_config.cpp +++ b/ecal/core/src/pubsub/ecal_publisher_config.cpp @@ -28,26 +28,9 @@ namespace eCAL { namespace Publisher { - // Configuration::Configuration() : - // share_topic_type(eCAL::Config::IsTopicTypeSharingEnabled()), - // share_topic_description(eCAL::Config::IsTopicDescriptionSharingEnabled()) - // { - // // shm config - // shm.enable = eCAL::Config::GetPublisherShmMode(); - // shm.zero_copy_mode = eCAL::Config::IsMemfileZerocopyEnabled(); - // shm.acknowledge_timeout_ms = eCAL::Config::GetMemfileAckTimeoutMs(); - - // shm.memfile_min_size_bytes = eCAL::Config::GetMemfileMinsizeBytes(); - // shm.memfile_reserve_percent = eCAL::Config::GetMemfileOverprovisioningPercentage(); - // shm.memfile_buffer_count = eCAL::Config::GetMemfileBufferCount(); - - // // udp config - // udp.enable = eCAL::Config::GetPublisherUdpMulticastMode(); - // udp.loopback = false; // TODO: make this configurable - // udp.sndbuf_size_bytes = eCAL::Config::GetUdpMulticastSndBufSizeBytes(); - - // // tcp config - // tcp.enable = eCAL::Config::GetPublisherTcpMode(); - // } + Configuration::Configuration() + { + *this = GetConfiguration().publisher; + } } } diff --git a/ecal/core/src/pubsub/ecal_subscriber_config.cpp b/ecal/core/src/pubsub/ecal_subscriber_config.cpp index 6a12180ea6..967ede6ce1 100644 --- a/ecal/core/src/pubsub/ecal_subscriber_config.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber_config.cpp @@ -28,16 +28,9 @@ namespace eCAL { namespace Subscriber { - // Configuration::Configuration() - // { - // // shm config - // shm.enable = eCAL::Config::IsShmRecEnabled(); - - // // udp config - // udp.enable = eCAL::Config::IsUdpMulticastRecEnabled(); - - // // tcp config - // tcp.enable = eCAL::Config::IsTcpRecEnabled(); - // } + Configuration::Configuration() + { + *this = GetConfiguration().subscriber; + } } } diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index a2d4d357eb..7aee27514a 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -79,7 +79,7 @@ namespace eCAL } }; - CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); + CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher); ~CDataWriter(); bool Stop(); diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 9ee676b947..ece057d464 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -85,32 +85,32 @@ TEST(core_cpp_config, user_config_passing) EXPECT_EQ(0, eCAL::Initialize(custom_config, "User Config Passing Test", eCAL::Init::Default)); // Test boolean assignment, default is false - EXPECT_EQ(network_enabled, eCAL::GetCurrentConfig().transport_layer.network_enabled); + EXPECT_EQ(network_enabled, eCAL::GetConfiguration().transport_layer.network_enabled); // Test IP address assignment, default is 239.0.0.1 - EXPECT_EQ(ip_address, static_cast(eCAL::GetCurrentConfig().transport_layer.mc_options.group)); + EXPECT_EQ(ip_address, static_cast(eCAL::GetConfiguration().transport_layer.mc_options.group)); // Test UDP send buffer assignment, default is 5242880 - EXPECT_EQ(upd_snd_buff, static_cast(eCAL::GetCurrentConfig().transport_layer.mc_options.sndbuf)); + EXPECT_EQ(upd_snd_buff, static_cast(eCAL::GetConfiguration().transport_layer.mc_options.sndbuf)); // Test monitoring timeout assignment, default is 5000U - EXPECT_EQ(mon_timeout, eCAL::GetCurrentConfig().monitoring.monitoring_timeout); + EXPECT_EQ(mon_timeout, eCAL::GetConfiguration().monitoring.monitoring_timeout); // Test monitoring filter exclude assignment, default is "_.*" - EXPECT_EQ(mon_filter_excl, eCAL::GetCurrentConfig().monitoring.filter_excl); + EXPECT_EQ(mon_filter_excl, eCAL::GetConfiguration().monitoring.filter_excl); // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) - EXPECT_EQ(mon_log_filter_con, eCAL::GetCurrentConfig().logging.filter_log_con); + EXPECT_EQ(mon_log_filter_con, eCAL::GetConfiguration().logging.filter_log_con); // Test monitoring mode assignment, default is eCAL::Config::MonitoringMode::none - EXPECT_EQ(monitoring_mode, eCAL::GetCurrentConfig().monitoring.monitoring_mode); + EXPECT_EQ(monitoring_mode, eCAL::GetConfiguration().monitoring.monitoring_mode); // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto - EXPECT_EQ(pub_use_shm, eCAL::GetCurrentConfig().publisher.shm.enable); + EXPECT_EQ(pub_use_shm, eCAL::GetConfiguration().publisher.shm.enable); // Test registration option assignment, default timeout is 60000U and default refresh is 1000U - EXPECT_EQ(registration_timeout, eCAL::GetCurrentConfig().registration.getTimeoutMS()); - EXPECT_EQ(registration_refresh, eCAL::GetCurrentConfig().registration.getRefreshMS()); + EXPECT_EQ(registration_timeout, eCAL::GetConfiguration().registration.getTimeoutMS()); + EXPECT_EQ(registration_refresh, eCAL::GetConfiguration().registration.getRefreshMS()); // Finalize eCAL API EXPECT_EQ(0, eCAL::Finalize()); From 80ef2a008dcc2a65e3ab07360aa1c4fccae00dc0 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 22 May 2024 10:17:10 +0200 Subject: [PATCH 091/105] Restructure eCAL Application Options and default init for publisher/subscriber config. --- ecal/core/include/ecal/ecal_publisher.h | 6 ++-- ecal/core/include/ecal/ecal_subscriber.h | 6 ++-- .../include/ecal/msg/capnproto/publisher.h | 4 +-- .../include/ecal/msg/flatbuffers/publisher.h | 4 +-- .../include/ecal/msg/messagepack/publisher.h | 4 +-- .../ecal/msg/protobuf/dynamic_publisher.h | 2 +- .../include/ecal/msg/protobuf/publisher.h | 4 +-- ecal/core/include/ecal/msg/publisher.h | 6 ++-- ecal/core/include/ecal/msg/string/publisher.h | 4 +-- .../ecal/types/ecal_application_options.h | 28 ++++++++++++------- .../include/ecal/types/ecal_config_types.h | 2 +- ecal/core/src/config/ecal_config.cpp | 4 +-- .../src/config/ecal_config_initializer.cpp | 27 +++++++++++++----- ecal/core/src/readwrite/ecal_writer.h | 2 +- 14 files changed, 62 insertions(+), 41 deletions(-) diff --git a/ecal/core/include/ecal/ecal_publisher.h b/ecal/core/include/ecal/ecal_publisher.h index 0111af48d2..22042e8687 100644 --- a/ecal/core/include/ecal/ecal_publisher.h +++ b/ecal/core/include/ecal/ecal_publisher.h @@ -85,7 +85,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); + ECAL_API CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}); /** * @brief Constructor. @@ -93,7 +93,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); + ECAL_API explicit CPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = {}); /** * @brief Destructor. @@ -129,7 +129,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetCurrentConfig().publisher); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/ecal_subscriber.h b/ecal/core/include/ecal/ecal_subscriber.h index 1f10e002a0..15f9cc3d43 100644 --- a/ecal/core/include/ecal/ecal_subscriber.h +++ b/ecal/core/include/ecal/ecal_subscriber.h @@ -97,7 +97,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); + ECAL_API CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {}); /** * @brief Constructor. @@ -105,7 +105,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param data_type_info_ Topic data type information (encoding, type, descriptor). **/ - ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); + ECAL_API explicit CSubscriber(const std::string& topic_name_, const Subscriber::Configuration& config_ = {}); /** * @brief Destructor. @@ -141,7 +141,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = eCAL::GetConfiguration().subscriber); + ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_ = {}); /** * @brief Creates this object. diff --git a/ecal/core/include/ecal/msg/capnproto/publisher.h b/ecal/core/include/ecal/msg/capnproto/publisher.h index 46b4b718e1..60192fd4ae 100644 --- a/ecal/core/include/ecal/msg/capnproto/publisher.h +++ b/ecal/core/include/ecal/msg/capnproto/publisher.h @@ -101,7 +101,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_) , builder(std::make_unique()) , root_builder(builder->initRoot()) @@ -150,7 +150,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/flatbuffers/publisher.h b/ecal/core/include/ecal/msg/flatbuffers/publisher.h index faf50afa14..8e6cf3a3c5 100644 --- a/ecal/core/include/ecal/msg/flatbuffers/publisher.h +++ b/ecal/core/include/ecal/msg/flatbuffers/publisher.h @@ -53,7 +53,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -85,7 +85,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/messagepack/publisher.h b/ecal/core/include/ecal/msg/messagepack/publisher.h index 5be1676ee3..5d7904c43a 100644 --- a/ecal/core/include/ecal/msg/messagepack/publisher.h +++ b/ecal/core/include/ecal/msg/messagepack/publisher.h @@ -56,7 +56,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -88,7 +88,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h index d79db88468..717ab81fe0 100644 --- a/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/dynamic_publisher.h @@ -62,7 +62,7 @@ namespace eCAL * @param msg_ Protobuf message object. * @param config_ Optional configuration parameters. **/ - CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + CDynamicPublisher(const std::string& topic_name_, const std::shared_ptr& msg_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetTopicInformationFromMessage(msg_.get()), config_) , m_msg{ msg_ } {} diff --git a/ecal/core/include/ecal/msg/protobuf/publisher.h b/ecal/core/include/ecal/msg/protobuf/publisher.h index f316b079a2..b6b79bd869 100644 --- a/ecal/core/include/ecal/msg/protobuf/publisher.h +++ b/ecal/core/include/ecal/msg/protobuf/publisher.h @@ -107,7 +107,7 @@ namespace eCAL // where the vtable is not created yet, or it's destructed. // Probably we can handle the Message publishers differently. One message publisher class and then one class for payloads and getting type // descriptor information. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : eCAL::CPublisher(topic_name_, CPublisher::GetDataTypeInformation(), config_) { } @@ -144,7 +144,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/publisher.h b/ecal/core/include/ecal/msg/publisher.h index 08c25a6043..74e993c6c9 100644 --- a/ecal/core/include/ecal/msg/publisher.h +++ b/ecal/core/include/ecal/msg/publisher.h @@ -63,7 +63,7 @@ namespace eCAL * @param data_type_info_ Topic data type information (encoding, type, descriptor). * @param config_ Optional configuration parameters. **/ - CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CPublisher(topic_name_, data_type_info_, config_) + CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}) : CPublisher(topic_name_, data_type_info_, config_) { } @@ -74,7 +74,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -109,7 +109,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const Publisher::Configuration& config_ = {}) { return(CPublisher::Create(topic_name_, data_type_info_, config_)); } diff --git a/ecal/core/include/ecal/msg/string/publisher.h b/ecal/core/include/ecal/msg/string/publisher.h index 0ea9f36b0d..03cbf886c3 100644 --- a/ecal/core/include/ecal/msg/string/publisher.h +++ b/ecal/core/include/ecal/msg/string/publisher.h @@ -60,7 +60,7 @@ namespace eCAL // call the function via its class because it's a virtual function that is called in constructor/destructor,- // where the vtable is not created yet, or it's destructed. - explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -92,7 +92,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher) + bool Create(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {}) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/types/ecal_application_options.h index b4088a5df8..42ecd79a38 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/types/ecal_application_options.h @@ -25,25 +25,33 @@ #pragma once #include +#include +#include namespace eCAL { - namespace Config + namespace Application { - struct SysOptions + namespace Sys { - std::string filter_excl{}; // mama - }; + struct Configuration + { + std::string filter_excl; // mama + }; + } - struct StartupOptions + namespace Startup { - std::string terminal_emulator{}; - }; + struct Configuration + { + std::string terminal_emulator; + }; + } - struct ApplicationOptions + struct ECAL_API Configuration { - SysOptions sys_options{}; - StartupOptions startup_options{}; + Sys::Configuration sys; + Startup::Configuration startup; }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/types/ecal_config_types.h index 486086a79a..8c3f6acb1b 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/types/ecal_config_types.h @@ -55,7 +55,7 @@ namespace eCAL Publisher::Configuration publisher{}; Config::TimesyncOptions timesync{}; Config::ServiceOptions service{}; - Config::ApplicationOptions application{}; + Application::Configuration application{}; Config::LoggingOptions logging{}; Cli::Configuration command_line_arguments{}; diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index 642acce42c..aa010a99ae 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -133,7 +133,7 @@ namespace eCAL // process ///////////////////////////////////// - ECAL_API std::string GetTerminalEmulatorCommand () { return GetConfiguration().application.startup_options.terminal_emulator; } + ECAL_API std::string GetTerminalEmulatorCommand () { return GetConfiguration().application.startup.terminal_emulator; } ///////////////////////////////////// // monitoring @@ -150,7 +150,7 @@ namespace eCAL // sys ///////////////////////////////////// - ECAL_API std::string GetEcalSysFilterExcludeList () { return GetConfiguration().application.sys_options.filter_excl; } + ECAL_API std::string GetEcalSysFilterExcludeList () { return GetConfiguration().application.sys.filter_excl; } ///////////////////////////////////// // publisher diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 5029caa4d0..9428afcf30 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -170,7 +170,7 @@ namespace eCAL shmMonitoringOptions.shm_monitoring_domain = iniConfig.get(EXPERIMENTAL, "shm_monitoring_domain", EXP_SHM_MONITORING_DOMAIN); shmMonitoringOptions.shm_monitoring_queue_size = iniConfig.get(EXPERIMENTAL, "shm_monitoring_queue_size", EXP_SHM_MONITORING_QUEUE_SIZE); - // receiving options + // subscriber options auto& subscriberOptions = subscriber; subscriberOptions.shm.enable = iniConfig.get(NETWORK, "shm_rec_enabled", NET_SHM_REC_ENABLED) != 0; subscriberOptions.tcp.enable = iniConfig.get(NETWORK, "tcp_rec_enabled", NET_TCP_REC_ENABLED) != 0; @@ -178,9 +178,22 @@ namespace eCAL // publisher options auto& publisherOptions = publisher; - publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; + publisherOptions.shm.enable = iniConfig.get(PUBLISHER, "use_shm", static_cast(PUB_USE_SHM)) != 0; + publisherOptions.shm.zero_copy_mode = iniConfig.get(PUBLISHER, "memfile_zero_copy", PUB_MEMFILE_ZERO_COPY); + publisherOptions.shm.acknowledge_timeout_ms = iniConfig.get(PUBLISHER, "memfile_ack_timeout", PUB_MEMFILE_ACK_TO); + publisherOptions.shm.memfile_min_size_bytes = iniConfig.get(PUBLISHER, "memfile_minsize", PUB_MEMFILE_MINSIZE); + publisherOptions.shm.memfile_reserve_percent = iniConfig.get(PUBLISHER, "memfile_reserve", PUB_MEMFILE_RESERVE); + publisherOptions.shm.memfile_buffer_count = iniConfig.get(PUBLISHER, "memfile_buffer_count", PUB_MEMFILE_BUF_COUNT); + + publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; + // TODO PG: Add here when its available in config file + publisherOptions.udp.loopback = false; + publisherOptions.udp.sndbuf_size_bytes = iniConfig.get(NETWORK, "multicast_sndbuf", NET_UDP_MULTICAST_SNDBUF); + + publisherOptions.share_topic_description = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); + publisherOptions.share_topic_type = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); + publisherOptions.tcp.enable = iniConfig.get(PUBLISHER, "use_tcp", static_cast(PUB_USE_TCP)) != 0; - publisherOptions.udp.enable = iniConfig.get(PUBLISHER, "use_udp_mc", static_cast(PUB_USE_UDP_MC)) != 0; // timesync options auto& timesyncOptions = timesync; @@ -193,12 +206,12 @@ namespace eCAL serviceOptions.protocol_v1 = iniConfig.get(SERVICE, "protocol_v1", SERVICE_PROTOCOL_V1); // sys options - auto& sysOptions = application.sys_options; - sysOptions.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); + auto& sysConfig = application.sys; + sysConfig.filter_excl = iniConfig.get(SYS, "filter_excl", SYS_FILTER_EXCL); // process options - auto& processOptions = application.startup_options; - processOptions.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); + auto& startupConfig = application.startup; + startupConfig.terminal_emulator = iniConfig.get(PROCESS, "terminal_emulator", PROCESS_TERMINAL_EMULATOR); auto& loggingOptions = logging; // needs to be adapted when switching from simpleini diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 7aee27514a..79d8b9ee59 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -79,7 +79,7 @@ namespace eCAL } }; - CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = eCAL::GetConfiguration().publisher); + CDataWriter(const std::string& topic_name_, const SDataTypeInformation& topic_info_, const Publisher::Configuration& config_ = {}); ~CDataWriter(); bool Stop(); From cafb41986c1ef851886c1737999f78668919cd06 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 22 May 2024 11:17:07 +0200 Subject: [PATCH 092/105] Use custom types in publisher config. --- .../ecal/config/ecal_publisher_config.h | 37 ++++++++++--------- .../ecal/config/ecal_subscriber_config.h | 10 ++--- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/ecal/core/include/ecal/config/ecal_publisher_config.h b/ecal/core/include/ecal/config/ecal_publisher_config.h index d4b3a04ad6..c6167a6350 100644 --- a/ecal/core/include/ecal/config/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/ecal_publisher_config.h @@ -89,6 +89,7 @@ #pragma once #include +#include #include @@ -98,46 +99,46 @@ namespace eCAL { namespace SHM { - struct ECAL_API Configuration + struct Configuration { - bool enable; //!< enable layer - bool zero_copy_mode; //!< enable zero copy shared memory transport mode - int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message - the publisher send call is blocked on this event with this timeout (0 == no handshake) */ - size_t memfile_min_size_bytes; //!< default memory file size for new publisher - size_t memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes - size_t memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) + bool enable; //!< enable layer + bool zero_copy_mode; //!< enable zero copy shared memory transport mode + unsigned int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message + the publisher send call is blocked on this event with this timeout (0 == no handshake) */ + Config::ConstrainedInteger<4096, 4096> memfile_min_size_bytes; //!< default memory file size for new publisher + Config::ConstrainedInteger<50, 1, 100> memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes + Config::ConstrainedInteger<1, 1> memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) }; } namespace UDP { - struct ECAL_API Configuration + struct Configuration { - bool enable; //!< enable layer - bool loopback; //!< enable to receive udp messages on the same local machine - int sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) + bool enable; //!< enable layer + bool loopback; //!< enable to receive udp messages on the same local machine + Config::ConstrainedInteger<5242880, 1024> sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) }; } namespace TCP { - struct ECAL_API Configuration + struct Configuration { - bool enable; //!< enable layer + bool enable; //!< enable layer }; } - struct ECAL_API Configuration + struct Configuration { - Configuration(); + ECAL_API Configuration(); SHM::Configuration shm; UDP::Configuration udp; TCP::Configuration tcp; - bool share_topic_type; //!< share topic type via registration - bool share_topic_description; //!< share topic description via registration + bool share_topic_type; //!< share topic type via registration + bool share_topic_description; //!< share topic description via registration }; } } diff --git a/ecal/core/include/ecal/config/ecal_subscriber_config.h b/ecal/core/include/ecal/config/ecal_subscriber_config.h index e885b5382b..d306250d43 100644 --- a/ecal/core/include/ecal/config/ecal_subscriber_config.h +++ b/ecal/core/include/ecal/config/ecal_subscriber_config.h @@ -34,7 +34,7 @@ namespace eCAL { namespace SHM { - struct ECAL_API Configuration + struct Configuration { bool enable; //!< enable layer }; @@ -42,7 +42,7 @@ namespace eCAL namespace UDP { - struct ECAL_API Configuration + struct Configuration { bool enable; //!< enable layer }; @@ -50,15 +50,15 @@ namespace eCAL namespace TCP { - struct ECAL_API Configuration + struct Configuration { bool enable; //!< enable layer }; } - struct ECAL_API Configuration + struct Configuration { - Configuration(); + ECAL_API Configuration(); SHM::Configuration shm; UDP::Configuration udp; From 25116ea8170c140bd4c30b381126cba248302312 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 22 May 2024 13:35:40 +0200 Subject: [PATCH 093/105] Restructered config file structure, config namespaces and and file names. --- .../configuration/runtime_configuration.rst | 2 +- ecal/core/CMakeLists.txt | 2 +- .../ecal_application_config.h} | 4 +- .../ecal_configuration.h} | 36 +++---- .../ecal_logging_config.h} | 8 +- .../ecal_monitoring_config.h} | 54 ++++++----- .../ecal/config/ecal_publisher_config.h | 8 +- .../ecal_registration_config.h} | 12 +-- .../ecal_service_config.h} | 8 +- .../ecal_transport_layer_config.h} | 29 +++--- .../user_arguments.h} | 4 +- ecal/core/include/ecal/ecal.h | 4 +- ecal/core/include/ecal/ecal_config.h | 96 +++++++++---------- ecal/core/include/ecal/ecal_core.h | 2 +- .../ecal/types/ecal_custom_data_types.h | 2 +- .../ecal/types/ecal_publisher_options.h | 40 -------- ecal/core/src/config/ecal_cmd_parser.h | 2 +- ecal/core/src/config/ecal_config.cpp | 4 +- .../src/config/ecal_config_initializer.cpp | 10 +- ecal/core/src/ecal_def.h | 13 +-- ecal/core/src/ecal_global_accessors.cpp | 2 +- .../src/io/udp/ecal_udp_configurations.cpp | 4 +- .../core/src/types/ecal_custom_data_types.cpp | 4 +- .../src/types/ecal_registration_options.cpp | 10 +- .../tests/cpp/config_test/src/config_test.cpp | 18 ++-- 25 files changed, 174 insertions(+), 204 deletions(-) rename ecal/core/include/ecal/{types/ecal_application_options.h => config/ecal_application_config.h} (92%) rename ecal/core/include/ecal/{types/ecal_config_types.h => config/ecal_configuration.h} (69%) rename ecal/core/include/ecal/{types/ecal_logging_options.h => config/ecal_logging_config.h} (88%) rename ecal/core/include/ecal/{types/ecal_monitoring_options.h => config/ecal_monitoring_config.h} (50%) rename ecal/core/include/ecal/{types/ecal_registration_options.h => config/ecal_registration_config.h} (85%) rename ecal/core/include/ecal/{types/ecal_service_options.h => config/ecal_service_config.h} (88%) rename ecal/core/include/ecal/{types/ecal_transport_layer_options.h => config/ecal_transport_layer_config.h} (67%) rename ecal/core/include/ecal/{types/user_arg_options.h => config/user_arguments.h} (93%) delete mode 100644 ecal/core/include/ecal/types/ecal_publisher_options.h diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 5a05eed558..19b75e2415 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -35,7 +35,7 @@ The size object can be used like a normal integer. eCAL::Config::ConstrainedInteger<1024, 512, 8192> size_4mb = 1024 + 6 * 512; std::cout << size_4mb << "\n"; -For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/types/ecal_config_types.h" for the limitations. +For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/config/ecal_configuration.h" for the limitations. Initialization of the configuration =================================== diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 5492549390..d976db47cb 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -478,7 +478,7 @@ set(ecal_header_cmn include/ecal/ecal_tlayer.h include/ecal/ecal_types.h include/ecal/ecal_util.h - include/ecal/types/ecal_config_types.h + include/ecal/config/ecal_configuration.h ) set(ecal_header_cimpl diff --git a/ecal/core/include/ecal/types/ecal_application_options.h b/ecal/core/include/ecal/config/ecal_application_config.h similarity index 92% rename from ecal/core/include/ecal/types/ecal_application_options.h rename to ecal/core/include/ecal/config/ecal_application_config.h index 42ecd79a38..cdf3574d04 100644 --- a/ecal/core/include/ecal/types/ecal_application_options.h +++ b/ecal/core/include/ecal/config/ecal_application_config.h @@ -18,8 +18,8 @@ */ /** - * @file ecal_application_options.h - * @brief eCAL options for configuration of applications + * @file ecal_application_config.h + * @brief eCAL configuration for applications **/ #pragma once diff --git a/ecal/core/include/ecal/types/ecal_config_types.h b/ecal/core/include/ecal/config/ecal_configuration.h similarity index 69% rename from ecal/core/include/ecal/types/ecal_config_types.h rename to ecal/core/include/ecal/config/ecal_configuration.h index 8c3f6acb1b..dbc2f8a9c0 100644 --- a/ecal/core/include/ecal/types/ecal_config_types.h +++ b/ecal/core/include/ecal/config/ecal_configuration.h @@ -18,23 +18,23 @@ */ /** - * @file ecal_config_types.h - * @brief eCAL config interface using structs + * @file ecal_configuration.h + * @brief eCAL configuration interface **/ #pragma once -#include "ecal_application_options.h" -#include "ecal_custom_data_types.h" -#include "ecal_monitoring_options.h" -#include "ecal_publisher_options.h" -#include "ecal_registration_options.h" -#include "ecal_service_options.h" -#include "ecal_logging_options.h" -#include "ecal_transport_layer_options.h" -#include "user_arg_options.h" -#include "ecal/config/ecal_publisher_config.h" -#include "ecal/config/ecal_subscriber_config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "ecal/ecal_os.h" #include "ecal/ecal_log_level.h" @@ -49,14 +49,14 @@ namespace eCAL struct Configuration { TransportLayer::Configuration transport_layer{}; - Config::RegistrationOptions registration{}; - Config::MonitoringOptions monitoring{}; + Registration::Configuration registration{}; + Monitoring::Configuration monitoring{}; Subscriber::Configuration subscriber{}; Publisher::Configuration publisher{}; - Config::TimesyncOptions timesync{}; - Config::ServiceOptions service{}; + Service::TimesyncOptions timesync{}; + Service::Configuration service{}; Application::Configuration application{}; - Config::LoggingOptions logging{}; + Logging::Configuration logging{}; Cli::Configuration command_line_arguments{}; ECAL_API Configuration(); diff --git a/ecal/core/include/ecal/types/ecal_logging_options.h b/ecal/core/include/ecal/config/ecal_logging_config.h similarity index 88% rename from ecal/core/include/ecal/types/ecal_logging_options.h rename to ecal/core/include/ecal/config/ecal_logging_config.h index e48c9a70a3..8555abe5ca 100644 --- a/ecal/core/include/ecal/types/ecal_logging_options.h +++ b/ecal/core/include/ecal/config/ecal_logging_config.h @@ -18,8 +18,8 @@ */ /** - * @file ecal_logging_options.h - * @brief eCAL options for logging configuration + * @file ecal_logging_config.h + * @brief eCAL configuration for logging **/ #pragma once @@ -28,9 +28,9 @@ namespace eCAL { - namespace Config + namespace Logging { - struct LoggingOptions + struct Configuration { eCAL_Logging_Filter filter_log_con{}; eCAL_Logging_Filter filter_log_file{}; diff --git a/ecal/core/include/ecal/types/ecal_monitoring_options.h b/ecal/core/include/ecal/config/ecal_monitoring_config.h similarity index 50% rename from ecal/core/include/ecal/types/ecal_monitoring_options.h rename to ecal/core/include/ecal/config/ecal_monitoring_config.h index 9b196c6b14..88382a5bb4 100644 --- a/ecal/core/include/ecal/types/ecal_monitoring_options.h +++ b/ecal/core/include/ecal/config/ecal_monitoring_config.h @@ -18,45 +18,53 @@ */ /** - * @file ecal_monitoring_options.h - * @brief eCAL options for monitoring configuration + * @file ecal_monitoring_config.h + * @brief eCAL configuration for monitoring **/ #pragma once -#include "ecal_custom_data_types.h" +#include namespace eCAL { - namespace Config + namespace Monitoring { - enum MonitoringMode + namespace Types { - none = 0, - udp_monitoring = 1 << 0, - shm_monitoring = 1 << 1 - }; + enum Mode + { + none = 0, + udp_monitoring = 1 << 0, + shm_monitoring = 1 << 1 + }; - using eCAL_MonitoringMode_Filter = char; + using Mode_Filter = char; + } - struct UDPMonitoringOptions + namespace UDP { - // Here? - }; + struct Configuration + { + }; + } - struct SHMMonitoringOptions + namespace SHM { - std::string shm_monitoring_domain{}; - size_t shm_monitoring_queue_size{}; - }; + struct Configuration + { + std::string shm_monitoring_domain{}; + size_t shm_monitoring_queue_size{}; + }; + } - struct MonitoringOptions + struct Configuration { - eCAL_MonitoringMode_Filter monitoring_mode{}; - ConstrainedInteger<1000, 1000> monitoring_timeout{}; - bool network_monitoring{}; - UDPMonitoringOptions udp_options{}; - SHMMonitoringOptions shm_options{}; + Types::Mode_Filter monitoring_mode{}; + eCAL::Types::ConstrainedInteger<1000, 1000> monitoring_timeout{}; + bool network_monitoring{}; + UDP::Configuration udp_options{}; + SHM::Configuration shm_options{}; std::string filter_excl{}; std::string filter_incl{}; diff --git a/ecal/core/include/ecal/config/ecal_publisher_config.h b/ecal/core/include/ecal/config/ecal_publisher_config.h index c6167a6350..7f5363d6ff 100644 --- a/ecal/core/include/ecal/config/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/ecal_publisher_config.h @@ -105,9 +105,9 @@ namespace eCAL bool zero_copy_mode; //!< enable zero copy shared memory transport mode unsigned int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message the publisher send call is blocked on this event with this timeout (0 == no handshake) */ - Config::ConstrainedInteger<4096, 4096> memfile_min_size_bytes; //!< default memory file size for new publisher - Config::ConstrainedInteger<50, 1, 100> memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes - Config::ConstrainedInteger<1, 1> memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) + Types::ConstrainedInteger<4096, 4096> memfile_min_size_bytes; //!< default memory file size for new publisher + Types::ConstrainedInteger<50, 1, 100> memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes + Types::ConstrainedInteger<1, 1> memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) }; } @@ -117,7 +117,7 @@ namespace eCAL { bool enable; //!< enable layer bool loopback; //!< enable to receive udp messages on the same local machine - Config::ConstrainedInteger<5242880, 1024> sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) + Types::ConstrainedInteger<5242880, 1024> sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) }; } diff --git a/ecal/core/include/ecal/types/ecal_registration_options.h b/ecal/core/include/ecal/config/ecal_registration_config.h similarity index 85% rename from ecal/core/include/ecal/types/ecal_registration_options.h rename to ecal/core/include/ecal/config/ecal_registration_config.h index 131fff26bb..777eeb3370 100644 --- a/ecal/core/include/ecal/types/ecal_registration_options.h +++ b/ecal/core/include/ecal/config/ecal_registration_config.h @@ -18,8 +18,8 @@ */ /** - * @file ecal_registration_options.h - * @brief eCAL options for configuration of the registration layer + * @file ecal_registration_config.h + * @brief eCAL configuration for the registration layer **/ #pragma once @@ -31,7 +31,7 @@ namespace eCAL { - namespace Config + namespace Registration { /** * @brief Struct for storing RegistrationOptions. @@ -44,11 +44,11 @@ namespace eCAL * * @throws std::invalid_argument exception. **/ - struct RegistrationOptions + struct Configuration { public: - ECAL_API RegistrationOptions(); - ECAL_API RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_); + ECAL_API Configuration(); + ECAL_API Configuration(unsigned int reg_timeout_, unsigned int reg_refresh_); ECAL_API unsigned int getTimeoutMS() const; ECAL_API unsigned int getRefreshMS() const; diff --git a/ecal/core/include/ecal/types/ecal_service_options.h b/ecal/core/include/ecal/config/ecal_service_config.h similarity index 88% rename from ecal/core/include/ecal/types/ecal_service_options.h rename to ecal/core/include/ecal/config/ecal_service_config.h index 802eecc17a..a77abc0f0b 100644 --- a/ecal/core/include/ecal/types/ecal_service_options.h +++ b/ecal/core/include/ecal/config/ecal_service_config.h @@ -18,8 +18,8 @@ */ /** - * @file ecal_service_options.h - * @brief eCAL options for configuration of services + * @file ecal_service_config.h + * @brief eCAL configuration for services **/ #pragma once @@ -28,9 +28,9 @@ namespace eCAL { - namespace Config + namespace Service { - struct ServiceOptions + struct Configuration { bool protocol_v0{}; bool protocol_v1{}; diff --git a/ecal/core/include/ecal/types/ecal_transport_layer_options.h b/ecal/core/include/ecal/config/ecal_transport_layer_config.h similarity index 67% rename from ecal/core/include/ecal/types/ecal_transport_layer_options.h rename to ecal/core/include/ecal/config/ecal_transport_layer_config.h index 72cc2b9d65..9261812bb0 100644 --- a/ecal/core/include/ecal/types/ecal_transport_layer_options.h +++ b/ecal/core/include/ecal/config/ecal_transport_layer_config.h @@ -18,13 +18,14 @@ */ /** - * @file ecal_transport_layer_options.h - * @brief eCAL options for configuration of the transport layer + * @file ecal_transport_layer_config.h + * @brief eCAL configuration for the transport layer **/ +// TODO PG: Deprecated? #pragma once -#include "ecal_custom_data_types.h" +#include namespace eCAL { @@ -40,25 +41,25 @@ namespace eCAL struct SHMOptions { std::string host_group_name{}; - Config::ConstrainedInteger<4096, 4096> memfile_minsize{}; - Config::ConstrainedInteger<50, 1, 100> memfile_reserve{}; + Types::ConstrainedInteger<4096, 4096> memfile_minsize{}; + Types::ConstrainedInteger<50, 1, 100> memfile_reserve{}; int memfile_ack_timeout{}; - Config::ConstrainedInteger<0, 1> memfile_buffer_count{}; + Types::ConstrainedInteger<0, 1> memfile_buffer_count{}; bool drop_out_of_order_messages{}; bool memfile_zero_copy{}; }; struct UdpMulticastOptions { - Config::UdpConfigVersion config_version{}; - Config::IpAddressV4 group{}; - Config::IpAddressV4 mask{}; - Config::ConstrainedInteger<14000, 10> port{}; - unsigned int ttl{}; + Types::UdpConfigVersion config_version{}; + Types::IpAddressV4 group{}; + Types::IpAddressV4 mask{}; + Types::ConstrainedInteger<14000, 10> port{}; + unsigned int ttl{}; // TODO PG: are these minimum limits correct? - Config::ConstrainedInteger<5242880, 1024> sndbuf{}; - Config::ConstrainedInteger<5242880, 1024> recbuf{}; - bool join_all_interfaces{}; + Types::ConstrainedInteger<5242880, 1024> sndbuf{}; + Types::ConstrainedInteger<5242880, 1024> recbuf{}; + bool join_all_interfaces{}; int bandwidth_max_udp{}; bool npcap_enabled{}; diff --git a/ecal/core/include/ecal/types/user_arg_options.h b/ecal/core/include/ecal/config/user_arguments.h similarity index 93% rename from ecal/core/include/ecal/types/user_arg_options.h rename to ecal/core/include/ecal/config/user_arguments.h index 591f847f15..d2ce561374 100644 --- a/ecal/core/include/ecal/types/user_arg_options.h +++ b/ecal/core/include/ecal/config/user_arguments.h @@ -18,8 +18,8 @@ */ /** - * @file user_arg_options.h - * @brief Options specified by the user via command line + * @file user_arguments.h + * @brief Arguments given by the user via command line **/ #pragma once diff --git a/ecal/core/include/ecal/ecal.h b/ecal/core/include/ecal/ecal.h index d341077808..813dfa4ee2 100644 --- a/ecal/core/include/ecal/ecal.h +++ b/ecal/core/include/ecal/ecal.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -42,4 +42,4 @@ #include #include #include -#include +#include diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index d86f7ee3ca..003f93dc30 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -23,7 +23,7 @@ #include #include #include -#include "ecal/types/ecal_config_types.h" +#include "ecal/config/ecal_configuration.h" #include @@ -38,100 +38,100 @@ namespace eCAL // common ///////////////////////////////////// - ECAL_API std::string GetLoadedEcalIniPath (); - ECAL_API int GetRegistrationTimeoutMs (); - ECAL_API int GetRegistrationRefreshMs (); + ECAL_API std::string GetLoadedEcalIniPath (); + ECAL_API int GetRegistrationTimeoutMs (); + ECAL_API int GetRegistrationRefreshMs (); ///////////////////////////////////// // network ///////////////////////////////////// - ECAL_API bool IsNetworkEnabled (); - ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion (); - ECAL_API std::string GetUdpMulticastGroup (); - ECAL_API std::string GetUdpMulticastMask (); - ECAL_API int GetUdpMulticastPort (); - ECAL_API int GetUdpMulticastTtl (); + ECAL_API bool IsNetworkEnabled (); + ECAL_API Types::UdpConfigVersion GetUdpMulticastConfigVersion (); + ECAL_API std::string GetUdpMulticastGroup (); + ECAL_API std::string GetUdpMulticastMask (); + ECAL_API int GetUdpMulticastPort (); + ECAL_API int GetUdpMulticastTtl (); - ECAL_API int GetUdpMulticastSndBufSizeBytes (); - ECAL_API int GetUdpMulticastRcvBufSizeBytes (); + ECAL_API int GetUdpMulticastSndBufSizeBytes (); + ECAL_API int GetUdpMulticastRcvBufSizeBytes (); - ECAL_API bool IsUdpMulticastJoinAllIfEnabled (); + ECAL_API bool IsUdpMulticastJoinAllIfEnabled (); - ECAL_API bool IsUdpMulticastRecEnabled (); - ECAL_API bool IsShmRecEnabled (); - ECAL_API bool IsTcpRecEnabled (); + ECAL_API bool IsUdpMulticastRecEnabled (); + ECAL_API bool IsShmRecEnabled (); + ECAL_API bool IsTcpRecEnabled (); - ECAL_API bool IsNpcapEnabled (); + ECAL_API bool IsNpcapEnabled (); - ECAL_API int GetTcpPubsubReaderThreadpoolSize (); - ECAL_API int GetTcpPubsubWriterThreadpoolSize (); - ECAL_API int GetTcpPubsubMaxReconnectionAttemps (); + ECAL_API int GetTcpPubsubReaderThreadpoolSize (); + ECAL_API int GetTcpPubsubWriterThreadpoolSize (); + ECAL_API int GetTcpPubsubMaxReconnectionAttemps (); - ECAL_API std::string GetHostGroupName (); + ECAL_API std::string GetHostGroupName (); ///////////////////////////////////// // time ///////////////////////////////////// - ECAL_API std::string GetTimesyncModuleName (); - ECAL_API std::string GetTimesyncModuleReplay (); + ECAL_API std::string GetTimesyncModuleName (); + ECAL_API std::string GetTimesyncModuleReplay (); ///////////////////////////////////// // process ///////////////////////////////////// - ECAL_API std::string GetTerminalEmulatorCommand (); + ECAL_API std::string GetTerminalEmulatorCommand (); ///////////////////////////////////// // monitoring ///////////////////////////////////// - ECAL_API int GetMonitoringTimeoutMs (); - ECAL_API std::string GetMonitoringFilterExcludeList (); - ECAL_API std::string GetMonitoringFilterIncludeList (); - ECAL_API eCAL_Logging_Filter GetConsoleLogFilter (); - ECAL_API eCAL_Logging_Filter GetFileLogFilter (); - ECAL_API eCAL_Logging_Filter GetUdpLogFilter (); + ECAL_API int GetMonitoringTimeoutMs (); + ECAL_API std::string GetMonitoringFilterExcludeList (); + ECAL_API std::string GetMonitoringFilterIncludeList (); + ECAL_API eCAL_Logging_Filter GetConsoleLogFilter (); + ECAL_API eCAL_Logging_Filter GetFileLogFilter (); + ECAL_API eCAL_Logging_Filter GetUdpLogFilter (); ///////////////////////////////////// // sys ///////////////////////////////////// - ECAL_API std::string GetEcalSysFilterExcludeList (); + ECAL_API std::string GetEcalSysFilterExcludeList (); ///////////////////////////////////// // publisher ///////////////////////////////////// - ECAL_API bool GetPublisherShmMode (); - ECAL_API bool GetPublisherTcpMode (); - ECAL_API bool GetPublisherUdpMulticastMode (); + ECAL_API bool GetPublisherShmMode (); + ECAL_API bool GetPublisherTcpMode (); + ECAL_API bool GetPublisherUdpMulticastMode (); - ECAL_API size_t GetMemfileMinsizeBytes (); - ECAL_API size_t GetMemfileOverprovisioningPercentage (); - ECAL_API int GetMemfileAckTimeoutMs (); - ECAL_API bool IsMemfileZerocopyEnabled (); - ECAL_API size_t GetMemfileBufferCount (); + ECAL_API size_t GetMemfileMinsizeBytes (); + ECAL_API size_t GetMemfileOverprovisioningPercentage (); + ECAL_API int GetMemfileAckTimeoutMs (); + ECAL_API bool IsMemfileZerocopyEnabled (); + ECAL_API size_t GetMemfileBufferCount (); - ECAL_API bool IsTopicTypeSharingEnabled (); - ECAL_API bool IsTopicDescriptionSharingEnabled (); + ECAL_API bool IsTopicTypeSharingEnabled (); + ECAL_API bool IsTopicDescriptionSharingEnabled (); ///////////////////////////////////// // service ///////////////////////////////////// - ECAL_API bool IsServiceProtocolV0Enabled (); - ECAL_API bool IsServiceProtocolV1Enabled (); + ECAL_API bool IsServiceProtocolV0Enabled (); + ECAL_API bool IsServiceProtocolV1Enabled (); ///////////////////////////////////// // experimental ///////////////////////////////////// namespace Experimental { - ECAL_API bool IsShmMonitoringEnabled (); - ECAL_API bool IsNetworkMonitoringDisabled (); - ECAL_API size_t GetShmMonitoringQueueSize (); - ECAL_API std::string GetShmMonitoringDomain (); - ECAL_API bool GetDropOutOfOrderMessages (); + ECAL_API bool IsShmMonitoringEnabled (); + ECAL_API bool IsNetworkMonitoringDisabled (); + ECAL_API size_t GetShmMonitoringQueueSize (); + ECAL_API std::string GetShmMonitoringDomain (); + ECAL_API bool GetDropOutOfOrderMessages (); } } } diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index 743e5d82a1..f8c714b03e 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -31,7 +31,7 @@ #include #include -#include +#include namespace eCAL { diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index bf7ffb0d57..671ceb9b73 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -33,7 +33,7 @@ namespace eCAL { - namespace Config + namespace Types { /** * @brief Class for evaluation and storing an IPv4/IPv6 address. diff --git a/ecal/core/include/ecal/types/ecal_publisher_options.h b/ecal/core/include/ecal/types/ecal_publisher_options.h deleted file mode 100644 index 9d3a24f86d..0000000000 --- a/ecal/core/include/ecal/types/ecal_publisher_options.h +++ /dev/null @@ -1,40 +0,0 @@ -/* =========================== LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * =========================== LICENSE ================================= - */ - -/** - * @file ecal_publisher_options.h - * @brief eCAL options for configuration of the publisher -**/ - -#pragma once - -#include - -namespace eCAL -{ - namespace Config - { - struct PublisherOptions - { - TLayer::eSendMode use_shm{}; - TLayer::eSendMode use_tcp{}; - TLayer::eSendMode use_udp_mc{}; - }; - } -} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index e723083b8c..ee4fc87dee 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -23,7 +23,7 @@ #pragma once -#include "ecal/types/user_arg_options.h" +#include #include #include diff --git a/ecal/core/src/config/ecal_config.cpp b/ecal/core/src/config/ecal_config.cpp index aa010a99ae..14f23cf803 100644 --- a/ecal/core/src/config/ecal_config.cpp +++ b/ecal/core/src/config/ecal_config.cpp @@ -99,7 +99,7 @@ namespace eCAL ECAL_API bool IsNetworkEnabled () { return GetConfiguration().transport_layer.network_enabled; } - ECAL_API UdpConfigVersion GetUdpMulticastConfigVersion () { return GetConfiguration().transport_layer.mc_options.config_version; } + ECAL_API Types::UdpConfigVersion GetUdpMulticastConfigVersion () { return GetConfiguration().transport_layer.mc_options.config_version; } ECAL_API std::string GetUdpMulticastGroup () { return GetConfiguration().transport_layer.mc_options.group; } ECAL_API std::string GetUdpMulticastMask () { return GetConfiguration().transport_layer.mc_options.mask; } @@ -181,7 +181,7 @@ namespace eCAL namespace Experimental { - ECAL_API bool IsShmMonitoringEnabled () { return (GetConfiguration().monitoring.monitoring_mode & MonitoringMode::shm_monitoring) != 0; } + ECAL_API bool IsShmMonitoringEnabled () { return (GetConfiguration().monitoring.monitoring_mode & Monitoring::Types::Mode::shm_monitoring) != 0; } ECAL_API bool IsNetworkMonitoringDisabled () { return !GetConfiguration().monitoring.network_monitoring; } ECAL_API size_t GetShmMonitoringQueueSize () { return GetConfiguration().monitoring.shm_options.shm_monitoring_queue_size; } ECAL_API std::string GetShmMonitoringDomain () { return GetConfiguration().monitoring.shm_options.shm_monitoring_domain;} diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 9428afcf30..12235fac44 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -118,9 +118,9 @@ namespace eCAL const std::string udp_config_version_string = iniConfig.get(NETWORK, "multicast_config_version", "v1"); if (udp_config_version_string == "v1") - multicastOptions.config_version = Config::UdpConfigVersion::V1; + multicastOptions.config_version = Types::UdpConfigVersion::V1; if (udp_config_version_string == "v2") - multicastOptions.config_version = Config::UdpConfigVersion::V2; + multicastOptions.config_version = Types::UdpConfigVersion::V2; multicastOptions.group = iniConfig.get(NETWORK, "multicast_group", NET_UDP_MULTICAST_GROUP); multicastOptions.mask = iniConfig.get(NETWORK, "multicast_mask", NET_UDP_MULTICAST_MASK); @@ -149,15 +149,15 @@ namespace eCAL // registration options auto registrationTimeout = iniConfig.get(COMMON, "registration_timeout", CMN_REGISTRATION_TO); auto registrationRefresh = iniConfig.get(COMMON, "registration_refresh", CMN_REGISTRATION_REFRESH); - registration = Config::RegistrationOptions(registrationTimeout, registrationRefresh); + registration = Registration::Configuration(registrationTimeout, registrationRefresh); auto& registrationOptions = registration; registrationOptions.share_tdesc = iniConfig.get(PUBLISHER, "share_tdesc", PUB_SHARE_TDESC); registrationOptions.share_ttype = iniConfig.get(PUBLISHER, "share_ttype", PUB_SHARE_TTYPE); // monitoring options auto& monitoringOptions = monitoring; - auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? Config::MonitoringMode::shm_monitoring : Config::MonitoringMode::none; - monitoringOptions.monitoring_mode = static_cast(monitoringMode); + auto monitoringMode = iniConfig.get(EXPERIMENTAL, "shm_monitoring_enabled", false) ? Monitoring::Types::Mode::shm_monitoring : Monitoring::Types::Mode::none; + monitoringOptions.monitoring_mode = static_cast(monitoringMode); monitoringOptions.monitoring_timeout = iniConfig.get(MONITORING, "timeout", MON_TIMEOUT);; monitoringOptions.network_monitoring = iniConfig.get(EXPERIMENTAL, "network_monitoring", EXP_NETWORK_MONITORING_ENABLED); monitoringOptions.filter_excl = iniConfig.get(MONITORING, "filter_excl", MON_FILTER_EXCL); diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 606996f2c1..1af986b6a3 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -23,7 +23,8 @@ #pragma once -#include +#include +#include #include #include @@ -68,7 +69,7 @@ constexpr const char* SYS_FILTER_EXCL = "^eCALSysClient$|^eCALSysGUI$|^eCALS constexpr bool NET_ENABLED = false; /* eCAL udp multicast defines */ -constexpr eCAL::Config::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = eCAL::Config::UdpConfigVersion::V1; +constexpr eCAL::Types::UdpConfigVersion NET_UDP_MULTICAST_CONFIG_VERSION = eCAL::Types::UdpConfigVersion::V1; constexpr const char* NET_UDP_MULTICAST_GROUP = "239.0.0.1"; constexpr const char* NET_UDP_MULTICAST_MASK = "0.0.0.15"; constexpr unsigned int NET_UDP_MULTICAST_PORT = 14000U; @@ -106,9 +107,9 @@ constexpr const char* NET_HOST_GROUP_NAME = ""; /* use shared memory transport layer [auto = 2, on = 1, off = 0] */ constexpr eCAL::TLayer::eSendMode PUB_USE_SHM = eCAL::TLayer::eSendMode::smode_auto; /* use tcp transport layer [auto = 2, on = 1, off = 0] */ -constexpr eCAL::TLayer::eSendMode PUB_USE_TCP = eCAL::TLayer::eSendMode::smode_off; +constexpr eCAL::TLayer::eSendMode PUB_USE_TCP = eCAL::TLayer::eSendMode::smode_off; /* use udp multicast transport layer [auto = 2, on = 1, off = 0] */ -constexpr eCAL::TLayer::eSendMode PUB_USE_UDP_MC = eCAL::TLayer::eSendMode::smode_auto; +constexpr eCAL::TLayer::eSendMode PUB_USE_UDP_MC = eCAL::TLayer::eSendMode::smode_auto; /* share topic type [ on = 1, off = 0] */ constexpr bool PUB_SHARE_TTYPE = true; @@ -200,4 +201,4 @@ constexpr unsigned int EXP_MEMFILE_ACCESS_TIMEOUT = 100U; /* enable dropping of payload messages that arrive out of order */ constexpr bool EXP_DROP_OUT_OF_ORDER_MESSAGES = false; -constexpr eCAL::Config::MonitoringMode EXP_MONITORING_MODE = eCAL::Config::MonitoringMode::none; +constexpr eCAL::Monitoring::Types::Mode EXP_MONITORING_MODE = eCAL::Monitoring::Types::Mode::none; diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index c85f33d416..dd2c8f0a48 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -24,7 +24,7 @@ #include "ecal_global_accessors.h" #include "ecal_def.h" #include "ecal_globals.h" -#include "ecal/types/ecal_config_types.h" +#include "ecal/config/ecal_configuration.h" #include #include diff --git a/ecal/core/src/io/udp/ecal_udp_configurations.cpp b/ecal/core/src/io/udp/ecal_udp_configurations.cpp index 589da3874b..d3e81cf46a 100644 --- a/ecal/core/src/io/udp/ecal_udp_configurations.cpp +++ b/ecal/core/src/io/udp/ecal_udp_configurations.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -140,7 +140,7 @@ namespace eCAL } // determine the UDP multicast configuration version - if (Config::GetUdpMulticastConfigVersion() == Config::UdpConfigVersion::V1) + if (Config::GetUdpMulticastConfigVersion() == Types::UdpConfigVersion::V1) { // retrieve the corresponding multicast address based on the topic name using v1 implementation return UDP::V1::topic2mcast(topic_name, Config::GetUdpMulticastGroup(), Config::GetUdpMulticastMask()); diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index ae462fae6b..af9e778b64 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * 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. @@ -40,7 +40,7 @@ namespace{ namespace eCAL { - namespace Config + namespace Types { // IpAddressV4 definitions diff --git a/ecal/core/src/types/ecal_registration_options.cpp b/ecal/core/src/types/ecal_registration_options.cpp index b3ddec7b1b..9a47d2a4ac 100644 --- a/ecal/core/src/types/ecal_registration_options.cpp +++ b/ecal/core/src/types/ecal_registration_options.cpp @@ -26,16 +26,16 @@ namespace eCAL { - namespace Config + namespace Registration { - RegistrationOptions::RegistrationOptions() + Configuration::Configuration() : share_ttype(PUB_SHARE_TTYPE) , share_tdesc(PUB_SHARE_TDESC) , m_registration_timeout(CMN_REGISTRATION_TO) , m_registration_refresh(CMN_REGISTRATION_REFRESH) {} - RegistrationOptions::RegistrationOptions(unsigned int reg_timeout_, unsigned int reg_refresh_) + Configuration::Configuration(unsigned int reg_timeout_, unsigned int reg_refresh_) : share_ttype(PUB_SHARE_TTYPE) , share_tdesc(PUB_SHARE_TDESC) { @@ -50,7 +50,7 @@ namespace eCAL } } - unsigned int RegistrationOptions::getTimeoutMS() const { return m_registration_timeout; } - unsigned int RegistrationOptions::getRefreshMS() const { return m_registration_refresh; } + unsigned int Configuration::getTimeoutMS() const { return m_registration_timeout; } + unsigned int Configuration::getRefreshMS() const { return m_registration_refresh; } } } \ No newline at end of file diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index ece057d464..7733689831 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -52,7 +52,7 @@ TEST(core_cpp_config, user_config_passing) const unsigned int mon_timeout = 6000U; const std::string mon_filter_excl = "_A.*"; const eCAL_Logging_Filter mon_log_filter_con = log_level_warning; - const eCAL::Config::eCAL_MonitoringMode_Filter monitoring_mode = eCAL::Config::MonitoringMode::udp_monitoring; + const eCAL::Monitoring::Types::Mode monitoring_mode = eCAL::Monitoring::Types::Mode::udp_monitoring; // Publisher options const bool pub_use_shm = true; @@ -60,7 +60,7 @@ TEST(core_cpp_config, user_config_passing) // Registration options const unsigned int registration_timeout = 80000U; const unsigned int registration_refresh = 2000U; - const eCAL::Config::RegistrationOptions registration = eCAL::Config::RegistrationOptions(registration_timeout, registration_refresh); + const eCAL::Registration::Configuration registration = eCAL::Registration::Configuration(registration_timeout, registration_refresh); try{ custom_config.transport_layer.network_enabled = network_enabled; @@ -102,7 +102,7 @@ TEST(core_cpp_config, user_config_passing) // Test monitoring console log assignment, default is (log_level_info | log_level_warning | log_level_error | log_level_fatal) EXPECT_EQ(mon_log_filter_con, eCAL::GetConfiguration().logging.filter_log_con); - // Test monitoring mode assignment, default is eCAL::Config::MonitoringMode::none + // Test monitoring mode assignment, default is eCAL::Types::MonitoringMode::none EXPECT_EQ(monitoring_mode, eCAL::GetConfiguration().monitoring.monitoring_mode); // Test publisher sendmode assignment, default is eCAL::TLayer::eSendMode::smode_auto @@ -181,26 +181,26 @@ TEST(ConfigDeathTest, user_config_death_test) // Test the registration option limits // Refresh timeout > registration timeout ASSERT_THROW( - eCAL::Config::RegistrationOptions(2000U, 3000U), std::invalid_argument); + eCAL::Registration::Configuration(2000U, 3000U), std::invalid_argument); // Refresh timeout = registration timeout ASSERT_THROW( - eCAL::Config::RegistrationOptions(2000U, 2000U), std::invalid_argument); + eCAL::Registration::Configuration(2000U, 2000U), std::invalid_argument); } TEST(core_cpp_config, config_custom_datatypes_tests) { // test custom datatype assignment operators - eCAL::Config::IpAddressV4 ip1; - eCAL::Config::IpAddressV4 ip2; + eCAL::Types::IpAddressV4 ip1; + eCAL::Types::IpAddressV4 ip2; EXPECT_EQ(static_cast(ip1), static_cast(ip2)); ip1 = "192.168.0.2"; ip2 = ip1; EXPECT_EQ(static_cast(ip1), static_cast(ip2)); - eCAL::Config::ConstrainedInteger<0,1,10> s1; - eCAL::Config::ConstrainedInteger<0,1,10> s2; + eCAL::Types::ConstrainedInteger<0,1,10> s1; + eCAL::Types::ConstrainedInteger<0,1,10> s2; EXPECT_EQ(static_cast(s1), static_cast(s2)); s1 = 5; From f7b8470a8ac094c0df2a99aedee797fe8d28fd8f Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 22 May 2024 16:30:49 +0200 Subject: [PATCH 094/105] Added comments to config structs from ini file. --- .../ecal/config/ecal_application_config.h | 10 ++--- .../include/ecal/config/ecal_logging_config.h | 7 +-- .../ecal/config/ecal_monitoring_config.h | 14 +++--- .../ecal/config/ecal_publisher_config.h | 14 +++--- .../ecal/config/ecal_registration_config.h | 8 ++-- .../include/ecal/config/ecal_service_config.h | 14 ++++-- .../ecal/config/ecal_transport_layer_config.h | 44 +++++++++---------- .../core/include/ecal/config/user_arguments.h | 11 +++-- .../src/types/ecal_registration_options.cpp | 2 +- 9 files changed, 65 insertions(+), 59 deletions(-) diff --git a/ecal/core/include/ecal/config/ecal_application_config.h b/ecal/core/include/ecal/config/ecal_application_config.h index cdf3574d04..e08367a24a 100644 --- a/ecal/core/include/ecal/config/ecal_application_config.h +++ b/ecal/core/include/ecal/config/ecal_application_config.h @@ -36,7 +36,7 @@ namespace eCAL { struct Configuration { - std::string filter_excl; // mama + std::string filter_excl; //!< }; } @@ -44,14 +44,14 @@ namespace eCAL { struct Configuration { - std::string terminal_emulator; + std::string terminal_emulator; //!< }; } - struct ECAL_API Configuration + struct Configuration { - Sys::Configuration sys; - Startup::Configuration startup; + Sys::Configuration sys; //!< + Startup::Configuration startup; //!< }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/config/ecal_logging_config.h b/ecal/core/include/ecal/config/ecal_logging_config.h index 8555abe5ca..bb1ae9ef45 100644 --- a/ecal/core/include/ecal/config/ecal_logging_config.h +++ b/ecal/core/include/ecal/config/ecal_logging_config.h @@ -32,9 +32,10 @@ namespace eCAL { struct Configuration { - eCAL_Logging_Filter filter_log_con{}; - eCAL_Logging_Filter filter_log_file{}; - eCAL_Logging_Filter filter_log_udp{}; + eCAL_Logging_Filter filter_log_con{}; /*!< Log messages logged to console (all, info, warning, error, fatal, debug1, debug2, debug3, debug4) + (Default: info, warning, error, fatal)*/ + eCAL_Logging_Filter filter_log_file{}; //!< Log messages to logged into file system (Default: "") + eCAL_Logging_Filter filter_log_udp{}; //!< Log messages logged via udp network (Default: info, warning, error, fatal) }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/config/ecal_monitoring_config.h b/ecal/core/include/ecal/config/ecal_monitoring_config.h index 88382a5bb4..2c116202ff 100644 --- a/ecal/core/include/ecal/config/ecal_monitoring_config.h +++ b/ecal/core/include/ecal/config/ecal_monitoring_config.h @@ -53,21 +53,21 @@ namespace eCAL { struct Configuration { - std::string shm_monitoring_domain{}; - size_t shm_monitoring_queue_size{}; + std::string shm_monitoring_domain{}; //!< Domain name for shared memory based monitoring/registration (Default: ecal_mon) + size_t shm_monitoring_queue_size{}; //!< Queue size of monitoring/registration events (Default: 1024) }; } struct Configuration { - Types::Mode_Filter monitoring_mode{}; - eCAL::Types::ConstrainedInteger<1000, 1000> monitoring_timeout{}; - bool network_monitoring{}; + Types::Mode_Filter monitoring_mode{}; //!< Specify which monitoring is enabled (Default: none) + eCAL::Types::ConstrainedInteger<1000, 1000> monitoring_timeout{}; //!< Timeout for topic monitoring in ms (Default: 5000) + bool network_monitoring{}; //!< Enable distribution of monitoring/registration information via network (Default: true) UDP::Configuration udp_options{}; SHM::Configuration shm_options{}; - std::string filter_excl{}; - std::string filter_incl{}; + std::string filter_excl{}; //!< Topics blacklist as regular expression (will not be monitored) (Default: "__.*") + std::string filter_incl{}; //!< Topics whitelist as regular expression (will be monitored only) (Default: "") }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/config/ecal_publisher_config.h b/ecal/core/include/ecal/config/ecal_publisher_config.h index 7f5363d6ff..c921c0d9cb 100644 --- a/ecal/core/include/ecal/config/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/ecal_publisher_config.h @@ -101,13 +101,13 @@ namespace eCAL { struct Configuration { - bool enable; //!< enable layer - bool zero_copy_mode; //!< enable zero copy shared memory transport mode - unsigned int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message + bool enable; //!< enable layer + bool zero_copy_mode; //!< enable zero copy shared memory transport mode + unsigned int acknowledge_timeout_ms; /*!< force connected subscribers to send acknowledge event after processing the message the publisher send call is blocked on this event with this timeout (0 == no handshake) */ - Types::ConstrainedInteger<4096, 4096> memfile_min_size_bytes; //!< default memory file size for new publisher - Types::ConstrainedInteger<50, 1, 100> memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes - Types::ConstrainedInteger<1, 1> memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) + Types::ConstrainedInteger<4096, 4096> memfile_min_size_bytes; //!< default memory file size for new publisher + Types::ConstrainedInteger<50, 1, 100> memfile_reserve_percent; //!< dynamic file size reserve before recreating memory file if topic size changes + Types::ConstrainedInteger<1, 1> memfile_buffer_count; //!< maximum number of used buffers (needs to be greater than 1, default = 1) }; } @@ -117,7 +117,7 @@ namespace eCAL { bool enable; //!< enable layer bool loopback; //!< enable to receive udp messages on the same local machine - Types::ConstrainedInteger<5242880, 1024> sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) + Types::ConstrainedInteger<5242880, 1024> sndbuf_size_bytes; //!< udp send buffer size in bytes (default 5MB) }; } diff --git a/ecal/core/include/ecal/config/ecal_registration_config.h b/ecal/core/include/ecal/config/ecal_registration_config.h index 777eeb3370..46c88f5b0d 100644 --- a/ecal/core/include/ecal/config/ecal_registration_config.h +++ b/ecal/core/include/ecal/config/ecal_registration_config.h @@ -50,11 +50,11 @@ namespace eCAL ECAL_API Configuration(); ECAL_API Configuration(unsigned int reg_timeout_, unsigned int reg_refresh_); - ECAL_API unsigned int getTimeoutMS() const; - ECAL_API unsigned int getRefreshMS() const; + ECAL_API unsigned int getTimeoutMS() const; //!< Timeout for topic registration in ms (internal) (Default: 60000) + ECAL_API unsigned int getRefreshMS() const; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000) - bool share_ttype; - bool share_tdesc; + bool share_ttype; //!< Share topic type via registration layer (Default: true) + bool share_tdesc; //!< Share topic description via registration layer (switch off to disable reflection) (Default: true) private: unsigned int m_registration_timeout; diff --git a/ecal/core/include/ecal/config/ecal_service_config.h b/ecal/core/include/ecal/config/ecal_service_config.h index a77abc0f0b..fe79a1d9bf 100644 --- a/ecal/core/include/ecal/config/ecal_service_config.h +++ b/ecal/core/include/ecal/config/ecal_service_config.h @@ -32,14 +32,20 @@ namespace eCAL { struct Configuration { - bool protocol_v0{}; - bool protocol_v1{}; + bool protocol_v0{}; //!< Support service protocol v0, eCAL 5.11 and older (Default: true) + bool protocol_v1{}; //!< Support service protocol v1, eCAL 5.12 and newer (Default: true) }; struct TimesyncOptions { - std::string timesync_module_rt{}; - std::string timesync_module_replay{}; + std::string timesync_module_rt{}; /*!< Time synchronisation interface name (dynamic library) + The name will be extended with platform suffix (32|64), debug suffix (d) and platform extension (.dll|.so) + Available modules are: + - ecaltime-localtime local system time without synchronization + - ecaltime-linuxptp For PTP / gPTP synchronization over ethernet on Linux + (device configuration in ecaltime.ini) + (Default: ecaltime-localtime)*/ + std::string timesync_module_replay{}; //!< (Default: "") }; } } \ No newline at end of file diff --git a/ecal/core/include/ecal/config/ecal_transport_layer_config.h b/ecal/core/include/ecal/config/ecal_transport_layer_config.h index 9261812bb0..32f5d61686 100644 --- a/ecal/core/include/ecal/config/ecal_transport_layer_config.h +++ b/ecal/core/include/ecal/config/ecal_transport_layer_config.h @@ -33,42 +33,42 @@ namespace eCAL { struct TCPubsubOptions { - size_t num_executor_reader{}; - size_t num_executor_writer{}; - size_t max_reconnections{}; + size_t num_executor_reader{}; //!< + size_t num_executor_writer{}; //!< + size_t max_reconnections{}; //!< }; struct SHMOptions { - std::string host_group_name{}; - Types::ConstrainedInteger<4096, 4096> memfile_minsize{}; - Types::ConstrainedInteger<50, 1, 100> memfile_reserve{}; - int memfile_ack_timeout{}; - Types::ConstrainedInteger<0, 1> memfile_buffer_count{}; - bool drop_out_of_order_messages{}; - bool memfile_zero_copy{}; + std::string host_group_name{}; //!< + Types::ConstrainedInteger<4096, 4096> memfile_minsize{}; //!< + Types::ConstrainedInteger<50, 1, 100> memfile_reserve{}; //!< + int memfile_ack_timeout{}; //!< + Types::ConstrainedInteger<0, 1> memfile_buffer_count{}; //!< + bool drop_out_of_order_messages{}; //!< + bool memfile_zero_copy{}; //!< }; struct UdpMulticastOptions { - Types::UdpConfigVersion config_version{}; - Types::IpAddressV4 group{}; - Types::IpAddressV4 mask{}; - Types::ConstrainedInteger<14000, 10> port{}; - unsigned int ttl{}; + Types::UdpConfigVersion config_version{}; //!< + Types::IpAddressV4 group{}; //!< + Types::IpAddressV4 mask{}; //!< + Types::ConstrainedInteger<14000, 10> port{}; //!< + unsigned int ttl{}; // TODO PG: are these minimum limits correct? - Types::ConstrainedInteger<5242880, 1024> sndbuf{}; - Types::ConstrainedInteger<5242880, 1024> recbuf{}; - bool join_all_interfaces{}; + Types::ConstrainedInteger<5242880, 1024> sndbuf{}; //!< + Types::ConstrainedInteger<5242880, 1024> recbuf{}; //!< + bool join_all_interfaces{}; //!< - int bandwidth_max_udp{}; - bool npcap_enabled{}; + int bandwidth_max_udp{}; //!< + bool npcap_enabled{}; //!< }; struct Configuration { - bool network_enabled{}; - bool drop_out_of_order_messages{}; + bool network_enabled{}; //!< + bool drop_out_of_order_messages{}; //!< UdpMulticastOptions mc_options{}; TCPubsubOptions tcp_options{}; SHMOptions shm_options{}; diff --git a/ecal/core/include/ecal/config/user_arguments.h b/ecal/core/include/ecal/config/user_arguments.h index d2ce561374..6f64cdf16a 100644 --- a/ecal/core/include/ecal/config/user_arguments.h +++ b/ecal/core/include/ecal/config/user_arguments.h @@ -32,15 +32,14 @@ namespace eCAL { namespace Cli { - // Map[Section][Option] = Value - using ConfigKey2DMap = std::map>; + using ConfigKey2DMap = std::map>; //!< Config key storage: Map[Section][Option] = Value struct Configuration { - std::vector config_keys{}; - ConfigKey2DMap config_keys_map; - std::string specified_config{}; - bool dump_config{}; + std::vector config_keys{}; //!< will be deprecated soon + ConfigKey2DMap config_keys_map; //!< The config keys given via command line and the --config-keys parameter (Default: empty) + std::string specified_config{}; //!< The used eCAL ini file (Default: "") + bool dump_config{}; //!< If specified, output configuration via standart output (Default: false) }; } } \ No newline at end of file diff --git a/ecal/core/src/types/ecal_registration_options.cpp b/ecal/core/src/types/ecal_registration_options.cpp index 9a47d2a4ac..69fbb1c06a 100644 --- a/ecal/core/src/types/ecal_registration_options.cpp +++ b/ecal/core/src/types/ecal_registration_options.cpp @@ -21,7 +21,7 @@ * @brief Definition of custom data types. **/ -#include "ecal/types/ecal_registration_options.h" +#include #include "ecal_def.h" namespace eCAL From f6f3dd5d92f770ab58a2b38af539f299ef288de4 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 23 May 2024 12:11:20 +0200 Subject: [PATCH 095/105] Some file renaming. --- ecal/core/CMakeLists.txt | 6 +-- ...cal_application_config.h => application.h} | 0 .../{ecal_configuration.h => configuration.h} | 19 ++++----- .../ecal/config/ecal_transport_layer_config.h | 2 +- .../{ecal_logging_config.h => logging.h} | 0 ...{ecal_monitoring_config.h => monitoring.h} | 0 .../{ecal_publisher_config.h => publisher.h} | 2 +- ...l_registration_config.h => registration.h} | 0 ecal/core/include/ecal/config/service.h | 39 +++++++++++++++++++ ...{ecal_subscriber_config.h => subscriber.h} | 0 .../config/{ecal_service_config.h => time.h} | 26 ++++++------- ecal/core/include/ecal/ecal.h | 2 +- ecal/core/include/ecal/ecal_config.h | 2 +- ecal/core/include/ecal/ecal_core.h | 2 +- ecal/core/include/ecal/ecal_publisher.h | 2 +- ecal/core/src/ecal_def.h | 2 +- ecal/core/src/ecal_global_accessors.cpp | 2 +- .../core/src/pubsub/ecal_publisher_config.cpp | 2 +- .../src/pubsub/ecal_subscriber_config.cpp | 2 +- ecal/core/src/readwrite/ecal_writer.h | 2 +- ecal/core/src/readwrite/shm/ecal_writer_shm.h | 2 +- ecal/core/src/readwrite/tcp/ecal_writer_tcp.h | 2 +- ecal/core/src/readwrite/udp/ecal_writer_udp.h | 2 +- .../src/types/ecal_registration_options.cpp | 2 +- 24 files changed, 78 insertions(+), 42 deletions(-) rename ecal/core/include/ecal/config/{ecal_application_config.h => application.h} (100%) rename ecal/core/include/ecal/config/{ecal_configuration.h => configuration.h} (84%) rename ecal/core/include/ecal/config/{ecal_logging_config.h => logging.h} (100%) rename ecal/core/include/ecal/config/{ecal_monitoring_config.h => monitoring.h} (100%) rename ecal/core/include/ecal/config/{ecal_publisher_config.h => publisher.h} (99%) rename ecal/core/include/ecal/config/{ecal_registration_config.h => registration.h} (100%) create mode 100644 ecal/core/include/ecal/config/service.h rename ecal/core/include/ecal/config/{ecal_subscriber_config.h => subscriber.h} (100%) rename ecal/core/include/ecal/config/{ecal_service_config.h => time.h} (75%) diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index d976db47cb..699efdd52c 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -454,8 +454,8 @@ endif() set(ecal_header_cmn include/ecal/types/logging.h include/ecal/types/monitoring.h - include/ecal/config/ecal_publisher_config.h - include/ecal/config/ecal_subscriber_config.h + include/ecal/config/publisher.h + include/ecal/config/subscriber.h include/ecal/ecal.h include/ecal/ecal_callback.h include/ecal/ecal_client.h @@ -478,7 +478,7 @@ set(ecal_header_cmn include/ecal/ecal_tlayer.h include/ecal/ecal_types.h include/ecal/ecal_util.h - include/ecal/config/ecal_configuration.h + include/ecal/config/configuration.h ) set(ecal_header_cimpl diff --git a/ecal/core/include/ecal/config/ecal_application_config.h b/ecal/core/include/ecal/config/application.h similarity index 100% rename from ecal/core/include/ecal/config/ecal_application_config.h rename to ecal/core/include/ecal/config/application.h diff --git a/ecal/core/include/ecal/config/ecal_configuration.h b/ecal/core/include/ecal/config/configuration.h similarity index 84% rename from ecal/core/include/ecal/config/ecal_configuration.h rename to ecal/core/include/ecal/config/configuration.h index dbc2f8a9c0..30758642f0 100644 --- a/ecal/core/include/ecal/config/ecal_configuration.h +++ b/ecal/core/include/ecal/config/configuration.h @@ -18,21 +18,22 @@ */ /** - * @file ecal_configuration.h + * @file configuration.h * @brief eCAL configuration interface **/ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include +#include +#include #include @@ -53,7 +54,7 @@ namespace eCAL Monitoring::Configuration monitoring{}; Subscriber::Configuration subscriber{}; Publisher::Configuration publisher{}; - Service::TimesyncOptions timesync{}; + Time::Configuration timesync{}; Service::Configuration service{}; Application::Configuration application{}; Logging::Configuration logging{}; diff --git a/ecal/core/include/ecal/config/ecal_transport_layer_config.h b/ecal/core/include/ecal/config/ecal_transport_layer_config.h index 32f5d61686..1c3f30d384 100644 --- a/ecal/core/include/ecal/config/ecal_transport_layer_config.h +++ b/ecal/core/include/ecal/config/ecal_transport_layer_config.h @@ -22,7 +22,7 @@ * @brief eCAL configuration for the transport layer **/ -// TODO PG: Deprecated? +// TODO PG: Deprecated when configuration is implemented in all modules? #pragma once #include diff --git a/ecal/core/include/ecal/config/ecal_logging_config.h b/ecal/core/include/ecal/config/logging.h similarity index 100% rename from ecal/core/include/ecal/config/ecal_logging_config.h rename to ecal/core/include/ecal/config/logging.h diff --git a/ecal/core/include/ecal/config/ecal_monitoring_config.h b/ecal/core/include/ecal/config/monitoring.h similarity index 100% rename from ecal/core/include/ecal/config/ecal_monitoring_config.h rename to ecal/core/include/ecal/config/monitoring.h diff --git a/ecal/core/include/ecal/config/ecal_publisher_config.h b/ecal/core/include/ecal/config/publisher.h similarity index 99% rename from ecal/core/include/ecal/config/ecal_publisher_config.h rename to ecal/core/include/ecal/config/publisher.h index c921c0d9cb..1af155c9b3 100644 --- a/ecal/core/include/ecal/config/ecal_publisher_config.h +++ b/ecal/core/include/ecal/config/publisher.h @@ -18,7 +18,7 @@ */ /** - * @file ecal_publisher_config.h + * @file publisher.h * @brief eCAL publisher configuration * * This publisher configuration struct can be used to define the behavior of an eCAL publisher. Additional information on diff --git a/ecal/core/include/ecal/config/ecal_registration_config.h b/ecal/core/include/ecal/config/registration.h similarity index 100% rename from ecal/core/include/ecal/config/ecal_registration_config.h rename to ecal/core/include/ecal/config/registration.h diff --git a/ecal/core/include/ecal/config/service.h b/ecal/core/include/ecal/config/service.h new file mode 100644 index 0000000000..74f4b54291 --- /dev/null +++ b/ecal/core/include/ecal/config/service.h @@ -0,0 +1,39 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file ecal_service_config.h + * @brief eCAL configuration for services +**/ + +#pragma once + +#include + +namespace eCAL +{ + namespace Service + { + struct Configuration + { + bool protocol_v0{}; //!< Support service protocol v0, eCAL 5.11 and older (Default: true) + bool protocol_v1{}; //!< Support service protocol v1, eCAL 5.12 and newer (Default: true) + }; + } +} \ No newline at end of file diff --git a/ecal/core/include/ecal/config/ecal_subscriber_config.h b/ecal/core/include/ecal/config/subscriber.h similarity index 100% rename from ecal/core/include/ecal/config/ecal_subscriber_config.h rename to ecal/core/include/ecal/config/subscriber.h diff --git a/ecal/core/include/ecal/config/ecal_service_config.h b/ecal/core/include/ecal/config/time.h similarity index 75% rename from ecal/core/include/ecal/config/ecal_service_config.h rename to ecal/core/include/ecal/config/time.h index fe79a1d9bf..dbe62028c3 100644 --- a/ecal/core/include/ecal/config/ecal_service_config.h +++ b/ecal/core/include/ecal/config/time.h @@ -1,25 +1,25 @@ -/* =========================== LICENSE ================================= +/* ========================= 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. * - * =========================== LICENSE ================================= - */ + * ========================= eCAL LICENSE ================================= +*/ /** - * @file ecal_service_config.h - * @brief eCAL configuration for services + * @file time.h + * @brief eCAL time configuration **/ #pragma once @@ -28,15 +28,9 @@ namespace eCAL { - namespace Service + namespace Time { struct Configuration - { - bool protocol_v0{}; //!< Support service protocol v0, eCAL 5.11 and older (Default: true) - bool protocol_v1{}; //!< Support service protocol v1, eCAL 5.12 and newer (Default: true) - }; - - struct TimesyncOptions { std::string timesync_module_rt{}; /*!< Time synchronisation interface name (dynamic library) The name will be extended with platform suffix (32|64), debug suffix (d) and platform extension (.dll|.so) @@ -48,4 +42,6 @@ namespace eCAL std::string timesync_module_replay{}; //!< (Default: "") }; } -} \ No newline at end of file +} + + diff --git a/ecal/core/include/ecal/ecal.h b/ecal/core/include/ecal/ecal.h index 813dfa4ee2..0bfbc13886 100644 --- a/ecal/core/include/ecal/ecal.h +++ b/ecal/core/include/ecal/ecal.h @@ -42,4 +42,4 @@ #include #include #include -#include +#include diff --git a/ecal/core/include/ecal/ecal_config.h b/ecal/core/include/ecal/ecal_config.h index 003f93dc30..570d01e579 100644 --- a/ecal/core/include/ecal/ecal_config.h +++ b/ecal/core/include/ecal/ecal_config.h @@ -23,7 +23,7 @@ #include #include #include -#include "ecal/config/ecal_configuration.h" +#include "ecal/config/configuration.h" #include diff --git a/ecal/core/include/ecal/ecal_core.h b/ecal/core/include/ecal/ecal_core.h index f8c714b03e..a725191b75 100644 --- a/ecal/core/include/ecal/ecal_core.h +++ b/ecal/core/include/ecal/ecal_core.h @@ -31,7 +31,7 @@ #include #include -#include +#include namespace eCAL { diff --git a/ecal/core/include/ecal/ecal_publisher.h b/ecal/core/include/ecal/ecal_publisher.h index 22042e8687..08dcaa7bff 100644 --- a/ecal/core/include/ecal/ecal_publisher.h +++ b/ecal/core/include/ecal/ecal_publisher.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/ecal/core/src/ecal_def.h b/ecal/core/src/ecal_def.h index 1af986b6a3..a9c6789d0a 100644 --- a/ecal/core/src/ecal_def.h +++ b/ecal/core/src/ecal_def.h @@ -23,7 +23,7 @@ #pragma once -#include +#include #include #include #include diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index dd2c8f0a48..eea548714e 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -24,7 +24,7 @@ #include "ecal_global_accessors.h" #include "ecal_def.h" #include "ecal_globals.h" -#include "ecal/config/ecal_configuration.h" +#include "ecal/config/configuration.h" #include #include diff --git a/ecal/core/src/pubsub/ecal_publisher_config.cpp b/ecal/core/src/pubsub/ecal_publisher_config.cpp index 2449709fd3..ede5ddddd9 100644 --- a/ecal/core/src/pubsub/ecal_publisher_config.cpp +++ b/ecal/core/src/pubsub/ecal_publisher_config.cpp @@ -22,7 +22,7 @@ **/ #include -#include +#include namespace eCAL { diff --git a/ecal/core/src/pubsub/ecal_subscriber_config.cpp b/ecal/core/src/pubsub/ecal_subscriber_config.cpp index 967ede6ce1..1ecdea261f 100644 --- a/ecal/core/src/pubsub/ecal_subscriber_config.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber_config.cpp @@ -22,7 +22,7 @@ **/ #include -#include +#include namespace eCAL { diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 79d8b9ee59..bc6919c08f 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/ecal/core/src/readwrite/shm/ecal_writer_shm.h b/ecal/core/src/readwrite/shm/ecal_writer_shm.h index b76acda891..fd6dff0d93 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 #include "readwrite/ecal_writer_base.h" #include "io/shm/ecal_memfile_sync.h" diff --git a/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h b/ecal/core/src/readwrite/tcp/ecal_writer_tcp.h index 0b12aa40d9..94a3e96fe7 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 #include "readwrite/ecal_writer_base.h" diff --git a/ecal/core/src/readwrite/udp/ecal_writer_udp.h b/ecal/core/src/readwrite/udp/ecal_writer_udp.h index dc5846eddf..32a7ef78b1 100644 --- a/ecal/core/src/readwrite/udp/ecal_writer_udp.h +++ b/ecal/core/src/readwrite/udp/ecal_writer_udp.h @@ -23,7 +23,7 @@ #pragma once -#include +#include #include "io/udp/ecal_udp_sample_sender.h" #include "readwrite/ecal_writer_base.h" diff --git a/ecal/core/src/types/ecal_registration_options.cpp b/ecal/core/src/types/ecal_registration_options.cpp index 69fbb1c06a..2454ca1d69 100644 --- a/ecal/core/src/types/ecal_registration_options.cpp +++ b/ecal/core/src/types/ecal_registration_options.cpp @@ -21,7 +21,7 @@ * @brief Definition of custom data types. **/ -#include +#include #include "ecal_def.h" namespace eCAL From 913fee0a62544914bd5e02867a6a2d4b9213a7ec Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Thu, 23 May 2024 12:35:12 +0200 Subject: [PATCH 096/105] Updated docu for config. --- doc/rst/configuration/runtime_configuration.rst | 6 +++--- doc/rst/configuration/src/hello_config/main.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 19b75e2415..58c4950bdf 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -22,7 +22,7 @@ The ip address can be used like a normal string object. For example: .. code-block:: c++ - eCAL::Config::IpAddressV4 ip_address = std::string("192.168.7.1"); // in hex: "C0.A8.7.1" + eCAL::Types::IpAddressV4 ip_address = std::string("192.168.7.1"); // in hex: "C0.A8.7.1" std::cout << ip_address << "\n"; ConstrainedInteger are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. @@ -32,10 +32,10 @@ The size object can be used like a normal integer. .. code-block:: c++ - eCAL::Config::ConstrainedInteger<1024, 512, 8192> size_4mb = 1024 + 6 * 512; + eCAL::Types::ConstrainedInteger<1024, 512, 8192> size_4mb = 1024 + 6 * 512; std::cout << size_4mb << "\n"; -For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/config/ecal_configuration.h" for the limitations. +For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/config/configuration.h" for the limitations. Initialization of the configuration =================================== diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 17b3d37af5..17befa109b 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char** argv) { // Create a configuration object with the command line arguments - eCAL::Config::eCALConfig custom_config(argc, argv); + eCAL::Configuration custom_config(argc, argv); // Use the .ini file of the system ... custom_config.InitConfigWithDefaultIni(); @@ -40,4 +40,6 @@ int main(int argc, char** argv) // Finalize eCAL API eCAL::Finalize(); + + return 0; } \ No newline at end of file From fd80badaa0aa95e74d14773cb1730c2a64bbd048 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 24 May 2024 08:34:24 +0200 Subject: [PATCH 097/105] Changes for transportlayer config. --- ecal/core/include/ecal/config/configuration.h | 2 +- .../ecal/config/ecal_transport_layer_config.h | 77 --------------- .../include/ecal/config/transport_layer.h | 94 +++++++++++++++++++ .../src/config/ecal_config_initializer.cpp | 1 - 4 files changed, 95 insertions(+), 79 deletions(-) delete mode 100644 ecal/core/include/ecal/config/ecal_transport_layer_config.h create mode 100644 ecal/core/include/ecal/config/transport_layer.h diff --git a/ecal/core/include/ecal/config/configuration.h b/ecal/core/include/ecal/config/configuration.h index 30758642f0..785b61dbf2 100644 --- a/ecal/core/include/ecal/config/configuration.h +++ b/ecal/core/include/ecal/config/configuration.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ecal/core/include/ecal/config/ecal_transport_layer_config.h b/ecal/core/include/ecal/config/ecal_transport_layer_config.h deleted file mode 100644 index 1c3f30d384..0000000000 --- a/ecal/core/include/ecal/config/ecal_transport_layer_config.h +++ /dev/null @@ -1,77 +0,0 @@ -/* =========================== LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * =========================== LICENSE ================================= - */ - -/** - * @file ecal_transport_layer_config.h - * @brief eCAL configuration for the transport layer -**/ - -// TODO PG: Deprecated when configuration is implemented in all modules? -#pragma once - -#include - -namespace eCAL -{ - namespace TransportLayer - { - struct TCPubsubOptions - { - size_t num_executor_reader{}; //!< - size_t num_executor_writer{}; //!< - size_t max_reconnections{}; //!< - }; - - struct SHMOptions - { - std::string host_group_name{}; //!< - Types::ConstrainedInteger<4096, 4096> memfile_minsize{}; //!< - Types::ConstrainedInteger<50, 1, 100> memfile_reserve{}; //!< - int memfile_ack_timeout{}; //!< - Types::ConstrainedInteger<0, 1> memfile_buffer_count{}; //!< - bool drop_out_of_order_messages{}; //!< - bool memfile_zero_copy{}; //!< - }; - - struct UdpMulticastOptions - { - Types::UdpConfigVersion config_version{}; //!< - Types::IpAddressV4 group{}; //!< - Types::IpAddressV4 mask{}; //!< - Types::ConstrainedInteger<14000, 10> port{}; //!< - unsigned int ttl{}; - // TODO PG: are these minimum limits correct? - Types::ConstrainedInteger<5242880, 1024> sndbuf{}; //!< - Types::ConstrainedInteger<5242880, 1024> recbuf{}; //!< - bool join_all_interfaces{}; //!< - - int bandwidth_max_udp{}; //!< - bool npcap_enabled{}; //!< - }; - - struct Configuration - { - bool network_enabled{}; //!< - bool drop_out_of_order_messages{}; //!< - UdpMulticastOptions mc_options{}; - TCPubsubOptions tcp_options{}; - SHMOptions shm_options{}; - }; - } -} \ No newline at end of file diff --git a/ecal/core/include/ecal/config/transport_layer.h b/ecal/core/include/ecal/config/transport_layer.h new file mode 100644 index 0000000000..41aa5ad5ae --- /dev/null +++ b/ecal/core/include/ecal/config/transport_layer.h @@ -0,0 +1,94 @@ +/* =========================== LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * =========================== LICENSE ================================= + */ + +/** + * @file transport_layer.h + * @brief eCAL configuration for the transport layer +**/ + +// TODO PG: Deprecated when configuration is implemented in all modules? +#pragma once + +#include + +namespace eCAL +{ + namespace TransportLayer + { + namespace TCPPubSub + { + struct Configuration + { + size_t num_executor_reader{}; //!< Tcp_pubsub reader amount of threads that shall execute workload (Default: 4) + size_t num_executor_writer{}; //!< Tcp_pubsub writer amount of threads that shall execute workload (Default: 4) + size_t max_reconnections{}; //!< Tcp_pubsub reconnection attemps the session will try to reconnect in (Default: 5) + }; + } + + namespace SHM + { + struct Configuration + { + std::string host_group_name{}; /*!< Common host group name that enables interprocess mechanisms across + (virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: "")*/ + Types::ConstrainedInteger<4096, 4096> memfile_minsize{}; //!< Default memory file size for new publisher (Default: 4096) + Types::ConstrainedInteger<50, 1, 100> memfile_reserve{}; //!< Dynamic file size reserve before recreating memory file if topic size changes in % (Default: 50) + unsigned int memfile_ack_timeout{}; //!< Publisher timeout for ack event from subscriber that memory file content is processed (Default: 0) + Types::ConstrainedInteger<0, 1> memfile_buffer_count{}; //!< Number of parallel used memory file buffers for 1:n publish/subscribe ipc connections (Default = 1) + bool drop_out_of_order_messages{}; //!< (Default: ) + bool memfile_zero_copy{}; //!< Allow matching subscriber to access memory file without copying its content in advance (Default: false) + }; + } + + namespace UDPMC + { + struct Configuration + { + Types::UdpConfigVersion config_version{}; /*!< UDP configuration version (Since eCAL 5.12.) + v1: default behavior + v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v1) */ + Types::IpAddressV4 group{}; //!< UDP multicast group base (Default: 239.0.0.1) + Types::IpAddressV4 mask{}; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255) + v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/ + Types::ConstrainedInteger<14000, 10> port{}; /*!< UDP multicast port number (eCAL will use at least the 2 following port + numbers too, so modify in steps of 10 (e.g. 1010, 1020 ...)(Default: 14000) */ + unsigned int ttl{}; /*!< UDP ttl value, also known as hop limit, is used in determining + the intermediate routers being traversed towards the destination(Default: 2) */ + // TODO PG: are these minimum limits correct? + Types::ConstrainedInteger<5242880, 1024> sndbuf{}; //!< UDP send buffer in bytes (Default: 5242880) + Types::ConstrainedInteger<5242880, 1024> recbuf{}; //!< UDP receive buffer in bytes (Default: 5242880) + bool join_all_interfaces{}; /*!< Linux specific setting to enable joining multicast groups on all network interfacs + independent of their link state. Enabling this makes sure that eCAL processes + receive data if they are started before network devices are up and running. (Default: false)*/ + + bool npcap_enabled{}; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false) + }; + } + + struct Configuration + { + bool network_enabled{}; /*!< true = all eCAL components communicate over network boundaries + false = local host only communication (Default: false) */ + bool drop_out_of_order_messages{}; //!< Enable dropping of payload messages that arrive out of order (Default: false) + UDPMC::Configuration mc_options{}; + TCPPubSub::Configuration tcp_options{}; + SHM::Configuration shm_options{}; + }; + } +} \ No newline at end of file diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index 12235fac44..ba79c6bf10 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -129,7 +129,6 @@ namespace eCAL multicastOptions.recbuf = iniConfig.get(NETWORK, "multicast_rcvbuf", NET_UDP_MULTICAST_RCVBUF); multicastOptions.sndbuf = iniConfig.get(NETWORK, "multicast_sndbuf", NET_UDP_MULTICAST_SNDBUF); multicastOptions.join_all_interfaces = iniConfig.get(NETWORK, "multicast_join_all_if", NET_UDP_MULTICAST_JOIN_ALL_IF_ENABLED); - multicastOptions.bandwidth_max_udp = iniConfig.get(NETWORK, "bandwidth_max_udp", NET_BANDWIDTH_MAX_UDP); multicastOptions.npcap_enabled = iniConfig.get(NETWORK, "npcap_enabled", NET_NPCAP_ENABLED); auto& tcpPubSubOptions = transportLayerOptions.tcp_options; From e126b12f4ca58b7aba07e2c09a0e3bade7f97723 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 24 May 2024 09:43:27 +0200 Subject: [PATCH 098/105] Try taking .ini file in normal initializing, as it was before. --- ecal/core/src/ecal.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ecal/core/src/ecal.cpp b/ecal/core/src/ecal.cpp index 9a9559485a..03c2e1a434 100644 --- a/ecal/core/src/ecal.cpp +++ b/ecal/core/src/ecal.cpp @@ -101,6 +101,10 @@ namespace eCAL int Initialize(int argc_ , char **argv_, const char *unit_name_, unsigned int components_) { eCAL::Configuration config(argc_, argv_); + + // Default behaviour: If not specified, try to use the default ini file + if (config.GetIniFilePath().empty()) + config.InitConfigWithDefaultIni(); return Initialize(config, unit_name_, components_); } @@ -117,6 +121,11 @@ namespace eCAL int Initialize(std::vector args_, const char *unit_name_, unsigned int components_) //-V826 { eCAL::Configuration config(args_); + + // Default behaviour: If not specified, try to use the default ini file + if (config.GetIniFilePath().empty()) + config.InitConfigWithDefaultIni(); + return Initialize(config, unit_name_, components_); } From 25dd3e0fb1ef598ee6da1c491d5d474ac4ed3cef Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 24 May 2024 11:06:42 +0200 Subject: [PATCH 099/105] Added doc for publisher config. --- .../configuration/runtime_configuration.rst | 28 ++++++++---- .../configuration/src/hello_config/main.cpp | 9 ++-- .../src/publisher_config/CMakeLists.txt | 19 ++++++++ .../src/publisher_config/main.cpp | 44 +++++++++++++++++++ 4 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 doc/rst/configuration/src/publisher_config/CMakeLists.txt create mode 100644 doc/rst/configuration/src/publisher_config/main.cpp diff --git a/doc/rst/configuration/runtime_configuration.rst b/doc/rst/configuration/runtime_configuration.rst index 58c4950bdf..5c62120e76 100644 --- a/doc/rst/configuration/runtime_configuration.rst +++ b/doc/rst/configuration/runtime_configuration.rst @@ -12,20 +12,20 @@ The corresponding structure reflects the configuration file (:ref:`configuration Custom types ============ -In order to exclude configuration errors, custom datatypes for IP addresses and sizes (constrained integer) are introduced. +In order to rule out configuration errors, custom datatypes for IP addresses (IpAddressV4) and sizes (constrained integer) are introduced. -For assigning an ip address simply assign a string with the desired address. +**IpAddressV4:** For assigning an IP address simply assign a string with the desired address. Decimal and hexadecimal format is supported. -In case the ip address is not valid, the type will throw a std::invalid_argument exception. +In case the IP address is not valid, the type will throw a std::invalid_argument exception. -The ip address can be used like a normal string object. For example: +The IP address can be used like a normal string object. For example: .. code-block:: c++ eCAL::Types::IpAddressV4 ip_address = std::string("192.168.7.1"); // in hex: "C0.A8.7.1" std::cout << ip_address << "\n"; -ConstrainedInteger are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. +**ConstrainedInteger**: ConstrainedInteger are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value. In case the assigned value does not fit into the specified limitation, the type will throw a std::invalid_argument exception. The size object can be used like a normal integer. @@ -37,16 +37,16 @@ The size object can be used like a normal integer. For specifying sizes in the ecal configuration object, refer to the .ini file or "ecal/config/configuration.h" for the limitations. -Initialization of the configuration +Global configuration initialization =================================== The configuration will be first initialized with the default values specified by eCAL. -If you want to use the systems eCAL .ini file, call the InitConfigWithDefaultIni() function of the config object. +If you want to use the systems eCAL .ini file, call the ``InitConfigWithDefaultIni()`` function of the config object. In case the .ini to use is specified via command line parameter, this one is chosen instead. The object will throw an error, in case the specified .ini file cannot be found. -It is also possible to specify the .ini by calling the function InitConfig(std::string _ini_path) of the config object. +It is also possible to specify the .ini by calling the function ``InitConfig(std::string _ini_path)`` of the config object. * |fa-file-alt| :file:`hello_config/main.cpp`: @@ -54,3 +54,15 @@ It is also possible to specify the .ini by calling the function InitConfig(std:: :language: cpp :linenos: +Individual publisher/subscriber configuration +============================================= + +Like a global configuration to pass at initialization, it is also possible to create indiviual configurations for publisher and subscriber. +That means it is possible to, e.g., create two publisher which send on different transport layers: + +* |fa-file-alt| :file:`publisher/main.cpp`: + + .. literalinclude:: src/publisher_config/main.cpp + :language: cpp + :linenos: + diff --git a/doc/rst/configuration/src/hello_config/main.cpp b/doc/rst/configuration/src/hello_config/main.cpp index 17befa109b..68a4967ad1 100644 --- a/doc/rst/configuration/src/hello_config/main.cpp +++ b/doc/rst/configuration/src/hello_config/main.cpp @@ -8,15 +8,16 @@ int main(int argc, char** argv) // Create a configuration object with the command line arguments eCAL::Configuration custom_config(argc, argv); - // Use the .ini file of the system ... + // Use the .ini file of the system if available custom_config.InitConfigWithDefaultIni(); - // .. or specify an own .ini file to use - custom_config.InitConfig("C:\\eCAL_local.ini"); - // Set the values in a try/catch block, as wrong configuration leads to exceptions try { + // In case you decided to specify an own .ini file to use + // Configuration based on previous ini file will be overwritten + custom_config.InitConfig("C:\\eCAL_local.ini"); + // Set the communication layer to network custom_config.transport_layer.network_enabled = true; diff --git a/doc/rst/configuration/src/publisher_config/CMakeLists.txt b/doc/rst/configuration/src/publisher_config/CMakeLists.txt new file mode 100644 index 0000000000..53f8f8fc47 --- /dev/null +++ b/doc/rst/configuration/src/publisher_config/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.0) +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +project(publisher_config) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(eCAL REQUIRED) + +set(source_files + main.cpp +) + +add_executable(${PROJECT_NAME} ${source_files}) + +target_link_libraries(${PROJECT_NAME} + eCAL::core +) \ No newline at end of file diff --git a/doc/rst/configuration/src/publisher_config/main.cpp b/doc/rst/configuration/src/publisher_config/main.cpp new file mode 100644 index 0000000000..c3cea80141 --- /dev/null +++ b/doc/rst/configuration/src/publisher_config/main.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + // initialize eCAL API + eCAL::Initialize(0, nullptr, "PublisherConfig", eCAL::Init::All); + + // create publisher config + eCAL::Publisher::Configuration pub_config; + + // disable all layers except for SHM + pub_config.shm.enable = true; + pub_config.udp.enable = false; + pub_config.tcp.enable = false; + + // create publisher 1 + eCAL::string::CPublisher pub_1("topic_1", pub_config); + + // enable for the second publisher also tcp + pub_config.tcp.enable = true; + + // create publisher 2 + eCAL::string::CPublisher pub_2("topic_2", pub_config); + + int counter {0}; + while (eCAL::Ok()) + { + std::string msg = "Send message number: " + std::to_string(counter++); + + // send message + pub_1.Send(msg); + pub_2.Send(msg); + + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + + // finalize eCAL API + eCAL::Finalize(); +} \ No newline at end of file From 7be0dd933bd0e4bcc6b80e77ce08d5536aa6e2d5 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 24 May 2024 11:09:56 +0200 Subject: [PATCH 100/105] Defaulted publisher test again. --- ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp index 0bb5db8e4e..1530f66e6d 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_acknowledge.cpp @@ -56,7 +56,6 @@ TEST(core_cpp_pubsub, TimeoutAcknowledgment) // create publisher config eCAL::Publisher::Configuration pub_config; pub_config.shm.acknowledge_timeout_ms = 500; - pub_config.shm.enable = true; // create publisher eCAL::string::CPublisher pub("topic", pub_config); From aa1d1ca0de29b73b60fc6128f4723af2f3658677 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 27 May 2024 07:30:23 +0200 Subject: [PATCH 101/105] Removed unncessary constructor/destructor in custom config classes. --- ecal/core/include/ecal/types/ecal_custom_data_types.h | 9 +-------- ecal/core/src/types/ecal_custom_data_types.cpp | 8 ++------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/ecal/core/include/ecal/types/ecal_custom_data_types.h b/ecal/core/include/ecal/types/ecal_custom_data_types.h index 671ceb9b73..8162c099ac 100644 --- a/ecal/core/include/ecal/types/ecal_custom_data_types.h +++ b/ecal/core/include/ecal/types/ecal_custom_data_types.h @@ -48,12 +48,9 @@ namespace eCAL public: ECAL_API IpAddressV4(); ECAL_API IpAddressV4(const std::string& ip_address_); - ECAL_API ~IpAddressV4(); - std::string GetIpString() const; + std::string Get() const; - ECAL_API IpAddressV4(IpAddressV4& other); - ECAL_API IpAddressV4& operator=(const IpAddressV4& other); ECAL_API IpAddressV4& operator=(const std::string& ip_string); ECAL_API operator std::string(); @@ -91,10 +88,6 @@ namespace eCAL } }; - ~ConstrainedInteger() = default; - - ConstrainedInteger(const ConstrainedInteger& other) { this->m_size = other; }; - ConstrainedInteger& operator=(const ConstrainedInteger& other) { this->m_size = other; return *this; }; operator int() const { return m_size; }; bool operator==(const ConstrainedInteger& other) const { return this->m_size == other; }; diff --git a/ecal/core/src/types/ecal_custom_data_types.cpp b/ecal/core/src/types/ecal_custom_data_types.cpp index af9e778b64..5fbf5615cd 100644 --- a/ecal/core/src/types/ecal_custom_data_types.cpp +++ b/ecal/core/src/types/ecal_custom_data_types.cpp @@ -51,8 +51,6 @@ namespace eCAL validateIpString(ip_address_); } - IpAddressV4::~IpAddressV4() = default; - void IpAddressV4::validateIpString(const std::string& ip_address_) { if ( std::regex_match(ip_address_, IPV4_DEC_REGEX) @@ -81,12 +79,10 @@ namespace eCAL throw std::invalid_argument("[IpAddressV4] No valid IP address: " + ip_address_); } - std::string IpAddressV4::GetIpString() const { return m_ip_address; }; - IpAddressV4::IpAddressV4(IpAddressV4& other) { this->m_ip_address = other; }; - IpAddressV4& IpAddressV4::operator=(const IpAddressV4& other) { this->m_ip_address = other.GetIpString(); return *this; }; + std::string IpAddressV4::Get() const { return m_ip_address; }; IpAddressV4& IpAddressV4::operator=(const std::string& ip_string) { this->validateIpString(ip_string); return *this; }; IpAddressV4::operator std::string() { return m_ip_address; }; - std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.GetIpString(); return os; }; + std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.Get(); return os; }; } } From db16ff609ec0235c016ed71a5d8d47749ad53f19 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Mon, 27 May 2024 08:25:18 +0200 Subject: [PATCH 102/105] Some ecal_cmd_parser cleanup. --- ecal/core/src/config/ecal_cmd_parser.cpp | 39 ++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 0666a731a2..a93703b38a 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -14,7 +14,7 @@ // for cwd #ifdef ECAL_OS_WINDOWS #include - // to get rid of deprecated warning + // to remove deprecated warning #define getcwd _getcwd #endif #ifdef ECAL_OS_LINUX @@ -23,7 +23,7 @@ namespace { - // things stolen and adapted from ecal_config_reader.cpp + // copied and adapted from ecal_config_reader.cpp #ifdef ECAL_OS_WINDOWS const char path_separator('\\'); #endif /* ECAL_OS_WINDOWS */ @@ -31,7 +31,7 @@ namespace const char path_separator('/'); #endif /* ECAL_OS_LINUX */ - bool SetPathSep(std::string file_path_) + bool setPathSep(std::string file_path_) { if (!file_path_.empty()) { @@ -48,7 +48,7 @@ namespace std::string eCALDataEnvPath() { std::string ecal_data_path = getEnvVar("ECAL_DATA"); - SetPathSep(ecal_data_path); + setPathSep(ecal_data_path); return ecal_data_path; } @@ -59,7 +59,7 @@ namespace if (cwd_path.empty()) throw std::runtime_error("getcwd() : cannot read current working directory."); - SetPathSep(cwd_path); + setPathSep(cwd_path); return cwd_path; } @@ -79,7 +79,7 @@ namespace { cmake_data_path = ecal_install_prefix + path_separator + ecal_install_config_dir; } - SetPathSep(cmake_data_path); + setPathSep(cmake_data_path); #endif /* ECAL_OS_LINUX */ return cmake_data_path; } @@ -89,23 +89,17 @@ namespace std::string system_data_path; #ifdef ECAL_OS_WINDOWS system_data_path = getEnvVar("ProgramData"); - if(SetPathSep(system_data_path)) - system_data_path += path_separator + std::string("eCAL"); + if(setPathSep(system_data_path)) + system_data_path += std::string("eCAL"); #endif /* ECAL_OS_WINDOWS */ #ifdef ECAL_OS_LINUX system_data_path = "/etc/ecal"; + setPathSep(system_data_path) #endif /* ECAL_OS_LINUX */ return system_data_path; } - bool isValidConfigFilePath(const std::string& file_path_) - { - // check existence of user defined file - const EcalUtils::Filesystem::FileStatus ecal_ini_status(file_path_, EcalUtils::Filesystem::Current); - return ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile); - } - void appendFileNameToPathIfPathIsValid(std::string& path_, const std::string& file_name_) { if (!path_.empty()) @@ -131,12 +125,19 @@ namespace } } - std::string checkForValidConfigFilePath(const std::string& config_file_) + bool isValidConfigFilePath(const std::string& file_path_) + { + // check existence of user defined file + const EcalUtils::Filesystem::FileStatus ecal_ini_status(file_path_, EcalUtils::Filesystem::Current); + return ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile); + } + + std::string& checkForValidConfigFilePath(const std::string& config_file_) { // differences to ecal_config_reader implementation are: - // 1. it does not use the default ini file name, instead uses the specified file - // 2. it searches relative to the executable path and takes it as highest priority - // 3. it throws a runtime error, if it cannot find the specified file + // 1. does not use the default ini file name, instead uses the specified file + // 2. searches relative to the executable path and takes it as highest priority + // 3. throws a runtime error, if it cannot find the specified file // ----------------------------------------------------------- // precedence 1: relative path to executable From 11044f158c56193f103f6f7e36ff71f82627f169 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 28 May 2024 15:49:55 +0200 Subject: [PATCH 103/105] Fix ecal_cmd_parser checkForValidConfigFilePath function. --- ecal/core/src/config/ecal_cmd_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index a93703b38a..750173c934 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -132,7 +132,7 @@ namespace return ecal_ini_status.IsOk() && (ecal_ini_status.GetType() == EcalUtils::Filesystem::Type::RegularFile); } - std::string& checkForValidConfigFilePath(const std::string& config_file_) + std::string checkForValidConfigFilePath(const std::string& config_file_) { // differences to ecal_config_reader implementation are: // 1. does not use the default ini file name, instead uses the specified file From a9a4a411d364233b6dadc0727deb033d7abddffe Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Wed, 29 May 2024 10:34:27 +0200 Subject: [PATCH 104/105] Fixed ecal_cmd_parser problem with path separator attachments. --- ecal/core/src/config/ecal_cmd_parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index 750173c934..fffb97cf07 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -31,7 +31,7 @@ namespace const char path_separator('/'); #endif /* ECAL_OS_LINUX */ - bool setPathSep(std::string file_path_) + bool setPathSep(std::string& file_path_) { if (!file_path_.empty()) { @@ -90,12 +90,15 @@ namespace #ifdef ECAL_OS_WINDOWS system_data_path = getEnvVar("ProgramData"); if(setPathSep(system_data_path)) + { system_data_path += std::string("eCAL"); + setPathSep(system_data_path); + } #endif /* ECAL_OS_WINDOWS */ #ifdef ECAL_OS_LINUX system_data_path = "/etc/ecal"; - setPathSep(system_data_path) + setPathSep(system_data_path); #endif /* ECAL_OS_LINUX */ return system_data_path; } @@ -103,7 +106,7 @@ namespace void appendFileNameToPathIfPathIsValid(std::string& path_, const std::string& file_name_) { if (!path_.empty()) - path_ += path_separator + file_name_; + path_ += file_name_; } void parseConfigKeysToMap(const std::vector& config_keys_, eCAL::Cli::ConfigKey2DMap& map_) From 23ac09564c14b82ac9296be0aa663c9bc50997c1 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:28:46 +0200 Subject: [PATCH 105/105] Changed handling of cli arguments to std::vector by default. --- ecal/core/include/ecal/config/configuration.h | 4 ++-- ecal/core/src/config/ecal_cmd_parser.cpp | 15 +++++------- ecal/core/src/config/ecal_cmd_parser.h | 4 ++-- .../src/config/ecal_config_initializer.cpp | 23 +++++++++++-------- .../tests/cpp/config_test/src/config_test.cpp | 20 +++++++--------- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/ecal/core/include/ecal/config/configuration.h b/ecal/core/include/ecal/config/configuration.h index 785b61dbf2..101c890dea 100644 --- a/ecal/core/include/ecal/config/configuration.h +++ b/ecal/core/include/ecal/config/configuration.h @@ -62,7 +62,7 @@ namespace eCAL ECAL_API Configuration(); ECAL_API Configuration(int argc_ , char **argv_); - ECAL_API Configuration(std::vector args_); + ECAL_API Configuration(std::vector& args_); ECAL_API void InitConfigWithDefaultIni(); ECAL_API void InitConfig(std::string ini_path_ = std::string("")); @@ -75,6 +75,6 @@ namespace eCAL std::string ecal_ini_file_path{}; private: - ECAL_API void Init(int argc_ , char **argv_); + ECAL_API void Init(std::vector& args_); }; } \ No newline at end of file diff --git a/ecal/core/src/config/ecal_cmd_parser.cpp b/ecal/core/src/config/ecal_cmd_parser.cpp index fffb97cf07..b2567657b4 100644 --- a/ecal/core/src/config/ecal_cmd_parser.cpp +++ b/ecal/core/src/config/ecal_cmd_parser.cpp @@ -193,16 +193,16 @@ namespace eCAL : m_dump_config{false} {} - CmdParser::CmdParser(int argc_ , char **argv_) + CmdParser::CmdParser(std::vector& arguments_) : CmdParser() { - parseArguments(argc_, argv_); + parseArguments(arguments_); } - void CmdParser::parseArguments(int argc_, char **argv_) + void CmdParser::parseArguments(std::vector& arguments_) { #if ECAL_CORE_COMMAND_LINE - if ((argc_ > 0) && (argv_ != nullptr)) + if (!arguments_.empty()) { // define command line object TCLAP::CmdLine cmd("", ' ', ECAL_VERSION); @@ -224,7 +224,7 @@ namespace eCAL cmd.setOutput(&advanced_tclap_output); // parse command line - cmd.parse(argc_, argv_); + cmd.parse(arguments_); // set globals if (dump_config_arg.isSet()) @@ -242,10 +242,7 @@ namespace eCAL } } #endif - if (argv_ != nullptr) - { - for (size_t i = 0; i < static_cast(argc_); ++i) if (argv_[i] != nullptr) m_task_parameter.emplace_back(argv_[i]); - } + m_task_parameter = arguments_; } bool CmdParser::getDumpConfig() const { return m_dump_config; }; diff --git a/ecal/core/src/config/ecal_cmd_parser.h b/ecal/core/src/config/ecal_cmd_parser.h index ee4fc87dee..dd1ed957bf 100644 --- a/ecal/core/src/config/ecal_cmd_parser.h +++ b/ecal/core/src/config/ecal_cmd_parser.h @@ -44,10 +44,10 @@ namespace eCAL class CmdParser { public: - CmdParser(int argc_ , char **argv_); + CmdParser(std::vector& arguments_); CmdParser(); - void parseArguments(int argc_, char **argv_); + void parseArguments(std::vector& arguments_); bool getDumpConfig() const; std::vector& getConfigKeys(); diff --git a/ecal/core/src/config/ecal_config_initializer.cpp b/ecal/core/src/config/ecal_config_initializer.cpp index ba79c6bf10..2441eccd40 100644 --- a/ecal/core/src/config/ecal_config_initializer.cpp +++ b/ecal/core/src/config/ecal_config_initializer.cpp @@ -221,21 +221,24 @@ namespace eCAL Configuration::Configuration(int argc_ , char **argv_) { - Init(argc_, argv_); + std::vector arguments; + if (argc_ > 0 && argv_ != nullptr) + { + for (size_t i = 0; i < static_cast(argc_); ++i) + if (argv_[i] != nullptr) + arguments.emplace_back(argv_[i]); + } + Init(arguments); } - Configuration::Configuration(std::vector args_) - { - args_.emplace(args_.begin(), eCAL::Process::GetProcessName()); - std::vector argv(args_.size()); - std::transform(args_.begin(), args_.end(), argv.begin(), [](std::string& s) {return s.c_str();}); - - Init(static_cast(argv.size()), const_cast(argv.data())); + Configuration::Configuration(std::vector& args_) + { + Init(args_); } - void Configuration::Init(int argc_ , char **argv_) + void Configuration::Init(std::vector& arguments_) { - Config::CmdParser parser(argc_, argv_); + Config::CmdParser parser(arguments_); command_line_arguments.config_keys = parser.getConfigKeys(); command_line_arguments.specified_config = parser.getUserIni(); diff --git a/ecal/tests/cpp/config_test/src/config_test.cpp b/ecal/tests/cpp/config_test/src/config_test.cpp index 7733689831..89d861dfda 100644 --- a/ecal/tests/cpp/config_test/src/config_test.cpp +++ b/ecal/tests/cpp/config_test/src/config_test.cpp @@ -237,7 +237,7 @@ TEST(core_cpp_config, config_cmd_parser) eCAL::Config::CmdParser parser; - std::vector arguments; + std::vector arguments; const std::string set_config_key = "--ecal-set-config-key "; const std::string sep_slash = "/"; @@ -257,18 +257,14 @@ TEST(core_cpp_config, config_cmd_parser) arguments.push_back("test_config_cmd_parser"); arguments.push_back("--ecal-ini-file customIni.ini"); - std::string host_group_string = set_config_key + network + sep_slash + host_group_name + sep_col + config_test_machine; - arguments.push_back(host_group_string.data()); - std::string network_enabled_string = set_config_key + network + sep_slash + network_enabled + sep_col + is_network_enabled; - arguments.push_back(network_enabled_string.data()); - std::string registration_to_string = set_config_key + common + sep_slash + registration_timeout + sep_col + reg_to_value; - arguments.push_back(registration_to_string.data()); - std::string registration_rf_string = set_config_key + common + sep_slash + registration_refresh + sep_col + reg_rf_value; - arguments.push_back(registration_rf_string.data()); + arguments.push_back(set_config_key + network + sep_slash + host_group_name + sep_col + config_test_machine); + arguments.push_back(set_config_key + network + sep_slash + network_enabled + sep_col + is_network_enabled); + arguments.push_back(set_config_key + common + sep_slash + registration_timeout + sep_col + reg_to_value); + arguments.push_back(set_config_key + common + sep_slash + registration_refresh + sep_col + reg_rf_value); try { - parser.parseArguments(static_cast(arguments.size()), const_cast(arguments.data())); + parser.parseArguments(arguments); } catch(const std::runtime_error& e) { @@ -291,13 +287,13 @@ TEST(CmdParserDeathTest, config_cmd_parser_death_test) { eCAL::Config::CmdParser parser; - std::vector arguments; + std::vector arguments; arguments.push_back("test_config_cmd_parser_death_test"); arguments.push_back("--ecal-ini-file someNotValidFileName.ini"); ASSERT_THROW( - parser.parseArguments(static_cast(arguments.size()), const_cast(arguments.data())), + parser.parseArguments(arguments), std::runtime_error ); } \ No newline at end of file