⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acdtapi.c

📁 TAPI ACD Samples
💻 C
📖 第 1 页 / 共 3 页
字号:
    PLISTITEM           pEntry;
    LONG                lResult;
    
    pLCI = LineGetCallInfo(hCall);

    if (!pLCI)
    {
        return FALSE;
    }

    pGroup = g.pGroups;

    // find the group that this call came in on
    // walk all the groups
    while (pGroup)
    {
        // if the line and address match, it's the
        // correct address
        if ((pGroup->hLine == pLCI->hLine) &&
            (pGroup->dwAddress == pLCI->dwAddressID))
        {
            break;
        }

        pGroup = pGroup->pNext;
    }

    // couldn't find the group
    if (!pGroup)
    {
        // error!
        ACDFree(pLCI);
        return FALSE;
    }

    // OK - found the group that this call is for.  Now transfer to
    // an agent that is available.
    pEntry = pGroup->pAgentList;

    while (pEntry)
    {
        if (pEntry->bLoggedIn &&
            (pEntry->pAgent->pAddressInfo[pEntry->dwAddress].dwState ==
                LINEAGENTSTATE_READY))
        {
            // found someone
            // doing a blind transfer here
            // other implementations may need to
            // do lineSetupTransfer / lineDial / lineCompleteTransfer
            if (lResult = lineBlindTransfer(hCall,
                                            (LPCWSTR)pEntry->pAgent->lpszNumber,
                                            0))
            {
                //LogTapiError(TEXT("lineBlindTransfer"), lResult);
                // don't break - try the next agent
            }
            else
            {
                // set the state to reflect that
                // a call is being handled
                SetAgentState(pEntry->pAgent,
                              pEntry->dwAddress,
                              LINEAGENTSTATE_BUSYACD,
                              LINEAGENTSTATE_READY);

                break;
            }

        }
        
        pEntry = pEntry->pNext;
    }

    if (!pEntry)
    {
        // couldn't find an available agent

        // NOTE! NOTE! NOTE! NOTE! NOTE!
        // something should be done here with this call.  put into
        // a queue on hold or something.  For this sample, we are just
        // ignoring it
    }

    ACDFree(pLCI);

    return TRUE;
}


//////////////////////////////////////////////////////////////////////////
//
//  BOOL HandleIdle(HCALL hCall)
//
//    Handles LINECALLSTATE_IDLE
//     Should always always always deallocate when
//     getting an IDLE message.  Also, determine if this is a call
//     that we know about and set the agent state appropriatly
//
//////////////////////////////////////////////////////////////////////////
BOOL HandleIdle(HCALL hCall)
{
    LPLINECALLINFO      pLCI;
    PAGENT              pAgent;

    pLCI = LineGetCallInfo(hCall);

    // always deallocate the call
    lineDeallocateCall(hCall);

    if (!pLCI)
    {
        return FALSE;
    }

    // get the agent associated with the line
    pAgent = GetAgentFromhLine(pLCI->hLine);

    if (!pAgent)
    {
        ACDFree(pLCI);
        return FALSE;
    }
              

    // set that agent to their next state
    // Assumption:  only calls that the ACD app know about
    // occur.  For example, if an agent made an outgoing call
    // and it transitioned to idle, this code would still be executed.
    // May make more sense to not handle NextState in the ACD app, and let
    // the client app handle it.
    SetAgentState(pAgent,
                  pLCI->dwAddressID,
                  pAgent->pAddressInfo[pLCI->dwAddressID].dwNextState,
                  0);

    ACDFree(pLCI);
    
    return TRUE;
    
}


