📄 callmanager.cpp
字号:
{ // Add the listener to it. call->addTaoListener(pListener, callId, ConnectId, mask); rc = OS_SUCCESS; } callCollectable = (UtlInt*)iterator(); } } } rc = addThisListener(pListener, callId, mask); return rc;}OsStatus CallManager::addThisListener(OsServerTask* pListener, char* callId, int mask){ // Check if listener is already added. for (int i = 0; i < mListenerCnt; i++) { // Check whether this listener (defined by PListener and callId) is // already in mpListners[]. if (mpListeners[i] && mpListeners[i]->mpListenerPtr == (int) pListener && (!callId || mpListeners[i]->mName.compareTo(callId) == 0)) { // If so, increment the count for this listener. mpListeners[i]->mRef++; return OS_SUCCESS; } } // If there is no room for more listeners in mpListeners[]: if (mListenerCnt == mMaxNumListeners) { // Reallocate a larger mpListeners[]. mMaxNumListeners += 20; mpListeners = (TaoListenerDb **)realloc(mpListeners,sizeof(TaoListenerDb *)*mMaxNumListeners); for (int loop = mListenerCnt; loop < mMaxNumListeners; loop++) { mpListeners[loop] = 0 ; } } // Construct a new TaoListenerDb to hold the information about the new // listener. TaoListenerDb *pListenerDb = new TaoListenerDb(); // Insert pListener and callId. if (callId) { pListenerDb->mName.append(callId); } pListenerDb->mpListenerPtr = (int) pListener; pListenerDb->mRef = 1; // Add it to mpListeners[]. mpListeners[mListenerCnt++] = pListenerDb; return OS_SUCCESS;}UtlBoolean CallManager::handleMessage(OsMsg& eventMessage){ int msgType = eventMessage.getMsgType(); int msgSubType = eventMessage.getMsgSubType(); UtlBoolean messageProcessed = TRUE; UtlString holdCallId; UtlBoolean messageConsumed = FALSE; CpMediaInterface* pMediaInterface = NULL; switch(msgType) { case OsMsg::PHONE_APP: { char eventDescription[100]; UtlString subTypeString; getEventSubTypeString((enum CpCallManager::EventSubTypes)msgSubType, subTypeString); sprintf(eventDescription, "%s (%d)", subTypeString.data(), msgSubType); addHistoryEvent(eventDescription); } switch(msgSubType) { case CP_MGCP_MESSAGE: case CP_MGCP_CAPS_MESSAGE: case CP_SIP_MESSAGE: { OsWriteLock lock(mCallListMutex); CpCall* handlingCall = NULL; handlingCall = findHandlingCall(eventMessage); // This message does not belong to any of the calls // If this is an invite for a new call // Currently only one call can exist if(!handlingCall) { UtlString callId; if(msgSubType == CP_SIP_MESSAGE) { const SipMessage* sipMsg = ((SipMessageEvent&)eventMessage).getMessage(); if(sipMsg) { UtlString method; sipMsg->getRequestMethod(&method); if(method == SIP_REFER_METHOD) { // If the message is a REFER, generate a new call id for it. // :TODO: Explain why. getNewCallId(&callId); } else { // Otherwise, get the call id from the message. sipMsg->getCallIdField(&callId); } OsSysLog::add(FAC_CP, PRI_DEBUG, "Message callid: %s\n", callId.data()); } ///////////////// UtlBoolean isUserValid = FALSE; UtlString method; sipMsg->getRequestMethod(&method); if(mpLineMgrTask && mIsRequredUserIdMatch && method.compareTo(SIP_INVITE_METHOD,UtlString::ignoreCase) == 0) { isUserValid = mpLineMgrTask->isUserIdDefined(sipMsg); if( !isUserValid) { //no such user - return 404 SipMessage noSuchUserResponse; noSuchUserResponse.setResponseData(sipMsg, SIP_NOT_FOUND_CODE, SIP_NOT_FOUND_TEXT); sipUserAgent->send(noSuchUserResponse); } } else { isUserValid = TRUE; } //////////////// if( isUserValid && CpPeerCall::shouldCreateCall( *sipUserAgent, eventMessage, *mpCodecFactory)) { // If this call would exceed the limit that we have been // given for calls to handle simultaneously, // send a BUSY_HERE SIP (486) message back to the sender. if(getCallStackSize() >= mMaxCalls) { if( (sipMsg->isResponse() == FALSE) && (method.compareTo(SIP_ACK_METHOD,UtlString::ignoreCase) != 0) ) { SipMessage busyHereResponse; busyHereResponse.setInviteBusyData(sipMsg); sipUserAgent->send(busyHereResponse); } } else { // Create a new SIP call int numCodecs; SdpCodec** codecArray = NULL; getCodecs(numCodecs, codecArray); OsSysLog::add(FAC_CP, PRI_DEBUG, "Creating new call for incoming SIP message\n"); UtlString publicAddress; int publicPort; //always use sipUserAgent public address, not the mPublicAddress of this call manager. sipUserAgent->getViaInfo(OsSocket::UDP,publicAddress,publicPort); UtlString localAddress; int port; char szAdapter[256]; localAddress = sipMsg->getLocalIp(); getContactAdapterName(szAdapter, localAddress.data()); CONTACT_ADDRESS contact; sipUserAgent->getContactDb().getRecordForAdapter(contact, szAdapter, LOCAL_CONTACT); port = contact.iPort; pMediaInterface = mpMediaFactory->createMediaInterface( NULL, localAddress, numCodecs, codecArray, mLocale.data(), mExpeditedIpTos, mStunServer, mStunOptions, mStunKeepAlivePeriodSecs); int inviteExpireSeconds; if (sipMsg->getExpiresField(&inviteExpireSeconds) && inviteExpireSeconds > 0) { if (inviteExpireSeconds > mInviteExpireSeconds) inviteExpireSeconds = mInviteExpireSeconds; } else inviteExpireSeconds = mInviteExpireSeconds; handlingCall = new CpPeerCall(mIsEarlyMediaFor180, this, pMediaInterface, aquireCallIndex(), callId.data(), sipUserAgent, mSipSessionReinviteTimer, mOutboundLine.data(), mHoldType, mOfferedTimeOut, mLineAvailableBehavior, mForwardUnconditional.data(), mLineBusyBehavior, mSipForwardOnBusy.data(), mNoAnswerTimeout, mForwardOnNoAnswer.data(), inviteExpireSeconds); for (int i = 0; i < numCodecs; i++) { delete codecArray[i]; } delete[] codecArray; } } } // If we created a new call if(handlingCall) { handlingCall->start(); addTaoListenerToCall(handlingCall); // addToneListener(callId.data(), 0); //if(infocusCall == NULL) //{ // infocusCall = handlingCall; // infocusCall->inFocus(); //} //else // { // Push the new call on the stack pushCall(handlingCall); // } //handlingCall->startMetaEvent( getNewMetaEventId(), // PtEvent::META_CALL_STARTING, // 0, // 0); } } // Pass on the message if there is a call to process if(handlingCall) { handlingCall->postMessage(eventMessage); messageProcessed = TRUE; } } break; case CP_CALL_EXITED: { CpCall* call; ((CpIntMessage&)eventMessage).getIntData((int&) call); OsSysLog::add(FAC_CP, PRI_DEBUG, "Call EXITING message received: %p infofocus: %p\r\n", (void*)call, (void*) infocusCall); call->stopMetaEvent(); mCallListMutex.acquireWrite() ; releaseCallIndex(call->getCallIndex()); if(infocusCall == call) { // The infocus call is not in the mCallList -- no need to // remove, but we should tell the call that it is not // longer in focus. call->outOfFocus(); } else { call = removeCall(call); } mCallListMutex.releaseWrite() ; if(call) { delete call; } messageProcessed = TRUE; break; } case CP_DIAL_STRING: { OsWriteLock lock(mCallListMutex); if(infocusCall && dialing) { //OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager::processMessage posting dial string to infocus call\n"); ((CpMultiStringMessage&)eventMessage).getString1Data(mDialString) ; infocusCall->postMessage(eventMessage); } dialing = FALSE; messageProcessed = TRUE; break; } case CP_YIELD_FOCUS: { CpCall* call; ((CpIntMessage&)eventMessage).getIntData((int&) call); OsSysLog::add(FAC_CP, PRI_DEBUG, "Call YIELD FOCUS message received: %p\r\n", (void*)call); OsSysLog::add(FAC_CP, PRI_DEBUG, "infocusCall: %p\r\n", infocusCall); { OsWriteLock lock(mCallListMutex); if(infocusCall == call) { infocusCall->outOfFocus(); pushCall(infocusCall); infocusCall = NULL; } } messageConsumed = TRUE; messageProcessed = TRUE; break; } case CP_GET_FOCUS: { CpCall* call; ((CpIntMessage&)eventMessage).getIntData((int&) call); OsSysLog::add(FAC_CP, PRI_DEBUG, "Call GET FOCUS message received: %p\r\n", (void*)call); OsSysLog::add(FAC_CP, PRI_DEBUG, "infocusCall: %p\r\n", infocusCall); { OsWriteLock lock(mCallListMutex); if(call && infocusCall != call) { changeCallFocus(call); } } messageConsumed = TRUE; messageProcessed = TRUE; break; } case CP_CREATE_CALL: { UtlString callId; int metaEventId = ((CpMultiStringMessage&)eventMessage).getInt1Data(); int metaEventType = ((CpMultiStringMessage&)eventMessage).getInt2Data(); int numCalls = ((CpMultiStringMessage&)eventMessage).getInt3Data(); UtlBoolean assumeFocusIfNoInfocusCall = ((CpMultiStringMessage&)eventMessage).getInt4Data(); const char* metaEventCallIds[4]; UtlString metaCallId0; UtlString metaCallId1; UtlString metaCallId2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -