| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- #include "StdAfx.h"
- #include "CtiCore.h"
- #include "MsgCenter.h"
- #include "CtiDataDef.h"
- #include "NetworkCti.h"
- #include "Config.h"
- #include "IvrFlowHolder.h"
- #include "LineHolder.h"
- #include "TaskMgr.h"
- #include "../Public/DaemonClient/DaemonClient.h"
- #include "LicenseMgr.h"
- SINGLETON_IMPLEMENT(CCtiCore)
- CCtiCore::CCtiCore(void)
- {
- }
- CCtiCore::~CCtiCore(void)
- {
- }
- /*****************************************************************
- **【函数名称】 __init
- **【函数功能】 内部初始化
- **【参数】
- **【返回值】
- ****************************************************************/
- void CCtiCore::__init(void)
- {
- // 注册底层设备消息事件
- CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
- MsgCenter.regist(DEV_EVENT_LOG, this);
- MsgCenter.regist(DEV_EVENT_INIT_END, this);
- MsgCenter.regist(DEV_EVENT_DEV_CLOSED, this);
- }
- void CCtiCore::__uninit(void)
- {
- // 取消注册底层设备消息事件
- CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
- MsgCenter.unregist(DEV_EVENT_LOG, this);
- MsgCenter.unregist(DEV_EVENT_INIT_END, this);
- MsgCenter.unregist(DEV_EVENT_DEV_CLOSED, this);
- }
- /*****************************************************************
- **【函数名称】 __onDevInitEnd
- **【函数功能】 处理设备初始化结束事处理函数
- **【参数】
- **【返回值】
- ****************************************************************/
- void CCtiCore::__onDevInitEnd(void)
- {
- AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_INITEND, 0);
- }
- /*****************************************************************
- **【函数名称】 __onDevClosed
- **【函数功能】 处理设备连接断开事件
- **【参数】
- **【返回值】
- ****************************************************************/
- void CCtiCore::__onDevClosed(void)
- {
- ILogger::getInstance().log(LOG_CLASS_DEV, LOG_LEVEL_ERROR, STR_ERR_DEVLINK_DROP);
- AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_CLOSE, 0);
- }
- /*****************************************************************
- **【函数名称】 stage1Start
- **【函数功能】 第一阶段启动
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CCtiCore::stage1Start(void)
- {
- // 连接配置数据库
- if (!IOtlConnection::getInstance()->Connect())
- {
- AfxMessageBox(STR_ERR_CORE_INIT_DB_CONN);
- return false;
- }
- // 加载配置
- if (!CConfig::GetInstance().loadConfig())
- {
- // 断开数据库连接
- IOtlConnection::getInstance()->Disconnect();
- AfxMessageBox(STR_ERR_CORE_INIT_CFG_LOAD);
- return false;
- }
- return true;
- }
- /*****************************************************************
- **【函数名称】 stage2Start
- **【函数功能】 第二阶段启动
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CCtiCore::stage2Start(void)
- {
- __init();
- CLineHolder::GetInstance().init();
- CTaskMgr::GetInstance().init();
- // 初始化Ivrflow
- CIvrFlowHolder::GetInstance().createIvrFlow(CConfig::GetInstance().ivrFlowNum());
- // 建立网络通讯
- if (!CNetworkCti::GetInstance().init())
- {
- // 断开数据库连接
- IOtlConnection::getInstance()->Disconnect();
- ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_NET_SETUP);
- return false;
- }
- // 打开底层设备
- if (!m_DevLink.open())
- {
- // 断开数据库连接
- IOtlConnection::getInstance()->Disconnect();
- ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_DEV_OPEN);
- return false;
- }
- CDaemonClient::GetInstance().doWork();
- return true;
- }
- /*****************************************************************
- **【函数名称】 stop
- **【函数功能】 停止CTI
- **【参数】
- **【返回值】
- ****************************************************************/
- void CCtiCore::stop(void)
- {
- CNetworkCti::GetInstance().release();
- // 销毁IVRFlow
- CIvrFlowHolder::GetInstance().destroyIvrFlow();
- // 关闭设备
- m_DevLink.close();
- // 断开数据库连接
- IOtlConnection::getInstance()->Disconnect();
- ILogger::getInstance().close();
- }
- void CCtiCore::StopForContinue(void)
- {
- CNetworkCti::GetInstance().release();
- // 销毁IVRFlow
- CIvrFlowHolder::GetInstance().destroyIvrFlow();
- // 关闭设备
- m_DevLink.close();
- // 断开数据库连接
- IOtlConnection::getInstance()->Disconnect();
- CDaemonClient::GetInstance().Release();
- //ILogger::getInstance().close();
- }
- void CCtiCore::UnInit(void)
- {
- CTaskMgr::GetInstance().uninit();
- CLineHolder::GetInstance().uninit();
- __uninit();
- }
- /*****************************************************************
- **【函数名称】 onMessage
- **【函数功能】 消息中心分发的消息处理函数
- **【参数】 MsgType:消息事件类型
- lpContent:消息内容
- **【返回值】
- ****************************************************************/
- void CCtiCore::onMessage(UINT MsgType, const PARAM lpContent)
- {
- switch (MsgType)
- {
- case DEV_EVENT_LOG: // 设备日志
- {
- ASSERT(lpContent != NULL);
- if (lpContent == NULL) return;
- EventLog* pLogInfo = (EventLog*)lpContent;
- ILogger::getInstance().log(LOG_CLASS_DEV, (LOG_LEVEL)(pLogInfo->nLevel), _T("%s"), pLogInfo->szContent);
- }
- break;
- case DEV_EVENT_INIT_END: // 设备初始化结束
- {
- __onDevInitEnd();
- }
- break;
- case DEV_EVENT_DEV_CLOSED: // 设备已关闭
- {
- __onDevClosed();
- }
- break;
- } //end switch
- }
- /*****************************************************************
- **【函数名称】 KillProcess
- **【函数功能】 强制结束线程
- **【参数】 窗口名称
- **【返回值】
- ****************************************************************/
- int CCtiCore::KillProcess(LPCSTR pszClassName, LPCSTR pszWindowTitle)
- {
- HANDLE hProcessHandle;
- ULONG nProcessID;
- HWND TheWindow;
- TheWindow = ::FindWindow(NULL, pszWindowTitle);
- ::GetWindowThreadProcessId(TheWindow, &nProcessID);
- hProcessHandle = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
- return ::TerminateProcess(hProcessHandle, 4);
- }
|