📄 cppeercall.cpp
字号:
while ((connection = (Connection*) iterator())) { // Do the transfer operation on each connection in this call UtlBoolean isOk = connection->originalCallTransfer(transferTargetAddress, NULL, targetCallId.data(), remoteHoldBeforeTransfer ); if (!isOk) { UtlString targetCallId; getTargetCallId(targetCallId); UtlString remoteAddress; connection->getRemoteAddress(&remoteAddress); UtlString responseText; connection->getResponseText(responseText); postTaoListenerMessage(connection->getResponseCode(), responseText, PtEvent::CONNECTION_FAILED, CONNECTION_STATE, PtEvent::CAUSE_TRANSFER, connection->isRemoteCallee(), remoteAddress, 1, targetCallId); /** SIPXTAPI: TBD **/#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::CP_BLIND_TRANSFER posting CONNECTION_FAILED to call: %s\n", mName.data(), targetCallId.data());#endif } else { // Send a message to the target call for each transfered // connection UtlString originalCallId; UtlString connectionAddress; connection->getCallId(&originalCallId); connection->getRemoteAddress(&connectionAddress);#ifdef TEST_PRINT osPrintf("%s-2 party transfer on connection: %s original call: %s target call: %s\n", mName.data(), connectionAddress.data(), originalCallId.data(), targetCallId.data());#endif CpMultiStringMessage transferConnect(CallManager::CP_TRANSFER_CONNECTION, targetCallId.data(), transferTargetAddress.data(), originalCallId.data(), connectionAddress.data(), NULL, metaEventId); mpManager->postMessage(transferConnect); } } } return TRUE;}// Handles the processing of a CallManager::CP_CONSULT_TRANSFER_ADDRESS// message.UtlBoolean CpPeerCall::handleTransferAddress(OsMsg* pEventMessage){ CpMultiStringMessage* pMessage = (CpMultiStringMessage*) pEventMessage ; int msgSubType = pEventMessage->getMsgSubType() ; UtlString sourceCallId ; UtlString sourceAddress ; UtlString targetCallId ; UtlString targetAddress ; UtlString targetUrl ; // Parse parameters pMessage->getString1Data(sourceCallId) ; pMessage->getString2Data(sourceAddress) ; pMessage->getString3Data(targetCallId) ; pMessage->getString4Data(targetAddress) ; pMessage->getString5Data(targetUrl) ; Connection* pConnection = findHandlingConnection(sourceAddress); if (pConnection) { UtlBoolean bRC = pConnection->originalCallTransfer(targetUrl, sourceAddress, targetCallId) ; if (!bRC) { } } return TRUE;}// Handles the processing of a CallManager::CP_TRANSFER_CONNECTION messageUtlBoolean CpPeerCall::handleTransferConnection(OsMsg* pEventMessage){ UtlString originalCallId; UtlString currentOriginalCallId; getOriginalCallId(currentOriginalCallId); UtlString transferTargetAddress; UtlString connectionAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(transferTargetAddress); ((CpMultiStringMessage*)pEventMessage)->getString3Data(originalCallId); ((CpMultiStringMessage*)pEventMessage)->getString4Data(connectionAddress);#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::CP_TRANSFER_CONNECTION target address: %s original call: %s target connection address: %s callType: %d originalCallId: %s\n", mName.data(), transferTargetAddress.data(), originalCallId.data(), connectionAddress.data(), getCallType(), originalCallId.data());#endif // If it is legal for this call to be a transfer target if(getCallType() == CP_NORMAL_CALL || (getCallType() == CP_TRANSFER_CONTROLLER_TARGET_CALL && currentOriginalCallId.compareTo(originalCallId) == 0)) { // Set the original call id so that we can send messages // back if necessary. if(getCallType() == CP_NORMAL_CALL) { setOriginalCallId(originalCallId.data()); setCallType(CP_TRANSFER_CONTROLLER_TARGET_CALL); } // Find the connection // Currently do not need to lock as we should not get // a connection back and if we do we do nothing with it. //OsReadLock lock(mConnectionMutex); Connection* connection = findHandlingConnection(connectionAddress); // The connection does not exist, for now we can assume // this is a blind transfer. Create a ghost connection // and put it in the offering state if(! connection) {#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::CP_TRANSFER_CONNECTION creating ghost connection\n", mName.data());#endif UtlString thisCallId; getCallId(thisCallId); mLocalConnectionState = PtEvent::CONNECTION_ESTABLISHED; mLocalTermConnectionState = PtTerminalConnection::TALKING; connection = new CpGhostConnection(mpManager, this, thisCallId.data()); addConnection(connection); connection->targetCallBlindTransfer(connectionAddress, NULL); addToneListenersToConnection(connection) ; } else {#ifdef TEST_PRINT // I think this is bad osPrintf("%s-CpPeerCall::CP_TRANSFER_CONNECTION connection already exists\n", mName.data());#endif } } /* * WARNING: We should creating another connection for the TARGET address. * We are not doing this now, because we don't have any code that * steps through state progressions. * * TODO: CODE ME */ return TRUE ;}// Handles the processing of a CallManager::CP_TRANSFEREE_CONNECTION messageUtlBoolean CpPeerCall::handleTransfereeConnection(OsMsg* pEventMessage){ // Message sent to target call on transferee UtlString referTo; UtlString referredBy; UtlString originalCallId; UtlString currentOriginalCallId; getOriginalCallId(currentOriginalCallId); UtlString originalConnectionAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(referTo); ((CpMultiStringMessage*)pEventMessage)->getString3Data(referredBy); ((CpMultiStringMessage*)pEventMessage)->getString4Data(originalCallId); ((CpMultiStringMessage*)pEventMessage)->getString5Data(originalConnectionAddress);#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::CP_TRANSFEREE_CONNECTION referTo: %s referredBy: \"%s\" originalCallId: %s originalConnectionAddress: %s\n", mName.data(), referTo.data(), referredBy.data(), originalCallId.data(), originalConnectionAddress.data());#endif if(getCallType() == CP_NORMAL_CALL || (getCallType() == CP_TRANSFEREE_TARGET_CALL && currentOriginalCallId.compareTo(originalCallId) == 0)) { if(getCallType() == CP_NORMAL_CALL) setOriginalCallId(originalCallId); // Do not need to lock as connection is never touched // and addConnection does its own locking //OsReadLock lock(mConnectionMutex); UtlString cleanReferTo; Url referToUrl(referTo); referToUrl.removeHeaderParameters(); referToUrl.toString(cleanReferTo); Connection* connection = findHandlingConnection(cleanReferTo); if(!connection) { // Create a new connection on this call to connect to the // transfer target.#ifdef TEST_PRINT osPrintf("%s-CpPeerCall:CP_TRANSFEREE_CONNECTION creating connection via addParty\n", mName.data());#endif addParty(referTo, referredBy, originalConnectionAddress, NULL); // Note: The connection is added to the call in addParty }#ifdef TEST_PRINT // I do not think this is good else { osPrintf("%s-CpPeerCall::CP_TRANSFEREE_CONNECTION connection already exists\n", mName.data()); }#endif }#ifdef TEST_PRINT else { osPrintf("%s-CpPeerCall::CP_TRANSFEREE_CONNECTION callType: %d \n", mName.data(), getCallType()); }#endif return TRUE ;}// Handles the processing of a CallManager::CP_SIP_MESSAGE messageUtlBoolean CpPeerCall::handleSipMessage(OsMsg* pEventMessage){ UtlBoolean bAddedConnection = FALSE ; addHistoryEvent("CP_SIP_MESSAGE (1)"); // There are of course small windows between: // findHandlingConnection, addConnection and the // read lock taken below. But you cannot have a // read or write lock nested in a write lock. Connection* connection = findHandlingConnection(*pEventMessage); UtlString name = getName(); if(connection == NULL) { if (SipConnection::shouldCreateConnection(*sipUserAgent, *pEventMessage)) {#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::handleSipMessage - connection NULL, shouldCreateConnection TRUE msgType %d msgSubType %d \n", name.data(), pEventMessage->getMsgType(), pEventMessage->getMsgSubType());#endif connection = new SipConnection("", // Get local address from message mIsEarlyMediaFor180, mpManager, this, mpMediaInterface, //mpCallUiContext, sipUserAgent, offeringDelay, mSipSessionReinviteTimer, lineAvailableBehavior, forwardUnconditional.data(), lineBusyBehavior, forwardOnBusy.data()); addConnection(connection); bAddedConnection = TRUE ; mDtmfEnabled = TRUE ; } else { SipConnection::processNewFinalMessage(sipUserAgent, pEventMessage);#ifdef TEST_PRINT osPrintf("%s CpPeerCall::handleSipMessage - processing new final response to INVITE\n", name.data());#endif } }#ifdef TEST_PRINT osPrintf("%s CpPeerCall::handleSipMessage - connection %d msgType %d msgSubType %d\n", name.data(), (int)connection, pEventMessage->getMsgType(), pEventMessage->getMsgSubType());#endif if(connection) { OsReadLock lock(mConnectionMutex); int previousConnectionState = connection->getState(); //PtTerminalConnection::TerminalConnectionState prevTermConState; //int gotPrevTermConState = getUiTerminalConnectionState(prevTermConState); // if (previousConnectionState == Connection::CONNECTION_IDLE) // { // startMetaEvent( mpManager->getNewMetaEventId(), // PtEvent::META_CALL_STARTING, // 0, // 0); // } connection->processMessage(*pEventMessage, mCallInFocus, !mDtmfEnabled); // mDtmfEnabled is the same as offHook state //mNumCodecs, mpaCodecArray); int currentConnectionState = connection->getState(); if ( ((previousConnectionState != currentConnectionState) || (getCallState() == PtCall::IDLE)) && ((currentConnectionState == Connection::CONNECTION_OFFERING) || (currentConnectionState == Connection::CONNECTION_ALERTING)) ) { UtlString responseText; connection->getResponseText(responseText); setCallState(connection->getResponseCode(), responseText, PtCall::ACTIVE); /** SIPXTAPI: TBD **/ } if (previousConnectionState == Connection::CONNECTION_IDLE && currentConnectionState == Connection::CONNECTION_OFFERING) { stopMetaEvent(connection->isRemoteCallee()); } // If this call does not have a callId set it if(!isCallIdSet() && (currentConnectionState != Connection::CONNECTION_FAILED || currentConnectionState != Connection::CONNECTION_DISCONNECTED || currentConnectionState != Connection::CONNECTION_IDLE)) { UtlString callId; connection->getCallId(&callId); setCallId(callId.data()); } if (bAddedConnection) addToneListenersToConnection(connection) ; } // End if we created a new connection or used and existing one // Check if call is dead and drop it if it is dropIfDead(); return TRUE ;}// Handles the processing of a CallManager::CP_DROP_CONNECTION messageUtlBoolean CpPeerCall::handleDropConnection(OsMsg* pEventMessage){ { OsReadLock lock(mConnectionMutex); UtlString connectionAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(connectionAddress); Connection* connection = findHandlingConnection(connectionAddress); if(connection) { // do not fire the taip event if it is a ghost connection CpGhostConnection* pGhost = NULL; pGhost = dynamic_cast<CpGhostConnection*>(connection); if (!pGhost) { connection->fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL) ; } connection->hangUp(); } } // Check if call is dead and drop it if it is dropIfDead(); return TRUE;}// Handles the processing of a CallManager::CP_FORCE_DROP_CONNECTION messageUtlBoolean CpPeerCall::handleForceDropConnection(OsMsg* pEventMessage){ { OsReadLock lock(mConnectionMutex); UtlString connectionAddress; ((CpMultiStringMessage*)pEventMessage)->getString2Data(connectionAddress); Connection* connection = findHandlingConnection(connectionAddress); if(connection) {#ifdef TEST_PRINT osPrintf("%s-CpPeerCall::CP_FORCE_DROP_CONNECTION Found connection\n", mName.data());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -