Package: DefaultDevicePublisher
DefaultDevicePublisher
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultDevicePublisher(Class) |
|
|
|
|
|
||||||||||||||||||||
computeFriendyName() |
|
|
|
|
|
||||||||||||||||||||
getDevice() |
|
|
|
|
|
||||||||||||||||||||
getDlnaCaps() |
|
|
|
|
|
||||||||||||||||||||
getDlnaDocs() |
|
|
|
|
|
||||||||||||||||||||
getFriendlyName() |
|
|
|
|
|
||||||||||||||||||||
getIcons() |
|
|
|
|
|
||||||||||||||||||||
getManufacturerDetails() |
|
|
|
|
|
||||||||||||||||||||
getMaxAge() |
|
|
|
|
|
||||||||||||||||||||
getModelDetails() |
|
|
|
|
|
||||||||||||||||||||
getModelName() |
|
|
|
|
|
||||||||||||||||||||
getPresentationUri() |
|
|
|
|
|
||||||||||||||||||||
getSerialNumber() |
|
|
|
|
|
||||||||||||||||||||
getUdaDeviceType() |
|
|
|
|
|
||||||||||||||||||||
getUdn() |
|
|
|
|
|
||||||||||||||||||||
getVersion() |
|
|
|
|
|
||||||||||||||||||||
initialize() |
|
|
|
|
|
||||||||||||||||||||
isAutoPublish() |
|
|
|
|
|
||||||||||||||||||||
isUseHostNameInFriendlyName() |
|
|
|
|
|
||||||||||||||||||||
publishDevice() |
|
|
|
|
|
||||||||||||||||||||
setAutoPublish(boolean) |
|
|
|
|
|
||||||||||||||||||||
setDlnaCaps(List) |
|
|
|
|
|
||||||||||||||||||||
setDlnaDocs(List) |
|
|
|
|
|
||||||||||||||||||||
setFriendlyName(String) |
|
|
|
|
|
||||||||||||||||||||
setIcons(List) |
|
|
|
|
|
||||||||||||||||||||
setManufacturerDetails(ManufacturerDetails) |
|
|
|
|
|
||||||||||||||||||||
setMaxAge(int) |
|
|
|
|
|
||||||||||||||||||||
setModelDetails(ModelDetails) |
|
|
|
|
|
||||||||||||||||||||
setModelName(String) |
|
|
|
|
|
||||||||||||||||||||
setPresentationUri(String) |
|
|
|
|
|
||||||||||||||||||||
setSerialNumber(String) |
|
|
|
|
|
||||||||||||||||||||
setUdaDeviceType(UDADeviceType) |
|
|
|
|
|
||||||||||||||||||||
setUdn(UDN) |
|
|
|
|
|
||||||||||||||||||||
setUseHostNameInFriendlyName(boolean) |
|
|
|
|
|
||||||||||||||||||||
setVersion(String) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.upnp.mediaserver.impl.device;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.PostConstruct;
31: import javax.inject.Inject;
32: import java.util.Arrays;
33: import java.util.Collections;
34: import java.util.List;
35: import java.util.Optional;
36: import java.net.InetAddress;
37: import java.net.URI;
38: import java.net.UnknownHostException;
39: import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
40: import org.fourthline.cling.UpnpService;
41: import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
42: import org.fourthline.cling.model.DefaultServiceManager;
43: import org.fourthline.cling.model.ValidationException;
44: import org.fourthline.cling.model.meta.DeviceDetails;
45: import org.fourthline.cling.model.meta.DeviceIdentity;
46: import org.fourthline.cling.model.meta.Icon;
47: import org.fourthline.cling.model.meta.LocalDevice;
48: import org.fourthline.cling.model.meta.LocalService;
49: import org.fourthline.cling.model.meta.ManufacturerDetails;
50: import org.fourthline.cling.model.meta.ModelDetails;
51: import org.fourthline.cling.model.types.DLNACaps;
52: import org.fourthline.cling.model.types.DLNADoc;
53: import org.fourthline.cling.model.types.UDADeviceType;
54: import org.fourthline.cling.model.types.UDN;
55: import lombok.Getter;
56: import lombok.RequiredArgsConstructor;
57: import lombok.Setter;
58: import lombok.extern.slf4j.Slf4j;
59:
60: /***********************************************************************************************************************
61: *
62: * @author Fabrizio Giudici
63: *
64: **********************************************************************************************************************/
65: @RequiredArgsConstructor @Slf4j
66: public class DefaultDevicePublisher<T> implements DevicePublisher<T>
67: {
68: @Inject
69: private UpnpService upnpService;
70:
71: @Inject
72: private AutowireCapableBeanFactory beanFactory;
73:
74: private final Class<?> serviceClass;
75:
76: private LocalService service;
77:
78: private DefaultServiceManager<T> serviceManager;
79:
80: private final AnnotationLocalServiceBinder serviceBinder = new AnnotationLocalServiceBinder();
81:
82: @Getter @Setter
83: private boolean autoPublish = true;
84:
85: @Getter @Setter
86: private UDN udn;
87:
88: @Getter @Setter
89: private String friendlyName = "bm II";
90:
91: @Getter @Setter
92: private boolean useHostNameInFriendlyName = true;
93:
94: @Getter @Setter
95: private String serialNumber = "n.a.";
96:
97: @Getter @Setter
98: private String version = "n.a.";
99:
100: @Getter @Setter
101: private UDADeviceType udaDeviceType = new UDADeviceType("MediaServer", 1);
102:
103: @Getter @Setter
104: private int maxAge = 1800;
105:
106: @Getter @Setter
107: private String modelName = "blueMarine II media server";
108:
109: @Getter @Setter
110: private String presentationUri;
111:
112: @Getter @Setter
113: private ManufacturerDetails manufacturerDetails = new ManufacturerDetails("Tidalwave s.a.s.", "http://tidalwave.it");
114:
115: @Getter @Setter
116: private ModelDetails modelDetails = new ModelDetails(modelName,
117: modelName,
118: version,
119: "http://bluemarine.tidalwave.it");
120:
121: @Getter @Setter
122: private List<DLNADoc> dlnaDocs = Arrays.asList
123: (
124: new DLNADoc("DMS", DLNADoc.Version.V1_5),
125: new DLNADoc("M-DMS", DLNADoc.Version.V1_5)
126: );
127:
128: @Getter @Setter
129: private List<String> dlnaCaps = Arrays.asList
130: (
131: "av-upload", "image-upload", "audio-upload"
132: );
133:
134: @Getter @Setter
135: private List<Icon> icons = Collections.emptyList();
136:
137: private LocalDevice device;
138:
139: private ValidationException exception;
140:
141: /*******************************************************************************************************************
142: *
143: * {@inheritDoc}
144: *
145: ******************************************************************************************************************/
146: @Override @Nonnull
147: public LocalDevice getDevice()
148: throws ValidationException
149: {
150:• if (exception != null)
151: {
152: throw exception;
153: }
154:
155:• assert device != null;
156:
157: return device;
158: }
159:
160: /*******************************************************************************************************************
161: *
162: * {@inheritDoc}
163: *
164: ******************************************************************************************************************/
165: @Override
166: public void publishDevice()
167: throws ValidationException
168: {
169: try
170: {
171: udn = UDN.uniqueSystemIdentifier("1");
172: service = serviceBinder.read(serviceClass);
173: serviceManager = new AutowireServiceManager<>(beanFactory, service, serviceClass);
174: service.setManager(serviceManager);
175: log.info("publishDevice() - {}", service);
176: final DeviceDetails deviceDetails = new DeviceDetails(computeFriendyName(),
177: manufacturerDetails,
178: modelDetails,
179: serialNumber,
180: null, // UPC
181: Optional.ofNullable(presentationUri).map(URI::create).orElse(null),
182: dlnaDocs.toArray(new DLNADoc[0]),
183: new DLNACaps(dlnaCaps.toArray(new String[0])));
184: device = new LocalDevice(new DeviceIdentity(udn, maxAge),
185: udaDeviceType,
186: deviceDetails,
187: icons.toArray(new Icon[0]),
188: service);
189: upnpService.getRegistry().addDevice(device);
190: }
191: catch (ValidationException e)
192: {
193: this.exception = e;
194: throw e;
195: }
196: }
197:
198: /*******************************************************************************************************************
199: *
200: *
201: ******************************************************************************************************************/
202: @PostConstruct
203: private void initialize()
204: {
205:• if (autoPublish)
206: {
207: try
208: {
209: publishDevice();
210: }
211: catch (RuntimeException | ValidationException e)
212: {
213: log.error("Could not publish device", e);
214: }
215: }
216: }
217:
218: /*******************************************************************************************************************
219: *
220: *
221: ******************************************************************************************************************/
222: @Nonnull
223: private String computeFriendyName()
224: {
225: final StringBuilder buffer = new StringBuilder(friendlyName);
226:
227:• if (useHostNameInFriendlyName)
228: {
229: try
230: {
231: buffer.append(" (").append(InetAddress.getLocalHost().getCanonicalHostName()).append(")");
232: }
233: catch (UnknownHostException e)
234: {
235: log.warn("Cannot get host name", e);
236: }
237: }
238:
239: return buffer.toString();
240: }
241: }