AceSmartSoft API Documentation
|
Client part of query pattern to perform two-way communication. More...
#include <smartQuery.hh>
Public Member Functions | |
QueryClient (SmartComponent *component, const std::string &port, WiringSlave *slave) | |
Constructor (exposed as port and wireable from outside by other components). More... | |
QueryClient (SmartComponent *component) | |
Constructor (not wired with service provider and not exposed as port). More... | |
QueryClient (SmartComponent *component, const std::string &server, const std::string &service) | |
Constructor (wired with specified service provider). More... | |
virtual | ~QueryClient () |
Destructor. More... | |
Smart::StatusCode | add (WiringSlave *slave, const std::string &port) |
Add this instance to the set of ports wireable via the wiring pattern from outside the component. More... | |
Smart::StatusCode | remove () |
Remove this service requestor from the set of ports wireable via the wiring pattern from outside the component. More... | |
Smart::StatusCode | connect (const std::string &server, const std::string &service) |
Connect this service requestor to the denoted service provider. More... | |
Smart::StatusCode | disconnect () |
Disconnect the service requestor from the service provider. More... | |
Smart::StatusCode | blocking (const bool b) |
Allow or abort and reject blocking calls. More... | |
Smart::StatusCode | query (const R &request, A &answer) |
Blocking Query. More... | |
Smart::StatusCode | queryRequest (const R &request, Smart::QueryIdPtr &id) |
Asynchronous Query. More... | |
Smart::StatusCode | queryReceive (const Smart::QueryIdPtr id, A &answer) |
Check if answer is available. More... | |
Smart::StatusCode | queryReceiveWait (const Smart::QueryIdPtr id, A &answer, const Smart::Duration &timeout=Smart::Duration::max()) |
Wait for reply. More... | |
Smart::StatusCode | queryDiscard (const Smart::QueryIdPtr id) |
Discard the pending answer with the identifier id More... | |
Client part of query pattern to perform two-way communication.
Template parameters
Demonstrated in first example and third example
SmartACE::QueryClient< R, A >::QueryClient | ( | SmartComponent * | component, |
const std::string & | port, | ||
WiringSlave * | slave | ||
) |
Constructor (exposed as port and wireable from outside by other components).
add()/remove() and connect()/disconnect() can always be used to change the status of the instance. Instance is not connected to a service provider.
Throws exception if port name is already in use.
component | management class of the component |
port | name of the wireable port |
slave | wiring slave of this component |
SmartACE::QueryClient< R, A >::QueryClient | ( | SmartComponent * | component | ) |
Constructor (not wired with service provider and not exposed as port).
add()/remove() and connect()/disconnect() can always be used to change the status of the instance. Instance is not connected to a service provider and is not exposed as port wireable from outside the component.
(Currently exception not thrown)
component | management class of the component |
SmartACE::QueryClient< R, A >::QueryClient | ( | SmartComponent * | component, |
const std::string & | server, | ||
const std::string & | service | ||
) |
Constructor (wired with specified service provider).
Connects to the denoted service and blocks until the connection has been established. Blocks infinitely if denoted service becomes not available since constructor performs retries. Blocking is useful to simplify startup of components which have mutual dependencies. add()/remove() and connect()/disconnect() can always be used to change the status of the instance.
Throws exception if denoted service is incompatible (wrong communication pattern or wrong communication objects).
component | management class of the component |
server | name of the server |
service | name of the service |
|
virtual |
Destructor.
The destructor calls remove() and disconnect() and therefore properly cleans up every pending query and removes the instance from the set of wireable ports.
Smart::StatusCode SmartACE::QueryClient< R, A >::add | ( | WiringSlave * | slave, |
const std::string & | port | ||
) |
Add this instance to the set of ports wireable via the wiring pattern from outside the component.
Already established connections keep valid. If this service requestor is already exposed as port, it is first removed and then added with the new port name. add()/remove() and connect()/disconnect() can always be used to change the status of this instance.
slave | wiring slave of this component |
port | name of port used for wiring |
Smart::StatusCode SmartACE::QueryClient< R, A >::blocking | ( | const bool | b | ) |
Allow or abort and reject blocking calls.
If blocking is set to false all blocking calls return with SMART_CANCELLED. This can be used to abort blocking calls.
b | (blocking) true/false |
Smart::StatusCode SmartACE::QueryClient< R, A >::connect | ( | const std::string & | server, |
const std::string & | service | ||
) |
Connect this service requestor to the denoted service provider.
An already established connection is first disconnected. See disconnect() for implications on running or pending queries in that case.
It is no problem to change the connection to a service provider at any point of time irrespective of any calls to query() / queryRequest() / queryReceive() or queryReceiveWait().
server | name of the server |
service | name of the service |
Smart::StatusCode SmartACE::QueryClient< R, A >::disconnect | ( | ) |
Disconnect the service requestor from the service provider.
All blocking queries are aborted with the SMART_DISCONNECTED status code. Already received but not yet picked up answers keep valid and can still be picked up with queryReceive()/queryReceiveWait(). Not yet received answers at the time of disconnection are lost and calls to queryReceive()/queryReceiveWait() return with SMART_DISCONNECTED.
It is no problem to change the connection to a service provider at any point of time irrespective of any calls to query() / queryRequest() / queryReceive() or queryReceiveWait().
Smart::StatusCode SmartACE::QueryClient< R, A >::query | ( | const R & | request, |
A & | answer | ||
) |
Blocking Query.
Perform a blocking query and return only when the query answer is available. Member function is thread safe and thread reentrant.
request | send this request to the server (Communication Object) |
answer | returned answer from the server (Communication Object) |
Smart::StatusCode SmartACE::QueryClient< R, A >::queryDiscard | ( | const Smart::QueryIdPtr | id | ) |
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.
id | provides the identifier of the query |
Smart::StatusCode SmartACE::QueryClient< R, A >::queryReceive | ( | const Smart::QueryIdPtr | id, |
A & | answer | ||
) |
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.
id | provides the identifier of the query |
answer | is set to the answer returned from the server if it was available |
Smart::StatusCode SmartACE::QueryClient< R, A >::queryReceiveWait | ( | const Smart::QueryIdPtr | id, |
A & | answer, | ||
const Smart::Duration & | timeout = Smart::Duration::max() |
||
) |
Wait for reply.
Blocking call to fetch the answer belonging to the given identifier. Waits until the answer is received.
id | provides the identifier of the query |
answer | is set to the answer returned from the server if it was available |
timeout | the optional maximum waiting time for a query answer (default value max: method blocks indefinitely) |
Smart::StatusCode SmartACE::QueryClient< R, A >::queryRequest | ( | const R & | request, |
Smart::QueryIdPtr & | id | ||
) |
Asynchronous Query.
Perform a query and receive the answer later, returns immediately. Member function is thread safe and reentrant.
request | send this request to the server (Communication Object) |
id | is set to the identifier which is later used to receive the reply to this request |
Smart::StatusCode SmartACE::QueryClient< R, A >::remove | ( | ) |
Remove this service requestor from the set of ports wireable via the wiring pattern from outside the component.
Already established connections keep valid but can now be changed only from inside and not from outside this component anymore.