You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by le...@apache.org on 2008/01/04 16:14:05 UTC
svn commit: r608884 - in /felix/trunk/upnp:
basedriver/src/main/java/org/apache/felix/upnp/basedriver/
basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/
basedriver/src/main/java/org/apache/felix/upnp/basedriver/util/
extra/src/main/java...
Author: lenzi
Date: Fri Jan 4 07:14:05 2008
New Revision: 608884
URL: http://svn.apache.org/viewvc?rev=608884&view=rev
Log:
ExporterUPnPEventListener, UPnPEventNotifier reverting changes in order to follow the specification proposed by Javadoc (FELIX-447)
Fixed blocking compilation issue
Modified:
felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/Activator.java
felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/BuildDevice.java
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/util/Constants.java
felix/trunk/upnp/extra/src/main/java/org/apache/felix/upnp/extra/util/UPnPEventNotifier.java
Modified: felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/Activator.java?rev=608884&r1=608883&r2=608884&view=diff
==============================================================================
--- felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/Activator.java (original)
+++ felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/Activator.java Fri Jan 4 07:14:05 2008
@@ -23,6 +23,7 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceRegistration;
import org.apache.felix.upnp.basedriver.controller.DevicesInfo;
@@ -38,21 +39,22 @@
import org.apache.felix.upnp.basedriver.importer.core.event.thread.Notifier;
import org.apache.felix.upnp.basedriver.importer.core.event.thread.SubScriber;
import org.apache.felix.upnp.basedriver.tool.Logger;
+import org.apache.felix.upnp.basedriver.util.Converter;
/*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class Activator implements BundleActivator {
- private final static String BASEDRIVER_LOG_PROP = "felix.upnpbase.log";
- private final static String EXPORTER_ENABLED_PROP = "felix.upnpbase.exporter.enabled";
- private final static String IMPORTER_ENABLED_PROP = "felix.upnpbase.importer.enabled";
- private final static String NET_ONLY_IPV4_PROP = "felix.upnpbase.cyberdomo.net.onlyIPV4";
- private final static String NET_ONLY_IPV6_PROP = "felix.upnpbase.cyberdomo.net.onlyIPV6";
- private final static String NET_USE_LOOPBACK_PROP = "felix.upnpbase.cyberdomo.net.loopback";
- private final static String CYBERDOMO_LOG_PROP = "felix.upnpbase.cyberdomo.log";
+ public final static String BASEDRIVER_LOG_PROP = "felix.upnpbase.log";
+ public final static String CYBERDOMO_LOG_PROP = "felix.upnpbase.cyberdomo.log";
+ public final static String EXPORTER_ENABLED_PROP = "felix.upnpbase.exporter.enabled";
+ public final static String IMPORTER_ENABLED_PROP = "felix.upnpbase.importer.enabled";
+ public final static String NET_ONLY_IPV4_PROP = "felix.upnpbase.cyberdomo.net.onlyIPV4";
+ public final static String NET_ONLY_IPV6_PROP = "felix.upnpbase.cyberdomo.net.onlyIPV6";
+ public final static String NET_USE_LOOPBACK_PROP = "felix.upnpbase.cyberdomo.net.loopback";
- public static BundleContext bc;
+ public static BundleContext bc;
public static Logger logger;
private RootDeviceExportingQueue queue;
private RootDeviceListener producerDeviceToExport;
@@ -65,7 +67,14 @@
private SubscriptionQueue subQueue;
private Monitor monitor;
private DriverControllerImpl drvController;
- private ServiceRegistration drvControllerRegistrar;
+ private ServiceRegistration drvControllerRegistrar;
+
+ private boolean useExporter = true;
+ private boolean useImporter = true;
+
+ private boolean useOnlyIPV4 = true;
+ private boolean useOnlyIPV6 = false;
+ private boolean useLoopback = false;
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
@@ -75,86 +84,18 @@
Activator.bc = context;
- //
- // Debugger configuration
- //
- String levelStr = getPropertyDefault(context,BASEDRIVER_LOG_PROP,"2");
- Activator.logger = new Logger(levelStr);
-
- String cyberLog = getPropertyDefault(context,CYBERDOMO_LOG_PROP,"false");
- Activator.logger.setCyberDebug(cyberLog);
-
-
- //
- // NET configuration
- //
- String useOnlyIPV4 = getPropertyDefault(context,NET_ONLY_IPV4_PROP,"true");
- if (useOnlyIPV4.equalsIgnoreCase("true"))
- UPnP.setEnable(UPnP.USE_ONLY_IPV4_ADDR);
- else
- UPnP.setDisable(UPnP.USE_ONLY_IPV4_ADDR);
-
- String useOnlyIPV6 = getPropertyDefault(context,NET_ONLY_IPV6_PROP,"false");
- if (useOnlyIPV6.equalsIgnoreCase("true"))
- UPnP.setEnable(UPnP.USE_ONLY_IPV6_ADDR);
- else
- UPnP.setDisable(UPnP.USE_ONLY_IPV6_ADDR);
-
- String useLoopback = getPropertyDefault(context,NET_USE_LOOPBACK_PROP,"false");
- if (useLoopback.equalsIgnoreCase("true"))
- UPnP.setEnable(UPnP.USE_LOOPBACK_ADDR);
- else
- UPnP.setDisable(UPnP.USE_LOOPBACK_ADDR);
-
- //
- // Exporter configuration
- //
- String useExporter = getPropertyDefault(context,EXPORTER_ENABLED_PROP,"true");
- if (useExporter.equalsIgnoreCase("true")){
- //Setting up Base Driver Exporter
- this.queue = new RootDeviceExportingQueue();
- this.producerDeviceToExport = new RootDeviceListener(queue);
- producerDeviceToExport.activate();
- consumerDeviceToExport = new ThreadExporter(queue);
- new Thread(consumerDeviceToExport, "upnp.basedriver.Exporter").start();
- }
-
- //
- // Importer configuration
- //
- String useImporter = getPropertyDefault(context,IMPORTER_ENABLED_PROP,"true");
- if (useImporter.equalsIgnoreCase("true")){
- //Setting up Base Driver Importer
- this.notifierQueue = new NotifierQueue();
- this.subQueue = new SubscriptionQueue();
- ctrl = new MyCtrlPoint(context, subQueue, notifierQueue);
-
- //Enable CyberLink re-new for Event
- ctrl.setNMPRMode(true);
-
- this.monitor=new Monitor();
- this.notifier = new Notifier(notifierQueue,monitor);
- this.subScriber = new SubScriber(ctrl, subQueue,monitor);
-
- ctrl.start();
- subScriber.start();
- notifier.start();
- }
-
+ doInitProperties();
+
+ doInitUPnPStack();
+
+ doInitExporter();
+
+ doInitImporter();
+
doControllerRegistration();
}
- private void doControllerRegistration() {
- drvController = new DriverControllerImpl(ctrl);
- drvControllerRegistrar = bc.registerService(
- new String[]{
- DriverController.class.getName(),
- DevicesInfo.class.getName()},
- drvController,
- null
- );
- }
/**
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
@@ -189,4 +130,150 @@
return value;
}
+
+
+ /**
+ * Method used for initilizing the Import component of the UPnP Base Driver
+ *
+ * @since 0.3
+ */
+ private void doInitImporter() {
+ if (!useImporter) return;
+
+
+ //Setting up Base Driver Importer
+ this.notifierQueue = new NotifierQueue();
+ this.subQueue = new SubscriptionQueue();
+ ctrl = new MyCtrlPoint(Activator.bc, subQueue, notifierQueue);
+
+ //Enable CyberLink re-new for Event
+ ctrl.setNMPRMode(true);
+
+ this.monitor=new Monitor();
+ this.notifier = new Notifier(notifierQueue,monitor);
+ this.subScriber = new SubScriber(ctrl, subQueue,monitor);
+
+ ctrl.start();
+ subScriber.start();
+ notifier.start();
+ }
+
+ /**
+ /**
+ * Method used for initilizing the Exporter component of the UPnP Base Driver
+ * @throws InvalidSyntaxException
+ *
+ * @since 0.3
+ * @throws InvalidSyntaxException
+ */
+ private void doInitExporter() throws InvalidSyntaxException {
+ if (!useExporter) return;
+
+
+ //Setting up Base Driver Exporter
+ this.queue = new RootDeviceExportingQueue();
+ this.producerDeviceToExport = new RootDeviceListener(queue);
+ producerDeviceToExport.activate();
+ consumerDeviceToExport = new ThreadExporter(queue);
+ new Thread(consumerDeviceToExport, "upnp.basedriver.Exporter").start();
+
+ }
+
+ /**
+ * Method used for initilizing the UPnP SDK component used by the UPnP Base Driver
+ *
+ * @since 0.3
+ */
+ private void doInitUPnPStack() {
+
+ if (useOnlyIPV4) UPnP.setEnable(UPnP.USE_ONLY_IPV4_ADDR);
+ else UPnP.setDisable(UPnP.USE_ONLY_IPV4_ADDR);
+
+ if (useOnlyIPV6) UPnP.setEnable(UPnP.USE_ONLY_IPV6_ADDR);
+ else UPnP.setDisable(UPnP.USE_ONLY_IPV6_ADDR);
+
+ if (useLoopback) UPnP.setEnable(UPnP.USE_LOOPBACK_ADDR);
+ else UPnP.setDisable(UPnP.USE_LOOPBACK_ADDR);
+
+ }
+
+ /**
+ * Method used for initilizing the general properties of the UPnP Base Driver
+ *
+ * @since 0.3
+ */
+ private void doInitProperties() {
+
+ //
+ // Debugger configuration
+ //
+ String levelStr = getPropertyDefault(Activator.bc,BASEDRIVER_LOG_PROP,"2");
+ Activator.logger = new Logger(levelStr);
+
+ String cyberLog = getPropertyDefault(Activator.bc,CYBERDOMO_LOG_PROP,"false");
+ Activator.logger.setCyberDebug(cyberLog);
+
+ //
+ // NET configuration
+ //
+ try {
+ useOnlyIPV4 = ((Boolean) Converter.parseString(
+ getPropertyDefault(Activator.bc,NET_ONLY_IPV4_PROP,"true"),"boolean"
+ )).booleanValue();
+ } catch (Exception e) {
+ logger.WARNING(NET_ONLY_IPV4_PROP+" initialized with wrong value, using default "+useOnlyIPV4);
+ }
+
+ try {
+ useOnlyIPV6 = ((Boolean) Converter.parseString(
+ getPropertyDefault(Activator.bc,NET_ONLY_IPV6_PROP,"false"),"boolean"
+ )).booleanValue();
+ } catch (Exception e) {
+ logger.WARNING(NET_ONLY_IPV6_PROP+" initialized with wrong value, using default "+useOnlyIPV6);
+ }
+
+ try {
+ useLoopback = ((Boolean) Converter.parseString(
+ getPropertyDefault(Activator.bc,NET_USE_LOOPBACK_PROP,"false"),"boolean"
+ )).booleanValue();
+ } catch (Exception e) {
+ logger.WARNING(NET_USE_LOOPBACK_PROP+" initialized with wrong value, using default "+useLoopback);
+ }
+
+ //
+ // Exporter configuration
+ //
+ try {
+ useExporter = ((Boolean) Converter.parseString(
+ getPropertyDefault(Activator.bc,EXPORTER_ENABLED_PROP,"true"),"boolean"
+ )).booleanValue();
+ } catch (Exception e) {
+ logger.WARNING(EXPORTER_ENABLED_PROP+" initialized with wrong value, using default "+useExporter);
+ }
+
+ //
+ // Importer configuration
+ //
+ try {
+ useImporter = ((Boolean) Converter.parseString(
+ getPropertyDefault(Activator.bc,IMPORTER_ENABLED_PROP,"true"),"boolean"
+
+ )).booleanValue();
+ } catch (Exception e) {
+ logger.WARNING(IMPORTER_ENABLED_PROP+" initialized with wrong value, using default "+useImporter);
+ }
+ }
+
+ private void doControllerRegistration() {
+ drvController = new DriverControllerImpl(ctrl);
+ drvControllerRegistrar = bc.registerService(
+ new String[]{
+ DriverController.class.getName(),
+ DevicesInfo.class.getName()},
+ drvController,
+ null
+ );
+ }
+
+
}
Modified: felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/BuildDevice.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/BuildDevice.java?rev=608884&r1=608883&r2=608884&view=diff
==============================================================================
--- felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/BuildDevice.java (original)
+++ felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/export/BuildDevice.java Fri Jan 4 07:14:05 2008
@@ -262,7 +262,7 @@
public static Device createCyberLinkDevice(ServiceReference sr){
Node root = buildRootNode();
- Device devUPnP = buildRootDeviceNode(root,sr);
+ Device devUPnP = buildRootDeviceNode(root,sr);
return devUPnP;
}
}
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=608884&r1=608883&r2=608884&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 Fri Jan 4 07:14:05 2008
@@ -49,35 +49,29 @@
* @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();
while (e.hasMoreElements()) {
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");
+ + key.getClass().getName() + " instead of " + String.class.getName()
+ + " as specified by Javadoc");
continue;
}
Modified: felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/util/Constants.java
URL: http://svn.apache.org/viewvc/felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/util/Constants.java?rev=608884&r1=608883&r2=608884&view=diff
==============================================================================
--- felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/util/Constants.java (original)
+++ felix/trunk/upnp/basedriver/src/main/java/org/apache/felix/upnp/basedriver/util/Constants.java Fri Jan 4 07:14:05 2008
@@ -28,5 +28,5 @@
* The value of the does not carry any mean. <br>
* The name of the property is "UPnP.device.import".
*/
- public static final String UPNP_IMPORT = "UPnP.device.imported";
+ public final static String UPNP_IMPORT = "UPnP.device.imported";
}
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=608884&r1=608883&r2=608884&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 Fri Jan 4 07:14:05 2008
@@ -26,7 +26,6 @@
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;
@@ -173,19 +172,10 @@
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
- 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();
Properties events = new Properties();
- events.put(variable,value);
+ events.put(property,value);
doNotify(events);
}