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

📄 sipxtapiinternal.cpp

📁 基于sipfoundy 公司开发的sipx协议API
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{    SIPX_CONF_DATA* pRC = (SIPX_CONF_DATA*) gpConfHandleMap->findHandle(hConf) ;    if (validConfData(pRC))    {        switch (type)        {            case SIPX_LOCK_READ:                // TODO: What happens if this fails?                pRC->pMutex->acquireRead() ;                break ;            case SIPX_LOCK_WRITE:                // TODO: What happens if this fails?                pRC->pMutex->acquireWrite() ;                break ;        }    }    else    {        pRC = NULL ;    }    return pRC ;}void sipxConfReleaseLock(SIPX_CONF_DATA* pData, SIPX_LOCK_TYPE type) {    if ((type != SIPX_LOCK_NONE) && validConfData(pData))    {        switch (type)        {            case SIPX_LOCK_READ:                // TODO: What happens if this fails?                pData->pMutex->releaseRead() ;                break ;            case SIPX_LOCK_WRITE:                // TODO: What happens if this fails?                pData->pMutex->releaseWrite() ;                break ;        }    }}void sipxConfFree(const SIPX_CONF hConf) {    SIPX_CONF_DATA* pData = sipxConfLookup(hConf, SIPX_LOCK_WRITE) ;        if (pData)    {        UtlString callId ;        SIPX_INSTANCE_DATA* pInst = NULL ;        const void* pRC = gpConfHandleMap->removeHandle(hConf);         if (pRC)        {            pData->pInst->pLock->acquire() ;            pData->pInst->nConferences-- ;            assert(pData->pInst->nConferences >= 0) ;            pData->pInst->pLock->release() ;                        callId = *pData->strCallId ;            pInst = pData->pInst ;                        delete pData->pMutex ;            delete pData->strCallId;            delete pData ;        }        else        {            sipxConfReleaseLock(pData, SIPX_LOCK_WRITE) ;        }                if (pInst && !callId.isNull())        {            pInst->pCallManager->drop(callId) ;        }    }}SIPX_INSTANCE_DATA* findSessionByCallManager(const void* pCallManager){    SIPX_INSTANCE_DATA *pInst = NULL ;    UtlDListIterator iter(*gpSessionList);       UtlVoidPtr* pObj = NULL;       while (pObj = dynamic_cast<UtlVoidPtr*>(iter()))           {        SIPX_INSTANCE_DATA* pTest = (SIPX_INSTANCE_DATA*) pObj->getValue() ;        if ((pTest) && (pTest->pCallManager == pCallManager))        {            pInst = pTest ;            break ;        }    }        return pInst ;}// Get the external host and port given the contact preferencevoid sipxGetContactHostPort(SIPX_INSTANCE_DATA* pData,                             SIPX_CONTACT_TYPE contactType,                             Url& uri){    UtlBoolean bSet = FALSE  ;    UtlString useIp ;    int       usePort ;    if (contactType == CONTACT_RELAY)    {        // Relay is not supported yet -- default to AUTO for now.        contactType = CONTACT_AUTO  ;    }    // Use configured address first    if ((contactType == CONTACT_AUTO) || (contactType == CONTACT_CONFIG))    {        if (pData->pSipUserAgent->getConfiguredPublicAddress(&useIp, &usePort))        {            uri.setHostAddress(useIp) ;            uri.setHostPort(usePort) ;            bSet = TRUE ;        }    }    // Use NAT_MAPPED next    if (!bSet && ((contactType == CONTACT_AUTO) || (contactType == CONTACT_NAT_MAPPED)))    {        if (pData->pSipUserAgent->getNatMappedAddress(&useIp, &usePort))        {            uri.setHostAddress(useIp) ;            uri.setHostPort(usePort) ;            bSet = TRUE ;        }    }    // Lastly, use local    if (!bSet)    {        if (pData->pSipUserAgent->getLocalAddress(&useIp, &usePort))        {            uri.setHostAddress(useIp) ;            uri.setHostPort(usePort) ;            bSet = TRUE ;        }    }}  SIPXTAPI_API void sipxLogEntryAdd(OsSysLogPriority priority,                      const char *format,                     ...){    va_list ap;    va_start(ap, format);    int threadId;    OsTask::getCurrentTaskId(threadId) ;    OsSysLog::vadd("sipXtapi", threadId, FAC_SIPXTAPI, priority, format, ap);           va_end(ap);}SIPXTAPI_API SIPX_RESULT sipxConfigAllowMethod(const SIPX_INST hInst, const char* method, const bool bAllow){    SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst;        if (pInst)    {        pInst->pSipUserAgent->allowMethod(method, bAllow);    }    return SIPX_RESULT_SUCCESS;}void sipxIncSessionCount(){    OsLock lock(*gpSessionLock);    ++gSessions;}void sipxDecSessionCount(){    OsLock lock(*gpSessionLock);    --gSessions;}int sipxGetSessionCount(){    return gSessions;}UtlBoolean sipxIsCallInFocus() {    UtlBoolean inFocus = false ;    gpCallHandleMap->lock() ;    UtlHashMapIterator iter(*gpCallHandleMap);       UtlInt* pIndex = NULL;    UtlVoidPtr* pObj = NULL;    SIPX_CALL hCall = 0 ;       while (pIndex = dynamic_cast<UtlInt*>( iter() ) )           {        pObj = dynamic_cast<UtlVoidPtr*>(gpCallHandleMap->findValue(pIndex));        SIPX_CALL_DATA* pData = NULL ;        if (pObj)        {            pData = (SIPX_CALL_DATA*) pObj->getValue() ;            if (pData->bInFocus)            {                inFocus = true ;                break ;            }        }    }    gpCallHandleMap->unlock() ;    return inFocus ;}SIPX_RESULT sipxGetActiveCallIds(SIPX_INST hInst, int maxCalls, int& actualCalls, UtlString callIds[]) {    SIPX_RESULT rc = SIPX_RESULT_FAILURE ;    SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst;    if (pInst)    {        OsStatus status = pInst->pCallManager->getCalls(maxCalls, actualCalls, callIds) ;        if (status == OS_SUCCESS)        {            rc = SIPX_RESULT_SUCCESS ;        }    }    else    {        rc = SIPX_RESULT_INVALID_ARGS ;    }    return rc ;}SIPX_RESULT sipxFlushHandles(){    gpCallHandleMap->destroyAll() ;    gpLineHandleMap->destroyAll() ;    gpConfHandleMap->destroyAll() ;    gpInfoHandleMap->destroyAll() ;    gpPubHandleMap->destroyAll() ;    gpSubHandleMap->destroyAll() ;    //gpTransportHandleMap->destroyAll() ;    gpSessionLock->acquire() ;    gpSessionList->destroyAll() ;    gpSessionLock->release() ;    if (g_pEventListenerLock && g_pEventListeners)    {        g_pEventListenerLock->acquire() ;        g_pEventListeners->destroyAll() ;        g_pEventListenerLock->release() ;    }    return SIPX_RESULT_SUCCESS ;}SIPX_RESULT sipxCheckForHandleLeaks() {    SIPX_RESULT rc = SIPX_RESULT_SUCCESS ;    if (gpCallHandleMap->entries() != 0)    {        printf("\ngpCallHandleMap Leaks (%d):\n", gpCallHandleMap->entries()) ;        gpCallHandleMap->dump() ;        rc = SIPX_RESULT_FAILURE ;    }    if (gpLineHandleMap->entries() != 0)    {        printf("\ngpLineHandleMap Leaks (%d):\n", gpLineHandleMap->entries()) ;        gpLineHandleMap->dump() ;        rc = SIPX_RESULT_FAILURE ;    }    if (gpConfHandleMap->entries() != 0)    {        printf("\ngpConfHandleMap Leaks (%d):\n", gpConfHandleMap->entries()) ;        gpConfHandleMap->dump() ;        rc = SIPX_RESULT_FAILURE ;    }    if (gpInfoHandleMap->entries() != 0)    {        printf("\ngpInfoHandleMap Leaks (%d):\n", gpInfoHandleMap->entries()) ;        gpInfoHandleMap->dump() ;        rc = SIPX_RESULT_FAILURE ;    }    if (gpSessionList->entries() != 0)    {        printf("\ngSessionList leaks (%d)\n", gpSessionList->entries()) ;        rc = SIPX_RESULT_FAILURE ;    }    return rc ;}SIPXTAPI_API SIPX_RESULT sipxCallGetConnectionMediaInterface(const SIPX_CALL hCall,                                                             void** ppInstData){    SIPX_RESULT sr = SIPX_RESULT_FAILURE;    int connectionId = -1;    UtlString callId ;    UtlString remoteAddress ;        SIPX_CALL_DATA* pData = sipxCallLookup(hCall, SIPX_LOCK_READ);        assert(pData != 0);    assert(pData->pInst != 0);        if (pData && pData->callId && pData->remoteAddress)    {        callId = *pData->callId ;        remoteAddress = *pData->remoteAddress ;    }        if (pData)    {        sipxCallReleaseLock(pData, SIPX_LOCK_READ) ;    }            if (!callId.isNull() && !remoteAddress.isNull())    {        connectionId = pData->pInst->pCallManager->getMediaConnectionId(callId, remoteAddress, ppInstData);        if (-1 != connectionId)        {            sr = SIPX_RESULT_SUCCESS;        }    }    return sr;}       #ifdef VOICE_ENGINE#include "include\VoiceEngineMediaInterface.h"SIPXTAPI_API GipsVoiceEngineLib* sipxCallGetVoiceEnginePtr(const SIPX_CALL hCall){    VoiceEngineMediaInterface* pMediaInterface = NULL;    GipsVoiceEngineLib* pLib = NULL;        if (hCall)    {        sipxCallGetConnectionMediaInterface(hCall, (void**)&pMediaInterface);        if (pMediaInterface)        {            pLib = pMediaInterface->getVoiceEnginePtr();        }    }    return pLib;    }SIPXTAPI_API GipsVoiceEngineLib* sipxConfigGetVoiceEnginePtr(const SIPX_INST hInst){    GipsVoiceEngineLib* ptr = NULL;    SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst ;    if (pInst)    {        VoiceEngineFactoryImpl* pInterface =                static_cast<VoiceEngineFactoryImpl*>(pInst->pCallManager->getMediaInterfaceFactory()->getFactoryImplementation());        if (pInterface)        {            ptr = pInterface->getVoiceEnginePointer();        }    }    OsSysLog::add(FAC_SIPXTAPI, PRI_INFO,        "sipxConfigGetVoiceEnginePtr hInst=%x, ptr=%08X",        hInst, ptr);    return ptr;}SIPXTAPI_API GIPSAECTuningWizard* sipxConfigGetVoiceEngineAudioWizard(){    GIPSAECTuningWizard& wizard = GetGIPSAECTuningWizard();        return &wizard;}#ifdef VIDEOSIPXTAPI_API GipsVideoEngineWindows* sipxConfigGetVideoEnginePtr(const SIPX_INST hInst){    GipsVideoEngineWindows* ptr = NULL;    SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst ;    if (pInst)    {        VoiceEngineFactoryImpl* pImpl = (VoiceEngineFactoryImpl *) pInst->pCallManager->getMediaInterfaceFactory()->getFactoryImplementation();        if (pImpl)        {            ptr = pImpl->getVideoEnginePointer();        }    }    OsSysLog::add(FAC_SIPXTAPI, PRI_INFO,        "sipxConfigGetVideoEnginePtr hInst=%x, ptr=%08X",        hInst, ptr);    return ptr;}#endifvoid GIPSVETraceCallback(char *szMsg, int iNum){    OsSysLog::add(FAC_AUDIO, PRI_DEBUG,            "%s (%d)",            szMsg,             iNum);}SIPXTAPI_API SIPX_RESULT sipxEnableAudioLogging(const SIPX_INST hInst, bool bEnable){    SIPX_RESULT rc = SIPX_RESULT_FAILURE;    GipsVoiceEngineLib* ptr = sipxConfigGetVoiceEnginePtr(hInst);    if (NULL != ptr)    {        if (bEnable)        {	        int irc = ptr->GIPSVE_SetTraceCallback(GIPSVETraceCallback);        }        else        {	        int irc = ptr->GIPSVE_SetTraceCallback(NULL);        }        rc = SIPX_RESULT_SUCCESS;    }    return rc;}#endifSIPXTAPI_API SIPX_RESULT sipxTranslateToneId(const TONE_ID toneId,                                             TONE_ID& xlateId){    SIPX_RESULT sr = SIPX_RESULT_SUCCESS;    xlateId = (TONE_ID)0;#ifdef VOICE_ENGINE    if (toneId >= '0' && toneId <= '9')    {        xlateId = (TONE_ID)(toneId - '0');    }     else if (toneId == ID_DTMF_STAR)    {        xlateId = (TONE_ID)10;    }    else if (toneId == ID_DTMF_POUND)    {        xlateId = (TONE_ID)11;    }

⌨️ 快捷键说明

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