felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r552478 - in /felix/sandbox/donsez/upnp.ogd.cmd: ./ doc/ src/main/java/org/apache/felix/upnp/ogd/cmd/ src/main/java/org/apache/felix/upnp/ogd/proxy/
Date Mon, 02 Jul 2007 12:13:06 GMT
Author: donsez
Date: Mon Jul  2 05:13:05 2007
New Revision: 552478

URL: http://svn.apache.org/viewvc?view=rev&rev=552478
Log:
refactor the bundle in order to export proxy classes independently of the class implementing the shell command.

Added:
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java   (with props)
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDConstant.java   (with props)
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDEventListener.java   (with props)
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java   (with props)
Removed:
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDConstant.java
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDEventListener.java
Modified:
    felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html
    felix/sandbox/donsez/upnp.ogd.cmd/pom.xml
    felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java

Modified: 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=diff&rev=552478&r1=552477&r2=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html (original)
+++ felix/sandbox/donsez/upnp.ogd.cmd/doc/readme.html Mon Jul  2 05:13:05 2007
@@ -45,8 +45,6 @@
 
 <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>
@@ -85,6 +83,7 @@
 <ul>
 <li>0.1.0, March 19, 2006 released by Didier Donsez</li>
 <li>0.2.0, April 2007</li>
+<li>0.3.0, July 2, 2007 : add an exported class playing the role of proxy</li>
 </ul>
 </p>
 

Modified: felix/sandbox/donsez/upnp.ogd.cmd/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/pom.xml?view=diff&rev=552478&r1=552477&r2=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/pom.xml (original)
+++ felix/sandbox/donsez/upnp.ogd.cmd/pom.xml Mon Jul  2 05:13:05 2007
@@ -62,10 +62,18 @@
           	<!-- 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>
+            <Export-Service>org.apache.felix.shell.Command, org.osgi.service.upnp.UPnPEventListener</Export-Service>
 
-            <Private-Package>${pom.artifactId}.*</Private-Package>
-            <Import-Package>*</Import-Package>
-            <Bundle-Activator>${pom.artifactId}.UPnPOGDCommand</Bundle-Activator>
+            <Import-Package>
+            	org.osgi.framework;version=1.3,
+            	org.osgi.service.upnp;version=1.1,
+				org.osgi.util.tracker
+            </Import-Package>
+            <DynamicImport-Package>org.apache.felix.shell</DynamicImport-Package>
+            <Export-Package>org.apache.felix.upnp.ogd.proxy</Export-Package>
+            <Private-Package>${pom.artifactId}</Private-Package>
+            
+            <Bundle-Activator>${pom.artifactId}.Activator</Bundle-Activator>
 
             <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</Bundle-DocURL>
             <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</Bundle-Url>

Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java?view=auto&rev=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java Mon Jul  2 05:13:05 2007
@@ -0,0 +1,67 @@
+/*
+ * 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 org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+
+/**
+ * this class starts/stops a command using dynamic importation
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator {
+
+	
+	BundleActivator activator=null;
+
+	/**
+	 * Call by the framework on bundle starting
+	 * 
+	 * @param context
+	 *            Description of the Parameter
+	 * @exception BundleException
+	 *                Description of the Exception
+	 */
+	public void start(BundleContext bundleContext) throws Exception {
+		try {
+			Class clazz=this.getClass().getClassLoader().loadClass("org.apache.felix.upnp.ogd.cmd.UPnPOGDCommand");
+			BundleActivator activator=(BundleActivator) clazz.newInstance();
+			activator.start(bundleContext);
+		} catch (Exception e) {
+			e.printStackTrace(System.err);
+			// silently do nothing
+		}
+	}
+
+	/**
+	 * Call by the framework on bundle stoping
+	 * 
+	 * @param context
+	 *            Description of the Parameter
+	 * @exception BundleException
+	 *                Description of the Exception
+	 */
+	public void stop(BundleContext bundleContext) throws Exception {
+		if(activator!=null) {
+			activator.stop(bundleContext);
+		}			
+	}
+}

