AceSmartSoft API Documentation
|
Client part of the Push pattern to provide a flexible push service. More...
#include <smartPush.hh>
Public Member Functions | |
PushClient (SmartComponent *component, const std::string &port, WiringSlave *slave) | |
Constructor (exposed as port and wireable from outside by other components). More... | |
PushClient (SmartComponent *component) | |
Constructor (not wired with service provider and not exposed as port). More... | |
PushClient (SmartComponent *component, const std::string &server, const std::string &service) | |
Constructor (wired with specified service provider). More... | |
virtual | ~PushClient () |
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 | subscribe (const unsigned int &prescale=1) |
Subscribe at the server to periodically get every n-th update. More... | |
Smart::StatusCode | unsubscribe () |
Unsubscribe to get no more updates. More... | |
Smart::StatusCode | blocking (const bool b) |
Allow or abort and reject blocking calls. More... | |
Smart::StatusCode | getUpdate (DataType &d) |
Non-blocking call to immediately return the latest available data buffered at the client side from the most recent update. More... | |
Smart::StatusCode | getUpdateWait (DataType &d, const Smart::Duration &timeout=Smart::Duration::max()) |
Blocking call which waits until the next update is received. More... | |
Smart::StatusCode | getServerInfo (SmartTimeValue &t, bool &r) |
Get cycle time and server state. More... | |
Client part of the Push pattern to provide a flexible push service.
Clients can subscribe to regularly get every n-th update. This class implements the Subject part of the Observer design pattern (see also PushClientObserver class).
Template parameters
Demonstrated in eigth example
SmartACE::PushClient< DataType >::PushClient | ( | 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 client-port (visible in wiring-slave) |
slave | reference to wiring-slave |
SmartACE::PushClient< DataType >::PushClient | ( | 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::PushClient< DataType >::PushClient | ( | 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 data reception and removes the instance from the set of wireable ports.
Smart::StatusCode SmartACE::PushClient< DataType >::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::PushClient< DataType >::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::PushClient< DataType >::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 pending data reception 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 getUpdate() / getUpdateWait().
server | name of the server |
service | name of the service |
Smart::StatusCode SmartACE::PushClient< DataType >::disconnect | ( | ) |
Disconnect the service requestor from the service provider.
A disconnect always first performs an unsubscribe. See unsubsribe() for implications on getUpdate() and getUpdateWait().
It is no problem to change the connection to a service provider at any point of time irrespective of any calls to getUpdate() / getUpdateWait().
Smart::StatusCode SmartACE::PushClient< DataType >::getServerInfo | ( | SmartTimeValue & | t, |
bool & | r | ||
) |
Get cycle time and server state.
Returns cycle time of server in [seconds] and server state indicating whether server is activated or not. The client can decide on the cycle time on its individual update rate at subscription.
t | is set to the server cycle time [seconds] |
r | indicates whether server is started [true, false] |
Smart::StatusCode SmartACE::PushClient< DataType >::getUpdate | ( | DataType & | d | ) |
Non-blocking call to immediately return the latest available data buffered at the client side from the most recent update.
No data is returned as long as no update is received since subscription. To avoid returning old data, no data is returned after the client is unsubscribed or when the server is not active.
d | is set to the newest currently available data |
Smart::StatusCode SmartACE::PushClient< DataType >::getUpdateWait | ( | DataType & | d, |
const Smart::Duration & | timeout = Smart::Duration::max() |
||
) |
Blocking call which waits until the next update is received.
Blocking is aborted with the appropriate status if either the server gets deactivated, the client gets unsubscribed or disconnected or if blocking is not allowed any more at the client.
d | is set to the newest currently available data |
timeout | allows to release the blocking wait after a given timeout time (the default max time means infinite blocking) |
Smart::StatusCode SmartACE::PushClient< DataType >::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.
Smart::StatusCode SmartACE::PushClient< DataType >::subscribe | ( | const unsigned int & | prescale = 1 | ) |
Subscribe at the server to periodically get every n-th update.
A newly subscribed client gets the next available new data and is then updated with regard to its individual update cycle.
prescale | whole-numbered value to set the update rate to every n-th value |
Smart::StatusCode SmartACE::PushClient< DataType >::unsubscribe | ( | ) |
Unsubscribe to get no more updates.
All blocking calls are aborted with the appropriate status and yet received and still buffered data is deleted to avoid returning old data.
(can not return SMART_DISCONNECTED since then client is for sure also unsubscribed which results in SMART_OK)