#include <FileDescriptorActivity.hpp>
Public Member Functions | |
virtual bool | breakLoop () |
virtual bool | breakLoop () |
void | clearAllWatches () |
void | clearAllWatches () |
FileDescriptorActivity (int scheduler, int priority, base::RunnableInterface *_r=0, const std::string &name="FileDescriptorActivity") | |
FileDescriptorActivity (int priority, base::RunnableInterface *_r=0, const std::string &name="FileDescriptorActivity") | |
FileDescriptorActivity (int scheduler, int priority, base::RunnableInterface *_r=0, const std::string &name="FileDescriptorActivity") | |
FileDescriptorActivity (int priority, base::RunnableInterface *_r=0, const std::string &name="FileDescriptorActivity") | |
int | getTimeout () const |
int | getTimeout () const |
bool | hasError () const |
bool | hasError () const |
bool | hasTimeout () const |
bool | hasTimeout () const |
bool | isRunning () const |
bool | isRunning () const |
bool | isUpdated (int fd) const |
bool | isUpdated (int fd) const |
bool | isWatched (int fd) const |
bool | isWatched (int fd) const |
virtual void | loop () |
virtual void | loop () |
void | setTimeout (int timeout) |
void | setTimeout (int timeout) |
virtual bool | start () |
virtual bool | start () |
virtual void | step () |
virtual void | step () |
virtual bool | stop () |
virtual bool | stop () |
virtual bool | trigger () |
virtual bool | trigger () |
void | unwatch (int fd) |
void | unwatch (int fd) |
void | watch (int fd) |
void | watch (int fd) |
virtual | ~FileDescriptorActivity () |
virtual | ~FileDescriptorActivity () |
Private Member Functions | |
void | triggerUpdateSets () |
void | triggerUpdateSets () |
Private Attributes | |
fd_set | m_fd_set |
fd_set | m_fd_work |
bool | m_has_error |
bool | m_has_timeout |
int | m_interrupt_pipe [2] |
RTT::os::Mutex | m_lock |
bool | m_running |
int | m_timeout |
std::set< int > | m_watched_fds |
Static Private Attributes | |
static const int | CMD_BREAK_LOOP = 0 |
static const int | CMD_TRIGGER = 1 |
static const int | CMD_UPDATE_SETS = 2 |
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); }
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 101 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
FileDescriptorActivity::FileDescriptorActivity | ( | int | priority, | |
base::RunnableInterface * | _r = 0 , |
|||
const std::string & | name = "FileDescriptorActivity" | |||
) |
Create a FileDescriptorActivity with a given priority and base::RunnableInterface instance. The default scheduler for NonPeriodicActivity objects is ORO_SCHED_RT.
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. | |
name | The name of the underlying thread. |
Create a FileDescriptorActivity with a given priority and RunnableInterface instance. The default scheduler for NonPeriodicActivity objects is ORO_SCHED_RT.
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. |
Definition at line 79 of file FileDescriptorActivity.cpp.
FileDescriptorActivity::FileDescriptorActivity | ( | int | scheduler, | |
int | priority, | |||
base::RunnableInterface * | _r = 0 , |
|||
const std::string & | name = "FileDescriptorActivity" | |||
) |
Create a FileDescriptorActivity with a given scheduler type, priority and base::RunnableInterface instance.
scheduler | The scheduler in which the activitie's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. | |
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. | |
name | The name of the underlying thread. |
Create a FileDescriptorActivity with a given scheduler type, priority and RunnableInterface instance.
scheduler | The scheduler in which the activitie's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. | |
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. |
Definition at line 97 of file FileDescriptorActivity.cpp.
FileDescriptorActivity::~FileDescriptorActivity | ( | ) | [virtual] |
Definition at line 106 of file FileDescriptorActivity.cpp.
RTT::extras::FileDescriptorActivity::FileDescriptorActivity | ( | int | priority, | |
base::RunnableInterface * | _r = 0 , |
|||
const std::string & | name = "FileDescriptorActivity" | |||
) |
Create a FileDescriptorActivity with a given priority and base::RunnableInterface instance. The default scheduler for NonPeriodicActivity objects is ORO_SCHED_RT.
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. | |
name | The name of the underlying thread. |
RTT::extras::FileDescriptorActivity::FileDescriptorActivity | ( | int | scheduler, | |
int | priority, | |||
base::RunnableInterface * | _r = 0 , |
|||
const std::string & | name = "FileDescriptorActivity" | |||
) |
Create a FileDescriptorActivity with a given scheduler type, priority and base::RunnableInterface instance.
scheduler | The scheduler in which the activitie's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. | |
priority | The priority of the underlying thread. | |
_r | The optional runner, if none, this->loop() is called. | |
name | The name of the underlying thread. |
virtual RTT::extras::FileDescriptorActivity::~FileDescriptorActivity | ( | ) | [virtual] |
virtual bool RTT::extras::FileDescriptorActivity::breakLoop | ( | ) | [virtual] |
Reimplemented from RTT::Activity.
bool FileDescriptorActivity::breakLoop | ( | ) | [virtual] |
Reimplemented from RTT::Activity.
Definition at line 286 of file FileDescriptorActivity.cpp.
void RTT::extras::FileDescriptorActivity::clearAllWatches | ( | ) |
Remove all FDs that are currently being watched
void FileDescriptorActivity::clearAllWatches | ( | ) |
Remove all FDs that are currently being watched
Definition at line 135 of file FileDescriptorActivity.cpp.
int RTT::extras::FileDescriptorActivity::getTimeout | ( | ) | const |
Get the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).
int FileDescriptorActivity::getTimeout | ( | ) | const |
Get the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).
Definition at line 113 of file FileDescriptorActivity.cpp.
bool RTT::extras::FileDescriptorActivity::hasError | ( | ) | const |
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().
bool FileDescriptorActivity::hasError | ( | ) | const |
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().
Definition at line 149 of file FileDescriptorActivity.cpp.
bool RTT::extras::FileDescriptorActivity::hasTimeout | ( | ) | const |
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().
bool FileDescriptorActivity::hasTimeout | ( | ) | const |
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().
Definition at line 151 of file FileDescriptorActivity.cpp.
bool RTT::extras::FileDescriptorActivity::isRunning | ( | ) | const [virtual] |
Query if the activity is initialized and executing. This is more strict than isActive(), it is only true after initialize() is executed and before finalize() is executed. More-over, an Activity may decide to be temporarily not running (not executing code), waiting for a signal to proceed. If this->isActive() and !this->isRunning() then the Activity is in a waiting state.
Reimplemented from RTT::Activity.
bool FileDescriptorActivity::isRunning | ( | ) | const [virtual] |
Query if the activity is initialized and executing. This is more strict than isActive(), it is only true after initialize() is executed and before finalize() is executed. More-over, an Activity may decide to be temporarily not running (not executing code), waiting for a signal to proceed. If this->isActive() and !this->isRunning() then the Activity is in a waiting state.
Reimplemented from RTT::Activity.
Definition at line 111 of file FileDescriptorActivity.cpp.
bool RTT::extras::FileDescriptorActivity::isUpdated | ( | int | fd | ) | const |
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().
bool FileDescriptorActivity::isUpdated | ( | int | fd | ) | const |
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().
Definition at line 147 of file FileDescriptorActivity.cpp.
bool RTT::extras::FileDescriptorActivity::isWatched | ( | int | fd | ) | const |
True if this specific FD is being watched by the activity
bool FileDescriptorActivity::isWatched | ( | int | fd | ) | const |
True if this specific FD is being watched by the activity
Definition at line 153 of file FileDescriptorActivity.cpp.
virtual void RTT::extras::FileDescriptorActivity::loop | ( | ) | [virtual] |
Reimplemented from RTT::Activity.
void FileDescriptorActivity::loop | ( | ) | [virtual] |
Reimplemented from RTT::Activity.
Definition at line 188 of file FileDescriptorActivity.cpp.
void RTT::extras::FileDescriptorActivity::setTimeout | ( | int | timeout | ) |
Sets the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).
void FileDescriptorActivity::setTimeout | ( | int | timeout | ) |
Sets the timeout, in milliseconds, for waiting on the IO. Set to 0 for blocking behaviour (no timeout).
Definition at line 115 of file FileDescriptorActivity.cpp.
virtual bool RTT::extras::FileDescriptorActivity::start | ( | ) | [virtual] |
Start the activity. This will call RunnableInterface::initialize() and upon success, effectively start the activity, by running the RunnableInterface::step() or RunnableInterface::loop() in a thread.
Reimplemented from RTT::Activity.
bool FileDescriptorActivity::start | ( | ) | [virtual] |
Start the activity. This will call RunnableInterface::initialize() and upon success, effectively start the activity, by running the RunnableInterface::step() or RunnableInterface::loop() in a thread.
Reimplemented from RTT::Activity.
Definition at line 157 of file FileDescriptorActivity.cpp.
virtual void RTT::extras::FileDescriptorActivity::step | ( | ) | [virtual] |
Called by loop() when data is available on the file descriptor. By default, it calls step() on the associated runner interface (if any)
Reimplemented from RTT::Activity.
void FileDescriptorActivity::step | ( | ) | [virtual] |
Called by loop() when data is available on the file descriptor. By default, it calls step() on the associated runner interface (if any)
Reimplemented from RTT::Activity.
Definition at line 297 of file FileDescriptorActivity.cpp.
virtual bool RTT::extras::FileDescriptorActivity::stop | ( | ) | [virtual] |
Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call RunnableInterface::breakLoop(). If no errors occured, RunnableInterface::finalize() is called.
Reimplemented from RTT::Activity.
bool FileDescriptorActivity::stop | ( | ) | [virtual] |
Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call RunnableInterface::breakLoop(). If no errors occured, RunnableInterface::finalize() is called.
Reimplemented from RTT::Activity.
Definition at line 305 of file FileDescriptorActivity.cpp.
virtual bool RTT::extras::FileDescriptorActivity::trigger | ( | ) | [virtual] |
Force calling step() even if no data is available on the file descriptor, and returns true if the signalling was successful
Reimplemented from RTT::Activity.
bool FileDescriptorActivity::trigger | ( | ) | [virtual] |
Force calling step() even if no data is available on the file descriptor, and returns true if the signalling was successful
Reimplemented from RTT::Activity.
Definition at line 175 of file FileDescriptorActivity.cpp.
void RTT::extras::FileDescriptorActivity::triggerUpdateSets | ( | ) | [private] |
Internal method that makes sure loop() takes into account modifications in the set of watched FDs
void FileDescriptorActivity::triggerUpdateSets | ( | ) | [private] |
Internal method that makes sure loop() takes into account modifications in the set of watched FDs
Definition at line 141 of file FileDescriptorActivity.cpp.
void RTT::extras::FileDescriptorActivity::unwatch | ( | int | fd | ) |
Removes a file descriptor from the set of watched FDs
This method is thread-safe, i.e. it can be called from any thread
void FileDescriptorActivity::unwatch | ( | int | fd | ) |
Removes a file descriptor from the set of watched FDs
This method is thread-safe, i.e. it can be called from any thread
Definition at line 129 of file FileDescriptorActivity.cpp.
void RTT::extras::FileDescriptorActivity::watch | ( | int | fd | ) |
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 | |
close_on_stop | if true, the FD will be closed automatically when the activity is stopped |
void FileDescriptorActivity::watch | ( | int | fd | ) |
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 | |
close_on_stop | if true, the FD will be closed automatically when the activity is stopped |
Definition at line 117 of file FileDescriptorActivity.cpp.
static const int RTT::extras::FileDescriptorActivity::CMD_BREAK_LOOP = 0 [static, private] |
Definition at line 114 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
static const int RTT::extras::FileDescriptorActivity::CMD_TRIGGER = 1 [static, private] |
Definition at line 115 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
static const int RTT::extras::FileDescriptorActivity::CMD_UPDATE_SETS = 2 [static, private] |
Definition at line 116 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
fd_set RTT::extras::FileDescriptorActivity::m_fd_set [private] |
Definition at line 109 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
fd_set RTT::extras::FileDescriptorActivity::m_fd_work [private] |
Definition at line 110 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
bool RTT::extras::FileDescriptorActivity::m_has_error [private] |
Definition at line 111 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
bool RTT::extras::FileDescriptorActivity::m_has_timeout [private] |
Definition at line 112 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
int RTT::extras::FileDescriptorActivity::m_interrupt_pipe [private] |
Definition at line 105 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
RTT::os::Mutex RTT::extras::FileDescriptorActivity::m_lock [mutable, private] |
Lock that protects the access to m_fd_set and m_watched_fds
Definition at line 108 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
bool RTT::extras::FileDescriptorActivity::m_running [private] |
Definition at line 104 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
int RTT::extras::FileDescriptorActivity::m_timeout [private] |
Definition at line 106 of file install/include/rtt/extras/FileDescriptorActivity.hpp.
std::set< int > RTT::extras::FileDescriptorActivity::m_watched_fds [private] |
Definition at line 103 of file install/include/rtt/extras/FileDescriptorActivity.hpp.