EchoLinkDispatcher.h
Go to the documentation of this file.00001
00037 #ifndef ECHOLINK_DISPATCHER_INCLUDED
00038 #define ECHOLINK_DISPATCHER_INCLUDED
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <sigc++/sigc++.h>
00048
00049 #include <map>
00050
00051
00052
00053
00054
00055
00056
00057
00058 #include <AsyncIpAddress.h>
00059 #include <AsyncUdpSocket.h>
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 namespace EchoLink
00085 {
00086
00087
00088
00089
00090
00091
00092
00093 class Qso;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00144 class Dispatcher : public SigC::Object
00145 {
00146 public:
00157 static void setPortBase(int base);
00158
00174 static Dispatcher *instance(void);
00175
00179 ~Dispatcher(void);
00180
00189 SigC::Signal3<void, const Async::IpAddress&, const std::string&,
00190 const std::string&> incomingConnection;
00191
00192 protected:
00193
00194 private:
00195 friend class Qso;
00196
00197 typedef void (Qso::*CtrlInputHandler)(unsigned char *buf, int len);
00198 typedef void (Qso::*AudioInputHandler)(unsigned char *buf, int len);
00199 typedef struct
00200 {
00201 Qso * con;
00202 CtrlInputHandler cih;
00203 AudioInputHandler aih;
00204 } ConData;
00205 struct ipaddr_lt
00206 {
00207 bool operator()(const Async::IpAddress& a1, const Async::IpAddress& a2)
00208 {
00209 return a1 < a2;
00210 }
00211 };
00212 typedef std::map<Async::IpAddress, ConData, ipaddr_lt> ConMap;
00213
00214 static const int DEFAULT_PORT_BASE = 5198;
00215
00216 static int port_base;
00217 static Dispatcher * the_instance;
00218
00219 ConMap con_map;
00220 Async::UdpSocket * ctrl_sock;
00221 Async::UdpSocket * audio_sock;
00222
00223 bool registerConnection(Qso *con, CtrlInputHandler cih,
00224 AudioInputHandler aih);
00225 void unregisterConnection(Qso *con);
00226
00227 Dispatcher(void);
00228 void ctrlDataReceived(const Async::IpAddress& ip, void *buf, int len);
00229 void audioDataReceived(const Async::IpAddress& ip, void *buf, int len);
00230 void printData(const char *buf, int len);
00231
00232
00233 bool sendCtrlMsg(const Async::IpAddress& to, const void *buf, int len);
00234 bool sendAudioMsg(const Async::IpAddress& to, const void *buf, int len);
00235
00236 };
00237
00238
00239 }
00240
00241 #endif
00242
00243
00244
00245
00246
00247
00248