GNet::EventLoop Class Reference

An abstract base class for a singleton which keeps track of open sockets and their associated handlers. More...

#include <geventloop.h>

Inheritance diagram for GNet::EventLoop:

GNet::Select

List of all members.

Public Member Functions

virtual ~EventLoop ()
 Destructor.
virtual bool init ()=0
 Initialises the object.
virtual void run ()=0
 Runs the main event loop.
virtual bool running () const =0
 Returns true if called from within run().
virtual bool quit ()=0
 Causes run() to return (once the call stack has unwound).
virtual void addRead (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the read list.
virtual void addWrite (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the write list.
virtual void addException (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the exception list.
virtual void dropRead (Descriptor fd)=0
 Removes the given event source descriptor from the list of read sources.
virtual void dropWrite (Descriptor fd)=0
 Removes the given event source descriptor from the list of write sources.
virtual void dropException (Descriptor fd)=0
 Removes the given event source descriptor from the list of exception sources.
virtual void setTimeout (G::DateTime::EpochTime t, bool &empty_implementation_hint)=0
 Used by GNet::TimerList.

Static Public Member Functions

static EventLoopcreate ()
 A factory method which creates an instance of a derived class on the heap.
static EventLoopinstance ()
 Returns a reference to an instance of the class, if any.
static bool exists ()
 Returns true if an instance exists.

Protected Member Functions

 EventLoop ()
 Constructor.


Detailed Description

An abstract base class for a singleton which keeps track of open sockets and their associated handlers.

Derived classes are used to implement different event loops, such as select() or WinSock.

In practice sockets are added and removed from the class by calling GNet::Socket::addReadHandler() etc rather than EventLoop::addRead(). This is to improve the encapsulation of the GNet::Descriptor data type within Socket.

The class has a static member for finding an instance, but instances are not created automatically.

Definition at line 55 of file geventloop.h.


Constructor & Destructor Documentation

GNet::EventLoop::EventLoop (  )  [protected]

Constructor.

Definition at line 29 of file geventloop.cpp.

References G_WARNING.

GNet::EventLoop::~EventLoop (  )  [virtual]

Destructor.

Definition at line 37 of file geventloop.cpp.


Member Function Documentation

GNet::EventLoop * GNet::EventLoop::create (  )  [static]

A factory method which creates an instance of a derived class on the heap.

Definition at line 203 of file geventloop_unix.cpp.

GNet::EventLoop & GNet::EventLoop::instance (  )  [static]

Returns a reference to an instance of the class, if any.

Asserts if none. Does not do any instantiation itself. Precondition: exists()

Definition at line 43 of file geventloop.cpp.

References G_ASSERT.

Referenced by GNet::Socket::addExceptionHandler(), GNet::Socket::addReadHandler(), GNet::Socket::addWriteHandler(), GNet::Socket::dropExceptionHandler(), GNet::Socket::dropReadHandler(), GNet::Socket::dropWriteHandler(), GSmtp::AdminServerPeer::onReceive(), and GNet::TimerList::update().

bool GNet::EventLoop::exists (  )  [static]

Returns true if an instance exists.

Definition at line 51 of file geventloop.cpp.

Referenced by GNet::AbstractTimer::AbstractTimer(), GSmtp::AdminServerPeer::onReceive(), and GNet::TimerList::update().

virtual bool GNet::EventLoop::init (  )  [pure virtual]

Initialises the object.

Implemented in GNet::Select.

virtual void GNet::EventLoop::run (  )  [pure virtual]

Runs the main event loop.

Implemented in GNet::Select.

virtual bool GNet::EventLoop::running (  )  const [pure virtual]

Returns true if called from within run().

Implemented in GNet::Select.

virtual bool GNet::EventLoop::quit (  )  [pure virtual]

Causes run() to return (once the call stack has unwound).

Returns true, or on some platforms the previous state of the quit flag. (This means that run() can be used to process one event at a time for testing purposes).

Implemented in GNet::Select.

virtual void GNet::EventLoop::addRead ( Descriptor  fd,
EventHandler handler 
) [pure virtual]

Adds the given event source descriptor and associated handler to the read list.

See also Socket::addReadHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::addReadHandler().

virtual void GNet::EventLoop::addWrite ( Descriptor  fd,
EventHandler handler 
) [pure virtual]

Adds the given event source descriptor and associated handler to the write list.

See also Socket::addWriteHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::addWriteHandler().

virtual void GNet::EventLoop::addException ( Descriptor  fd,
EventHandler handler 
) [pure virtual]

Adds the given event source descriptor and associated handler to the exception list.

See also Socket::addExceptionHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::addExceptionHandler().

virtual void GNet::EventLoop::dropRead ( Descriptor  fd  )  [pure virtual]

Removes the given event source descriptor from the list of read sources.

See also Socket::dropReadHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::dropReadHandler().

virtual void GNet::EventLoop::dropWrite ( Descriptor  fd  )  [pure virtual]

Removes the given event source descriptor from the list of write sources.

See also Socket::dropWriteHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::dropWriteHandler().

virtual void GNet::EventLoop::dropException ( Descriptor  fd  )  [pure virtual]

Removes the given event source descriptor from the list of exception sources.

See also Socket::dropExceptionHandler().

Implemented in GNet::Select.

Referenced by GNet::Socket::dropExceptionHandler().

virtual void GNet::EventLoop::setTimeout ( G::DateTime::EpochTime  t,
bool &  empty_implementation_hint 
) [pure virtual]

Used by GNet::TimerList.

Sets the time at which TimerList::doTimeouts() is to be called. A parameter of zero is used to cancel the timer.

Some concrete implementations of this interface may use TimerList::interval() rather than setTimeout()/doTimeouts(). Empty implementations should set the hint value to true as an optimisation.

Referenced by GNet::TimerList::update().


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5