E-MailRelay

geventloop.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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/// \file geventloop.cpp
19///
20
21#include "gdef.h"
22#include "geventloop.h"
23#include "glog.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::ptr() noexcept
43{
44 return m_this ;
45}
46
47 GNet::EventLoop & GNet::EventLoop::instance()
48{
49 if( m_this == nullptr )
50 throw NoInstance() ;
51 return *m_this ;
52}
53
54 bool GNet::EventLoop::exists()
55{
56 return m_this != nullptr ;
57}
58
59 void GNet::EventLoop::stop( const G::SignalSafe & signal_safe )
60{
61 if( m_this != nullptr )
62 m_this->quit( signal_safe ) ;
63}
64
GNet::EventLoop
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:53
GNet::EventLoop::~EventLoop
virtual ~EventLoop()
Destructor.
Definition: geventloop.cpp:36
GNet::EventLoop::stop
static void stop(const G::SignalSafe &)
Calls quit() on instance().
Definition: geventloop.cpp:59
GNet::EventLoop::ptr
static EventLoop * ptr() noexcept
Returns a pointer to an instance of the class, if any.
Definition: geventloop.cpp:42
GNet::EventLoop::exists
static bool exists()
Returns true if an instance exists.
Definition: geventloop.cpp:54
GNet::EventLoop::instance
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
Definition: geventloop.cpp:47
GNet::EventLoop::EventLoop
EventLoop()
Constructor.
Definition: geventloop.cpp:28
G::SignalSafe
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Definition: gsignalsafe.h:37
gassert.h
geventloop.h
glog.h