Propchange: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 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=diff&rev=552478&r1=552477&r2=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java (original)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/cmd/UPnPOGDCommand.java Mon Jul  2 05:13:05 2007
@@ -19,33 +19,21 @@
 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.apache.felix.upnp.ogd.proxy.UPnPOGDProxy;
 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 {
+public class UPnPOGDCommand extends UPnPOGDProxy implements Command, BundleActivator {
 
 	private final static String CMD = "ogd";
 
@@ -75,93 +63,8 @@
 
 	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
 	 * 
@@ -170,15 +73,8 @@
 	 * @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();
+	public void start(BundleContext bundleContext) throws Exception {
+		super.start(bundleContext);
 		commandServiceRegistration = bundleContext.registerService(
 				Command.class.getName(), this, null);
 	}
@@ -191,25 +87,11 @@
 	 * @exception BundleException
 	 *                Description of the Exception
 	 */
-	public final void stop(BundleContext context) throws Exception {
-		stopAllEventListeners(null, null);
+	public void stop(BundleContext bundleContext) throws Exception {
 		commandServiceRegistration.unregister();
-		serviceTracker.close();
+		super.stop(bundleContext);		
 	}
 
-	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;
@@ -236,11 +118,12 @@
 			.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 + SERVICES_CMD + " <gwid> <bid> : list all services of a bundle on 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")
@@ -262,6 +145,9 @@
 
 	public void execute(String commandline, PrintStream out, PrintStream err) {
 
+		setOut(out);
+		setErr(err);
+		
 		StringTokenizer st = new StringTokenizer(commandline, " ");
 
 		if (st.countTokens() == 1) {
@@ -283,15 +169,8 @@
 			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");
+			gateways();
 			return;
-
 		} else if (option.equals(LISTEN_CMD)) {
 			if (!st.hasMoreTokens()) {
 				printUsage(out, "deviceId is missing");
@@ -355,49 +234,7 @@
 			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;
-		}
-		
+		installBundle(deviceId, bundleLocation);
 	}
 
 	void startCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -414,37 +251,7 @@
 		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;
-		}
-		
+		startBundle(deviceId, bid);
 	}
 	
 	void stopCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -461,36 +268,7 @@
 		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;
-		}		
+		stopBundle(deviceId, bid);
 	}
 	
 	void updateCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -507,55 +285,12 @@
 		String bundleId = st.nextToken().trim();
 		long bid = Long.parseLong(bundleId);
 
-		String BundleLocation = null;
+		String bundleLocation = null;
 		if (st.hasMoreTokens()) {
-			BundleLocation = st.nextToken().trim();
+			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;
-		}
-
+		updateBundle(deviceId, bid, bundleLocation);
 	}
 	
 	void uninstallCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -572,37 +307,7 @@
 		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;
-		}		
-		
+		uninstallBundle(deviceId, bid);
 	}
 	
 	void bundlesCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -611,71 +316,8 @@
 			return;
 		}
 		String deviceId = st.nextToken().trim();
+		bundles(deviceId);
 
-		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) {
@@ -692,64 +334,7 @@
 		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;
-		}
+		headers(deviceId, bid);
 	}
 	
 	void servicesCmd(PrintStream out, PrintStream err, StringTokenizer st) {
@@ -759,109 +344,11 @@
 		}
 		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;
+		Long displayBundleId=null;
+		if (st.hasMoreTokens()) {
+			String displayBundleIdStr = st.nextToken().trim();
+			displayBundleId = new Long(displayBundleIdStr);
 		}
