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

ViewMgr.cpp 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "StdAfx.h"
  2. #include "ViewMgr.h"
  3. #include "resource.h"
  4. #include "DisplayWnd.h"
  5. #include "Config.h"
  6. #include "MsgCenter.h"
  7. #include "ViewExten.h"
  8. #include "ViewTrunk.h"
  9. #include "ViewVoip.h"
  10. #include "ViewIvr.h"
  11. #include "ViewFax.h"
  12. SINGLETON_IMPLEMENT(CViewMgr)
  13. CViewMgr::CViewMgr(void)
  14. {
  15. }
  16. CViewMgr::~CViewMgr(void)
  17. {
  18. __free();
  19. }
  20. /*****************************************************************
  21. **【函数名称】 __free
  22. **【函数功能】 释放资源
  23. **【参数】
  24. **【返回值】
  25. ****************************************************************/
  26. void CViewMgr::__free(void)
  27. {
  28. UINT Key = 0;
  29. CViewResBase *pView = NULL;
  30. POSITION pos = m_ViewMap.GetStartPosition();
  31. while (pos != NULL)
  32. {
  33. m_ViewMap.GetNextAssoc(pos, Key, pView);
  34. if (pView != NULL)
  35. delete pView;
  36. } // end while
  37. m_ViewMap.RemoveAll();
  38. }
  39. /*****************************************************************
  40. **【函数名称】 __showResView
  41. **【函数功能】 显示资源视图
  42. **【参数】
  43. **【返回值】
  44. ****************************************************************/
  45. void CViewMgr::__showResView(CViewResBase* pView)
  46. {
  47. if (m_ViewMap.IsEmpty())
  48. return;
  49. ViewMap::CPair* pPair = m_ViewMap.PGetFirstAssoc();
  50. ASSERT(pPair != NULL);
  51. pView->showTogether(pPair->value);
  52. }
  53. /*****************************************************************
  54. **【函数名称】 __procResType
  55. **【函数功能】 设备资源类型初始化函数
  56. **【参数】 Type 设备资源类型
  57. **【返回值】
  58. ****************************************************************/
  59. void CViewMgr::procResType(UINT Type)
  60. {
  61. CViewResBase* pView = NULL;
  62. UINT NameId;
  63. UINT ListId;
  64. if (m_ViewMap.Lookup(Type, pView)) // ych
  65. {
  66. return;
  67. }
  68. switch (Type)
  69. {
  70. case DEV_RES_TYPE_EXT: // 内线
  71. {
  72. pView = new CViewExten();
  73. m_ViewRes.newRes(DEV_RES_TYPE_EXT);
  74. NameId = IDS_STR_VIEW_EXT;
  75. ListId = IDC_LIST_EXT;
  76. m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_EXT, IDS_STR_VIEW_EXT);
  77. }
  78. break;
  79. case DEV_RES_TYPE_TRUNK: // 外线
  80. {
  81. pView = new CViewTrunk();
  82. m_ViewRes.newRes(DEV_RES_TYPE_TRUNK);
  83. NameId = IDS_STR_VIEW_TRUNK;
  84. ListId = IDC_LIST_TRUNK;
  85. m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_TRUNK, IDS_STR_VIEW_TRUNK);
  86. }
  87. break;
  88. case DEV_RES_TYPE_VOIP: // VoIP
  89. {
  90. pView = new CViewVoip();
  91. m_ViewRes.newRes(DEV_RES_TYPE_VOIP);
  92. NameId = IDS_STR_VIEW_VOIP;
  93. ListId = IDC_LIST_VOIP;
  94. m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_VOIP, IDS_STR_VIEW_VOIP);
  95. }
  96. break;
  97. case DEV_RES_TYPE_IVR: // IVR线路
  98. {
  99. pView = new CViewIvr();
  100. m_ViewRes.newRes(DEV_RES_TYPE_IVR);
  101. NameId = IDS_STR_VIEW_IVR;
  102. ListId = IDC_LIST_IVR;
  103. m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_IVR, IDS_STR_VIEW_IVR);
  104. }
  105. break;
  106. case DEV_RES_TYPE_FAX: // 传真
  107. {
  108. pView = new CViewFax();
  109. m_ViewRes.newRes(DEV_RES_TYPE_FAX);
  110. NameId = IDS_STR_VIEW_FAX;
  111. ListId = IDC_LIST_FAX;
  112. m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_FAX, IDS_STR_VIEW_FAX);
  113. }
  114. break;
  115. //case DEV_RES_TYPE_CONFERENCE: // 会议
  116. // {
  117. // pView = new CViewMeeting();
  118. // m_ViewRes.newRes(DEV_RES_TYPE_CONFERENCE);
  119. // NameId = IDS_STR_VIEW_MEETING;
  120. // ListId = IDC_LIST_MEETING;
  121. // m_pWnd->InsertMenuItem(ID_MENU_LOG, ID_MENU_VIEW_MEETING, IDS_STR_VIEW_MEETING);
  122. // }
  123. // break;
  124. default:
  125. break;
  126. } // end switch
  127. // 生成并存储设备资源类型节点
  128. if (pView != NULL)
  129. {
  130. pView->create(m_pWnd, NameId, ListId);
  131. __showResView(pView);
  132. m_ViewMap.SetAt(Type, pView);
  133. }
  134. }
  135. /*****************************************************************
  136. **【函数名称】 __procResDetail
  137. **【函数功能】 资源明细处理函数
  138. **【参数】 pResDetail 资源明细
  139. **【返回值】
  140. ****************************************************************/
  141. void CViewMgr::__procResDetail(EventResDetail *pResDetail)
  142. {
  143. ASSERT(pResDetail != NULL);
  144. CViewResBase* pView = NULL;
  145. if (m_ViewMap.Lookup(pResDetail->nResType, pView))
  146. {
  147. ASSERT(pView != NULL);
  148. pView->onResDetail(pResDetail);
  149. }
  150. }
  151. /*****************************************************************
  152. **【函数名称】 __procResState
  153. **【函数功能】 资源状态变化处理函数
  154. **【参数】 pResStatus 资源状态
  155. **【返回值】
  156. ****************************************************************/
  157. void CViewMgr::__procResState(EventResStatus *pResStatus)
  158. {
  159. ASSERT(pResStatus != NULL);
  160. CViewResBase* pView = NULL;
  161. if (m_ViewMap.Lookup(pResStatus->nResType, pView))
  162. {
  163. ASSERT(pView != NULL);
  164. pView->onResState(pResStatus);
  165. }
  166. }
  167. /*****************************************************************
  168. **【函数名称】 setup
  169. **【函数功能】 视图管理器创建
  170. **【参数】
  171. **【返回值】
  172. ****************************************************************/
  173. bool CViewMgr::setup(CDisplayWnd* pWnd)
  174. {
  175. ASSERT(pWnd != NULL);
  176. m_pWnd = pWnd;
  177. if (!m_ViewLog.create(pWnd))
  178. {
  179. AfxMessageBox(_T("日志视图创建失败!"));
  180. return false;
  181. }
  182. ILogger::getInstance().init(&m_ViewLog, LOG_DEV_CTI, CConfig::GetInstance().logFilePath());
  183. ILogger::getInstance().start();
  184. if (!m_ViewRes.create(pWnd))
  185. {
  186. AfxMessageBox(_T("设备资源视图创建失败!"));
  187. return false;
  188. }
  189. CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
  190. MsgCenter.regist(DEV_EVENT_RES_TYPE, this);
  191. MsgCenter.regist(DEV_EVENT_RES_DETAIL, this);
  192. MsgCenter.regist(DEV_EVENT_RES_STATUS, this);
  193. return true;
  194. }
  195. /*****************************************************************
  196. **【函数名称】 showResView
  197. **【函数功能】 显示指定资源视图
  198. **【参数】
  199. **【返回值】
  200. ****************************************************************/
  201. bool CViewMgr::showResView(UINT ResType)
  202. {
  203. CViewResBase* pView = NULL;
  204. if (m_ViewMap.Lookup(ResType, pView))
  205. {
  206. ASSERT(pView != NULL);
  207. pView->show();
  208. return true;
  209. }
  210. else
  211. return false;
  212. }
  213. /*****************************************************************
  214. **【函数名称】 onMessage
  215. **【函数功能】 消息事件处理函数
  216. **【参数】 MsgType: 消息事件类型
  217. lpContent: 消息内容
  218. **【返回值】
  219. ****************************************************************/
  220. void CViewMgr::onMessage(UINT MsgType, const PARAM lpContent)
  221. {
  222. if (lpContent == NULL) return;
  223. switch (MsgType)
  224. {
  225. case DEV_EVENT_RES_TYPE: // 设备资源类型
  226. {
  227. EventResType* pResType = (EventResType*)lpContent;
  228. #ifdef _USE_EHANGCOM
  229. AfxGetMainWnd()->PostMessage(WM_CORE_EVENT, CORE_EVENT_DEV_RES_TYPE, pResType->nResType);
  230. #else
  231. AfxGetMainWnd()->SendMessage(WM_CORE_EVENT, CORE_EVENT_DEV_RES_TYPE, pResType->nResType);
  232. #endif
  233. }
  234. break;
  235. case DEV_EVENT_RES_DETAIL: // 设备资源明细
  236. {
  237. EventResDetail* pResDetail = (EventResDetail*)lpContent;
  238. __procResDetail(pResDetail);
  239. }
  240. break;
  241. case DEV_EVENT_RES_STATUS: // 设备资源状态变化
  242. {
  243. EventResStatus* pResStatus = (EventResStatus*)lpContent;
  244. __procResState(pResStatus);
  245. }
  246. break;
  247. default:
  248. break;
  249. }
  250. }