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
26GNet::EventLoop * GNet::EventLoop::m_this = nullptr ;
27
29{
30 if( m_this == nullptr )
31 m_this = this ;
32 else
33 G_WARNING( "GNet::EventLoop::ctor: multiple instances" ) ;
34}
35
37{
38 if( m_this == this )
39 m_this = nullptr ;
40}
41
43{
44 return m_this ;
45}
46
48{
49 if( m_this == nullptr )
50 throw NoInstance() ;
51 return *m_this ;
52}
53
55{
56 return m_this != nullptr ;
57}
58
59void GNet::EventLoop::stop( const G::SignalSafe & signal_safe )
60{
61 if( m_this != nullptr )
62 m_this->quit( signal_safe ) ;
63}
64
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:53
virtual ~EventLoop()
Destructor.
Definition: geventloop.cpp:36
static void stop(const G::SignalSafe &)
Calls quit() on instance().
Definition: geventloop.cpp:59
static EventLoop * ptr() noexcept
Returns a pointer to an instance of the class, if any.
Definition: geventloop.cpp:42
static bool exists()
Returns true if an instance exists.
Definition: geventloop.cpp:54
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
Definition: geventloop.cpp:47
EventLoop()
Constructor.
Definition: geventloop.cpp:28
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Definition: gsignalsafe.h:37