1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling;
17
18 import org.fourthline.cling.model.message.header.STAllHeader;
19 import org.fourthline.cling.model.meta.LocalDevice;
20 import org.fourthline.cling.model.meta.RemoteDevice;
21 import org.fourthline.cling.registry.Registry;
22 import org.fourthline.cling.registry.RegistryListener;
23
24
25
26
27 public class Main {
28
29 public static void main(String[] args) throws Exception {
30
31
32 RegistryListener listener = new RegistryListener() {
33
34 public void remoteDeviceDiscoveryStarted(Registry registry,
35 RemoteDevice device) {
36 System.out.println(
37 "Discovery started: " + device.getDisplayString()
38 );
39 }
40
41 public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice device, Exception ex) {
42 System.out.println(
43 "Discovery failed: " + device.getDisplayString() + " => " + ex
44 );
45 }
46
47 public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
48 System.out.println(
49 "Remote device available: " + device.getDisplayString()
50 );
51 }
52
53 public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
54 System.out.println(
55 "Remote device updated: " + device.getDisplayString()
56 );
57 }
58
59 public void remoteDeviceRemoved(Registry registry, RemoteDevice device) {
60 System.out.println(
61 "Remote device removed: " + device.getDisplayString()
62 );
63 }
64
65 public void localDeviceAdded(Registry registry, LocalDevice device) {
66 System.out.println(
67 "Local device added: " + device.getDisplayString()
68 );
69 }
70
71 public void localDeviceRemoved(Registry registry, LocalDevice device) {
72 System.out.println(
73 "Local device removed: " + device.getDisplayString()
74 );
75 }
76
77 public void beforeShutdown(Registry registry) {
78 System.out.println(
79 "Before shutdown, the registry has devices: " + registry.getDevices().size()
80 );
81 }
82
83 public void afterShutdown() {
84 System.out.println("Shutdown of registry complete!");
85
86 }
87 };
88
89
90 System.out.println("Starting Cling...");
91 UpnpService upnpService = new UpnpServiceImpl(listener);
92
93
94 System.out.println("Sending SEARCH message to all devices...");
95 upnpService.getControlPoint().search(new STAllHeader());
96
97
98 System.out.println("Waiting 10 seconds before shutting down...");
99 Thread.sleep(10000);
100
101
102 System.out.println("Stopping Cling...");
103 upnpService.shutdown();
104 }
105 }
106