felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From furf...@apache.org
Subject svn commit: r685978 - /felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
Date Thu, 14 Aug 2008 17:57:53 GMT
Author: furfari
Date: Thu Aug 14 10:57:52 2008
New Revision: 685978

URL: http://svn.apache.org/viewvc?rev=685978&view=rev
Log:
Factorized different methods of MyCtrlPoint.java
Improved searchForListenrs()
cleaned some parts of code

Modified:
    felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java

Modified: felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
URL: http://svn.apache.org/viewvc/felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java?rev=685978&r1=685977&r2=685978&view=diff
==============================================================================
--- felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
(original)
+++ felix/sandbox/furfari/Version-1.0.0/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
Thu Aug 14 10:57:52 2008
@@ -23,7 +23,6 @@
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.Vector;
 
 import org.osgi.framework.BundleContext;
@@ -37,16 +36,12 @@
 import org.osgi.service.upnp.UPnPDevice;
 import org.osgi.service.upnp.UPnPEventListener;
 import org.osgi.service.upnp.UPnPService;
-import org.osgi.service.upnp.UPnPStateVariable;
 
 import org.cybergarage.http.HTTPRequest;
 import org.cybergarage.upnp.ControlPoint;
 import org.cybergarage.upnp.Device;
 import org.cybergarage.upnp.DeviceList;
 import org.cybergarage.upnp.Service;
-import org.cybergarage.upnp.ServiceList;
-import org.cybergarage.upnp.ServiceStateTable;
-import org.cybergarage.upnp.StateVariable;
 import org.cybergarage.upnp.device.DeviceChangeListener;
 import org.cybergarage.upnp.event.NotifyRequest;
 import org.cybergarage.upnp.event.Property;
@@ -93,19 +88,9 @@
 		super();
 		this.context = context;
 		
-		Vector test = new Vector();
-		String[] test2 = (String[]) test.toArray(new String[]{});
-		if (test == null)
-			System.out.println((" test2 is null"));
-		else
-			System.out.println("test2 size is " + test2.length);
-		
-		
-		
-		
         devices = new Hashtable();
         addDeviceChangeListener(this);
-//        waitingEvents = new Hashtable();
+//      waitingEvents = new Hashtable();
 //      sidServices = new Hashtable();
 		try {
 			context.addServiceListener(this, UPNP_EVENT_LISTENER_FLTR);
@@ -116,169 +101,130 @@
 		this.notifierQueue = notifierQueue;
 	}
 
