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 static void main(String[] aArgs) throws Exception {
- public void shutdown() {
- upnpService.shutdown();
- }
- }
+ Config config = new Config(30, "echo starting", "echo stopping",
+ "mediatomb");
- 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");
+ monitor.stop();
}
});
- for (;;) {
- UpnpStack stack = new UpnpStack();
- stack.search();
- Thread.sleep(10000);
- stack.shutdown();
-
- }
-
+ monitor.start();
}
}