iodrivers_base
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
iodrivers_base::Task Class Referenceabstract

#include <Task.hpp>

Inheritance diagram for iodrivers_base::Task:

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
 
PortStreammStream
 
PortListenermListener
 
RawPacket mRawPacket
 
base::Time mLastStatus
 

Friends

class TaskBase
 
class ConfigureGuard
 

Detailed Description

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.

Device ownership

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.

Constructor & Destructor Documentation

◆ Task() [1/2]

Task::Task ( std::string const &  name = "iodrivers_base::Task")

◆ Task() [2/2]

Task::Task ( std::string const &  name,
RTT::ExecutionEngine *  engine 
)

◆ ~Task()

Task::~Task ( )
virtual

Member Function Documentation

◆ cleanupHook()

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.

◆ configureHook()

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

◆ detachDriver()

void Task::detachDriver ( )
protected

Detaches the current driver from the task

◆ exceptionHook()

void Task::exceptionHook ( )

◆ getDriver()

Driver * Task::getDriver ( ) const
protected

Returns the current driver object

◆ hasIO()

bool Task::hasIO ( )
protected

Returns true if there is some I/O available to read on the driver

◆ processIO()

virtual void iodrivers_base::Task::processIO ( )
protectedpure virtual

Called back by the updateHook. It must be reimplemented to process all packets that are currently queued in the driver

◆ pushAllData()

void Task::pushAllData ( )
protected

DEPRECATED

◆ setDriver()

void Task::setDriver ( Driver *  driver)
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

◆ startHook()

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.

◆ stopHook()

void Task::stopHook ( )

This hook is called by Orocos when the state machine transitions from Running to Stopped after stop() has been called.

◆ updateHook()

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.

◆ updateIOStatus()

void Task::updateIOStatus ( )
protected

Updates the IO status information on the io_status port

Friends And Related Function Documentation

◆ ConfigureGuard

friend class ConfigureGuard
friend

◆ TaskBase

friend class TaskBase
friend

Member Data Documentation

◆ mDriver

Driver* iodrivers_base::Task::mDriver
protected

◆ mLastStatus

base::Time iodrivers_base::Task::mLastStatus
protected

◆ mListener

PortListener* iodrivers_base::Task::mListener
protected

Listener object that forwards I/O to the monitoring ports

◆ mRawPacket

RawPacket iodrivers_base::Task::mRawPacket
protected

◆ mStream

PortStream* iodrivers_base::Task::mStream
protected

IOStream object that does I/O on the ports


The documentation for this class was generated from the following files: