hd

LineHolder.cpp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #include "StdAfx.h"
  2. #include "LineHolder.h"
  3. #include "LogicLineExt.h"
  4. #include "LogicLineTrunk.h"
  5. #include "LogicLineVoip.h"
  6. #include "MsgCenter.h"
  7. SINGLETON_IMPLEMENT(CLineHolder)
  8. CLineHolder::CLineHolder(void)
  9. {
  10. m_LineMap.InitHashTable(MAX_LENGTH_HASH);
  11. }
  12. CLineHolder::~CLineHolder(void)
  13. {
  14. }
  15. /*****************************************************************
  16. **【函数名称】 __deleteExten
  17. **【函数功能】 删除指定分机
  18. **【参数】
  19. **【返回值】
  20. ****************************************************************/
  21. void CLineHolder::__deleteExten( UINT ExtId )
  22. {
  23. CLogicLine* pLine = NULL;
  24. // 不存在
  25. if(!m_LineMap.Lookup(ExtId, pLine))
  26. return;
  27. // 删除IP分机类
  28. m_LineMap.RemoveKey(ExtId);
  29. delete pLine;
  30. pLine = NULL;
  31. }
  32. /*****************************************************************
  33. **【函数名称】 __procResDetail
  34. **【函数功能】 处理资源类型明细,创建相关线路实体类
  35. **【参数】 EvtInfo: 资源信息
  36. **【返回值】
  37. ****************************************************************/
  38. void CLineHolder::__procResDetail( const EventResDetail &EvtInfo )
  39. {
  40. CLogicLine* pLine = NULL;
  41. switch(EvtInfo.nResType)
  42. {
  43. case DEV_RES_TYPE_EXT: // 内线分机
  44. {
  45. UINT Ext = EvtInfo.nResID;
  46. if (Ext & DEL_EXT_DETAIL) // 删除分机
  47. {
  48. // 去掉首位
  49. Ext = Ext << 4;
  50. Ext = Ext >> 4;
  51. __deleteExten(Ext);
  52. }
  53. else
  54. {
  55. // 已存在
  56. if(m_LineMap.Lookup(EvtInfo.nResID, pLine))
  57. return;
  58. // 建立内线分机类
  59. pLine = new CLogicLineExt(EvtInfo.nResID);
  60. m_LineMap.SetAt(EvtInfo.nResID, pLine);
  61. }
  62. }
  63. break;
  64. case DEV_RES_TYPE_TRUNK: // 外线
  65. {
  66. if(m_LineMap.Lookup(EvtInfo.nResID, pLine))
  67. return;
  68. // 建立外线类
  69. pLine = new CLogicLineTrunk(EvtInfo.nResID);
  70. m_LineMap.SetAt(EvtInfo.nResID, pLine);
  71. }
  72. break;
  73. case DEV_RES_TYPE_VOIP: // VOIP线路
  74. {
  75. if(m_LineMap.Lookup(EvtInfo.nResID, pLine))
  76. return;
  77. // 建立外线类
  78. pLine = new CLogicLineVoip(EvtInfo.nResID);
  79. m_LineMap.SetAt(EvtInfo.nResID, pLine);
  80. }
  81. break;
  82. default:
  83. break;
  84. } // end switch
  85. if(pLine != NULL)
  86. pLine->pushLineData2ACD();
  87. }
  88. /*****************************************************************
  89. **【函数名称】 __procResStatus
  90. **【函数功能】 处理资源状态变化
  91. **【参数】 EvtInfo:资源状态信息
  92. **【返回值】
  93. ****************************************************************/
  94. void CLineHolder::__procResStatus( const EventResStatus &EvtInfo )
  95. {
  96. CLogicLine* pLine = NULL;
  97. if(!m_LineMap.Lookup(EvtInfo.nResID, pLine))
  98. return;
  99. ASSERT(pLine != NULL);
  100. if(pLine == NULL)
  101. return;
  102. // 发给相关线路类处理
  103. pLine->onLineStatusUpdated(EvtInfo);
  104. if(EvtInfo.nState == INNER_STATE_REMOVE)
  105. __deleteExten(EvtInfo.nResID);
  106. }
  107. /*****************************************************************
  108. **【函数名称】 onAcdConnected
  109. **【函数功能】 ACD连接成功后的处理
  110. **【参数】
  111. **【返回值】
  112. ****************************************************************/
  113. void CLineHolder::onAcdConnected(void)
  114. {
  115. CLogicLine* pLogicLine = NULL;
  116. POSITION pos = m_LineMap.GetStartPosition();
  117. while(pos != NULL)
  118. {
  119. UINT nKey;
  120. m_LineMap.GetNextAssoc(pos, nKey, pLogicLine);
  121. // 发送线路初始信息到ACD
  122. pLogicLine->pushLineData2ACD();
  123. } // end while
  124. }
  125. /*****************************************************************
  126. **【函数名称】 getLogicLine
  127. **【函数功能】 获取逻辑线路实体类指针
  128. **【参数】 LineId: 线路ID
  129. **【返回值】
  130. ****************************************************************/
  131. CLogicLine* CLineHolder::getLogicLine( UINT LineId )
  132. {
  133. CLogicLine* pLogicLine = NULL;
  134. m_LineMap.Lookup(LineId, pLogicLine);
  135. return pLogicLine;
  136. }
  137. /*****************************************************************
  138. **【函数名称】 getLineAssoAgentId
  139. **【函数功能】 读取内线关联的座席工号
  140. **【参数】 nLineId: 线路ID
  141. **【返回值】 座席工号
  142. ****************************************************************/
  143. UINT CLineHolder::getLineAssoAgentId( UINT nLineId )
  144. {
  145. CLogicLine* pLine = getLogicLine(nLineId);
  146. return pLine == NULL ? 0 : pLine->getAgentNum();
  147. }
  148. /*****************************************************************
  149. **【函数名称】 onMessage
  150. **【函数功能】 消息事件处理函数
  151. **【参数】 MsgType: 消息事件类型
  152. lpContent: 消息内容
  153. **【返回值】
  154. ****************************************************************/
  155. void CLineHolder::onMessage( UINT MsgType, const PARAM lpContent )
  156. {
  157. if(lpContent == NULL) return;
  158. switch(MsgType)
  159. {
  160. case DEV_EVENT_RES_DETAIL: // 设备资源明显
  161. {
  162. __procResDetail(*(EventResDetail*)lpContent);
  163. }
  164. break;
  165. case DEV_EVENT_RES_STATUS: // 设备资源状态
  166. {
  167. __procResStatus(*(EventResStatus*)lpContent);
  168. }
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. /*****************************************************************
  175. **【函数名称】 init
  176. **【函数功能】 初始化
  177. **【参数】
  178. **【返回值】
  179. ****************************************************************/
  180. void CLineHolder::init(void)
  181. {
  182. // 注册底层设备消息
  183. CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
  184. MsgCenter.regist(DEV_EVENT_RES_DETAIL, this);
  185. MsgCenter.regist(DEV_EVENT_RES_STATUS, this);
  186. }
  187. void CLineHolder::uninit(void)
  188. {
  189. // 注册底层设备消息
  190. CMsgCenter& MsgCenter = CMsgCenter::GetInstance();
  191. MsgCenter.unregist(DEV_EVENT_RES_DETAIL, this);
  192. MsgCenter.unregist(DEV_EVENT_RES_STATUS, this);
  193. }