bool ACDQueue_LongestIdle::buildTargetAgentList(UtlSList& rTargetAgentList, ACDCall* pCallRef) { // Always rebuild the list to get the agents added on the fly buildACDAgentList(); // Iterate through the ACDAgent list, starting at the head of the list // and find the agent that has been idle the longest. for(;;) { ACDAgent* pAgent; ACDAgent* pLongestIdleAgent = NULL; unsigned long maxIdleTime = 0; UtlSListIterator listIterator(mAcdAgentList); // Find the available agent with the longest idle time while ((pAgent = dynamic_cast<ACDAgent*>(listIterator())) != NULL) { if (pAgent->isAvailable(false)) { if (pAgent->getIdleTime() >= maxIdleTime) { maxIdleTime = pAgent->getIdleTime(); pLongestIdleAgent = pAgent; } } } if (pLongestIdleAgent == NULL) { // None available break ; } // If he is still available, use him. Otherwise start again. if (pLongestIdleAgent->isAvailable(true)) { rTargetAgentList.append(pLongestIdleAgent); OsSysLog::add(FAC_ACD, gACD_DEBUG, "%s::buildTargetAgentList - agent(%s) is added to the target list. Idle time was %lu seconds", mAcdSchemeString, pLongestIdleAgent->getUriString()->data(), maxIdleTime); return true ; } } // The whole list was tried, yet no appropriate agents were found. return false; }
bool ACDQueue_Linear::buildTargetAgentList(UtlSList& rTargetAgentList, ACDCall* pCallRef) { ACDAgent* pAgent; ACDAgent* pLastAttemptedAgent; // Always rebuild the list to get the agents added on the fly buildACDAgentList(); UtlSListIterator listIterator(mAcdAgentList); int numAgents = mAcdAgentList.entries(); // Iterate through the ACDAgent list, starting after the agent that // The ACDCall was last using. If the end of the list is // reached, wrap around to the beginning. If this LastAttemptedAgent // is NULL, start from the head of the list pLastAttemptedAgent = pCallRef->getLastAgent(); if (pLastAttemptedAgent != NULL) { // walk the iterator to point after pLastAttemptedAgent if (listIterator.findNext(pLastAttemptedAgent) == NULL) { // Didn't find pLastAttemptedAgent, start again from the top. listIterator.reset(); pCallRef->setLastAgent(NULL); } } for(int i=0; i<numAgents; i++) { // Check the next agent pAgent = dynamic_cast<ACDAgent*>(listIterator()); if (pAgent == NULL) { // We've hit the end of the list start back from the head of the list listIterator.reset(); pAgent = dynamic_cast<ACDAgent*>(listIterator()); if (pAgent == NULL) { // All out of agents to try return false; } } if (pAgent->isAvailable(true)) { rTargetAgentList.append(pAgent); // Remember the agent chosen pCallRef->setLastAgent(pAgent); OsSysLog::add(FAC_ACD, gACD_DEBUG, "%s::buildTargetAgentList - agent(%s) is added to the target list", mAcdSchemeString, pAgent->getUriString()->data()); return true; } } // The whole list was tried, yet no appropriate agents were found. return false; }