Orocos Real-Time Toolkit
2.8.3
|
An activity which is triggered by the availability of data on a set of file descriptors. More...
#include <rtt/extras/FileDescriptorActivityInterface.hpp>
Public Member Functions | |
virtual | ~FileDescriptorActivityInterface () |
virtual void | watch (int fd)=0 |
Sets the file descriptor the activity should be listening to. More... | |
virtual void | unwatch (int fd)=0 |
Removes a file descriptor from the set of watched FDs. More... | |
virtual void | clearAllWatches ()=0 |
Remove all FDs that are currently being watched. More... | |
virtual bool | isWatched (int fd) const =0 |
True if this specific FD is being watched by the activity. More... | |
virtual bool | isUpdated (int fd) const =0 |
True if this specific FD has new data. More... | |
virtual bool | hasTimeout () const =0 |
True if the base::RunnableInterface has been triggered because of a timeout, instead of because of new data is available. More... | |
virtual bool | hasError () const =0 |
True if one of the file descriptors has a problem (for instance it has been closed) More... | |
virtual void | setTimeout (int timeout)=0 |
Sets the timeout, in milliseconds, for waiting on the IO. More... | |
virtual void | setTimeout_us (int timeout_us)=0 |
Sets the timeout, in microseconds, for waiting on the IO. More... | |
virtual int | getTimeout () const =0 |
Get the timeout, in milliseconds, for waiting on the IO. More... | |
virtual int | getTimeout_us () const =0 |
Get the timeout, in microseconds, for waiting on the IO. More... | |
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.
|
inlinevirtual |
Definition at line 98 of file FileDescriptorActivityInterface.hpp.
|
pure virtual |
Remove all FDs that are currently being watched.
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
pure virtual |
Get the timeout, in milliseconds, for waiting on the IO.
Set to 0 for blocking behaviour (no timeout).
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
pure virtual |
Get the timeout, in microseconds, for waiting on the IO.
Set to 0 for blocking behaviour (no timeout).
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
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.
|
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.
|
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().
fd | the file descriptor |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
pure virtual |
True if this specific FD is being watched by the activity.
fd | the file descriptor |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
pure virtual |
Sets the timeout, in milliseconds, for waiting on the IO.
Set to 0 for blocking behaviour (no timeout).
timeout | The timeout (milliseconds) |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
pure virtual |
Sets the timeout, in microseconds, for waiting on the IO.
Set to 0 for blocking behaviour (no timeout).
timeout | The timeout (microseconds) |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
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
fd | the file descriptor |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.
|
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
fd | the file descriptor |
Implemented in RTT::extras::FileDescriptorActivity, and RTT::extras::FileDescriptorSimulationActivity.