Class CServiceClient

Class Documentation

class CServiceClient

Service client wrapper class.

Public Functions

ECAL_API_EXPORTED_MEMBER CServiceClient(const std::string &service_name_, const ServiceMethodInformationSetT &method_information_set_ = ServiceMethodInformationSetT(), const ClientEventCallbackT &event_callback_ = ClientEventCallbackT())

Constructor.

Parameters:
  • service_name_ – Unique service name.

  • method_information_set_ – Set of method names and corresponding datatype information.

  • event_callback_ – The client event callback funtion.

virtual ECAL_API_EXPORTED_MEMBER ~CServiceClient()

Destructor.

CServiceClient(const CServiceClient&) = delete

CServiceClient are non-copyable.

CServiceClient &operator=(const CServiceClient&) = delete

CServiceClient are non-copyable.

ECAL_API_EXPORTED_MEMBER CServiceClient(CServiceClient &&rhs) noexcept

CServiceClient are move-enabled.

ECAL_API_EXPORTED_MEMBER CServiceClient & operator= (CServiceClient &&rhs) noexcept

CServiceClient are move-enabled.

ECAL_API_EXPORTED_MEMBER std::vector< CClientInstance > GetClientInstances () const

Get the client instances for all matching services.

Returns:

Vector of client instances

ECAL_API_EXPORTED_MEMBER bool CallWithResponse (const std::string &method_name_, const std::string &request_, ServiceResponseVecT &service_response_vec_, int timeout_ms_=DEFAULT_TIME_ARGUMENT) const

Blocking call of a service method for all existing service instances, response will be returned as ServiceResponseVecT.

This method calls all existing service instances of the service with the given method name and request string.

This method will block until all service calls have returned. In case that a timeout is specified, this method will wait for a service call response until the timeout is reached.

If a service call times out, it WILL NOT be cancelled (i.e. it may continue to execute in the background), but any responses that arrive will be ignored. Instead, the response vector will contain a service response element with: service_response.call_state == eCallState::timeouted.

Changes with eCAL 6.1: In eCAL 6.0 and earlier, the response vector did not contain responses for timeouted calls. Instead, a timeout event was called. Beginning with eCAL 6.1, this function DOES include responses for timeouted calls in the response vector.

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • service_response_vec_[out] Response vector containing service responses from every called service (null pointer == no response).

  • timeout_ms_ – Maximum time before operation returns (in milliseconds. 0 or negative values mean infinite).

Returns:

True if all calls were successful and minimum one instance was connected, otherwise false.

ECAL_API_EXPORTED_MEMBER bool CallWithCallback (const std::string &method_name_, const std::string &request_, const ResponseCallbackT &response_callback_, int timeout_ms_=DEFAULT_TIME_ARGUMENT) const

Blocking call (with timeout) of a service method for all existing service instances, using callback.

This method calls all existing service instances of the service with the given method name and request string.

This method will block until all service calls have returned, AND their response callbacks have been executed. In case that a timeout is specified, this method will wait for a service call response until the timeout is reached. This method MAY block longer than the specified timeout, as it also waits for the response callbacks to be executed.

If a service call times out, it WILL NOT be cancelled (i.e. it will continue to execute in the background), but any responses that arrive will be ignored. Instead, the response callback will be called with an eCAL::SServiceResponse, where service_response.call_state == eCallState::timeouted.

Changes with eCAL 6.1: In eCAL 6.0 and earlier, the response callback was NOT called in case of timeouts. Instead, a timeout event was called. Beginning with eCAL 6.1, the response callback IS called in case of timeouts

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • response_callback_ – Callback function for the service method response.

  • timeout_ms_ – Maximum time before operation returns (in milliseconds. 0 or negative values mean infinite).

Returns:

True if all calls were successful and minimum one instance was connected, otherwise false.

ECAL_API_EXPORTED_MEMBER bool CallWithCallbackAsync (const std::string &method_name_, const std::string &request_, const ResponseCallbackT &response_callback_) const

Asynchronous call of a service method for all existing service instances, using callback.

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • response_callback_ – Callback function for the service method response.

