Exemple #1
0
OsStatus ACDCallManager::updateCallState(SIPX_CALLSTATE_INFO* pCallInfo)
{
   SIPX_CALL hCallHandle;
   SIPX_LINE hLineHandle;
   int       callEvent;
   int       callCause;
   OsStatus status = OS_FAILED ;

   mLock.acquire();

   // Extract the call handle and state info
   hCallHandle = pCallInfo->hCall;
   hLineHandle = pCallInfo->hLine;
   callEvent   = pCallInfo->event;
   callCause   = pCallInfo->cause;

   OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::updateCallState hCall=%d  hLine=%d callEvent %d callCause %d associated callHandle %d remoteAddr %s",
                    hCallHandle, hLineHandle, callEvent, callCause, pCallInfo->hAssociatedCall, pCallInfo->remoteAddress);

   // Search for the call handle in the various maps

   // Inbound calls are in the mCallHandleMap
   char *which = "mCallHandleMap" ;
   UtlHashMap *map = &mCallHandleMap ;
   UtlInt callKey(hCallHandle);
   UtlContainable *pValue = NULL ;
   pValue = mCallHandleMap.findValue(&callKey) ;

   if (pValue == NULL) {
      // Calls to agents are in the mAgentCallHandleMap
      which = "mAgentCallHandleMap" ;
      map = &mAgentCallHandleMap ;
      pValue = mAgentCallHandleMap.findValue(&callKey) ;
   }

   if (pValue == NULL) {
      // In transfer mode, sometimes calls end up in the mTransferCallHandleMap
      which = "mTransferCallHandleMap" ;
      map = &mTransferCallHandleMap ;
      pValue = mTransferCallHandleMap.findValue(&callKey) ;
   }

   if (pValue == NULL) {
      which = "mDeadCallHandleMap" ;
      map = &mDeadCallHandleMap ;
      pValue = mDeadCallHandleMap.findValue(&callKey) ;
   }

   if (pValue != NULL)
   {
      if (callEvent == CALLSTATE_DESTROYED) {
         // If event is destroyed, then that is the last we will see of this
         // handle.  Remove it from whatever map we found it in.
         OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::updateCallState - "
            "removing hCall=%d from %s", hCallHandle, which) ;
         map->removeReference(&callKey);
      }
      else
      {
         if (map != &mDeadCallHandleMap) {
            // Pass event along to the ACDCall we found
            ACDCall*  pCallRef = dynamic_cast<ACDCall*>(pValue);
            OsSysLog::add(FAC_ACD, gACD_DEBUG,
               "ACDCallManager::updateCallState - "
               "Found ACDCall Call(%d) hCall=%d Object(%p) using %s",
                  pCallRef->mhCallHandle, hCallHandle,
                  pCallRef, which) ;
            pCallRef->updateState(hCallHandle, callEvent, callCause);
         } else {
            OsSysLog::add(FAC_ACD, gACD_DEBUG,
              "ACDCallManager::updateCallState - ignoring dead hCall=%d events",
                 hCallHandle);
            // Kill the darn thing, just to make sure it goes away
            sipxCallDestroy(hCallHandle) ;
         }
      }
      status = OS_SUCCESS ;
   } else {
      OsSysLog::add(FAC_ACD, gACD_DEBUG,
         "ACDCallManager::updateCallState - did not find hCall=%d hLine=%d",
            hCallHandle, hLineHandle);
   }

   mLock.release();
   return status;
}