View Javadoc
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  
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.model.ModelUtil;
26  
27  import java.beans.PropertyChangeSupport;
28  
29  @UpnpService(
30          serviceId = @UpnpServiceId("SwitchPower"),
31          serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
32  )
33  public class SwitchPowerWithBundledPropertyChange {
34  
35      private final PropertyChangeSupport propertyChangeSupport;
36  
37      public SwitchPowerWithBundledPropertyChange() {
38          this.propertyChangeSupport = new PropertyChangeSupport(this);
39      }
40  
41      public PropertyChangeSupport getPropertyChangeSupport() {
42          return propertyChangeSupport;
43      }
44  
45      @UpnpStateVariable(defaultValue = "0")
46      private boolean target = false;
47  
48      @UpnpStateVariable(defaultValue = "0")
49      private boolean status = false;
50  
51      @UpnpAction
52      public void setTarget(@UpnpInputArgument(name = "NewTargetValue") boolean newTargetValue) {
53  
54          target = newTargetValue;
55          status = newTargetValue;
56  
57          // If several evented variables changed, bundle them in one event separated with commas:
58          getPropertyChangeSupport().firePropertyChange(
59              "Target, Status", null, null
60          );
61  
62          // Or if you don't like string manipulation:
63          // getPropertyChangeSupport().firePropertyChange(
64          //    ModelUtil.toCommaSeparatedList(new String[]{"Target", "Status"}), null, null
65          //);
66      }
67  
68      @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
69      public boolean getTarget() {
70          return target;
71      }
72  
73      @UpnpAction(out = @UpnpOutputArgument(name = "ResultStatus"))
74      public boolean getStatus() {
75          return status;
76      }
77  
78  }