SmartSoft Component-Developer API
Public Member Functions | List of all members
Smart::IQueryClientPattern< RequestType, AnswerType > Class Template Referenceabstract

The client part of Query pattern to perform two-way (request-response) communication. More...

#include <smartIQueryClientPattern_T.h>

Inheritance diagram for Smart::IQueryClientPattern< RequestType, AnswerType >:
Smart::IClientPattern Smart::ICommunicationPattern Smart::IShutdownObserver

Public Member Functions

 IQueryClientPattern (IComponent *component)
 Constructor (not wired with any service provider). More...
 
 IQueryClientPattern (IComponent *component, const std::string &server, const std::string &service)
 Connection Constructor (implicitly wiring with specified service provider). More...
 
virtual ~IQueryClientPattern ()
 Destructor. More...
 
virtual StatusCode query (const RequestType &request, AnswerType &answer)
 Blocking Query. More...
 
virtual StatusCode queryRequest (const RequestType &request, QueryIdPtr &id)=0
 Asynchronous Query. More...
 
virtual StatusCode queryReceive (const QueryIdPtr id, AnswerType &answer)=0
 Check if answer is available. More...
 
virtual StatusCode queryReceiveWait (const QueryIdPtr id, AnswerType &answer, const Duration &timeout=Duration::max())=0
 Wait for reply. More...
 
virtual StatusCode queryDiscard (const QueryIdPtr id)=0
 Discard the pending answer with the identifier id More...
 
- Public Member Functions inherited from Smart::IClientPattern
 IClientPattern (IComponent *component)
 Default Constructor (not yet connecting with any service provider). More...
 
 IClientPattern (IComponent *component, const std::string &server, const std::string &service)
 Connection Constructor (implicitly connecting with specified service provider). More...
 
virtual ~IClientPattern ()=default
 Default destructor. More...
 
virtual StatusCode connect (const std::string &server, const std::string &service)=0
 Connect this service requestor to the denoted service provider. More...
 
virtual StatusCode disconnect ()=0
 Disconnect the service requestor from the service provider. More...
 
virtual StatusCode blocking (const bool blocking)=0
 Allow or abort and reject blocking calls. More...
 
- Public Member Functions inherited from Smart::ICommunicationPattern
 ICommunicationPattern (IComponent *component)
 Default Constructor initializing an IShutdownObserver. More...
 
virtual ~ICommunicationPattern ()=default
 Default Destructor. More...
 
- Public Member Functions inherited from Smart::IShutdownObserver
 IShutdownObserver (ShutdownSubject *subject=nullptr)
 The default constructor. More...
 
virtual ~IShutdownObserver ()
 The default destructor. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Smart::IClientPattern
bool is_shutting_down () const
 
virtual void on_shutdown () override
 implements individual shutdown strategy The default behavior for each client during component shutdown is to call disconnect() which automatically disconnects the current client instance. More...
 
 IClientPattern ()=delete
 
- Protected Member Functions inherited from Smart::ICommunicationPattern
 ICommunicationPattern (const ICommunicationPattern &)=delete
 
ICommunicationPatternoperator= (const ICommunicationPattern &)=delete
 
 ICommunicationPattern ()=delete
 
- Protected Member Functions inherited from Smart::IShutdownObserver
void attach_self_to (ShutdownSubject *subject)
 call this method from within the constructor of derived classes More...
 
void detach_self_from (ShutdownSubject *subject)
 this method is called within the destructor More...
 
- Protected Attributes inherited from Smart::IClientPattern
std::string connectionServerName
 the server-name used for the last connection (can be used in derived classes) More...
 
std::string connectionServiceName
 the service-name used for the last connection (can be used in derived classes) More...
 
std::atomic< bool > is_blocking
 the flag indicating the current blocking state of this client (can be used in derived classes) More...
 
- Protected Attributes inherited from Smart::ICommunicationPattern
IComponenticomponent
 the internal pointer to the component (can be accessed in derived classes) More...
 

Detailed Description

template<class RequestType, class AnswerType>
class Smart::IQueryClientPattern< RequestType, AnswerType >

The client part of Query pattern to perform two-way (request-response) communication.

Template parameters

Constructor & Destructor Documentation

◆ IQueryClientPattern() [1/2]

template<class RequestType , class AnswerType >
Smart::IQueryClientPattern< RequestType, AnswerType >::IQueryClientPattern ( IComponent component)
inline

Constructor (not wired with any service provider).

connect() / disconnect() can always be used to change the connection status of the instance. Instance is not connected to a service provider.

Parameters
componentthe management class of the component

◆ IQueryClientPattern() [2/2]

template<class RequestType , class AnswerType >
Smart::IQueryClientPattern< RequestType, AnswerType >::IQueryClientPattern ( IComponent component,
const std::string &  server,
const std::string &  service 
)
inline

Connection Constructor (implicitly wiring with specified service provider).

Connects to the denoted service and blocks until the connection has been established. Blocks infinitely if denoted service becomes unavailable since constructor performs retries. Blocking is useful to simplify startup of components which have mutual dependencies. connect() / disconnect() can always be used to change the status of the instance.

Parameters
componentthe management class of the component
servername of the server (i.e. the component-name to connect to)
servicename of the service (i.e. the port-name of the component to connect to)

◆ ~IQueryClientPattern()

template<class RequestType , class AnswerType >
virtual Smart::IQueryClientPattern< RequestType, AnswerType >::~IQueryClientPattern ( )
inlinevirtual

Destructor.

