From 366e14c1c998029c256c439d06e40685a48af667 Mon Sep 17 00:00:00 2001
From: Domenico Chierico <domenico.chierico@sip2ser.it>
Date: Mon, 14 May 2012 13:47:05 +0200
Subject: [PATCH] acd fixes

---
 sipXacd/src/ACDCall.cpp  |   11 +++++++++--
 sipXacd/src/ACDCall.h    |    1 +
 sipXacd/src/ACDQueue.cpp |    1 -
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/sipXacd/src/ACDCall.cpp b/sipXacd/src/ACDCall.cpp
index 6e0ba7c..e22797f 100644
--- a/sipXacd/src/ACDCall.cpp
+++ b/sipXacd/src/ACDCall.cpp
@@ -976,7 +976,7 @@ void ACDCall::setManagingQueueMessage(ACDQueue* pManagingQueue, int waitTime)
 
    // Reset a previous max-wait-time timer
    resetQueueMaxWaitTimer();
-
+   mpQueueResidualWait = waitTime;
    // Associate the ACDCall with a managing ACDQueue
    mpManagingQueue = pManagingQueue;
 
@@ -1340,6 +1340,8 @@ void ACDCall::routeRequestMessage(UtlSList* pTargetAgentList, int connectionSche
    mConnectionScheme = connectionScheme;
    mRingNoAnswerTime = timeout;
 
+   resetQueueMaxWaitTimer();   // here agent is ringin
+
    if (mRouteState != ACDCallRouteState::IDLE)
    {
       if ((mRouteState == ACDCallRouteState::FAILED) ||
@@ -1821,7 +1823,9 @@ void ACDCall::acdAgentDisconnectedEvent(SIPX_CALL callHandle)
 {
    OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCall::acdAgentDisconnectedEvent - Call(%d) [%s] is being disconnected from AgentCall %d",
                  mhCallHandle, mpCallIdentity, callHandle);
-
+   if( mpQueueResidualWait != 0){
+     mpQueueMaxWaitTimer->oneshotAfter(OsTime(mpQueueResidualWait, 0));
+   }
     mpRouteStateMachine->acdAgentDisconnectedEvent(this, callHandle);
 }
 
@@ -1971,6 +1975,9 @@ void ACDCall::acdTransferAgentDisconnectedEvent(SIPX_CALL agentCallHandle)
 
 void ACDCall::routeRequestTimeoutEvent(void)
 {
+  if ( mpQueueResidualWait != 0 ) {
+    mpQueueMaxWaitTimer->oneshotAfter(OsTime(mpQueueResidualWait, 0));
+  }
    mpRouteStateMachine->routeRequestTimeoutEvent(this);
 }
 
diff --git a/sipXacd/src/ACDCall.h b/sipXacd/src/ACDCall.h
index 2006420..5e769ce 100644
--- a/sipXacd/src/ACDCall.h
+++ b/sipXacd/src/ACDCall.h
@@ -262,6 +262,7 @@ private:
    ACDCallRouteState::eRouteState mRouteState;   // The state of the call routing process
    ACDCallRouteState* mpRouteStateMachine;
    ACDQueue*        mpManagingQueue;             // The current ACDQueue that is managing this call
+   int              mpQueueResidualWait;         // The queue residual timer
    OsTimer*         mpQueueMaxWaitTimer;         // The queue max-wait-time timer
    UtlSList         mAgentCandidateList;         // List of possible ACDAgents to route this call to
    ACDAgent*        mpActiveAgent;               // The ACDAgent that this call was routed to
diff --git a/sipXacd/src/ACDQueue.cpp b/sipXacd/src/ACDQueue.cpp
index 7a26f4e..d667e03 100644
--- a/sipXacd/src/ACDQueue.cpp
+++ b/sipXacd/src/ACDQueue.cpp
@@ -1879,7 +1879,6 @@ void ACDQueue::adjustTimers()
    }
    // Disable the max wait time if there is no overflow queue/entry is defined
    if (mOverflowQueue == NULL &&  mOverflowEntry == NULL ) {
-      mMaxWaitTime = 0;
 
       if (mAcdScheme == RING_ALL) {
          mMaxRingDelay = 0;
-- 
1.7.4.4

