EchoLib  1.3.2
EchoLinkProxy.h
Go to the documentation of this file.
1 
32 #ifndef ECHOLINK_PROXY_INCLUDED
33 #define ECHOLINK_PROXY_INCLUDED
34 
35 
36 /****************************************************************************
37  *
38  * System Includes
39  *
40  ****************************************************************************/
41 
42 #include <string>
43 #include <sigc++/sigc++.h>
44 
45 
46 /****************************************************************************
47  *
48  * Project Includes
49  *
50  ****************************************************************************/
51 
52 #include <AsyncTcpClient.h>
53 #include <AsyncTimer.h>
54 
55 
56 /****************************************************************************
57  *
58  * Local Includes
59  *
60  ****************************************************************************/
61 
62 
63 
64 /****************************************************************************
65  *
66  * Forward declarations
67  *
68  ****************************************************************************/
69 
70 
71 
72 /****************************************************************************
73  *
74  * Namespace
75  *
76  ****************************************************************************/
77 
78 namespace EchoLink
79 {
80 
81 
82 /****************************************************************************
83  *
84  * Forward declarations of classes inside of the declared namespace
85  *
86  ****************************************************************************/
87 
88 
89 
90 /****************************************************************************
91  *
92  * Defines & typedefs
93  *
94  ****************************************************************************/
95 
96 
97 
98 /****************************************************************************
99  *
100  * Exported Global Variables
101  *
102  ****************************************************************************/
103 
104 
105 
106 /****************************************************************************
107  *
108  * Class definitions
109  *
110  ****************************************************************************/
111 
128 class Proxy : public sigc::trackable
129 {
130  public:
131  typedef enum
132  {
134  } ProxyState;
135 
136  typedef enum
137  {
140  } TcpState;
141 
142  static Proxy *instance(void) { return the_instance; }
143 
147  Proxy(const std::string &host, uint16_t port, const std::string &callsign,
148  const std::string &password);
149 
153  ~Proxy(void);
154 
158  void connect(void);
159 
163  void disconnect(void);
164 
168  void reset(void);
169 
182  bool tcpOpen(const Async::IpAddress &remote_ip);
183 
196  bool tcpClose(void);
197 
202  TcpState tcpState(void) { return tcp_state; }
203 
215  bool tcpData(const void *data, unsigned len);
216 
227  bool udpData(const Async::IpAddress &addr, const void *data, unsigned len);
228 
239  bool udpCtrl(const Async::IpAddress &addr, const void *data, unsigned len);
240 
250  sigc::signal<void, bool> proxyReady;
251 
258  sigc::signal<void> tcpConnected;
259 
266  sigc::signal<void> tcpDisconnected;
267 
282  sigc::signal<int, void*, unsigned> tcpDataReceived;
283 
293  sigc::signal<void, const Async::IpAddress&, void*,
294  unsigned> udpDataReceived;
295 
305  sigc::signal<void, const Async::IpAddress&, void*,
306  unsigned> udpCtrlReceived;
307 
320  sigc::signal<void, uint32_t> tcpStatusReceived;
321 
329  sigc::signal<void> tcpCloseReceived;
330 
331  protected:
332 
333  private:
334  typedef enum
335  {
336  MSG_TYPE_TCP_OPEN=1, MSG_TYPE_TCP_DATA, MSG_TYPE_TCP_CLOSE,
337  MSG_TYPE_TCP_STATUS, MSG_TYPE_UDP_DATA, MSG_TYPE_UDP_CONTROL,
338  MSG_TYPE_SYSTEM
339  } MsgBlockType;
340 
341  static const int NONCE_SIZE = 8;
342  static const int MSG_HEADER_SIZE = 1 + 4 + 4;
343  static const int RECONNECT_INTERVAL = 10000;
344  static const int CMD_TIMEOUT = 10000;
345  static const int recv_buf_size = 16384;
346 
347  static Proxy *the_instance;
348 
349  Async::TcpClient con;
350  const std::string callsign;
351  std::string password;
352  ProxyState state;
353  TcpState tcp_state;
354  uint8_t recv_buf[recv_buf_size];
355  int recv_buf_cnt;
356  Async::Timer reconnect_timer;
357  Async::Timer cmd_timer;
358 
359  Proxy(const Proxy&);
360  Proxy& operator=(const Proxy&);
361  bool sendMsgBlock(MsgBlockType type,
362  const Async::IpAddress &remote_ip=Async::IpAddress(),
363  const void *data=0, unsigned len=0);
364  void onConnected(void);
365  int onDataReceived(Async::TcpConnection *con, void *data, int len);
366  void onDisconnected(Async::TcpConnection *con,
367  Async::TcpClient::DisconnectReason reason);
368  void disconnectHandler(void);
369  int handleAuthentication(const unsigned char *buf, int len);
370  int parseProxyMessageBlock(unsigned char *buf, int len);
371  void handleProxyMessageBlock(MsgBlockType type,
372  const Async::IpAddress &remote_ip, uint32_t len,
373  unsigned char *data);
374  void handleTcpDataMsg(uint8_t *buf, int len);
375  void handleTcpCloseMsg(const uint8_t *buf, int len);
376  void handleTcpStatusMsg(const uint8_t *buf, int len);
377  void handleUdpDataMsg(const Async::IpAddress &remote_ip, uint8_t *buf,
378  int len);
379  void handleUdpCtrlMsg(const Async::IpAddress &remote_ip, uint8_t *buf,
380  int len);
381  void handleSystemMsg(const unsigned char *buf, int len);
382  void cmdTimeout(void);
383 
384 }; /* class Proxy */
385 
386 
387 } /* namespace */
388 
389 #endif /* ECHOLINK_PROXY_INCLUDED */
390 
391 
392 
393 /*
394  * This file has not been truncated
395  */
uint8_t data[1024]
Definition: EchoLinkQso.h:390