Returns:

True if all calls were successful and minimum one instance was connected, otherwise false.

ECAL_API_EXPORTED_MEMBER const std::string & GetServiceName () const

Retrieve service name.

Returns:

The service name.

ECAL_API_EXPORTED_MEMBER const SServiceId & GetServiceId () const

Retrieve the service id.

Returns:

The service id.

ECAL_API_EXPORTED_MEMBER bool IsConnected () const

Check connection to at least one service.

Returns:

True if at least one service client instance is connected.

ECAL_API_EXPORTED_MEMBER CServiceClient()

Constructor.

explicit ECAL_API_EXPORTED_MEMBER CServiceClient(const std::string &service_name_)

Constructor.

Parameters:

service_name_ – Unique service name.

explicit ECAL_API_EXPORTED_MEMBER CServiceClient(const std::string &service_name_, const ServiceMethodInformationSetT &method_information_map_)

Constructor.

Parameters:
  • service_name_ – Unique service name.

  • method_information_map_ – Map of method names and corresponding datatype information.

virtual ECAL_API_EXPORTED_MEMBER ~CServiceClient()

Destructor.

CServiceClient(const CServiceClient&) = delete

CServiceClients are non-copyable.

CServiceClient &operator=(const CServiceClient&) = delete

CServiceClients are non-copyable.

ECAL_API_EXPORTED_MEMBER bool Create (const std::string &service_name_)

Creates this object.

Parameters:

service_name_ – Unique service name.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool Create (const std::string &service_name_, const ServiceMethodInformationSetT &method_information_map_)

Creates this object.

Parameters:
  • service_name_ – Unique service name.

  • method_information_map_ – Map of method names and corresponding datatype information.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool Destroy ()

Destroys this object.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool SetHostName (const std::string &host_name_)

Change the host name filter for that client instance.

Parameters:

host_name_ – Host name filter (empty == all hosts)

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool Call (const std::string &method_name_, const std::string &request_, int timeout_=-1)

Call a method of this service, responses will be returned by callback.

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • timeout_ – Maximum time before operation returns (in milliseconds, -1 means infinite).

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool Call (const std::string &method_name_, const std::string &request_, int timeout_, ServiceResponseVecT *service_response_vec_)

Call a method of this service, all responses will be returned in service_response_vec_.

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • timeout_ – Maximum time before operation returns (in milliseconds, -1 means infinite).

  • service_response_vec_[out] Response vector containing service responses from every called service (null pointer == no response).

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool CallAsync (const std::string &method_name_, const std::string &request_, int timeout_=-1)

Call a method of this service asynchronously, responses will be returned by callback.

Parameters:
  • method_name_ – Method name.

  • request_ – Request string.

  • timeout_ – Maximum time before operation returns (in milliseconds, -1 means infinite) - NOT SUPPORTED YET.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool AddResponseCallback (const ResponseCallbackT &callback_)

Add server response callback.

Parameters:

callback_ – Callback function for server response.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool RemResponseCallback ()

Remove server response callback.

Returns:

True if successful.

ECAL_API_EXPORTED_MEMBER bool AddEventCallback (eClientEvent type_, ClientEventCallbackT callback_)

Add client event callback function.

Parameters:
  • type_ – The event type to react on.

  • callback_ – The callback function to add.

Returns:

True if succeeded, false if not.

ECAL_API_EXPORTED_MEMBER bool RemEventCallback (eClientEvent type_)

Remove client event callback function.

Parameters:

type_ – The event type to remove.

Returns:

True if succeeded, false if not.

ECAL_API_EXPORTED_MEMBER std::string GetServiceName ()

Retrieve service name.

Returns:

The service name.

ECAL_API_EXPORTED_MEMBER bool IsConnected ()

Check connection state.

Returns:

True if connected, false if not.

Public Static Attributes

static constexpr ECAL_API_EXPORTED_MEMBER long long DEFAULT_TIME_ARGUMENT   = -1

Use DEFAULT_TIME_ARGUMENT in the CallWithResponse() and CallWithCallback() functions for blocking calls