| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #include "StdAfx.h"
- #include "AgentGroup.h"
- #include "Agent.h"
- #include "NetworkAcd.h"
- #include "StrategyAD.h"
- CAgentGroup::CAgentGroup( void )
- {
- }
- CAgentGroup::~CAgentGroup( void )
- {
- }
- /*****************************************************************
- **【函数名称】 add
- **【函数功能】 添加座席
- **【参数】
- **【返回值】
- ****************************************************************/
- void CAgentGroup::add( CAgent* a_pAgent )
- {
- ASSERT(a_pAgent != NULL);
- m_CsLock4Distribute.Lock();
- Add(a_pAgent);
- m_CsLock4Distribute.Unlock();
- }
- /*****************************************************************
- **【函数名称】 remove
- **【函数功能】 删除座席
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CAgentGroup::remove( CAgent* a_pAgent )
- {
- ASSERT(a_pAgent != NULL);
- CSingleLock Lock(&m_CsLock4Distribute, TRUE);
- for(int i = 0; i < m_nSize; ++i)
- {
- if(m_pData[i] == a_pAgent)
- {
- RemoveAt(i, 1);
- TRACE(_T("Succeed @CAgentGroup::remove\r\n"));
- return true;
- }
- }
- return false;
- }
- /*****************************************************************
- **【函数名称】 clear
- **【函数功能】 释放所有座席
- **【参数】
- **【返回值】
- ****************************************************************/
- void CAgentGroup::clear( void )
- {
- RemoveAll();
- }
- /*****************************************************************
- **【函数名称】 isNoFreeAgent
- **【函数功能】 是否座席全忙
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CAgentGroup::isNoFreeAgent( void )
- {
- CSingleLock Lock(&m_CsLock4Distribute, TRUE);
- for(int i = 0; i < m_nSize; ++i) // 保证遍历一轮
- {
- if(m_pData[i]->isFree())
- return false;
- }
- return true;
- }
- /*****************************************************************
- **【函数名称】 distributeAgent
- **【函数功能】 分派座席
- **【参数】
- **【返回值】
- ****************************************************************/
- QUEUE_AGENT_RESULT CAgentGroup::distributeAgent( CStrategyAD* pStrategy, const CString& InfoEx, UINT& Agent, UINT& Exten )
- {
- if(m_nSize == 0)
- return QUEUE_AGENT_FAILED_NO_AGENT;
- // 如果座席全忙
- if(isNoFreeAgent())
- return QUEUE_AGENT_FAILED_NO_FREE;
- CAgent* pAgent = NULL;
- CSingleLock Lock(&m_CsLock4Distribute, TRUE);
- QUEUE_AGENT_RESULT Result = pStrategy->distributeAgent(*this, InfoEx, pAgent);
- if(pAgent != NULL && pAgent->lock()) // 对于无法锁定的座席,默认分配失败
- {
- Agent = pAgent->id();
- Exten = pAgent->assoExten();
- return Result;
- }
- else
- {
- return QUEUE_AGETN_FAILED_NO_SPEC;
- }
- }
|