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

CtiCore.cpp 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #include "StdAfx.h"
  2. #include "CtiCore.h"
  3. #include "MsgCenter.h"
  4. #include "CtiDataDef.h"
  5. #include "NetworkCti.h"
  6. #include "Config.h"
  7. #include "IvrFlowHolder.h"
  8. #include "LineHolder.h"
  9. #include "TaskMgr.h"
  10. #include "../Public/DaemonClient/DaemonClient.h"
  11. #include "LicenseMgr.h"
  12. SINGLETON_IMPLEMENT(CCtiCore)
  13. CCtiCore::CCtiCore(void)
  14. {
  15. }
  16. CCtiCore::~CCtiCore(void)
  17. {
  18. }
  19. /*****************************************************************
  20. **【函数名称】 __init
  21. **【函数功能】 内部初始化
  22. **【参数】
  23. **【返回值】
  24. ****************************************************************/
  25. void CCtiCore::__init(void)
  26. {
  27. // 注册底层设备消息事件
  28. CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
  29. MsgCenter.regist(DEV_EVENT_LOG, this);
  30. MsgCenter.regist(DEV_EVENT_INIT_END, this);
  31. MsgCenter.regist(DEV_EVENT_DEV_CLOSED, this);
  32. }
  33. void CCtiCore::__uninit(void)
  34. {
  35. // 取消注册底层设备消息事件
  36. CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
  37. MsgCenter.unregist(DEV_EVENT_LOG, this);
  38. MsgCenter.unregist(DEV_EVENT_INIT_END, this);
  39. MsgCenter.unregist(DEV_EVENT_DEV_CLOSED, this);
  40. }
  41. /*****************************************************************
  42. **【函数名称】 __onDevInitEnd
  43. **【函数功能】 处理设备初始化结束事处理函数
  44. **【参数】
  45. **【返回值】
  46. ****************************************************************/
  47. void CCtiCore::__onDevInitEnd(void)
  48. {
  49. AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_INITEND, 0);
  50. }
  51. /*****************************************************************
  52. **【函数名称】 __onDevClosed
  53. **【函数功能】 处理设备连接断开事件
  54. **【参数】
  55. **【返回值】
  56. ****************************************************************/
  57. void CCtiCore::__onDevClosed(void)
  58. {
  59. ILogger::getInstance().log(LOG_CLASS_DEV, LOG_LEVEL_ERROR, STR_ERR_DEVLINK_DROP);
  60. AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_CLOSE, 0);
  61. }
  62. /*****************************************************************
  63. **【函数名称】 stage1Start
  64. **【函数功能】 第一阶段启动
  65. **【参数】
  66. **【返回值】
  67. ****************************************************************/
  68. bool CCtiCore::stage1Start(void)
  69. {
  70. // 连接配置数据库
  71. if (!IOtlConnection::getInstance()->Connect())
  72. {
  73. AfxMessageBox(STR_ERR_CORE_INIT_DB_CONN);
  74. return false;
  75. }
  76. // 加载配置
  77. if (!CConfig::GetInstance().loadConfig())
  78. {
  79. // 断开数据库连接
  80. IOtlConnection::getInstance()->Disconnect();
  81. AfxMessageBox(STR_ERR_CORE_INIT_CFG_LOAD);
  82. return false;
  83. }
  84. return true;
  85. }
  86. /*****************************************************************
  87. **【函数名称】 stage2Start
  88. **【函数功能】 第二阶段启动
  89. **【参数】
  90. **【返回值】
  91. ****************************************************************/
  92. bool CCtiCore::stage2Start(void)
  93. {
  94. __init();
  95. CLineHolder::GetInstance().init();
  96. CTaskMgr::GetInstance().init();
  97. // 初始化Ivrflow
  98. CIvrFlowHolder::GetInstance().createIvrFlow(CConfig::GetInstance().ivrFlowNum());
  99. // 建立网络通讯
  100. if (!CNetworkCti::GetInstance().init())
  101. {
  102. // 断开数据库连接
  103. IOtlConnection::getInstance()->Disconnect();
  104. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_NET_SETUP);
  105. return false;
  106. }
  107. // 打开底层设备
  108. if (!m_DevLink.open())
  109. {
  110. // 断开数据库连接
  111. IOtlConnection::getInstance()->Disconnect();
  112. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_DEV_OPEN);
  113. return false;
  114. }
  115. CDaemonClient::GetInstance().doWork();
  116. return true;
  117. }
  118. /*****************************************************************
  119. **【函数名称】 stop
  120. **【函数功能】 停止CTI
  121. **【参数】
  122. **【返回值】
  123. ****************************************************************/
  124. void CCtiCore::stop(void)
  125. {
  126. CNetworkCti::GetInstance().release();
  127. // 销毁IVRFlow
  128. CIvrFlowHolder::GetInstance().destroyIvrFlow();
  129. // 关闭设备
  130. m_DevLink.close();
  131. // 断开数据库连接
  132. IOtlConnection::getInstance()->Disconnect();
  133. ILogger::getInstance().close();
  134. }
  135. void CCtiCore::StopForContinue(void)
  136. {
  137. CNetworkCti::GetInstance().release();
  138. // 销毁IVRFlow
  139. CIvrFlowHolder::GetInstance().destroyIvrFlow();
  140. // 关闭设备
  141. m_DevLink.close();
  142. // 断开数据库连接
  143. IOtlConnection::getInstance()->Disconnect();
  144. CDaemonClient::GetInstance().Release();
  145. //ILogger::getInstance().close();
  146. }
  147. void CCtiCore::UnInit(void)
  148. {
  149. CTaskMgr::GetInstance().uninit();
  150. CLineHolder::GetInstance().uninit();
  151. __uninit();
  152. }
  153. /*****************************************************************
  154. **【函数名称】 onMessage
  155. **【函数功能】 消息中心分发的消息处理函数
  156. **【参数】 MsgType:消息事件类型
  157. lpContent:消息内容
  158. **【返回值】
  159. ****************************************************************/
  160. void CCtiCore::onMessage(UINT MsgType, const PARAM lpContent)
  161. {
  162. switch (MsgType)
  163. {
  164. case DEV_EVENT_LOG: // 设备日志
  165. {
  166. ASSERT(lpContent != NULL);
  167. if (lpContent == NULL) return;
  168. EventLog* pLogInfo = (EventLog*)lpContent;
  169. ILogger::getInstance().log(LOG_CLASS_DEV, (LOG_LEVEL)(pLogInfo->nLevel), _T("%s"), pLogInfo->szContent);
  170. }
  171. break;
  172. case DEV_EVENT_INIT_END: // 设备初始化结束
  173. {
  174. __onDevInitEnd();
  175. }
  176. break;
  177. case DEV_EVENT_DEV_CLOSED: // 设备已关闭
  178. {
  179. __onDevClosed();
  180. }
  181. break;
  182. } //end switch
  183. }
  184. /*****************************************************************
  185. **【函数名称】 KillProcess
  186. **【函数功能】 强制结束线程
  187. **【参数】 窗口名称
  188. **【返回值】
  189. ****************************************************************/
  190. int CCtiCore::KillProcess(LPCSTR pszClassName, LPCSTR pszWindowTitle)
  191. {
  192. HANDLE hProcessHandle;
  193. ULONG nProcessID;
  194. HWND TheWindow;
  195. TheWindow = ::FindWindow(NULL, pszWindowTitle);
  196. ::GetWindowThreadProcessId(TheWindow, &nProcessID);
  197. hProcessHandle = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
  198. return ::TerminateProcess(hProcessHandle, 4);
  199. }