Skip to content

Commit

Permalink
commenting and whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Dec 3, 2024
1 parent 56041ba commit a41504d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 196 deletions.
4 changes: 1 addition & 3 deletions ecal/core/include/ecal/ecal_client_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include <memory>
#include <string>

#pragma once

namespace eCAL
{
class CServiceClientImpl;
Expand Down Expand Up @@ -111,7 +109,7 @@ namespace eCAL
Registration::SEntityId GetClientID() const;

private:
Registration::SEntityId m_entity_id;
Registration::SEntityId m_entity_id;
const std::shared_ptr<eCAL::CServiceClientImpl> m_service_client_impl;
};
}
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/ecal_client_v5.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

/**
* @file ecal_client.h
* @brief eCAL client interface
* @file ecal_client_v5.h
* @brief eCAL client interface (deprecated eCAL5 version)
**/

#pragma once
Expand Down
63 changes: 2 additions & 61 deletions ecal/core/src/service/ecal_service_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@
**/

#include <ecal/ecal.h>
#include <string>

#include "ecal_clientgate.h"
#include "ecal_global_accessors.h"
#include "ecal_service_client_impl.h"

#include <string>

namespace eCAL
{
/**
* @brief Constructor.
*
* @param service_name_ Service name.
* @param method_information_map_ Map of method names and corresponding datatype information.
* @param event_callback_ The client event callback funtion.
**/
CServiceClient::CServiceClient(const std::string& service_name_, const ServiceMethodInformationMapT method_information_map_, const ClientEventIDCallbackT event_callback_)
{
// Create client implementation
Expand All @@ -49,9 +43,6 @@ namespace eCAL
}
}

/**
* @brief Destructor.
**/
CServiceClient::~CServiceClient()
{
// Unregister client
Expand All @@ -64,18 +55,12 @@ namespace eCAL
m_service_client_impl.reset();
}

/**
* @brief Move constructor
**/
CServiceClient::CServiceClient(CServiceClient&& rhs) noexcept
: m_service_client_impl(std::move(rhs.m_service_client_impl))
{
rhs.m_service_client_impl = nullptr;
}

/**
* @brief Move assignment operator
**/
CServiceClient& CServiceClient::operator=(CServiceClient&& rhs) noexcept
{
if (this != &rhs)
Expand All @@ -94,11 +79,6 @@ namespace eCAL
return *this;
}

/**
* @brief Get the client instances for all matching services
*
* @return Vector of client instances
**/
std::vector<CClientInstance> CServiceClient::GetClientInstances() const
{
std::vector<CClientInstance> instances;
Expand All @@ -112,16 +92,6 @@ namespace eCAL
return instances;
}

/**
* @brief Blocking call of a service method for all existing service instances, response will be returned as vector<pair<bool, SServiceReponse>>
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
* @param [out] service_response_vec_ Response vector containing service responses from every called service (null pointer == no response).
*
* @return True if all calls were successful.
**/
bool CServiceClient::CallWithResponse(const std::string& method_name_, const std::string& request_, int timeout_, ServiceResponseVecT& service_response_vec_) const
{
auto instances = GetClientInstances();
Expand Down Expand Up @@ -174,16 +144,6 @@ namespace eCAL
return overall_success;
}

/**
* @brief Blocking call (with timeout) of a service method for all existing service instances, using callback
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
* @param response_callback_ Callback function for the service method response.
*
* @return True if all calls were successful.
**/
bool CServiceClient::CallWithCallback(const std::string& method_name_, const std::string& request_, int timeout_, const ResponseIDCallbackT& response_callback_) const
{
auto instances = GetClientInstances();
Expand Down Expand Up @@ -219,15 +179,6 @@ namespace eCAL
return return_state;
}

/**
* @brief Asynchronous call of a service method for all existing service instances, using callback
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param response_callback_ Callback function for the service method response.
*
* @return True if all calls were successful.
**/
bool CServiceClient::CallWithCallbackAsync(const std::string& method_name_, const std::string& request_, const ResponseIDCallbackT& response_callback_) const
{
bool return_state = true;
Expand All @@ -239,21 +190,11 @@ namespace eCAL
return return_state;
}

/**
* @brief Retrieve service name.
*
* @return The service name.
**/
std::string CServiceClient::GetServiceName() const
{
return m_service_client_impl->GetServiceName();
}

