felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r608549 - in /felix/trunk/upnp: ./ basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/ extra/ extra/src/main/java/org/apache/felix/upnp/extra/util/ sampl...
Date Thu, 03 Jan 2008 16:29:45 GMT
Author: lenzi
Date: Thu Jan  3 08:29:44 2008
New Revision: 608549

URL: http://svn.apache.org/viewvc?rev=608549&view=rev
Log:
Refined svn:ignore properties

POM modified in order to compile bundle as default

Fixed problem in UPnPEventNotifier which was sending event containg pair <String name,String
value> instead of <UPnPStateVariable, Object value> see OSGi Compendium R4 pag. 257
ExporterUPnPEventListener was aspecting pair <String name, Object value> instead of
<UPnPStateVariable, Object value> so I have changed it to be complaint to OSGi specification
but also legacy compatible
Fixed Service leak in UPnP Base Driver see class MyCtrlPoint
Fixed compilation issue with Java 6 in
TimeStateVariable was returing wrong value with metho getCurrentValue() and was not compatible
with Java6
SetTimeAction was not updating the time and it was not notifing the change of the UPnP statevariable
ClockDevice was badly notifing UPnP state variable changeing with pair <String name,String
value> instead of <UPnPStateVariable, Object value>  
StatusStateVariable was not compatible with Java6

Modified:
    felix/trunk/upnp/   (props changed)
    felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
    felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
    felix/trunk/upnp/extra/   (props changed)
    felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
    felix/trunk/upnp/pom.xml
    felix/trunk/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
    felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
    felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
    felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
    felix/trunk/upnp/samples/pom.xml
    felix/trunk/upnp/tester/   (props changed)

Propchange: felix/trunk/upnp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan  3 08:29:44 2008
@@ -0,0 +1,4 @@
+.project
+.classpath
+bin
+.settings

Modified: felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
(original)
+++ felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
Thu Jan  3 08:29:44 2008
@@ -29,7 +29,9 @@
 import org.cybergarage.upnp.StateVariable;
 
 import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPStateVariable;
 
+import org.apache.felix.upnp.basedriver.Activator;
 import org.apache.felix.upnp.basedriver.util.Converter;
 
 /* 
@@ -47,23 +49,42 @@
 	 * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String,
java.util.Dictionary)
 	 */
 	public void notifyUPnPEvent(String deviceId, String serviceId,Dictionary events) {
-		Device dAux = null;
-		if(d.getUDN().equals(deviceId)){
-			dAux=d;
-		}else{
-			dAux= d.getDevice(deviceId);
-		}
-		Service s = dAux.getService(serviceId);
+        Device dAux = null;
+        if(d.getUDN().equals(deviceId)){
+            dAux=d;
+        }else{
+            dAux= d.getDevice(deviceId);
+        }
+        Service s = dAux.getService(serviceId);
 		// fix 2/9/2004 francesco 
 		Enumeration e = events.keys();
-		StateVariable sv;
 		while (e.hasMoreElements()) {
-			String name = (String) e.nextElement();
-			sv=s.getStateVariable(name);
-			//sv.setValue((String) events.get(name));
+            StateVariable sv;
+            String dataType;
+            String name;
+            //TODO Keep for compatibility? The OSGi compendium R4 pag. 257 requires pair
containg <UPnPStateVariable,Object value> instead of <String name,Object value>
+            Object key = e.nextElement();
+            if(key instanceof String){
+                name=(String) key;
+                sv=s.getStateVariable(name);
+                dataType=sv.getDataType();
+            }else if(key instanceof UPnPStateVariable){
+                UPnPStateVariable variable = (UPnPStateVariable) key;
+                name=variable.getName();
+                dataType=variable.getUPnPDataType();
+                sv=s.getStateVariable(name);
+            }else{
+                Activator.logger.ERROR(deviceId + " notified the change in the StateVariable
of " 
+                                       + serviceId + " but the key Java type contained in
the Dictiories was " 
+                                       + key.getClass().getName() + " instead of " + UPnPStateVariable.class.getName()
+                                       + " as specified by OSGi Compendium Release 4 pag.
257");
+                continue;
+            }
+            
 			try {
-				sv.setValue(Converter.toString(events.get(name),sv.getDataType()));
+				sv.setValue(Converter.toString(events.get(key),dataType));
 			} catch (Exception ignored) {
+                Activator.logger.ERROR("UPnP Base Driver Exporter: error converting datatype
while sending event, exception message follows:"+ignored.getMessage());
 			}
 		}
 	}

Modified: felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
(original)
+++ felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
Thu Jan  3 08:29:44 2008
@@ -485,7 +485,6 @@
 						dic.put(UPnPDevice.ID, device.getDescriptions(null).get(UPnPDevice.UDN));
 						dic.put(UPnPDevice.TYPE, device.getDescriptions(null).get(UPnPDevice.TYPE));
 						UPnPService[] services = device.getServices();
-						//TODO do I have to do the unget of UPnPDevice??
 						if (services != null) {
 							for (int j = 0; j < services.length; j++) {
 								dic.put(UPnPService.ID, services[j].getId());
@@ -508,6 +507,7 @@
 								}
 							}
 						}
+                        context.ungetService(devicesRefs[i]);
 					}
 				}
 			} else {/* obj==null (interested in all devices) */
@@ -526,7 +526,6 @@
 						UPnPDevice device = (UPnPDevice) context
 								.getService(devicesRefs[i]);
 						UPnPService[] services = device.getServices();
-						//do I have to do the unget of UPnPDevice??
 						if (services != null) {
 							for (int j = 0; j < services.length; j++) {
 								UPnPStateVariable[] stateVars = services[j]
@@ -548,6 +547,7 @@
 								}
 							}
 						}
