Skip to content

Commit

Permalink
[core] get service id implementation (#1875)
Browse files Browse the repository at this point in the history
* implement GetServiceId of CServiceClient and CServiceServer
  • Loading branch information
rex-schilasky authored Jan 8, 2025
1 parent 47402d6 commit b3023ae
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 16 deletions.
5 changes: 1 addition & 4 deletions ecal/core/include/ecal/ecal_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions ecal/core/include/ecal/ecal_registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ namespace eCAL
deleted_entity //!< Represents a deletion of an entity
};

using TopicIDCallbackT = std::function<void(const STopicId&, RegistrationEventType)>;
using ServiceIDCallbackT = std::function<void(const SServiceMethodId&, RegistrationEventType)>;
using TopicIDCallbackT = std::function<void(const STopicId&, RegistrationEventType)>;

/**
* @brief Get complete snapshot of all known publisher.
Expand Down
5 changes: 1 addition & 4 deletions ecal/core/include/ecal/ecal_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions ecal/core/include/ecal/ecal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/service/ecal_service_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions ecal/core/src/service/ecal_service_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ecal/core/src/service/ecal_service_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/service/ecal_service_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions ecal/core/src/service/ecal_service_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ecal/core/src/service/ecal_service_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b3023ae

Please sign in to comment.