diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index a2a450206d..ff0ae7fb8d 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -98,9 +98,6 @@ namespace eCAL // mark as created m_created = true; - - // register - Register(false); } CDataReader::~CDataReader() @@ -256,9 +253,6 @@ namespace eCAL bool CDataReader::SetAttribute(const std::string& attr_name_, const std::string& attr_value_) { - auto current_val = m_attr.find(attr_name_); - - const bool force = current_val == m_attr.end() || current_val->second != attr_value_; m_attr[attr_name_] = attr_value_; #ifndef NDEBUG @@ -266,16 +260,11 @@ namespace eCAL Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::SetAttribute"); #endif - // register it - Register(force); - return(true); } bool CDataReader::ClearAttribute(const std::string& attr_name_) { - auto force = m_attr.find(attr_name_) != m_attr.end(); - m_attr.erase(attr_name_); #ifndef NDEBUG @@ -283,9 +272,6 @@ namespace eCAL Logging::Log(log_level_debug2, m_topic_name + "::CDataReader::ClearAttribute"); #endif - // register it - Register(force); - return(true); } @@ -533,10 +519,10 @@ namespace eCAL return(out.str()); } - void CDataReader::Register(bool force_) + void CDataReader::Register() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetRegistrationSample(), force_); + if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(GetRegistrationSample()); #ifndef NDEBUG // log it @@ -548,7 +534,7 @@ namespace eCAL void CDataReader::Unregister() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetUnregistrationSample(), false); + if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterSample(GetUnregistrationSample()); #ifndef NDEBUG // log it diff --git a/ecal/core/src/readwrite/ecal_reader.h b/ecal/core/src/readwrite/ecal_reader.h index 5716610dd6..eebff4d34c 100644 --- a/ecal/core/src/readwrite/ecal_reader.h +++ b/ecal/core/src/readwrite/ecal_reader.h @@ -125,7 +125,7 @@ namespace eCAL std::string Dump(const std::string& indent_ = ""); protected: - void Register(bool force_); + void Register(); void Unregister(); void CheckConnections(); diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 5f00b7f33f..6f4164c1b4 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -120,9 +120,6 @@ namespace eCAL // mark as created m_created = true; - - // register - Register(false); } CDataWriter::~CDataWriter() @@ -227,7 +224,7 @@ namespace eCAL if (m_writer_shm->PrepareWrite(wattr)) { // register new to update listening subscribers and rematch - Register(true); + Register(); Process::SleepMS(5); } @@ -291,7 +288,7 @@ namespace eCAL if (m_writer_udp->PrepareWrite(wattr)) { // register new to update listening subscribers and rematch - Register(true); + Register(); Process::SleepMS(5); } @@ -364,8 +361,6 @@ namespace eCAL bool CDataWriter::SetDataTypeInformation(const SDataTypeInformation& topic_info_) { - // Does it even make sense to register if the info is the same??? - const bool force = m_topic_info != topic_info_; m_topic_info = topic_info_; #ifndef NDEBUG @@ -373,17 +368,11 @@ namespace eCAL Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::SetDescription"); #endif - // register it - Register(force); - return(true); } bool CDataWriter::SetAttribute(const std::string& attr_name_, const std::string& attr_value_) { - auto current_val = m_attr.find(attr_name_); - - const bool force = current_val == m_attr.end() || current_val->second != attr_value_; m_attr[attr_name_] = attr_value_; #ifndef NDEBUG @@ -391,16 +380,11 @@ namespace eCAL Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::SetAttribute"); #endif - // register it - Register(force); - return(true); } bool CDataWriter::ClearAttribute(const std::string& attr_name_) { - auto force = m_attr.find(attr_name_) != m_attr.end(); - m_attr.erase(attr_name_); #ifndef NDEBUG @@ -408,9 +392,6 @@ namespace eCAL Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ClearAttribute"); #endif - // register it - Register(force); - return(true); } @@ -484,10 +465,10 @@ namespace eCAL StartUdpLayer(); break; case tl_ecal_shm: - if (StartShmLayer()) Register(true); + StartShmLayer(); break; case tl_ecal_tcp: - if (StartTcpLayer()) Register(true); + StartTcpLayer(); break; default: break; @@ -585,10 +566,10 @@ namespace eCAL return(out.str()); } - void CDataWriter::Register(bool force_) + void CDataWriter::Register() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetRegistrationSample(), force_); + if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(GetRegistrationSample()); #ifndef NDEBUG // log it @@ -600,7 +581,7 @@ namespace eCAL void CDataWriter::Unregister() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetUnregistrationSample(), false); + if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterSample(GetUnregistrationSample()); #ifndef NDEBUG // log it @@ -625,8 +606,7 @@ namespace eCAL // check connection timeouts CheckConnections(); - if (m_created) return GetRegistrationSample(); - else return GetUnregistrationSample(); + return GetRegistrationSample(); } Registration::Sample CDataWriter::GetRegistrationSample() @@ -816,6 +796,9 @@ namespace eCAL // create writer m_writer_udp = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.udp); + // register activated layer + Register(); + #ifndef NDEBUG Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateUdpLayer::WRITER_CREATED"); #endif @@ -839,6 +822,9 @@ namespace eCAL // create writer m_writer_shm = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.shm); + // register activated layer + Register(); + #ifndef NDEBUG Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateShmLayer::WRITER_CREATED"); #endif @@ -862,6 +848,9 @@ namespace eCAL // create writer m_writer_tcp = std::make_unique(m_host_name, m_topic_name, m_topic_id, m_config.layer.tcp); + // register activated layer + Register(); + #ifndef NDEBUG Logging::Log(log_level_debug2, m_topic_name + "::CDataWriter::ActivateTcpLayer::WRITER_CREATED"); #endif diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index c1108de17e..1ea35da0d0 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -128,7 +128,7 @@ namespace eCAL std::string Dump(const std::string& indent_ = ""); protected: - void Register(bool force_); + void Register(); void Unregister(); void CheckConnections(); diff --git a/ecal/core/src/registration/ecal_registration_provider.cpp b/ecal/core/src/registration/ecal_registration_provider.cpp index 49f75c6041..f920848e5c 100644 --- a/ecal/core/src/registration/ecal_registration_provider.cpp +++ b/ecal/core/src/registration/ecal_registration_provider.cpp @@ -22,7 +22,7 @@ * * All process internal publisher/subscriber, server/clients register here with all their attributes. * - * These information will be send cyclic (registration refresh) via UDP to external eCAL processes. + * These information will be send cyclic (registration refresh) via UDP or SHM to external eCAL processes. * **/ #include "ecal_registration_provider.h" @@ -84,7 +84,7 @@ namespace eCAL // start cyclic registration thread m_reg_sample_snd_thread = std::make_shared(std::bind(&CRegistrationProvider::RegisterSendThread, this)); - m_reg_sample_snd_thread->start(std::chrono::milliseconds(Config::GetRegistrationRefreshMs())); + m_reg_sample_snd_thread->start(std::chrono::milliseconds(0)); m_created = true; } @@ -97,37 +97,27 @@ namespace eCAL m_reg_sample_snd_thread->stop(); // send process unregistration sample - SendSample(Registration::GetProcessUnregisterSample()); + //m_reg_sender->SendSample(Registration::GetProcessUnregisterSample()); + // delete registration sender m_reg_sender.reset(); m_created = false; } - bool CRegistrationProvider::ApplySample(const Registration::Sample& sample_, const bool force_) + // register single sample (currently we do not differ between registration/unregistration) + bool CRegistrationProvider::RegisterSample(const Registration::Sample& sample_) { if (!m_created) return(false); + ProcessSingleSample(sample_); + return(true); + } - // forward all registration samples to outside "customer" (e.g. monitoring, descgate) - { - const std::lock_guard lock(m_callback_custom_apply_sample_map_mtx); - for (const auto& iter : m_callback_custom_apply_sample_map) - { - iter.second(sample_); - } - } - - if (force_) - { - // send sample - SendSample(sample_); - } - else - { - // add sample to sample list and send it later - AddSample2SampleList(sample_); - } - + // unregister single sample (currently we do not differ between registration/unregistration) + bool CRegistrationProvider::UnregisterSample(const Registration::Sample& sample_) + { + if (!m_created) return(false); + ProcessSingleSample(sample_); return(true); } @@ -147,55 +137,70 @@ namespace eCAL } } - void CRegistrationProvider::AddSample2SampleList(const Registration::Sample& sample_) + void CRegistrationProvider::ForwardSample(const Registration::Sample& sample_) + { + const std::lock_guard lock(m_callback_custom_apply_sample_map_mtx); + for (const auto& iter : m_callback_custom_apply_sample_map) + { + iter.second(sample_); + } + } + + void CRegistrationProvider::ProcessSingleSample(const Registration::Sample& sample_) { - const std::lock_guard lock(m_sample_list_mtx); - m_sample_list.samples.push_back(sample_); + // forward registration sample to outside "customer" (currently monitoring and descgate) + ForwardSample(sample_); + + // force rgistration thread to send + TriggerRegisterSendThread(); } - void CRegistrationProvider::SendSample(const Registration::Sample& sample_) + void CRegistrationProvider::TriggerRegisterSendThread() { - Registration::SampleList sample_list; - sample_list.samples.push_back(sample_); - m_reg_sender->SendSampleList(sample_list); + { + std::lock_guard lock(m_reg_sample_snd_thread_cv_mtx); + m_reg_sample_snd_thread_trigger = true; + } + m_reg_sample_snd_thread_cv.notify_one(); } void CRegistrationProvider::RegisterSendThread() { - // collect all registrations and send them out - // the internal list already contain elements here: - // one process registration sample - // one or more registration/unregistration samples added by AddSample2SampleList + // collect all registrations and send them out cyclic { - // lock sample list - std::lock_guard lock(m_sample_list_mtx); + // create sample list + Registration::SampleList sample_list; + + // and add process registration sample + sample_list.samples.push_back(Registration::GetProcessRegisterSample()); #if ECAL_CORE_SUBSCRIBER // add subscriber registrations - if (g_subgate() != nullptr) g_subgate()->GetRegistrations(m_sample_list); + if (g_subgate() != nullptr) g_subgate()->GetRegistrations(sample_list); #endif #if ECAL_CORE_PUBLISHER // add publisher registrations - if (g_pubgate() != nullptr) g_pubgate()->GetRegistrations(m_sample_list); + if (g_pubgate() != nullptr) g_pubgate()->GetRegistrations(sample_list); #endif #if ECAL_CORE_SERVICE // add server registrations - if (g_servicegate() != nullptr) g_servicegate()->GetRegistrations(m_sample_list); + if (g_servicegate() != nullptr) g_servicegate()->GetRegistrations(sample_list); // add client registrations - if (g_clientgate() != nullptr) g_clientgate()->GetRegistrations(m_sample_list); + if (g_clientgate() != nullptr) g_clientgate()->GetRegistrations(sample_list); #endif // send registration sample list - m_reg_sender->SendSampleList(m_sample_list); + m_reg_sender->SendSampleList(sample_list); - // clear it - m_sample_list.samples.clear(); - - // and add process registration sample to internal sample list as first sample (for next registration loop) - m_sample_list.samples.push_back(Registration::GetProcessRegisterSample()); + // wait for trigger or registration refresh timeout + { + std::unique_lock lock(m_reg_sample_snd_thread_cv_mtx); + m_reg_sample_snd_thread_cv.wait_for(lock, std::chrono::milliseconds(Config::GetRegistrationRefreshMs()), [this] { return m_reg_sample_snd_thread_trigger; }); + m_reg_sample_snd_thread_trigger = false; + } } } } diff --git a/ecal/core/src/registration/ecal_registration_provider.h b/ecal/core/src/registration/ecal_registration_provider.h index 587be88dec..85bdccd708 100644 --- a/ecal/core/src/registration/ecal_registration_provider.h +++ b/ecal/core/src/registration/ecal_registration_provider.h @@ -31,6 +31,7 @@ #include "io/udp/ecal_udp_sample_sender.h" #include +#include #include #include #include @@ -50,26 +51,28 @@ namespace eCAL void Start(); void Stop(); - bool ApplySample(const Registration::Sample& sample_, bool force_); + bool RegisterSample(const Registration::Sample& sample_); + bool UnregisterSample(const Registration::Sample& sample_); using ApplySampleCallbackT = std::function; void SetCustomApplySampleCallback(const std::string& customer_, const ApplySampleCallbackT& callback_); void RemCustomApplySampleCallback(const std::string& customer_); protected: - void AddSample2SampleList(const Registration::Sample& sample_); - void SendSample(const Registration::Sample& sample_); + void ForwardSample(const Registration::Sample& sample_); + void ProcessSingleSample(const Registration::Sample& sample_); + void TriggerRegisterSendThread(); void RegisterSendThread(); static std::atomic m_created; std::unique_ptr m_reg_sender; - std::shared_ptr m_reg_sample_snd_thread; - std::mutex m_sample_list_mtx; - Registration::SampleList m_sample_list; + std::condition_variable m_reg_sample_snd_thread_cv; + std::mutex m_reg_sample_snd_thread_cv_mtx; + bool m_reg_sample_snd_thread_trigger; bool m_use_registration_udp; bool m_use_registration_shm; diff --git a/ecal/core/src/registration/ecal_registration_sample_applier.cpp b/ecal/core/src/registration/ecal_registration_sample_applier.cpp index 41b7a4aa17..4f3b65282f 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.cpp +++ b/ecal/core/src/registration/ecal_registration_sample_applier.cpp @@ -96,6 +96,36 @@ namespace eCAL return true; } + bool CSampleApplier::IsSameProcess(const Registration::Sample& sample_) + { + int32_t pid(0); + switch (sample_.cmd_type) + { + case bct_reg_process: + case bct_unreg_process: + pid = sample_.process.pid; + break; + case bct_reg_publisher: + case bct_unreg_publisher: + case bct_reg_subscriber: + case bct_unreg_subscriber: + pid = sample_.topic.pid; + break; + case bct_reg_service: + case bct_unreg_service: + pid = sample_.service.pid; + break; + case bct_reg_client: + case bct_unreg_client: + pid = sample_.client.pid; + break; + default: + break; + } + + return pid == m_pid; + } + bool CSampleApplier::AcceptRegistrationSample(const Registration::Sample& sample_) { // check if the sample is from the same host group @@ -103,7 +133,7 @@ namespace eCAL { // register if the sample is from another process // or if loopback mode is enabled - return m_loopback || (sample_.topic.pid != m_pid); + return !IsSameProcess(sample_) || m_loopback; } else { diff --git a/ecal/core/src/registration/ecal_registration_sample_applier.h b/ecal/core/src/registration/ecal_registration_sample_applier.h index 354f9c982c..401fdf4820 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.h +++ b/ecal/core/src/registration/ecal_registration_sample_applier.h @@ -54,6 +54,7 @@ namespace eCAL void RemCustomApplySampleCallback(const std::string& customer_); private: + bool IsSameProcess(const Registration::Sample& sample_); bool IsHostGroupMember(const eCAL::Registration::Sample& sample_); bool AcceptRegistrationSample(const Registration::Sample& sample_); diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index 96f48f280d..abce7327eb 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -89,7 +89,7 @@ namespace eCAL m_created = true; // register this client - Register(true); + Register(); return(true); } @@ -687,13 +687,13 @@ namespace eCAL return ecal_reg_sample; } - void CServiceClientImpl::Register(const bool force_) + void CServiceClientImpl::Register() { if (!m_created) return; if (m_service_name.empty()) return; // register entity - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetRegistrationSample(), force_); + if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(GetRegistrationSample()); } void CServiceClientImpl::Unregister() @@ -701,7 +701,7 @@ namespace eCAL if (m_service_name.empty()) return; // unregister entity - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetUnregistrationSample(), false); + if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterSample(GetUnregistrationSample()); } void CServiceClientImpl::CheckForNewServices() diff --git a/ecal/core/src/service/ecal_service_client_impl.h b/ecal/core/src/service/ecal_service_client_impl.h index 1c75b75ab3..cb9059d124 100644 --- a/ecal/core/src/service/ecal_service_client_impl.h +++ b/ecal/core/src/service/ecal_service_client_impl.h @@ -99,7 +99,7 @@ namespace eCAL Registration::Sample GetRegistrationSample(); Registration::Sample GetUnregistrationSample(); - void Register(bool force_); + void Register(); void Unregister(); void CheckForNewServices(); diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 7aab9c31f4..10d2ff6450 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -128,9 +128,6 @@ namespace eCAL // mark as created m_created = true; - // register this service - Register(false); - return(true); } @@ -200,9 +197,6 @@ namespace eCAL } } - // register this service - Register(false); - return true; } @@ -238,9 +232,6 @@ namespace eCAL } } - // register this service - Register(false); - return true; } @@ -377,10 +368,10 @@ namespace eCAL return ecal_reg_sample; } - void CServiceServerImpl::Register(bool force_) + void CServiceServerImpl::Register() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetRegistrationSample(), force_); + if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(GetRegistrationSample()); #ifndef NDEBUG // log it @@ -392,7 +383,7 @@ namespace eCAL void CServiceServerImpl::Unregister() { #if ECAL_CORE_REGISTRATION - if (g_registration_provider() != nullptr) g_registration_provider()->ApplySample(GetUnregistrationSample(), false); + if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterSample(GetUnregistrationSample()); #ifndef NDEBUG // log it diff --git a/ecal/core/src/service/ecal_service_server_impl.h b/ecal/core/src/service/ecal_service_server_impl.h index 22eef8a9ec..ccf741bef2 100644 --- a/ecal/core/src/service/ecal_service_server_impl.h +++ b/ecal/core/src/service/ecal_service_server_impl.h @@ -85,7 +85,7 @@ namespace eCAL std::string GetServiceName() { return m_service_name; }; protected: - void Register(bool force_); + void Register(); void Unregister(); Registration::Sample GetRegistrationSample(); diff --git a/ecal/tests/cpp/util_test/src/util_getclients.cpp b/ecal/tests/cpp/util_test/src/util_getclients.cpp index bd70c9dbe0..8a938cf16e 100644 --- a/ecal/tests/cpp/util_test/src/util_getclients.cpp +++ b/ecal/tests/cpp/util_test/src/util_getclients.cpp @@ -22,8 +22,8 @@ #include enum { - CMN_MONITORING_TIMEOUT_MS = (5000), - CMN_REGISTRATION_REFRESH_MS = (1000 * 2) + CMN_MONITORING_TIMEOUT_MS = (5000 + 100), + CMN_REGISTRATION_REFRESH_MS = (1000) }; TEST(core_cpp_util, ClientExpiration) @@ -31,6 +31,9 @@ TEST(core_cpp_util, ClientExpiration) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map client_info_map; // create simple client and let it expire @@ -43,6 +46,9 @@ TEST(core_cpp_util, ClientExpiration) service_method_info.response_type.descriptor = "foo::resp_desc"; const eCAL::CServiceClient client("foo::service", { {"foo::method", service_method_info} }); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all clients eCAL::Util::GetClients(client_info_map); @@ -70,7 +76,7 @@ TEST(core_cpp_util, ClientExpiration) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all clients again, all clients // should be removed from the map @@ -88,6 +94,9 @@ TEST(core_cpp_util, ClientEqualQualities) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map client_info_map; // create 2 clients with the same quality of data type information @@ -100,6 +109,9 @@ TEST(core_cpp_util, ClientEqualQualities) service_method_info1.response_type.descriptor = "foo::resp_desc1"; eCAL::CServiceClient client1("foo::service", { {"foo::method", service_method_info1} }); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all clients eCAL::Util::GetClients(client_info_map); @@ -159,7 +171,7 @@ TEST(core_cpp_util, ClientEqualQualities) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all clients again, all clients // should be removed from the map @@ -177,6 +189,9 @@ TEST(core_cpp_util, ClientDifferentQualities) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map client_info_map; // create 2 clients with different qualities of data type information @@ -189,6 +204,9 @@ TEST(core_cpp_util, ClientDifferentQualities) service_method_info1.response_type.descriptor = ""; eCAL::CServiceClient client1("foo::service", { {"foo::method", service_method_info1} }); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all clients eCAL::Util::GetClients(client_info_map); @@ -214,6 +232,9 @@ TEST(core_cpp_util, ClientDifferentQualities) service_method_info2.response_type.descriptor = "foo::resp_desc2"; eCAL::CServiceClient client2("foo::service", { {"foo::method", service_method_info2} }); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // check attributes, we expect attributes from client 2 here eCAL::Util::GetClientTypeNames("foo::service", "foo::method", req_type, resp_type); EXPECT_EQ(req_type, "foo::req_type2"); @@ -227,7 +248,7 @@ TEST(core_cpp_util, ClientDifferentQualities) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all clients again, all clients // should be removed from the map diff --git a/ecal/tests/cpp/util_test/src/util_getservices.cpp b/ecal/tests/cpp/util_test/src/util_getservices.cpp index fbf2239d43..7ad633d5c1 100644 --- a/ecal/tests/cpp/util_test/src/util_getservices.cpp +++ b/ecal/tests/cpp/util_test/src/util_getservices.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. @@ -23,7 +23,7 @@ enum { CMN_MONITORING_TIMEOUT_MS = (5000 + 100), - CMN_REGISTRATION_REFRESH_MS = (1000 + 100) + CMN_REGISTRATION_REFRESH_MS = (1000) }; TEST(core_cpp_util, ServiceExpiration) @@ -31,6 +31,9 @@ TEST(core_cpp_util, ServiceExpiration) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map service_info_map; // create simple service and let it expire @@ -39,6 +42,9 @@ TEST(core_cpp_util, ServiceExpiration) eCAL::CServiceServer service("foo::service"); service.AddDescription("foo::method", "foo::req_type", "foo::req_desc", "foo::resp_type", "foo::resp_desc"); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all services eCAL::Util::GetServices(service_info_map); @@ -66,7 +72,7 @@ TEST(core_cpp_util, ServiceExpiration) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all services again, all services // should be removed from the map @@ -84,6 +90,9 @@ TEST(core_cpp_util, ServiceEqualQualities) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map service_info_map; // create 2 services with the same quality of data type information @@ -92,6 +101,9 @@ TEST(core_cpp_util, ServiceEqualQualities) eCAL::CServiceServer service1("foo::service"); service1.AddDescription("foo::method", "foo::req_type1", "foo::req_desc1", "foo::resp_type1", "foo::resp_desc1"); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all services eCAL::Util::GetServices(service_info_map); @@ -147,7 +159,7 @@ TEST(core_cpp_util, ServiceEqualQualities) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all services again, all services // should be removed from the map @@ -165,6 +177,9 @@ TEST(core_cpp_util, ServiceDifferentQualities) // initialize eCAL API eCAL::Initialize(0, nullptr, "core_cpp_util"); + // enable loop back communication in the same process + eCAL::Util::EnableLoopback(true); + std::map service_info_map; // create 2 services with different qualities of data type information @@ -173,6 +188,9 @@ TEST(core_cpp_util, ServiceDifferentQualities) eCAL::CServiceServer service1("foo::service"); service1.AddDescription("foo::method", "foo::req_type1", "foo::req_desc1", "", ""); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all services eCAL::Util::GetServices(service_info_map); @@ -194,6 +212,9 @@ TEST(core_cpp_util, ServiceDifferentQualities) eCAL::CServiceServer service2("foo::service"); service2.AddDescription("foo::method", "foo::req_type2", "foo::req_desc2", "foo::resp_type2", "foo::resp_desc2"); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // check attributes, we expect attributes from service 2 here eCAL::Util::GetServiceTypeNames("foo::service", "foo::method", req_type, resp_type); EXPECT_EQ(req_type, "foo::req_type2"); @@ -207,7 +228,7 @@ TEST(core_cpp_util, ServiceDifferentQualities) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all services again, all services // should be removed from the map diff --git a/ecal/tests/cpp/util_test/src/util_gettopics.cpp b/ecal/tests/cpp/util_test/src/util_gettopics.cpp index 495a9dcfea..19b27429da 100644 --- a/ecal/tests/cpp/util_test/src/util_gettopics.cpp +++ b/ecal/tests/cpp/util_test/src/util_gettopics.cpp @@ -27,8 +27,8 @@ #include enum { - CMN_MONITORING_TIMEOUT_MS = (5000), - CMN_REGISTRATION_REFRESH_MS = (1000 * 2) + CMN_MONITORING_TIMEOUT_MS = (5000 + 100), + CMN_REGISTRATION_REFRESH_MS = (1000) }; TEST(core_cpp_util, GetTopics) @@ -69,6 +69,9 @@ TEST(core_cpp_util, GetTopics) // this should trigger a warning but not increase map size eCAL::CSubscriber sub12("B1", info_B1_2); + // let's register + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); + // get all topics eCAL::Util::GetTopics(topic_info_map); @@ -116,7 +119,7 @@ TEST(core_cpp_util, GetTopics) } // let's unregister - eCAL::Process::SleepMS(CMN_REGISTRATION_REFRESH_MS); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // get all topics again, now all topics // should be removed from the map @@ -132,7 +135,7 @@ TEST(core_cpp_util, GetTopics) TEST(core_cpp_util, GetTopicsParallel) { constexpr const int max_publisher_count(2000); - constexpr const int waiting_time_thread(1000); + constexpr const int waiting_time_thread(4000); constexpr const int parallel_threads(1); // initialize eCAL API