VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::EventLoop Class Referenceabstract

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

#include <geventloop.h>

Classes

struct  Running
 RAII class that sets a boolean, for implementations of run()/running(). More...
 

Public Member Functions

virtual ~EventLoop ()
 Destructor.
 
virtual std::string run ()=0
 Runs the main event loop. More...
 
virtual bool running () const =0
 Returns true if called from within run().
 
virtual void quit (std::string reason)=0
 Causes run() to return (once the call stack has unwound). More...
 
virtual void quit (const G::SignalSafe &)=0
 A signal-safe overload to quit() the event loop.
 
virtual void addRead (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the read list. More...
 
virtual void addWrite (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the write list. More...
 
virtual void addException (Descriptor fd, EventHandler &handler)=0
 Adds the given event source descriptor and associated handler to the exception list. More...
 
virtual void dropRead (Descriptor fd)=0
 Removes the given event source descriptor from the list of read sources. More...
 
virtual void dropWrite (Descriptor fd)=0
 Removes the given event source descriptor from the list of write sources. More...
 
virtual void dropException (Descriptor fd)=0
 Removes the given event source descriptor from the list of exception sources. More...
 
virtual void setTimeout (G::EpochTime t)=0
 Used by GNet::TimerList. More...
 
virtual std::string report () const =0
 Returns a line of text reporting the status of the event loop. More...
 

Static Public Member Functions

static EventLoopcreate ()
 A factory method which creates an instance of a derived class on the heap. More...
 
static EventLoopinstance ()
 Returns a reference to an instance of the class, if any. More...
 
static bool exists ()
 Returns true if an instance exists.
 
static void stop (const G::SignalSafe &)
 Calls quit() on instance().
 

Protected Member Functions

 EventLoop ()
 Constructor.
 

Detailed Description

An abstract base class for a singleton that 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 52 of file geventloop.h.

Member Function Documentation

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().

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().

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().

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

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

Throws on error.

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().

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().

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().

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

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

Throws if none. Does not do any instantiation itself.

Definition at line 43 of file geventloop.cpp.

virtual void GNet::EventLoop::quit ( std::string  reason)
pure virtual

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

If there are multiple quit()s before run() returns then the latest reason is used.

virtual std::string GNet::EventLoop::report ( ) const
pure virtual

Returns a line of text reporting the status of the event loop.

Used in debugging and diagnostics.

virtual std::string GNet::EventLoop::run ( )
pure virtual

Runs the main event loop.

Returns a quit() reason, if any.

virtual void GNet::EventLoop::setTimeout ( G::EpochTime  t)
pure virtual

Used by GNet::TimerList.

Sets the absolute time at which TimerList::doTimeouts() is to be called. A zero time is used if there are no active timers.


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