中间件底层,websocket

FlowTemplate.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include "StdAfx.h"
  2. #include "FlowTemplate.h"
  3. #include "CellBase.h"
  4. #include "IFlowDataProvider.h"
  5. #include <regex>
  6. CFlowTemplate::CFlowTemplate(void) : m_Type(FLOW_UNKNOWN), m_Concurrency(1)
  7. {
  8. m_CellMap.InitHashTable(MAX_LENGTH_HASH);
  9. }
  10. CFlowTemplate::~CFlowTemplate(void)
  11. {
  12. __release();
  13. }
  14. /*****************************************************************
  15. **【函数名称】 __release
  16. **【函数功能】 释放所有cell
  17. **【参数】
  18. **【返回值】
  19. ****************************************************************/
  20. void CFlowTemplate::__release( void )
  21. {
  22. if(!m_CellMap.IsEmpty())
  23. {
  24. int Key = 0;
  25. CCellBase *pCell = NULL;
  26. POSITION pos = m_CellMap.GetStartPosition();
  27. while(pos != NULL)
  28. {
  29. m_CellMap.GetNextAssoc(pos, Key, pCell);
  30. if(pCell != NULL)
  31. delete pCell;
  32. pCell = NULL;
  33. }
  34. m_CellMap.RemoveAll();
  35. }
  36. }
  37. /*****************************************************************
  38. **【函数名称】 fillData
  39. **【函数功能】 解析流程文件为数据字段赋值
  40. **【参数】 Provider:数据提供者对象
  41. **【返回值】
  42. ****************************************************************/
  43. bool CFlowTemplate::fillData( IFlowDataProvider& Provider )
  44. {
  45. if(!Provider.getData(FLOW_ATTRIBUTE_NAME, m_Name))
  46. return false;
  47. CString Data;
  48. if(!Provider.getData(FLOW_ATTRIBUTE_TYPE, Data))
  49. return false;
  50. if(Data == FLOW_TYPE_STR_NORMAL)
  51. m_Type = FLOW_NORMAL;
  52. else if(Data == FLOW_TYPE_STR_AUTO)
  53. m_Type = FLOW_AUTO;
  54. else
  55. m_Type = FLOW_SUB;
  56. if(!Provider.getData(FLOW_ATTRIBUTE_MATCHED_NUM, m_MatchedNum))
  57. return false;
  58. if(!Provider.getData(FLOW_ATTRIBUTE_ASSO_LINE, m_MatchedLine))
  59. return false;
  60. if(m_Type == FLOW_AUTO)
  61. {
  62. if(!Provider.getData(FLOW_ATTRIBUTE_CONCURRENCY, Data))
  63. return false;
  64. else
  65. {
  66. sscanf_s(Data, _T("%d"), &m_Concurrency);
  67. if(m_Concurrency < 1)
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73. /*****************************************************************
  74. **【函数名称】 accept
  75. **【函数功能】 填充cell map
  76. **【参数】 CellPos:节点编号
  77. pCell:节点对象
  78. **【返回值】
  79. ****************************************************************/
  80. void CFlowTemplate::accept( int CellPos, CCellBase* pCell )
  81. {
  82. ASSERT(pCell != NULL);
  83. m_CellMap.SetAt(CellPos, pCell);
  84. }
  85. /*****************************************************************
  86. **【函数名称】 getCellPos
  87. **【函数功能】 根据节点名称查找节点
  88. **【参数】 CellName:节点名称
  89. **【返回值】
  90. ****************************************************************/
  91. int CFlowTemplate::getCellPos( const CString& CellName )
  92. {
  93. int Key = 0;
  94. CCellBase *pCell = NULL;
  95. POSITION pos = m_CellMap.GetStartPosition();
  96. while(pos != NULL)
  97. {
  98. m_CellMap.GetNextAssoc(pos, Key, pCell);
  99. if(pCell->name() == CellName)
  100. return pCell->position();
  101. }
  102. return 0;
  103. }
  104. /*****************************************************************
  105. **【函数名称】 findCell
  106. **【函数功能】 根据节点编号查找节点
  107. **【参数】 CellPos:节点编号
  108. **【返回值】 节点对象
  109. ****************************************************************/
  110. CCellBase* CFlowTemplate::findCell( int CellPos )
  111. {
  112. CCellBase *pCell = NULL;
  113. m_CellMap.Lookup(CellPos, pCell);
  114. if(pCell != NULL)
  115. return pCell->copy();
  116. return NULL;
  117. }
  118. /*****************************************************************
  119. **【函数名称】 matchLine
  120. **【函数功能】 匹配线路
  121. **【参数】 TrunkId:外线Id
  122. **【返回值】 0:不匹配;1:匹配;-1为默认流程
  123. ****************************************************************/
  124. int CFlowTemplate::matchLine( UINT TrunkId )
  125. {
  126. if(m_MatchedLine.IsEmpty())
  127. return 0;
  128. if(m_MatchedLine == "|-1|" )
  129. return -1;
  130. CString Temp;
  131. Temp.Format("|%lu|", TrunkId);
  132. if(m_MatchedLine.Find(Temp) != -1)
  133. return 1;
  134. return 0;
  135. }
  136. /*****************************************************************
  137. **【函数名称】 matchCaller
  138. **【函数功能】 根据主叫号码分析流程的适用性
  139. **【参数】 Caller:主叫号码
  140. **【返回值】 匹配true,否则false
  141. ****************************************************************/
  142. bool CFlowTemplate::matchCaller( LPCTSTR Caller )
  143. {
  144. std::string CallerString(Caller);
  145. std::regex Reg(m_MatchedNum);
  146. std::smatch Res;
  147. bool IsMatched = false;
  148. IsMatched = std::regex_match(CallerString, Res, Reg);
  149. return IsMatched;
  150. }
  151. /*****************************************************************
  152. **【函数名称】 isMatchedPreCall
  153. **【函数功能】 是否适用预测呼叫
  154. **【参数】
  155. **【返回值】 匹配true,否则false
  156. ****************************************************************/
  157. bool CFlowTemplate::isMatchedPreCall( void ) const
  158. {
  159. if(m_MatchedLine.IsEmpty())
  160. return false;
  161. if(m_MatchedLine == "|-2|" )
  162. return true;
  163. else
  164. return false;
  165. }