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
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@608549 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java b/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
index 7bea4fd..af090ba 100644
--- a/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
+++ b/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/ExporterUPnPEventListener.java
@@ -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());
}
}
}
diff --git a/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java b/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
index 7e5509a..a1dffb2 100644
--- a/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
+++ b/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/importer/core/MyCtrlPoint.java
@@ -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));
diff --git a/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java b/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
index 49ba4ec..c2fe6d5 100644
--- a/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
+++ b/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
@@ -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);
}
diff --git a/upnp/pom.xml b/upnp/pom.xml
index 2dfdd55..cb4a705 100644
--- a/upnp/pom.xml
+++ b/upnp/pom.xml
@@ -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>
diff --git a/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java b/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
index 1963b59..f28ea45 100644
--- a/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
+++ b/upnp/samples/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/statevariables/StatusStateVariable.java
@@ -97,6 +97,6 @@
}
public Object getCurrentValue() {
- return Boolean.valueOf(model.getStatus());
+ return new Boolean(model.getStatus());
}
}
diff --git a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
index a8c249d..44772c0 100644
--- a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
+++ b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/ClockDevice.java
@@ -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)));
}
}
diff --git a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
index 9719aa2..752028e 100644
--- a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
+++ b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/SetTimeAction.java
@@ -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;
diff --git a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
index 9c27db0..6985f0f 100644
--- a/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
+++ b/upnp/samples/clock/src/main/java/org/apache/felix/upnp/sample/clock/TimeStateVariable.java
@@ -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());
}
}
diff --git a/upnp/samples/pom.xml b/upnp/samples/pom.xml
index 65e8278..3f0b6db 100644
--- a/upnp/samples/pom.xml
+++ b/upnp/samples/pom.xml
@@ -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>