EchoLib  0.14.0
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  * System Includes
00044  *
00045  ****************************************************************************/
00046 
00047 #include <sigc++/sigc++.h>
00048 
00049 #include <map>
00050 
00051 
00052 /****************************************************************************
00053  *
00054  * Project Includes
00055  *
00056  ****************************************************************************/
00057 
00058 #include <AsyncIpAddress.h>
00059 #include <AsyncUdpSocket.h>
00060 
00061 
00062 /****************************************************************************
00063  *
00064  * Local Includes
00065  *
00066  ****************************************************************************/
00067 
00068 
00069 
00070 /****************************************************************************
00071  *
00072  * Forward declarations
00073  *
00074  ****************************************************************************/
00075 
00076 
00077 
00078 /****************************************************************************
00079  *
00080  * Namespace
00081  *
00082  ****************************************************************************/
00083 
00084 namespace EchoLink
00085 {
00086 
00087 /****************************************************************************
00088  *
00089  * Forward declarations of classes inside of the declared namespace
00090  *
00091  ****************************************************************************/
00092 
00093 class Qso;
00094 
00095 
00096 /****************************************************************************
00097  *
00098  * Defines & typedefs
00099  *
00100  ****************************************************************************/
00101 
00102 
00103 
00104 /****************************************************************************
00105  *
00106  * Exported Global Variables
00107  *
00108  ****************************************************************************/
00109 
00110 
00111 
00112 /****************************************************************************
00113  *
00114  * Class definitions
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     
00190     SigC::Signal4<void, const Async::IpAddress&, const std::string&,
00191                   const std::string&, const std::string&> incomingConnection;
00192     
00193   protected:
00194     
00195   private:
00196     friend class Qso;
00197   
00198     typedef void (Qso::*CtrlInputHandler)(unsigned char *buf, int len);
00199     typedef void (Qso::*AudioInputHandler)(unsigned char *buf, int len);
00200     typedef struct
00201     {
00202       Qso *             con;
00203       CtrlInputHandler  cih;
00204       AudioInputHandler aih;
00205     } ConData;
00206     struct ipaddr_lt
00207     {
00208       bool operator()(const Async::IpAddress& a1, const Async::IpAddress& a2)
00209       {
00210         return a1 < a2;
00211       }
00212     };
00213     typedef std::map<Async::IpAddress, ConData, ipaddr_lt> ConMap;
00214     
00215     static const int    DEFAULT_PORT_BASE = 5198;
00216     
00217     static int          port_base;
00218     static Dispatcher * the_instance;
00219     
00220     ConMap              con_map;
00221     Async::UdpSocket *  ctrl_sock;
00222     Async::UdpSocket *  audio_sock;
00223     
00224     bool registerConnection(Qso *con, CtrlInputHandler cih,
00225         AudioInputHandler aih);
00226     void unregisterConnection(Qso *con);
00227     
00228     Dispatcher(void);
00229     void ctrlDataReceived(const Async::IpAddress& ip, void *buf, int len);
00230     void audioDataReceived(const Async::IpAddress& ip, void *buf, int len);
00231     void printData(const char *buf, int len);
00232     
00233       // These functions are accessed by the Qso class
00234     bool sendCtrlMsg(const Async::IpAddress& to, const void *buf, int len);
00235     bool sendAudioMsg(const Async::IpAddress& to, const void *buf, int len);
00236     
00237 };  /* class Dispatcher */
00238 
00239 
00240 } /* namespace */
00241 
00242 #endif /* ECHOLINK_DISPATCHER_INCLUDED */
00243 
00244 
00245 
00246 /*
00247  * This file has not been truncated
00248  */
00249