EchoLib 1.3.5
EchoLinkProxy.h
Go to the documentation of this file.
1
27#ifndef ECHOLINK_PROXY_INCLUDED
28#define ECHOLINK_PROXY_INCLUDED
29
30
31/****************************************************************************
32 *
33 * System Includes
34 *
35 ****************************************************************************/
36
37#include <string>
38#include <sigc++/sigc++.h>
39
40
41/****************************************************************************
42 *
43 * Project Includes
44 *
45 ****************************************************************************/
46
47#include <AsyncTcpClient.h>
48#include <AsyncTimer.h>
49
50
51/****************************************************************************
52 *
53 * Local Includes
54 *
55 ****************************************************************************/
56
57
58
59/****************************************************************************
60 *
61 * Forward declarations
62 *
63 ****************************************************************************/
64
65
66
67/****************************************************************************
68 *
69 * Namespace
70 *
71 ****************************************************************************/
72
73namespace EchoLink
74{
75
76
77/****************************************************************************
78 *
79 * Forward declarations of classes inside of the declared namespace
80 *
81 ****************************************************************************/
82
83
84
85/****************************************************************************
86 *
87 * Defines & typedefs
88 *
89 ****************************************************************************/
90
91
92
93/****************************************************************************
94 *
95 * Exported Global Variables
96 *
97 ****************************************************************************/
98
99
100
101/****************************************************************************
102 *
103 * Class definitions
104 *
105 ****************************************************************************/
106
121class Proxy : public sigc::trackable
122{
123 public:
128
134
135 static Proxy *instance(void) { return the_instance; }
136
140 Proxy(const std::string &host, uint16_t port, const std::string &callsign,
141 const std::string &password);
142
146 ~Proxy(void);
147
151 void connect(void);
152
156 void disconnect(void);
157
161 void reset(void);
162
175 bool tcpOpen(const Async::IpAddress &remote_ip);
176
189 bool tcpClose(void);
190
195 TcpState tcpState(void) { return tcp_state; }
196
208 bool tcpData(const void *data, unsigned len);
209
220 bool udpData(const Async::IpAddress &addr, const void *data, unsigned len);
221
232 bool udpCtrl(const Async::IpAddress &addr, const void *data, unsigned len);
233
243 sigc::signal<void, bool> proxyReady;
244
251 sigc::signal<void> tcpConnected;
252
259 sigc::signal<void> tcpDisconnected;
260
275 sigc::signal<int, void*, unsigned> tcpDataReceived;
276
287 sigc::signal<void, const Async::IpAddress&, uint16_t, void*,
289
300 sigc::signal<void, const Async::IpAddress&, uint16_t, void*,
302
315 sigc::signal<void, uint32_t> tcpStatusReceived;
316
324 sigc::signal<void> tcpCloseReceived;
325
326 protected:
327
328 private:
329 typedef enum
330 {
331 MSG_TYPE_TCP_OPEN=1, MSG_TYPE_TCP_DATA, MSG_TYPE_TCP_CLOSE,
332 MSG_TYPE_TCP_STATUS, MSG_TYPE_UDP_DATA, MSG_TYPE_UDP_CONTROL,
333 MSG_TYPE_SYSTEM
334 } MsgBlockType;
335
336 static const int NONCE_SIZE = 8;
337 static const int MSG_HEADER_SIZE = 1 + 4 + 4;
338 static const int RECONNECT_INTERVAL = 10000;
339 static const int CMD_TIMEOUT = 10000;
340 static const int recv_buf_size = 16384;
341
342 static Proxy *the_instance;
343
344 Async::TcpClient<> con;
345 const std::string callsign;
346 std::string password;
347 ProxyState state;
348 TcpState tcp_state;
349 uint8_t recv_buf[recv_buf_size];
350 int recv_buf_cnt;
351 Async::Timer reconnect_timer;
352 Async::Timer cmd_timer;
353
354 Proxy(const Proxy&);
355 Proxy& operator=(const Proxy&);
356 bool sendMsgBlock(MsgBlockType type,
357 const Async::IpAddress &remote_ip=Async::IpAddress(),
358 const void *data=0, unsigned len=0);
359 void onConnected(void);
360 int onDataReceived(Async::TcpConnection *con, void *data, int len);
361 void onDisconnected(Async::TcpConnection *con,
362 Async::TcpClient<>::DisconnectReason reason);
363 void disconnectHandler(void);
364 int handleAuthentication(const unsigned char *buf, int len);
365 int parseProxyMessageBlock(unsigned char *buf, int len);
366 void handleProxyMessageBlock(MsgBlockType type,
367 const Async::IpAddress &remote_ip, uint32_t len,
368 unsigned char *data);
369 void handleTcpDataMsg(uint8_t *buf, int len);
370 void handleTcpCloseMsg(const uint8_t *buf, int len);
371 void handleTcpStatusMsg(const uint8_t *buf, int len);
372 void handleUdpDataMsg(const Async::IpAddress &remote_ip, uint8_t *buf,
373 int len);
374 void handleUdpCtrlMsg(const Async::IpAddress &remote_ip, uint8_t *buf,
375 int len);
376 void handleSystemMsg(const unsigned char *buf, int len);
377 void cmdTimeout(void);
378
379}; /* class Proxy */
380
381
382} /* namespace */
383
384#endif /* ECHOLINK_PROXY_INCLUDED */
385
386
387
388/*
389 * This file has not been truncated
390 */
uint8_t data[1024]
Definition EchoLinkQso.h:7