+		services(deviceId, displayBundleId);
 	}
 }

Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDConstant.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDConstant.java?view=auto&rev=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDConstant.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDConstant.java Mon Jul  2 05:13:05 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.proxy;
+
+/**
+ * This interface provides constants related to OGD types and ids
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+
+public interface 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/proxy/UPnPOGDConstant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDEventListener.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDEventListener.java?view=auto&rev=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDEventListener.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDEventListener.java Mon Jul  2 05:13:05 2007
@@ -0,0 +1,138 @@
+/*
+ * 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.proxy;
+
+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;
+
+
+/**
+ * This class provides a UPnPEventListener for OGD change listening.
+ * @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/proxy/UPnPOGDEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java?view=auto&rev=552478
==============================================================================
--- felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java (added)
+++ felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java Mon Jul  2 05:13:05 2007
@@ -0,0 +1,655 @@
+/*
+ * 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.proxy;
+
+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.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.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 UPnP ControlPoint proxy  to manage remote gateways using UPnP
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class UPnPOGDProxy {
+
+	BundleContext bundleContext;
+
+	ServiceTracker serviceTracker;
+
+	Map/* <DeviceId,upnpogdEventListeners> */upnpogdEventListeners = new HashMap();
+
+	Map/* <DeviceId,UPnPDevice> */upnpdevices = new HashMap();
+
+	private PrintStream out;
+
+	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);
+			if(out!=null) out.println("the gateway " + deviceId
+					+ " is available");
+			return upnpdevice;
+		}
+
+		public void removedService(ServiceReference ref, Object upnpdevice) {
+			String deviceId = (String) ref.getProperty(UPnPDevice.ID);
+			upnpdevices.remove(deviceId);
+			if(out!=null) out.println("the gateway " + deviceId
+					+ " is not available");
+			upnpogdEventListeners.remove(deviceId);
+			bundleContext.ungetService(ref);
+		}
+
+		public void modifiedService(ServiceReference ref, Object upnpdevice) {
+			// TODO Auto-generated method stub
+		}
+	}
+
+	public 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");
+		}
+	}
+
+	public 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 {
+			if(err!=null) err.println(deviceId + " not listened");
+		}
+	}
+
+	public 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 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();
+	}
+
+	/**
+	 * Call by the framework on bundle stoping
+	 * 
+	 * @param context
+	 *            Description of the Parameter
+	 * @exception BundleException
+	 *                Description of the Exception
+	 */
+	public void stop(BundleContext context) throws Exception {
+		stopAllEventListeners(null, null);
+		serviceTracker.close();
+	}
+
+	private boolean debug = true;
+
+	private PrintStream err;
+
+	/**
+	 * Description of the Method
+	 * 
+	 * @param msg
+	 *            Description of the Parameter
+	 */
+	public void println(String msg) {
+		if (debug) {
+			System.err.println(getClass().getName() + ":" + msg);
+		}
+	}
+
+
+	public void installBundle(String deviceId, String bundleLocation) {
+
+		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;
+		}
+		
+	}
+
+	public void startBundle(String deviceId, long bid) {
+
+		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;
+		}
+		
+	}
+	
+	public void stopBundle(String deviceId, long bid) {
+
+		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;
+		}		
+	}
+	
+	public void updateBundle(String deviceId, long bid, String bundleLocation) {
+		
+		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;
+		}
+
+	}
+	
+	public void uninstallBundle(String deviceId, long bid) {
+
+		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;
+		}		
+		
+	}
+	
+	public void bundles(String deviceId ) {
+
+		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;
+		}
+	}
+	
+	public void headers(String deviceId, long bid) {
+
+		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;
+		}
+	}
+
+	
+	
+	/**
+	 * list all available gateways
+	 * @param deviceId
+	 * @param displayBundleId
+	 */
+	public void gateways() {
+		Iterator iterator = upnpdevices.keySet().iterator();
+		int cpt = 0;
+		while (iterator.hasNext()) {
+			cpt++;
+			out.println(iterator.next());
+		}
+		out.println(cpt + " gateway(s) available");
+		return;
+	}	
+	
+	/**
+	 * list all services
+	 * @param deviceId
+	 * @param displayBundleId
+	 */
+	public void services(String deviceId, Long displayBundleId) {
+
+		
+		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");
+					
+					
+					if(displayBundleId!=null && !displayBundleId.equals(bundleID)) continue;
+					
+					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");
+			}
+		}
+	}
+
+	public PrintStream getOut() {
+		return out;
+	}
+
+	public void setOut(PrintStream out) {
+		this.out = out;
+	}
+
+	public PrintStream getErr() {
+		return err;
+	}
+
+	public void setErr(PrintStream err) {
+		this.err = err;
+	}
+}

Propchange: felix/sandbox/donsez/upnp.ogd.cmd/src/main/java/org/apache/felix/upnp/ogd/proxy/UPnPOGDProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message