1 package org.wamblee.upnpmonitor;
3 import java.util.logging.Logger;
5 import org.teleal.cling.UpnpService;
6 import org.teleal.cling.UpnpServiceImpl;
7 import org.teleal.cling.controlpoint.ControlPoint;
8 import org.teleal.cling.model.message.header.DeviceTypeHeader;
9 import org.teleal.cling.model.meta.Device;
10 import org.teleal.cling.model.types.DeviceType;
11 import org.teleal.cling.registry.DefaultRegistryListener;
12 import org.teleal.cling.registry.Registry;
13 import org.teleal.cling.registry.RegistryListener;
17 private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
19 public static class UpnpStack {
20 private UpnpService upnpService;
21 private ControlPoint controlPoint;
22 private DeviceType deviceType;
25 RegistryListener listener = new DefaultRegistryListener() {
27 public void deviceAdded(Registry aRegistry, Device aDevice) {
28 super.deviceAdded(aRegistry, aDevice);
29 System.out.println("Device added: " +
30 aDevice.getDisplayString());
31 System.out.println(aDevice.getType());
35 public void deviceRemoved(Registry aRegistry, Device aDevice) {
36 super.deviceRemoved(aRegistry, aDevice);
37 System.out.println("Device removed: " +
38 aDevice.getDisplayString());
41 upnpService = new UpnpServiceImpl(listener);
42 controlPoint = upnpService.getControlPoint();
43 deviceType = new DeviceType("schemas-upnp-org", "MediaServer");
47 public void search() {
48 controlPoint.search(new DeviceTypeHeader(deviceType));
51 public void shutdown() {
52 upnpService.shutdown();
56 public static void main(String[] aArgs) throws Exception {
58 Runtime.getRuntime().addShutdownHook(new Thread() {
61 System.out.println("Shutdown hook");
66 UpnpStack stack = new UpnpStack();