FileDocCategorySizeDatePackage
NatPMPUPnPImpl.javaAPI DocAzureus 3.0.3.43101Sat Aug 19 07:13:58 BST 2006com.aelitis.net.natpmp.upnp.impl

NatPMPUPnPImpl

public class NatPMPUPnPImpl extends Object implements com.aelitis.net.natpmp.upnp.NatPMPUPnP

Fields Summary
private com.aelitis.net.upnp.UPnP
upnp
private com.aelitis.net.natpmp.NatPMPDevice
nat_device
private NatPMPUPnPRootDeviceImpl
root_device
private List
listeners
private boolean
enabled
private boolean
started
Constructors Summary
public NatPMPUPnPImpl(com.aelitis.net.upnp.UPnP _upnp, com.aelitis.net.natpmp.NatPMPDevice _nat_device)

	
	
	
					
			 
	
		upnp		= _upnp;
		nat_device	= _nat_device;
	
Methods Summary
public synchronized voidaddListener(com.aelitis.net.upnp.UPnPListener listener)

		listeners.add( listener );
		
		if ( root_device == null ){
			
			if ( listeners.size() == 1 && !started ){
			
				started	= true;
				
				start();
			}
		}else{
			
			listener.rootDeviceFound( root_device );
		}
	
public booleanisEnabled()

		return( enabled );
	
public synchronized voidremoveListener(com.aelitis.net.upnp.UPnPListener listener)

		listeners.remove( listener );
	
protected voidsearch()

		if ( !enabled ){
			
			return;
		}
		
		if ( root_device != null ){
			
			return;
		}
		
		try{
			boolean found = nat_device.connect();
			
			if ( found ){
			
				root_device	= new NatPMPUPnPRootDeviceImpl(upnp, nat_device );
				
				for (int i=0;i<listeners.size();i++){
					
					try{
						((UPnPListener)listeners.get(i)).rootDeviceFound( root_device );
						
					}catch( Throwable e ){
						
						Debug.printStackTrace(e);
					}
				}
			}
		}catch( Throwable e ){
			
			Debug.printStackTrace(e);
		}
	
public voidsetEnabled(boolean _enabled)

		enabled	= _enabled;
	
protected voidstart()

		SimpleTimer.addPeriodicEvent(
			"NATPMP:search",
			60*1000,
			new TimerEventPerformer()
			{
				public void
				perform(
					TimerEvent	event )
				{
					search();
				}
			});
		
		search();