////////////////////////////////////////////////////////////////////////////
//
//  void HandleLineProxyRequest(HLINE hLine,
//                              LPLINEPROXYREQUEST pProxyRequest)
//
//    Handles LINE_PROXYREQUEST message
//     Just dispatches to appropriate functions
//
////////////////////////////////////////////////////////////////////////////
void HandleLineProxyRequest(HLINE hLine,
                            LPLINEPROXYREQUEST pProxyRequest)
{
    PAGENT       pAgent;
    LRESULT      lResult;

    pAgent = GetAgentFromName((LPTSTR)(((LPBYTE)pProxyRequest) +
                                       pProxyRequest->dwClientUserNameOffset));
    
    if (!pAgent)
    {
        lineProxyResponse(hLine,
                          pProxyRequest,
                          LINEERR_INVALAGENTID);

        return;
    }
    
    switch (pProxyRequest->dwRequestType)
    {
        case LINEPROXYREQUEST_SETAGENTGROUP:

            lResult = SetGroupList(pAgent,
                                   pProxyRequest->SetAgentGroup.dwAddressID,
                                   &pProxyRequest->SetAgentGroup.GroupList);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);

            return;
            
        case LINEPROXYREQUEST_SETAGENTSTATE:

            lResult = SetAgentState(pAgent,
                                    pProxyRequest->SetAgentState.dwAddressID,
                                    pProxyRequest->SetAgentState.dwAgentState,
                                    pProxyRequest->SetAgentState.dwNextAgentState);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            
            break;
            
        case LINEPROXYREQUEST_SETAGENTACTIVITY:

            lResult = SetAgentActivity(pAgent,
                                       pProxyRequest->SetAgentActivity.dwAddressID,
                                       pProxyRequest->SetAgentActivity.dwActivityID);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            
            break;
            
        case LINEPROXYREQUEST_GETAGENTSTATUS:

            lResult = GetAgentStatus(pAgent,
                                     pProxyRequest->GetAgentStatus.dwAddressID,
                                     &pProxyRequest->GetAgentStatus.AgentStatus);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            
            break;
            
        case LINEPROXYREQUEST_GETAGENTCAPS:

            if ((hLine == pAgent->hLine) &&
                (pProxyRequest->GetAgentCaps.dwAddressID < pAgent->dwNumAddresses))
            {
                lResult = MakeAgentCaps(pAgent,
                                        &pProxyRequest->GetAgentCaps.AgentCaps);
            }
            else
            {
                lResult = LINEERR_BADDEVICEID;
            }

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            break;
            
        case LINEPROXYREQUEST_GETAGENTACTIVITYLIST:

            lResult = MakeAgentActivityList(pAgent,
                                            &pProxyRequest->GetAgentActivityList.ActivityList);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            
            break;
            
        case LINEPROXYREQUEST_GETAGENTGROUPLIST:

            lResult = MakeGroupList(pAgent,
                                    &pProxyRequest->GetAgentGroupList.GroupList);

            lineProxyResponse(hLine,
                              pProxyRequest,
                              lResult);
            return;
            

    }
    return;
}

/////////////////////////////////////////////////////////////
//
//  void HandleLineCallState(DWORD dwDevice,
//
//  Handles callstate messages we are interested in
//
/////////////////////////////////////////////////////////////
void HandleLineCallState(DWORD dwDevice,
                         DWORD dwParam1,
                         DWORD dwParam2,
                         DWORD dwParam3)
{
    switch (dwParam1)
    {
    case LINECALLSTATE_OFFERING:
    {
        LPLINECALLSTATUS        pLCS;

        // get the call privilege.
        // NOTE:  the new LINE_APPNEWCALL message notifies applications
        // of their priv for new calls not created by app
        pLCS = LineGetCallStatus((HCALL)dwDevice);
        if (!pLCS)
        {
            break;
        }
        
        if (pLCS->dwCallPrivilege & LINECALLPRIVILEGE_OWNER)
        {
            HandleOffering((HCALL)dwDevice);
        }

        ACDFree(pLCS);
        
        break;
    }
    case LINECALLSTATE_CONNECTED:
        break;

    case LINECALLSTATE_DISCONNECTED:
        break;

    case LINECALLSTATE_IDLE:

        HandleIdle((HCALL)dwDevice);
        
        break;

    case LINECALLSTATE_BUSY:
        break;

    default:
        break;
    }
}


///////////////////////////////////////////////////////////////////////
// TAPI message handlers.  For this sample, they don't
// do anything
///////////////////////////////////////////////////////////////////////
void HandleLineDevState(DWORD dwParam1,
                        DWORD dwParam2,
                        DWORD dwParam3)
{
}


void HandleLineReply(DWORD dwParam1,
                     DWORD dwParam2,
                     DWORD dwParam3)
{
}
void HandleLineCallInfo(DWORD dwParam1,
                             DWORD dwParam2,
                             DWORD dwParam3)
{
}

void HandleLineClose(DWORD dwParam1,
                          DWORD dwParam2,
                          DWORD dwParam3)
{
}


//////////////////////////////////////////////////////////////////////////////////
//
// LineCallback() - TAPI callback function
//
//////////////////////////////////////////////////////////////////////////////////
VOID CALLBACK LineCallback (DWORD hDevice,
                            DWORD dwMsg,
                            DWORD dwCallbackInstance, 
                            DWORD dwParam1,
                            DWORD dwParam2, 
                            DWORD dwParam3)
{
    switch(dwMsg)
    {
      case LINE_PROXYREQUEST:
           HandleLineProxyRequest((HLINE) hDevice,
                                  (LPLINEPROXYREQUEST)dwParam1);
           return;
           
      case LINE_LINEDEVSTATE:
          HandleLineDevState(dwParam1,
                             dwParam2,
                             dwParam3);
          return;
      case LINE_REPLY:
          HandleLineReply(dwParam1,
                          dwParam2,
                          dwParam3);
          return;
      case LINE_CALLSTATE:
          HandleLineCallState(hDevice,
                              dwParam1,
                              dwParam2,
                              dwParam3);
          return; 
      case LINE_CALLINFO:
          HandleLineCallInfo(dwParam1,
                             dwParam2,
                             dwParam3);
          return;
      case LINE_CLOSE:
          HandleLineClose(dwParam1,
                          dwParam2,
                          dwParam3);
          return;

      default:
          return;
   }
}

   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -