gclient.h
Go to the documentation of this file.
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 // ===
20 
21 #ifndef G_CLIENT_H
22 #define G_CLIENT_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gheapclient.h"
27 #include "glinebuffer.h"
28 #include "gtimer.h"
29 #include "gslot.h"
30 
32 namespace GNet
33 {
34  class ClientTimer ;
35  class Client ;
36 }
37 
52 {
53 public:
54  explicit Client( const ResolverInfo & remote_info , unsigned int connection_timeout = 0U ,
55  unsigned int response_timeout = 0U , unsigned int secure_connection_timeout = 0U ,
56  const std::string & eol = std::string("\n") ,
57  const Address & local_interface = Address(0U) , bool privileged = false ,
58  bool sync_dns = synchronousDnsDefault() ) ;
60 
68 
76 
80 
84 
85 protected:
86  virtual ~Client() ;
88 
89  virtual bool onReceive( const std::string & ) = 0 ;
95 
96  void clearInput() ;
98 
99  virtual void onDeleteImp( const std::string & , bool ) ;
101 
102  virtual void onConnectImp() ;
104 
105  virtual void onData( const char * , SimpleClient::size_type ) ;
107 
108  virtual void onConnecting() ;
110 
111  virtual void onSendImp() ;
113 
114 private:
115  Client( const Client& ) ; // not implemented
116  void operator=( const Client& ) ; // not implemented
117  void onConnectionTimeout() ;
118  void onResponseTimeout() ;
119 
120 private:
121  G::Signal2<std::string,bool> m_done_signal ;
122  G::Signal2<std::string,std::string> m_event_signal ;
123  G::Signal0 m_connected_signal ;
124  G::Signal0 m_secure_signal ;
125  unsigned int m_connection_timeout ;
126  unsigned int m_response_timeout ;
127  GNet::Timer<Client> m_connection_timer ;
128  GNet::Timer<Client> m_response_timer ;
129  GNet::LineBuffer m_line_buffer ;
130 } ;
131 
132 #endif
Client(const ResolverInfo &remote_info, unsigned int connection_timeout=0U, unsigned int response_timeout=0U, unsigned int secure_connection_timeout=0U, const std::string &eol=std::string("\n"), const Address &local_interface=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault())
Constructor.
Definition: gclient.cpp:25
std::string::size_type size_type
Definition: gsimpleclient.h:86
Network classes.
virtual void onSendImp()
Final override from GNet::SimpleClient.
Definition: gclient.cpp:69
G::Signal0 & connectedSignal()
Returns a signal that incidcates that the client has successfully connected to the server...
Definition: gclient.cpp:95
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
G::Signal2< std::string, bool > & doneSignal()
Returns a signal that indicates that client processing is complete.
Definition: gclient.cpp:85
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
virtual void onDeleteImp(const std::string &, bool)
Override from GNet::HeapClient.
Definition: gclient.cpp:61
G::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something interesting has happened.
Definition: gclient.cpp:90
virtual ~Client()
Destructor.
Definition: gclient.cpp:42
virtual void onData(const char *, SimpleClient::size_type)
Final override from GNet::SocketProtocolSink.
Definition: gclient.cpp:105
void clearInput()
Clears any pending input from the server.
Definition: gclient.cpp:122
virtual bool onReceive(const std::string &)=0
Called when a complete line is received from the peer.
A SimpleClient class for client objects that manage their own lifetime on the heap.
Definition: gheapclient.h:54
Part of the slot/signal system.
Definition: gslot.h:138
static bool synchronousDnsDefault()
Returns true if DNS queries should normally be synchronous on this platform.
G::Signal0 & secureSignal()
Returns a signal that incidcates that the security layer has been successfully established.
Definition: gclient.cpp:100
A class which does line buffering.
Definition: glinebuffer.h:52
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:103
virtual void onConnectImp()
Final override from GNet::SimpleClient.
Definition: gclient.cpp:51
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:51
virtual void onConnecting()
Final override from GNet::HeapClient.
Definition: gclient.cpp:46