Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Examples  

SUEEventSelector Class Reference

Event selector. More...

#include <sue_sel.hpp>

Collaboration diagram for SUEEventSelector:

Collaboration graph
[legend]
List of all members.

Public Methods

 SUEEventSelector ()
 Constructor.

virtual ~SUEEventSelector ()
 Destructor.

void RegisterFdHandler (SUEFdHandler *h)
 Register file descriptor handler.

void RemoveFdHandler (SUEFdHandler *h)
 Removes the specified handler.

void RegisterTimeoutHandler (SUETimeoutHandler *h)
 Register a timeout handler.

void RemoveTimeoutHandler (SUETimeoutHandler *h)
 Removes the specified handler.

void RegisterSignalHandler (SUESignalHandler *h)
 Register a signal handler.

void RemoveSignalHandler (SUESignalHandler *h)
 Remove a signal handler.

void Go ()
 Main loop.

void Break ()
 Cause main loop to break (Go() function to return).

virtual void HandleSelectFailure (int rc)
 Handle select(2) errors.


Detailed Description

Event selector.

This class provides an object-oriented framework for the unix select(2) system call. It uses objects of:

Note:
This class is THE good point to start with. You *ALWAYS* need one (and in almost all cases only one) object of this class. The Go() method of this class is the main loop of your application, and the Break() method is used to break the main loop.
You can use this class as it is to create your Selector object. You might want to create a subclass when you need to use sets of handlers somewhere outside of the class (e.g., for debugging purposes), or if you want to handle select(2) failures specifically via overriding the HandleSelectFailure() method.
Examples:

chat.cpp, children.cpp, hellobot.cpp, sigs.cpp, sitter.cpp, and sleep5.cpp.


Constructor & Destructor Documentation

SUEEventSelector::SUEEventSelector  
 

Constructor.

virtual SUEEventSelector::~SUEEventSelector   [virtual]
 

Destructor.


Member Function Documentation

void SUEEventSelector::Break  
 

Cause main loop to break (Go() function to return).

This function sets the loop breaking flag which causes Go() function to return. The flag is cleared each time Go() is called. Go() checks for this flag after the main sequence of actions is performed, before repeating it.

Examples:
sigs.cpp, sitter.cpp, and sleep5.cpp.

void SUEEventSelector::Go  
 

Main loop.

This function

  • sets up the fd_set's for read, write and except notifications in accordance to the set of registered file handlers
  • chooses the closest time event from the set of registered timeout handlers
  • sets the signal handling functions as appropriate
  • calls select(2)
  • checks if any handled signals happened
  • examines the fd_set's for FDs changed state and calls the appropriate callback methods
  • examines the timeouts list, selects those are now in the past, removes each of them from the list of registered objects and calls its notification method
  • checks for the loop breaking flag. If it is set, breaks the loop and returns. Otherwise, continues from the beginning.

The function is intended to be the main loop of your process.

Examples:
chat.cpp, children.cpp, hellobot.cpp, sigs.cpp, sitter.cpp, and sleep5.cpp.

virtual void SUEEventSelector::HandleSelectFailure int    rc [inline, virtual]
 

Handle select(2) errors.

This method is called whenever select(2) returns negative value.

Parameters:
rc  is the value returned by select(2)
Note:
override this method to handle the event yourself

void SUEEventSelector::RegisterFdHandler SUEFdHandler   h
 

Register file descriptor handler.

Registers an FD to be watched. FD is specified with a SUEFdHandler subclass object. SUEFdHandler provides the value of the descriptor, the notification modes (r/w/e), and the callback function for notification (as a virtual method).

Note:
The FD handler remains registered unless it is explicitly unregistered with RemoveFdHandler method.
Warning:
It is assumed FD doesn't change when the handler is registered.
Examples:
sitter.cpp.

void SUEEventSelector::RegisterSignalHandler SUESignalHandler   h
 

Register a signal handler.

Registers a signal specified with SUESignalHandler object

Examples:
sigs.cpp.

void SUEEventSelector::RegisterTimeoutHandler SUETimeoutHandler   h
 

Register a timeout handler.

Registers a time moment at which to wake up and call the notification method. Time value (in seconds and microseconds) is specified by a SUEFdHandler subclass object which also provides a callback function for notification (as a virtual method).

Note:
The timeout handler remains registered unless either the moment comes and notification function is called OR it is explicitly unregistered with RemoveTimeoutHandler method.
Warning:
It is assumed that the value of the timeout doesn't change when it is registered. Changind it will lead to unpredictable behaviour. If you need to change thee timeout, then first unregister it, then change and register again.
Examples:
children.cpp, sitter.cpp, and sleep5.cpp.

void SUEEventSelector::RemoveFdHandler SUEFdHandler   h
 

Removes the specified handler.

Removes (unregisters) an FD handler. In case the handler is not registered, silently ignores the call

void SUEEventSelector::RemoveSignalHandler SUESignalHandler   h
 

Remove a signal handler.

void SUEEventSelector::RemoveTimeoutHandler SUETimeoutHandler   h
 

Removes the specified handler.

Removes (unregisters) a timeout handler. In case the handler is not registered, silently ignores the call

Examples:
sitter.cpp.


The documentation for this class was generated from the following file:
Generated on Fri Feb 27 13:17:26 2004 for SUE Library by doxygen1.2.18