商丘数字城管中间件 - 测试用

AgentGroup.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "StdAfx.h"
  2. #include "AgentGroup.h"
  3. #include "Agent.h"
  4. #include "NetworkAcd.h"
  5. #include "StrategyAD.h"
  6. CAgentGroup::CAgentGroup( void )
  7. {
  8. }
  9. CAgentGroup::~CAgentGroup( void )
  10. {
  11. }
  12. /*****************************************************************
  13. **【函数名称】 add
  14. **【函数功能】 添加座席
  15. **【参数】
  16. **【返回值】
  17. ****************************************************************/
  18. void CAgentGroup::add( CAgent* a_pAgent )
  19. {
  20. ASSERT(a_pAgent != NULL);
  21. m_CsLock4Distribute.Lock();
  22. Add(a_pAgent);
  23. m_CsLock4Distribute.Unlock();
  24. }
  25. /*****************************************************************
  26. **【函数名称】 remove
  27. **【函数功能】 删除座席
  28. **【参数】
  29. **【返回值】
  30. ****************************************************************/
  31. bool CAgentGroup::remove( CAgent* a_pAgent )
  32. {
  33. ASSERT(a_pAgent != NULL);
  34. CSingleLock Lock(&m_CsLock4Distribute, TRUE);
  35. for(int i = 0; i < m_nSize; ++i)
  36. {
  37. if(m_pData[i] == a_pAgent)
  38. {
  39. RemoveAt(i, 1);
  40. TRACE(_T("Succeed @CAgentGroup::remove\r\n"));
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. /*****************************************************************
  47. **【函数名称】 clear
  48. **【函数功能】 释放所有座席
  49. **【参数】
  50. **【返回值】
  51. ****************************************************************/
  52. void CAgentGroup::clear( void )
  53. {
  54. RemoveAll();
  55. }
  56. /*****************************************************************
  57. **【函数名称】 isNoFreeAgent
  58. **【函数功能】 是否座席全忙
  59. **【参数】
  60. **【返回值】
  61. ****************************************************************/
  62. bool CAgentGroup::isNoFreeAgent( void )
  63. {
  64. CSingleLock Lock(&m_CsLock4Distribute, TRUE);
  65. for(int i = 0; i < m_nSize; ++i) // 保证遍历一轮
  66. {
  67. if(m_pData[i]->isFree())
  68. return false;
  69. }
  70. return true;
  71. }
  72. //2018.6.14 for 严格循环
  73. CAgent* CAgentGroup::GetFreeAgentForLoop()
  74. {
  75. CSingleLock Lock(&m_CsLock4Distribute, TRUE);
  76. CAgent *pAgent = NULL;
  77. for (int idx = m_nSize; idx > 0; idx-- ) {
  78. pAgent = m_pData[0];
  79. RemoveAt(0, 1);
  80. Add(pAgent);
  81. if (pAgent->isFree()) {
  82. return pAgent; // ych
  83. }
  84. }
  85. return NULL; // ych
  86. }
  87. /*****************************************************************
  88. **【函数名称】 distributeAgent
  89. **【函数功能】 分派座席
  90. **【参数】
  91. **【返回值】
  92. ****************************************************************/
  93. QUEUE_AGENT_RESULT CAgentGroup::distributeAgent( CStrategyAD* pStrategy, const CString& InfoEx, UINT& Agent, UINT& Exten )
  94. {
  95. if(m_nSize == 0)
  96. return QUEUE_AGENT_FAILED_NO_AGENT;
  97. // 如果座席全忙
  98. if(isNoFreeAgent())
  99. return QUEUE_AGENT_FAILED_NO_FREE;
  100. CAgent* pAgent = NULL;
  101. CSingleLock Lock(&m_CsLock4Distribute, TRUE);
  102. QUEUE_AGENT_RESULT Result = pStrategy->distributeAgent(*this, InfoEx, pAgent);
  103. if(pAgent != NULL && pAgent->lock()) // 对于无法锁定的座席,默认分配失败
  104. {
  105. Agent = pAgent->id();
  106. Exten = pAgent->assoExten();
  107. return Result;
  108. }
  109. else
  110. {
  111. return QUEUE_AGETN_FAILED_NO_SPEC;
  112. }
  113. }