/* * 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.service.protocol.media; import java.util.*; import net.java.sip.communicator.service.neomedia.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.util.*; /** * Represents a default implementation of OperationSetBasicTelephony in * order to make it easier for implementers to provide complete solutions while * focusing on implementation-specific details. * * @param the implementation specific provider class like for example * ProtocolProviderServiceSipImpl. * * @author Lyubomir Marinov * @author Emil Ivov * @author Dmitri Melnikov */ public abstract class AbstractOperationSetBasicTelephony implements OperationSetBasicTelephony { /** * The Logger used by the * AbstractOperationSetBasicTelephony class and its instances for * logging output. */ private static final Logger logger = Logger.getLogger(AbstractOperationSetBasicTelephony.class); /** * A list of listeners registered for call events. */ private final List callListeners = new ArrayList(); /** * Registers listener with this provider so that it * could be notified when incoming calls are received. * * @param listener the listener to register with this provider. */ public void addCallListener(CallListener listener) { synchronized(callListeners) { if (!callListeners.contains(listener)) callListeners.add(listener); } } /** * Creates and dispatches a CallEvent notifying registered * listeners that an event with id eventID has occurred on * sourceCall. * * @param eventID the ID of the event to dispatch * @param sourceCall the call on which the event has occurred. */ public void fireCallEvent(int eventID, Call sourceCall) { CallEvent cEvent = new CallEvent(sourceCall, eventID); List listeners; synchronized (callListeners) { listeners = new ArrayList(callListeners); } if (logger.isDebugEnabled()) logger.debug("Dispatching a CallEvent to " + listeners.size() + " listeners. event is: " + cEvent); for (CallListener listener : listeners) { switch (eventID) { case CallEvent.CALL_INITIATED: listener.outgoingCallCreated(cEvent); break; case CallEvent.CALL_RECEIVED: listener.incomingCallReceived(cEvent); break; case CallEvent.CALL_ENDED: listener.callEnded(cEvent); break; } } } /** * Removes the listener from the list of call listeners. * * @param listener the listener to unregister. */ public void removeCallListener(CallListener listener) { synchronized(callListeners) { callListeners.remove(listener); } } /** * Sets the mute state of the Call. *

* Muting audio streams sent from the call is implementation specific * and one of the possible approaches to it is sending silence. *

* * @param call the Call whose mute state is to be set * @param mute true to mute the call streams being sent to * peers; otherwise, false */ public void setMute(Call call, boolean mute) { /* * While throwing UnsupportedOperationException may be a possible * approach, putOnHold/putOffHold just do nothing when not supported so * this implementation takes inspiration from them. */ } /** * Creates a new Recorder which is to record the specified * Call (into a file which is to be specified when starting the * returned Recorder). *

* AbstractOperationSetBasicTelephony implements the described * functionality for MediaAwareCall only; otherwise, does nothing * and just returns null. *

* * @param call the Call which is to be recorded by the returned * Recorder when the latter is started * @return a new Recorder which is to record the specified * call (into a file which is to be specified when starting the * returned Recorder) * @throws OperationFailedException if anything goes wrong while creating * the new Recorder for the specified call * @see OperationSetBasicTelephony#createRecorder(Call) */ public Recorder createRecorder(Call call) throws OperationFailedException { return (call instanceof MediaAwareCall) ? ((MediaAwareCall) call).createRecorder() : null; } }