| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- #include "StdAfx.h"
- #include "ControlShell.h"
- #include "MsgCenter.h"
- #include "ProxyShell.h"
- #include "SessionShell.h"
- #include "MC.h"
- #include "NetLinkMgr.h"
- #include "Config.h"
- #include "DaemonClient.h"
- #include "TrunkAidedAllocator.h"
- SINGLETON_IMPLEMENT(CControlShell)
- CControlShell::CControlShell(void)
- {
- }
- CControlShell::~CControlShell(void)
- {
- }
- /*****************************************************************
- **【函数名称】 __openTts
- **【函数功能】 打开TTS
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::__openTts( void )
- {
- TTS_TYPE TtsType = CConfig::ttsType();
- if(TtsType != TTS_NONE)
- {
- CHAR szErrCode[BUFFER_LENGTH];
- if(ITtsInterface::getInstance().init(TtsType, CConfig::ttsPath(), szErrCode))
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, _T("{Core}: TTS打开成功"));
- else
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_WARNING, _T("{Core}: TTS打开失败, Reason = %s"), szErrCode);
- }
- }
- /*****************************************************************
- **【函数名称】 __closeTts
- **【函数功能】 关闭TTS
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::__closeTts( void )
- {
- if(CConfig::ttsType() != TTS_NONE)
- ITtsInterface::getInstance().close();
- }
- /*****************************************************************
- **【函数名称】 __exitSystem
- **【函数功能】 退出系统
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::__exitSystem( void )
- {
- // close();
- #ifdef _SC_UI_MODE
- AfxGetMainWnd()->PostMessage(WM_CLOSE);
- #else
- CMsgCenter::GetInstance().stopMsgPump();
- #endif
- TerminateProcess(GetCurrentProcess(), 0);
- }
- /*****************************************************************
- **【函数名称】 __isAlarmExist
- **【函数功能】 判断告警是否已存在
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CControlShell::__isAlarmExist( int DevNo, int BoardNo )
- {
- AlarmMap::iterator itr;
- AlarmMap::iterator itrEnd;
- itr = m_DevAlarmMap.find(DevNo);
- if(itr == m_DevAlarmMap.end())
- return false;
- itrEnd = m_DevAlarmMap.upper_bound(DevNo);
- for(; itr != itrEnd; ++itr)
- {
- if(itr->second == BoardNo)
- return true;
- }
- return false;
- }
- /*****************************************************************
- **【函数名称】 stage1Start
- **【函数功能】 第一阶段启动
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CControlShell::stage1Start( void )
- {
- // 加载配置
- if(!CConfig::load())
- {
- // 断开数据库连接
- AfxMessageBox(STR_ERR_CORE_INIT_CFG_LOAD);
- return false;
- }
- CTrunkAidedAllocator::GetInstance().init();
- return true;
- }
- /*****************************************************************
- **【函数名称】 stage2Start
- **【函数功能】 第二阶段启动
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CControlShell::stage2Start( void )
- {
- CMsgCenter::GetInstance().startInThreadMode();
- __openTts();
- if(!CMC::GetInstance().open())
- {
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_MC_OPEN);
- return false;
- }
- if(!CNetLinkMgr::GetInstance().open())
- {
- CMC::GetInstance().close();
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_NET_SETUP);
- return false;
- }
- CSessionShell::GetInstance().start();
- CDaemonClient::GetInstance().doWork();
- return true;
- }
- /*****************************************************************
- **【函数名称】 startDirectly
- **【函数功能】 直接启动
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CControlShell::startDirectly( void )
- {
- // 加载配置
- if(!CConfig::load())
- {
- // 断开数据库连接
- AfxMessageBox(STR_ERR_CORE_INIT_CFG_LOAD);
- return false;
- }
- CTrunkAidedAllocator::GetInstance().init();
- ILogger::getInstance().init(NULL, LOG_DEV_SC, CConfig::logFilePath());
- ILogger::getInstance().start();
- __openTts();
- if(!CMC::GetInstance().open())
- {
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_MC_OPEN);
- return false;
- }
- if(!CNetLinkMgr::GetInstance().open())
- {
- CMC::GetInstance().close();
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_CORE_INIT_NET_SETUP);
- return false;
- }
- CSessionShell::GetInstance().start();
- CDaemonClient::GetInstance().doWork();
- return true;
- }
- /*****************************************************************
- **【函数名称】 close
- **【函数功能】 关闭
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::close( void )
- {
- CSessionShell::GetInstance().stop();
- CNetLinkMgr::GetInstance().close();
- CMC::GetInstance().close();
- __closeTts();
- ILogger::getInstance().close();
- }
- /*****************************************************************
- **【函数名称】 onDevValid
- **【函数功能】 设备状态可用的处理函数
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::onDevValid( int DevNo )
- {
- m_DevAlarmMap.erase(DevNo);
- CProxyShell::GetInstance().notifyDevResourceState(DEV_RES_TYPE_MB, DevNo, DEVICE_STATE_ENABLE); // 通知设备状态可用
- }
- /*****************************************************************
- **【函数名称】 onDevInvalid
- **【函数功能】 设备状态不可用的处理函数
- **【参数】
- **【返回值】
- ****************************************************************/
- void CControlShell::onDevInvalid( int DevNo, int BoardNo )
- {
- bool NeedExit = false;
- if(DevNo == DEVICE_MC_NO)
- {
- NeedExit = true;
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("{Core}: 收到MC不可用通知, 系统将退出"));
- CProxyShell::GetInstance().notifyDevResourceState(DEV_RES_TYPE_MB, DevNo, DEVICE_STATE_DISABLE); // 通知设备状态不可用
- }
- else
- {
- if(__isAlarmExist(DevNo, BoardNo))
- {
- NeedExit = true;
- LOGGER(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("{Core}: 收到设备[%d-%d]不可用通知且告警次数达到上限, 系统将退出"), DevNo, BoardNo);
- CProxyShell::GetInstance().notifyDevResourceState(DEV_RES_TYPE_MB, DevNo, DEVICE_STATE_DISABLE); // 通知设备状态不可用
- }
- else
- {
- m_DevAlarmMap.insert(pair<int, int>(DevNo, BoardNo)); // 插入告警
- }
- }
- if(NeedExit)
- __exitSystem();
- }
|