1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package example.localservice;
17
18 import org.fourthline.cling.binding.annotations.UpnpAction;
19 import org.fourthline.cling.binding.annotations.UpnpInputArgument;
20 import org.fourthline.cling.binding.annotations.UpnpOutputArgument;
21 import org.fourthline.cling.binding.annotations.UpnpService;
22 import org.fourthline.cling.binding.annotations.UpnpServiceId;
23 import org.fourthline.cling.binding.annotations.UpnpServiceType;
24 import org.fourthline.cling.binding.annotations.UpnpStateVariable;
25 import org.fourthline.cling.binding.annotations.UpnpStateVariables;
26 import org.fourthline.cling.model.profile.RemoteClientInfo;
27
28 @UpnpService(
29 serviceId = @UpnpServiceId("SwitchPower"),
30 serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
31 )
32 @UpnpStateVariables(
33 {
34 @UpnpStateVariable(
35 name = "Target",
36 defaultValue = "0",
37 sendEvents = false
38 ),
39 @UpnpStateVariable(
40 name = "Status",
41 defaultValue = "0"
42 )
43 }
44 )
45 public class SwitchPowerWithClientInfo {
46
47 private boolean power;
48
49
50 @UpnpAction
51 public void setTarget(@UpnpInputArgument(name = "NewTargetValue")
52 boolean newTargetValue,
53 RemoteClientInfo clientInfo) {
54 power = newTargetValue;
55 System.out.println("Switch is: " + power);
56
57 if (clientInfo != null) {
58 System.out.println(
59 "Client's address is: " + clientInfo.getRemoteAddress()
60 );
61 System.out.println(
62 "Received message on: " + clientInfo.getLocalAddress()
63 );
64 System.out.println(
65 "Client's user agent is: " + clientInfo.getRequestUserAgent()
66 );
67 System.out.println(
68 "Client's custom header is: " +
69 clientInfo.getRequestHeaders().getFirstHeader("X-MY-HEADER")
70 );
71
72
73 clientInfo.getExtraResponseHeaders().add("X-MY-HEADER", "foobar");
74 }
75 }
76
77
78 @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
79 public boolean getTarget() {
80 return power;
81 }
82
83 @UpnpAction(out = @UpnpOutputArgument(name = "ResultStatus"))
84 public boolean getStatus() {
85 return power;
86 }
87 }