+                        context.ungetService(devicesRefs[i]);
 					}
 				}
 			}
@@ -584,7 +584,6 @@
 								.get(UPnPDevice.TYPE));
 						UPnPService[] services = device.getServices();
 
-						//do I have to do the unget of UPnPDevice??
 						if (services != null) {
 							for (int j = 0; j < services.length; j++) {
 								dic.put(UPnPService.ID, services[j].getId());
@@ -611,6 +610,7 @@
 								}
 							}//for services
 						}//services ==null
+						context.ungetService(devicesRefs[i]);
 					}//for devicesRefs
 					ListenerModified msg = new ListenerModified(newServices,
 							listener);
@@ -634,7 +634,6 @@
 						UPnPDevice device = (UPnPDevice) context
 								.getService(devicesRefs[i]);
 						UPnPService[] services = device.getServices();
-						//do I have to do the unget of UPnPDevice??
 						if (services != null) {
 							for (int j = 0; j < services.length; j++) {
 								UPnPStateVariable[] stateVars = services[j]
@@ -653,6 +652,7 @@
 								}//hasEventedvars
 							}//for services
 						}//services !=null
+                        context.ungetService(devicesRefs[i]);
 					}//for devicesRefs
 					subQueue
 							.enqueue(new ListenerModified(newServices, listener));

Propchange: felix/trunk/upnp/extra/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Jan  3 08:29:44 2008
@@ -1,3 +1,4 @@
+.checkstyle
 classes
 target
 *.log

Modified: felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
(original)
+++ felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
Thu Jan  3 08:29:44 2008
@@ -26,6 +26,7 @@
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.felix.upnp.basedriver.Activator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -172,12 +173,19 @@
 	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
 	 */
 	public void propertyChange(PropertyChangeEvent evt) {
-		
-		String property = evt.getPropertyName();
+        UPnPStateVariable variable;
+        String property = evt.getPropertyName();
+        try{
+            variable = (UPnPStateVariable) evt.getSource();
+        }catch(ClassCastException ex){
+            Activator.logger.ERROR("Trying to nofied the change of a UPnPStateVariable but
event source Java type is "
+                                   +evt.getSource().getClass().getName()+" instead of "+UPnPStateVariable.class.getName()
+                                   +" so "+property+"it's been SKIPPED");
+            return;
+        }
 		Object value = evt.getNewValue();
-		String valueString = value.toString();
-		Properties events = new Properties();
-		events.put(property,valueString);
+		Properties events = new Properties();		
+        events.put(variable,value);
 		doNotify(events);
 	}
 

Modified: felix/trunk/upnp/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/pom.xml?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/pom.xml (original)
+++ felix/trunk/upnp/pom.xml Thu Jan  3 08:29:44 2008
@@ -45,5 +45,19 @@
           <module>samples</module>
       </modules>
     </profile>
+    <profile>
+      <id>default</id>
+      <activation>
+        <property>
+          <name>!packaging</name>
+        </property>
+      </activation>
+      <modules>
+          <module>extra</module>
+          <module>basedriver</module>
+          <module>tester</module>
+          <module>samples</module>
+      </modules>
+    </profile>
   </profiles>
 </project>

Modified: felix/trunk/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
(original)
+++ felix/trunk/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
Thu Jan  3 08:29:44 2008
@@ -97,6 +97,6 @@
 	}
 
 	public Object getCurrentValue() {
-		return Boolean.valueOf(model.getStatus());
+		return new Boolean(model.getStatus());
 	}
 }

