From 6c7e563e5ccd804f671c883e8faeff1c70f6b57d Mon Sep 17 00:00:00 2001 From: Sebastien Mazy Date: Mon, 15 Dec 2008 20:13:32 +0000 Subject: [PATCH] Moves RegistrationStateChangeListener to ProtocolProviderServiceSipImpl. For readability, it makes sense to have the class (ProtocolProviderServiceSipImpl) calling SipStackSharing.addSipListener(listener) also call SipStackSharing.removeSipListener(listener). --- .../sip/ProtocolProviderServiceSipImpl.java | 23 ++++++++++++++++++- .../impl/protocol/sip/SipStackSharing.java | 23 ++----------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java index 84653e45a..acfed89ba 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -39,7 +39,8 @@ */ public class ProtocolProviderServiceSipImpl extends AbstractProtocolProviderService - implements SipListener + implements SipListener, + RegistrationStateChangeListener { private static final Logger logger = Logger.getLogger(ProtocolProviderServiceSipImpl.class); @@ -290,6 +291,9 @@ public void register(SecurityAuthority authority) } sipStackSharing.addSipListener(this); + // be warned when we will unregister, so that we can + // then remove us as SipListener + this.addRegistrationStateChangeListener(this); // Enable the user name modification. Setting this property to true we'll // allow the user to change the user name stored in the given authority. @@ -2292,4 +2296,21 @@ private InetAddress getIntendedDestination(String host) return destinationInetAddress; } + + /** + * Stops dispatching SIP messages to a SIP protocol provider service + * once it's been unregistered. + * + * @param event the change event in the registration state of a provider. + */ + public void registrationStateChanged(RegistrationStateChangeEvent event) + { + if(event.getNewState() == RegistrationState.UNREGISTERED) + { + ProtocolProviderServiceSipImpl listener + = (ProtocolProviderServiceSipImpl) event.getProvider(); + this.sipStackSharing.removeSipListener(listener); + listener.removeRegistrationStateChangeListener(this); + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java b/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java index 01b94ec0f..bd4b1404a 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java @@ -33,8 +33,7 @@ * @author Sebastien Mazy */ public class SipStackSharing - implements SipListener, - RegistrationStateChangeListener + implements SipListener { /** * Logger for this class. @@ -127,7 +126,6 @@ public void addSipListener(ProtocolProviderServiceSipImpl listener) if(this.listeners.size() == 0) startListening(); this.listeners.add(listener); - listener.addRegistrationStateChangeListener(this); logger.trace(this.listeners.size() + " listeners now"); } } @@ -139,7 +137,7 @@ public void addSipListener(ProtocolProviderServiceSipImpl listener) * * @param listener possible target to remove for the dispatching process. */ - private void removeSipListener(ProtocolProviderServiceSipImpl listener) + public void removeSipListener(ProtocolProviderServiceSipImpl listener) { synchronized(this.listeners) { @@ -165,23 +163,6 @@ private Set getSipListeners() } } - /** - * Stops dispatching SIP messages to a SIP protocol provider service - * once it's been unregistered. - * - * @param event the change event in the registration state of a provider. - */ - public void registrationStateChanged(RegistrationStateChangeEvent event) - { - if(event.getNewState() == RegistrationState.UNREGISTERED) - { - ProtocolProviderServiceSipImpl listener - = (ProtocolProviderServiceSipImpl) event.getProvider(); - this.removeSipListener(listener); - listener.removeRegistrationStateChangeListener(this); - } - } - /** * Returns the JAIN-SIP ListeningPoint associated to the given * transport string.