>();
/**
* The ProtocolProviderService implementation which created this
* instance and for which telephony conferencing services are being provided
* by this instance.
*/
protected final T parentProvider;
/**
* Initializes a new AbstractOperationSetDesktopSharing instance
* which is to be provided by a specific ProtocolProviderService.
*
* @param parentProvider the ProtocolProviderService implementation
* which is creating the new instance and for which telephony conferencing
* services are being provided by this instance
*/
protected AbstractOperationSetDesktopSharingClient(T parentProvider)
{
this.parentProvider = parentProvider;
}
/**
* Adds a RemoteControlListener to be notified when the remote peer
* accepts to give us full control of their desktop.
*
* The default implementation of
* AbstractOperationSetDesktopSharingClient adds a
* WeakReference to the specified RemoteControlListener in
* order to avoid memory leaks because of code which calls
* addRemoteControlListener and never calls
* removeRemoteControlListener.
*
*
* @param listener the RemoteControlListener to add
*/
public void addRemoteControlListener(RemoteControlListener listener)
{
synchronized (listeners)
{
Iterator> i
= listeners.iterator();
boolean contains = false;
while (i.hasNext())
{
RemoteControlListener l = i.next().get();
if (l == null)
i.remove();
else if (l.equals(listener))
contains = true;
}
if (!contains)
{
listeners.add(
new WeakReference(listener));
listener.getCallPeer().addCallPeerListener(callPeerListener);
}
}
// Notifies the new listener if the corresponding peer has already been
// granted to remotely control the shared desktop.
CallPeer peer = listener.getCallPeer();
// Removes the null peers from the granted remote control peer list.
// If the corresponding peer was in the granted list, then this peer has
// already been granted and we must call the remoteControlGranted
// function for this listener.
if(this.removesNullAndRevokedControlPeer(peer.getPeerID()) != -1)
listener.remoteControlGranted(new RemoteControlGrantedEvent(peer));
}
/**
* Fires a RemoteControlGrantedEvent to all registered listeners.
*
* @param peer the CallPeer
*/
public void fireRemoteControlGranted(CallPeer peer)
{
RemoteControlListener listener = getListener(peer);
if(listener != null)
{
listener.remoteControlGranted(new RemoteControlGrantedEvent(peer));
}
// The UI has not created the listener yet, then we need to store the
// information taht this peer has alreayd been granted.
else
{
// Removes all previous instance of this peer.
this.removesNullAndRevokedControlPeer(peer.getPeerID());
// Adds the peer to the granted remote control peer list.
synchronized(this.grantedRemoteControlPeers)
{
this.grantedRemoteControlPeers.add(peer);
}
}
}
/**
* Fires a RemoteControlGrantedEvent to all registered listeners.
*
* @param peer the CallPeer
*/
public void fireRemoteControlRevoked(CallPeer peer)
{
RemoteControlListener listener = getListener(peer);
if(listener != null)
{
listener.remoteControlRevoked(new RemoteControlRevokedEvent(peer));
}
// Removes the peer from the granted remote control peer list.
this.removesNullAndRevokedControlPeer(peer.getPeerID());
}
/**
* Gets a list of RemoteControlListeners to be notified of remote
* control access changes.
*
* @return a list of RemoteControlListeners to be notifed of remote
* control access changes
*/
protected List getListeners()
{
List listeners;
synchronized (this.listeners)
{
Iterator> i
= this.listeners.iterator();
listeners
= new ArrayList(this.listeners.size());
while (i.hasNext())
{
RemoteControlListener l = i.next().get();
if (l == null)
i.remove();
else
listeners.add(l);
}
}
return listeners;
}
/**
* Removes a RemoteControlListener to be notified when remote peer
* accept/revoke to give us full control.
*
* @param listener RemoteControlListener to remove
*/
public void removeRemoteControlListener(RemoteControlListener listener)
{
synchronized (listeners)
{
Iterator> i
= listeners.iterator();
while (i.hasNext())
{
RemoteControlListener l = i.next().get();
if ((l == null) || l.equals(listener))
i.remove();
}
}
}
/**
* Removes null and the peer corresponding to the revokedPeerID from the
* granted control peer list.
*
* @param revokedPeerID The ID of the revoked peer. May be null to only
* clear null instances from the granted control peer list.
*
* @return The index corresponding to the revokedPeerID entry. -1 if the
* revoked PeerID is null, or if the revokedPeerID is not found and removed.
*/
private int removesNullAndRevokedControlPeer(String revokedPeerID)
{
int index = -1;
synchronized(this.grantedRemoteControlPeers)
{
CallPeer peer;
for(int i = 0; i < this.grantedRemoteControlPeers.size(); ++i)
{
peer = this.grantedRemoteControlPeers.get(i);
if(peer == null || peer.getPeerID().equals(revokedPeerID))
{
this.grantedRemoteControlPeers.remove(i);
index = i;
--i;
}
}
}
return index;
}
/**
* Returns the RemoteControlListener corresponding to the given
* callPeer, if it exists.
*
* @param callPeer the CallPeer to get the corresponding
* RemoteControlListener of
* @return the RemoteControlListener corresponding to the given
* callPeer, if it exists; null, otherwise
*/
protected RemoteControlListener getListener(CallPeer callPeer)
{
String peerID = callPeer.getPeerID();
synchronized (listeners)
{
Iterator> i
= listeners.iterator();
while (i.hasNext())
{
RemoteControlListener l = i.next().get();
if (l == null)
i.remove();
else if (peerID.equals(l.getCallPeer().getPeerID()))
return l;
}
}
return null;
}
}