- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

geventloop.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_EVENT_LOOP_H
22 #define G_EVENT_LOOP_H
23
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "geventhandler.h"
27 #include "gexception.h"
28 #include "gdatetime.h"
29 #include "gdescriptor.h"
30 #include <list>
31 #include <string>
32
34 namespace GNet
35 {
36 class EventLoop ;
37 }
38
51 class GNet::EventLoop
52 {
53 public:
54 G_EXCEPTION( NoInstance , "no event loop instance" ) ;
55
56 protected:
57 EventLoop() ;
59
60 public:
61 static EventLoop * create() ;
64
65 static EventLoop & instance() ;
70
71 static bool exists() ;
73
74 virtual ~EventLoop() ;
76
77 virtual bool init() = 0 ;
79
80 virtual std::string run() = 0 ;
83
84 virtual bool running() const = 0 ;
86
87 virtual void quit( std::string reason ) = 0 ;
92
93 virtual void addRead( Descriptor fd , EventHandler & handler ) = 0 ;
97
98 virtual void addWrite( Descriptor fd , EventHandler & handler ) = 0 ;
102
103 virtual void addException( Descriptor fd , EventHandler & handler ) = 0 ;
107
108 virtual void dropRead( Descriptor fd ) = 0 ;
112
113 virtual void dropWrite( Descriptor fd ) = 0 ;
117
118 virtual void dropException( Descriptor fd ) = 0 ;
122
123 virtual void setTimeout( G::DateTime::EpochTime t , bool & empty_implementation_hint ) = 0 ;
134
135 private:
136 static EventLoop * m_this ;
137 } ;
138
139 #endif
140
GNet::EventLoop::init
virtual bool init()=0
Initialises the object.
G::DateTime::EpochTime
std::time_t EpochTime
Definition: gdatetime.h:41
GNet
Network classes.
GNet::EventLoop::addWrite
virtual void addWrite(Descriptor fd, EventHandler &handler)=0
Adds the given event source descriptor and associated handler to the write list.
GNet::EventLoop
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:51
GNet::EventLoop::dropRead
virtual void dropRead(Descriptor fd)=0
Removes the given event source descriptor from the list of read sources.
GNet::Descriptor
A network file descriptor.
Definition: gdescriptor.h:37
GNet::EventLoop::dropException
virtual void dropException(Descriptor fd)=0
Removes the given event source descriptor from the list of exception sources.
GNet::EventLoop::addRead
virtual void addRead(Descriptor fd, EventHandler &handler)=0
Adds the given event source descriptor and associated handler to the read list.
GNet::EventLoop::running
virtual bool running() const =0
Returns true if called from within run().
GNet::EventLoop::run
virtual std::string run()=0
Runs the main event loop.
GNet::EventLoop::setTimeout
virtual void setTimeout(G::DateTime::EpochTime t, bool &empty_implementation_hint)=0
Used by GNet::TimerList.
GNet::EventLoop::addException
virtual void addException(Descriptor fd, EventHandler &handler)=0
Adds the given event source descriptor and associated handler to the exception list.
geventhandler.h
GNet::EventHandler
A base class for classes that handle asynchronous socket events.
Definition: geventhandler.h:54
GNet::EventLoop::EventLoop
EventLoop()
Constructor.
Definition: geventloop.cpp:29
gdescriptor.h
gdatetime.h
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GNet::EventLoop::create
static EventLoop * create()
A factory method which creates an instance of a derived class on the heap.
Definition: geventloop_unix.cpp:204
GNet::EventLoop::exists
static bool exists()
Returns true if an instance exists.
Definition: geventloop.cpp:51
GNet::EventLoop::~EventLoop
virtual ~EventLoop()
Destructor.
Definition: geventloop.cpp:37
GNet::EventLoop::dropWrite
virtual void dropWrite(Descriptor fd)=0
Removes the given event source descriptor from the list of write sources.
GNet::EventLoop::instance
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
Definition: geventloop.cpp:43
GNet::EventLoop::quit
virtual void quit(std::string reason)=0
Causes run() to return (once the call stack has unwound).