completed setup for installation, fixed robustness problem.
[upnpmonitor] / monitor / src / main / java / org / wamblee / upnpmonitor / Main.java
index 8fc5b778dd49d5ae58d9712ad36ca9ecece547e4..f982fbc3e743ad450e80c348de6a022d54e1bd7e 100644 (file)
@@ -1,74 +1,38 @@
 package org.wamblee.upnpmonitor;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
 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 static void main(String[] aArgs) throws Exception {
 
-        }
+        String propertyFile = System
+            .getProperty("org.wamblee.upnpmonitor.propertyfile");
+        Properties props = new Properties();
+        InputStream is = new FileInputStream(new File(propertyFile));
+        props.load(is);
+        is.close();
 
-        public void search() {
-            controlPoint.search(new DeviceTypeHeader(deviceType));
-        }
+        Config config = Config.parse(props);
+        LOGGER.info("COnfiguration: " + config);
 
-        public void shutdown() {
-            upnpService.shutdown();
-        }
-    }
-
-    public static void main(String[] aArgs) throws Exception {
+        final Monitor monitor = new Monitor(config);
 
         Runtime.getRuntime().addShutdownHook(new Thread() {
             @Override
             public void run() {
-                System.out.println("Shutdown hook");
+                System.out
+                    .println("Signal caught, terminating monitor and executing shutdown command");
+                monitor.stop();
             }
         });
 
-        for (;;) {
-            UpnpStack stack = new UpnpStack();
-            stack.search();
-            Thread.sleep(10000);
-            stack.shutdown();
-
-        }
-
+        monitor.start();
     }
 }