|
Robot Raconteur Core C++ Library
|
Generator type for use with generator functions, with parameter. More...
#include <Generator.h>
Public Member Functions | |
| virtual void | Next (const Param &v)=0 |
| Advance the generator. | |
| virtual bool | TryNext (const Param &v) |
| Try to advance the generator. Return false if no more values are available. | |
| virtual void | AsyncNext (const Param &v, boost::function< void(const boost::shared_ptr< RobotRaconteurException > &err)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)=0 |
| Asynchronously advance the generator. | |
| virtual void | Abort ()=0 |
| Abort the generator. | |
| virtual void | AsyncAbort (boost::function< void(const boost::shared_ptr< RobotRaconteurException > &err)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)=0 |
| Asynchronously abort the generator. | |
| virtual void | Close ()=0 |
| Close the generator. | |
| virtual void | AsyncClose (boost::function< void(const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)=0 |
| Asynchronously closes the generator. | |
Generator type for use with generator functions, with parameter.
Generators are used with generator functions to implement simple coroutines. They are returned by function members with a parameter and/or return marked with the generator container type. Robot Raconteur generators are modeled on Python generators, and are intended to be used in two scenarios:
Generators are a generalization of iterators, where a value is returned every time the iterator is advanced until there are no more values. Python and Robot Raconteur iterators add the option of passing a parameter every advance, allowing for simple coroutines. The generator is advanced by calling the Next() or AsyncNext() functions. These functions will either return a value or throw StopIterationException if there are no more values. Next() and AsyncNext() may also throw any valid Robot Raconteur exception.
Generators can be terminated with either the Close() or Abort() functions. Close() should be used to cleanly close the generator, and is not considered an error condition. Next(), if called after close, should throw StopIterationException. Abort() is considered an error condition, and will cause any action associated with the generator to be aborted as quickly as possible (ie faulting a robot). If Next() is called after Abort(), OperationAbortedException should be thrown.
Robot Raconteur clients will return a populated stub generator that calls the service. Services are expected to return a subclass of Generator that implements at a minimum Next(), Close(), and Abort(). AsyncNext(), AsyncAbort(), and AsyncClose() may optionally be implemented for asynchronous operation on the service side.
| Return | The type of value returned by Next() and AsyncNext() |
| Param | The type of the parameter passed to Next() and AsyncNext() |
|
pure virtual |
Abort the generator.
Aborts and destroys the generator. This is assumed to be an error condition. Next() should throw OperationAbortedException if called after Abort(). Any ongoing operations should be terminated with an error condition, for example a moving robot should be immediately halted.
Implemented in RobotRaconteur::SyncGenerator< void, Param >.
|
pure virtual |
Asynchronously abort the generator.
Same as Abort() but returns asynchronously.
| handler | The handler to call when abort is complete |
| timeout | Timeout in milliseconds, or RR_TIMEOUT_INFINITE for no timeout. |
|
pure virtual |
Asynchronously closes the generator.
Same as Close() but returns asynchronously.
| handler | The handler to call when close is complete |
| timeout | Timeout in milliseconds, or RR_TIMEOUT_INFINITE for no timeout. |
Implemented in RobotRaconteur::SyncGenerator< void, Param >.
|
pure virtual |
Asynchronously advance the generator.
Same as Next() but returns asynchronously.
| v | Parameter to pass to generator |
| handler | The handler to call when next is complete |
| timeout | Timeout in milliseconds, or RR_TIMEOUT_INFINITE for no timeout. |
|
pure virtual |
Close the generator.
Closes the generator. Closing the generator terminates iteration and destroys the generator. This operation cleanly closes the generator, and is not considered to be an error condition. Next() should throw StopIterationException if called after Close().
Implemented in RobotRaconteur::SyncGenerator< void, Param >.
|
pure virtual |
Advance the generator.
Next() advances the generator to retrieve the next value. This version of Generator includes passing a parameter to the generator.
| v | Parameter to pass to generator |
Implemented in RobotRaconteur::SyncGenerator< void, Param >.
|
inlinevirtual |
Try to advance the generator. Return false if no more values are available.
TryNext() is similar to Next() but returns false if no more values are available. This version of TryNext() includes passing a parameter to the generator.
| v | The parameter to pass to the generator |