AceSmartSoft API Documentation
|
Handles the event service on client side. More...
#include <smartEvent.hh>
Public Member Functions | |
EventClient (SmartComponent *component, const std::string &port, WiringSlave *slave) | |
Constructor (exposed as port wireable from outside by other components and without handler). More... | |
EventClient (SmartComponent *component) | |
Constructor (not wired with service provider, not exposed as port and without handler). More... | |
EventClient (SmartComponent *component, const std::string &server, const std::string &service) | |
Constructor (wired with specified service provider and without handler) More... | |
virtual | ~EventClient () |
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 | activate (const Smart::EventMode &mode, const P ¶meter, Smart::EventIdPtr &id) |
Activate an event with the provided parameters in either "single" or "continuous" mode. More... | |
Smart::StatusCode | deactivate (const Smart::EventIdPtr id) |
Deactivate the event with the specified identifier. More... | |
Smart::StatusCode | tryEvent (const Smart::EventIdPtr id) |
Check whether event has already fired and return immediately with status information. More... | |
Smart::StatusCode | getEvent (const Smart::EventIdPtr id, E &event, const Smart::Duration &timeout=Smart::Duration::max()) |
Blocking call which waits for the event to fire and then consumes the event. More... | |
Smart::StatusCode | getNextEvent (const Smart::EventIdPtr id, E &event, const Smart::Duration &timeout=Smart::Duration::max()) |
Blocking call which waits for the next event. More... | |
Handles the event service on client side.
Template parameters:
Demonstrated in fifth example
SmartACE::EventClient< P, E >::EventClient | ( | SmartComponent * | component, |
const std::string & | port, | ||
WiringSlave * | slave | ||
) |
Constructor (exposed as port wireable from outside by other components and without handler).
Constructs an EventClient for method oriented event processing. Use tryEvent()/getEvent()/getNextEvent() to process incoming events.
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::EventClient< P, E >::EventClient | ( | SmartComponent * | component | ) |
Constructor (not wired with service provider, not exposed as port and without handler).
Constructs an EventClient for method oriented event processing. Use tryEvent()/getEvent()/getNextEvent() to process incoming events.
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::EventClient< P, E >::EventClient | ( | SmartComponent * | component, |
const std::string & | server, | ||
const std::string & | service | ||
) |
Constructor (wired with specified service provider and without handler)
Constructs an EventClient for method oriented event processing. Use tryEvent()/getEvent()/getNextEvent() to process incoming events. 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 deactivates every still active event and removes the instance from the set of wireable ports.
Smart::StatusCode SmartACE::EventClient< P, E >::activate | ( | const Smart::EventMode & | mode, |
const P & | parameter, | ||
Smart::EventIdPtr & | id | ||
) |
Activate an event with the provided parameters in either "single" or "continuous" mode.
mode | "single" or "continuous" mode |
parameter | activation parameter class (Communication Object) |
id | is set to the unique id of the event activation |
Smart::StatusCode SmartACE::EventClient< P, E >::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::EventClient< P, E >::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::EventClient< P, E >::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 active events 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 tryEvent()/getEvent() or getNextEvent().
server | name of the server |
service | name of the service |
Smart::StatusCode SmartACE::EventClient< P, E >::deactivate | ( | const Smart::EventIdPtr | id | ) |
Deactivate the event with the specified identifier.
An event must always be deactivated, even if it has already fired in single mode. This is just necessary for cleanup procedures and provides a uniform user API independently of the event mode. Calling deactivate() while there are blocking calls aborts them with the appropriate status code.
id | of event to be disabled |
(Hint: can not return SMART_DISCONNECTED since then each event is for sure also deactivated resulting in SMART_WRONGID)
Smart::StatusCode SmartACE::EventClient< P, E >::disconnect | ( | ) |
Disconnect the service requestor from the service provider.
All blocking calls are aborted with the SMART_DISCONNECTED status code. All events are deactivated.
It is no problem to change the connection to a service provider at any point of time irrespective of any calls to tryEvent() / getEvent() or getNextEvent().
Smart::StatusCode SmartACE::EventClient< P, E >::getEvent | ( | const Smart::EventIdPtr | id, |
E & | event, | ||
const Smart::Duration & | timeout = Smart::Duration::max() |
||
) |
Blocking call which waits for the event to fire and then consumes the event.
This method consumes an event. Returns immediately if an unconsumed event is available. Blocks otherwise till event becomes available. If method is called concurrently from several threads with the same id and method is blocking, then every call returns with the same event once the event fired. If there is however already an unconsumed event available, then only one out of the concurrent calls consumes the event and the other calls return with appropriate status codes.
id | of the event activation |
event | is set to the returned event if fired (Communication Object) |
timeout | the optional maximum waiting time for an event (default value max: method blocks indefinitely) |
Since an event in single mode fires only once, return immediately if the event is already consumed. Also return immediately with an available and unconsumed event and consume it. Otherwise wait until the event fires.
Returns status code:
Returns immediately if an unconsumed event is available. Returns the newest unconsumed event since activation. Otherwise waits until the event fires again.
Returns status code:
Smart::StatusCode SmartACE::EventClient< P, E >::getNextEvent | ( | const Smart::EventIdPtr | id, |
E & | event, | ||
const Smart::Duration & | timeout = Smart::Duration::max() |
||
) |
Blocking call which waits for the next event.
This methods waits for the next arriving event to make sure that only events arriving after entering the method are considered. Method consumes event. An old event that has been fired is ignored (in contrary to getEvent()). If method is called concurrently from several threads with the same id, then every call returns with the same event once the event fired.
id | of the event activation |
event | is set to the returned event if fired (Communication Object) |
timeout | the optional maximum waiting time for an event (default value max: method blocks indefinitely) |
In single mode one misses the event if it fired before entering this member function.
Returns status code:
Makes sure that only events fired after entering this member function are considered.
Returns status code:
Smart::StatusCode SmartACE::EventClient< P, E >::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::EventClient< P, E >::tryEvent | ( | const Smart::EventIdPtr | id | ) |
Check whether event has already fired and return immediately with status information.
This method does not consume an available event.
id | of the event activation to be checked |