📄 callmanager.cpp
字号:
} } return(messageProcessed);}void CallManager::requestShutdown(){ // Need to put a Mutex on the call stack UtlSListIterator iterator(callStack); CpCall* call = NULL; UtlInt* callCollectable; while(! callStack.isEmpty() && ! iterator.atLast()) { callCollectable = (UtlInt*) iterator(); if(callCollectable) { call = (CpCall*) callCollectable->getValue(); call->requestShutdown(); } } if(infocusCall) { infocusCall->requestShutdown(); } // Pass the shut down to itself OsServerTask::requestShutdown(); yield();}void CallManager::addTaoListenerToCall(CpCall* pCall){ // Check if listener is already added. for (int i = 0; i < mListenerCnt; i++) { if (mpListeners[i] && mpListeners[i]->mpListenerPtr) { pCall->addTaoListener((OsServerTask*) mpListeners[i]->mpListenerPtr); } }}void CallManager::unhold(const char* callId){ CpStringMessage unholdMessage(CP_OFF_HOLD_CALL, callId); postMessage(unholdMessage);}void CallManager::createCall(UtlString* callId, int metaEventId, int metaEventType, int numCalls, const char* callIds[], UtlBoolean assumeFocusIfNoInfocusCall){ if(callId->isNull()) { getNewCallId(callId); } OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager::createCall new Id: %s\n", callId->data()); CpMultiStringMessage callMessage(CP_CREATE_CALL, callId->data(), numCalls >= 1 ? callIds[0] : NULL, numCalls >= 2 ? callIds[1] : NULL, numCalls >= 3 ? callIds[2] : NULL, numCalls >= 4 ? callIds[3] : NULL, metaEventId, metaEventType, numCalls, assumeFocusIfNoInfocusCall); postMessage(callMessage); mnTotalOutgoingCalls++;}OsStatus CallManager::getCalls(int maxCalls, int& numCalls, UtlString callIds[]){ OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); UtlSList* addressList = new UtlSList; OsProtectedEvent* callsSet = eventMgr->alloc(); callsSet->setIntData((int) addressList); OsTime maxEventTime(CP_MAX_EVENT_WAIT_SECONDS, 0); OsStatus returnCode = OS_WAIT_TIMEOUT; CpMultiStringMessage getCallsMessage(CP_GET_CALLS, NULL, NULL, NULL, NULL, NULL, (int)callsSet); postMessage(getCallsMessage); // Wait until the call manager sets the callIDs if(callsSet->wait(0, maxEventTime) == OS_SUCCESS) { int callIndex = 0; { // scope the iterator UtlSListIterator iterator(*addressList); UtlString* callIdCollectable; callIdCollectable = (UtlString*)iterator(); returnCode = OS_SUCCESS; while (callIdCollectable) { if(callIndex >= maxCalls) { returnCode = OS_LIMIT_REACHED; break; } callIds[callIndex] = *callIdCollectable; callIndex++; callIdCollectable = (UtlString*)iterator(); } numCalls = callIndex; } // end of iterator scope#ifdef TEST_PRINT_EVENT OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager::getCalls %d calls\n", numCalls);#endif addressList->destroyAll(); delete addressList; eventMgr->release(callsSet); } else { OsSysLog::add(FAC_CP, PRI_ERR, "CallManager::getCalls TIMED OUT\n"); // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == callsSet->signal(0)) { addressList->destroyAll(); delete addressList; eventMgr->release(callsSet); } numCalls = 0; }#ifdef TEST_PRINT OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager:getCalls numCalls = %d\n ", numCalls) ;#endif return(returnCode);}PtStatus CallManager::connect(const char* callId, const char* toAddressString, const char* fromAddressString, const char* desiredCallIdString, CONTACT_ID contactId, const void* pDisplay){ UtlString toAddressUrl(toAddressString ? toAddressString : ""); UtlString fromAddressUrl(fromAddressString ? fromAddressString : ""); UtlString desiredCallId(desiredCallIdString ? desiredCallIdString : "") ; PtStatus returnCode = validateAddress(toAddressUrl); if(returnCode == PT_SUCCESS) { CpMultiStringMessage callMessage(CP_CONNECT, callId, toAddressUrl, fromAddressUrl, desiredCallId, NULL, contactId, (int)pDisplay); postMessage(callMessage); } return(returnCode);}PtStatus CallManager::consult(const char* idleTargetCallId, const char* activeOriginalCallId, const char* originalCallControllerAddress, const char* originalCallControllerTerminalId, const char* consultAddressString, UtlString& targetCallControllerAddress, UtlString& targetCallConsultAddress){ UtlString consultAddressUrl(consultAddressString ? consultAddressString : ""); PtStatus returnCode = validateAddress(consultAddressUrl); if(returnCode == PT_SUCCESS) { // There is an implied hold for all connections in // the original call holdAllTerminalConnections(activeOriginalCallId); // Not sure if we should explicitly put the consultative // call in focus or not. // For now we won't //unholdTerminalConnection(idleTargetCallId, extension.data(), NULL); // Create the consultative connection on the new call connect(idleTargetCallId, consultAddressString); //targetCallControllerAddress = extension; // temporary kludge targetCallControllerAddress = mOutboundLine; targetCallConsultAddress = consultAddressUrl; } return(returnCode);}void CallManager::drop(const char* callId){ CpMultiStringMessage callMessage(CP_DROP, callId); OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager::drop is called for call %s", callId); postMessage(callMessage);}void CallManager::sendInfo(const char* callId, const char* szContentType, const size_t nContentLength, const char* szContent){ // UtlString encodedContent; // NetBase64Codec::encode(nContentLength, (char*) pContent, encodedContent); CpMultiStringMessage infoMessage(CP_OUTGOING_INFO, UtlString(callId), UtlString(szContentType), UtlString(szContent, nContentLength)); postMessage(infoMessage);}// Cosultative transferPtStatus CallManager::transfer(const char* targetCallId, const char* originalCallId){#ifdef TEST_PRINT OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManger::transfer targetCallId=%s, originalCallId=%s\n", targetCallId, originalCallId) ;#endif PtStatus returnCode = PT_SUCCESS; // Make sure the consultative call is on hold CpMultiStringMessage allHold(CP_HOLD_ALL_TERM_CONNECTIONS, targetCallId); postMessage(allHold); // Need to get the To URL from the consultative call UtlString addresses[2]; int numConnections; getConnections(targetCallId, 2, numConnections, addresses); // It is only valid to have 2 connections (local and transfer target) // <2 suggest the target hung up. >2 suggest we are trying to transfer // a conference. if (numConnections == 2) { // Assume the first is always the local connection UtlString fromAddress; UtlString toAddress; // getToField(targetCallId, addresses[1].data(), toAddress) ; toAddress = addresses[1]; getFromField(targetCallId, addresses[1].data(), fromAddress) ; // Construct the replaces header info // SIP alert: this is SIP specific and should not be in CallManager // Add the Replaces header info to the consultative URL UtlString replacesField; SipMessage::buildReplacesField(replacesField, targetCallId, fromAddress.data(), toAddress.data()); Url transferTargetUrl(toAddress); transferTargetUrl.removeFieldParameters() ; transferTargetUrl.setHeaderParameter(SIP_REPLACES_FIELD, replacesField.data()); UtlString transferTargetUrlString; transferTargetUrl.toString(transferTargetUrlString);#ifdef TEST_PRINT OsSysLog::add(FAC_CP, PRI_DEBUG, "CallManager::transfer transferTargetUrlString=%s, targetCallId=%s\n", transferTargetUrlString.data(), targetCallId);#endif // Tell the original call to complete the // consultative transfer CpMultiStringMessage consultTransfer(CP_CONSULT_TRANSFER, originalCallId, transferTargetUrlString.data(), targetCallId); postMessage(consultTransfer); } else { returnCode = PT_INVALID_STATE; } return(returnCode);}// Transfer an individual participant from one end point to another using // REFER w/replaces.PtStatus CallManager::transfer(const char* sourceCallId, const char* sourceAddress, const char* targetCallId, const char* targetAddress, bool remoteHoldBeforeTransfer) { PtStatus returnCode = PT_SUCCESS; // Place connections on hold if (remoteHoldBeforeTransfer) { CpMultiStringMessage sourceHold(CP_HOLD_TERM_CONNECTION, sourceCallId, sourceAddress); postMessage(sourceHold); CpMultiStringMessage targetHold(CP_HOLD_TERM_CONNECTION, targetCallId, targetAddress); postMessage(targetHold); } // Construct the replaces header info // SIP alert: this is SIP specific and should not be in CallManager UtlString fromAddress; getFromField(targetCallId, targetAddress, fromAddress) ; // Add the Replaces header info to the consultative URL UtlString replacesField; SipMessage::buildReplacesField(replacesField, targetCallId, fromAddress, targetAddress); Url transferTargetUrl(targetAddress); transferTargetUrl.removeFieldParameters() ; transferTargetUrl.setHeaderParameter(SIP_REPLACES_FIELD, replacesField.data()); UtlString transferTargetUrlString; transferTargetUrl.toString(transferTargetUrlString); // Tell the original call to complete the consultative transfer CpMultiStringMessage consultTransfer(CP_CONSULT_TRANSFER_ADDRESS, sourceCallId, sourceAddress, targetCallId, targetAddress, transferTargetUrlString, NULL, /* int2 */ remoteHoldBeforeTransfer ); postMessage(consultTransfer); return returnCode ;}// Split szSourceAddress from szSourceCallId and join it to the specified // target call id. The source call/connection MUST be on hold prior// to initiating the split/join.PtStatus CallManager::split(const char* szSourceCallId, const char* szSourceAddress, const char* szTargetCallId) { PtStatus status = PT_FAILED ; OsProtectEventMgr* eventMgr = OsProtectEventMgr::getEventMgr(); OsProtectedEvent* splitSuccess = eventMgr->alloc(); OsTime maxEventTime(CP_MAX_EVENT_WAIT_SECONDS, 0); CpMultiStringMessage splitMessage(CP_SPLIT_CONNECTION, szSourceCallId, szSourceAddress, szTargetCallId, NULL, NULL, (int) splitSuccess); postMessage(splitMessage); // Wait until the call sets the number of connections if(splitSuccess->wait(0, maxEventTime) == OS_SUCCESS) { int success ; splitSuccess->getEventData(success); eventMgr->release(splitSuccess); if (success)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -