多数据源中间件标准版1.0

FsProxy.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*************************************************************************
  2. 【文件名】 FsProxy.h
  3. 【功能模块和目的】 FS代理控制类头文件
  4. 【开发者及日期】 郑石诺 2016/06/21
  5. 【版本】 V1.0.0
  6. 【版权信息】 Copyright (C)2016 河南华谊网络科技有限公司
  7. 【更改记录】
  8. *************************************************************************/
  9. #pragma once
  10. #include "EslGateway.h"
  11. #include "IEslEventHandler.h"
  12. #include "CallStringMaker.h"
  13. #include <mutex>
  14. class CChanExten;
  15. class CChanTrunk;
  16. class CVirtualChan;
  17. class CSession;
  18. /*************************************************************************
  19. 【类名】 CFsProxy
  20. 【功能】
  21. 【接口说明】 FS代理控制类
  22. 【开发者及日期】 郑石诺 2016/06/21
  23. 【版本】 V1.0.0
  24. 【版权信息】 Copyright (C)2016 河南华谊网络科技有限公司
  25. 【更改记录】
  26. *************************************************************************/
  27. class CFsProxy
  28. {
  29. SINGLETON_DECLARE(CFsProxy)
  30. public:
  31. ~CFsProxy(void);
  32. bool init(IEslEventHandler* pEventHandler);
  33. void release(void);
  34. // 事件处理
  35. void onChanRegist(DEV_RES_TYPE ChanType, UINT ChanNo, CHAN_LOGIC_STATE ChanState);
  36. void onExtenDestroy(UINT ExtenNo);
  37. void onExtenDirectOp(DEV_OP OpType, CVirtualChan* pHostChan, PCHAN_EVENT_NOTIFY pNotify);
  38. void onChanStateUpdate(LONG OpInstance, CVirtualChan* pChan);
  39. void onChanPoor(CSession* pSession, PCHAN_EVENT_NOTIFY pNotify);
  40. void onTrunkCallIn(CChanTrunk* pTrunk);
  41. // ESL事件
  42. void onEslDisconnect(void);
  43. void onEslExtenReg(UINT ExtenNo);
  44. void onEslExtenUnreg(UINT ExtenNo);
  45. void onEslEvtBgJobDone(PBG_JOB_NOTIFY pNotify);
  46. void onEslEvtChannel(PCHAN_EVENT_NOTIFY pNotify);
  47. void onEslEvtDtmf(PDTMF_NOTIFY pNotify);
  48. void onEslEvtHold(PHOLD_NOTIFY pNotify);
  49. void onEslGwExtenReg(LPCTSTR ExtenNo, LPCTSTR Ip);
  50. void onEslGwExtenUnreg(LPCTSTR ExtenNo);
  51. // 功能接口
  52. CChanExten* getExten(UINT ExtenNo);
  53. CChanTrunk* getTrunk(UINT TrunkNo);
  54. void delChan(CVirtualChan* pChan);
  55. CChanTrunk* getFreeTrunk(void);
  56. CVirtualChan* getAssoChanInSession(CVirtualChan* pChan);
  57. CVirtualChan* getBusyChan(LPCTSTR ChanId);
  58. void regBusyChan(CVirtualChan* pChan);
  59. void unregBusyChan(CVirtualChan* pChan);
  60. // 语音操作接口
  61. bool ExtenCall(LONG JobId, CVirtualChan* pChan, LPCTSTR CallerNum, LPCTSTR CalleeNum);
  62. bool PredictionCall(LONG JobId, CString CallerNum, CString CalleeNum);
  63. bool answer(LONG JobId, CVirtualChan* pChan);
  64. bool kill(LONG JobId, CVirtualChan* pChan);
  65. bool consult(LONG JobId, CVirtualChan* pChan, CString DestNum);
  66. bool insert(LONG JobId, CVirtualChan* pChan, LPCTSTR DestSessionId);
  67. bool intercept(LONG JobId, CVirtualChan* pChan, LPCTSTR DestChanId);
  68. bool listen(LONG JobId, CVirtualChan* pChan, LPCTSTR DestChanId);
  69. bool meeting(LONG JobId, CString CallerNum, CString DestNum, LPCTSTR MeetingId);
  70. std::string EslCommand(std::string strFsIp, int FsPort, std::string strName, std::string strPsWd, std::string strCommand);
  71. bool muteOn(LONG JobId, CVirtualChan* pChan);
  72. bool muteOff(LONG JobId, CVirtualChan* pChan);
  73. bool holdon(LONG JobId, CVirtualChan* pChan);
  74. bool takeBack(LONG JobId, CVirtualChan* pChan);
  75. bool record(LONG JobId, CVirtualChan* pChan, LPCTSTR RcdFile);
  76. bool transfer(LONG JobId, CVirtualChan* pChan, LPCTSTR DestNum);
  77. bool transfer2Context(LONG JobId, LPCTSTR DestChanId, LPCTSTR Exten, LPCTSTR Context, bool BothSide = false);
  78. // IVR任务
  79. bool cancel(CChanTrunk* pChan);
  80. bool hangup(CChanTrunk* pChan);
  81. bool leaveWord(CChanTrunk* pChan, LPCTSTR FileName, UINT LimitTime, TCHAR FinishKey);
  82. bool playAndDtmf(CChanTrunk* pChan, PlayVoiceContent* pPlayContent);
  83. bool bridge(CChanTrunk* pChan, CString CallerNum, CString CalleeNum);
  84. bool bridge(CChanTrunk* pChan, CString CalleeNum); // 2019-9-18 bwj 动态网关 外线转外线使用
  85. private:
  86. CFsProxy(void);
  87. UINT __transLogicState2CtiState(DEV_RES_TYPE ChanType, CHAN_LOGIC_STATE State);
  88. void __addExten(UINT ExtenNo);
  89. void __delExten(UINT ExtenNo);
  90. void __freeExten(void);
  91. void __initTrunkChan(void);
  92. void __freeTrunkChan(void);
  93. CSession* __getSession(LPCTSTR SessionId);
  94. CSession* __getSession(PCHAN_EVENT_NOTIFY pNotify, bool NewWhenNull = false);
  95. void __delSession(LPCTSTR SessionId);
  96. void __freeSession(void);
  97. bool __kill(LONG JobId, LPCTSTR ChanId);
  98. private:
  99. CEslGateway m_Gateway;
  100. CCallStringMaker m_CallStringMaker;
  101. CArray<CChanTrunk*, CChanTrunk*> m_ArrayTrunk; // 中继数组
  102. CMap<UINT, UINT, CChanExten*, CChanExten*> m_MapChanExt; // 分机表
  103. CMap<CString, LPCTSTR, CVirtualChan*, CVirtualChan*> m_MapBusyChan; // 忙通道表
  104. CMap<CString, LPCTSTR, CSession*, CSession*> m_MapSession; // 会话表
  105. CMap<CString, LPCTSTR, CString, LPCTSTR> m_MapAddrGwExt; //外部地址
  106. IEslEventHandler* m_pEventHandler;
  107. esl_handle_t m_EslHandle;
  108. std::mutex m_LockArrayTrunk; // 2020-03-02
  109. std::mutex m_LockMapChanExt; // 2020-03-02
  110. std::mutex m_LockMapBusyChan; // 2020-03-02
  111. std::mutex m_LockMapSesssoin; // 2020-03-02
  112. };