Public Member Functions | List of all members
RTT::extras::FileDescriptorActivityInterface Class Referenceabstract

#include <FileDescriptorActivityInterface.hpp>

Inheritance diagram for RTT::extras::FileDescriptorActivityInterface:
Inheritance graph
[legend]

Public Member Functions

virtual void clearAllWatches ()=0
 
virtual int getTimeout () const =0
 
virtual int getTimeout_us () const =0
 
virtual bool hasError () const =0
 
virtual bool hasTimeout () const =0
 
virtual bool isUpdated (int fd) const =0
 
virtual bool isWatched (int fd) const =0
 
virtual void setTimeout (int timeout)=0
 
virtual void setTimeout_us (int timeout_us)=0
 
virtual void unwatch (int fd)=0
 
virtual void watch (int fd)=0
 
virtual ~FileDescriptorActivityInterface ()
 

Detailed Description

An activity which is triggered by the availability of data on a set of file descriptors. step() (and hence the base::RunnableInterface's step() method) is called when data is available or when an error is encountered on the file descriptor.

To use it, one must add the file descriptors to watch in the task's configureHook()

FileDescriptorActivity* fd_activity = dynamic_cast<FileDescriptorActivity*>(getActivity().get()); if (fd_activity) { fd_activity->watch(device_fd); // optional, set a timeout in milliseconds fd_activity->setTimeout(1000); // or in microseconds fd_activity->setTimeout_us(1000); }

Then, updateHook() and – when in ERROR state – errorHook() will be called when one of these three events happen:

The different cases can be tested in updateHook() as follows:

FileDescriptorActivity* fd_activity = dynamic_cast<FileDescriptorActivity*>(getActivity().get()); if (fd_activity) { if (fd_activity->hasError()) { } else if (fd_activity->hasTimeout()) { } else { // If there is more than one FD, discriminate. Otherwise, // we don't need to use isUpdated if (fd_activity->isUpdated(device_fd)) { } else if (fd_activity->isUpdated(another_fd)) { } } }

Definition at line 95 of file FileDescriptorActivityInterface.hpp.

Constructor & Destructor Documentation

virtual RTT::extras::FileDescriptorActivityInterface::~FileDescriptorActivityInterface ( )
inlinevirtual

Definition at line 98 of file FileDescriptorActivityInterface.hpp.

Member Function Documentation

virtual void RTT::extras::FileDescriptorActivityInterface::clearAllWatches ( )
pure virtual

Remove all FDs that are currently being watched

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual int RTT::extras::FileDescriptorActivityInterface::getTimeout ( ) const
pure virtual

Get the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).

Returns
The timeout (milliseconds)

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual int RTT::extras::FileDescriptorActivityInterface::getTimeout_us ( ) const
pure virtual

Get the timeout, in microseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).

Returns
The timeout (microseconds)

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual bool RTT::extras::FileDescriptorActivityInterface::hasError ( ) const
pure virtual

True if one of the file descriptors has a problem (for instance it has been closed)

This should only be used from within the base::RunnableInterface this activity is driving, i.e. in TaskContext::updateHook() or TaskContext::errorHook().

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual bool RTT::extras::FileDescriptorActivityInterface::hasTimeout ( ) const
pure virtual

True if the base::RunnableInterface has been triggered because of a timeout, instead of because of new data is available.

This should only be used from within the base::RunnableInterface this activity is driving, i.e. in TaskContext::updateHook() or TaskContext::errorHook().

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual bool RTT::extras::FileDescriptorActivityInterface::isUpdated ( int  fd) const
pure virtual

True if this specific FD has new data.

This should only be used from within the base::RunnableInterface this activity is driving, i.e. in TaskContext::updateHook() or TaskContext::errorHook().

Parameters
fdthe file descriptor

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual bool RTT::extras::FileDescriptorActivityInterface::isWatched ( int  fd) const
pure virtual

True if this specific FD is being watched by the activity

Parameters
fdthe file descriptor

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual void RTT::extras::FileDescriptorActivityInterface::setTimeout ( int  timeout)
pure virtual

Sets the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).

Precondition
0 <= timeout (otherwise an error is logged and timeout is ignored)
Parameters
timeoutThe timeout (milliseconds)

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual void RTT::extras::FileDescriptorActivityInterface::setTimeout_us ( int  timeout_us)
pure virtual

Sets the timeout, in microseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).

Precondition
0 <= timeout (otherwise an error is logged and timeout_us is ignored)
Parameters
timeoutThe timeout (microseconds)

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual void RTT::extras::FileDescriptorActivityInterface::unwatch ( int  fd)
pure virtual

Removes a file descriptor from the set of watched FDs

This method is thread-safe, i.e. it can be called from any thread

Parameters
fdthe file descriptor

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.

virtual void RTT::extras::FileDescriptorActivityInterface::watch ( int  fd)
pure virtual

Sets the file descriptor the activity should be listening to.

This method is thread-safe, i.e. it can be called from any thread

Parameters
fdthe file descriptor

Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.


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


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:43