-	synchronized public void httpRequestRecieved(HTTPRequest httpReq) {
-        Activator.logger.DEBUG("[Importer] httpRequestRecieved event");
-        Activator.logger.PACKET(httpReq.toString());
-
-        if (httpReq.isNotifyRequest() == true) {
-            Activator.logger.DEBUG("[Importer] Notify Request");
-			NotifyRequest notifyReq = new NotifyRequest(httpReq);
-            newEventArrived(notifyReq);
-			httpReq.returnOK();
-			return;
-		}
 
-        Activator.logger.DEBUG("BAD Request");
-		httpReq.returnBadRequest();
-
-	}
-
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.cybergarage.upnp.ControlPoint#removeExpiredDevices()
-	 *  
-	 */
-	public void removeExpiredDevices() {
-		DeviceList devList = getDeviceList();
-		int devCnt = devList.size();
-		for (int n = 0; n < devCnt; n++) {
-			Device dev = devList.getDevice(n);
-			if (dev.isExpired() == true) {
-                Activator.logger.DEBUG("[Importer] Expired device:"+ dev.getFriendlyName());
-				removeDevice(dev);
-				removeOSGiExpireDevice(dev);
-			}
-		}
+    /***************************************
+    *
+    *	Device Discovery
+    *
+    ****************************************/
+	
+	public void deviceAdded(Device cyberDevice) {
+		String udn = cyberDevice.getUDN();
+		String friendlyName = cyberDevice.getFriendlyName();
+		
+		if (isExportedDevice(udn)) {
+            Activator.logger.INFO("[Importer] discoverded Exported Device :"+friendlyName+"("+udn+")"
);
+		}
+		else {// a real device to import
+            Activator.logger.INFO("[Importer] registering UPnPDevice:"+friendlyName+"("+udn+")"
);
+            registerUPnPDevice(cyberDevice);
+        }		
 	}
 	
-	public void deviceAdded(Device dev) {
-		String udn = dev.getUDN();
-		ServiceReference[] refs = null;
-		String filter = "(&" + UPNP_DEVICE_FLTR + EXPORT_FLTR+ ")";
+	private boolean isExportedDevice(String udn) {
 		try {
-			refs = context.getServiceReferences(UPnPDevice.class.getName(),	filter);
-		} catch (InvalidSyntaxException e) {
-			e.printStackTrace();
-		}
-		if (refs != null) {
-			for (int i = 0; i < refs.length; i++) {
-				UPnPDevice osgidev = (UPnPDevice) context.getService(refs[i]);
-				Dictionary dic = osgidev.getDescriptions(null);
-				if (((String) dic.get(UPnPDevice.UDN)).equals(udn)) {
-					return;
+			String filter = "(&" + UPNP_DEVICE_FLTR + EXPORT_FLTR+ ")";
+			ServiceReference[] refs = context.getServiceReferences(UPnPDevice.class.getName(),	filter);
+			if (refs != null) {
+				for (int i = 0; i < refs.length; i++) {
+					UPnPDevice osgidev = (UPnPDevice) context.getService(refs[i]);
+					Dictionary dic = osgidev.getDescriptions(null);
+					if (((String) dic.get(UPnPDevice.UDN)).equals(udn)) {
+						return true;
+					}
 				}
 			}
+		} catch (InvalidSyntaxException e) {
+			e.printStackTrace();
 		}
-		if(devices.containsKey(udn) == false) {
-            Activator.logger.INFO("[Importer] registering UPnPDevice:"+dev.getFriendlyName()+"("+dev.getUDN()+")"
);
-            registerUPnPDevice(dev, null, null);
-            //new SearchForListenerThread(dev).start();
-            searchForListener(dev);
-            
-            for (Iterator i = dev.getDeviceList().iterator(); i.hasNext();) {
-				Device d = (Device) i.next();
-				if (isDeviceRegistered(udn) == false)
-					doEmbeddedRegistration(d); 
-			}
-        }else if(devices.containsKey(udn) == true) {
-        	Activator.logger.INFO("[Importer] UPnPDevice UDN::"+dev.getFriendlyName()+"("+dev.getUDN()+")
already registered Skipping");
-        }		
+		return false;
 	}
+		
+    public synchronized void registerUPnPDevice(Device cyberDevice){
+    	
+		UPnPDeviceImpl osgiDevice = new UPnPDeviceImpl(cyberDevice, context);
+		ServiceRegistration registration = 
+            context.registerService(UPnPDevice.class.getName(), 
+                                    osgiDevice, 
+                                    osgiDevice.getDescriptions(null));
+		OSGiDeviceInfo deviceInfo = new OSGiDeviceInfo(osgiDevice,registration);
+        
+        String udn = cyberDevice.getUDN();
+        
+        synchronized (devices) {
+    		devices.put(udn, deviceInfo);		
+		}
+        
+        /*
+		 * Check if any UPnPEvent Listener is already registered for such a device
+		 */       
+        searchForListener(osgiDevice);
 
-	public void deviceRemoved(Device cyberdevice) {
-		String udn = cyberdevice.getUDN();
-		synchronized (devices) {
-			
-		if (devices.containsKey(udn)) {
-
-                Activator.logger.DEBUG("[Importer] parseUSN.isDevice ...unregistering all
the children devices ");
-                
-				//unregistering all the children devices 
-				UPnPDeviceImpl dev = ((OSGiDeviceInfo) devices.get(udn)).getOSGiDevice();
-				removeOSGiandUPnPDeviceHierarchy(dev);
-
-			}		
+        
+        /*
+		 * registering the embedded devices if any 
+		 */       
+		DeviceList devList = cyberDevice.getDeviceList();
+		int size = devList.size();
+		for (int n=0; n<size; n++) {
+			Device embeddedDevice= devList.getDevice(n);
+			registerUPnPDevice(embeddedDevice);
 		}
-	}
+    }
 
     
-	public synchronized void removeOSGiandUPnPDeviceHierarchy(final UPnPDeviceImpl dev) 
-    {
-		/*
-		 * remove all the UPnPDevice from the struct of local device recursively
-		 */
-		final String udn = (String) dev.getDescriptions(null).get(UPnPDevice.UDN);
-		
-		if(devices.containsKey(udn) == false){
-			Activator.logger.INFO("Device "+dev.getDescriptions(null).get(UPnPDevice.FRIENDLY_NAME)+"("+udn+")
already removed");
-			return;
-		}		
+	public void deviceRemoved(Device cyberDevice) {
+		String udn = cyberDevice.getUDN();
+		String friendlyName = cyberDevice.getFriendlyName();
 		
-		String[] childrenUDN = (String[]) dev.getDescriptions(null).get(
-				UPnPDevice.CHILDREN_UDN);
+		Activator.logger.DEBUG("[Importer] unregistering UPnPDevice: " + friendlyName + " (" +udn+
")");
+		removeOSGiDevices(udn);
+	}
 
-		if (childrenUDN == null) {
-			//no children			
-			unregisterUPnPDevice(((OSGiDeviceInfo) devices.get(udn)).getRegistration());
-			Activator.logger.INFO("Device "+dev.getDescriptions(null).get(UPnPDevice.FRIENDLY_NAME)+"("+udn+")
deleted");
-			devices.remove(udn);
-			return;
-		} else {
-			for (int i = 0; i < childrenUDN.length; i++) {
-				if (devices.get(childrenUDN[i]) != null) {
-					removeOSGiandUPnPDeviceHierarchy(((OSGiDeviceInfo) devices.get(childrenUDN[i])).getOSGiDevice());
+	private void removeOSGiDevices(String  udn) {
+		synchronized (devices) {
+			try{
+				OSGiDeviceInfo info = (OSGiDeviceInfo) devices.remove(udn);
+				if (info != null){
+					info.getRegistration().unregister();
+
+					UPnPDeviceImpl osgiDevice = info.getOSGiDevice();
+					String[] childrenUDN = (String[]) osgiDevice.getDescriptions(null).get(UPnPDevice.CHILDREN_UDN);
+					if (childrenUDN != null){
+						for (int i = 0; i < childrenUDN.length; i++) {
+							removeOSGiDevices(childrenUDN[i]);
+						}
+					}
 				}
+			}catch (Exception ex){
+				System.out.println(ex);
 			}
-			unregisterUPnPDevice(((OSGiDeviceInfo) devices.get(udn)).getRegistration());
-			Activator.logger.INFO("Device "+dev.getDescriptions(null).get(UPnPDevice.FRIENDLY_NAME)+"("+udn+")
deleted");
-			devices.remove(udn);
 		}
-	}
-
-	public synchronized void removeOSGiExpireDevice(Device dev) {
-		/*
-		 * unregistering root device with all its children device from OSGi 
-		 * deleting root device and all its children from struct that conatin 
-		 * a list of local device
-		 */
-		removeOSGiandUPnPDeviceHierarchy(((OSGiDeviceInfo) devices.get(dev
-				.getUDN())).getOSGiDevice());
-	}
-
-	public void registerUPnPDevice(Device dev, UPnPDeviceImpl upnpDev,
-			Dictionary prop) {
-		/*
-		 * registering the new Device as OSGi UPnPDevice and then add 
-		 * ServiceRegistration and UPnPDevice reference to the hashtable
-		 * that contains local devices
-		 */
-		if (prop == null && upnpDev == null) {
-			UPnPDeviceImpl newDevice = new UPnPDeviceImpl(dev, context);
-			ServiceRegistration registration = 
-                context.registerService(UPnPDevice.class.getName(), 
-                                        newDevice, 
-                                        newDevice.getDescriptions(null));
-			OSGiDeviceInfo deviceInfo = 
-                new OSGiDeviceInfo(newDevice,registration);
-            
-            String udn = (String) ((newDevice.getDescriptions(null)).get(UPnPDevice.UDN));
-			devices.put(udn, deviceInfo);
-		} else {
-			ServiceRegistration registration = 
-                context.registerService(UPnPDevice.class.getName(), upnpDev, prop);
-			OSGiDeviceInfo deviceInfo = 
-                new OSGiDeviceInfo(upnpDev,	registration);
-			devices.put(upnpDev.getDescriptions(null).get(UPnPDevice.UDN),deviceInfo);
+	} 
+	
+	public void removeExpiredDevices() {
+		DeviceList devList = getDeviceList();
+		int devCnt = devList.size();
+		for (int n = 0; n < devCnt; n++) {
+			Device dev = devList.getDevice(n);
+			if (dev.isExpired() == true) {
+				removeDevice(dev);
+				String udn = dev.getUDN();
+                Activator.logger.DEBUG("[Importer] Expired device: "+ dev.getFriendlyName()
+ "(" + udn +")");
+				removeOSGiDevices(udn);
+			}
 		}
 	}
-    
-    
-	public void unregisterUPnPDevice(ServiceRegistration registration) {
-		registration.unregister();
 
-	}
+	
+	
+	
+	
+    /***************************************
+    *
+    *	UPnP Event Listeners and Subscription 
+    *
+    ****************************************/
 
 	/*
 	 * (non-Javadoc)
@@ -297,18 +243,9 @@
 		Filter filter = (Filter) upnpEventListenerReference.getProperty(UPnPEventListener.UPNP_FILTER);
 		
 		if (event.getType() == ServiceEvent.REGISTERED) {
-			ServiceReference[] devicesRefs = null;
+			
 			if (filter != null) {
-				System.out.println("new UPnPEvent Listners registered ....");
-
-				try {
-					String filterString = filter.toString();
-					String filter4ImportedDevices = "(&" + filterString +  IMPORT_FLTR + ")";
-					devicesRefs = context.getServiceReferences(UPnPDevice.class.getName(),filter4ImportedDevices);
-				} catch (InvalidSyntaxException e) {
-					e.printStackTrace();
-				}
-
+				ServiceReference[] devicesRefs = getFilteredImportedDevices(filter);
 				if (devicesRefs != null) {
 					for (int i = 0; i < devicesRefs.length; i++) {
 						UPnPDeviceImpl device = (UPnPDeviceImpl) context.getService(devicesRefs[i]);
@@ -329,12 +266,7 @@
 				}
 
 			} else {/* filter == null (interested in all devices) */
-				try {
-					devicesRefs = context.getServiceReferences(UPnPDevice.class.getName(), IMPORT_FLTR);
-				} catch (InvalidSyntaxException e) {
-					e.printStackTrace();
-				}
-
+				ServiceReference[] devicesRefs = getAllImportedDevices();
 				if (devicesRefs != null) {
 					for (int i = 0; i < devicesRefs.length; i++) {
 						UPnPDeviceImpl device = (UPnPDeviceImpl) context.getService(devicesRefs[i]);
@@ -350,19 +282,12 @@
 					}
 				}
 			}
-		} 
+		} // ServiceEvent.REGISTERED
+		
 		else if (event.getType() == ServiceEvent.MODIFIED) {
-			ServiceReference[] devicesRefs = null;
 
 			if (filter != null) {
-				try {
-					String filtra = filter.toString();
-                    String newfilter = "(&" + filtra + IMPORT_FLTR + ")";
-					devicesRefs = context.getServiceReferences(UPnPDevice.class.getName(), newfilter);
-				} catch (InvalidSyntaxException e) {
-					e.printStackTrace();
-				}
-				
+				ServiceReference[] devicesRefs = getFilteredImportedDevices(filter);				
 				if (devicesRefs != null) {
 					for (int i = 0; i < devicesRefs.length; i++) {
 						Vector newServices = new Vector();
@@ -383,13 +308,7 @@
 				}
 			} 
 			else { //interrested in all devices
-				try {
-					devicesRefs = context.getServiceReferences(UPnPDevice.class
-							.getName(), IMPORT_FLTR);
-				} catch (InvalidSyntaxException e) {
-					e.printStackTrace();
-				}
-				
+				ServiceReference[] devicesRefs = getAllImportedDevices();				
 				if (devicesRefs != null) {
 					for (int i = 0; i < devicesRefs.length; i++) {
 						Vector newServices = new Vector();
@@ -402,10 +321,9 @@
 						ListenerModified msg = new ListenerModified(newServices,upnpEventListenerService);
 						subQueue.enqueue(msg);
 					}
-				}
-			
-			} //end interrested in all devices		
-		} 
+				}			
+			} 	
+		} // ServiceEvent.MODIFIED	
 		
 		else if (event.getType() == ServiceEvent.UNREGISTERING) {
 			if (upnpEventListenerService != null) {
@@ -420,48 +338,96 @@
 	} 
 	
 	
-	public Service serviceFromSid(String sid) {
-		
-//		synchronized (sidServices) {
-//			return (Service) sidServices.get(sid);
-//		}
-		
-		
-		synchronized (devices) {
-			
-		Enumeration e = devices.elements();
-		//System.out.println("#### DEVICES SIZE" +devices.size());
-		Service cyberService = null;
-		while (e.hasMoreElements()) {
-			OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) e.nextElement();
-			UPnPDevice device = deviceinfo.getOSGiDevice();
-			UPnPService[] services = (UPnPService[]) device.getServices();
-			UPnPServiceImpl[] servicesImpl = new UPnPServiceImpl[services.length];
-			for (int i = 0; i < servicesImpl.length; i++) {
-				servicesImpl[i] = (UPnPServiceImpl) services[i];
-			}
-			for (int i = 0; i < servicesImpl.length; i++) {
-				cyberService = servicesImpl[i].getCyberService();
-				boolean bool = cyberService.isSubscribed();
-				if (bool) {
-					if (cyberService.getSID().equals(sid)) {
-						return cyberService;
-					}
-				}
-			}
-			//System.out.println("Device NOT MATCHED " +device.getDescriptions(null).get(UPnPDevice.ID));
+	private ServiceReference[] getFilteredImportedDevices(Filter filter) {
+		try {
+			String filterString = filter.toString();
+			String filter4ImportedDevices = "(&" + IMPORT_FLTR  + filterString  + ")";
+			return context.getServiceReferences(UPnPDevice.class.getName(),filter4ImportedDevices);
+		} catch (InvalidSyntaxException e) {
+			e.printStackTrace();
+			return null;
 		}
+		
+	}
+	private ServiceReference[] getAllImportedDevices() {
+		try {
+			return context.getServiceReferences(UPnPDevice.class.getName(),IMPORT_FLTR);
+		} catch (InvalidSyntaxException e) {
+			e.printStackTrace();
+			return null;
 		}
 		
-		return null;
 	}
+	
+    public void searchForListener(UPnPDeviceImpl device) {
+    	System.out.println("searching for UPnPEvent Listners already registered");
+    	
+    	Activator.logger.DEBUG("[Importer] searching for UPnPEventListener");
+    	ServiceReference[] listeners = null;
+    	try {
+    		listeners = context.getServiceReferences(UPnPEventListener.class.getName(), null);
+    	} catch (InvalidSyntaxException e) {
+    		e.printStackTrace();
+    	}
+    	if (listeners != null) {
 
+    		for (int i = 0; i < listeners.length; i++) {
+    			UPnPEventListener listener = (UPnPEventListener) context.getService(listeners[i]);
+    			Filter filter = (Filter) listeners[i].getProperty(UPnPEventListener.UPNP_FILTER);
+    			if (filter == null) {
+    				UPnPServiceImpl[] eventedServices = device.getEventedServices();
+    				for (int j = 0; j < eventedServices.length; j++) {
+    					FirstMessage msg = new FirstMessage(
+    							eventedServices[j].getCyberService(),
+    							listener);
+    					subQueue.enqueue(msg);
+    				}
+    			} else {
+    				Dictionary[] filters = device.getEventedServicesFilters();
+    				for (int j = 0; j < filters.length; j++) {
+    					if( filter.match(filters[j])){
+    						String serviceId = (String) filters[j].get(UPnPService.ID);
+    						UPnPServiceImpl service = (UPnPServiceImpl) device.getService(serviceId);					
	
+    						subQueue.enqueue(new FirstMessage(service.getCyberService(), listener));
+    					}
+    				}
+    			}
+    		}
+    	}
+    }
+	
+	
+	
+    /***************************************
+    *
+    *	Eventing
+    *
+    ****************************************/
+	
 	/*
-	 * (non-Javadoc)
 	 * 
-	 * @see org.apache.felix.upnpbase.importer.MyEventListener#newEventArrived(java.lang.String,
-	 *      long, java.util.Dictionary)
+	 * 	Override Cyber dispatching of state variables changes because we have to cache and deliver
them all together
+	 * 
+	 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
 	 */
+	
+	synchronized public void httpRequestRecieved(HTTPRequest httpReq) {
+        Activator.logger.DEBUG("[Importer] httpRequestRecieved event");
+        Activator.logger.PACKET(httpReq.toString());
+
+        if (httpReq.isNotifyRequest() == true) {
+            Activator.logger.DEBUG("[Importer] Notify Request");
+			NotifyRequest notifyReq = new NotifyRequest(httpReq);
+            newEventArrived(notifyReq);
+			httpReq.returnOK();
+			return;
+		}
+
+        Activator.logger.DEBUG("BAD Request");
+		httpReq.returnBadRequest();
+
+	}
+
 
 	public void newEventArrived(NotifyRequest notifyReq) {
         Activator.logger.DEBUG("[Importer] newEventArrived");
@@ -504,110 +470,45 @@
 	}
     
 
-    
-    public boolean isDeviceRegistered(String udn){
+	public Service serviceFromSid(String sid) {
 		
-		try {
-			ServiceReference[] refs =
-				Activator.bc.getServiceReferences(
-					UPnPDevice.class.getName(),
-					"(" + UPnPDevice.UDN + "=" + udn + ")"
-				);
-			if(refs!= null)
-				return true;
-			else
-				return false;
-		} catch (InvalidSyntaxException ignored) {
-			return false;
-		}
-    }
-    
-    public synchronized void doEmbeddedRegistration(Device device){
-        registerUPnPDevice(device, null, null);
-        //new SearchForListenerThread(device).start();
-        searchForListener(device);
-        
-		DeviceList devList = device.getDeviceList();
-		int size = devList.size();
-		for (int n=0; n<size; n++) {
-			Device dev = devList.getDevice(n);
-			doEmbeddedRegistration(dev);
-		}
-    }
-
-    
-    class SearchForListenerThread extends Thread{ 
-	private Device device;
-    	public SearchForListenerThread(Device device) {
-			this.device= device;
-		}
-    	public void run(){
-    		searchForListener(device);
-    	}
-    }
-    
-	public void searchForListener(Device device) {
-		System.out.println("searching for UPnPEvent Listners already registered");
-        Activator.logger.DEBUG("[Importer] searching for UPnPEventListener");
-		ServiceReference[] listeners = null;
-		try {
-			listeners = context.getServiceReferences(UPnPEventListener.class.getName(), null);
-		} catch (InvalidSyntaxException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		if (listeners != null) {
-			String deviceID = device.getUDN();
-			String serviceID;
-			String deviceType = device.getDeviceType();
-			String serviceType;
-			Hashtable hash = new Hashtable();
-			hash.put(UPnPDevice.ID, deviceID);
-			hash.put(UPnPDevice.TYPE, deviceType);
-			ServiceList services = device.getServiceList();
-			Vector eventedSers = new Vector();
-
-			for (int i = 0; i < services.size(); i++) {
-				Service service = (Service) services.elementAt(i);
-				ServiceStateTable vars = service.getServiceStateTable();
-				for (int j = 0; j < vars.size(); j++) {
-					StateVariable var = (StateVariable) vars.elementAt(j);
-					if (var.isSendEvents()) {
-						eventedSers.add(service);
-						break;
-					}
-				}
+//		synchronized (sidServices) {
+//			return (Service) sidServices.get(sid);
+//		}
+		
+		
+		synchronized (devices) {
+			
+		Enumeration e = devices.elements();
+		//System.out.println("#### DEVICES SIZE" +devices.size());
+		Service cyberService = null;
+		while (e.hasMoreElements()) {
+			OSGiDeviceInfo deviceinfo = (OSGiDeviceInfo) e.nextElement();
+			UPnPDevice device = deviceinfo.getOSGiDevice();
+			UPnPService[] services = (UPnPService[]) device.getServices();
+			UPnPServiceImpl[] servicesImpl = new UPnPServiceImpl[services.length];
+			for (int i = 0; i < servicesImpl.length; i++) {
+				servicesImpl[i] = (UPnPServiceImpl) services[i];
 			}
-
-			for (int i = 0; i < listeners.length; i++) {
-				UPnPEventListener listener = (UPnPEventListener) context
-						.getService(listeners[i]);
-				Filter filter = (Filter) listeners[i]
-						.getProperty(UPnPEventListener.UPNP_FILTER);
-				if (filter == null) {
-					for (int j = 0; j < eventedSers.size(); j++) {
-						Service ser = (Service) eventedSers.elementAt(j);
-						subQueue.enqueue(new FirstMessage(ser, listener));
-					}
-				} else {
-					for (int j = 0; j < eventedSers.size(); j++) {
-						Service ser = (Service) eventedSers.elementAt(j);
-						serviceID = ser.getServiceID();
-						serviceType = ser.getServiceType();
-						hash.put(UPnPService.ID, serviceID);
-						hash.put(UPnPService.TYPE, serviceType);
-						boolean bool = filter.match(hash);
-						if (bool) {
-							subQueue.enqueue(new FirstMessage(ser, listener));
-						}
-
+			for (int i = 0; i < servicesImpl.length; i++) {
+				cyberService = servicesImpl[i].getCyberService();
+				boolean bool = cyberService.isSubscribed();
+				if (bool) {
+					if (cyberService.getSID().equals(sid)) {
+						return cyberService;
 					}
 				}
-
 			}
-
+			//System.out.println("Device NOT MATCHED " +device.getDescriptions(null).get(UPnPDevice.ID));
+		}
 		}
+		
+		return null;
 	}
+	  
+    
+
+     
 
 //	public Hashtable getWaitingEvents() {
 //		return waitingEvents;
@@ -647,6 +548,14 @@
 //		service.clearSID();
 //		return false;
 	}
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.cybergarage.upnp.ControlPoint#removeExpiredDevices()
+	 *  
+	 */
+	
+	
 
 
 }



Mime
View raw message