1 // 2 // Copyright (C) 2001-2013 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_GNET_MONITOR_H 22 #define G_GNET_MONITOR_H 23 24 #include "gdef.h" 25 #include "gslot.h" 26 #include "gnet.h" 27 #include "gconnection.h" 28 #include "gnoncopyable.h" 29 #include <iostream> 30 #include <utility> 31 32 /// \namespace GNet 33 namespace GNet 34 { 35 class Monitor ; 36 class MonitorImp ; 37 } 38 39 /// \class GNet::Monitor 40 /// A singleton for monitoring SimpleClient and ServerPeer connections. 41 /// \see GNet::SimpleClient, GNet::ServerPeer 42 /// 43 class GNet::Monitor : public G::noncopyable 44 { 45 public: 46 Monitor() ; 47 ///< Default constructor. 48 49 virtual ~Monitor() ; 50 ///< Destructor. 51 52 static Monitor * instance() ; 53 ///< Returns the singleton pointer. Returns null if none. 54 55 void addClient( const Connection & simple_client ) ; 56 ///< Adds a client connection. 57 58 void removeClient( const Connection & simple_client ) ; 59 ///< Removes a client connection. 60 61 void addServerPeer( const Connection & server_peer ) ; 62 ///< Adds a server connection. 63 64 void removeServerPeer( const Connection & server_peer ) ; 65 ///< Removes a server connection. 66 67 void report( std::ostream & stream , 68 const std::string & line_prefix = std::string() , 69 const std::string & eol = std::string("\n") ) const ; 70 ///< Reports itself onto a stream. 71 72 std::pair<std::string,bool> findCertificate( const std::string & certificate ) ; 73 ///< Returns a short id for the given certificate and a boolean 74 ///< flag to indicate if it is a new certificate id that has 75 ///< not been returned before. 76 77 G::Signal2<std::string,std::string> & signal() ; 78 ///< Provides a callback signal which can be connect()ed 79 ///< to a slot. 80 ///< 81 ///< The signal emits events with two string parameters: 82 ///< the first is "in" or "out", and the second is 83 ///< "start" or "stop". 84 85 private: 86 static Monitor * & pthis() ; 87 MonitorImp * m_imp ; 88 G::Signal2<std::string,std::string> m_signal ; 89 } ; 90 91 #endif 92