My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
SshClient.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_SSHCLIENT_H
2 #define GCP_UTIL_SSHCLIENT_H
3 
11 #include "gcp/util/common/FdSet.h"
12 #include "gcp/util/common/NetDat.h"
13 #include "gcp/util/common/NetHandler.h"
14 #include "gcp/util/common/Runnable.h"
15 #include "gcp/util/common/SshTunnel.h"
16 #include "gcp/util/common/TcpClient.h"
17 #include "gcp/util/common/TimeVal.h"
18 
19 namespace gcp {
20  namespace util {
21 
22  class SshClient : public Runnable {
23  public:
24 
28  SshClient(bool spawn,
29  std::string gateway, std::string host, unsigned connectPort,
30  unsigned readBufSize=0, unsigned sendBufSize=0);
31 
35  virtual ~SshClient();
36 
40  void run();
41 
42  void setReadBufSize(unsigned size);
43  void setSendBufSize(unsigned size);
44 
45  protected:
46 
47  // Method called when data have been completely read from the server
48 
49  virtual void readServerData(NetHandler& handler) {};
50 
51  // Send data to the server
52 
53  void sendServerData(NetDat& dat);
54 
55  TimeVal timeOut_;
56  struct timeval* timeOutPtr_;
57 
58  protected:
59 
60  SshTunnel tunnel_;
61 
62  std::string gateway_;
63  std::string host_;
64  unsigned short port_;
65 
66  bool stop_;
67 
68  // The connection manager
69 
70  TcpClient tcp_;
71 
72  NetHandler handler_;
73 
74  FdSet fdSet_;
75 
76  void initMembers(std::string gateway, std::string host, unsigned port,
77  unsigned readBufSize, unsigned sendBufSize);
78 
79  // A run method to be called from pthread_start()
80 
81  static RUN_FN(runFn);
82 
83  static NET_READ_HANDLER(readHandler);
84  static NET_SEND_HANDLER(sendHandler);
85  static NET_ERROR_HANDLER(errHandler);
86 
87  void connect();
88  void disconnect();
89  virtual void reportError() {};
90 
91  }; // End class SshClient
92 
93  } // End namespace util
94 } // End namespace gcp
95 
96 
97 #endif // End #ifndef GCP_UTIL_SSHCLIENT_H
void run()
Definition: SshClient.cc:129
Definition: SshTunnel.h:40
Definition: SshClient.h:22
Definition: NetHandler.h:16
Definition: FdSet.h:16
Definition: TcpClient.h:18
Definition: Runnable.h:23
Definition: TimeVal.h:55
SshClient(bool spawn, std::string gateway, std::string host, unsigned connectPort, unsigned readBufSize=0, unsigned sendBufSize=0)
Definition: SshClient.cc:15
Definition: NetDat.h:23
virtual ~SshClient()
Definition: SshClient.cc:77
void sendServerData(NetDat &dat)
Definition: SshClient.cc:85