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