|
iodrivers_base
|
#include <Task.hpp>
Public Member Functions | |
| Task (std::string const &name="iodrivers_base::Task") | |
| Task (std::string const &name, RTT::ExecutionEngine *engine) | |
| virtual | ~Task () |
| bool | configureHook () |
| The following lines are template definitions for the various state machine. More... | |
| bool | startHook () |
| void | updateHook () |
| void | exceptionHook () |
| void | stopHook () |
| void | cleanupHook () |
Protected Member Functions | |
| void | setDriver (Driver *driver) |
| void | detachDriver () |
| Driver * | getDriver () const |
| void | pushAllData () |
| bool | hasIO () |
| virtual void | processIO ()=0 |
| void | updateIOStatus () |
Protected Attributes | |
| Driver * | mDriver |
| PortStream * | mStream |
| PortListener * | mListener |
| RawPacket | mRawPacket |
| base::Time | mLastStatus |
Friends | |
| class | TaskBase |
| class | ConfigureGuard |
Generic integration of an iodrivers_base::Driver in oroGen
configureHook: Subclasses must call setDriver with a valid driver object before calling the base task's configureHook. Any I/O must be done after the base configureHook is done. If the _io_port property is not empty, the subclass must open the URI itself. Otherwise, the base configureHook will tie the task's io_raw_in and io_raw_out ports to the device. Additionally, in order to easily guarantee an acceptable level of exception-safety, one should use the scope guard ConfigureGuard provided with this package.
bool Task::configureHook() { iodrivers_base::ConfigureGuard guard(this); std::auto_ptr<MyDriver> driver(new MyDriver); if (!_io_port.get().empty()) driver->openURI(_io_port.get()); setDriver(driver.release());
if (!TaskBase::configureHook()) return false;
// Do device initialization here. NEVER before // TaskBase::configureHook has been called // Also, don't forget to release the guard by // calling commit() on it just before returning. guard.commit(); return true; }
cleanupHook: the base implementation closes the device. Perform device de-initialization before calling the base cleanupHook.
processIO: called when the task is called because of I/O has been received. It will be called as long as there are valid packets buffered, so processIO must ensure that all available packets have been read.
The device object is owned by the subclass, which is responsible for its destruction. setDriver may be called more than once with the same device (so, it's OK to allocate the device as an attribute instead of allocating on the heap).
Calling setDriver adds connections between the driver and task ports. If this connection must be removed (to get a "detached" device), one must call detachDriver() after having called setDriver. Note that one does not need to do so before the driver is deleted. Calling detachDriver after having deleted the driver, though, will lead to a use-after-free.
| Task::Task | ( | std::string const & | name = "iodrivers_base::Task" | ) |
| Task::Task | ( | std::string const & | name, |
| RTT::ExecutionEngine * | engine | ||
| ) |
|
virtual |
| void Task::cleanupHook | ( | ) |
This hook is called by Orocos when the state machine transitions from Stopped to PreOperational, requiring the call to configureHook() before calling start() again.
| bool Task::configureHook | ( | ) |
The following lines are template definitions for the various state machine.
This hook is called by Orocos when the state machine transitions from PreOperational to Stopped. If it returns false, then the component will stay in PreOperational. Otherwise, it goes into Stopped.
It is meaningful only if the #needs_configuration has been specified in the task context definition with (for example):
task_context "TaskName" do needs_configuration ... end
|
protected |
Detaches the current driver from the task
| void Task::exceptionHook | ( | ) |
|
protected |
Returns the current driver object
|
protected |
Returns true if there is some I/O available to read on the driver
|
protectedpure virtual |
Called back by the updateHook. It must be reimplemented to process all packets that are currently queued in the driver
|
protected |
DEPRECATED
|
protected |
Sets the driver object
Must be called before either the TaskBase::startHook method gets called for tasks that do not require configuration, or TaskBase::configureHook otherwise
| bool Task::startHook | ( | ) |
This hook is called by Orocos when the state machine transitions from Stopped to Running. If it returns false, then the component will stay in Stopped. Otherwise, it goes into Running and updateHook() will be called.
| void Task::stopHook | ( | ) |
This hook is called by Orocos when the state machine transitions from Running to Stopped after stop() has been called.
| void Task::updateHook | ( | ) |
This hook is called by Orocos when the component is in the Running state, at each activity step. Here, the activity gives the "ticks" when the hook should be called.
The error(), exception() and fatal() calls, when called in this hook, allow to get into the associated RunTimeError, Exception and FatalError states.
In the first case, updateHook() is still called, and recover() allows you to go back into the Running state. In the second case, the errorHook() will be called instead of updateHook(). In Exception, the component is stopped and recover() needs to be called before starting it again. Finally, FatalError cannot be recovered.
|
protected |
Updates the IO status information on the io_status port
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
Listener object that forwards I/O to the monitoring ports
|
protected |
|
protected |
IOStream object that does I/O on the ports
1.8.11