Modified: felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
(original)
+++ felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
Thu Jan  3 08:29:44 2008
@@ -21,6 +21,7 @@
 
 
 import java.beans.PropertyChangeEvent;
+import java.util.Calendar;
 import java.util.Dictionary;
 import java.util.Properties;
 
@@ -28,6 +29,7 @@
 import org.osgi.service.upnp.UPnPDevice;
 import org.osgi.service.upnp.UPnPIcon;
 import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
 
 import org.apache.felix.upnp.extra.util.UPnPEventNotifier;
 
@@ -38,7 +40,7 @@
 	private TimerService timerService;
 	private UPnPService[] services;
 	private Dictionary dictionary;
-	UPnPEventNotifier notifier;
+	public static UPnPEventNotifier notifier = null;
 	
 	public ClockDevice(BundleContext context) {
 		this.context=context;
@@ -130,8 +132,10 @@
 	 */
 	public void update() {
 		Clock clock = Clock.getInstance();
-		String timeStr = clock.toString();
-		notifier.propertyChange(new PropertyChangeEvent(this,"Time","",timeStr));
+		Calendar cal = clock.getCalendar();
+        long time = cal.getTime().getTime();
+        UPnPStateVariable variable =  timerService.getStateVariable("Time");
+		notifier.propertyChange(new PropertyChangeEvent(variable,"Time",new Long(time-1000),new
Long(time)));
 	}
 	
 }

Modified: felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
(original)
+++ felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
Thu Jan  3 08:29:44 2008
@@ -19,6 +19,7 @@
 
 package org.apache.felix.upnp.sample.clock;
 
+import java.beans.PropertyChangeEvent;
 import java.util.Dictionary;
 
 import org.osgi.service.upnp.UPnPAction;
@@ -85,9 +86,10 @@
 	 * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
 	 */
 	public Dictionary invoke(Dictionary args) throws Exception {
-		//Date value = (Date) args.get(NEW_TIME_VALUE);
-		long l = ((Long) args.get(NEW_TIME_VALUE)).longValue();
-		((TimeStateVariable) time).setCurrentTime(l);
+		Long newValue = (Long) args.get(NEW_TIME_VALUE);
+        Long oldValue = (Long) ((TimeStateVariable) time).getCurrentValue();
+		((TimeStateVariable) time).setCurrentTime(newValue.longValue());
+        ClockDevice.notifier.propertyChange(new PropertyChangeEvent(time,"Time",oldValue,newValue));
       
 		args.remove(NEW_TIME_VALUE);
 		args.put(NEW_RESULT_VALUE,((TimeStateVariable) time).getCurrentTime());
 		return args;

Modified: felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
(original)
+++ felix/trunk/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
Thu Jan  3 08:29:44 2008
@@ -18,6 +18,8 @@
  */
 
 package org.apache.felix.upnp.sample.clock;
+import java.util.Date;
+
 import org.osgi.service.upnp.UPnPLocalStateVariable;
 
 public class TimeStateVariable implements UPnPLocalStateVariable{
@@ -98,11 +100,11 @@
 		return clock.getTimeString();
 	}
 	
-	public void setCurrentTime(long milliseconds){
-		clock.getCalendar().setTimeInMillis(milliseconds);
+	public void setCurrentTime(long milliseconds){        
+		clock.getCalendar().setTime(new Date(milliseconds));
 	}
 
 	public Object getCurrentValue() {
-		return getCurrentTime();
+		return new Long(clock.getCalendar().getTime().getTime());
 	}
 }

Modified: felix/trunk/upnp/samples/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/samples/pom.xml?rev=608549&r1=608548&r2=608549&view=diff
==============================================================================
--- felix/trunk/upnp/samples/pom.xml (original)
+++ felix/trunk/upnp/samples/pom.xml Thu Jan  3 08:29:44 2008
@@ -44,5 +44,18 @@
           <module>tv</module>
       </modules>
     </profile>
+    <profile>
+      <id>default</id>
+      <activation>
+        <property>
+          <name>!packaging</name>
+        </property>
+      </activation>
+      <modules>
+          <module>binarylight</module>
+          <module>clock</module>
+          <module>tv</module>
+      </modules>
+    </profile>
   </profiles>
 </project>

Propchange: felix/trunk/upnp/tester/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Jan  3 08:29:44 2008
@@ -1,3 +1,4 @@
+.checkstyle
 classes
 target
 *.log



Mime
View raw message