View Javadoc
1   package example.localservice;
2   
3   import org.fourthline.cling.binding.annotations.*;
4   import java.beans.PropertyChangeSupport;
5   
6   @UpnpService(
7           serviceId = @UpnpServiceId("SwitchPower"),
8           serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
9   )
10  public class SwitchPowerWithPropertyChangeSupport {
11  
12      private final PropertyChangeSupport propertyChangeSupport;
13  
14      public SwitchPowerWithPropertyChangeSupport() {
15          this.propertyChangeSupport = new PropertyChangeSupport(this);
16      }
17  
18      public PropertyChangeSupport getPropertyChangeSupport() {
19          return propertyChangeSupport;
20      }
21  
22      @UpnpStateVariable(defaultValue = "0", sendEvents = false)
23      private boolean target = false;
24  
25      @UpnpStateVariable(defaultValue = "0")
26      private boolean status = false;
27  
28      @UpnpAction
29      public void setTarget(@UpnpInputArgument(name = "NewTargetValue") boolean newTargetValue) {
30  
31          boolean targetOldValue = target;
32          target = newTargetValue;
33          boolean statusOldValue = status;
34          status = newTargetValue;
35  
36          // These have no effect on the UPnP monitoring but it's JavaBean compliant
37          getPropertyChangeSupport().firePropertyChange("target", targetOldValue, target);
38          getPropertyChangeSupport().firePropertyChange("status", statusOldValue, status);
39  
40          // This will send a UPnP event, it's the name of a state variable that triggers events
41          getPropertyChangeSupport().firePropertyChange("Status", statusOldValue, status);
42      }
43  
44      @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
45      public boolean getTarget() {
46          return target;
47      }
48  
49      @UpnpAction(out = @UpnpOutputArgument(name = "ResultStatus"))
50      public boolean getStatus() {
51          return status;
52      }
53  
54  }