From f499437a13e1ba5f31722535b97bd9892748692b Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Tue, 7 Jan 2025 09:40:44 +0100 Subject: [PATCH 1/3] implement GetServiceId of CServiceClient and CServiceServer --- ecal/core/include/ecal/ecal_client.h | 3 --- ecal/core/include/ecal/ecal_server.h | 3 --- ecal/core/src/service/ecal_service_client.cpp | 4 ++-- ecal/core/src/service/ecal_service_client_impl.cpp | 14 ++++++++++++++ ecal/core/src/service/ecal_service_client_impl.h | 3 +++ ecal/core/src/service/ecal_service_server.cpp | 4 ++-- ecal/core/src/service/ecal_service_server_impl.cpp | 14 ++++++++++++++ ecal/core/src/service/ecal_service_server_impl.h | 3 +++ 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/ecal/core/include/ecal/ecal_client.h b/ecal/core/include/ecal/ecal_client.h index d72c95c4b7..db6640a8a1 100644 --- a/ecal/core/include/ecal/ecal_client.h +++ b/ecal/core/include/ecal/ecal_client.h @@ -145,9 +145,6 @@ namespace eCAL * * @return The service id. **/ - - // TODO: Implement this - ECAL_API_EXPORTED_MEMBER Registration::SServiceMethodId GetServiceId() const; diff --git a/ecal/core/include/ecal/ecal_server.h b/ecal/core/include/ecal/ecal_server.h index 25a95edada..09342ad0ea 100644 --- a/ecal/core/include/ecal/ecal_server.h +++ b/ecal/core/include/ecal/ecal_server.h @@ -121,9 +121,6 @@ namespace eCAL * * @return The service id. **/ - - // TODO: Implement this - ECAL_API_EXPORTED_MEMBER Registration::SServiceMethodId GetServiceId() const; diff --git a/ecal/core/src/service/ecal_service_client.cpp b/ecal/core/src/service/ecal_service_client.cpp index c29aba46f2..4463c56aeb 100644 --- a/ecal/core/src/service/ecal_service_client.cpp +++ b/ecal/core/src/service/ecal_service_client.cpp @@ -186,8 +186,8 @@ namespace eCAL Registration::SServiceMethodId CServiceClient::GetServiceId() const { - // TODO: Implement this - return Registration::SServiceMethodId(); + if (m_service_client_impl == nullptr) return Registration::SServiceMethodId(); + return m_service_client_impl->GetServiceId(); } bool CServiceClient::IsConnected() const diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index 961a495e43..b33076f588 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -368,6 +368,20 @@ namespace eCAL return GetRegistrationSample(); } + Registration::SServiceMethodId CServiceClientImpl::GetServiceId() const + { + Registration::SServiceMethodId service_id; + + service_id.service_id.entity_id = m_client_id; + service_id.service_id.entity_id = Process::GetProcessID(); + service_id.service_id.host_name = Process::GetHostName(); + + service_id.service_name = m_service_name; + service_id.method_name = ""; + + return service_id; + } + std::string CServiceClientImpl::GetServiceName() const { return m_service_name; diff --git a/ecal/core/src/service/ecal_service_client_impl.h b/ecal/core/src/service/ecal_service_client_impl.h index f0bffdc0ce..69c88d6552 100644 --- a/ecal/core/src/service/ecal_service_client_impl.h +++ b/ecal/core/src/service/ecal_service_client_impl.h @@ -78,6 +78,9 @@ namespace eCAL // Called by the registration provider to get a registration sample Registration::Sample GetRegistration(); + // Retrieves the service id + Registration::SServiceMethodId GetServiceId() const; + // Retrieves the service name std::string GetServiceName() const; diff --git a/ecal/core/src/service/ecal_service_server.cpp b/ecal/core/src/service/ecal_service_server.cpp index fda2e33d92..3e3e2bf128 100644 --- a/ecal/core/src/service/ecal_service_server.cpp +++ b/ecal/core/src/service/ecal_service_server.cpp @@ -82,8 +82,8 @@ namespace eCAL Registration::SServiceMethodId CServiceServer::GetServiceId() const { - // TODO: Implement this - return Registration::SServiceMethodId(); + if (m_service_server_impl == nullptr) return Registration::SServiceMethodId(); + return m_service_server_impl->GetServiceId(); } bool CServiceServer::IsConnected() diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 6be955148f..c09714b238 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -152,6 +152,20 @@ namespace eCAL return GetRegistrationSample(); } + Registration::SServiceMethodId CServiceServerImpl::GetServiceId() const + { + Registration::SServiceMethodId service_id; + + service_id.service_id.entity_id = m_service_id; + service_id.service_id.entity_id = Process::GetProcessID(); + service_id.service_id.host_name = Process::GetHostName(); + + service_id.service_name = m_service_name; + service_id.method_name = ""; + + return service_id; + } + std::string CServiceServerImpl::GetServiceName() const { return m_service_name; diff --git a/ecal/core/src/service/ecal_service_server_impl.h b/ecal/core/src/service/ecal_service_server_impl.h index be5ad0c44d..55b95db855 100644 --- a/ecal/core/src/service/ecal_service_server_impl.h +++ b/ecal/core/src/service/ecal_service_server_impl.h @@ -67,6 +67,9 @@ namespace eCAL // Called by the registration provider to get a registration sample Registration::Sample GetRegistration(); + // Retrieves the service id + Registration::SServiceMethodId GetServiceId() const; + // Retrieves the service name std::string GetServiceName() const; From 6a72da4fef30bffbb859f736c215d96b9d60c687 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:29:43 +0100 Subject: [PATCH 2/3] entity_id -> process_id --- ecal/core/src/service/ecal_service_client_impl.cpp | 6 +++--- ecal/core/src/service/ecal_service_server_impl.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index b33076f588..8b650de670 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -372,9 +372,9 @@ namespace eCAL { Registration::SServiceMethodId service_id; - service_id.service_id.entity_id = m_client_id; - service_id.service_id.entity_id = Process::GetProcessID(); - service_id.service_id.host_name = Process::GetHostName(); + service_id.service_id.entity_id = m_client_id; + service_id.service_id.process_id = Process::GetProcessID(); + service_id.service_id.host_name = Process::GetHostName(); service_id.service_name = m_service_name; service_id.method_name = ""; diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index c09714b238..a71696ead0 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -156,9 +156,9 @@ namespace eCAL { Registration::SServiceMethodId service_id; - service_id.service_id.entity_id = m_service_id; - service_id.service_id.entity_id = Process::GetProcessID(); - service_id.service_id.host_name = Process::GetHostName(); + service_id.service_id.entity_id = m_service_id; + service_id.service_id.process_id = Process::GetProcessID(); + service_id.service_id.host_name = Process::GetHostName(); service_id.service_name = m_service_name; service_id.method_name = ""; From 08710342ab123bf56346fdf11a0d8d72e764333a Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:17:35 +0100 Subject: [PATCH 3/3] introduce new type SServiceId (without method name field) to not use SServiceMethodId type when method name is not needed --- ecal/core/include/ecal/ecal_client.h | 2 +- ecal/core/include/ecal/ecal_registration.h | 3 +-- ecal/core/include/ecal/ecal_server.h | 2 +- ecal/core/include/ecal/ecal_types.h | 16 ++++++++++++++++ ecal/core/src/service/ecal_service_client.cpp | 4 ++-- .../src/service/ecal_service_client_impl.cpp | 8 +++----- ecal/core/src/service/ecal_service_client_impl.h | 2 +- ecal/core/src/service/ecal_service_server.cpp | 4 ++-- .../src/service/ecal_service_server_impl.cpp | 8 +++----- ecal/core/src/service/ecal_service_server_impl.h | 2 +- 10 files changed, 31 insertions(+), 20 deletions(-) diff --git a/ecal/core/include/ecal/ecal_client.h b/ecal/core/include/ecal/ecal_client.h index db6640a8a1..cfe1685c1c 100644 --- a/ecal/core/include/ecal/ecal_client.h +++ b/ecal/core/include/ecal/ecal_client.h @@ -146,7 +146,7 @@ namespace eCAL * @return The service id. **/ ECAL_API_EXPORTED_MEMBER - Registration::SServiceMethodId GetServiceId() const; + Registration::SServiceId GetServiceId() const; /** * @brief Check connection to at least one service. diff --git a/ecal/core/include/ecal/ecal_registration.h b/ecal/core/include/ecal/ecal_registration.h index b477441273..233c41f815 100644 --- a/ecal/core/include/ecal/ecal_registration.h +++ b/ecal/core/include/ecal/ecal_registration.h @@ -57,8 +57,7 @@ namespace eCAL deleted_entity //!< Represents a deletion of an entity }; - using TopicIDCallbackT = std::function; - using ServiceIDCallbackT = std::function; + using TopicIDCallbackT = std::function; /** * @brief Get complete snapshot of all known publisher. diff --git a/ecal/core/include/ecal/ecal_server.h b/ecal/core/include/ecal/ecal_server.h index 09342ad0ea..a5c5dd4826 100644 --- a/ecal/core/include/ecal/ecal_server.h +++ b/ecal/core/include/ecal/ecal_server.h @@ -122,7 +122,7 @@ namespace eCAL * @return The service id. **/ ECAL_API_EXPORTED_MEMBER - Registration::SServiceMethodId GetServiceId() const; + Registration::SServiceId GetServiceId() const; /** * @brief Check connection state. diff --git a/ecal/core/include/ecal/ecal_types.h b/ecal/core/include/ecal/ecal_types.h index e4883af14c..c44fced4cc 100644 --- a/ecal/core/include/ecal/ecal_types.h +++ b/ecal/core/include/ecal/ecal_types.h @@ -151,6 +151,22 @@ namespace eCAL return os; } + struct SServiceId + { + SEntityId service_id; + std::string service_name; + + bool operator==(const SServiceId& other) const + { + return service_id == other.service_id && service_name == other.service_name; + } + + bool operator<(const SServiceId& other) const + { + return std::tie(service_id, service_name) < std::tie(other.service_id, other.service_name); + } + }; + struct SServiceMethodId { SEntityId service_id; diff --git a/ecal/core/src/service/ecal_service_client.cpp b/ecal/core/src/service/ecal_service_client.cpp index 4463c56aeb..40803a9f9c 100644 --- a/ecal/core/src/service/ecal_service_client.cpp +++ b/ecal/core/src/service/ecal_service_client.cpp @@ -184,9 +184,9 @@ namespace eCAL return m_service_client_impl->GetServiceName(); } - Registration::SServiceMethodId CServiceClient::GetServiceId() const + Registration::SServiceId CServiceClient::GetServiceId() const { - if (m_service_client_impl == nullptr) return Registration::SServiceMethodId(); + if (m_service_client_impl == nullptr) return Registration::SServiceId(); return m_service_client_impl->GetServiceId(); } diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index 8b650de670..edf4c6e1b2 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -368,16 +368,14 @@ namespace eCAL return GetRegistrationSample(); } - Registration::SServiceMethodId CServiceClientImpl::GetServiceId() const + Registration::SServiceId CServiceClientImpl::GetServiceId() const { - Registration::SServiceMethodId service_id; + Registration::SServiceId service_id; service_id.service_id.entity_id = m_client_id; service_id.service_id.process_id = Process::GetProcessID(); service_id.service_id.host_name = Process::GetHostName(); - - service_id.service_name = m_service_name; - service_id.method_name = ""; + service_id.service_name = m_service_name; return service_id; } diff --git a/ecal/core/src/service/ecal_service_client_impl.h b/ecal/core/src/service/ecal_service_client_impl.h index 69c88d6552..2a98718860 100644 --- a/ecal/core/src/service/ecal_service_client_impl.h +++ b/ecal/core/src/service/ecal_service_client_impl.h @@ -79,7 +79,7 @@ namespace eCAL Registration::Sample GetRegistration(); // Retrieves the service id - Registration::SServiceMethodId GetServiceId() const; + Registration::SServiceId GetServiceId() const; // Retrieves the service name std::string GetServiceName() const; diff --git a/ecal/core/src/service/ecal_service_server.cpp b/ecal/core/src/service/ecal_service_server.cpp index 3e3e2bf128..e41cecf022 100644 --- a/ecal/core/src/service/ecal_service_server.cpp +++ b/ecal/core/src/service/ecal_service_server.cpp @@ -80,9 +80,9 @@ namespace eCAL return m_service_server_impl->GetServiceName(); } - Registration::SServiceMethodId CServiceServer::GetServiceId() const + Registration::SServiceId CServiceServer::GetServiceId() const { - if (m_service_server_impl == nullptr) return Registration::SServiceMethodId(); + if (m_service_server_impl == nullptr) return Registration::SServiceId(); return m_service_server_impl->GetServiceId(); } diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index a71696ead0..50fea1f0e7 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -152,16 +152,14 @@ namespace eCAL return GetRegistrationSample(); } - Registration::SServiceMethodId CServiceServerImpl::GetServiceId() const + Registration::SServiceId CServiceServerImpl::GetServiceId() const { - Registration::SServiceMethodId service_id; + Registration::SServiceId service_id; service_id.service_id.entity_id = m_service_id; service_id.service_id.process_id = Process::GetProcessID(); service_id.service_id.host_name = Process::GetHostName(); - - service_id.service_name = m_service_name; - service_id.method_name = ""; + service_id.service_name = m_service_name; return service_id; } diff --git a/ecal/core/src/service/ecal_service_server_impl.h b/ecal/core/src/service/ecal_service_server_impl.h index 55b95db855..48aca677b6 100644 --- a/ecal/core/src/service/ecal_service_server_impl.h +++ b/ecal/core/src/service/ecal_service_server_impl.h @@ -68,7 +68,7 @@ namespace eCAL Registration::Sample GetRegistration(); // Retrieves the service id - Registration::SServiceMethodId GetServiceId() const; + Registration::SServiceId GetServiceId() const; // Retrieves the service name std::string GetServiceName() const;