You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2006/05/06 13:59:43 UTC
svn commit: r400297 - in
/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp: ./ 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/eventadmin/
src/main/j...
Author: pauls
Date: Sat May 6 04:59:40 2006
New Revision: 400297
URL: http://svn.apache.org/viewcvs?rev=400297&view=rev
Log:
Initial implementation of a bundle mapping UPnP Events to the Event Admin (FELIX-68)
Added:
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/ (with props)
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml (with props)
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java (with props)
incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java (with props)
Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat May 6 04:59:40 2006
@@ -0,0 +1,16 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml?rev=400297&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml Sat May 6 04:59:40 2006
@@ -0,0 +1,56 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>osgi-bundle</packaging>
+ <name>Apache Felix EventAdmin Bridge UPnP</name>
+ <artifactId>org.apache.felix.eventadmin.bridge.upnp</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <version>${pom.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>EventAdmin Bridge UPnP</bundleName>
+ <bundleVendor>Apache Software Foundation</bundleVendor>
+ <bundleDescription>
+ This bundle provides a bridge between UPnP and EventAdmin events.
+ </bundleDescription>
+ <bundleActivator>
+ org.apache.felix.eventadmin.bridge.upnp.Activator
+ </bundleActivator>
+ <importPackage>
+ org.osgi.framework, org.osgi.service.event; version=1.0.1, org.osgi.service.upnp; version=1.1
+ </importPackage>
+ <importService>
+ org.osgi.service.event.EventAdmin
+ </importService>
+ <exportService>
+ org.osgi.service.upnp.UPnPEventListener
+ </exportService>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java?rev=400297&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java (added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java Sat May 6 04:59:40 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.eventadmin.bridge.upnp;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The BundleActivator that will register an UPnPEventListener service with the
+ * framework on start. Subsequently, UPnPEvents will be bridged to available
+ * EventAdmin services (as per spec).
+ *
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator
+{
+ /**
+ * This registers an UPnPEventListener service with the framework that bridges
+ * UPnPEvents to the EventAdmin.
+ *
+ * @param context The context to use
+ *
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(final BundleContext context) throws Exception
+ {
+ new UPnPEventToEventAdminBridge(context);
+ }
+
+ /**
+ * Stop the bridging of UPnPEvents to the EventAdmin.
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(final BundleContext context) throws Exception
+ {
+ // Services are unregistered by the framework
+ }
+}
Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java?rev=400297&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java (added)
+++ incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java Sat May 6 04:59:40 2006
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.eventadmin.bridge.upnp;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.upnp.UPnPEventListener;
+
+/**
+ * This class registers itself as an UPnPEventListener service with the
+ * framework and subsequently, bridges UPnPEvents received to available EventAdmin
+ * services. In order to track EventAdmin services this class registers itself as
+ * a ServiceListener for EventAdmin services too.
+ *
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class UPnPEventToEventAdminBridge implements ServiceListener,
+ UPnPEventListener
+{
+ // The references to the EventAdmins additionally, used as a lock
+ private final Set m_refs = new HashSet();
+
+ private final BundleContext m_context;
+
+ /**
+ * Registers itself as an UPnPEventListener service with the given context and
+ * in order to track EventAdmin services as a ServicListener too.
+ *
+ * @param context The context to register with.
+ */
+ public UPnPEventToEventAdminBridge(final BundleContext context)
+ {
+ synchronized(m_refs)
+ {
+ m_context = context;
+
+ try {
+ m_context.addServiceListener(this, "(" + Constants.OBJECTCLASS +
+ "=" + EventAdmin.class.getName() + ")");
+
+ final ServiceReference[] refs = m_context.getServiceReferences(
+ EventAdmin.class.getName(), null);
+
+ if(null != refs)
+ {
+ for(int i = 0;i < refs.length;i++)
+ {
+ m_refs.add(refs[i]);
+ }
+ }
+ } catch(InvalidSyntaxException e) {
+ // This will never happen
+ }
+
+ m_context.registerService(UPnPEventListener.class.getName(), this, null);
+ }
+ }
+
+ /**
+ * Add newly registered service references.
+ *
+ * @param event If event.getType equals REGISTERED the reference is added.
+ *
+ * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+ */
+ public void serviceChanged(final ServiceEvent event)
+ {
+ synchronized (m_refs)
+ {
+ if(ServiceEvent.REGISTERED == event.getType())
+ {
+ m_refs.add(event.getServiceReference());
+ }
+ }
+ }
+
+ /**
+ * Bridge any event to all available EventAdmin services.
+ *
+ * @param deviceId Bridged to <tt>upnp.deviceId</tt>
+ * @param serviceId Bridged to <tt>upnp.serviceId</tt>
+ * @param events Bridged to <tt>upnp.events</tt>
+ *
+ * @see org.osgi.service.upnp.UPnPEventListener#notifyUPnPEvent(java.lang.String, java.lang.String, java.util.Dictionary)
+ */
+ public void notifyUPnPEvent(final String deviceId, final String serviceId,
+ final Dictionary events)
+ {
+ synchronized (m_refs)
+ {
+ for (Iterator iter = m_refs.iterator(); iter.hasNext();)
+ {
+ final ServiceReference ref = (ServiceReference) iter.next();
+
+ final EventAdmin eventAdmin = (EventAdmin) m_context.getService(ref);
+
+ if(null != eventAdmin)
+ {
+ eventAdmin.postEvent(new Event("org/osgi/service/upnp/UPnPEvent",
+ new Hashtable(){{
+ put("upnp.deviceId", deviceId);
+ put("upnp.serviceId", serviceId);
+ put("upnp.events", events);
+ }}));
+// TODO: See 113.3.2
+
+ m_context.ungetService(ref);
+ }
+ else
+ {
+ iter.remove();
+ }
+ }
+ }
+ }
+}
Propchange: incubator/felix/trunk/org.apache.felix.eventadmin.bridge.upnp/src/main/java/org/apache/felix/eventadmin/bridge/upnp/UPnPEventToEventAdminBridge.java
------------------------------------------------------------------------------
svn:eol-style = native