00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _BOGOTEL_MSGTRANSPORT_H
00011 #define _BOGOTEL_MSGTRANSPORT_H
00012
00013 #include <boost/thread/mutex.hpp>
00014 #include <boost/thread/condition.hpp>
00015 #include <boost/thread/thread.hpp>
00016
00017 #include <gclib.h>
00018
00019 #include <string>
00020 #include <map>
00021 #include <deque>
00022
00023 namespace bogotel {
00024
00025 class CBgtRt;
00026
00027 typedef std::map<long, std::string, std::less<long> > MAP_LONG2STR;
00028 typedef std::deque<std::string> DEQUE_STRING;
00029
00030 #define INVALID_CRN 0
00031
00032 enum MessageClass {
00033 MC_SIGNAL = 0,
00034 MC_VOICE,
00035 MC_INVALID
00036 } ;
00037
00038 enum MessageType {
00039 MT_INVALID = 0,
00040 MT_MAKE_CALL,
00041 MT_ACCEPT_CALL,
00042 MT_ANSWER_CALL,
00043 MT_DROPCALL,
00044 MT_RELEASE_CALL,
00045 MT_PLAY_WAV,
00046 MT_PLAY_WAV_FINISHED,
00047 MT_PLAY_DTMF,
00048 MT_PLAY_DTMF_FINISHED
00049 } ;
00050
00051 enum ParmType {
00052 PT_INVALID = 0,
00053 PT_ANI,
00054 PT_DNIS,
00055 PT_WAV_FILENAME,
00056 PT_DTMF
00057 } ;
00058
00059 class CMsg
00060 {
00061 public:
00062 MessageType m_type;
00063 MessageClass m_class;
00064 long m_id;
00065 CRN m_crn;
00066
00067 CMsg();
00068 virtual ~CMsg();
00069 void addParam(enum ParmType pt, std::string strParm);
00070 void addParam(enum ParmType pt, char *szParm);
00071 std::string getParam(enum ParmType pt);
00072 void clear();
00073 void init(MessageType type, MessageClass cls, long lId);
00074 char *toString(char *szDmp, size_t iDmpLen);
00075 int init(char *szMsg);
00076 void getMsgTypeString(char *szType, int iMaxLen);
00077
00078 protected:
00079 MAP_LONG2STR m_mapParam;
00080 };
00081
00082 class CMsgTransport
00083 {
00084 public:
00085 CMsgTransport(CBgtRt *pBgtRt);
00086 virtual ~CMsgTransport();
00087
00088 int init();
00089 int sendMsg(CMsg *pMsg);
00090
00091 static void do_thread_listen(void* param);
00092 static void do_thread_talk(void* param);
00093
00094 static int openListenerSocket(struct sockaddr_in *pAddr,int *pFd,u_short usPort);
00095 private:
00096 int openTalkerSocket();
00097 void runListener();
00098 void runTalker();
00099
00100 boost::thread* m_pthrdListener;
00101 boost::thread* m_pthrdTalker;
00102
00103 boost::mutex m_mtxStartup;
00104 boost::condition m_condStartup;
00105 bool m_bListenerStarted;
00106
00107 bool m_bStopTalker;
00108 bool m_bStopListener;
00109
00110 boost::mutex m_mtxDeque;
00111
00112 boost::mutex m_mtxAddedToQueue;
00113 boost::condition m_condEvent;
00114
00115 u_short m_usMyPort;
00116 u_short m_usOppPort;
00117 std::string m_strOppIp;
00118 CBgtRt *m_pBgtRt;
00119 DEQUE_STRING m_deqMsg;
00120
00121 struct sockaddr_in m_addrListener;
00122 int m_fdListener;
00123
00124 struct sockaddr_in m_addrTalker;
00125 int m_fdTalker;
00126
00127 };
00128 }
00129
00130 #endif // ! _BOGOTEL_MSG_TRANSPORT_H