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.mediaserver;
16  
17  import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
18  import org.fourthline.cling.model.DefaultServiceManager;
19  import org.fourthline.cling.model.meta.DeviceDetails;
20  import org.fourthline.cling.model.meta.DeviceIdentity;
21  import org.fourthline.cling.model.meta.LocalDevice;
22  import org.fourthline.cling.model.meta.LocalService;
23  import org.fourthline.cling.model.types.UDADeviceType;
24  import org.fourthline.cling.model.types.UDN;
25  import org.fourthline.cling.support.model.Protocol;
26  import org.fourthline.cling.support.model.ProtocolInfo;
27  import org.fourthline.cling.support.model.ProtocolInfos;
28  
29  /**
30   * @author Christian Bauer
31   */
32  public class MediaServerSampleData {
33  
34   public static LocalService readService(Class<?> serviceClass) throws Exception {
35          LocalService service = new AnnotationLocalServiceBinder().read(serviceClass);
36          service.setManager(
37                  new DefaultServiceManager(service, serviceClass)
38          );
39          return service;
40      }
41  
42      public static LocalDevice createDevice(Class<?> serviceClass) throws Exception {
43          return new LocalDevice(
44                  new DeviceIdentity(new UDN("1111")),
45                  new UDADeviceType("MediaServer"),
46                  new DeviceDetails("My MediaServer"),
47                  readService(serviceClass)
48          );
49      }
50  
51      public static ProtocolInfos createSourceProtocols() {
52          final ProtocolInfos sourceProtocols =                                           // DOC: PROT
53                  new ProtocolInfos(
54                          new ProtocolInfo(
55                                  Protocol.HTTP_GET,
56                                  ProtocolInfo.WILDCARD,
57                                  "audio/mpeg",
58                                  "DLNA.ORG_PN=MP3;DLNA.ORG_OP=01"
59                          ),
60                          new ProtocolInfo(
61                                  Protocol.HTTP_GET,
62                                  ProtocolInfo.WILDCARD,
63                                  "video/mpeg",
64                                  "DLNA.ORG_PN=MPEG1;DLNA.ORG_OP=01;DLNA.ORG_CI=0"
65                          )
66                  );                                                                      // DOC: PROT
67          return sourceProtocols;
68      }
69  
70      
71  }