The destructor calls disconnect() and therefore properly cleans up every pending query and removes the instance from the set of wireable ports.

Member Function Documentation

◆ query()

template<class RequestType , class AnswerType >
virtual StatusCode Smart::IQueryClientPattern< RequestType, AnswerType >::query ( const RequestType &  request,
AnswerType &  answer 
)
inlinevirtual

Blocking Query.

Perform a blocking query and return only when the query answer is available. Member function is thread safe and thread reentrant.

Parameters
requestsend this request to the server (Communication Object)
answerreturned answer from the server (Communication Object)
Returns
status code:
  • SMART_OK : everything is ok and answer contains answer
  • SMART_CANCELLED : blocking is not allowed or is not allowed anymore and therefore pending query is aborted, answer is lost and answer contains no valid answer.
  • SMART_DISCONNECTED : the client is either disconnected and no query can be made or it got disconnected and a pending query is aborted without answer. In both cases, answer is not valid.
  • SMART_ERROR_COMMUNICATION : communication problems, answer is not valid.
  • SMART_ERROR : something went wrong, answer is not valid.

◆ queryDiscard()

template<class RequestType , class AnswerType >
virtual StatusCode Smart::IQueryClientPattern< RequestType, AnswerType >::queryDiscard ( const QueryIdPtr  id)
pure virtual

Discard the pending answer with the identifier id

Call this member function if you do not want to get the answer of a request anymore which was invoked by queryRequest(). This member function invalidates the identifier id.

Warning
This member function does NOT abort blocking calls ! This is done by the blocking() member function. It has to be called if you have not yet received an answer and the identifier is still valid, for example due to a CANCELLED return value, and you don't want to get the answer anymore.
It is not allowed to call queryReceive(), queryReceiveWait() or queryDiscard() concurrently with the same query id (which is not a restriction since it makes no sense !)
Parameters
idprovides the identifier of the query
Returns
status code:
  • SMART_OK : everything is ok and query with the identifier id discarded.
  • SMART_WRONGID : no pending query with this identifier.
  • SMART_ERROR : something went wrong, id not valid any longer.

◆ queryReceive()

template<class RequestType , class AnswerType >
virtual StatusCode Smart::IQueryClientPattern< RequestType, AnswerType >::queryReceive ( const QueryIdPtr  id,
AnswerType &  answer 
)
pure virtual

Check if answer is available.

Non-blocking call to fetch the answer belonging to the given identifier. Returns immediately. Member function is thread safe and reentrant.

Warning
It is not allowed to call queryReceive(), queryReceiveWait() or queryDiscard() concurrently with the same query id (which is not a restriction since it makes no sense !)
Parameters
idprovides the identifier of the query
answeris set to the answer returned from the server if it was available
Returns
status code:
  • SMART_OK : everything is ok and answer contains the answer
  • SMART_WRONGID : no pending query with this identifier available, therefore no valid answer returned.
  • SMART_NODATA : answer not yet available, therefore try again later. The identifier id keeps valid, but answer contains no valid answer.
  • SMART_DISCONNECTED : the answer belonging to the id can not be received anymore since the client got disconnected. id is not valid any longer and answer contains no valid answer.
  • SMART_ERROR : something went wrong, answer contains no answer and id is not valid any longer.

◆ queryReceiveWait()

template<class RequestType , class AnswerType >
virtual StatusCode Smart::IQueryClientPattern< RequestType, AnswerType >::queryReceiveWait ( const QueryIdPtr  id,
AnswerType &  answer,
const Duration timeout = Duration::max() 
)
pure virtual

Wait for reply.

Blocking call to fetch the answer belonging to the given identifier. Waits until the answer is received.

Warning
It is not allowed to call queryReceive(), queryReceiveWait() or queryDiscard() concurrently with the same query id (which is not a restriction since it makes no sense !)
Parameters
idprovides the identifier of the query
answeris set to the answer returned from the server if it was available
timeoutis the timeout time to block the method maximally (default value max blocks infinitely)
Returns
status code:
  • SMART_OK : everything is ok and answer contains the answer
  • SMART_WRONGID : no pending query with this identifier available, therefore no valid answer returned.
  • SMART_CANCELLED : blocking call is not allowed or is not allowed anymore and therefore blocking call is aborted and no valid answer is returned. The query identifier id keeps valid and one can either again call queryReceive(), queryReceiveWait() or discard the answer by calling queryDiscard().
  • SMART_DISCONNECTED : blocking call is aborted and the answer belonging to id can not be received anymore since client got disconnected. id is not valid any longer and answer contains no valid answer.
  • SMART_ERROR : something went wrong, answer contains no answer and id is not valid any longer.

◆ queryRequest()

template<class RequestType , class AnswerType >
virtual StatusCode Smart::IQueryClientPattern< RequestType, AnswerType >::queryRequest ( const RequestType &  request,
QueryIdPtr id 
)
pure virtual

Asynchronous Query.

Perform a query and receive the answer later, returns immediately. Member function is thread safe and reentrant.

Parameters
requestsend this request to the server (Communication Object)
idis set to the identifier which is later used to receive the reply to this request
Returns
status code:
  • SMART_OK : everything is ok and id contains query identifier used to either fetch or discard the answer.
  • SMART_DISCONNECTED : request is rejected since client is not connected to a server and therefore id is not a valid identifier.
  • SMART_ERROR_COMMUNICATION : communication problems, id is not valid.
  • SMART_ERROR : something went wrong, id is not valid.

The documentation for this class was generated from the following file: