📄 sipxtapievents.cpp
字号:
return str ;}SIPXTAPI_API char* sipxEventToString(const SIPX_EVENT_CATEGORY category, const void* pEvent, char* szBuffer, size_t nBuffer){ switch (category) { case EVENT_CATEGORY_CALLSTATE: { SIPX_CALLSTATE_INFO* pCallEvent = (SIPX_CALLSTATE_INFO*)pEvent; SNPRINTF(szBuffer, nBuffer, "%s::%s::%s", convertEventCategoryToString(category), MajorEventToString((SIPX_CALLSTATE_MAJOR) pCallEvent->event), MinorEventToString((SIPX_CALLSTATE_MINOR) pCallEvent->cause)) ; } break; case EVENT_CATEGORY_LINESTATE: { SIPX_LINESTATE_INFO* pLineEvent = (SIPX_LINESTATE_INFO*)pEvent; SNPRINTF(szBuffer, nBuffer, "%s::%s::%s", convertEventCategoryToString(category), MajorLineEventToString((SIPX_LINE_EVENT_TYPE_MAJOR) pLineEvent->event), MinorLineEventToString((SIPX_LINE_EVENT_TYPE_MINOR) pLineEvent->cause)) ; } break; case EVENT_CATEGORY_INFO_STATUS: { SIPX_INFOSTATUS_INFO* pInfoEvent = (SIPX_INFOSTATUS_INFO*)pEvent; SNPRINTF(szBuffer, nBuffer, "%s::%s::%s", convertEventCategoryToString(category), convertInfoStatusEventToString(pInfoEvent->event), convertMessageStatusToString(pInfoEvent->status)) ; } break; case EVENT_CATEGORY_INFO: { SNPRINTF(szBuffer, nBuffer, "%s", convertEventCategoryToString(category)) ; } break ; case EVENT_CATEGORY_SUB_STATUS: { SIPX_SUBSTATUS_INFO* pStatusInfo = (SIPX_SUBSTATUS_INFO*) pEvent ; SNPRINTF(szBuffer, nBuffer, "%s::%s::%s", convertEventCategoryToString(category), convertSubscriptionStateToString(pStatusInfo->state), convertSubscriptionCauseToString(pStatusInfo->cause)) ; } break ; case EVENT_CATEGORY_NOTIFY: { SNPRINTF(szBuffer, nBuffer, "%s", convertEventCategoryToString(category)) ; } break ; case EVENT_CATEGORY_CONFIG: { SIPX_CONFIG_INFO* pConfigEvent = (SIPX_CONFIG_INFO*)pEvent; SNPRINTF(szBuffer, nBuffer, "%s::%s", convertEventCategoryToString(category), convertConfigEventToString(pConfigEvent->event)) ; } break ; default: break; } return szBuffer ;}SIPXTAPI_API char* sipxCallEventToString(SIPX_CALLSTATE_MAJOR eMajor, SIPX_CALLSTATE_MINOR eMinor, char* szBuffer, size_t nBuffer){ assert(szBuffer != NULL) ; if (szBuffer) { SNPRINTF(szBuffer, nBuffer, "%s::%s", MajorEventToString(eMajor), MinorEventToString(eMinor)) ; } return szBuffer ;}SIPXTAPI_API char* sipxLineEventToString(SIPX_LINE_EVENT_TYPE_MAJOR lineTypeMajor, SIPX_LINE_EVENT_TYPE_MINOR lineTypeMinor, char* szBuffer, size_t nBuffer){#if defined(WIN32) _snprintf(szBuffer, nBuffer, "%s::%s", MajorLineEventToString(lineTypeMajor), MinorLineEventToString(lineTypeMinor));#else snprintf(szBuffer, nBuffer, "%s::%s", MajorLineEventToString(lineTypeMajor), MinorLineEventToString(lineTypeMinor));#endif return szBuffer;}void ReportCallback(SIPX_CALL hCall, SIPX_LINE hLine, SIPX_CALLSTATE_MAJOR eMajor, SIPX_CALLSTATE_MINOR eMinor, void* pUserData){ SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; UtlString lineId ; static size_t nCnt = 0 ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, &lineId)) { printf("<event i=%p, h=%04X, c=%4d, M=%25s, m=%25s, a=%s, c=%s l=%s/>\n", pInst, hCall, ++nCnt, MajorEventToString(eMajor), MinorEventToString(eMinor), remoteAddress.data(), callId.data(), lineId.data()) ; }}void sipxFireCallEvent(const void* pSrc, const char* szCallId, SipSession* pSession, const char* szRemoteAddress, SIPX_CALLSTATE_MAJOR major, SIPX_CALLSTATE_MINOR minor, void* pEventData, const char* szRemoteAssertedIdentity){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxFireCallEvent pSrc=%p callId=%s pSession=%p, szRemoteAddress=%s major=%d minor=%d assertedId=%s", pSrc, szCallId, pSession, szRemoteAddress, major, minor, szRemoteAssertedIdentity ? szRemoteAssertedIdentity : ""); SIPX_CALL hCall = SIPX_CALL_NULL; { // Scope for listener/event locks OsLock lock(*g_pListenerLock) ; OsLock eventLock(*g_pEventListenerLock) ; SIPX_CALL_DATA* pCallData = NULL; SIPX_LINE hLine = SIPX_LINE_NULL ; UtlVoidPtr* ptr = NULL; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; UtlString lineId ; SIPX_CALL hAssociatedCall = SIPX_CALL_NULL ; // If this is an NEW inbound call (first we are hearing of it), then create // a call handle/data structure for it. if (major == NEWCALL) { pCallData = new SIPX_CALL_DATA; memset((void*) pCallData, 0, sizeof(SIPX_CALL_DATA)); pCallData->callId = new UtlString(szCallId) ; pCallData->remoteAddress = new UtlString(szRemoteAddress) ; pCallData->pMutex = new OsRWMutex(OsRWMutex::Q_FIFO) ; Url urlFrom; pSession->getFromUrl(urlFrom) ; pCallData->lineURI = new UtlString(urlFrom.toString()) ; pCallData->pInst = findSessionByCallManager(pSrc) ; hCall = gpCallHandleMap->allocHandle(pCallData) ; pInst = pCallData->pInst ; if (pEventData) { char* szOriginalCallId = (char*) pEventData ; hAssociatedCall = sipxCallLookupHandle(UtlString(szOriginalCallId), pSrc) ; // Make sure we remove the call instead of allowing a drop. When acting // as a transfer target, we are performing surgery on a CpPeerCall. We // want to remove the call leg -- not drop the entire call. if (hAssociatedCall) { sipxCallSetRemoveInsteadofDrop(hAssociatedCall) ; } } // Increment call count pInst->pLock->acquire() ; pInst->nCalls++ ; pInst->pLock->release() ; callId = szCallId ; remoteAddress = szRemoteAddress ; lineId = urlFrom.toString() ; } else { hCall = sipxCallLookupHandle(szCallId, pSrc); if (!sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, &lineId)) { // osPrintf("event sipXtapiEvents: Unable to find call data for handle: %d\n", hCall) ; // osPrintf("event callid=%s address=%s", szCallId, szRemoteAddress) ; // osPrintf("event M=%s m=%s\n", MajorEventToString(major), MinorEventToString(minor)) ; } } // Filter duplicate events UtlBoolean bDuplicateEvent = FALSE ; SIPX_CALLSTATE_EVENT lastEvent ; SIPX_CALLSTATE_CAUSE lastCause ; SIPX_INTERNAL_CALLSTATE state ; if (sipxCallGetState(hCall, lastEvent, lastCause, state)) { if ((lastEvent == major) && (lastCause == minor)) { bDuplicateEvent = TRUE ; } } // Only proceed if this isn't a duplicate event and we have a valid // call handle. if (!bDuplicateEvent && hCall != 0) { // Find Line hLine = sipxLineLookupHandle(lineId.data()) ; if (0 == hLine) { // no line exists for the lineId // log it OsSysLog::add(FAC_SIPXTAPI, PRI_NOTICE, "unknown line id = %s\n", lineId.data()); } // Fill in remote address if (szRemoteAddress) { pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE) ; if (pCallData) { if (pCallData->remoteAddress) { delete pCallData->remoteAddress; } pCallData->remoteAddress = new UtlString(szRemoteAddress) ; sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } } // Report events to subscribe listeners UtlSListIterator itor(*g_pListeners) ; while ((ptr = (UtlVoidPtr*) itor()) != NULL) { CALL_LISTENER_DATA *pData = (CALL_LISTENER_DATA*) ptr->getValue() ; if (pData->pInst->pCallManager == pSrc) { pData->pCallbackProc(hCall, hLine, major, minor, pData->pUserData) ; } } UtlSListIterator eventListenerItor(*g_pEventListeners); while ((ptr = (UtlVoidPtr*) eventListenerItor()) != NULL) { EVENT_LISTENER_DATA *pData = (EVENT_LISTENER_DATA*) ptr->getValue(); if (pData->pInst->pCallManager == pSrc) { SIPX_CALLSTATE_INFO callInfo; memset((void*) &callInfo, 0, sizeof(SIPX_CALLSTATE_INFO)); callInfo.event = (SIPX_CALLSTATE_EVENT)(int)major; callInfo.cause = (SIPX_CALLSTATE_CAUSE)(int)minor; callInfo.hCall = hCall; callInfo.hLine = hLine; callInfo.hAssociatedCall = hAssociatedCall ; callInfo.szRemoteIdentity = szRemoteAssertedIdentity; callInfo.nSize = sizeof(SIPX_CALLSTATE_INFO); if (minor == CALLSTATE_AUDIO_START) { // Copy codec information into callInfo memcpy((void*)&callInfo.codecs, pEventData, sizeof(SIPX_CODEC_INFO)); } // callback signature: typedef bool (*SIPX_EVENT_CALLBACK_PROC)(SIPX_EVENT_CATEGORY category, void* pInfo, void* pUserData); pData->pCallbackProc(EVENT_CATEGORY_CALLSTATE, &callInfo, pData->pUserData); } } sipxCallSetState(hCall, (SIPX_CALLSTATE_EVENT) major, (SIPX_CALLSTATE_CAUSE) minor) ; #ifdef DEBUG_SIPXTAPI_EVENTS ReportCallback(hCall, hLine, major, minor, NULL) ; #endif // If this is a DESTROY message, free up resources after all listeners // have been notified. if (DESTROYED == major) { SIPX_CONF hConf = sipxCallGetConf(hCall) ; if (hConf != 0) { SIPX_CONF_DATA* pConfData = sipxConfLookup(hConf, SIPX_LOCK_WRITE) ; if (pConfData) { sipxRemoveCallHandleFromConf(hConf, hCall) ; sipxConfReleaseLock(pConfData, SIPX_LOCK_WRITE) ; } } sipxCallObjectFree(hCall); } } } if ((DISCONNECTED == major) && ((sipxCallGetConf(hCall) != 0) || sipxCallIsRemoveInsteadOfDropSet(hCall))) { sipxFireCallEvent(pSrc, szCallId, pSession, szRemoteAddress, DESTROYED, DESTROYED_NORMAL, pEventData) ; } }SIPXTAPI_API SIPX_RESULT sipxEventListenerAdd(const SIPX_INST hInst, SIPX_EVENT_CALLBACK_PROC pCallbackProc, void *pUserData){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxEventListenerAdd hInst=%p pCallbackProc=%p pUserData=%p", hInst, pCallbackProc, pUserData); SIPX_RESULT rc = SIPX_RESULT_INVALID_ARGS; OsLock lock(*g_pListenerLock) ; OsLock eventLock(*g_pEventListenerLock) ; OsLock lock2(*g_pLineListenerLock); if (hInst && pCallbackProc) { EVENT_LISTENER_DATA *pData = new EVENT_LISTENER_DATA; pData->pCallbackProc = pCallbackProc; pData->pUserData = pUserData; pData->pInst = (SIPX_INSTANCE_DATA*) hInst; g_pEventListeners->append(new UtlVoidPtr(pData)); rc = SIPX_RESULT_SUCCESS; } return rc;}SIPXTAPI_API SIPX_RESULT sipxEventListenerRemove(const SIPX_INST hInst, SIPX_EVENT_CALLBACK_PROC pCallbackProc, void* pUserData) { OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxEventListenerRemove hInst=%p pCallbackProc=%p pUserData=%p", hInst, pCallbackProc, pUserData); SIPX_RESULT rc = SIPX_RESULT_INVALID_ARGS ; OsLock lock(*g_pListenerLock) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -