1 /*
2 * Copyright (C) 2013 4th Line GmbH, Switzerland
3 *
4 * The contents of this file are subject to the terms of either the GNU
5 * Lesser General Public License Version 2 or later ("LGPL") or the
6 * Common Development and Distribution License Version 1 or later
7 * ("CDDL") (collectively, the "License"). You may not use this file
8 * except in compliance with the License. See LICENSE.txt for more
9 * information.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 */
15 package example.localservice;
16
17 import org.fourthline.cling.binding.annotations.*;
18
19 /**
20 * Getting an output value from another method
21 * <p>
22 * In the following example, the UPnP action has an output argument but the
23 * mapped method is void and does not return any value:
24 * </p>
25 * <a class="citation" href="javacode://this" style="include:INC1"/>
26 * <p>
27 * By providing a <code>getterName</code> in the annotation you can instruct
28 * Cling to call this getter method when the action method completes, taking
29 * the getter method's return value as the output argument value. If there
30 * are several output arguments you can map each to a different getter method.
31 * </p>
32 */
33 @UpnpService(
34 serviceId = @UpnpServiceId("SwitchPower"),
35 serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
36 )
37 public class SwitchPowerExtraGetter {
38
39 @UpnpStateVariable(defaultValue = "0", sendEvents = false)
40 private boolean target = false;
41
42 @UpnpStateVariable(defaultValue = "0")
43 private boolean status = false;
44
45 @UpnpAction
46 public void setTarget(@UpnpInputArgument(name = "NewTargetValue")
47 boolean newTargetValue) {
48 target = newTargetValue;
49 status = newTargetValue;
50 System.out.println("Switch is: " + status);
51 }
52
53 @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
54 public boolean getTarget() {
55 return target;
56 }
57
58 public boolean getStatus() { // DOC:INC1
59 return status;
60 }
61
62 @UpnpAction(
63 name = "GetStatus",
64 out = @UpnpOutputArgument(
65 name = "ResultStatus",
66 getterName = "getStatus"
67 )
68 )
69 public void retrieveStatus() {
70 // NOOP in this example
71 } // DOC:INC1
72
73 }