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  package example.messagebox;
16  
17  import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
18  import org.fourthline.cling.binding.annotations.UpnpAction;
19  import org.fourthline.cling.binding.annotations.UpnpInputArgument;
20  import org.fourthline.cling.binding.annotations.UpnpService;
21  import org.fourthline.cling.binding.annotations.UpnpServiceId;
22  import org.fourthline.cling.binding.annotations.UpnpServiceType;
23  import org.fourthline.cling.binding.annotations.UpnpStateVariable;
24  import org.fourthline.cling.binding.annotations.UpnpStateVariables;
25  import org.fourthline.cling.model.DefaultServiceManager;
26  import org.fourthline.cling.model.meta.DeviceDetails;
27  import org.fourthline.cling.model.meta.DeviceIdentity;
28  import org.fourthline.cling.model.meta.LocalDevice;
29  import org.fourthline.cling.model.meta.LocalService;
30  import org.fourthline.cling.model.types.DeviceType;
31  import org.fourthline.cling.model.types.UDN;
32  
33  /**
34   * @author Christian Bauer
35   */
36  public class MessageBoxSampleData {
37  
38      public static LocalService readService(Class<?> serviceClass) throws Exception {
39          LocalService service = new AnnotationLocalServiceBinder().read(serviceClass);
40          service.setManager(
41                  new DefaultServiceManager(service, serviceClass)
42          );
43          return service;
44      }
45  
46      public static LocalDevice createDevice(Class<?> serviceClass) throws Exception {
47          return new LocalDevice(
48                  new DeviceIdentity(new UDN("1111")),
49                  new DeviceType("samsung.com", "PersonalMessageReceiver"),
50                  new DeviceDetails("My TV"),
51                  readService(serviceClass)
52          );
53      }
54  
55      @UpnpService(
56              serviceId = @UpnpServiceId(namespace = "samsung.com", value = "MessageBoxService"),
57              serviceType = @UpnpServiceType(namespace = "samsung.com", value = "MessageBoxService")
58      )
59      @UpnpStateVariables({
60              @UpnpStateVariable(name ="A_ARG_TYPE_MessageID", datatype = "string", sendEvents = false),
61              @UpnpStateVariable(name ="A_ARG_TYPE_MessageType", datatype = "string", sendEvents = false, defaultValue = "text/xml; charset=\"utf-8\""),
62              @UpnpStateVariable(name ="A_ARG_TYPE_Message", datatype = "string", sendEvents = false)
63      })
64      public static class MessageBoxService {
65  
66          @UpnpAction
67          public void addMessage(@UpnpInputArgument(name = "MessageID") String id,
68                                 @UpnpInputArgument(name = "MessageType") String type,
69                                 @UpnpInputArgument(name = "Message") String messageText) {
70              checkMessage(id, type, messageText);
71          }
72  
73          protected void checkMessage(String id, String type, String messageText) {
74  
75          }
76  
77      }
78  }