From b3023aeddfacff6f87161cd8e2de12a7d65d4654 Mon Sep 17 00:00:00 2001 From: Rex Schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:24:37 +0100 Subject: [PATCH] [core] get service id implementation (#1875) * implement GetServiceId of CServiceClient and CServiceServer --- ecal/core/include/ecal/ecal_client.h | 5 +---- ecal/core/include/ecal/ecal_registration.h | 3 +-- ecal/core/include/ecal/ecal_server.h | 5 +---- ecal/core/include/ecal/ecal_types.h | 16 ++++++++++++++++ ecal/core/src/service/ecal_service_client.cpp | 6 +++--- .../src/service/ecal_service_client_impl.cpp | 12 ++++++++++++ ecal/core/src/service/ecal_service_client_impl.h | 3 +++ ecal/core/src/service/ecal_service_server.cpp | 6 +++--- .../src/service/ecal_service_server_impl.cpp | 12 ++++++++++++ ecal/core/src/service/ecal_service_server_impl.h | 3 +++ 10 files changed, 55 insertions(+), 16 deletions(-) diff --git a/ecal/core/include/ecal/ecal_client.h b/ecal/core/include/ecal/ecal_client.h index d72c95c4b7..cfe1685c1c 100644 --- a/ecal/core/include/ecal/ecal_client.h +++ b/ecal/core/include/ecal/ecal_client.h @@ -145,11 +145,8 @@ namespace eCAL * * @return The service id. **/ - - // TODO: Implement this - 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 25a95edada..a5c5dd4826 100644 --- a/ecal/core/include/ecal/ecal_server.h +++ b/ecal/core/include/ecal/ecal_server.h @@ -121,11 +121,8 @@ namespace eCAL * * @return The service id. **/ - - // TODO: Implement this - 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 0cb0a370a3..f985e611fa 100644 --- a/ecal/core/include/ecal/ecal_types.h +++ b/ecal/core/include/ecal/ecal_types.h @@ -154,6 +154,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 c29aba46f2..40803a9f9c 100644 --- a/ecal/core/src/service/ecal_service_client.cpp +++ b/ecal/core/src/service/ecal_service_client.cpp @@ -184,10 +184,10 @@ namespace eCAL return m_service_client_impl->GetServiceName(); } - Registration::SServiceMethodId CServiceClient::GetServiceId() const + Registration::SServiceId CServiceClient::GetServiceId() const { - // TODO: Implement this - return Registration::SServiceMethodId(); + if (m_service_client_impl == nullptr) return Registration::SServiceId(); + 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 c4ef2eba34..6bd435a265 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -366,6 +366,18 @@ namespace eCAL return GetRegistrationSample(); } + Registration::SServiceId CServiceClientImpl::GetServiceId() const + { + 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; + + 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 787a246b84..e6f25e1d7b 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::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 fda2e33d92..e41cecf022 100644 --- a/ecal/core/src/service/ecal_service_server.cpp +++ b/ecal/core/src/service/ecal_service_server.cpp @@ -80,10 +80,10 @@ namespace eCAL return m_service_server_impl->GetServiceName(); } - Registration::SServiceMethodId CServiceServer::GetServiceId() const + Registration::SServiceId CServiceServer::GetServiceId() const { - // TODO: Implement this - return Registration::SServiceMethodId(); + if (m_service_server_impl == nullptr) return Registration::SServiceId(); + 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 73bacbd2d4..4d492e3e27 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -152,6 +152,18 @@ namespace eCAL return GetRegistrationSample(); } + Registration::SServiceId CServiceServerImpl::GetServiceId() const + { + 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; + + 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 19b6784a8d..72e65c0e5e 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::SServiceId GetServiceId() const; + // Retrieves the service name std::string GetServiceName() const;