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 org.fourthline.cling.test.gena;
17  
18  import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
19  import org.fourthline.cling.binding.annotations.UpnpAction;
20  import org.fourthline.cling.binding.annotations.UpnpInputArgument;
21  import org.fourthline.cling.binding.annotations.UpnpOutputArgument;
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.meta.DeviceDetails;
26  import org.fourthline.cling.model.meta.LocalDevice;
27  import org.fourthline.cling.model.meta.LocalService;
28  import org.fourthline.cling.model.types.UDADeviceType;
29  import org.fourthline.cling.test.data.SampleData;
30  
31  /**
32   * @author Christian Bauer
33   */
34  public class GenaSampleData {
35  
36      public static LocalDevice createTestDevice() throws Exception {
37          return createTestDevice(LocalTestService.class);
38      }
39  
40      public static LocalDevice createTestDevice(Class<?> clazz) throws Exception {
41          return createTestDevice(
42                  SampleData.readService(
43                          new AnnotationLocalServiceBinder(),
44                          clazz
45                  )
46          );
47      }
48  
49      public static LocalDevice createTestDevice(LocalService service) throws Exception {
50          return new LocalDevice(
51                  SampleData.createLocalDeviceIdentity(),
52                  new UDADeviceType("BinaryLight", 1),
53                  new DeviceDetails("Example Binary Light"),
54                  service
55          );
56      }
57  
58      @org.fourthline.cling.binding.annotations.UpnpService(
59              serviceId = @UpnpServiceId("SwitchPower"),
60              serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
61      )
62      public static class LocalTestService {
63  
64          @UpnpStateVariable(sendEvents = false)
65          private boolean target = false;
66  
67          @UpnpStateVariable
68          private boolean status = false;
69  
70          @UpnpStateVariable(defaultValue = "foo")
71          Foo someVar;
72  
73          @UpnpAction
74          public void setTarget(@UpnpInputArgument(name = "NewTargetValue") boolean newTargetValue) {
75              target = newTargetValue;
76              status = newTargetValue;
77          }
78  
79          @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
80          public boolean getTarget() {
81              return target;
82          }
83  
84          @UpnpAction(name = "GetStatus", out = @UpnpOutputArgument(name = "ResultStatus", getterName = "getStatus"))
85          public void dummyStatus() {
86              // NOOP
87          }
88  
89          public boolean getStatus() {
90              return status;
91          }
92      }
93  
94      public static enum Foo {
95          foo, bar
96      }
97  
98  }