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