kodi
PltDeviceHost.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - Device Host
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
39 #ifndef _PLT_DEVICE_HOST_H_
40 #define _PLT_DEVICE_HOST_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltDeviceData.h"
47 #include "PltSsdp.h"
48 #include "PltTaskManager.h"
49 #include "PltAction.h"
50 #include "PltHttp.h"
51 #include "PltHttpServer.h"
52 
53 /*----------------------------------------------------------------------
54 | forward declarations
55 +---------------------------------------------------------------------*/
57 class PLT_SsdpListenTask;
58 
59 /*----------------------------------------------------------------------
60 | PLT_DeviceHost class
61 +---------------------------------------------------------------------*/
72 {
73 public:
86  PLT_DeviceHost(const char* description_path = "/",
87  const char* uuid = "",
88  const char* device_type = "",
89  const char* friendly_name = "",
90  bool show_ip = false,
91  NPT_UInt16 port = 0,
92  bool port_rebind = false);
93  ~PLT_DeviceHost() override;
94 
95  virtual void SetExtraBroadcast(bool broadcast) { m_ExtraBroascast = broadcast; }
96 
104  virtual void SetByeByeFirst(bool bye_bye_first) { m_ByeByeFirst = bye_bye_first; }
105 
110  virtual NPT_UInt16 GetPort() { return m_Port; };
111 
116  NPT_Result SetLeaseTime(NPT_TimeInterval lease_time) { return PLT_DeviceData::SetLeaseTime(lease_time); }
117 
118 protected:
126  NPT_Result SetupResponse(NPT_HttpRequest& request,
127  const NPT_HttpRequestContext& context,
128  NPT_HttpResponse& response) override;
129 
137  static NPT_Result Announce(PLT_DeviceData* device,
138  NPT_HttpRequest& request,
140  PLT_SsdpAnnounceType type);
148  NPT_Result Announce(NPT_HttpRequest& request,
149  NPT_UdpSocket& socket,
150  PLT_SsdpAnnounceType type) {
151  return Announce(this, request, socket, type);
152  }
153 
159  NPT_Result OnSsdpPacket(const NPT_HttpRequest& request,
160  const NPT_HttpRequestContext& context) override;
161 
171  static NPT_Result SendSsdpSearchResponse(PLT_DeviceData* device,
172  NPT_HttpResponse& response,
173  NPT_UdpSocket& socket,
174  const char* st,
175  const NPT_SocketAddress* addr = NULL);
185  virtual NPT_Result SendSsdpSearchResponse(NPT_HttpResponse& response,
186  NPT_UdpSocket& socket,
187  const char* st,
188  const NPT_SocketAddress* addr = NULL) {
189  return SendSsdpSearchResponse(this, response, socket, st, addr);
190  }
191 
192 public:
204  virtual NPT_Result AddIcon(const PLT_DeviceIcon& icon,
205  const char* fileroot,
206  const char* urlroot = "/");
207 
215  virtual NPT_Result AddIcon(const PLT_DeviceIcon& icon,
216  const void* data,
217  NPT_Size size,
218  bool copy = true);
219 
220 protected:
225  virtual NPT_Result SetupServices() = 0;
226 
231  virtual NPT_Result SetupIcons();
232 
237  virtual NPT_Result SetupDevice();
238 
244  virtual NPT_Result Start(PLT_SsdpListenTask* task);
245 
251  virtual NPT_Result Stop(PLT_SsdpListenTask* task);
252 
260  virtual NPT_Result OnAction(PLT_ActionReference& action,
261  const PLT_HttpRequestContext& context);
262 
270  virtual NPT_Result ProcessGetDescription(NPT_HttpRequest& request,
271  const NPT_HttpRequestContext& context,
272  NPT_HttpResponse& response);
273 
281  virtual NPT_Result ProcessGetSCPD(PLT_Service* service,
282  NPT_HttpRequest& request,
283  const NPT_HttpRequestContext& context,
284  NPT_HttpResponse& response);
285 
293  virtual NPT_Result ProcessHttpGetRequest(NPT_HttpRequest& request,
294  const NPT_HttpRequestContext& context,
295  NPT_HttpResponse& response);
296 
305  virtual NPT_Result ProcessHttpPostRequest(NPT_HttpRequest& request,
306  const NPT_HttpRequestContext& context,
307  NPT_HttpResponse& response);
308 
316  virtual NPT_Result ProcessHttpSubscriberRequest(NPT_HttpRequest& request,
317  const NPT_HttpRequestContext& context,
318  NPT_HttpResponse& response);
319 
320 protected:
321  friend class PLT_UPnP;
322  friend class PLT_UPnP_DeviceStartIterator;
323  friend class PLT_UPnP_DeviceStopIterator;
324  friend class PLT_Service;
325  friend class NPT_Reference<PLT_DeviceHost>;
329 
330  PLT_TaskManagerReference m_TaskManager;
331  PLT_HttpServerReference m_HttpServer;
332  bool m_ExtraBroascast;
333  NPT_UInt16 m_Port;
334  bool m_PortRebind;
335  bool m_ByeByeFirst;
336  bool m_Started;
337 };
338 
340 
341 #endif /* _PLT_DEVICE_HOST_H_ */
The PLT_SsdpDeviceAnnounceTask class is a task to send UPnP Device SSDP announcements (alive or byeby...
Definition: PltSsdp.h:230
Definition: NptHttp.h:566
virtual NPT_Result ProcessGetSCPD(PLT_Service *service, NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
This method is called when a control point is requesting a service SCPD.
Definition: PltDeviceHost.cpp:463
static NPT_Result SendSsdpSearchResponse(PLT_DeviceData *device, NPT_HttpResponse &response, NPT_UdpSocket &socket, const char *st, const NPT_SocketAddress *addr=NULL)
Static method similar to SendSsdpSearchResponse.
Definition: PltDeviceHost.cpp:853
The PLT_SsdpAnnounceInterfaceIterator class is used to send SSDP announcements given a list of networ...
Definition: PltSsdp.h:183
virtual NPT_Result Stop(PLT_SsdpListenTask *task)
Called by PLT_TaskManager when the device is stoped.
Definition: PltDeviceHost.cpp:227
virtual NPT_Result SetupServices()=0
Required method for setting up UPnP services of device host (and any embedded).
Definition: NptHttp.h:315
Definition: NptHttp.h:282
The PLT_UPnP class maintains a list of devices (PLT_DeviceHost) to advertise and/or control points (P...
Definition: PltUPnP.h:68
virtual NPT_Result ProcessHttpPostRequest(NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
This method is called when a "POST" request has been received.
Definition: PltDeviceHost.cpp:487
virtual NPT_Result ProcessGetDescription(NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
This method is called when a control point is requesting the device description.
Definition: PltDeviceHost.cpp:441
The PLT_SsdpDeviceSearchResponseInterfaceIterator class looks for the best network interface to use t...
Definition: PltSsdp.h:132
The PLT_SsdpListenTask class is used to listen for incoming SSDP packets and keep track of a list of ...
Definition: PltSsdp.h:310
Definition: NptHttp.h:593
The PLT_DeviceIcon class represents a given instance of a UPnP device icon.
Definition: PltDeviceData.h:63
UPnP Service.
Definition: PltService.h:67
UPnP SSDP.
Definition: NptTime.h:50
NPT_Result SetupResponse(NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response) override
NPT_HttpRequestHandler method for setting up the response of an incoming HTTP request.
Definition: PltDeviceHost.cpp:387
static NPT_Result Announce(PLT_DeviceData *device, NPT_HttpRequest &request, NPT_UdpSocket &socket, PLT_SsdpAnnounceType type)
Static method similar to Announce.
Definition: PltDeviceHost.cpp:262
NPT_Result OnSsdpPacket(const NPT_HttpRequest &request, const NPT_HttpRequestContext &context) override
PLT_SsdpPacketListener method called when a M-SEARCH SSDP packet is received.
Definition: PltDeviceHost.cpp:795
Definition: NptSockets.h:77
The PLT_SsdpDeviceSearchResponseTask class is used by a PLT_DeviceHost to respond to SSDP M-SEARCH re...
Definition: PltSsdp.h:156
virtual NPT_Result SetupDevice()
Default implementation for setting up device host.
Definition: PltDeviceHost.cpp:157
virtual NPT_UInt16 GetPort()
Returns the port used by the internal HTTP server for all incoming requests.
Definition: PltDeviceHost.h:110
virtual NPT_Result OnAction(PLT_ActionReference &action, const PLT_HttpRequestContext &context)
This mehod is called when an action performed by a control point has been received and needs to be an...
Definition: PltDeviceHost.cpp:947
The PLT_SsdpPacketListener class is an interface for handling SSDP packets (M-SEARCH and NOTIFY)...
Definition: PltSsdp.h:70
virtual NPT_Result SetupIcons()
Default implementation for registering device icon resources.
Definition: PltDeviceHost.cpp:134
virtual NPT_Result Start(PLT_SsdpListenTask *task)
Called by PLT_TaskManager when the device is started.
Definition: PltDeviceHost.cpp:168
virtual NPT_Result SendSsdpSearchResponse(NPT_HttpResponse &response, NPT_UdpSocket &socket, const char *st, const NPT_SocketAddress *addr=NULL)
Called by PLT_SsdpDeviceSearchResponseTask when responding to a M-SEARCH SSDP request.
Definition: PltDeviceHost.h:185
PLT_DeviceHost(const char *description_path="/", const char *uuid="", const char *device_type="", const char *friendly_name="", bool show_ip=false, NPT_UInt16 port=0, bool port_rebind=false)
Creates a new instance of UPnP Device Host.
Definition: PltDeviceHost.cpp:59
UPnP Service Action.
The PLT_DeviceData class holds information about a device being advertised or found by a control poin...
Definition: PltDeviceData.h:93
UPnP Device Host.
Definition: PltDeviceHost.h:69
HTTP Server.
virtual NPT_Result ProcessHttpGetRequest(NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
This method is called when a "GET" request for a resource other than the device description, SCPD, or icons has been received.
Definition: PltDeviceHost.cpp:426
virtual void SetByeByeFirst(bool bye_bye_first)
When a UPnP device comes up, the specifications require that a SSDP bye-bye sequence is sent to force...
Definition: PltDeviceHost.h:104
NPT_Result Announce(NPT_HttpRequest &request, NPT_UdpSocket &socket, PLT_SsdpAnnounceType type)
Called during SSDP announce.
Definition: PltDeviceHost.h:148
virtual NPT_Result ProcessHttpSubscriberRequest(NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
This method is called when a request from a subscriber has been received.
Definition: PltDeviceHost.cpp:708
The PLT_HttpRequestContext class holds information about the request sent, the local & remote ip addr...
Definition: PltHttp.h:111
Runnable Tasks Manager.
NPT_Result SetLeaseTime(NPT_TimeInterval lease_time)
Sets the lease time.
Definition: PltDeviceHost.h:116
Definition: NptSockets.h:243
UPnP Device information.
virtual NPT_Result AddIcon(const PLT_DeviceIcon &icon, const char *fileroot, const char *urlroot="/")
Add UPnP icon information to serve from file system.
Definition: PltDeviceHost.cpp:99
Definition: PltUPnP.cpp:113
Definition: PltUPnP.cpp:88
HTTP utilities.