1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.meta;
17
18 import org.fourthline.cling.model.ModelUtil;
19 import org.fourthline.cling.model.message.discovery.IncomingNotificationRequest;
20 import org.fourthline.cling.model.message.discovery.IncomingSearchResponse;
21 import org.fourthline.cling.model.types.UDN;
22
23 import java.net.InetAddress;
24 import java.net.URL;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class RemoteDeviceIdentity extends DeviceIdentity {
44
45 final private URL descriptorURL;
46 final private byte[] interfaceMacAddress;
47 final private InetAddress discoveredOnLocalAddress;
48
49 public RemoteDeviceIdentity(UDN udn, RemoteDeviceIdentity template) {
50 this(udn, template.getMaxAgeSeconds(), template.getDescriptorURL(), template.getInterfaceMacAddress(), template.getDiscoveredOnLocalAddress());
51 }
52
53 public RemoteDeviceIdentity(UDN udn, Integer maxAgeSeconds, URL descriptorURL, byte[] interfaceMacAddress, InetAddress discoveredOnLocalAddress) {
54 super(udn, maxAgeSeconds);
55 this.descriptorURL = descriptorURL;
56 this.interfaceMacAddress = interfaceMacAddress;
57 this.discoveredOnLocalAddress = discoveredOnLocalAddress;
58 }
59
60 public RemoteDeviceIdentity(IncomingNotificationRequest notificationRequest) {
61 this(notificationRequest.getUDN(),
62 notificationRequest.getMaxAge(),
63 notificationRequest.getLocationURL(),
64 notificationRequest.getInterfaceMacHeader(),
65 notificationRequest.getLocalAddress()
66 );
67 }
68
69 public RemoteDeviceIdentity(IncomingSearchResponse searchResponse) {
70 this(searchResponse.getRootDeviceUDN(),
71 searchResponse.getMaxAge(),
72 searchResponse.getLocationURL(),
73 searchResponse.getInterfaceMacHeader(),
74 searchResponse.getLocalAddress()
75 );
76 }
77
78 public URL getDescriptorURL() {
79 return descriptorURL;
80 }
81
82 public byte[] getInterfaceMacAddress() {
83 return interfaceMacAddress;
84 }
85
86 public InetAddress getDiscoveredOnLocalAddress() {
87 return discoveredOnLocalAddress;
88 }
89
90 public byte[] getWakeOnLANBytes() {
91 if (getInterfaceMacAddress() == null) return null;
92 byte[] bytes = new byte[6 + 16 * getInterfaceMacAddress().length];
93 for (int i = 0; i < 6; i++) {
94 bytes[i] = (byte) 0xff;
95 }
96 for (int i = 6; i < bytes.length; i += getInterfaceMacAddress().length) {
97 System.arraycopy(getInterfaceMacAddress(), 0, bytes, i, getInterfaceMacAddress().length);
98 }
99 return bytes;
100 }
101
102 @Override
103 public String toString() {
104
105 if(ModelUtil.ANDROID_RUNTIME) {
106 return "(RemoteDeviceIdentity) UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
107 }
108 return "(" + getClass().getSimpleName() + ") UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL();
109 }
110 }