EchoLib  0.14.0
EchoLinkDispatcher.h
Go to the documentation of this file.
1 
37 #ifndef ECHOLINK_DISPATCHER_INCLUDED
38 #define ECHOLINK_DISPATCHER_INCLUDED
39 
40 
41 /****************************************************************************
42  *
43  * System Includes
44  *
45  ****************************************************************************/
46 
47 #include <sigc++/sigc++.h>
48 
49 #include <map>
50 
51 
52 /****************************************************************************
53  *
54  * Project Includes
55  *
56  ****************************************************************************/
57 
58 #include <AsyncIpAddress.h>
59 #include <AsyncUdpSocket.h>
60 
61 
62 /****************************************************************************
63  *
64  * Local Includes
65  *
66  ****************************************************************************/
67 
68 
69 
70 /****************************************************************************
71  *
72  * Forward declarations
73  *
74  ****************************************************************************/
75 
76 
77 
78 /****************************************************************************
79  *
80  * Namespace
81  *
82  ****************************************************************************/
83 
84 namespace EchoLink
85 {
86 
87 /****************************************************************************
88  *
89  * Forward declarations of classes inside of the declared namespace
90  *
91  ****************************************************************************/
92 
93 class Qso;
94 
95 
96 /****************************************************************************
97  *
98  * Defines & typedefs
99  *
100  ****************************************************************************/
101 
102 
103 
104 /****************************************************************************
105  *
106  * Exported Global Variables
107  *
108  ****************************************************************************/
109 
110 
111 
112 /****************************************************************************
113  *
114  * Class definitions
115  *
116  ****************************************************************************/
117 
144 class Dispatcher : public SigC::Object
145 {
146  public:
157  static void setPortBase(int base);
158 
174  static Dispatcher *instance(void);
175 
179  ~Dispatcher(void);
180 
190  SigC::Signal4<void, const Async::IpAddress&, const std::string&,
191  const std::string&, const std::string&> incomingConnection;
192 
193  protected:
194 
195  private:
196  friend class Qso;
197 
198  typedef void (Qso::*CtrlInputHandler)(unsigned char *buf, int len);
199  typedef void (Qso::*AudioInputHandler)(unsigned char *buf, int len);
200  typedef struct
201  {
202  Qso * con;
203  CtrlInputHandler cih;
204  AudioInputHandler aih;
205  } ConData;
206  struct ipaddr_lt
207  {
208  bool operator()(const Async::IpAddress& a1, const Async::IpAddress& a2)
209  {
210  return a1 < a2;
211  }
212  };
213  typedef std::map<Async::IpAddress, ConData, ipaddr_lt> ConMap;
214 
215  static const int DEFAULT_PORT_BASE = 5198;
216 
217  static int port_base;
218  static Dispatcher * the_instance;
219 
220  ConMap con_map;
221  Async::UdpSocket * ctrl_sock;
222  Async::UdpSocket * audio_sock;
223 
224  bool registerConnection(Qso *con, CtrlInputHandler cih,
225  AudioInputHandler aih);
226  void unregisterConnection(Qso *con);
227 
228  Dispatcher(void);
229  void ctrlDataReceived(const Async::IpAddress& ip, void *buf, int len);
230  void audioDataReceived(const Async::IpAddress& ip, void *buf, int len);
231  void printData(const char *buf, int len);
232 
233  // These functions are accessed by the Qso class
234  bool sendCtrlMsg(const Async::IpAddress& to, const void *buf, int len);
235  bool sendAudioMsg(const Async::IpAddress& to, const void *buf, int len);
236 
237 }; /* class Dispatcher */
238 
239 
240 } /* namespace */
241 
242 #endif /* ECHOLINK_DISPATCHER_INCLUDED */
243 
244 
245 
246 /*
247  * This file has not been truncated
248  */
249