File descriptor event. More...
#include <senf/Scheduler/FdEvent.hh>
Classes | |
struct | DuplicateEventRegistrationException |
Public Types | |
enum | Events { EV_NULL = 0, EV_READ = detail::FdManager::EV_READ, EV_PRIO = detail::FdManager::EV_PRIO, EV_WRITE = detail::FdManager::EV_WRITE, EV_HUP = detail::FdManager::EV_HUP, EV_ERR = detail::FdManager::EV_ERR, EV_ALL } |
typedef boost::function< void(int)> | Callback |
Public Types inherited from senf::scheduler::detail::FIFORunner::TaskInfo | |
enum | Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 } |
Public Member Functions | |
void | disable () |
Disable event. More... | |
void | enable () |
Enable event. More... | |
FdEvent & | action (Callback const &cb) |
Change event callback. More... | |
FdEvent & | events (int events) |
Change event mask. More... | |
FdEvent & | addEvents (int events) |
Add additional events to event mask. More... | |
FdEvent & | removeEvents (int events) |
Remove events from event mask. More... | |
int | events () |
Current event mask. More... | |
template<class Handle > | |
FdEvent & | handle (Handle const &handle) |
Change event file handle. More... | |
Public Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo | |
TaskInfo (std::string const &name, Priority priority=PRIORITY_NORMAL) | |
virtual | ~TaskInfo () |
void | run () |
bool | runnable () const |
Public Member Functions inherited from senf::scheduler::detail::Event | |
std::string const & | name () const |
Get event name. More... | |
bool | enabled () const |
true , if event is enabled, false otherwise More... | |
unsigned | runCount () const |
Number of times, event was fired. More... | |
char const * | type () const |
Event type code. More... | |
std::string | info () const |
Additional event information. More... | |
Event (std::string const &name) | |
virtual | ~Event () |
Public Member Functions inherited from senf::scheduler::detail::FdManager::Event | |
virtual | ~Event () |
Structors and default members | |
template<class Handle > | |
FdEvent (std::string const &name, Callback const &cb, Handle const &handle, int events, bool initiallyEnabled=true) | |
Register a file descriptor event. More... | |
FdEvent (std::string const &name, Callback const &cb) | |
Create a file descriptor event. More... | |
~FdEvent () | |
Additional Inherited Members | |
Protected Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo | |
void | setRunnable () |
Protected Member Functions inherited from senf::scheduler::detail::Event | |
void | countRun () |
File descriptor event.
The FdEvent class registers a file descriptor for read or write events.
There are a number of different event types supported for file descriptors. Those are specified using a bit mask. Possible events are
EV_READ:
File descriptor is readable (or at EOF) EV_PRIO:
There is out-of-band data available to be read on the file descriptor EV_WRITE:
File descriptor is writableThe callback will be called with one additional argument. This argument is the event mask of type int. This mask will tell, which of the registered events are signaled. There are some additional flags which can be set when calling the handler callback:
EV_HUP:
The other end has closed the connection EV_ERR:
Transport errorOnly a single handler may be registered for any combination of file descriptor and event otherwise a DuplicateEventRegistrationException is thrown.
The file descriptor is specified using an arbitrary handle type which supports the retrieve_filehandle()
protocol: There must be a global function retrieve_filehandle
callable with the handle type. This function must return the file descriptor associated with the handle. Implementations for integer numbers (explicit file descriptors) and senf socket handles are provided.
The FdEvent class is an implementation of the RAII idiom: The event will be automatically unregistered in the FdEvent destructor. The FdEvent instance should be created within the same scope or on a scope below where the callback is defined (e.g. if the callback is a member function it should be defined as a class member).
Definition at line 72 of file FdEvent.hh.
typedef boost::function<void (int)> senf::scheduler::FdEvent::Callback |
Definition at line 81 of file FdEvent.hh.
Definition at line 83 of file FdEvent.hh.
senf::scheduler::FdEvent::FdEvent | ( | std::string const & | name, |
Callback const & | cb, | ||
Handle const & | handle, | ||
int | events, | ||
bool | initiallyEnabled = true |
||
) |
Register a file descriptor event.
Registers cb to be called when any of the events occurs on handle. If initiallyEnabled is set false
, the callback will not be enabled automatically. Use enable() to do so.
[in] | name | Descriptive event name (purely informational) |
[in] | cb | Callback to call |
[in] | handle | Handle (file descriptor) to watch |
[in] | events | Events to watch for (see Events enum) |
[in] | initiallyEnabled | if set false , do not enable callback automatically. |
senf::scheduler::FdEvent::FdEvent | ( | std::string const & | name, |
Callback const & | cb | ||
) |
Create a file descriptor event.
Creates a file descriptor event for callback cb. The event is initially disabled. Use the other members to set the missing parameters and enable the event.
[in] | name | Descriptive event name (purely informational) |
[in] | cb | Callback to call. This callback may explicitly be set to 0 if the value cannot be initialized. |
senf::scheduler::FdEvent::~FdEvent | ( | ) |
FdEvent& senf::scheduler::FdEvent::addEvents | ( | int | events | ) |
Add additional events to event mask.
void senf::scheduler::FdEvent::disable | ( | ) |
Disable event.
Definition at line 120 of file FdEvent.cc.
void senf::scheduler::FdEvent::enable | ( | ) |
Enable event.
Definition at line 130 of file FdEvent.cc.
senf::scheduler::FdEvent & senf::scheduler::FdEvent::events | ( | int | events | ) |
Change event mask.
Definition at line 140 of file FdEvent.cc.
int senf::scheduler::FdEvent::events | ( | ) |
Current event mask.
FdEvent& senf::scheduler::FdEvent::handle | ( | Handle const & | handle | ) |
Change event file handle.
FdEvent& senf::scheduler::FdEvent::removeEvents | ( | int | events | ) |
Remove events from event mask.