中间件标准版5.1git,去除基础模块

VsControl.cpp 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. #include "StdAfx.h"
  2. #include "VsControl.h"
  3. #include "Config.h"
  4. #include "DevControl.h"
  5. #include "TapiLine.h"
  6. #include "TapiControl.h"
  7. #include "LineFactory.h"
  8. SINGLETON_IMPLEMENT(CVsControl)
  9. CVsControl::CVsControl(void) : m_VsDevVoc(CONST_DEV_ID_INVALID), m_VsDevRec(CONST_DEV_ID_INVALID), m_VsDevFax(CONST_DEV_ID_INVALID)
  10. {
  11. }
  12. CVsControl::~CVsControl(void)
  13. {
  14. }
  15. /*****************************************************************
  16. **【函数名称】 __procCmdReg
  17. **【函数功能】 VS注册命令处理
  18. **【参数】
  19. **【返回值】
  20. ****************************************************************/
  21. void CVsControl::__procCmdReg( CPduEntity* pCmd )
  22. {
  23. switch(pCmd->GetLocalDevType())
  24. {
  25. case PDU_DEV_TYPE_VS_PLAY: // 放音VP台
  26. {
  27. m_VsDevVoc != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
  28. }
  29. break;
  30. case PDU_DEV_TYPE_VS_REC: // 录音VP台
  31. {
  32. m_VsDevRec != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
  33. }
  34. break;
  35. case PDU_DEV_TYPE_VS_PLAY_REC:
  36. {
  37. (m_VsDevVoc != CONST_DEV_ID_INVALID || m_VsDevRec != CONST_DEV_ID_INVALID) ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
  38. }
  39. break;
  40. case PDU_DEV_TYPE_VS_FAX:
  41. {
  42. m_VsDevFax != CONST_DEV_ID_INVALID ? pCmd->SetDataBool(0, false) : pCmd->SetDataBool(0, true);
  43. }
  44. break;
  45. default: // 未知设备
  46. pCmd->SetDataBool(0, false);
  47. break;
  48. } // end switch
  49. // 返回消息
  50. pCmd->SetToExecReturn();
  51. CInterfaceWindow::getCommInstance()->Send(pCmd, pCmd->GetLocalDevType(), pCmd->GetLocalDevId());
  52. }
  53. /*****************************************************************
  54. **【函数名称】 __procCmdPlayDtmf
  55. **【函数功能】 VS放音收号执行结果命令处理
  56. **【参数】
  57. **【返回值】
  58. ****************************************************************/
  59. void CVsControl::__procCmdPlayDtmf( CPduEntity* pCmd )
  60. {
  61. ASSERT(pCmd->GetIsExecReturn() == TRUE);
  62. CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(17), pCmd->GetDataBool(0), pCmd->GetDataString(16));
  63. }
  64. /*****************************************************************
  65. **【函数名称】 __ProcCmdFax
  66. **【函数功能】 VS传真结果命令处理
  67. **【参数】
  68. **【返回值】
  69. ****************************************************************/
  70. void CVsControl::__procCmdFax( CPduEntity* pCmd )
  71. {
  72. ASSERT(pCmd->GetIsExecReturn() == TRUE);
  73. CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(6), pCmd->GetDataBool(0));
  74. }
  75. /*****************************************************************
  76. **【函数名称】 __procCmdLeaveWord
  77. **【函数功能】 VS留言结果命令处理
  78. **【参数】
  79. **【返回值】
  80. ****************************************************************/
  81. void CVsControl::__procCmdLeaveWord( CPduEntity* pCmd )
  82. {
  83. ASSERT(pCmd->GetIsExecReturn() == TRUE);
  84. CDevControl::GetInstance().onEventOpResult(pCmd->GetDataLong(7), pCmd->GetDataBool(0));
  85. }
  86. /*****************************************************************
  87. **【函数名称】 init
  88. **【函数功能】 初始化
  89. **【参数】
  90. **【返回值】
  91. ****************************************************************/
  92. bool CVsControl::init( void )
  93. {
  94. // 初始化命令配置
  95. #ifdef _DEBUG
  96. CPduDataFormat::getInstance()->Load("../NetLib/PDUFormat.ini");//"../NetLib/PDUFormat.ini
  97. #else
  98. CPduDataFormat::getInstance()->Load("./PDUFormat.ini");
  99. #endif
  100. // 注册事件响应接口
  101. CInterfaceWindow::getLinkInstance()->RegistPduLinkProc(this, TRUE);
  102. CInterfaceWindow::getCommInstance()->RegistPduCommProc(this, TRUE);
  103. int ListenPort = CConfig::listenPort();
  104. // 创建Socket服务器端
  105. if (CInterfaceWindow::getLinkInstance()->CreatePduServer(ListenPort, PDU_DEV_TYPE_CTI, 0))
  106. {
  107. CDevControl::GetInstance().onEventLog(LOG_LEVEL_NORMAL, _T("{VsCtrl}: 创建网络服务端成功, ListenPort = %d"), ListenPort);
  108. return true;
  109. }
  110. else
  111. {
  112. CDevControl::GetInstance().onEventLog(LOG_LEVEL_WARNING, _T("{VsCtrl}: 创建网络服务端失败, ListenPort = %d"), ListenPort);
  113. return false;
  114. }
  115. }
  116. /*****************************************************************
  117. **【函数名称】 Init
  118. **【函数功能】 关闭VP台控制
  119. **【参数】
  120. **【返回值】
  121. ****************************************************************/
  122. void CVsControl::release( void )
  123. {
  124. CInterfaceWindow::getLinkInstance()->StopAll();
  125. }
  126. /*****************************************************************
  127. **【函数名称】 OnRecvCommand
  128. **【函数功能】 Pdu命令到达事件处理
  129. **【参数】
  130. **【返回值】
  131. ****************************************************************/
  132. void CVsControl::OnRecvCommand( CPduEntity* a_pPduEntity )
  133. {
  134. // 根据命令类型进行相关操作
  135. switch(a_pPduEntity->GetCmdType())
  136. {
  137. case PDU_CMD_REG: // 注册
  138. __procCmdReg(a_pPduEntity);
  139. break;
  140. case PDU_CMD_IVR_LEAVE_WORD: // 留言录音
  141. __procCmdLeaveWord(a_pPduEntity);
  142. break;
  143. case PDU_CMD_IVR_PLAY_DTMF: // 放音
  144. __procCmdPlayDtmf(a_pPduEntity);
  145. break;
  146. case PDU_CMD_IVR_FAX: // 传真
  147. __procCmdFax(a_pPduEntity);
  148. break;
  149. } // end switch
  150. }
  151. /*****************************************************************
  152. **【函数名称】 OnLinkStateChanged
  153. **【函数功能】 Pdu连接状态变化事件处理
  154. **【参数】
  155. **【返回值】
  156. ****************************************************************/
  157. void CVsControl::OnLinkStateChanged( const PduLinkContent& linkContent )
  158. {
  159. CString strMsg;
  160. LOG_LEVEL Level = LOG_LEVEL_NORMAL;
  161. switch(linkContent.nLinkState)
  162. {
  163. case PDU_LINK_STATE_ACCEPTED: // 已接受对端连接
  164. {
  165. strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d], Hint = 已接受远端网络连接..."),
  166. linkContent.szFarIp,
  167. linkContent.nFarPort);
  168. }
  169. break;
  170. case PDU_LINK_STATE_DISCONNECTED: // 连接已断开
  171. {
  172. strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d, Type = %d, Id = %d], Hint = 网络连接已断开..."),
  173. linkContent.szFarIp,
  174. linkContent.nFarPort,
  175. linkContent.nFarType,
  176. linkContent.nFarId);
  177. if(linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevVoc = CONST_DEV_ID_INVALID;
  178. if(linkContent.nFarType == PDU_DEV_TYPE_VS_REC || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevRec = CONST_DEV_ID_INVALID;
  179. if(linkContent.nFarType == PDU_DEV_TYPE_VS_FAX) m_VsDevFax = CONST_DEV_ID_INVALID;
  180. Level = LOG_LEVEL_WARNING;
  181. }
  182. break;
  183. case PDU_LINK_STATE_REG_OK: // 注册成功
  184. {
  185. strMsg.Format(_T("{VsCtrl}: Far End[Type = %d, Id = %d, Ip = %s, Port = %d], Hint = 网络连接注册成功..."),
  186. linkContent.nFarType,
  187. linkContent.nFarId,
  188. linkContent.szFarIp,
  189. linkContent.nFarPort);
  190. if(linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevVoc = linkContent.nFarType;
  191. if(linkContent.nFarType == PDU_DEV_TYPE_VS_REC || linkContent.nFarType == PDU_DEV_TYPE_VS_PLAY_REC) m_VsDevRec = linkContent.nFarType;
  192. if(linkContent.nFarType == PDU_DEV_TYPE_VS_FAX) m_VsDevFax = linkContent.nFarType;
  193. }
  194. break;
  195. case PDU_LINK_STATE_REG_FAILED: // 注册失败
  196. {
  197. strMsg.Format(_T("{VsCtrl}: Far End[Ip = %s, Port = %d], Hint = 网络连接注册失败, 通讯禁止..."),
  198. linkContent.szFarIp,
  199. linkContent.nFarPort);
  200. Level = LOG_LEVEL_WARNING;
  201. }
  202. break;
  203. default:
  204. strMsg.Format(_T("{VsCtrl}: Far End[Type = %d, Id = %d, Ip = %s, Port = %d], Hint = "),
  205. linkContent.nFarType,
  206. linkContent.nFarId,
  207. linkContent.szFarIp,
  208. linkContent.nFarPort);
  209. } // end switch
  210. CDevControl::GetInstance().onEventLog(Level, _T("%s"), strMsg);
  211. }
  212. /*****************************************************************
  213. **【函数名称】 sendCmd2Rec
  214. **【函数功能】 发送PDU命令到录音VS
  215. **【参数】
  216. **【返回值】
  217. ****************************************************************/
  218. bool CVsControl::sendCmd2Rec( CPduEntity* pCmd )
  219. {
  220. if(m_VsDevRec == CONST_DEV_ID_INVALID)
  221. return false;
  222. return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)m_VsDevRec, 0) == TRUE;
  223. }
  224. /*****************************************************************
  225. **【函数名称】 sendCmd2Voc
  226. **【函数功能】 发送PDU命令到放音VS
  227. **【参数】
  228. **【返回值】
  229. ****************************************************************/
  230. bool CVsControl::sendCmd2Voc( CPduEntity* pCmd )
  231. {
  232. if(m_VsDevVoc == CONST_DEV_ID_INVALID)
  233. return false;
  234. return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)m_VsDevVoc, 0) == TRUE;
  235. }
  236. /*****************************************************************
  237. **【函数名称】 sendCmd2Fax
  238. **【函数功能】 发送PDU命令到传真VS
  239. **【参数】
  240. **【返回值】
  241. ****************************************************************/
  242. bool CVsControl::sendCmd2Fax( CPduEntity* pCmd )
  243. {
  244. if(m_VsDevFax == CONST_DEV_ID_INVALID && m_VsDevVoc == CONST_DEV_ID_INVALID)
  245. return false;
  246. int TmpDevType = (m_VsDevFax == CONST_DEV_ID_INVALID ? m_VsDevVoc : m_VsDevFax);
  247. return CInterfaceWindow::getCommInstance()->Send(pCmd, (PDU_DEV_TYPE)TmpDevType, 0) == TRUE;
  248. }
  249. /*****************************************************************
  250. **【函数名称】 NotifyVpLineFree
  251. **【函数功能】 通知VP台线路释放
  252. **【参数】 LineId 释放的线路ID
  253. TypeType 释放的线路类型
  254. **【返回值】
  255. ****************************************************************/
  256. bool CVsControl::notifyLineFree( UINT LineId, DEV_RES_TYPE LineType )
  257. {
  258. // 初始化PDU命令
  259. CPduEntity cmd(PDU_CMD_CTI_VS_LINECONTROL);
  260. cmd.SetDataUInt(0, LineId);
  261. cmd.SetDataInt(1, 0);
  262. // 根据线路类型作分类处理
  263. switch(LineType)
  264. {
  265. case DEV_RES_TYPE_EXT: // 内线分机
  266. {
  267. if(CConfig::recordType() == RECORD_TYPE_EXTEN)
  268. return sendCmd2Rec(&cmd);
  269. }
  270. break;
  271. case DEV_RES_TYPE_TRUNK: // 外线
  272. {
  273. if(CConfig::recordType() == RECORD_TYPE_TRUNK)
  274. return sendCmd2Rec(&cmd);
  275. }
  276. break;
  277. case DEV_RES_TYPE_IVR: // IVR线路
  278. {
  279. return sendCmd2Voc(&cmd);
  280. }
  281. break;
  282. case DEV_RES_TYPE_FAX: // 传真线路
  283. {
  284. return sendCmd2Fax(&cmd);
  285. }
  286. break;
  287. default:
  288. ASSERT(FALSE);
  289. } // end switch
  290. return false;
  291. }