kodi
PltDeviceData.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - Device Data
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_DATA_H_
40 #define _PLT_DEVICE_DATA_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltConstants.h"
47 
48 /*----------------------------------------------------------------------
49 | forward declarations
50 +---------------------------------------------------------------------*/
51 class PLT_Service;
52 class PLT_DeviceData;
53 
56 
57 /*----------------------------------------------------------------------
58 | PLT_DeviceIcon class
59 +---------------------------------------------------------------------*/
64 {
65 public:
66  PLT_DeviceIcon(const char* mimetype = "",
67  NPT_Int32 width = 0,
68  NPT_Int32 height = 0,
69  NPT_Int32 depth = 0,
70  const char* urlpath = "") :
71  m_MimeType(mimetype),
72  m_Width(width),
73  m_Height(height),
74  m_Depth(depth),
75  m_UrlPath(urlpath) {}
76  virtual ~PLT_DeviceIcon() {}
77 
78  NPT_String m_MimeType;
79  NPT_Int32 m_Width;
80  NPT_Int32 m_Height;
81  NPT_Int32 m_Depth;
82  NPT_String m_UrlPath;
83 };
84 
85 /*----------------------------------------------------------------------
86 | PLT_DeviceData class
87 +---------------------------------------------------------------------*/
94 {
95 public:
97  NPT_HttpUrl description_url = NPT_HttpUrl(NULL, 0, "/description.xml"),
98  const char* uuid = "",
99  NPT_TimeInterval lease_time = *PLT_Constants::GetInstance().GetDefaultDeviceLease(),
100  const char* device_type = "",
101  const char* friendly_name = "");
102 
103  /* methods */
104  virtual NPT_Result GetDescription(NPT_String& desc);
105  virtual NPT_String GetDescriptionUrl(const char* ip_address = NULL);
106  virtual NPT_HttpUrl GetURLBase();
107  virtual NPT_HttpUrl NormalizeURL(const NPT_String& url);
108  virtual NPT_Result GetDescription(NPT_XmlElementNode* parent, NPT_XmlElementNode** device = NULL);
109  virtual NPT_String GetIconUrl(const char* mimetype = NULL, NPT_Int32 maxsize = 0, NPT_Int32 maxdepth = 0);
110 
111  bool IsRoot() { return m_ParentUUID.IsEmpty(); }
112  const NPT_TimeInterval& GetLeaseTime() const { return m_LeaseTime; }
113  const NPT_String& GetUUID() const { return m_UUID; }
114  const NPT_String& GetFriendlyName() const { return m_FriendlyName; }
115  const NPT_String& GetType() const { return m_DeviceType; }
116  const NPT_String& GetModelDescription() const { return m_ModelDescription; }
117  const NPT_String& GetParentUUID() const { return m_ParentUUID; }
118  const NPT_IpAddress& GetLocalIP() const { return m_LocalIfaceIp; }
119 
120  const NPT_Array<PLT_Service*>& GetServices() const { return m_Services; }
121  const NPT_Array<PLT_DeviceDataReference>& GetEmbeddedDevices() const { return m_EmbeddedDevices; }
122 
123  NPT_Result FindEmbeddedDevice(const char* uuid, PLT_DeviceDataReference& device);
124  NPT_Result FindEmbeddedDeviceByType(const char* type, PLT_DeviceDataReference& device);
125  NPT_Result FindServiceById(const char* id, PLT_Service*& service);
126  NPT_Result FindServiceByType(const char* type, PLT_Service*& service);
127  NPT_Result FindServiceByName(const char* name, PLT_Service*& service);
128  NPT_Result FindServiceBySCPDURL(const char* url, PLT_Service*& service, bool recursive = false);
129  NPT_Result FindServiceByControlURL(const char* url, PLT_Service*& service, bool recursive = false);
130  NPT_Result FindServiceByEventSubURL(const char* url, PLT_Service*& service, bool recursive = false);
131 
132  /* called by PLT_Device subclasses */
133  NPT_Result AddEmbeddedDevice(PLT_DeviceDataReference& device);
134  NPT_Result RemoveEmbeddedDevice(PLT_DeviceDataReference& device);
135  NPT_Result AddService(PLT_Service* service);
136  NPT_Result RemoveService(PLT_Service* service);
137 
138  /* BOOTID UPnP 1/1 */
139  void SetBootId(NPT_UInt32 bootId);
140  void SetNextBootId(NPT_UInt32 nextBootId);
141  NPT_UInt32 GenerateNextBootId();
142 
143  operator const char* ();
144 
145 protected:
146  virtual ~PLT_DeviceData();
147 
148  virtual void Cleanup();
149  virtual NPT_Result OnAddExtraInfo(NPT_XmlElementNode* /*device_node*/) { return NPT_SUCCESS; }
150 
151 
152 private:
153  /* called by PLT_CtrlPoint when an existing device location is updated */
154  NPT_Result SetDescriptionUrl(NPT_HttpUrl& url);
155  NPT_Result SetLeaseTime(NPT_TimeInterval lease_time, NPT_TimeStamp lease_time_last_update = 0.);
156  NPT_Result SetURLBase(NPT_HttpUrl& url_base);
157  NPT_TimeStamp GetLeaseTimeLastUpdate();
158  void UpdateConfigId();
159 
160  /* class methods */
161  static NPT_Result SetDescription(PLT_DeviceDataReference& root_device,
162  NPT_TimeInterval leasetime,
163  NPT_HttpUrl description_url,
164  const char* description,
165  const NPT_HttpRequestContext& context);
166  static NPT_Result SetDescriptionDevice(PLT_DeviceDataReference& device,
167  NPT_XmlElementNode* device_node,
168  const NPT_HttpRequestContext& context);
169 
170 public:
171  NPT_String m_Manufacturer;
172  NPT_String m_ManufacturerURL;
173  NPT_String m_ModelDescription;
174  NPT_String m_ModelName;
175  NPT_String m_ModelNumber;
176  NPT_String m_ModelURL;
177  NPT_String m_SerialNumber;
178  NPT_String m_UPC;
179  NPT_String m_PresentationURL;
180  NPT_String m_DlnaDoc;
181  NPT_String m_DlnaCap;
182  NPT_String m_AggregationFlags;
183 
184 protected:
185  friend class NPT_Reference<PLT_DeviceData>;
186  friend class PLT_CtrlPoint;
187  friend class PLT_DeviceReadyIterator;
188  friend class PLT_DeviceHost;
189 
190  //members
191  NPT_String m_ParentUUID;
192  NPT_String m_UUID;
193  NPT_HttpUrl m_URLDescription;
194  NPT_HttpUrl m_URLBase;
195  NPT_String m_DeviceType;
196  NPT_String m_FriendlyName;
197  NPT_TimeInterval m_LeaseTime;
198  NPT_TimeStamp m_LeaseTimeLastUpdate;
199  NPT_Array<PLT_Service*> m_Services;
200  NPT_Array<PLT_DeviceDataReference> m_EmbeddedDevices;
202 
203  /* IP address of interface used when retrieving device description.
204  We need the info for the control point subscription callback */
205  NPT_IpAddress m_LocalIfaceIp;
206  NPT_String m_Representation;
207 
208 private:
209  NPT_UInt32 m_BootId;
210  NPT_UInt32 m_NextBootId;
211  NPT_UInt32 m_ConfigId;
212 };
213 
214 /*----------------------------------------------------------------------
215 | PLT_DeviceDataFinder
216 +---------------------------------------------------------------------*/
222 {
223 public:
224  // methods
225  PLT_DeviceDataFinder(const char* uuid) : m_UUID(uuid) {}
226  virtual ~PLT_DeviceDataFinder() {}
227 
228  bool operator()(const PLT_DeviceDataReference& data) const {
229  return data->GetUUID().Compare(m_UUID, true) ? false : true;
230  }
231 
232 private:
233  // members
234  NPT_String m_UUID;
235 };
236 
237 /*----------------------------------------------------------------------
238 | PLT_DeviceDataFinderByType
239 +---------------------------------------------------------------------*/
245 {
246 public:
247  // methods
248  PLT_DeviceDataFinderByType(const char* type) : m_Type(type) {}
249  virtual ~PLT_DeviceDataFinderByType() {}
250 
251  bool operator()(const PLT_DeviceDataReference& data) const {
252  return data->GetType().Compare(m_Type, true) ? false : true;
253  }
254 
255 private:
256  // members
257  NPT_String m_Type;
258 };
259 
260 #endif /* _PLT_DEVICE_DATA_H_ */
The PLT_DeviceDataFinder class returns a PLT_DeviceData instance given a device UUID.
Definition: PltDeviceData.h:221
Definition: NptXml.h:172
Definition: NptHttp.h:566
Definition: NptHttp.h:126
Definition: NptArray.h:54
Definition: PltCtrlPoint.cpp:206
The PLT_DeviceIcon class represents a given instance of a UPnP device icon.
Definition: PltDeviceData.h:63
UPnP Service.
Definition: PltService.h:67
Definition: NptTime.h:50
Definition: NptNetwork.h:74
The PLT_DeviceData class holds information about a device being advertised or found by a control poin...
Definition: PltDeviceData.h:93
UPnP Constants.
UPnP Device Host.
Definition: PltDeviceHost.h:69
The PLT_DeviceDataFinderByType class returns a PLT_DeviceData instance given a device type...
Definition: PltDeviceData.h:244
Definition: NptStrings.h:57
The PLT_CtrlPoint class implements the base functionality of a UPnP ControlPoint. ...
Definition: PltCtrlPoint.h:89
Definition: NptList.h:54