E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

geventloop.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // ===
17 //
18 // geventloop.cpp
19 //
20
21 #include "gdef.h"
22 #include "geventloop.h"
23 #include "gdebug.h"
24 #include "gassert.h"
25
26 GNet::EventLoop * GNet::EventLoop::m_this = nullptr ;
27
28 GNet::EventLoop::EventLoop()
29 {
30 if( m_this == nullptr )
31 m_this = this ;
32 else
33 G_WARNING( "GNet::EventLoop::ctor: multiple instances" ) ;
34 }
35
36 GNet::EventLoop::~EventLoop()
37 {
38 if( m_this == this )
39 m_this = nullptr ;
40 }
41
42 GNet::EventLoop & GNet::EventLoop::instance()
43 {
44 if( m_this == nullptr )
45 throw NoInstance() ;
46 G_ASSERT( m_this != nullptr ) ;
47 return *m_this ;
48 }
49
50 bool GNet::EventLoop::exists()
51 {
52 return m_this != nullptr ;
53 }
54
55 void GNet::EventLoop::stop( const G::SignalSafe & signal_safe )
56 {
57 if( m_this != nullptr )
58 m_this->quit( signal_safe ) ;
59 }
60
61 void GNet::EventLoop::onException( std::exception & )
62 {
63 throw ;
64 }
65
66 /// \file geventloop.cpp
GNet::EventLoop::stop
static void stop(const G::SignalSafe &)
Calls quit() on instance().
Definition: geventloop.cpp:55
G::SignalSafe
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Definition: gsignalsafe.h:36
GNet::EventLoop
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:54
GNet::EventLoop::onException
virtual void onException(std::exception &) override
Override from ExceptionHandler that just rethrows the current exception.
Definition: geventloop.cpp:61
geventloop.h
gassert.h
GNet::EventLoop::EventLoop
EventLoop()
Constructor.
Definition: geventloop.cpp:28
GNet::EventLoop::exists
static bool exists()
Returns true if an instance exists.
Definition: geventloop.cpp:50
GNet::EventLoop::~EventLoop
virtual ~EventLoop()
Destructor.
Definition: geventloop.cpp:36
GNet::EventLoop::instance
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
Definition: geventloop.cpp:42
gdebug.h