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;
17  
18  import org.fourthline.cling.binding.xml.DeviceDescriptorBinder;
19  import org.fourthline.cling.binding.xml.ServiceDescriptorBinder;
20  import org.fourthline.cling.model.Namespace;
21  import org.fourthline.cling.model.message.UpnpHeaders;
22  import org.fourthline.cling.model.meta.RemoteDeviceIdentity;
23  import org.fourthline.cling.model.meta.RemoteService;
24  import org.fourthline.cling.model.types.ServiceType;
25  import org.fourthline.cling.transport.spi.DatagramIO;
26  import org.fourthline.cling.transport.spi.DatagramProcessor;
27  import org.fourthline.cling.transport.spi.GENAEventProcessor;
28  import org.fourthline.cling.transport.spi.MulticastReceiver;
29  import org.fourthline.cling.transport.spi.NetworkAddressFactory;
30  import org.fourthline.cling.transport.spi.SOAPActionProcessor;
31  import org.fourthline.cling.transport.spi.StreamClient;
32  import org.fourthline.cling.transport.spi.StreamServer;
33  
34  import java.util.concurrent.Executor;
35  import java.util.concurrent.ExecutorService;
36  
37  /**
38   * Shared configuration data of the UPnP stack.
39   * <p>
40   * This interface offers methods for retrieval of configuration data by the
41   * {@link org.fourthline.cling.transport.Router} and the {@link org.fourthline.cling.registry.Registry},
42   * as well as other parts of the UPnP stack.
43   * </p>
44   * <p>
45   * You can re-use this interface if you implement a subclass of {@link UpnpServiceImpl} or
46   * if you create a new implementation of {@link UpnpService}.
47   * </p>
48   *
49   * @author Christian Bauer
50   */
51  public interface UpnpServiceConfiguration {
52  
53      /**
54       * @return A new instance of the {@link org.fourthline.cling.transport.spi.NetworkAddressFactory} interface.
55       */
56      public NetworkAddressFactory createNetworkAddressFactory();
57  
58      /**
59       * @return The shared implementation of {@link org.fourthline.cling.transport.spi.DatagramProcessor}.
60       */
61      public DatagramProcessor getDatagramProcessor();
62  
63      /**
64       * @return The shared implementation of {@link org.fourthline.cling.transport.spi.SOAPActionProcessor}.
65       */
66      public SOAPActionProcessor getSoapActionProcessor();
67  
68      /**
69       * @return The shared implementation of {@link org.fourthline.cling.transport.spi.GENAEventProcessor}.
70       */
71      public GENAEventProcessor getGenaEventProcessor();
72  
73      /**
74       * @return A new instance of the {@link org.fourthline.cling.transport.spi.StreamClient} interface.
75       */
76      public StreamClient createStreamClient();
77  
78      /**
79       * @param networkAddressFactory The configured {@link org.fourthline.cling.transport.spi.NetworkAddressFactory}.
80       * @return A new instance of the {@link org.fourthline.cling.transport.spi.MulticastReceiver} interface.
81       */
82      public MulticastReceiver createMulticastReceiver(NetworkAddressFactory networkAddressFactory);
83  
84      /**
85       * @param networkAddressFactory The configured {@link org.fourthline.cling.transport.spi.NetworkAddressFactory}.
86       * @return A new instance of the {@link org.fourthline.cling.transport.spi.DatagramIO} interface.
87       */
88      public DatagramIO createDatagramIO(NetworkAddressFactory networkAddressFactory);
89  
90      /**
91       * @param networkAddressFactory The configured {@link org.fourthline.cling.transport.spi.NetworkAddressFactory}.
92       * @return A new instance of the {@link org.fourthline.cling.transport.spi.StreamServer} interface.
93       */
94      public StreamServer createStreamServer(NetworkAddressFactory networkAddressFactory);
95  
96      /**
97       * @return The executor which runs the listening background threads for multicast datagrams.
98       */
99      public Executor getMulticastReceiverExecutor();
100 
101     /**
102      * @return The executor which runs the listening background threads for unicast datagrams.
103      */
104     public Executor getDatagramIOExecutor();
105 
106     /**
107      * @return The executor which runs the listening background threads for HTTP requests.
108      */
109     public ExecutorService getStreamServerExecutorService();
110 
111     /**
112      * @return The shared implementation of {@link org.fourthline.cling.binding.xml.DeviceDescriptorBinder} for the UPnP 1.0 Device Architecture..
113      */
114     public DeviceDescriptorBinder getDeviceDescriptorBinderUDA10();
115 
116     /**
117      * @return The shared implementation of {@link org.fourthline.cling.binding.xml.ServiceDescriptorBinder} for the UPnP 1.0 Device Architecture..
118      */
119     public ServiceDescriptorBinder getServiceDescriptorBinderUDA10();
120 
121     /**
122      * Returns service types that can be handled by this UPnP stack, all others will be ignored.
123      * <p>
124      * Return <code>null</code> to completely disable remote device and service discovery.
125      * All incoming notifications and search responses will then be dropped immediately.
126      * This is mostly useful in applications that only provide services with no (remote)
127      * control point functionality.
128      * </p>
129      * <p>
130      * Note that a discovered service type with version 2 or 3 will match an exclusive
131      * service type with version 1. UPnP services are required to be backwards
132      * compatible, version 2 is a superset of version 1, and version 3 is a superset
133      * of version 2, etc.
134      * </p>
135      *
136      * @return An array of service types that are exclusively discovered, no other service will
137      *         be discovered. A <code>null</code> return value will disable discovery!
138      *         An empty array means all services will be discovered.
139      */
140     public ServiceType[] getExclusiveServiceTypes();
141 
142     /**
143      * @return The time in milliseconds to wait between each registry maintenance operation.
144      */
145     public int getRegistryMaintenanceIntervalMillis();
146     
147     /**
148      * Optional setting for flooding alive NOTIFY messages for local devices.
149      * <p>
150      * Use this to advertise local devices at the specified interval, independent of its
151      * {@link org.fourthline.cling.model.meta.DeviceIdentity#maxAgeSeconds} value. Note
152      * that this will increase network traffic.
153      * </p>
154      * <p>
155      * Some control points (XBMC and other Platinum UPnP SDK based devices, OPPO-93) seem
156      * to not properly receive SSDP M-SEARCH replies sent by Cling, but will handle NOTIFY
157      * alive messages just fine.
158      * </p>
159      *
160      * @return The time in milliseconds for ALIVE message intervals, set to <code>0</code> to disable
161      */
162     public int getAliveIntervalMillis();
163 
164     /**
165      * Ignore the received event subscription timeout from remote control points.
166      * <p>
167      * Some control points have trouble renewing subscriptions properly; enabling this option
168      * in conjunction with a high value for
169      * {@link org.fourthline.cling.model.UserConstants#DEFAULT_SUBSCRIPTION_DURATION_SECONDS}
170      * ensures that your devices will not disappear on such control points.
171      * </p>
172      *
173      * @return <code>true</code> if the timeout in incoming event subscriptions should be ignored
174      *         and the default value ({@link org.fourthline.cling.model.UserConstants#DEFAULT_SUBSCRIPTION_DURATION_SECONDS})
175      *         should be used instead.
176      *
177      */
178     public boolean isReceivedSubscriptionTimeoutIgnored();
179 
180     /**
181      * Returns the time in seconds a remote device will be registered until it is expired.
182      * <p>
183      * This setting is useful on systems which do not support multicast networking
184      * (Android on HTC phones, for example). On such a system you will not receive messages when a
185      * remote device disappears from the network and you will not receive its periodic heartbeat
186      * alive messages. Only an initial search response (UDP unicast) has been received from the
187      * remote device, with its proposed maximum age. To avoid (early) expiration of the remote
188      * device, you can override its maximum age with this configuration setting, ignoring the
189      * initial maximum age sent by the device. You most likely want to return
190      * <code>0</code> in this case, so that the remote device is never expired unless you
191      * manually remove it from the {@link org.fourthline.cling.registry.Registry}. You typically remove
192      * the device when an action or GENA subscription request to the remote device failed.
193      * </p>
194      *
195      * @return <code>null</code> (the default) to accept the remote device's proposed maximum age, or
196      *         <code>0</code> for unlimited age, or a value in seconds.
197      */
198     public Integer getRemoteDeviceMaxAgeSeconds();
199 
200     /**
201      * Optional extra headers for device descriptor retrieval HTTP requests.
202      * <p>
203      * Some devices might require extra headers to recognize your control point, use this
204      * method to set these headers. They will be used for every descriptor (XML) retrieval
205      * HTTP request by Cling. See {@link org.fourthline.cling.model.profile.ClientInfo} for
206      * action request messages.
207      * </p>
208      *
209      * @param identity The (so far) discovered identity of the remote device.
210      * @return <code>null</code> or extra HTTP headers.
211      */
212     public UpnpHeaders getDescriptorRetrievalHeaders(RemoteDeviceIdentity identity);
213 
214     /**
215      * Optional extra headers for event subscription (almost HTTP) messages.
216      * <p>
217      * Some devices might require extra headers to recognize your control point, use this
218      * method to set these headers for GENA subscriptions. Note that the headers will
219      * not be applied to actual event messages, only subscribe, unsubscribe, and renewal.
220      * </p>
221      *
222      * @return <code>null</code> or extra HTTP headers.
223      */
224     public UpnpHeaders getEventSubscriptionHeaders(RemoteService service);
225 
226     /**
227      * @return The executor which runs the processing of asynchronous aspects of the UPnP stack (discovery).
228      */
229     public Executor getAsyncProtocolExecutor();
230 
231     /**
232      * @return The executor service which runs the processing of synchronous aspects of the UPnP stack (description, control, GENA).
233      */
234     public ExecutorService getSyncProtocolExecutorService();
235 
236     /**
237      * @return An instance of {@link org.fourthline.cling.model.Namespace} for this UPnP stack.
238      */
239     public Namespace getNamespace();
240 
241     /**
242      * @return The executor which runs the background thread for maintaining the registry.
243      */
244     public Executor getRegistryMaintainerExecutor();
245 
246     /**
247      * @return The executor which runs the notification threads of registry listeners.
248      */
249     public Executor getRegistryListenerExecutor();
250 
251     /**
252      * Called by the {@link org.fourthline.cling.UpnpService} on shutdown, useful to e.g. shutdown thread pools.
253      */
254     public void shutdown();
255 
256 }