/**
* @brief Check connection to at least one service.
*
* @return True if at least one service client instance is connected.
**/
bool CServiceClient::IsConnected() const
{
const auto instances = GetClientInstances();
Expand Down
1 change: 0 additions & 1 deletion ecal/core/src/service/ecal_service_client_v5_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ namespace eCAL
{
const std::lock_guard<std::mutex> lock(m_response_callback_mutex);
m_response_callback = nullptr;

}

return true;
Expand Down
168 changes: 39 additions & 129 deletions ecal/core/src/service/ecal_service_client_v5_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/

/**
* @file ecal_client.h
* @brief eCAL client interface
* @brief eCAL service client implementation (deprecated eCAL5 version)
**/

#pragma once
Expand All @@ -38,174 +37,85 @@ namespace eCAL
namespace v5
{
/**
* @brief Service client wrapper class.
* @brief Service client implementation class.
**/
class CServiceClientImpl
{
public:
/**
* @brief Constructor.
**/
// Default constructor for creating an empty service client instance.
CServiceClientImpl();

/**
* @brief Constructor.
*
* @param service_name_ Unique service name.
**/
// Constructor for creating a service client instance with a specific service name.
explicit CServiceClientImpl(const std::string& service_name_);

/**
* @brief Constructor.
*
* @param service_name_ Unique service name.
* @param method_information_map_ Map of method names and corresponding datatype information.
**/
// Constructor for creating a service client instance with a service name and method information map.
explicit CServiceClientImpl(const std::string& service_name_, const ServiceMethodInformationMapT& method_information_map_);

/**
* @brief Destructor.
**/
// Destructor to clean up resources.
virtual ~CServiceClientImpl();

/**
* @brief CServiceClients are non-copyable
**/
CServiceClientImpl(const CServiceClientImpl&) = delete;

/**
* @brief CServiceClients are non-copyable
**/
CServiceClientImpl& operator=(const CServiceClientImpl&) = delete;

/**
* @brief Creates this object.
*
* @param service_name_ Unique service name.
*
* @return True if successful.
**/
// Creates a service client with a specific service name.
bool Create(const std::string& service_name_);

/**
* @brief Creates this object.
*
* @param service_name_ Unique service name.
* @param method_information_map_ Map of method names and corresponding datatype information.
*
* @return True if successful.
**/
// Creates a service client with a specific service name and method information map.
bool Create(const std::string& service_name_, const ServiceMethodInformationMapT& method_information_map_);

/**
* @brief Destroys this object.
*
* @return True if successful.
**/
// Destroys the service client instance and releases resources.
bool Destroy();

/**
* @brief Change the host name filter for that client instance
*
* @param host_name_ Host name filter (empty == all hosts)
*
* @return True if successful.
**/
// Sets the host name filter for the service client instance.
bool SetHostName(const std::string& host_name_);

/**
* @brief Call a method of this service, responses will be returned by callback.
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
*
* @return True if successful.
**/
// Calls a method of the service and retrieves responses via callback.
bool Call(const std::string& method_name_, const std::string& request_, int timeout_ = -1);

/**
* @brief Call a method of this service, all responses will be returned in service_response_vec_.
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
* @param [out] service_response_vec_ Response vector containing service responses from every called service (null pointer == no response).
*
* @return True if successful.
**/
// Calls a method of the service and retrieves all responses in a vector.
bool Call(const std::string& method_name_, const std::string& request_, int timeout_, ServiceResponseVecT* service_response_vec_);

/**
* @brief Call a method of this service asynchronously, responses will be returned by callback.
*
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite) - NOT SUPPORTED YET.
*
* @return True if successful.
**/
// Makes an asynchronous call to a method of the service, responses are received via callback.
bool CallAsync(const std::string& method_name_, const std::string& request_, int timeout_ = -1);

/**
* @brief Add server response callback.
*
* @param callback_ Callback function for server response.
*
* @return True if successful.
**/
// Registers a callback function for server responses.
bool AddResponseCallback(const ResponseCallbackT& callback_);

/**
* @brief Remove server response callback.
*
* @return True if successful.
**/
// Removes the registered server response callback function.
bool RemResponseCallback();

/**
* @brief Add client event callback function.
*
* @param type_ The event type to react on.
* @param callback_ The callback function to add.
*
* @return True if succeeded, false if not.
**/
// Registers a callback function for a specific client event.
bool AddEventCallback(eCAL_Client_Event type_, ClientEventCallbackT callback_);

/**
* @brief Remove client event callback function.
*
* @param type_ The event type to remove.
*
* @return True if succeeded, false if not.
**/
// Removes the registered callback function for a specific client event.
bool RemEventCallback(eCAL_Client_Event type_);

/**
* @brief Retrieve service name.
*
* @return The service name.
**/
// Retrieves the name of the associated service.
std::string GetServiceName();

/**
* @brief Check connection state.
*
* @return True if connected, false if not.
**/
// Checks the connection state of the service client.
bool IsConnected();

protected:
std::shared_ptr<eCAL::CServiceClient> m_service_client_impl;
bool m_created;
std::string m_host_name;
// Prevent copy and move operations
CServiceClientImpl(const CServiceClientImpl&) = delete;
CServiceClientImpl& operator=(const CServiceClientImpl&) = delete;
CServiceClientImpl(CServiceClientImpl&&) = delete;
CServiceClientImpl& operator=(CServiceClientImpl&&) = delete;

private:
// Pointer to the underlying service client implementation
std::shared_ptr<eCAL::CServiceClient> m_service_client_impl;

// Indicates whether the client has been successfully created
bool m_created;

// Host name filter for the service client
std::string m_host_name;

std::mutex m_event_callback_map_mutex;
// Mutex and map for managing event callbacks
std::mutex m_event_callback_map_mutex;
std::map<eCAL_Client_Event, ClientEventCallbackT> m_event_callback_map;

std::mutex m_response_callback_mutex;
ResponseCallbackT m_response_callback;
// Mutex and callback for managing server responses
std::mutex m_response_callback_mutex;
ResponseCallbackT m_response_callback;
};
}
}

0 comments on commit a41504d

Please sign in to comment.