From 50f5b8198b3d4a7157a15a7ac91928849ec207c4 Mon Sep 17 00:00:00 2001 From: Kristof Hannemann <50989282+hannemn@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:13:28 +0100 Subject: [PATCH] [core] Removed AddRegistrationCallback API and its underlying code base (#1861) --- ecal/core/CMakeLists.txt | 4 +- .../include/ecal/cimpl/ecal_callback_cimpl.h | 13 -- ecal/core/include/ecal/ecal_callback.h | 8 -- ecal/core/include/ecal/ecal_process.h | 19 --- ecal/core/src/ecal_process.cpp | 18 --- .../ecal_registration_receiver.cpp | 15 -- .../registration/ecal_registration_receiver.h | 9 -- .../ecal_registration_sample_applier_user.cpp | 120 ---------------- .../ecal_registration_sample_applier_user.h | 57 -------- ecal/samples/CMakeLists.txt | 1 - .../monitoring/monitoring_reg/CMakeLists.txt | 44 ------ .../monitoring_reg/src/monitoring_reg.cpp | 135 ------------------ 12 files changed, 1 insertion(+), 442 deletions(-) delete mode 100644 ecal/core/src/registration/ecal_registration_sample_applier_user.cpp delete mode 100644 ecal/core/src/registration/ecal_registration_sample_applier_user.h delete mode 100644 ecal/samples/cpp/monitoring/monitoring_reg/CMakeLists.txt delete mode 100644 ecal/samples/cpp/monitoring/monitoring_reg/src/monitoring_reg.cpp diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 2b8412762b..e9f44f409e 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -296,9 +296,7 @@ if (ECAL_CORE_REGISTRATION) src/registration/ecal_registration_sample_applier.cpp src/registration/ecal_registration_sample_applier.h src/registration/ecal_registration_sample_applier_gates.cpp - src/registration/ecal_registration_sample_applier_gates.h - src/registration/ecal_registration_sample_applier_user.cpp - src/registration/ecal_registration_sample_applier_user.h + src/registration/ecal_registration_sample_applier_gates.h src/registration/ecal_registration_timeout_provider.cpp src/registration/ecal_registration_timeout_provider.h src/registration/ecal_registration_sender.h diff --git a/ecal/core/include/ecal/cimpl/ecal_callback_cimpl.h b/ecal/core/include/ecal/cimpl/ecal_callback_cimpl.h index b2e7b2d2cc..81efea5c5b 100644 --- a/ecal/core/include/ecal/cimpl/ecal_callback_cimpl.h +++ b/ecal/core/include/ecal/cimpl/ecal_callback_cimpl.h @@ -71,19 +71,6 @@ enum eCAL_Server_Event server_event_disconnected = 2, }; -/** - * @brief eCAL common registration event type. -**/ -enum eCAL_Registration_Event -{ - reg_event_none = 0, - reg_event_publisher = 1, - reg_event_subscriber = 2, - reg_event_service = 3, - reg_event_client = 5, - reg_event_process = 4, -}; - #ifdef _MSC_VER #pragma pack(push, 8) #endif diff --git a/ecal/core/include/ecal/ecal_callback.h b/ecal/core/include/ecal/ecal_callback.h index 0b993c43b3..65689936a6 100644 --- a/ecal/core/include/ecal/ecal_callback.h +++ b/ecal/core/include/ecal/ecal_callback.h @@ -146,14 +146,6 @@ namespace eCAL **/ using TimerCallbackT = std::function; - /** - * @brief Registration callback type. - * - * @param sample_ The sample protocol buffer registration payload buffer. - * @param sample_size_ The payload buffer size. - **/ - using RegistrationCallbackT = std::function; - /** * @brief Publisher event callback function type. (deprecated) * diff --git a/ecal/core/include/ecal/ecal_process.h b/ecal/core/include/ecal/ecal_process.h index cca66d526a..14dc037040 100644 --- a/ecal/core/include/ecal/ecal_process.h +++ b/ecal/core/include/ecal/ecal_process.h @@ -154,25 +154,6 @@ namespace eCAL **/ ECAL_API void SetState(eCAL_Process_eSeverity severity_, eCAL_Process_eSeverity_Level level_, const char* info_); - /** - * @brief Add registration callback. - * - * @param event_ The type of registration. - * @param callback_ The callback. - * - * @return Zero if succeeded. - **/ - ECAL_API int AddRegistrationCallback(enum eCAL_Registration_Event event_, const RegistrationCallbackT& callback_); - - /** - * @brief Remove registration callback. - * - * @param event_ The type of registration. - * - * @return Zero if succeeded. - **/ - ECAL_API int RemRegistrationCallback(enum eCAL_Registration_Event event_); - /** * @brief Start specified process (windows only). * diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 74ee39e770..475f79aa6a 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -298,24 +298,6 @@ namespace eCAL g_process_info = info_; } } - - int AddRegistrationCallback(enum eCAL_Registration_Event event_, const RegistrationCallbackT& callback_) - { -#if ECAL_CORE_REGISTRATION - if (g_registration_receiver() == nullptr) return -1; - if (g_registration_receiver()->AddRegistrationCallback(event_, callback_)) return 0; -#endif - return -1; - } - - int RemRegistrationCallback(enum eCAL_Registration_Event event_) - { -#if ECAL_CORE_REGISTRATION - if (g_registration_receiver() == nullptr) return -1; - if (g_registration_receiver()->RemRegistrationCallback(event_)) return 0; -#endif - return -1; - } } } diff --git a/ecal/core/src/registration/ecal_registration_receiver.cpp b/ecal/core/src/registration/ecal_registration_receiver.cpp index 8353ca4086..fb05e3d014 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.cpp +++ b/ecal/core/src/registration/ecal_registration_receiver.cpp @@ -65,11 +65,6 @@ namespace eCAL { Registration::CSampleApplierGates::ApplySample(sample_); }); - m_sample_applier.SetCustomApplySampleCallback("custom_registration", [this](const eCAL::Registration::Sample& sample_) - { - m_user_applier.ApplySample(sample_); - }); - } CRegistrationReceiver::~CRegistrationReceiver() @@ -138,16 +133,6 @@ namespace eCAL m_created = false; } - bool CRegistrationReceiver::AddRegistrationCallback(enum eCAL_Registration_Event event_, const RegistrationCallbackT& callback_) - { - return m_user_applier.AddRegistrationCallback(event_, callback_); - } - - bool CRegistrationReceiver::RemRegistrationCallback(enum eCAL_Registration_Event event_) - { - return m_user_applier.RemRegistrationCallback(event_); - } - void CRegistrationReceiver::SetCustomApplySampleCallback(const std::string& customer_, const ApplySampleCallbackT& callback_) { m_sample_applier.SetCustomApplySampleCallback(customer_, callback_); diff --git a/ecal/core/src/registration/ecal_registration_receiver.h b/ecal/core/src/registration/ecal_registration_receiver.h index e264e21c12..d67b9de6eb 100644 --- a/ecal/core/src/registration/ecal_registration_receiver.h +++ b/ecal/core/src/registration/ecal_registration_receiver.h @@ -33,7 +33,6 @@ #include "serialization/ecal_struct_sample_registration.h" #include "registration/ecal_registration_sample_applier.h" #include "registration/ecal_registration_sample_applier_gates.h" -#include "registration/ecal_registration_sample_applier_user.h" #include "config/attributes/registration_attributes.h" #include @@ -67,9 +66,6 @@ namespace eCAL void Start(); void Stop(); - bool AddRegistrationCallback(enum eCAL_Registration_Event event_, const RegistrationCallbackT& callback_); - bool RemRegistrationCallback(enum eCAL_Registration_Event event_); - using ApplySampleCallbackT = std::function; void SetCustomApplySampleCallback(const std::string& customer_, const ApplySampleCallbackT& callback_); void RemCustomApplySampleCallback(const std::string& customer_); @@ -90,11 +86,6 @@ namespace eCAL // This class distributes samples to all everyone who is interested in being notified about samples Registration::CSampleApplier m_sample_applier; - // These classes are interested in being notified about samples - // Possibly remove these from this class - // The custom user callbacks (who receive serialized samples), e.g. registration events. - Registration::CSampleApplierUser m_user_applier; - Registration::SAttributes m_attributes; }; } diff --git a/ecal/core/src/registration/ecal_registration_sample_applier_user.cpp b/ecal/core/src/registration/ecal_registration_sample_applier_user.cpp deleted file mode 100644 index 0edae0f70e..0000000000 --- a/ecal/core/src/registration/ecal_registration_sample_applier_user.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* ========================= eCAL LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ========================= eCAL LICENSE ================================= -*/ - -#include "registration/ecal_registration_sample_applier_user.h" -#include "serialization/ecal_serialize_sample_registration.h" - -namespace eCAL -{ - namespace Registration - { - bool CSampleApplierUser::AddRegistrationCallback(eCAL_Registration_Event event_, const RegistrationCallbackT& callback_) - { - switch (event_) - { - case reg_event_publisher: - m_callback_pub = callback_; - return true; - case reg_event_subscriber: - m_callback_sub = callback_; - return true; - case reg_event_service: - m_callback_service = callback_; - return true; - case reg_event_client: - m_callback_client = callback_; - return true; - case reg_event_process: - m_callback_process = callback_; - return true; - default: - return false; - } - } - - bool CSampleApplierUser::RemRegistrationCallback(eCAL_Registration_Event event_) - { - switch (event_) - { - case reg_event_publisher: - m_callback_pub = nullptr; - return true; - case reg_event_subscriber: - m_callback_sub = nullptr; - return true; - case reg_event_service: - m_callback_service = nullptr; - return true; - case reg_event_client: - m_callback_client = nullptr; - return true; - case reg_event_process: - m_callback_process = nullptr; - return true; - default: - return false; - } - } - - void CSampleApplierUser::ApplySample(const eCAL::Registration::Sample& sample_) - { - RegistrationCallbackT reg_callback(nullptr); - switch (sample_.cmd_type) - { - case bct_none: - case bct_set_sample: - break; - case bct_reg_process: - case bct_unreg_process: - // unregistration event not implemented currently - reg_callback = m_callback_process; - break; - case bct_reg_service: - case bct_unreg_service: - reg_callback = m_callback_service; - break; - case bct_reg_client: - case bct_unreg_client: - // current client implementation doesn't need that information - reg_callback = m_callback_client; - break; - case bct_reg_subscriber: - case bct_unreg_subscriber: - reg_callback = m_callback_sub; - break; - case bct_reg_publisher: - case bct_unreg_publisher: - reg_callback = m_callback_pub; - break; - default: - break; - } - - // call user registration callback - if (reg_callback) - { - std::string reg_sample; - if (SerializeToBuffer(sample_, reg_sample)) - { - reg_callback(reg_sample.c_str(), static_cast(reg_sample.size())); - } - } - } - } -} \ No newline at end of file diff --git a/ecal/core/src/registration/ecal_registration_sample_applier_user.h b/ecal/core/src/registration/ecal_registration_sample_applier_user.h deleted file mode 100644 index f6fcd1f07d..0000000000 --- a/ecal/core/src/registration/ecal_registration_sample_applier_user.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ========================= 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 eCAL registration receiver - * - * Receives registration information from the sample applier and forwards them to - * user defined callbacks. -**/ - -#pragma once - -#include -#include - -#include "serialization/ecal_struct_sample_registration.h" - -namespace eCAL -{ - namespace Registration - { - class CSampleApplierUser - { - public: - bool AddRegistrationCallback(enum eCAL_Registration_Event event_, const RegistrationCallbackT& callback_); - bool RemRegistrationCallback(enum eCAL_Registration_Event event_); - - void ApplySample(const eCAL::Registration::Sample& sample_); - - private: - // in the future this may be stored in a map? or somehow differently - RegistrationCallbackT m_callback_pub = nullptr; - RegistrationCallbackT m_callback_sub = nullptr; - RegistrationCallbackT m_callback_service = nullptr; - RegistrationCallbackT m_callback_client = nullptr; - RegistrationCallbackT m_callback_process = nullptr; - - // protect by mutexes? very likeley need to! - }; - } -} diff --git a/ecal/samples/CMakeLists.txt b/ecal/samples/CMakeLists.txt index eb751a33bd..da990bd041 100644 --- a/ecal/samples/CMakeLists.txt +++ b/ecal/samples/CMakeLists.txt @@ -84,7 +84,6 @@ if(ECAL_CORE_MONITORING) add_subdirectory(cpp/monitoring/monitoring_performance) if(ECAL_CORE_HAS_PROTOBUF) add_subdirectory(cpp/monitoring/monitoring_rec) - add_subdirectory(cpp/monitoring/monitoring_reg) endif() endif() diff --git a/ecal/samples/cpp/monitoring/monitoring_reg/CMakeLists.txt b/ecal/samples/cpp/monitoring/monitoring_reg/CMakeLists.txt deleted file mode 100644 index 43a3318540..0000000000 --- a/ecal/samples/cpp/monitoring/monitoring_reg/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# ========================= 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 ================================= - -cmake_minimum_required(VERSION 3.10) - -set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) - -project(monitoring_reg) - -find_package(eCAL REQUIRED) -find_package(Protobuf REQUIRED) - -set(monitoring_reg_src - src/monitoring_reg.cpp -) - -ecal_add_sample(${PROJECT_NAME} ${monitoring_reg_src}) - -target_link_libraries(${PROJECT_NAME} - eCAL::core - eCAL::core_pb - protobuf::libprotobuf -) - -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) - -ecal_install_sample(${PROJECT_NAME}) - -set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/monitoring) diff --git a/ecal/samples/cpp/monitoring/monitoring_reg/src/monitoring_reg.cpp b/ecal/samples/cpp/monitoring/monitoring_reg/src/monitoring_reg.cpp deleted file mode 100644 index 5504aa6004..0000000000 --- a/ecal/samples/cpp/monitoring/monitoring_reg/src/monitoring_reg.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* ========================= 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 ================================= -*/ - -#include - -#include - -#ifdef _MSC_VER -#pragma warning(push, 0) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -void OnProcessRegistration(const char* sample_, int sample_size_) -{ - eCAL::pb::Sample sample; - if (sample.ParseFromArray(sample_, sample_size_)) - { - std::cout << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << "Process Registration" << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << sample.DebugString(); - std::cout << std::endl; - } -} - -void OnServiceRegistration(const char* sample_, int sample_size_) -{ - eCAL::pb::Sample sample; - if (sample.ParseFromArray(sample_, sample_size_)) - { - std::cout << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << "Service Registration" << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << sample.DebugString(); - std::cout << std::endl; - } -} - -void OnClientRegistration(const char* sample_, int sample_size_) -{ - eCAL::pb::Sample sample; - if (sample.ParseFromArray(sample_, sample_size_)) - { - std::cout << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << "Client Registration" << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << sample.DebugString(); - std::cout << std::endl; - } -} - -void OnSubscriberRegistration(const char* sample_, int sample_size_) -{ - eCAL::pb::Sample sample; - if (sample.ParseFromArray(sample_, sample_size_)) - { - std::cout << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << "Subscriber Registration" << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << sample.DebugString(); - std::cout << std::endl; - } -} - -void OnPublisherRegistration(const char* sample_, int sample_size_) -{ - eCAL::pb::Sample sample; - if (sample.ParseFromArray(sample_, sample_size_)) - { - std::cout << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << "Publisher Registration" << std::endl; - std::cout << "----------------------------------" << std::endl; - std::cout << sample.DebugString(); - std::cout << std::endl; - } -} - -int main() -{ - // initialize eCAL API - eCAL::Initialize("monitoring registrations", eCAL::Init::None); - - // set process state - eCAL::Process::SetState(proc_sev_healthy, proc_sev_level1, "I feel good !"); - - // add process register callback function - eCAL::Process::AddRegistrationCallback(reg_event_process, std::bind(OnProcessRegistration, std::placeholders::_1, std::placeholders::_2)); - - // add service register callback function - eCAL::Process::AddRegistrationCallback(reg_event_service, std::bind(OnServiceRegistration, std::placeholders::_1, std::placeholders::_2)); - - // add client register callback function - eCAL::Process::AddRegistrationCallback(reg_event_client, std::bind(OnClientRegistration, std::placeholders::_1, std::placeholders::_2)); - - // add subscriber register callback function - eCAL::Process::AddRegistrationCallback(reg_event_subscriber, std::bind(OnSubscriberRegistration, std::placeholders::_1, std::placeholders::_2)); - - // add publisher register callback function - eCAL::Process::AddRegistrationCallback(reg_event_publisher, std::bind(OnPublisherRegistration, std::placeholders::_1, std::placeholders::_2)); - - while(eCAL::Ok()) - { - // sleep 100 ms - eCAL::Process::SleepMS(100); - } - - // finalize eCAL API - eCAL::Finalize(); - - return(0); -}