📄 sipxtapi.cpp
字号:
return sr ;}static SIPX_RESULT sipxCallCreateHelper(const SIPX_INST hInst, const SIPX_LINE hLine, const SIPX_CONF hConf, SIPX_CALL* phCall){ SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_LINE_DATA* pLine = sipxLineLookup(hLine, SIPX_LOCK_READ) ; SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst ; assert(phCall != NULL) ; assert(pLine != NULL) ; assert(pLine->lineURI != NULL) ; if (pInst) { if (phCall && pLine) { SIPX_CALL_DATA* pData = new SIPX_CALL_DATA ; memset((void*)pData, 0, sizeof(SIPX_CALL_DATA)); // Set the call state to initialized but not yet used (e.g. not connecting) pData->state = SIPX_INTERNAL_CALLSTATE_UNKNOWN; if (pData) { UtlString callId ; pInst->pCallManager->createCall(&callId) ; // Set Call ID pData->callId = new UtlString(callId) ; assert(pData->callId != NULL) ; // Set Conf handle pData->hConf = hConf ; // Set Line URI pData->hLine = hLine ; pData->lineURI = new UtlString(pLine->lineURI->toString().data()) ; assert(pData->lineURI != NULL) ; // Remote Address pData->remoteAddress = NULL ; // Store Instance pData->pInst = pInst ; // Create Mutex pData->pMutex = new OsRWMutex(OsRWMutex::Q_FIFO) ; // Increment call count pInst->pLock->acquire() ; pInst->nCalls++ ; pInst->pLock->release() ; if ((pData->callId == NULL) || (pData->lineURI == NULL)) { *phCall = SIPX_CALL_NULL ; destroyCallData(pData) ; sr = SIPX_RESULT_OUT_OF_MEMORY ; } else { *phCall = gpCallHandleMap->allocHandle(pData) ; assert(*phCall != 0) ; sr = SIPX_RESULT_SUCCESS ; } } else { sr = SIPX_RESULT_OUT_OF_MEMORY ; destroyCallData(pData) ; *phCall = SIPX_CALL_NULL ; } } else { sr = SIPX_RESULT_INVALID_ARGS ; } } sipxLineReleaseLock(pLine, SIPX_LOCK_READ) ; return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallCreate(const SIPX_INST hInst, const SIPX_LINE hLine, SIPX_CALL* phCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallCreate hInst=%p hLine=%d phCall=%p", hInst, hLine, phCall); SIPX_RESULT rc = sipxCallCreateHelper(hInst, hLine, NULL, phCall) ; if (rc == SIPX_RESULT_SUCCESS) { SIPX_CALL_DATA* pData = sipxCallLookup(*phCall, SIPX_LOCK_READ) ; SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst ; UtlString callId = *pData->callId ; sipxCallReleaseLock(pData, SIPX_LOCK_READ) ; // Notify Listeners SipSession session ; sipxFireCallEvent(pInst->pCallManager, callId.data(), &session, NULL, DIALTONE, DIALTONE_UNKNOWN) ; } return rc ;}SIPXTAPI_API SIPX_RESULT sipxCallConnect(SIPX_CALL hCall, const char* szAddress, SIPX_CONTACT_ID contactId, SIPX_VIDEO_DISPLAY* const pDisplay){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallConnect hCall=%d szAddress=%s contactId=%d", hCall, szAddress, contactId);#ifdef VIDEO if (pDisplay) { assert(pDisplay->handle); }#endif SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; UtlString lineId ; bool bSetFocus = false ; assert(szAddress != NULL) ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, &lineId)) { CONTACT_ADDRESS* pContact = NULL; CONTACT_TYPE contactType; if (contactId > 0) { pContact = pInst->pSipUserAgent->getContactDb().find(contactId); assert(pContact); contactType = pContact->eContactType; } else { contactType = AUTO; } if (szAddress) { PtStatus status ; assert(remoteAddress.length() == 0) ; // should be null // Only take focus if something doesn't already have it. if (!sipxIsCallInFocus()) { pInst->pCallManager->unholdLocalTerminalConnection(callId.data()) ; bSetFocus = true ; } pInst->pCallManager->setOutboundLineForCall(callId.data(), lineId.data()) ; UtlString sessionId ; pInst->pCallManager->getNewSessionId(&sessionId) ; SIPX_CALL_DATA* pData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); if (pData) { pData->bInFocus = bSetFocus ; assert(pData->sessionCallId == NULL) ; // should be null if (pData->sessionCallId != NULL) { delete pData->sessionCallId ; } pData->sessionCallId = new UtlString(sessionId.data()) ; if (pDisplay) { pData->display = *pDisplay; } sipxCallReleaseLock(pData, SIPX_LOCK_WRITE) ; } // Set the outbound line for the new connection pInst->pCallManager->setOutboundLineForCall(*(pData->callId), lineId); if (pDisplay && pDisplay->handle) { status = pInst->pCallManager->connect(callId.data(), szAddress, NULL, sessionId, (CONTACT_ID) contactId, &pData->display) ; } else { status = pInst->pCallManager->connect(callId.data(), szAddress, NULL, sessionId, (CONTACT_ID) contactId) ; } if (status == PT_SUCCESS) { int numAddresses = 0 ; UtlString address ; OsStatus rc = pInst->pCallManager->getCalledAddresses( callId.data(), 1, numAddresses, &address) ; OsSysLog::add(FAC_SIPXTAPI, PRI_DEBUG, "sipxCallConnect connected hCall=%d callId=%s, numAddr = %d, addr = %s", hCall, callId.data(), numAddresses, address.data()); if(rc == OS_SUCCESS) { assert(numAddresses == 1); } // There is more than 1 connection in this CpPeerCall. else if(rc == OS_LIMIT_REACHED) { // Need to get the remote address (To field) for the new connection. // For now as with sipXconferenceAdd, we defer setting the remote address // until an event bubbles out. This avoids the abiguity problem when there // is more than one connection with the same SIP URI user Id. The events // get labeled with a sessionId which is unique. So the first event for // this sessionId with a remote address set will set the remoteAddress for // this call handle. address = ""; } else { assert(rc == OS_SUCCESS) ; } // Set Remote Connection SIPX_CALL_DATA* pData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); if (pData) { if (pData->remoteAddress) { delete pData->remoteAddress ; } pData->remoteAddress = new UtlString(address) ; assert(pData->remoteAddress != NULL) ; if (pData->remoteAddress == NULL) { sr = SIPX_RESULT_OUT_OF_MEMORY ; } else { sr = SIPX_RESULT_SUCCESS ; } sipxCallReleaseLock(pData, SIPX_LOCK_WRITE) ; } } else { SipSession session ; sipxFireCallEvent(pInst->pCallManager, callId.data(), &session, szAddress, DISCONNECTED, DISCONNECTED_BADADDRESS) ; sr = SIPX_RESULT_BAD_ADDRESS ; } } else { sr = SIPX_RESULT_INVALID_ARGS ; } } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallHold(const SIPX_CALL hCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallHold hCall=%d", hCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { SIPX_CONF hConf = sipxCallGetConf(hCall) ; if (hConf == SIPX_CONF_NULL) { pInst->pCallManager->holdLocalTerminalConnection(callId.data()) ; pInst->pCallManager->holdTerminalConnection(callId.data(), remoteAddress.data(), 0) ; } else { pInst->pCallManager->holdTerminalConnection(callId.data(), remoteAddress.data(), 0) ; } sr = SIPX_RESULT_SUCCESS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallUnhold(const SIPX_CALL hCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallUnhold hCall=%d", hCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { SIPX_CONF hConf = sipxCallGetConf(hCall) ; if (hConf == SIPX_CONF_NULL) { SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE) ; if (pCallData) { pCallData->bInFocus = true ; sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } pInst->pCallManager->unholdTerminalConnection(callId.data(), remoteAddress, NULL); pInst->pCallManager->unholdLocalTerminalConnection(callId.data()) ; } else { pInst->pCallManager->unholdTerminalConnection(callId.data(), remoteAddress, NULL); } sr = SIPX_RESULT_SUCCESS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallDestroy(SIPX_CALL& hCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallDestroy hCall=%d", hCall); SIPX_CONF hConf = sipxCallGetConf(hCall) ; SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteUrl ; UtlString ghostCallId ; if (hConf != 0) { sr = sipxConferenceRemove(hConf, hCall) ; } else if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteUrl, NULL, &ghostCallId)) { if (sipxCallIsRemoveInsteadOfDropSet(hCall)) { pInst->pCallManager->dropConnection(callId, remoteUrl) ; } else { pInst->pCallManager->drop(callId.data()) ; if (ghostCallId.length() > 0) { pInst->pCallManager->drop(ghostCallId.data()) ; } sr = SIPX_RESULT_SUCCESS ; } // If not remote url, then the call was never completed and no // connection object exists (and no way to send an event) -- remove // the call handle. if (remoteUrl.length() == 0) { sipxCallObjectFree(hCall) ; } } else { // Not finding the call is ok (torn down) providing // that the handle is valid. if (hCall != SIPX_CALL_NULL) { sr = SIPX_RESULT_SUCCESS ; } } hCall = SIPX_CALL_NULL ; return sr ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -