40 void remove(
const Connection & ,
bool is_client ) ;
41 void report( std::ostream & s ,
const std::string & px ,
const std::string & eol )
const ;
42 std::string
certificateId(
const std::string & certificiate ) ;
43 std::pair<std::string,bool>
findCertificate(
const std::string & certificate ) ;
49 explicit ConnectionInfo(
bool is_client_ ) : is_client(is_client_) {}
51 struct CertificateInfo
53 std::string certificate ;
55 CertificateInfo(
const std::string & c ,
int id_ ) : certificate(c) , id(id_) {}
56 bool match( std::string s )
const {
return s == certificate ; }
58 struct CertificateMatch
60 const std::string & m_s ;
61 explicit CertificateMatch(
const std::string & s ) : m_s(s) {}
62 bool operator()(
const CertificateInfo & o )
const {
return o.match(m_s) ; }
64 typedef std::map<const Connection*,ConnectionInfo> ConnectionMap ;
65 typedef std::deque<CertificateInfo> Certificates ;
66 ConnectionMap m_connections ;
67 Certificates m_certificates ;
69 unsigned long m_client_adds ;
70 unsigned long m_client_removes ;
71 unsigned long m_server_peer_adds ;
72 unsigned long m_server_peer_removes ;
78 m_client_removes(0UL) ,
79 m_server_peer_adds(0UL) ,
80 m_server_peer_removes(0UL)
117 m_imp->add( client ,
true ) ;
118 m_signal.emit(
"out" ,
"start" ) ;
123 m_imp->remove( client ,
true ) ;
124 m_signal.emit(
"out" ,
"end" ) ;
129 m_imp->add( server_peer ,
false ) ;
130 m_signal.emit(
"in" ,
"start" ) ;
136 m_imp->remove( server_peer ,
false ) ;
137 m_signal.emit(
"in" ,
"end" ) ;
142 return m_imp->findCertificate( certificate ) ;
147 m_imp->report( s , px , eol ) ;
154 bool inserted = m_connections.insert(ConnectionMap::value_type(&connection,ConnectionInfo(is_client))).second ;
160 m_server_peer_adds++ ;
166 bool removed = 0U != m_connections.erase( &connection ) ;
172 m_server_peer_removes++ ;
178 s << px <<
"OUT started: " << m_client_adds << eol ;
179 s << px <<
"OUT finished: " << m_client_removes << eol ;
181 for( ConnectionMap::const_iterator p = m_connections.begin() ; p != m_connections.end() ; ++p )
183 if( (*p).second.is_client )
187 << (*p).first->localAddress().second.displayString() <<
" -> "
188 << (*p).first->peerAddress().second.displayString() << eol ;
193 s << px <<
"IN started: " << m_server_peer_adds << eol ;
194 s << px <<
"IN finished: " << m_server_peer_removes << eol ;
196 for( ConnectionMap::const_iterator p = m_connections.begin() ; p != m_connections.end() ; ++p )
198 if( !(*p).second.is_client )
202 << (*p).first->localAddress().second.displayString() <<
" <- "
203 << (*p).first->peerAddress().second.displayString() << eol ;
211 std::pair<std::string,bool> result( std::string() ,
false ) ;
212 if( certificate.empty() )
216 Certificates::iterator p = std::find_if( m_certificates.begin() , m_certificates.end() , CertificateMatch(certificate) ) ;
217 if( p != m_certificates.end() )
219 CertificateInfo tmp = *p ;
221 result.second = false ;
222 p = std::remove_if( m_certificates.begin() , m_certificates.end() , CertificateMatch(certificate) ) ;
223 G_ASSERT( p != m_certificates.end() ) ;
229 if( m_certificates.size() == limit && !m_certificates.empty() )
230 m_certificates.pop_front() ;
231 int id = ++m_id_generator ;
232 m_certificates.push_back( CertificateInfo(certificate,
id) ) ;
234 result.second = true ;
void removeServerPeer(const Connection &server_peer)
Removes a server connection.
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.
std::pair< std::string, bool > findCertificate(const std::string &certificate)
G::Signal2< std::string, std::string > & signal()
Provides a callback signal which can be connect()ed to a slot.
void addClient(const Connection &simple_client)
Adds a client connection.
void remove(const Connection &, bool is_client)
static std::string fromInt(int i)
Converts int 'i' to a string.
void report(std::ostream &s, const std::string &px, const std::string &eol) const
A pimple pattern implementation class for GNet::Monitor.
std::string certificateId(const std::string &certificiate)
A singleton for monitoring SimpleClient and ServerPeer connections.
static Monitor * instance()
Returns the singleton pointer. Returns null if none.
virtual ~Monitor()
Destructor.
void removeClient(const Connection &simple_client)
Removes a client connection.
void addServerPeer(const Connection &server_peer)
Adds a server connection.
An interface which provides address information for a network connection.
std::pair< std::string, bool > findCertificate(const std::string &certificate)
Returns a short id for the given certificate and a boolean flag to indicate if it is a new certificat...
MonitorImp(Monitor &monitor)
void add(const Connection &, bool is_client)
Monitor()
Default constructor.