E-MailRelay

gmonitor.h
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 gmonitor.h
19///
20
21#ifndef G_NET_MONITOR_H
22#define G_NET_MONITOR_H
23
24#include "gdef.h"
25#include "gslot.h"
26#include "gconnection.h"
27#include "glistener.h"
28#include <memory>
29#include <utility>
30#include <iostream>
31
32 namespace GNet
33{
34 class Monitor ;
35 class MonitorImp ;
36}
37
38//| \class GNet::Monitor
39/// A singleton for monitoring GNet::Client and GNet::ServerPeer
40/// connections.
41/// \see GNet::Client, GNet::ServerPeer
42///
43 class GNet::Monitor
44{
45 public:
46 Monitor() ;
47 ///< Default constructor.
48
49 ~Monitor() ;
50 ///< Destructor.
51
52 static Monitor * instance() ;
53 ///< Returns the singleton pointer. Returns nullptr if none.
54
55 static void addClient( const Connection & client ) ;
56 ///< Adds a client connection.
57
58 static void removeClient( const Connection & client ) noexcept ;
59 ///< Removes a client connection.
60
61 static void addServerPeer( const Connection & server_peer ) ;
62 ///< Adds a server connection.
63
64 static void removeServerPeer( const Connection & server_peer ) noexcept ;
65 ///< Removes a server connection.
66
67 static void addServer( const Listener & server ) ;
68 ///< Adds a server.
69
70 static void removeServer( const Listener & server ) noexcept ;
71 ///< Removes a server.
72
73 void report( std::ostream & stream ,
74 const std::string & line_prefix = {} ,
75 const std::string & eol = std::string("\n") ) const ;
76 ///< Reports itself onto a stream.
77
78 void report( G::StringArray & out ) const ;
79 ///< Reports itself into a three-column table (ordered
80 ///< with the column index varying fastest).
81
82 G::Slot::Signal<const std::string&,const std::string&> & signal() ;
83 ///< Provides a callback signal which can be connect()ed
84 ///< to a slot.
85 ///<
86 ///< The signal emits events with two string parameters:
87 ///< the first is "in", "out" or "listen", and the second
88 ///< is "start" or "stop".
89
90 public:
91 Monitor( const Monitor & ) = delete ;
92 Monitor( Monitor && ) = delete ;
93 Monitor & operator=( const Monitor & ) = delete ;
94 Monitor & operator=( Monitor && ) = delete ;
95
96 private:
97 static Monitor * & pthis() noexcept ;
98 std::unique_ptr<MonitorImp> m_imp ;
99 G::Slot::Signal<const std::string&,const std::string&> m_signal ;
100} ;
101
102#endif
GNet::Connection
An abstract interface which provides information about a network connection.
Definition: gconnection.h:38
GNet::Listener
An interface for a network listener.
Definition: glistener.h:37
GNet::Monitor
A singleton for monitoring GNet::Client and GNet::ServerPeer connections.
Definition: gmonitor.h:44
GNet::Monitor::addServer
static void addServer(const Listener &server)
Adds a server.
Definition: gmonitor.cpp:141
GNet::Monitor::removeClient
static void removeClient(const Connection &client) noexcept
Removes a client connection.
Definition: gmonitor.cpp:113
GNet::Monitor::addServerPeer
static void addServerPeer(const Connection &server_peer)
Adds a server connection.
Definition: gmonitor.cpp:122
GNet::Monitor::removeServer
static void removeServer(const Listener &server) noexcept
Removes a server.
Definition: gmonitor.cpp:150
GNet::Monitor::signal
G::Slot::Signal< const std::string &, const std::string & > & signal()
Provides a callback signal which can be connect()ed to a slot.
Definition: gmonitor.cpp:99
GNet::Monitor::report
void report(std::ostream &stream, const std::string &line_prefix={}, const std::string &eol=std::string("\n")) const
Reports itself onto a stream.
Definition: gmonitor.cpp:159
GNet::Monitor::Monitor
Monitor()
Default constructor.
Definition: gmonitor.cpp:82
GNet::Monitor::instance
static Monitor * instance()
Returns the singleton pointer. Returns nullptr if none.
Definition: gmonitor.cpp:94
GNet::Monitor::~Monitor
~Monitor()
Destructor.
Definition: gmonitor.cpp:89
GNet::Monitor::removeServerPeer
static void removeServerPeer(const Connection &server_peer) noexcept
Removes a server connection.
Definition: gmonitor.cpp:132
GNet::Monitor::addClient
static void addClient(const Connection &client)
Adds a client connection.
Definition: gmonitor.cpp:104
gconnection.h
glistener.h
gslot.h
GNet
Network classes.
Definition: gdef.h:1243
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
G::Slot::Signal< const std::string &, const std::string & >