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/05/09 23:58:34 UTC
svn commit: r536676 - in /felix/sandbox/donsez/upnp.devicegen.util: ./ 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/d...
Author: donsez
Date: Wed May 9 14:58:32 2007
New Revision: 536676
URL: http://svn.apache.org/viewvc?view=rev&rev=536676
Log:
creation of upnp.devicegen.util (by extracting utilities classes from upnp/devicegen
Added:
felix/sandbox/donsez/upnp.devicegen.util/
felix/sandbox/donsez/upnp.devicegen.util/pom.xml (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/
felix/sandbox/donsez/upnp.devicegen.util/src/main/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java (with props)
felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java (with props)
Added: felix/sandbox/donsez/upnp.devicegen.util/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/pom.xml?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/pom.xml (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/pom.xml Wed May 9 14:58:32 2007
@@ -0,0 +1,91 @@
+<!--
+ 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>utility classes for the Felix UPnP Device Generator (org.apache.felix.upnp.devicegen).</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>Apache Felix UPnP Device Generator Utilities</name>
+ <artifactId>org.apache.felix.upnp.devicegen.util</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>
+ </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 -->
+
+ <Export-Package>org.apache.felix.upnp.devicegen.holder,org.apache.felix.upnp.devicegen.util</Export-Package>
+ <Import-Package>*</Import-Package>
+
+ <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.devicegen.util/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,35 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class BooleanHolder {
+
+ private boolean value;
+
+ public BooleanHolder(){}
+
+ public BooleanHolder(boolean initial){
+ value=initial;
+ }
+
+ public void setValue(boolean value){
+ this.value=value;
+ }
+
+ public boolean getValue(){
+ return value;
+ }
+
+ public Boolean getObject(){
+ return new Boolean(value);
+ }
+
+ public static boolean toValue(Boolean value){
+ return value.booleanValue();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/BooleanHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,35 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class ByteArrayHolder {
+
+ private byte[] value;
+
+ public ByteArrayHolder(){}
+
+ public ByteArrayHolder(byte[] initial){
+ value=initial;
+ }
+
+ public void setValue(byte[] value){
+ this.value=value;
+ }
+
+ public byte[] getValue(){
+ return value;
+ }
+
+ public byte[] getObject(){
+ return value;
+ }
+
+ public static byte[] toValue(byte[] value){
+ return value;
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/ByteArrayHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,37 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class CharacterHolder {
+
+ private char value;
+
+ public CharacterHolder(){}
+
+ public CharacterHolder(char initial){
+ value=initial;
+ }
+
+ public void setValue(char value){
+ this.value=value;
+ }
+
+ public char getValue(){
+ return value;
+ }
+
+ public Character getObject(){
+ return new Character(value);
+ }
+
+
+ public static char toValue(Character value){
+ return value.charValue();
+ }
+
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/CharacterHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,38 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+import java.util.Date;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class DateHolder {
+
+ private Date value;
+
+ public DateHolder(){}
+
+ public DateHolder(Date initial){
+ value=initial;
+ }
+
+ public void setValue(Date value){
+ this.value=value;
+ }
+
+ public Date getValue(){
+ return value;
+ }
+
+ public Date getObject(){
+ return value;
+ }
+
+ public static Date toValue(Date value){
+ return value;
+ }
+
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DateHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,36 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class DoubleHolder {
+
+ private double value;
+
+ public DoubleHolder(){}
+
+ public DoubleHolder(double initial){
+ value=initial;
+ }
+
+ public void setValue(double value){
+ this.value=value;
+ }
+
+ public double getValue(){
+ return value;
+ }
+
+ public Double getObject(){
+ return new Double(value);
+ }
+
+ public static double toValue(Double value){
+ return value.doubleValue();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/DoubleHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,36 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class FloatHolder {
+
+ private float value;
+
+ public FloatHolder(){}
+
+ public FloatHolder(float initial){
+ value=initial;
+ }
+
+ public void setValue(float value){
+ this.value=value;
+ }
+
+ public Float getObject(){
+ return new Float(value);
+ }
+
+ public float getValue(){
+ return value;
+ }
+
+
+ public static float toValue(Float value){
+ return value.floatValue();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/FloatHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,35 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class IntegerHolder {
+
+ private int value;
+
+ public IntegerHolder(){}
+
+ public IntegerHolder(int initial){
+ value=initial;
+ }
+
+ public void setValue(int value){
+ this.value=value;
+ }
+
+ public int getValue(){
+ return value;
+ }
+
+ public Integer getObject(){
+ return new Integer(value);
+ }
+
+ public static int toValue(Integer value){
+ return value.intValue();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/IntegerHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,37 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class LongHolder {
+
+ private long value;
+
+ public LongHolder(){}
+
+ public LongHolder(long initial){
+ value=initial;
+ }
+
+ public void setValue(long value){
+ this.value=value;
+ }
+
+ public long getValue(){
+ return value;
+ }
+
+ public Long getObject(){
+ return new Long(value);
+ }
+
+
+
+ public static long toValue(Long value){
+ return value.longValue();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/LongHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java Wed May 9 14:58:32 2007
@@ -0,0 +1,36 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.holder;
+
+/**
+ * holder for out parameters
+ * @author Didier Donsez
+ */
+public class StringHolder {
+
+ private String value;
+
+ public StringHolder(){}
+
+ public StringHolder(String initial){
+ value=initial;
+ }
+
+ public void setValue(String value){
+ this.value=value;
+ }
+
+ public String getValue(){
+ return value;
+ }
+
+ public String getObject(){
+ return value;
+ }
+
+ public static String toValue(String value){
+ return value;
+ }
+
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/holder/StringHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java Wed May 9 14:58:32 2007
@@ -0,0 +1,98 @@
+/*
+ * @author donsez
+ */
+
+package org.apache.felix.upnp.devicegen.util;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/*
+ * @author donsez
+ */
+
+public abstract class AbstractUPnPAction
+ implements UPnPAction, BundleActivator {
+ final private UPnPService upnpService;
+ final private String NAME;
+ final private String RESULT_STATUS;
+ private String[] IN_ARG_NAMES;
+ private String[] OUT_ARG_NAMES;
+ private Map inArgNames=new HashMap();
+ private Map outArgNames=new HashMap();
+
+ // HERE specific action members
+
+ public AbstractUPnPAction(
+ UPnPService upnpService,
+ String NAME,
+ String RESULT_STATUS
+ ){
+ this.upnpService=upnpService;
+ this.NAME=NAME;
+ this.RESULT_STATUS=RESULT_STATUS;
+ }
+
+ protected void addInArg(String argName,UPnPStateVariable upnpStateVariable){
+ inArgNames.put(argName,upnpStateVariable);
+ }
+
+ protected void addOutArg(String argName,UPnPStateVariable upnpStateVariable){
+ outArgNames.put(argName,upnpStateVariable);
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#getName()
+ */
+ public String getName() {
+ return NAME;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#getReturnArgumentName()
+ */
+ public String getReturnArgumentName() {
+ return RESULT_STATUS;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#getInputArgumentNames()
+ */
+ public String[] getInputArgumentNames() {
+ if(IN_ARG_NAMES==null)
+ IN_ARG_NAMES=(String[]) inArgNames.keySet().toArray(new String[]{});
+ return IN_ARG_NAMES;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#getOutputArgumentNames()
+ */
+ public String[] getOutputArgumentNames() {
+ if(OUT_ARG_NAMES==null)
+ OUT_ARG_NAMES=(String[]) outArgNames.keySet().toArray(new String[]{});
+ return OUT_ARG_NAMES;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#getStateVariable(java.lang.String)
+ */
+ public UPnPStateVariable getStateVariable(String argumentName) {
+ UPnPStateVariable sv=(UPnPStateVariable)inArgNames.get(argumentName);
+ if(sv!=null) return sv;
+ return (UPnPStateVariable)outArgNames.get(argumentName);
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
+ */
+ public abstract Dictionary invoke(Dictionary args) throws Exception;
+ public abstract void start(BundleContext bundleContext) throws Exception;
+ public abstract void stop(BundleContext bundleContext) throws Exception;
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java Wed May 9 14:58:32 2007
@@ -0,0 +1,181 @@
+/*
+ */
+package org.apache.felix.upnp.devicegen.util;
+
+
+import java.beans.PropertyChangeEvent;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPIcon;
+import org.osgi.service.upnp.UPnPService;
+
+/**
+ * @author donsez
+ */
+public abstract class AbstractUPnPDevice implements BundleActivator, UPnPDevice {
+
+ protected BundleContext bundleContext;
+
+ protected UPnPService[] services;
+
+ protected UPnPIcon[] icons;
+
+ protected String DEVICE_ID;
+
+ protected Dictionary dictionary;
+
+ protected UPnPEventNotifier[] notifiers;
+
+ private ServiceRegistration serviceRegistration;
+
+ protected List/*<AbstractUPnPDevice>*/ children;
+ protected AbstractUPnPDevice parent;
+
+ public AbstractUPnPDevice(BundleContext bundleContext,AbstractUPnPDevice parent) {
+ this.bundleContext = bundleContext;
+ this.parent = parent;
+
+ dictionary = new Properties();
+ dictionary.put(UPnPDevice.UPNP_EXPORT,"");
+ dictionary.put(org.osgi.service.device.Constants.DEVICE_CATEGORY,new String[]{UPnPDevice.DEVICE_CATEGORY});
+ if(parent!=null) dictionary.put(UPnPDevice.PARENT_UDN,parent.getUDN());
+
+ List servicesList = new ArrayList();
+ List iconList = new ArrayList();
+ }
+
+ /**
+ *
+ */
+ private String myUDN;
+
+ public String getUDN() {
+ if (myUDN == null) {
+ try {
+ myUDN = DEVICE_ID + '@'
+ + InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ myUDN = DEVICE_ID;
+ }
+ }
+ return myUDN;
+ }
+
+ protected abstract void setupDeviceProperties();
+
+ /**
+ * @see org.osgi.service.upnp.UPnPDevice#getService(java.lang.String)
+ */
+ public UPnPService getService(String serviceId) {
+ for (int s = 0; s < services.length; s++)
+ if (serviceId.equals(services[s].getId()))
+ return services[s];
+ return null;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPDevice#getServices()
+ */
+ public UPnPService[] getServices() {
+ return services;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPDevice#getIcons(java.lang.String)
+ */
+ public UPnPIcon[] getIcons(String locale) {
+ return icons;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPDevice#getDescriptions(java.lang.String)
+ */
+ public Dictionary getDescriptions(String locale) {
+ return dictionary;
+ }
+
+ protected void addChild(AbstractUPnPDevice childDevice){
+ if(children==null) children=new LinkedList();
+ children.add(childDevice);
+ }
+
+ /**
+ *
+ */
+ private void buildEventNotifier() {
+ notifiers = new UPnPEventNotifier[services.length];
+ for (int n = 0; n < notifiers.length; n++)
+ notifiers[n] = new UPnPEventNotifier(bundleContext, this, services[n],
+ null);
+ }
+
+ /**
+ * @throws Exception
+ *
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ this.bundleContext=bundleContext;
+
+ setupDeviceProperties();
+
+ if(children!=null){
+ Iterator iterator=children.iterator();
+ while(iterator.hasNext()){
+ try{
+ AbstractUPnPDevice embeddedDevice=((AbstractUPnPDevice)iterator.next());
+ System.out.println("start "+embeddedDevice.getUDN()+" ...");
+ embeddedDevice.start(bundleContext);
+ } catch(Exception e) {
+ // TODO compensate previous starting ???
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ System.out.println(this.toString());
+ serviceRegistration = bundleContext.registerService(
+ UPnPDevice.class.getName(),
+ this,
+ dictionary
+ );
+ buildEventNotifier();
+ }
+
+ /**
+ *
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ for (int n = 0; n < notifiers.length; n++)
+ notifiers[n].destroy();
+ serviceRegistration.unregister();
+ if(children!=null){
+ Iterator iterator=children.iterator();
+ while(iterator.hasNext()){
+ try{
+ ((BundleActivator)iterator.next()).stop(bundleContext);
+ } catch(Exception e) {
+ // TODO compensate previous starting ???
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ final public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+ for (int n = 0; n < notifiers.length; n++) {
+ notifiers[n].propertyChange(propertyChangeEvent);
+ }
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPDevice.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java Wed May 9 14:58:32 2007
@@ -0,0 +1,120 @@
+package org.apache.felix.upnp.devicegen.util;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+
+public abstract class AbstractUPnPService implements UPnPService, BundleActivator {
+
+ final private String serviceId;
+ final private String serviceType;
+ final private String version;
+ final protected UPnPDevice upnpDevice;
+
+ protected Map stateVariables;
+ protected Map actions;
+
+ /** constructor
+ */
+ public AbstractUPnPService(
+ UPnPDevice upnpDevice,
+ String serviceId,
+ String serviceType,
+ String version
+ ){
+ this.upnpDevice=upnpDevice;
+ this.serviceId=serviceId;
+ this.serviceType=serviceType;
+ this.version=version;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getId()
+ */
+ public String getId() {
+ return serviceId;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getType()
+ */
+ public String getType() {
+ return serviceType;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getVersion()
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getActions()
+ */
+ public UPnPAction[] getActions() {
+ if(actions==null) return null;
+ return (UPnPAction[])(actions.values()).toArray(new UPnPAction[]{});
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getAction(java.lang.String)
+ */
+ public UPnPAction getAction(String name) {
+ if(actions==null) return null;
+ return (UPnPAction)actions.get(name);
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getStateVariables()
+ */
+ public UPnPStateVariable[] getStateVariables() {
+ if(stateVariables==null) return null;
+ return (UPnPStateVariable[])(stateVariables.values()).toArray(new UPnPStateVariable[]{});
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPService#getStateVariable(java.lang.String)
+ */
+ public UPnPStateVariable getStateVariable(String name) {
+ if(stateVariables==null) return null;
+ return (UPnPStateVariable)stateVariables.get(name);
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ if(stateVariables!=null) {
+ Iterator iter=stateVariables.values().iterator();
+ while(iter.hasNext()){
+ ((BundleActivator)iter.next()).start(bundleContext);
+ }
+ }
+ if(actions!=null) {
+ Iterator iter=actions.values().iterator();
+ while(iter.hasNext()){
+ ((BundleActivator)iter.next()).start(bundleContext);
+ }
+ }
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ if(actions!=null) {
+ Iterator iter=actions.values().iterator();
+ while(iter.hasNext()){
+ ((BundleActivator)iter.next()).stop(bundleContext);
+ }
+ }
+ if(stateVariables!=null) {
+ Iterator iter=stateVariables.values().iterator();
+ while(iter.hasNext()){
+ ((BundleActivator)iter.next()).stop(bundleContext);
+ }
+ }
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java Wed May 9 14:58:32 2007
@@ -0,0 +1,112 @@
+package org.apache.felix.upnp.devicegen.util;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+public abstract class AbstractUPnPStateVariable
+ implements UPnPStateVariable, BundleActivator {
+
+ final protected String NAME;
+ final protected String DATA_TYPE;
+ final protected Object DEFAULT_VALUE;
+ final protected String[] ALLOWED_VALUES;
+ final protected Number STEP;
+ final protected Number MIN;
+ final protected Number MAX;
+ final protected boolean SENDEVENT;
+ final protected boolean OPTIONAL;
+
+ final protected UPnPService upnpService;
+
+ public AbstractUPnPStateVariable(
+ UPnPService upnpService,
+ String NAME,
+ String DATA_TYPE,
+ Object DEFAULT_VALUE,
+ String[] ALLOWED_VALUES,
+ Number STEP,
+ Number MIN,
+ Number MAX,
+ boolean SENDEVENT,
+ boolean OPTIONAL
+ ) {
+ this.upnpService = upnpService;
+ this.NAME = NAME;
+ this.DATA_TYPE = DATA_TYPE;
+ this.DEFAULT_VALUE = DEFAULT_VALUE;
+ this.ALLOWED_VALUES = ALLOWED_VALUES;
+ this.STEP = STEP;
+ this.MIN = MIN;
+ this.MAX = MAX;
+ this.SENDEVENT = SENDEVENT;
+ this.OPTIONAL = OPTIONAL;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getName()
+ */
+ public String getName() {
+ return NAME;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getJavaDataType()
+ */
+ public Class getJavaDataType() {
+ return UPnPDataTypeUtil.getClass(DATA_TYPE);
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getUPnPDataType()
+ */
+ public String getUPnPDataType() {
+ return DATA_TYPE;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getDefaultValue()
+ */
+ public Object getDefaultValue() {
+ return DEFAULT_VALUE;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getAllowedValues()
+ */
+ public String[] getAllowedValues() {
+ return ALLOWED_VALUES;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getMinimum()
+ */
+ public Number getMinimum() {
+ return MIN;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getMaximum()
+ */
+ public Number getMaximum() {
+ return MAX;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#getStep()
+ */
+ public Number getStep() {
+ return STEP;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPStateVariable#sendsEvents()
+ */
+ public boolean sendsEvents() {
+ return SENDEVENT;
+ }
+
+ public abstract void start(BundleContext bundleContext) throws Exception;
+ public abstract void stop(BundleContext bundleContext) throws Exception;
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/AbstractUPnPStateVariable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java Wed May 9 14:58:32 2007
@@ -0,0 +1,82 @@
+/*
+__LICENSE__
+*/
+package org.apache.felix.upnp.devicegen.util;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.osgi.service.upnp.UPnPIcon;
+
+public class DeviceIcon implements UPnPIcon {
+
+ private String mimetype;
+ private int width;
+ private int height;
+ private int size;
+ private int depth;
+ private String urlStr;
+ private ClassLoader classLoader;
+
+ public DeviceIcon(
+ String mimetype,
+ int width,
+ int height,
+ int size,
+ int depth,
+ String urlStr,
+ ClassLoader classLoader
+ ){
+ this.mimetype=mimetype;
+ this.width=width;
+ this.height=height;
+ this.size=size;
+ this.depth=depth;
+ this.urlStr=urlStr;
+ this.classLoader=classLoader;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getMimeType()
+ */
+ public String getMimeType() {
+ return "image/png";
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getWidth()
+ */
+ public int getWidth() {
+ return 32;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getHeight()
+ */
+ public int getHeight() {
+ return 32;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getSize()
+ */
+ public int getSize() {
+ return 0;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getDepth()
+ */
+ public int getDepth() {
+ return 16;
+ }
+
+ /**
+ * @see org.osgi.service.upnp.UPnPIcon#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException {
+ return classLoader.getResourceAsStream(urlStr);
+ //return Thread.currentThread().getContextClassLoader().getResourceAsStream(urlStr);
+ //return DeviceIcon.class.getResourceAsStream(urlStr);
+ }
+}
+
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/DeviceIcon.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java Wed May 9 14:58:32 2007
@@ -0,0 +1,36 @@
+/*
+DomoWare OSGi UPnP Sample TV Device is an implementation of UPnP Device service to be used with OSGi Framework
+Copyright (C) 2004 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+You can contact us at:
+ {matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+package org.apache.felix.upnp.devicegen.util;
+
+import java.beans.PropertyChangeListener;
+
+/**
+ * EventSource.java 8-feb-2005
+ * @author Francesco Furfari
+ */
+public interface EventSource {
+ void addPropertyChangeListener(PropertyChangeListener listener);
+ void addPropertyChangeListener(String propertyName, PropertyChangeListener listener);
+ void removePropertyChangeListener(PropertyChangeListener listener);
+ void removePropertyChangeListener(String propertyName, PropertyChangeListener listener);
+}
+
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/EventSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java Wed May 9 14:58:32 2007
@@ -0,0 +1,118 @@
+/*
+DomoWare UPnP Base Driver is an implementation of the OSGi UnP Device Specifaction
+Copyright (C) 2005 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+You can contact us at:
+ {matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+
+package org.apache.felix.upnp.devicegen.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPService;
+
+/**
+ * Lookup.java 8-feb-2005
+ * @author Francesco Furfari
+ */
+public class Lookup {
+
+ static BundleContext context;
+ private ArrayList references = new ArrayList();
+
+ public UPnPService getService(String deviceId,String serviceId){
+ UPnPDevice device = getDevice(deviceId);
+ if (device == null) return null;
+ return device.getService(serviceId);
+ }
+
+ public UPnPDevice getDevice(String deviceId){
+ ServiceReference sr = getReference(deviceId);
+ if (sr == null) return null;
+ return getDevice(sr);
+ }
+
+ private UPnPDevice getDevice(ServiceReference sr){
+ references.add(sr);
+ return(UPnPDevice) context.getService(sr);
+ }
+
+ public ServiceReference getReference(String deviceId){
+ try {
+ String filter = "(" + UPnPDevice.ID + "="+ deviceId + ")";
+ ServiceReference[] listeners = context.getServiceReferences(UPnPDevice.class.getName(),filter);
+ if (listeners != null)
+ for (int i = 0;i<listeners.length;i++){
+ return listeners[i]; // the Device Id should be unique
+ }
+ return null;
+ } catch (Exception ex) {
+ System.out.println(ex);
+ return null;
+ }
+ }
+
+ public String getDeviceType(String deviceId){
+ ServiceReference sr = getReference(deviceId);
+ if (sr == null) return null;
+ return (String) sr.getProperty(UPnPDevice.TYPE);
+ }
+
+ public Object getDeviceProperty(String deviceId,String key){
+ ServiceReference sr = getReference(deviceId);
+ if (sr == null) return null;
+ return sr.getProperty(key);
+ }
+
+ public String getServiceType(String deviceId, String serviceId){
+ UPnPDevice device = getDevice(deviceId);
+ if (device == null) return null;
+ return device.getService(serviceId).getType();
+ }
+
+ public boolean isRootDevice(String deviceId){
+ ServiceReference sr = getReference(deviceId);
+ //if (sr == null) return null;
+ String parent = (String) sr.getProperty(UPnPDevice.PARENT_UDN);
+ if((parent == null)||parent.equals("")) return true;
+ return false;
+ }
+
+ public UPnPDevice getRootDevice(String deviceId) {
+ ServiceReference sr = getReference(deviceId);
+ String parent = (String) sr.getProperty(UPnPDevice.PARENT_UDN);
+ if((parent == null)||parent.equals(""))
+ return getDevice(sr);
+ else
+ return getRootDevice(parent);
+ }
+
+ public void ungetServices(){
+ Iterator list = this.references.iterator();
+ while( list.hasNext()){
+ ServiceReference sr = (ServiceReference) list.next();
+ context.ungetService(sr);
+ list.remove();
+ }
+ }
+
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/Lookup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java Wed May 9 14:58:32 2007
@@ -0,0 +1,72 @@
+/*
+ * __LICENSE__
+ */
+package org.apache.felix.upnp.devicegen.util;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/**
+ * utility class to obtains java class for UPnP data type
+ * @author donsez
+ */
+public class UPnPDataTypeUtil {
+
+ private static Map dataTypeMap;
+ static {
+ dataTypeMap = new HashMap();
+ dataTypeMap.put(UPnPStateVariable.TYPE_UI1, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_UI2, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_UI4, Long.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_I1, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_I2, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_I4, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_INT, Integer.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_R4, Float.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_R8, Double.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_NUMBER, Double.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_FIXED_14_4, Double.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_FLOAT, Float.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_CHAR, Character.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_STRING, String.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_DATE, Date.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_DATETIME, Date.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_DATETIME_TZ, Date.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_TIME, Long.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_TIME_TZ, Long.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_BOOLEAN, Boolean.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_BIN_BASE64, byte[].class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_BIN_HEX, byte[].class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_URI, String.class);
+ dataTypeMap.put(UPnPStateVariable.TYPE_UUID, String.class);
+ }
+
+ public static Class getClass(String upnpDataType){
+ return (Class)dataTypeMap.get(upnpDataType);
+ }
+
+ public static String getClassName(String upnpDataType)throws IllegalArgumentException {
+ Class clazz=(Class)dataTypeMap.get(upnpDataType);
+ if(clazz==null) throw new IllegalArgumentException("No class for "+upnpDataType);
+ return clazz.getName();
+ }
+
+ public static Object instanciateObject(String upnpDataType, String value){
+ Class clazz=(Class)dataTypeMap.get(upnpDataType);
+ if(clazz.equals(Integer.class)) return new Integer(value);
+ if(clazz.equals(Long.class)) return new Long(value);
+ if(clazz.equals(Float.class)) return new Float(value);
+ if(clazz.equals(Double.class)) return new Double(value);
+ if(clazz.equals(Boolean.class)) return new Boolean(value);
+ if(clazz.equals(String.class)) return new String(value);
+ if(clazz.equals(Character.class)) return new Character(value.charAt(0));
+
+ // TODO TYPE_DATE,TYPE_BIN_BASE64, TYPE_BIN_HEX
+ if(clazz==null) throw new IllegalArgumentException("Can not instanciate object for "+upnpDataType);
+ return null;
+ }
+
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPDataTypeUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java Wed May 9 14:58:32 2007
@@ -0,0 +1,66 @@
+/*
+ * __LICENSE__
+ */
+package org.apache.felix.upnp.devicegen.util;
+
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/**
+ * @author donsez
+ */
+public class UPnPEventListenerUtil {
+
+ /**
+ * trace the event received by org.osgi.service.upnp.UPnPEventListener
+ *
+ * @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.
+ * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String,
+ * java.lang.String, java.util.Dictionary)
+ */
+
+ public static void traceEvent(PrintStream printStream, String deviceId,
+ String serviceId, Dictionary events) {
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("UPnPEvent:[deviceId=").append(deviceId);
+ sb.append(",serviceId=").append(serviceId);
+ 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(
+ "\"(" + newValue.getClass().getName() + "),");
+ sb.append(newValue).append("]");
+ if (enumeration.hasMoreElements())
+ sb.append(',');
+ }
+ sb.append("]]");
+ String msg = sb.toString();
+ printStream.println(msg);
+
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventListenerUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java Wed May 9 14:58:32 2007
@@ -0,0 +1,205 @@
+/*
+DomoWare OSGi UPnP Sample TV Device is an implementation of UPnP Device service to be used with OSGi Framework
+Copyright (C) 2004 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+You can contact us at:
+ {matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+package org.apache.felix.upnp.devicegen.util;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/**
+ * UPnPEventNotifier.java 8-feb-2005
+ * @author Francesco Furfari
+ */
+public class UPnPEventNotifier implements PropertyChangeListener,ServiceListener {
+ BundleContext context;
+ UPnPDevice device;
+ UPnPService service;
+ EventSource source;
+
+ Properties UPnPTargetListener;
+ String deviceId;
+ String serviceId;
+ Vector upnpListeners = new Vector();
+
+ public UPnPEventNotifier(BundleContext context,UPnPDevice device,UPnPService service,EventSource source){
+ if ((context == null) || (device == null) || (service == null))
+ throw new IllegalArgumentException("Illegal arguments in UPnPEventNotifier constructor.");
+ this.context=context;
+ this.device=device;
+ this.service=service;
+ this.source=source;
+ this.serviceId=service.getId();
+ setupUPnPListenerHouseKeeping(device);
+ }
+
+ /**
+ * @param deviceId
+ */
+ private void setupUPnPListenerHouseKeeping(UPnPDevice device) {
+ UPnPTargetListener = new Properties();
+ Dictionary dict = device.getDescriptions(null);
+ deviceId = (String) dict.get(UPnPDevice.ID);
+ UPnPTargetListener.put(UPnPDevice.ID,deviceId);
+ UPnPTargetListener.put(UPnPService.ID,serviceId);
+ UPnPTargetListener.put(UPnPDevice.TYPE,dict.get(UPnPDevice.TYPE));
+ UPnPTargetListener.put(UPnPService.TYPE,service.getType());
+ String ANY_UPnPEventListener = "("+Constants.OBJECTCLASS+"="+UPnPEventListener.class.getName()+")";
+
+ ServiceReference[] listeners = null;
+ try {
+ listeners = context.getServiceReferences(UPnPEventListener.class.getName(),null);
+ if (listeners != null){
+ for (int i = 0;i<listeners.length;i++){
+ ServiceReference sr = listeners[i];
+ Filter filter = (Filter) sr.getProperty(UPnPEventListener.UPNP_FILTER);
+ if (filter == null) addNewListener(sr);
+ else {
+ if (filter.match(UPnPTargetListener))
+ addNewListener(sr);
+ }
+ }
+ }
+ } catch (Exception ex) {
+ System.out.println(ex);
+ }
+
+ try {
+ String filter = ANY_UPnPEventListener;
+ context.addServiceListener(this,filter);
+ } catch (Exception ex) {
+ System.out.println(ex);
+ }
+
+ if (source!=null){
+ UPnPStateVariable[] vars = service.getStateVariables();
+ if (vars != null){
+ for (int i=0;i<vars.length;i++)
+ if(vars[i].sendsEvents())
+ source.addPropertyChangeListener(vars[i].getName(),this);
+ }
+ }
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ Iterator list = upnpListeners.iterator();
+ String property = evt.getPropertyName();
+ Object value = evt.getNewValue();
+ //String valueString = value.toString();
+ final Properties events = new Properties();
+ //events.put(property,valueString);
+ events.put(property,value);
+ while (list.hasNext()){
+ final ServiceReference sr = (ServiceReference)list.next();
+ String[] props =sr.getPropertyKeys();
+ new Thread(null,null,"UPnPEventNotifier"){
+ public void run(){
+ try {
+ UPnPEventListener listener = (UPnPEventListener) context.getService(sr);
+ listener.notifyUPnPEvent(deviceId,serviceId,events);
+ context.ungetService(sr);
+ } catch (Exception ex){
+ System.out.println("UPnPEventNotifier Err: " + ex);
+ System.out.println("UPnPEventNotifier bundleId: " + context.getBundle().getBundleId());
+ System.out.println("UPnPEventNotifier listener: " + context.getService(sr));
+ System.out.println("UPnPEventNotifier sr: " +sr);
+ ex.printStackTrace(System.out);
+ }
+ }
+ }.start();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(ServiceEvent e) {
+ switch(e.getType()){
+ case ServiceEvent.REGISTERED:{
+ ServiceReference sr = e.getServiceReference();
+ Filter filter = (Filter) sr.getProperty(UPnPEventListener.UPNP_FILTER);
+ if (filter == null) addNewListener(sr);
+ else {
+ if (filter.match(UPnPTargetListener))
+ addNewListener(sr);
+ }
+ };break;
+
+ case ServiceEvent.MODIFIED:{
+ ServiceReference sr = e.getServiceReference();
+ Filter filter = (Filter) sr.getProperty(UPnPEventListener.UPNP_FILTER);
+ removeListener(sr);
+ if (filter == null)
+ addNewListener(sr);
+ else {
+ if (filter.match(UPnPTargetListener))
+ addNewListener(sr);
+ }
+ };break;
+
+ case ServiceEvent.UNREGISTERING:{
+ removeListener(e.getServiceReference());
+ };break;
+
+ }
+
+ }
+
+ private void removeListener(ServiceReference reference) {
+ upnpListeners.remove(reference);
+ }
+
+ private void addNewListener(ServiceReference reference) {
+ upnpListeners.add(reference);
+ UPnPStateVariable[] vars = service.getStateVariables();
+ if (vars != null){
+ for (int i=0;i<vars.length;i++)
+ if(vars[i].sendsEvents()){
+ Object value = ((UPnPStateVariableDescriptor) vars[i]).getValue();
+ propertyChange(new PropertyChangeEvent(this,vars[i].getName(),value,value));
+ }
+ }
+ }
+
+ public void destroy(){
+ context.removeServiceListener(this);
+ upnpListeners.removeAllElements();
+ }
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPEventNotifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java Wed May 9 14:58:32 2007
@@ -0,0 +1,33 @@
+/*
+DomoWare UPnP Base Driver is an implementation of the OSGi UnP Device Specifaction
+Copyright (C) 2005 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+You can contact us at:
+ {matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+
+package org.apache.felix.upnp.devicegen.util;
+
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/**
+ * UPnPStateVariableDescriptor.java 22-gen-2005
+ * @author Francesco Furfari
+ */
+public interface UPnPStateVariableDescriptor extends UPnPStateVariable {
+ Object getValue();
+}
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPStateVariableDescriptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java?view=auto&rev=536676
==============================================================================
--- felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java (added)
+++ felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java Wed May 9 14:58:32 2007
@@ -0,0 +1,142 @@
+/*
+DomoWare OSGi UPnP Sample TV Device is an implementation of UPnP Device service to be used with OSGi Framework
+Copyright (C) 2004 Matteo Demuru, Francesco Furfari, Stefano "Kismet" Lenzi
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+You can contact us at:
+ {matte-d, sygent, kismet-sl} [at] users.sourceforge.net
+*/
+package org.apache.felix.upnp.devicegen.util;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPEventListener;
+import org.osgi.service.upnp.UPnPService;
+
+/**
+ * UPnPSubscriber.java 8-feb-2005
+ * @author Francesco Furfari
+ */
+public class UPnPSubscriber {
+ private BundleContext context;
+ private UPnPEventListener listener;
+ private HashMap hash;
+
+ private class Subscription implements UPnPEventListener{
+ ServiceRegistration registration;
+
+ Subscription(String keys){
+ try {
+ Filter filter = context.createFilter(keys);
+ Properties props = new Properties();
+ props.put(UPnPEventListener.UPNP_FILTER, filter);
+ registration = context.registerService(UPnPEventListener.class.getName(), this, props);
+ }catch (Exception ex){
+ System.out.println(ex);
+ }
+ }
+
+ public void unsubscribe(){
+ registration.unregister();
+ }
+
+ public void notifyUPnPEvent(String arg0, String arg1, Dictionary arg2) {
+ listener.notifyUPnPEvent( arg0, arg1, arg2);
+ }
+ }
+
+
+ public UPnPSubscriber(BundleContext context,UPnPEventListener listener){
+ if ((context == null)|| (listener == null))
+ throw new IllegalArgumentException("Illegal arguments in UPnPSubscriber constructor.");
+ this.context = context;
+ this.listener = listener;
+ hash = new HashMap();
+ }
+
+ public void subscribe(String filter){
+ if (hash.get(filter) == null){
+ hash.put(filter, new Subscription(filter));
+ }
+ }
+
+ public void unsubscribe(String filter){
+ if (hash.containsKey(filter)) {
+ Subscription subscription = (Subscription) hash.get(filter);
+ subscription.unsubscribe();
+ hash.remove(filter);
+ }
+ }
+
+ public void unsubscribeAll(){
+ Iterator list = hash.entrySet().iterator();
+ while (list.hasNext()){
+ Map.Entry entry = (Map.Entry) list.next();
+ Subscription subcription = (Subscription) entry.getValue();
+ subcription.unsubscribe();
+ list.remove();
+ }
+ }
+
+ public String subscribeServiceIdOf(String deviceId, String serviceId){
+ String keys = "(&(" + UPnPDevice.ID + "="+ deviceId + ")(" + UPnPService.ID + "=" + serviceId + "))";
+ subscribe(keys);
+ return keys;
+ }
+
+ public String subscribeServiceTypeOf(String deviceId, String serviceType){
+ String keys = "(&(" + UPnPDevice.ID + "="+ deviceId + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
+ subscribe(keys);
+ return keys;
+ }
+
+ public String subscribeEveryServiceType(String deviceType, String serviceType){
+ String keys = "(&(" + UPnPDevice.TYPE + "="+ deviceType + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
+ subscribe(keys);
+ return keys;
+ }
+
+ public String subscribeAllServicesOf(String deviceId){
+ String keys = "(" + UPnPDevice.ID + "="+ deviceId + ")";
+ subscribe(keys);
+ return keys;
+ }
+
+ public String subscribeEveryDeviceTypeServices(String deviceType){
+ String keys = "(" + UPnPDevice.TYPE + "="+ deviceType + ")";
+ subscribe(keys);
+ return keys;
+ }
+
+
+ public void unsubscribeServiceIdOf(String deviceId, String serviceId){
+ String keys = "(&(" + UPnPDevice.ID + "="+ deviceId + ")(" + UPnPService.ID + "=" + serviceId + "))";
+ unsubscribe(keys);
+ }
+
+ public void unsubscribeAllServicesOf(String deviceId){
+ String keys = "(" + UPnPDevice.ID + "="+ deviceId + ")";
+ unsubscribe(keys);
+ }
+}
\ No newline at end of file
Propchange: felix/sandbox/donsez/upnp.devicegen.util/src/main/java/org/apache/felix/upnp/devicegen/util/UPnPSubscriber.java
------------------------------------------------------------------------------
svn:eol-style = native