#include "StdAfx.h" #include "ViewMgr.h" #include "resource.h" #include "DisplayWnd.h" #include "Config.h" #include "MsgCenter.h" SINGLETON_IMPLEMENT(CViewMgr) CViewMgr::CViewMgr(void) { } CViewMgr::~CViewMgr(void) { } /***************************************************************** **【函数名称】 __getView **【函数功能】 查找指定资源的视图 **【参数】 **【返回值】 ****************************************************************/ CViewResBase* CViewMgr::__getView( UINT ResType ) { switch(ResType) { case DEV_RES_TYPE_TRUNK: return &m_ViewDti; case DEV_RES_TYPE_VOIP: return &m_ViewVoip; case DEV_RES_TYPE_IPM: return &m_ViewIpm; case DEV_RES_TYPE_DSP: return &m_ViewDsp; } return NULL; } /***************************************************************** **【函数名称】 setup **【函数功能】 视图管理器创建 **【参数】 **【返回值】 ****************************************************************/ bool CViewMgr::setup( CDisplayWnd* pWnd ) { ASSERT(pWnd != NULL); m_pWnd = pWnd; if(!m_ViewLog.create(pWnd)) { AfxMessageBox(_T("日志视图创建失败!")); return false; } if(!m_ViewDti.create(m_pWnd, IDS_STR_VIEW_DTI)) { AfxMessageBox(_T("DTI视图创建失败!")); return false; } if(!m_ViewVoip.create(m_pWnd, IDS_STR_VIEW_VOIP)) { AfxMessageBox(_T("VOIP视图创建失败!")); return false; } if(!m_ViewIpm.create(m_pWnd, IDS_STR_VIEW_IPM)) { AfxMessageBox(_T("IPM视图创建失败!")); return false; } if(!m_ViewDsp.create(m_pWnd, IDS_STR_VIEW_DSP)) { AfxMessageBox(_T("DSP视图创建失败!")); return false; } ILogger::getInstance().init(&m_ViewLog, LOG_DEV_SC, CConfig::logFilePath()); ILogger::getInstance().start(); CMsgCenter& MsgCenter = CMsgCenter::GetInstance(); MsgCenter.regist(SYS_MSG_RES_NEW, this); MsgCenter.regist(SYS_MSG_RES_DEL, this); MsgCenter.regist(SYS_MSG_RES_STATE, this); return true; } /***************************************************************** **【函数名称】 showResView **【函数功能】 显示指定资源视图 **【参数】 **【返回值】 ****************************************************************/ void CViewMgr::showResView( UINT ResType ) { CViewResBase* pView = __getView(ResType); ASSERT(pView != NULL); if(pView != NULL) pView->show(); } /***************************************************************** **【函数名称】 onMessage **【函数功能】 消息事件处理函数 **【参数】 MsgType: 消息事件类型 lpContent: 消息内容 **【返回值】 ****************************************************************/ void CViewMgr::onMessage( UINT MsgType, PARAM lpContent ) { ASSERT(lpContent != NULL); DEV_RES_ID* pResId = new DEV_RES_ID(*(DEV_RES_ID*)lpContent); ASSERT(pResId != NULL); switch(MsgType) { case SYS_MSG_RES_NEW: AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_RES_NEW, (LPARAM)pResId); break; case SYS_MSG_RES_DEL: AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_RES_DEL, (LPARAM)pResId); break; case SYS_MSG_RES_STATE: AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_RES_STATE, (LPARAM)pResId); break; } } /***************************************************************** **【函数名称】 onResNew **【函数功能】 添加资源处理函数 **【参数】 **【返回值】 ****************************************************************/ void CViewMgr::onResNew( DEV_RES_ID*& pResId ) { CViewResBase* pView = __getView(pResId->ResType); ASSERT(pView != NULL); if(pView != NULL) pView->onResNew(*pResId); delete pResId; pResId = NULL; } /***************************************************************** **【函数名称】 onResDel **【函数功能】 删除资源处理函数 **【参数】 **【返回值】 ****************************************************************/ void CViewMgr::onResDel( DEV_RES_ID*& pResId ) { CViewResBase* pView = __getView(pResId->ResType); ASSERT(pView != NULL); if(pView != NULL) pView->onResDel(*pResId); delete pResId; pResId = NULL; } /***************************************************************** **【函数名称】 onResState **【函数功能】 资源状态更新处理函数 **【参数】 **【返回值】 ****************************************************************/ void CViewMgr::onResState( DEV_RES_ID*& pResId ) { CViewResBase* pView = __getView(pResId->ResType); ASSERT(pView != NULL); if(pView != NULL) pView->onResState(*pResId); delete pResId; pResId = NULL; }