upnpmonitor script added that executes a simple test program.
authorErik Brakkee <erik@brakkee.org>
Sat, 22 Dec 2012 20:08:22 +0000 (21:08 +0100)
committerErik Brakkee <erik@brakkee.org>
Sat, 22 Dec 2012 20:08:22 +0000 (21:08 +0100)
.gitignore
monitor/src/main/java/org/wamblee/upnpmonitor/Main.java [new file with mode: 0644]
wamblee-upnpmonitor/files/opt/upnpmonitor/bin/upnpmonitor [new file with mode: 0755]
wamblee-upnpmonitor/pom.xml

index d913617bcdd124aeeb9f302c2aa7b1627251ae10..5d95490188fda02e825195f71513f966fad0e260 100644 (file)
@@ -1,2 +1,5 @@
 target
+.project
+.classpath
+.settings
 
diff --git a/monitor/src/main/java/org/wamblee/upnpmonitor/Main.java b/monitor/src/main/java/org/wamblee/upnpmonitor/Main.java
new file mode 100644 (file)
index 0000000..8fc5b77
--- /dev/null
@@ -0,0 +1,74 @@
+package org.wamblee.upnpmonitor;
+
+import java.util.logging.Logger;
+
+import org.teleal.cling.UpnpService;
+import org.teleal.cling.UpnpServiceImpl;
+import org.teleal.cling.controlpoint.ControlPoint;
+import org.teleal.cling.model.message.header.DeviceTypeHeader;
+import org.teleal.cling.model.meta.Device;
+import org.teleal.cling.model.types.DeviceType;
+import org.teleal.cling.registry.DefaultRegistryListener;
+import org.teleal.cling.registry.Registry;
+import org.teleal.cling.registry.RegistryListener;
+
+public class Main {
+
+    private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
+
+    public static class UpnpStack {
+        private UpnpService upnpService;
+        private ControlPoint controlPoint;
+        private DeviceType deviceType;
+
+        public UpnpStack() {
+            RegistryListener listener = new DefaultRegistryListener() {
+                @Override
+                public void deviceAdded(Registry aRegistry, Device aDevice) {
+                    super.deviceAdded(aRegistry, aDevice);
+                    System.out.println("Device added: " +
+                        aDevice.getDisplayString());
+                    System.out.println(aDevice.getType());
+                }
+
+                @Override
+                public void deviceRemoved(Registry aRegistry, Device aDevice) {
+                    super.deviceRemoved(aRegistry, aDevice);
+                    System.out.println("Device removed: " +
+                        aDevice.getDisplayString());
+                }
+            };
+            upnpService = new UpnpServiceImpl(listener);
+            controlPoint = upnpService.getControlPoint();
+            deviceType = new DeviceType("schemas-upnp-org", "MediaServer");
+
+        }
+
+        public void search() {
+            controlPoint.search(new DeviceTypeHeader(deviceType));
+        }
+
+        public void shutdown() {
+            upnpService.shutdown();
+        }
+    }
+
+    public static void main(String[] aArgs) throws Exception {
+
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                System.out.println("Shutdown hook");
+            }
+        });
+
+        for (;;) {
+            UpnpStack stack = new UpnpStack();
+            stack.search();
+            Thread.sleep(10000);
+            stack.shutdown();
+
+        }
+
+    }
+}
diff --git a/wamblee-upnpmonitor/files/opt/upnpmonitor/bin/upnpmonitor b/wamblee-upnpmonitor/files/opt/upnpmonitor/bin/upnpmonitor
new file mode 100755 (executable)
index 0000000..6af0dd4
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+
+jardir="$( dirname $0 )/../lib"
+classpath=""
+for jar in $jardir/*.jar
+do
+  classpath="$classpath:$jar"
+done
+
+java -classpath $classpath org.wamblee.upnpmonitor.Main
+
+
index 8a651ed83e54e2637bd82476131bb5b7172025cd..85fcd569be6798c8848d37098e4d676fff90cecb 100644 (file)
                         </mapping>
                                                
                                                <mapping>
-                            <directory>/opt/upnpmonitor</directory>
+                            <directory>/opt/upnpmonitor/bin</directory>
                             <username>root</username>
                             <groupname>root</groupname>
+                                                       <filemode>755</filemode>
                             <sources>
                                 <source>
-                                    <location>files/opt/upnpmonitor</location>
+                                    <location>files/opt/upnpmonitor/bin</location>
                                 </source>
                             </sources>
                         </mapping>