You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/06/26 15:22:34 UTC
svn commit: r550801 - in /felix/sandbox/donsez/upnp.ogd.cmd: ./ doc/ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/upnp/
src/main/java/org/apache/felix/upnp/ogd...
Author: donsez
Date: Tue Jun 26 06:22:32 2007
New Revision: 550801
URL: http://svn.apache.org/viewvc?view=rev&rev=550801
Log:
creation of the upnp.ogd.cmd bundle : a command to remotely manage UPnP OSGi Gateway Device
Added:
felix/sandbox/donsez/upnp.ogd.cmd/
felix/sandbox/donsez/upnp.ogd.cmd/.classpath (with props)
felix/sandbox/donsez/upnp.ogd.cmd/.project (with props)
felix/sandbox/donsez/upnp.ogd.cmd/doc/
felix/sandbox/donsez/upnp.ogd.cmd/doc/ogdcmd.png (with props)
felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html (with props)
felix/sandbox/donsez/upnp.ogd.cmd/pom.xml (with props)
felix/sandbox/donsez/upnp.ogd.cmd/src/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java (with props)
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java (with props)
felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java (with props)
Added: felix/sandbox/donsez/upnp.ogd.cmd/.classpath
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/.classpath?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/.classpath (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/.classpath Tue Jun 26 06:22:32 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="OSGI_CORE"/>
+ <classpathentry kind="var" path="OSGI_COMPENDIUM"/>
+ <classpathentry kind="lib" path="E:/Felix-Dist/felix-svn/trunk/shell/target/org.apache.felix.shell-0.9.0-incubator-SNAPSHOT.jar"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/.classpath
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/.project
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/.project?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/.project (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/.project Tue Jun 26 06:22:32 2007
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>upnpgendevice</name>
+ <comment></comment>
+ <projects>
+ <project>oscar</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/.project
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/doc/ogdcmd.png
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/doc/ogdcmd.png?view=auto&rev=550801
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/doc/ogdcmd.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html Tue Jun 26 06:22:32 2007
@@ -0,0 +1,119 @@
+<html>
+<head>
+<title>OSGi Gateway UPnP Device (OGD) Command</title>
+</head>
+<body>
+
+<!-- Start of Felix Bundle Documentation -->
+<hr width="100%" size="2">
+<h1><i><a name="upnp.ogd.cmd"></a><font color="#0000aa">OSGi Gateway UPnP Device (OGD) Command</font></i></h1>
+
+<p>
+<b>Description</b><br>
+Enables to manage remote gateways with UPnP.
+Managed gateways must provide a device with type <code>urn:osgi-org:device:OSGiGatewayDevice:1</code>.
+This device is provided by the bundle <a href="http://www.apache.org/~donsez/dev/osgi/upnp.ogd/readme.html">upnp.ogd</a>.
+<br>For more details on how to use this bundle, refer to the /doc/readme.html file embedded in the bundle jarfile.<br>
+</p>
+
+<p>
+<b>Contributors</b><br>
+<ul>
+<li>Author:<a href="dev@felix.apache.org">Felix Project Team</a></li>
+</ul>
+</p>
+
+<p>
+<b>License</b><br>
+ASL2
+</p>
+
+<p>
+<b>Services</b><br>
+<ul>
+<li>org.osgi.service.upnp.UPnPEventListener</li>
+<li>org.apache.felix.shell.Command</li>
+</ul>
+</p>
+
+<p>
+<b>Properties</b><br>
+<ul>
+ <li>TODO</li>
+</ul>
+</p>
+
+<p><b>Requirements</b><br>
+ <li>org.osgi.service.upnp;specification-version=1.1.0</li>
+ <li>org.apache.felix.upnp.devicegen.util</li>
+ <li>org.apache.felix.upnp.devicegen.holder</li>
+ <li>org.osgi.util.tracker; specification-version=1.1.0</li>
+ <li>org.apache.felix.shell</li>
+</p>
+
+<!-- End of Felix Bundle Documentation -->
+
+
+<!-- End of OSCAR Bundle Documentation -->
+
+<hr width="100%" size="2">
+
+<!-- Start of extra information -->
+
+<p>
+<b>Download</b><br>
+<ul>
+<li><a href='http://www.apache.org/~donsez/dev/osgi/upnp.ogd.cmd/'>Bundle binaries</a></li>
+<li><a href='http://www.apache.org/~donsez/dev/osgi/upnp.ogd.cmd/s'>Bundle sources</a></li>
+<li><a href='http://www.apache.org/~donsez/dev/osgi/upnp.ogd.cmd/readme.html'>The latest version of this documentation</a></li>
+</ul>
+</p>
+
+<p>
+<b>Build</b><br>
+<li>build with <code>mvn clean install</code></li>
+</ol>
+</p>
+
+<p>
+<b>Run demo</b><br>
+Launch commands listed in the demo script available <a href="http://www.apache.org/~donsez/dev/osgi/script/upnpogd.txt">here</a>
+</p>
+
+<p id="versions">
+<b>Versions history</b><br>
+<ul>
+<li>0.1.0, March 19, 2006 released by Didier Donsez</li>
+<li>0.2.0, April 2007</li>
+</ul>
+</p>
+
+<p>
+<b>TODO (suggestions and contributions are welcome)</b><br>
+<ul>
+<li>?</li>
+</ul>
+</p>
+
+
+<p>
+<b>Tested gateways</b><br>
+<ul>
+<li><a href="http//oscar.objectweb.org/">Oscar</a> (done)</li>
+<li>Felix (done)</li>
+<li><a href="http://www.knopflerfish.org">Knopflerfish OSGi</a> (to do)</li>
+<li>Equinox (to do)</li>
+</ul>
+</p>
+
+<p id="links">
+<b>Links</b><br>
+<ul>
+<li><a href="http://www.apache.org/~donsez/dev/osgi/upnp.ogd/readme.html">The UPnPOGD Device</a></li>
+<li><a href="http://www.apache.org/~donsez/dev/osgi/">My Bundle Farm</a></li>
+<li><a href="http://www.upnp.org">UPnP Forum</a></li>
+</ul>
+</p>
+
+</body>
+</html>
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/pom.xml?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/pom.xml (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/pom.xml Tue Jun 26 06:22:32 2007
@@ -0,0 +1,99 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+
+ <properties>
+ <repositoryLocation>http://www-adele.imag.fr/users/Didier.Donsez/dev/felix/sandbox/</repositoryLocation>
+ <description>provides a shell command to list/manage OGD devices.</description>
+ </properties>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.9.0-incubator-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>OGD UPnP Device Command</name>
+ <artifactId>org.apache.felix.upnp.ogd.cmd</artifactId>
+ <description>${description}</description>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.shell</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
+ <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+
+ <Import-Service>org.osgi.service.upnp.UPnPDevice</Import-Service>
+
+ <Private-Package>${pom.artifactId}.*</Private-Package>
+ <Import-Package>*</Import-Package>
+ <Bundle-Activator>${pom.artifactId}.UPnPOGDCommand</Bundle-Activator>
+
+ <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</Bundle-DocURL>
+ <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</Bundle-Url>
+ <Bundle-Source>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
+
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Description>${description}</Bundle-Description>
+ <Bundle-Vendor>Apache Software Foundation</Bundle-Vendor>
+
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <!--
+ <repositories>
+ <repository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </pluginRepository>
+ </pluginRepositories>
+ -->
+</project>
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java Tue Jun 26 06:22:32 2007
@@ -0,0 +1,867 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.upnp.ogd.cmd;
+
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+
+/**
+ * this class implements a command to manage remote gateways using UPnP
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class UPnPOGDCommand implements Command, BundleActivator {
+
+ private final static String CMD = "ogd";
+
+ private final static String CMDSP = "ogd ";
+
+ private final static String HELP_CMD = "help";
+
+ private final static String GATEWAYS_CMD = "gateways";
+
+ private final static String BUNDLES_CMD = "bundles";
+
+ private final static String SERVICES_CMD = "services";
+
+ private final static String HEADERS_CMD = "headers";
+
+ private final static String START_CMD = "start";
+
+ private final static String STOP_CMD = "stop";
+
+ private final static String INSTALL_CMD = "install";
+
+ private final static String UNINSTALL_CMD = "uninstall";
+
+ private final static String UPDATE_CMD = "update";
+
+ private final static String LISTEN_CMD = "listen";
+
+ private final static String STOPLISTEN_CMD = "stoplisten";
+
+ BundleContext bundleContext;
+
+ ServiceRegistration commandServiceRegistration;
+
+ ServiceTracker serviceTracker;
+
+ Map/* <DeviceId,upnpogdEventListeners> */upnpogdEventListeners = new HashMap();
+
+ Map/* <DeviceId,UPnPDevice> */upnpdevices = new HashMap();
+
+ class UPnPDeviceServiceTrackerCustomizer implements
+ ServiceTrackerCustomizer {
+
+ public Object addingService(ServiceReference ref) {
+ UPnPDevice upnpdevice = (UPnPDevice) bundleContext.getService(ref);
+ String deviceId = (String) ref.getProperty(UPnPDevice.ID);
+ upnpdevices.put(deviceId, upnpdevice);
+ System.out.println(CMD + ": the gateway " + deviceId
+ + " is available");
+ return upnpdevice;
+ }
+
+ public void removedService(ServiceReference ref, Object upnpdevice) {
+ String deviceId = (String) ref.getProperty(UPnPDevice.ID);
+ upnpdevices.remove(deviceId);
+ System.out.println(CMD + ": the gateway " + deviceId
+ + " is not available");
+ // upnpogdEventListeners.remove(deviceId);
+ bundleContext.ungetService(ref);
+ }
+
+ public void modifiedService(ServiceReference ref, Object upnpdevice) {
+ // TODO Auto-generated method stub
+ }
+ }
+
+ private void startEventListener(PrintStream out, PrintStream err,
+ String deviceId) throws Exception {
+ UPnPOGDEventListener upnpogdeventlistener = (UPnPOGDEventListener) upnpogdEventListeners
+ .get(deviceId);
+ if (upnpogdeventlistener == null) {
+ upnpogdeventlistener = new UPnPOGDEventListener(deviceId);
+ upnpogdeventlistener.start(bundleContext);
+ upnpogdEventListeners.put(deviceId, upnpogdeventlistener);
+ if (out != null)
+ out.println("Listening " + deviceId);
+ } else {
+ if (err != null)
+ err.println(deviceId + " is already listened");
+ }
+ }
+
+ private void stopEventListener(PrintStream out, PrintStream err,
+ String deviceId) {
+ UPnPOGDEventListener upnpogdeventlistener = (UPnPOGDEventListener) upnpogdEventListeners
+ .remove(deviceId);
+ if (upnpogdeventlistener != null) {
+ try {
+ upnpogdeventlistener.stop(bundleContext);
+ } catch (Exception e) {
+ if (err != null)
+ e.printStackTrace(err);
+ }
+ if (out != null)
+ out.println("Stop to listen " + deviceId);
+ } else {
+ err.println(deviceId + " not listened");
+ }
+ }
+
+ private void stopAllEventListeners(PrintStream out, PrintStream err) {
+ Iterator iterator = upnpogdEventListeners.keySet().iterator();
+ while (iterator.hasNext()) {
+ String deviceId = (String) iterator.next();
+ UPnPOGDEventListener upnpogdeventlistener = (UPnPOGDEventListener) upnpogdEventListeners
+ .remove(deviceId);
+ try {
+ upnpogdeventlistener.stop(bundleContext);
+ } catch (Exception e) {
+ if (err != null)
+ e.printStackTrace(err);
+ }
+ }
+ if (out != null)
+ out.println("Stop to listen all gateways");
+ }
+
+ /**
+ * Call by the framework on bundle starting
+ *
+ * @param context
+ * Description of the Parameter
+ * @exception BundleException
+ * Description of the Exception
+ */
+ public final void start(BundleContext bundleContext) throws Exception {
+ this.bundleContext = bundleContext;
+ Filter filter = bundleContext.createFilter("(&" + "("
+ + Constants.OBJECTCLASS + "=" + UPnPDevice.class.getName()
+ + ")" + "(" + UPnPDevice.TYPE + "="
+ + UPnPOGDConstant.DEVICE_TYPE + ")" + ")");
+ serviceTracker = new ServiceTracker(bundleContext, filter,
+ new UPnPDeviceServiceTrackerCustomizer());
+ serviceTracker.open();
+ commandServiceRegistration = bundleContext.registerService(
+ Command.class.getName(), this, null);
+ }
+
+ /**
+ * Call by the framework on bundle stoping
+ *
+ * @param context
+ * Description of the Parameter
+ * @exception BundleException
+ * Description of the Exception
+ */
+ public final void stop(BundleContext context) throws Exception {
+ stopAllEventListeners(null, null);
+ commandServiceRegistration.unregister();
+ serviceTracker.close();
+ }
+
+ private boolean debug = true;
+
+ /**
+ * Description of the Method
+ *
+ * @param msg
+ * Description of the Parameter
+ */
+ public void println(String msg) {
+ if (debug) {
+ System.err.println(getClass().getName() + ":" + msg);
+ }
+ }
+
+ public String getName() {
+ return CMD;
+ }
+
+ public String getUsage() {
+ return CMD
+ + " [help|bundles|headers|services|start|stop|install|uninstall|update|listen|stoplisten]";
+ }
+
+ public String getShortDescription() {
+ return "manages remote OSGi gateways";
+ }
+
+ private void printUsage(PrintStream out, String message) {
+ StringBuffer sb = new StringBuffer();
+ if (message != null)
+ sb.append(message);
+ sb.append(getUsage()).append('\n');
+
+ sb.append(CMDSP + GATEWAYS_CMD + " : list the available gateways")
+ .append('\n');
+ sb.append(CMDSP + LISTEN_CMD + " <gwid> : listen the OSGi-related events of a gateway")
+ .append('\n');
+ sb.append(CMDSP + STOPLISTEN_CMD + " <gwid> : disable the listener about the listen gateway")
+ .append('\n');
+
+ sb.append(CMDSP + BUNDLES_CMD + " <gwid> : list all bundles of a gateway")
+ .append('\n');
+ sb.append(CMDSP + SERVICES_CMD + " <gwid> : list all services of a gateway")
+ .append('\n');
+ sb.append(CMDSP + INSTALL_CMD + " <gwid> <url> : install a bundle from an url")
+ .append('\n');
+ sb.append(CMDSP + HEADERS_CMD + " <gwid> <bid> : display the header fields of a bundle")
+ .append('\n');
+ sb.append(CMDSP + START_CMD + " <gwid> <bid> : start a bundle")
+ .append('\n');
+ sb.append(CMDSP + STOP_CMD + " <gwid> <bid> : stop a bundle")
+ .append('\n');
+ sb.append(CMDSP + UPDATE_CMD + " <gwid> <bid> : update a bundle from the default location")
+ .append('\n');
+ sb.append(CMDSP + UPDATE_CMD + " <gwid> <bid> <url> : update a bundle from an url")
+ .append('\n');
+ sb.append(CMDSP + UNINSTALL_CMD + " <gwid> <bid> : uninstall a bundle")
+ .append('\n');
+
+ out.println(sb.toString());
+ return;
+ }
+
+ public void execute(String commandline, PrintStream out, PrintStream err) {
+
+ StringTokenizer st = new StringTokenizer(commandline, " ");
+
+ if (st.countTokens() == 1) {
+ printUsage(out, null);
+ return;
+ }
+
+ // Ignore the command name.
+ st.nextToken();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, null);
+ return;
+ }
+
+ String option = st.nextToken().trim();
+
+ if (option.equals(HELP_CMD)) {
+ printUsage(out, null);
+ return;
+ } else if (option.equals(GATEWAYS_CMD)) {
+ Iterator iterator = upnpdevices.keySet().iterator();
+ int cpt = 0;
+ while (iterator.hasNext()) {
+ cpt++;
+ out.println(iterator.next());
+ }
+ out.println(cpt + " gateway(s) available");
+ return;
+
+ } else if (option.equals(LISTEN_CMD)) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ try {
+ startEventListener(out, err, deviceId);
+ } catch (Exception e) {
+ err.println(e);
+ e.printStackTrace(err);
+ return;
+ }
+ } else if (option.equals(STOPLISTEN_CMD)) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ try {
+ stopEventListener(out, err, deviceId);
+ } catch (Exception e) {
+ err.println(e);
+ e.printStackTrace(err);
+ return;
+ }
+ } else if (option.equals(BUNDLES_CMD)) {
+ bundlesCmd(out, err, st);
+ } else if (option.equals(SERVICES_CMD)) {
+ servicesCmd(out, err, st);
+ } else if (option.equals(INSTALL_CMD)) {
+ installCmd(out, err, st);
+ } else if (option.equals(HEADERS_CMD)) {
+ headersCmd(out, err, st);
+ } else if (option.equals(START_CMD)) {
+ startCmd(out, err, st);
+ } else if (option.equals(STOP_CMD)) {
+ stopCmd(out, err, st);
+ } else if (option.equals(UPDATE_CMD)) {
+ updateCmd(out, err, st);
+ } else if (option.equals(UNINSTALL_CMD)) {
+ uninstallCmd(out, err, st);
+ } else {
+ printUsage(err, "unknown or unimplemented command");
+ return;
+ }
+ }
+
+
+ void installCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleLocation is missing");
+ return;
+ }
+ String bundleLocation = st.nextToken().trim();
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("InstallBundle");
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleLocation", bundleLocation);
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ Long bundleID = (Long) result.get("BundleID");
+
+ if(bundleID==null) {
+ out.print("Bundle at location ");
+ out.print(bundleLocation);
+ out.print("was not installed on gateway ");
+ out.println(deviceId);
+
+ } else {
+ out.print("Bundle ");
+ out.print(bundleID);
+ out.print("(");
+ out.print(bundleLocation);
+ out.print(") is installed on gateway ");
+ out.println(deviceId);
+ }
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+
+ }
+
+ void startCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleId is missing");
+ return;
+ }
+ String bundleId = st.nextToken().trim();
+ long bid = Long.parseLong(bundleId);
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("StartBundle");
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleID", new Long(bid));
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print("Bundle ");
+ out.print(bid);
+ out.print(" started on gateway ");
+ out.println(deviceId);
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+
+ }
+
+ void stopCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleId is missing");
+ return;
+ }
+ String bundleId = st.nextToken().trim();
+ long bid = Long.parseLong(bundleId);
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("StopBundle");
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleID", new Long(bid));
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print("Bundle ");
+ out.print(bid);
+ out.print(" stopped on gateway ");
+ out.println(deviceId);
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+ }
+
+ void updateCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleId is missing");
+ return;
+ }
+ String bundleId = st.nextToken().trim();
+ long bid = Long.parseLong(bundleId);
+
+ String BundleLocation = null;
+ if (st.hasMoreTokens()) {
+ BundleLocation = st.nextToken().trim();
+ }
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+
+ UPnPAction upnpAction = null;
+ if(BundleLocation==null) {
+ upnpAction=upnpService.getAction("UpdateBundle");
+ } else {
+ upnpAction=upnpService.getAction("UpdateBundleWithLocation");
+ }
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleID", new Long(bid));
+ if(BundleLocation==null) {
+ parameters.put("BundleLocation", BundleLocation);
+ }
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print("Bundle ");
+ out.print(bid);
+ if(BundleLocation==null) {
+ out.print(" updated on gateway ");
+ } else {
+ out.print(" updated with location "+BundleLocation+" on gateway ");
+ }
+ out.println(deviceId);
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+
+ }
+
+ void uninstallCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleId is missing");
+ return;
+ }
+ String bundleId = st.nextToken().trim();
+ long bid = Long.parseLong(bundleId);
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("UninstallBundle");
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleID", new Long(bid));
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print("Bundle ");
+ out.print(bid);
+ out.print(" uninstalled on gateway ");
+ out.println(deviceId);
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+
+ }
+
+ void bundlesCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("ListBundles");
+
+ Dictionary parameters = new Hashtable();
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ String currentBundleList = (String) result
+ .get("CurrentBundleList");
+ // out.println(currentBundleList);
+
+ StringTokenizer bundleListSt = new StringTokenizer(
+ currentBundleList, ";");
+ while (bundleListSt.hasMoreTokens()) {
+ String _bid = bundleListSt.nextToken();
+ long bid = Long.parseLong(_bid);
+
+ UPnPAction upnpAction2 = upnpService
+ .getAction("GetBundleInfo");
+
+ Dictionary parameters2 = new Hashtable();
+ parameters2.put("BundleID", new Long(bid));
+ Dictionary result2;
+ try {
+ result2 = upnpAction2.invoke(parameters2);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print(bid);
+ out.print('\t');
+
+ out.print(result2.get("BundleState"));
+ out.print('\t');
+
+ out.print(result2.get("StartLevel"));
+ out.print('\t');
+
+ out.print(result2.get("BundleLocation"));
+ // out.print('\t');
+
+ // out.print(result2.get("HeaderNames"));
+
+ out.println();
+ }
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+ }
+
+ void headersCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "bundleId is missing");
+ return;
+ }
+ String bundleId = st.nextToken().trim();
+ long bid = Long.parseLong(bundleId);
+
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService.getAction("GetBundleInfo");
+
+ Dictionary parameters = new Hashtable();
+ parameters.put("BundleID", new Long(bid));
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ String headerNames = (String) result.get("HeaderNames");
+
+ out.print("Bundle ");
+ out.print(bid);
+ out.print(" on gateway ");
+ out.println(deviceId);
+
+ StringTokenizer headerNamesSt = new StringTokenizer(
+ headerNames, ";");
+ while (headerNamesSt.hasMoreTokens()) {
+ String headerName = headerNamesSt.nextToken();
+
+ UPnPAction upnpAction2 = upnpService
+ .getAction("GetBundleHeader");
+
+ Dictionary parameters2 = new Hashtable();
+ parameters2.put("BundleID", new Long(bid));
+ parameters2.put("HeaderName", headerName);
+ Dictionary result2;
+ try {
+ result2 = upnpAction2.invoke(parameters2);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print(headerName);
+ out.print('=');
+ out.print(result2.get("HeaderValue"));
+
+ out.println();
+ }
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+ }
+
+ void servicesCmd(PrintStream out, PrintStream err, StringTokenizer st) {
+ if (!st.hasMoreTokens()) {
+ printUsage(out, "deviceId is missing");
+ return;
+ }
+ String deviceId = st.nextToken().trim();
+
+ if (!st.hasMoreTokens()) {
+ // list all services
+ UPnPDevice upnpDevice = (UPnPDevice) upnpdevices.get(deviceId);
+ if (upnpDevice != null) {
+ UPnPService upnpService = upnpDevice
+ .getService(UPnPOGDConstant.SERVICE_ID);
+ if (upnpService == null) {
+ err.println("this device has not the "
+ + UPnPOGDConstant.SERVICE_ID + " service");
+ return;
+ }
+ UPnPAction upnpAction = upnpService
+ .getAction("ListServices");
+
+ Dictionary parameters = new Hashtable();
+ Dictionary result;
+ try {
+ result = upnpAction.invoke(parameters);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ String currentServiceList = (String) result
+ .get("CurrentServiceList");
+ if (currentServiceList == null) {
+ out.println("No service available");
+ } else {
+
+ StringTokenizer st2 = new StringTokenizer(
+ currentServiceList, ";");
+ while (st2.hasMoreTokens()) {
+ long sid = Long.parseLong(st2.nextToken());
+
+ UPnPAction upnpAction2 = upnpService
+ .getAction("GetServiceInfo");
+
+ Dictionary parameters2 = new Hashtable();
+ parameters2.put("ServiceID", new Long(sid));
+ Dictionary result2;
+ try {
+ result2 = upnpAction2.invoke(parameters2);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ Long bundleID = (Long) result2.get("BundleID");
+ String usingBundles = (String) result2
+ .get("UsingBundles");
+ String propertyKeys = (String) result2
+ .get("PropertyKeys");
+
+ out.println("Service " + sid + " (Bundle "
+ + bundleID + ")");
+
+ StringTokenizer st3 = new StringTokenizer(
+ usingBundles, ";");
+ out.print("\t used by bundles ");
+ while (st3.hasMoreTokens()) {
+ long bid3 = Long.parseLong(st3.nextToken());
+ out.print(bid3 + " ");
+ }
+ out.print("\n");
+
+ StringTokenizer st4 = new StringTokenizer(
+ propertyKeys, ";");
+ while (st4.hasMoreTokens()) {
+ String prop4 = st4.nextToken();
+
+ UPnPAction upnpAction4 = upnpService
+ .getAction("GetServiceProperty");
+
+ Dictionary parameters4 = new Hashtable();
+ parameters4.put("ServiceID", new Long(sid));
+ parameters4.put("PropertyKey", prop4);
+ Dictionary result4;
+ try {
+ result4 = upnpAction4.invoke(parameters4);
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return;
+ }
+
+ out.print("\t");
+ out.print(prop4);
+ out.print('=');
+ Object value4=result4.get("PropertyValue");
+ out.print(value4);
+// out.print(" (");
+// out.print(result4.get("PropertyClassName"));
+// out.print(")");
+
+ out.println();
+ }
+ }
+ out.print("\n");
+ }
+ }
+
+ } else {
+ err.println("gateway "+deviceId+" does not exist");
+ return;
+ }
+ }
+}
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java Tue Jun 26 06:22:32 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.upnp.ogd.cmd;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+
+public class UPnPOGDConstant {
+ public static final String DEVICE_TYPE="urn:osgi-org:device:OSGiGatewayDevice:1";
+ public static final String SERVICE_TYPE="urn:osgi-org:service:BundleAdmin:1";
+ public static final String SERVICE_ID="urn:osgi-org:serviceId:BundleAdmin:1";
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java?view=auto&rev=550801
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java Tue Jun 26 06:22:32 2007
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.upnp.ogd.cmd;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class UPnPOGDEventListener implements UPnPEventListener, BundleActivator {
+
+ BundleContext bundleContext;
+
+ ServiceRegistration serviceRegistration;
+
+ private String deviceId;
+
+ public UPnPOGDEventListener(String deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ /**
+ * Callback method that is invoked for received events. The events are
+ * collected in a Dictionary object. Each entry has a String key
+ * representing the event name (= state variable name) and the new value of
+ * the state variable.
+ * <p>
+ * The class of the value object must match the class specified by the UPnP
+ * <p>
+ * State Variable associated with the event. This method must be called
+ * asynchronously
+ *
+ * @param deviceId
+ * ID of the device sending the events
+ * @param serviceId
+ * ID of the service sending the events
+ * @param events
+ * Dictionary object containing the new values for the state
+ * variables that have changed.
+ */
+
+ public void notifyUPnPEvent(String deviceId, String serviceId,
+ Dictionary events) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Event on ").append(deviceId);
+ sb.append(" :[");
+ Enumeration enumeration = events.keys();
+ while (enumeration.hasMoreElements()) {
+ Object key = enumeration.nextElement();
+ Object newValue = events.get(key);
+ Object name;
+ if (key instanceof UPnPStateVariable) {
+ /*
+ * 25.8 says: One or multiple events are passed as parameters to
+ * the notifyUPnPEvent( String ,String,Dictionary) method. The
+ * Dictionary object holds a pair of UpnPStateVariab le objects
+ * that triggered the event and an Object for the new value of
+ * the state variable.
+ */
+ name = ((UPnPStateVariable) key).getName();
+ } else {
+ name = key;
+ }
+ sb.append("[\"").append(name).append("\",");
+ sb.append(newValue).append("]");
+ if (enumeration.hasMoreElements())
+ sb.append(',');
+ }
+ sb.append("]");
+ String msg = sb.toString();
+ System.out.println(msg);
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ this.bundleContext = bundleContext;
+ Filter filter = null;
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("(&");
+ sb.append("(&");
+ sb.append("(").append(UPnPDevice.ID).append("=").append(deviceId)
+ .append(")");
+ sb.append("(").append(UPnPDevice.TYPE).append("=").append(
+ UPnPOGDConstant.DEVICE_TYPE).append(")");
+ sb.append("(").append(UPnPService.ID).append("=").append(
+ UPnPOGDConstant.SERVICE_ID).append(")");
+ sb.append(")");
+ sb.append(")");
+
+ try {
+ filter = bundleContext.createFilter(sb.toString());
+ } catch (InvalidSyntaxException e) {
+ // System.err.println(e);
+ return;
+ }
+ Dictionary properties = new Properties();
+ properties.put(UPNP_FILTER, filter);
+
+ serviceRegistration = bundleContext.registerService(
+ UPnPEventListener.class.getName(), this, properties);
+
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ serviceRegistration.unregister();
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java
------------------------------------------------------------------------------
svn:eol-style = native