From e075f7c4de414f5bb9db7366aed9e93ce52373bc Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Mon, 13 Oct 2008 12:33:59 +0000 Subject: [PATCH] Puts existing calls on hold when a new call starts. --- .../impl/protocol/AccountManagerImpl.java | 22 +- .../protocol/ProtocolProviderActivator.java | 15 +- .../protocol/SingleCallInProgressPolicy.java | 374 ++++++++++++++++++ .../OperationSetBasicTelephonySipImpl.java | 214 ++++------ 4 files changed, 472 insertions(+), 153 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/protocol/SingleCallInProgressPolicy.java diff --git a/src/net/java/sip/communicator/impl/protocol/AccountManagerImpl.java b/src/net/java/sip/communicator/impl/protocol/AccountManagerImpl.java index 0c3d6e8bb..51315d428 100644 --- a/src/net/java/sip/communicator/impl/protocol/AccountManagerImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/AccountManagerImpl.java @@ -461,27 +461,25 @@ private void runInLoadStoredAccountsThread() * implementation tracks the registrations of * ProtocolProviderFactory services in order to queue them for * loading their stored accounts. - * + * * @param serviceEvent the ServiceEvent containing the event * data */ private void serviceChanged(ServiceEvent serviceEvent) { - Object service = - bundleContext.getService(serviceEvent.getServiceReference()); - - if (service instanceof ProtocolProviderFactory) + switch (serviceEvent.getType()) { - ProtocolProviderFactory factory = (ProtocolProviderFactory) service; + case ServiceEvent.REGISTERED: + Object service = + bundleContext.getService(serviceEvent.getServiceReference()); - switch (serviceEvent.getType()) + if (service instanceof ProtocolProviderFactory) { - case ServiceEvent.REGISTERED: - protocolProviderFactoryRegistered(factory); - break; - default: - break; + protocolProviderFactoryRegistered((ProtocolProviderFactory) service); } + break; + default: + break; } } diff --git a/src/net/java/sip/communicator/impl/protocol/ProtocolProviderActivator.java b/src/net/java/sip/communicator/impl/protocol/ProtocolProviderActivator.java index 288e3064b..a3beb8993 100644 --- a/src/net/java/sip/communicator/impl/protocol/ProtocolProviderActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/ProtocolProviderActivator.java @@ -8,19 +8,26 @@ import org.osgi.framework.*; -import net.java.sip.communicator.impl.protocol.*; import net.java.sip.communicator.service.protocol.*; +/** + * @author Lubomir Marinov + */ public class ProtocolProviderActivator implements BundleActivator { private ServiceRegistration accountManagerServiceRegistration; + private SingleCallInProgressPolicy singleCallInProgressPolicy; + public void start(BundleContext bundleContext) throws Exception { accountManagerServiceRegistration = bundleContext.registerService(AccountManager.class.getName(), new AccountManagerImpl(bundleContext), null); + + singleCallInProgressPolicy = + new SingleCallInProgressPolicy(bundleContext); } public void stop(BundleContext bundleContext) throws Exception @@ -30,5 +37,11 @@ public void stop(BundleContext bundleContext) throws Exception accountManagerServiceRegistration.unregister(); accountManagerServiceRegistration = null; } + + if (singleCallInProgressPolicy != null) + { + singleCallInProgressPolicy.dispose(); + singleCallInProgressPolicy = null; + } } } diff --git a/src/net/java/sip/communicator/impl/protocol/SingleCallInProgressPolicy.java b/src/net/java/sip/communicator/impl/protocol/SingleCallInProgressPolicy.java new file mode 100644 index 000000000..5ce3c8ec9 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/SingleCallInProgressPolicy.java @@ -0,0 +1,374 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol; + +import java.util.*; + +import org.osgi.framework.*; + +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +/** + * Imposes the policy to have one call in progress i.e. to put existing calls on + * hold when a new call enters in progress. + * + * @author Lubomir Marinov + */ +public class SingleCallInProgressPolicy +{ + + /** + * Implements the listeners interfaces used by this policy. + */ + private class SingleCallInProgressPolicyListener + implements CallChangeListener, CallListener, ServiceListener + { + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event.CallListener + * #callEnded(net.java.sip.communicator.service.protocol.event + * .CallEvent) + */ + public void callEnded(CallEvent callEvent) + { + SingleCallInProgressPolicy.this.handleCallEvent( + CallEvent.CALL_ENDED, callEvent); + } + + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event + * .CallChangeListener#callParticipantAdded(net.java.sip.communicator + * .service.protocol.event.CallParticipantEvent) + */ + public void callParticipantAdded( + CallParticipantEvent callParticipantEvent) + { + + /* + * Not of interest, just implementing CallChangeListener in which + * only #callStateChanged(CallChangeEvent) is of interest. + */ + } + + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event + * .CallChangeListener#callParticipantRemoved(net.java.sip.communicator + * .service.protocol.event.CallParticipantEvent) + */ + public void callParticipantRemoved( + CallParticipantEvent callParticipantEvent) + { + + /* + * Not of interest, just implementing CallChangeListener in which + * only #callStateChanged(CallChangeEvent) is of interest. + */ + } + + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event + * .CallChangeListener#callStateChanged(net.java.sip.communicator + * .service.protocol.event.CallChangeEvent) + */ + public void callStateChanged(CallChangeEvent callChangeEvent) + { + SingleCallInProgressPolicy.this.callStateChanged(callChangeEvent); + } + + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event.CallListener + * #incomingCallReceived(net.java.sip.communicator.service.protocol + * .event.CallEvent) + */ + public void incomingCallReceived(CallEvent callEvent) + { + SingleCallInProgressPolicy.this.handleCallEvent( + CallEvent.CALL_RECEIVED, callEvent); + } + + /* + * (non-Javadoc) + * + * @see net.java.sip.communicator.service.protocol.event.CallListener + * #outgoingCallCreated(net.java.sip.communicator.service.protocol + * .event.CallEvent) + */ + public void outgoingCallCreated(CallEvent callEvent) + { + SingleCallInProgressPolicy.this.handleCallEvent( + CallEvent.CALL_INITIATED, callEvent); + } + + public void serviceChanged(ServiceEvent serviceEvent) + { + SingleCallInProgressPolicy.this.serviceChanged(serviceEvent); + } + } + + private static final Logger logger = + Logger.getLogger(SingleCallInProgressPolicy.class); + + /** + * The BundleContext to the Calls of which this policy applies. + */ + private final BundleContext bundleContext; + + /** + * The Calls this policy manages i.e. put on hold when one of + * them enters in progress. + */ + private final List calls = new ArrayList(); + + /** + * The listener utilized by this policty to discover new Call + * and track their in-progress state. + */ + private final SingleCallInProgressPolicyListener listener = + new SingleCallInProgressPolicyListener(); + + /** + * Initializes a new SingleCallInProgressPolicy instance which + * will apply to the Calls of a specific + * BundleContext. + */ + public SingleCallInProgressPolicy(BundleContext bundleContext) + { + this.bundleContext = bundleContext; + + this.bundleContext.addServiceListener(listener); + } + + /** + * Registers a specific Call with this policy in order to have + * the rules of the latter apply to the former. + * + * @param call the Call to register with this policy in order + * to have the rules of the latter apply to the former + */ + private void addCallListener(Call call) + { + synchronized (calls) + { + if (!calls.contains(call)) + { + CallState callState = call.getCallState(); + + if ((callState != null) + && !callState.equals(CallState.CALL_ENDED)) + { + calls.add(call); + } + } + } + + call.addCallChangeListener(listener); + } + + /** + * Registers a specific OperationSetBasicTelephony with this + * policy in order to have the rules of the latter apply to the + * Calls created by the former. + * + * @param telephony the OperationSetBasicTelephony to register + * with this policy in order to have the rules of the latter + * apply to the Calls created by the former + */ + private void addOperationSetBasicTelephonyListener( + OperationSetBasicTelephony telephony) + { + telephony.addCallListener(listener); + } + + /** + * Handles changes in the state of a Call this policy applies + * to. + * + * @param callChangeEvent a CallChangeEvent value which + * describes the Call and the change in its state + */ + private void callStateChanged(CallChangeEvent callChangeEvent) + { + Call call = callChangeEvent.getSourceCall(); + + if (CallState.CALL_IN_PROGRESS.equals(call.getCallState()) + && CallState.CALL_INITIALIZATION.equals(callChangeEvent + .getOldValue())) + { + synchronized (calls) + { + for (Iterator callIter = calls.iterator(); callIter + .hasNext();) + { + Call otherCall = callIter.next(); + + if (!call.equals(otherCall) + && CallState.CALL_IN_PROGRESS.equals(otherCall + .getCallState())) + { + putOnHold(otherCall); + } + } + } + } + } + + /** + * Performs end-of-life cleanup associated with this instance e.g. removes + * added listeners. + */ + public void dispose() + { + bundleContext.removeServiceListener(listener); + } + + /** + * Handles the start and end of the Calls this policy applies + * to. + * + * @param type one of {@link CallEvent#CALL_ENDED}, + * {@link CallEvent#CALL_INITIATED} and + * {@link CallEvent#CALL_RECEIVED} which described the type of + * the event to be handled + * @param callEvent a CallEvent value which describes the + * change and the Call associated with it + */ + private void handleCallEvent(int type, CallEvent callEvent) + { + Call call = callEvent.getSourceCall(); + + switch (type) + { + case CallEvent.CALL_ENDED: + removeCallListener(call); + break; + + case CallEvent.CALL_INITIATED: + case CallEvent.CALL_RECEIVED: + addCallListener(call); + break; + } + } + + /** + * Puts the CallParticipants of a specific Call + * on hold. + * + * @param call the Call the CallParticipants of + * which are to be put on hold. + */ + private void putOnHold(Call call) + { + OperationSetBasicTelephony telephony = + (OperationSetBasicTelephony) call.getProtocolProvider() + .getOperationSet(OperationSetBasicTelephony.class); + + if (telephony != null) + { + for (Iterator participantIter = + call.getCallParticipants(); participantIter.hasNext();) + { + CallParticipant participant = participantIter.next(); + CallParticipantState participantState = participant.getState(); + + if (!CallParticipantState.DISCONNECTED.equals(participantState) + && !CallParticipantState.FAILED.equals(participantState) + && !CallParticipantState.isOnHold(participantState)) + { + try + { + telephony.putOnHold(participant); + } + catch (OperationFailedException ex) + { + logger.error("Failed to put " + participant + + " on hold.", ex); + } + } + } + } + } + + /** + * Unregisters a specific Call from this policy in order to + * have the rules of the latter no longer applied to the former. + * + * @param call the Call to unregister from this policy in order + * to have the rules of the latter no longer apply to the former + */ + private void removeCallListener(Call call) + { + call.removeCallChangeListener(listener); + + synchronized (calls) + { + calls.remove(call); + } + } + + /** + * Unregisters a specific OperationSetBasicTelephony from this + * policy in order to have the rules of the latter no longer apply to the + * Calls created by the former. + * + * @param telephony the OperationSetBasicTelephony to + * unregister from this policy in order to have the rules of the + * latter apply to the Calls created by the former + */ + private void removeOperationSetBasicTelephonyListener( + OperationSetBasicTelephony telephony) + { + telephony.removeCallListener(listener); + } + + /** + * Handles the registering and unregistering of + * OperationSetBasicTelephony instances in order to apply or + * unapply the rules of this policy to them. + * + * @param serviceEvent a ServiceEvent value which described + * a change in a OSGi service and which is to be examined for the + * registering or unregistering of a + * ProtocolProviderService and thus a + * OperationSetBasicTelephony + */ + private void serviceChanged(ServiceEvent serviceEvent) + { + Object service = + bundleContext.getService(serviceEvent.getServiceReference()); + + if (service instanceof ProtocolProviderService) + { + OperationSetBasicTelephony telephony = + (OperationSetBasicTelephony) ((ProtocolProviderService) service) + .getOperationSet(OperationSetBasicTelephony.class); + + if (telephony != null) + { + switch (serviceEvent.getType()) + { + case ServiceEvent.REGISTERED: + addOperationSetBasicTelephonyListener(telephony); + break; + case ServiceEvent.UNREGISTERING: + removeOperationSetBasicTelephonyListener(telephony); + break; + } + } + } + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java index 994138847..5b5f6a89c 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java @@ -49,7 +49,7 @@ public class OperationSetBasicTelephonySipImpl /** * Contains references for all currently active (non ended) calls. */ - private ActiveCallsRepository activeCallsRepository = + private final ActiveCallsRepository activeCallsRepository = new ActiveCallsRepository(this); /** @@ -188,12 +188,9 @@ private synchronized CallSipImpl createOutgoingCall(Address calleeAddress, catch (ParseException ex) { // Shouldn't happen - logger.error( - "Failed to create a content type header for the INVITE " - + "request", ex); - throw new OperationFailedException( - "Failed to create a content type header for the INVITE " - + "request", OperationFailedException.INTERNAL_ERROR, ex); + throwOperationFailedException( + "Failed to create a content type header for the INVITE request", + OperationFailedException.INTERNAL_ERROR, ex); } // check whether there's a cached authorization header for this @@ -220,7 +217,7 @@ private synchronized CallSipImpl createOutgoingCall(Address calleeAddress, } // Transaction - ClientTransaction inviteTransaction; + ClientTransaction inviteTransaction = null; SipProvider jainSipProvider = protocolProvider.getDefaultJainSipProvider(); try @@ -229,9 +226,7 @@ private synchronized CallSipImpl createOutgoingCall(Address calleeAddress, } catch (TransactionUnavailableException ex) { - logger.error("Failed to create inviteTransaction.\n" - + "This is most probably a network connection error.", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to create inviteTransaction.\n" + "This is most probably a network connection error.", OperationFailedException.INTERNAL_ERROR, ex); @@ -278,17 +273,13 @@ private synchronized CallSipImpl createOutgoingCall(Address calleeAddress, } catch (ParseException ex) { - logger.error( - "Failed to parse sdp data while creating invite request!", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to parse sdp data while creating invite request!", OperationFailedException.INTERNAL_ERROR, ex); } catch (MediaException ex) { - logger.error("Could not access media devices!", ex); - throw new OperationFailedException( - "Could not access media devices!", + throwOperationFailedException("Could not access media devices!", OperationFailedException.INTERNAL_ERROR, ex); } @@ -300,8 +291,7 @@ private synchronized CallSipImpl createOutgoingCall(Address calleeAddress, } catch (SipException ex) { - logger.error("An error occurred while sending invite request", ex); - throw new OperationFailedException( + throwOperationFailedException( "An error occurred while sending invite request", OperationFailedException.NETWORK_FAILURE, ex); } @@ -895,7 +885,7 @@ private void processSessionProgress(ClientTransaction clientTransaction, if (!contentTypeHeader.getContentType().equalsIgnoreCase("application") || !contentTypeHeader.getContentSubType().equalsIgnoreCase("sdp")) { - // This can happen if we are receigin early media for a second time. + // This can happen if we are receiving early media for a second time. logger.warn("Ignoring invite 183 since call participant is " + "already exchanging early media."); return; @@ -925,25 +915,18 @@ private void processSessionProgress(ClientTransaction clientTransaction, } catch (ParseException exc) { - logger.error("There was an error parsing the SDP description of " - + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")", exc); - callParticipant.setState(CallParticipantState.FAILED, + logErrorAndFailCallParticipant( "There was an error parsing the SDP description of " + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")"); + + callParticipant.getAddress() + ")", exc, callParticipant); } catch (MediaException exc) { - logger.error("We failed to process the SDP description of " - + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")" + ". Error was: " - + exc.getMessage(), exc); - callParticipant.setState(CallParticipantState.FAILED, + logErrorAndFailCallParticipant( "We failed to process the SDP description of " + callParticipant.getDisplayName() + "(" + callParticipant.getAddress() + ")" + ". Error was: " - + exc.getMessage()); + + exc.getMessage(), exc, callParticipant); } // set the call url in case there was one @@ -975,11 +958,12 @@ private void processInviteOK(ClientTransaction clientTransaction, if (callParticipant == null) { - // In case of forwarding a call, the dialog maybe forked. - // If the dialog is forked - // we must check whether we have early state dialogs - // established and we must end them, do this by replacing the dialog - // with new one + + /* + * In case of forwarding a call, the dialog may have forked. If the + * dialog is forked, we must end early state dialogs by replacing + * the dialog with the new one. + */ CallIdHeader call = (CallIdHeader) ok.getHeader(CallIdHeader.NAME); String callid = call.getCallId(); @@ -1045,24 +1029,21 @@ private void processInviteOK(ClientTransaction clientTransaction, catch (ParseException ex) { // Shouldn't happen - callParticipant.setState(CallParticipantState.FAILED, - "Failed to create a content type header for the ACK request"); - logger.error( + logErrorAndFailCallParticipant( "Failed to create a content type header for the ACK request", - ex); + ex, callParticipant); } catch (InvalidArgumentException ex) { // Shouldn't happen - callParticipant.setState(CallParticipantState.FAILED, - "Failed ACK request, problem with the supplied cseq"); - logger.error("Failed ACK request, problem with the supplied cseq", - ex); + logErrorAndFailCallParticipant( + "Failed ACK request, problem with the supplied cseq", ex, + callParticipant); } catch (SipException ex) { - logger.error("Failed to create ACK request!", ex); - callParticipant.setState(CallParticipantState.FAILED); + logErrorAndFailCallParticipant("Failed to create ACK request!", ex, + callParticipant); return; } @@ -1084,7 +1065,7 @@ private void processInviteOK(ClientTransaction clientTransaction, if (callSession == null) { // non existent call session - that means we didn't send sdp - // in the invide and this is the offer so we need to create + // in the invite and this is the offer so we need to create // the answer. callSession = SipActivator.getMediaService().createCallSession( @@ -1102,7 +1083,6 @@ private void processInviteOK(ClientTransaction clientTransaction, callParticipant .setCallInfoURL(callSession.getCallInfoURL()); } - } finally { @@ -1115,8 +1095,8 @@ private void processInviteOK(ClientTransaction clientTransaction, } catch (SipException ex) { - logger.error("Failed to acknowledge call!", ex); - callParticipant.setState(CallParticipantState.FAILED); + logErrorAndFailCallParticipant( + "Failed to acknowledge call!", ex, callParticipant); return; } } @@ -1140,25 +1120,18 @@ private void processInviteOK(ClientTransaction clientTransaction, } catch (ParseException exc) { - logger.error("There was an error parsing the SDP description of " - + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")", exc); - callParticipant.setState(CallParticipantState.FAILED, + logErrorAndFailCallParticipant( "There was an error parsing the SDP description of " + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")"); + + callParticipant.getAddress() + ")", exc, callParticipant); } catch (MediaException exc) { - logger.error("We failed to process the SDP description of " - + callParticipant.getDisplayName() + "(" - + callParticipant.getAddress() + ")" + ". Error was: " - + exc.getMessage(), exc); - callParticipant.setState(CallParticipantState.FAILED, + logErrorAndFailCallParticipant( "We failed to process the SDP description of " + callParticipant.getDisplayName() + "(" + callParticipant.getAddress() + ")" + ". Error was: " - + exc.getMessage()); + + exc.getMessage(), exc, callParticipant); } // change status @@ -1166,6 +1139,13 @@ private void processInviteOK(ClientTransaction clientTransaction, callParticipant.setState(CallParticipantState.CONNECTED); } + private void logErrorAndFailCallParticipant(String message, + Throwable throwable, CallParticipantSipImpl participant) + { + logger.error(message, throwable); + participant.setState(CallParticipantState.FAILED, message); + } + /** * Sets corresponding state to the call participant associated with this * transaction. @@ -1244,10 +1224,10 @@ private void processAuthenticationChallenge( } catch (Exception exc) { - logger.error("We failed to authenticate an INVITE request.", exc); - // tell the others we couldn't register - callParticipant.setState(CallParticipantState.FAILED); + logErrorAndFailCallParticipant( + "We failed to authenticate an INVITE request.", exc, + callParticipant); } } @@ -1370,21 +1350,15 @@ private Request createInviteRequest(Address toAddress) catch (InvalidArgumentException ex) { // Shouldn't happen - logger.error("An unexpected erro occurred while" - + "constructing the CSeqHeadder", ex); - throw new OperationFailedException( - "An unexpected erro occurred while" - + "constructing the CSeqHeadder", + throwOperationFailedException("An unexpected erro occurred while" + + "constructing the CSeqHeadder", OperationFailedException.INTERNAL_ERROR, ex); } catch (ParseException exc) { // shouldn't happen - logger.error("An unexpected erro occurred while" - + "constructing the CSeqHeadder", exc); - throw new OperationFailedException( - "An unexpected erro occurred while" - + "constructing the CSeqHeadder", + throwOperationFailedException("An unexpected erro occurred while" + + "constructing the CSeqHeadder", OperationFailedException.INTERNAL_ERROR, exc); } @@ -1408,11 +1382,8 @@ private Request createInviteRequest(Address toAddress) catch (ParseException ex) { // these two should never happen. - logger.error("An unexpected erro occurred while" - + "constructing the ToHeader", ex); - throw new OperationFailedException( - "An unexpected erro occurred while" - + "constructing the ToHeader", + throwOperationFailedException("An unexpected erro occurred while" + + "constructing the ToHeader", OperationFailedException.INTERNAL_ERROR, ex); } @@ -1440,9 +1411,7 @@ private Request createInviteRequest(Address toAddress) catch (ParseException ex) { // shouldn't happen - logger.error("Failed to create invite Request!", ex); - throw new OperationFailedException( - "Failed to create invite Request!", + throwOperationFailedException("Failed to create invite Request!", OperationFailedException.INTERNAL_ERROR, ex); } @@ -1945,7 +1914,7 @@ private void processBye(ServerTransaction serverTransaction, * @param serverTransaction the transaction that the Ack was received in. * @param ackRequest Request */ - void processAck(ServerTransaction serverTransaction, Request ackRequest) + private void processAck(ServerTransaction serverTransaction, Request ackRequest) { // find the call CallParticipantSipImpl callParticipant = @@ -2002,17 +1971,15 @@ void processCancel(ServerTransaction serverTransaction, } catch (ParseException ex) { - logger.error( - "Failed to create an OK Response to an CANCEL request.", ex); - callParticipant.setState(CallParticipantState.FAILED, - "Failed to create an OK Response to an CANCEL request."); + logErrorAndFailCallParticipant( + "Failed to create an OK Response to an CANCEL request.", ex, + callParticipant); } catch (Exception ex) { - logger.error("Failed to send an OK Response to an CANCEL request.", - ex); - callParticipant.setState(CallParticipantState.FAILED, - "Failed to send an OK Response to an CANCEL request."); + logErrorAndFailCallParticipant( + "Failed to send an OK Response to an CANCEL request.", ex, + callParticipant); } try { @@ -2661,9 +2628,7 @@ public void sayError(CallParticipantSipImpl callParticipant, int errorCode) } catch (ParseException ex) { - logger.error( - "Failed to construct an OK response to an INVITE request", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to construct an OK response to an INVITE request", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2679,9 +2644,7 @@ public void sayError(CallParticipantSipImpl callParticipant, int errorCode) } catch (Exception ex) { - logger.error("Failed to send an OK response to an INVITE request", - ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to send an OK response to an INVITE request", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2774,9 +2737,7 @@ private void sayCancel(CallParticipantSipImpl callParticipant) } catch (SipException ex) { - logger.error("Failed to send the CANCEL request", ex); - throw new OperationFailedException( - "Failed to send the CANCEL request", + throwOperationFailedException("Failed to send the CANCEL request", OperationFailedException.NETWORK_FAILURE, ex); } } // cancel @@ -2804,8 +2765,7 @@ private void sayBusyHere(CallParticipantSipImpl callParticipant) } catch (ParseException ex) { - logger.error("Failed to create the BUSY_HERE response!", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to create the BUSY_HERE response!", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2827,8 +2787,7 @@ private void sayBusyHere(CallParticipantSipImpl callParticipant) } catch (Exception ex) { - logger.error("Failed to send the BUSY_HERE response", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to send the BUSY_HERE response", OperationFailedException.NETWORK_FAILURE, ex); } @@ -2883,9 +2842,7 @@ public synchronized void answerCallParticipant(CallParticipant participant) catch (ParseException ex) { callParticipant.setState(CallParticipantState.DISCONNECTED); - logger.error( - "Failed to construct an OK response to an INVITE request", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to construct an OK response to an INVITE request", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2904,10 +2861,7 @@ public synchronized void answerCallParticipant(CallParticipant participant) { // Shouldn't happen callParticipant.setState(CallParticipantState.DISCONNECTED); - logger.error( - "Failed to create a content type header for the OK response", - ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to create a content type header for the OK response", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2920,15 +2874,12 @@ public synchronized void answerCallParticipant(CallParticipant participant) ((CallSipImpl) callParticipant.getCall()) .setMediaCallSession(callSession); + String sdpOffer = callParticipant.getSdpDescription(); String sdp = null; // if the offer was in the invite create an sdp answer - if (callParticipant.getSdpDescription() != null - && callParticipant.getSdpDescription().length() > 0) + if ((sdpOffer != null) && (sdpOffer.length() > 0)) { - - sdp = - callSession.processSdpOffer(callParticipant, - callParticipant.getSdpDescription()); + sdp = callSession.processSdpOffer(callParticipant, sdpOffer); // set the call url in case there was one /** @@ -2948,9 +2899,7 @@ public synchronized void answerCallParticipant(CallParticipant participant) { this.sayError((CallParticipantSipImpl) participant, Response.NOT_ACCEPTABLE_HERE); - logger.error("No sdp data was provided for the ok response to " - + "an INVITE request!", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to created an SDP description for an ok response " + "to an INVITE request!", OperationFailedException.INTERNAL_ERROR, ex); @@ -2958,9 +2907,7 @@ public synchronized void answerCallParticipant(CallParticipant participant) catch (ParseException ex) { callParticipant.setState(CallParticipantState.DISCONNECTED); - logger.error( - "Failed to parse sdp data while creating invite request!", ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to parse sdp data while creating invite request!", OperationFailedException.INTERNAL_ERROR, ex); } @@ -2977,9 +2924,7 @@ public synchronized void answerCallParticipant(CallParticipant participant) catch (Exception ex) { callParticipant.setState(CallParticipantState.DISCONNECTED); - logger.error("Failed to send an OK response to an INVITE request", - ex); - throw new OperationFailedException( + throwOperationFailedException( "Failed to send an OK response to an INVITE request", OperationFailedException.NETWORK_FAILURE, ex); } @@ -3052,24 +2997,13 @@ private CallParticipantSipImpl createCallParticipantFor( * Returns a string representation of this OperationSetBasicTelephony * instance including information that would permit to distinguish it among * other instances when reading a log file. - *

- * + * * @return a string representation of this operation set. */ public String toString() { - String className = getClass().getName(); - try - { - className = className.substring(className.lastIndexOf('.') + 1); - } - catch (Exception ex) - { - // we don't want to fail in this method because we've messed up - // something with indexes, so just ignore. - } - return className + "-[dn=" + protocolProvider.getOurDisplayName() - + " addr=[" + return getClass().getSimpleName() + "-[dn=" + + protocolProvider.getOurDisplayName() + " addr=[" + protocolProvider.getRegistrarConnection().getAddressOfRecord() + "]"; }