From f69194edc31d6dce4371d6af6d3bb558cdf77757 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 22 Dec 2012 21:08:22 +0100 Subject: [PATCH] upnpmonitor script added that executes a simple test program. --- .gitignore | 3 + .../java/org/wamblee/upnpmonitor/Main.java | 74 +++++++++++++++++++ .../files/opt/upnpmonitor/bin/upnpmonitor | 13 ++++ wamblee-upnpmonitor/pom.xml | 5 +- 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 monitor/src/main/java/org/wamblee/upnpmonitor/Main.java create mode 100755 wamblee-upnpmonitor/files/opt/upnpmonitor/bin/upnpmonitor diff --git a/.gitignore b/.gitignore index d913617..5d95490 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 0000000..8fc5b77 --- /dev/null +++ b/monitor/src/main/java/org/wamblee/upnpmonitor/Main.java @@ -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 index 0000000..6af0dd4 --- /dev/null +++ b/wamblee-upnpmonitor/files/opt/upnpmonitor/bin/upnpmonitor @@ -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 + + diff --git a/wamblee-upnpmonitor/pom.xml b/wamblee-upnpmonitor/pom.xml index 8a651ed..85fcd56 100644 --- a/wamblee-upnpmonitor/pom.xml +++ b/wamblee-upnpmonitor/pom.xml @@ -48,12 +48,13 @@ - /opt/upnpmonitor + /opt/upnpmonitor/bin root root + 755 - files/opt/upnpmonitor + files/opt/upnpmonitor/bin -- 2.31.1