From 6dae2f4fc5a02eb5c8355f8799cc7b3e114e041d Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Thu, 22 Feb 2007 12:33:45 +0000 Subject: [PATCH] Added multichat operation set definition and Gibberish protocol implementation. Related issues: Issue #241 , Issue #244, Issue #250 A gibberish implementation of the TypingNotifications operation set --- ...onSetTypingNotificationsGibberishImpl.java | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetTypingNotificationsGibberishImpl.java diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetTypingNotificationsGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetTypingNotificationsGibberishImpl.java new file mode 100644 index 000000000..1df1208a3 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetTypingNotificationsGibberishImpl.java @@ -0,0 +1,134 @@ +/* + * 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.gibberish; + +import java.util.*; + +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +/** + * Implements typing notifications for the Gibberish protocol. The operation + * set would simply mirror all outgoing typing notifications and make them + * appear as incoming events generated by the contact that we are currently + * writing a message to. + * + * @author Emil Ivov + */ +public class OperationSetTypingNotificationsGibberishImpl + implements OperationSetTypingNotifications +{ + private static final Logger logger = + Logger.getLogger(OperationSetTypingNotificationsGibberishImpl.class); + + /** + * All currently registered TN listeners. + */ + private List typingNotificationsListeners = new ArrayList(); + + /** + * The provider that created us. + */ + private ProtocolProviderServiceGibberishImpl gibberishProvider = null; + + /** + * Creates a new instance of this operation set and keeps the parent + * provider as a reference. + * + * @param provider a ref to the ProtocolProviderServiceImpl + * that created us and that we'll use for retrieving the underlying aim + * connection. + */ + OperationSetTypingNotificationsGibberishImpl( + ProtocolProviderServiceGibberishImpl provider) + { + this.gibberishProvider = provider; + } + + /** + * Adds listener to the list of listeners registered for receiving + * TypingNotificationEvents + * + * @param listener the TypingNotificationsListener listener that + * we'd like to add to the list of listeneres registered for receiving + * typing notificaions. + */ + public void addTypingNotificationsListener( + TypingNotificationsListener listener) + { + synchronized(typingNotificationsListeners) + { + typingNotificationsListeners.add(listener); + } + } + + /** + * Removes listener from the list of listeners registered for + * receiving TypingNotificationEvents + * + * @param listener the TypingNotificationsListener listener that + * we'd like to remove + */ + public void removeTypingNotificationsListener( + TypingNotificationsListener listener) + { + synchronized(typingNotificationsListeners) + { + typingNotificationsListeners.remove(listener); + } + } + + /** + * Delivers a TypingNotificationEvent to all registered listeners. + * @param sourceContact the contact who has sent the notification. + * @param evtCode the code of the event to deliver. + */ + private void fireTypingNotificationsEvent(Contact sourceContact + ,int evtCode) + { + logger.debug("Dispatching a TypingNotif. event to " + + typingNotificationsListeners.size()+" listeners. Contact " + + sourceContact.getAddress() + " has now a typing status of " + + evtCode); + + TypingNotificationEvent evt = new TypingNotificationEvent( + sourceContact, evtCode); + + Iterator listeners = null; + synchronized (typingNotificationsListeners) + { + listeners = new ArrayList(typingNotificationsListeners).iterator(); + } + + while (listeners.hasNext()) + { + TypingNotificationsListener listener + = (TypingNotificationsListener) listeners.next(); + + listener.typingNotificationReceifed(evt); + } + } + + /** + * Sends a notification to notifiedContatct that we have entered + * typingState. + * + * @param notifiedContact the Contact to notify + * @param typingState the typing state that we have entered. + * + * @throws java.lang.IllegalStateException if the underlying stack is + * not registered and initialized. + * @throws java.lang.IllegalArgumentException if notifiedContact is + * not an instance belonging to the underlying implementation. + */ + public void sendTypingNotification(Contact notifiedContact, int typingState) + throws IllegalStateException, IllegalArgumentException + { + this.fireTypingNotificationsEvent(notifiedContact, typingState); + } +}