MythTV  master
upnpcdsobjects.h
Go to the documentation of this file.
1 // Program Name: UPnpCDSObjects.h
3 // Created : Oct. 24, 2005
4 //
5 // Purpose : uPnp Content Directory Service Object Definitions
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #ifndef UPNPCDSOBJECTS_H
14 #define UPNPCDSOBJECTS_H
15 
16 #include <QDateTime>
17 #include <QString>
18 #include <QList>
19 #include <QMap>
20 
21 #include "upnpexp.h"
22 #include "httprequest.h"
23 #include <referencecounter.h>
24 
25 class CDSObject;
26 class QTextStream;
27 
29 //
31 
33 {
36  OT_Item = 2,
37  OT_Res = 3
38 };
39 
41 //
43 
44 class Property
45 {
46  public:
47 
48  QString m_sName;
49  QString m_sNameSpace;
50  bool m_bRequired {false};
51  bool m_bMultiValue {false};
53 
54  public:
55 
56  explicit Property( const QString &sName,
57  const QString &sNameSpace = "",
58  bool bRequired = false,
59  const QString &sValue = "",
60  bool bMultiValue = false
61  )
62  {
63  m_sName = sName;
64  m_sNameSpace = sNameSpace;
65  m_bRequired = bRequired;
66  m_sValue = HTTPRequest::Encode(sValue);
67  m_bMultiValue = bMultiValue;
68  }
69 
70  void SetValue(const QString &value)
71  {
72  m_sValue = value;
73  }
74 
75  QString GetValue(void) const
76  {
77  return m_sValue;
78  }
79 
80  QString GetEncodedValue(void) const
81  {
83  }
84 
85  void AddAttribute( const QString &sName,
86  const QString &sValue )
87  {
88  m_lstAttributes.push_back(NameValue(sName, HTTPRequest::Encode(sValue)));
89  }
90 
91  protected:
92  QString m_sValue;
93 };
94 
95 using Properties = QMap<QString,Property*>;
96 using CDSObjects = QList<CDSObject*>;
97 
99 //
101 
102 class Resource
103 {
104  public:
105 
107  QString m_sURI;
108 
110 
111  public:
112 
113  Resource( const QString &sProtocolInfo,
114  const QString &sURI )
115  {
116  m_sProtocolInfo = sProtocolInfo;
117  m_sURI = HTTPRequest::Encode(sURI);
118  }
119 
120  void AddAttribute( const QString &sName,
121  const QString &sValue )
122  {
123  m_lstAttributes.push_back(NameValue(sName, HTTPRequest::Encode(sValue)));
124  }
125 };
126 
127 using Resources = QList<Resource*>;
128 
130 //
132 
134 {
135  public:
136 
137  QString m_sClass;
138  QString m_sName;
140 
141  public:
142 
143  ContainerClass( const QString &sClass,
144  const QString &sName,
145  bool bIncludeDerived )
146  {
147  m_sClass = sClass;
148  m_sName = sName;
149  m_bIncludeDerived = bIncludeDerived;
150  }
151 };
152 
153 using Classes = QList<ContainerClass*>;
154 
179 using FilterMap = QStringList;
180 
182 
184 {
185  public:
186  short m_nUpdateId {1};
187 
189 
190  // Required
191 
192  QString m_sId;
193  QString m_sParentId;
194  QString m_sTitle;
195  QString m_sClass;
196  bool m_bRestricted {true};
197  bool m_bSearchable {false};
198 
199  // Optional
200 
201  QString m_sCreator;
202  QString m_sWriteStatus {"PROTECTED"};
203 
204  // Only appropriate for Container Classes
205 
208 
209  //
210 
213  uint32_t m_nChildCount {0};
214  uint32_t m_nChildContainerCount {0};
215 
217 
218 
219  public:
220 
221  explicit CDSObject( const QString &sId = "-1",
222  const QString &sTitle = "",
223  const QString &sParentId = "-1" );
224  ~CDSObject() override;
225 
226  Property *AddProperty( Property *pProp );
227  QList<Property*> GetProperties( const QString &sName );
228  CDSObject *AddChild ( CDSObject *pChild );
229  CDSObjects GetChildren( void ) const { return m_children; }
230  CDSObject *GetChild ( const QString &sID );
231 
234 
235  void SetPropValue( const QString &sName, const QString &sValue,
236  const QString &type = "" );
237  QString GetPropValue( const QString &sName ) const;
238  QString toXml ( FilterMap &filter,
239  bool ignoreChildren = false ) const;
240  void toXml ( QTextStream &os, FilterMap &filter,
241  bool ignoreChildren = false ) const;
242 
243  uint32_t GetChildCount( void ) const;
244  void SetChildCount( uint32_t nCount );
245 
246  uint32_t GetChildContainerCount( void ) const;
247  void SetChildContainerCount( uint32_t nCount );
248 
249  Resource *AddResource( const QString& sProtocol, const QString& sURI );
250 
251  public:
252 
253  static CDSObject *CreateItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
254  static CDSObject *CreateContainer ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
255  static CDSObject *CreateAudioItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
256  static CDSObject *CreateMusicTrack ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
257  static CDSObject *CreateAudioBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
258  static CDSObject *CreateAudioBook ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
259  static CDSObject *CreateVideoItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
260  static CDSObject *CreateMovie ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
261  static CDSObject *CreateVideoBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
262  static CDSObject *CreateMusicVideoClip ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
263  static CDSObject *CreateImageItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
264  static CDSObject *CreatePhoto ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
265  static CDSObject *CreatePlaylistItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
266  static CDSObject *CreateTextItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
267  static CDSObject *CreateAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
268  static CDSObject *CreateMusicAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
269  static CDSObject *CreatePhotoAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
270  static CDSObject *CreateGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
271  static CDSObject *CreateMusicGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
272  static CDSObject *CreateMovieGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
273  static CDSObject *CreatePlaylistContainer( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
274  static CDSObject *CreatePerson ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
275  static CDSObject *CreateMusicArtist ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
276  static CDSObject *CreateStorageSystem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
277  static CDSObject *CreateStorageVolume ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
278  static CDSObject *CreateStorageFolder ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
279 
280  private:
281  static bool FilterContains( const FilterMap &filter, const QString &name ) ;
282 
283 };
284 
285 #endif // UPNPCDSOBJECTS_H
NameValue
Definition: upnputil.h:52
Property::m_sName
QString m_sName
Definition: upnpcdsobjects.h:48
CDSObject::GetChildren
CDSObjects GetChildren(void) const
Definition: upnpcdsobjects.h:229
OT_Item
@ OT_Item
Definition: upnpcdsobjects.h:36
CDSObject::m_children
CDSObjects m_children
Definition: upnpcdsobjects.h:212
Resource::m_sURI
QString m_sURI
Definition: upnpcdsobjects.h:107
Property::GetEncodedValue
QString GetEncodedValue(void) const
Definition: upnpcdsobjects.h:80
CDSObject::m_sTitle
QString m_sTitle
Definition: upnpcdsobjects.h:194
CDSObject
Definition: upnpcdsobjects.h:184
Resource::m_lstAttributes
NameValues m_lstAttributes
Definition: upnpcdsobjects.h:109
Resource
Definition: upnpcdsobjects.h:103
ContainerClass
Definition: upnpcdsobjects.h:134
Property::GetValue
QString GetValue(void) const
Definition: upnpcdsobjects.h:75
Resource::AddAttribute
void AddAttribute(const QString &sName, const QString &sValue)
Definition: upnpcdsobjects.h:120
CDSObject::m_sCreator
QString m_sCreator
Definition: upnpcdsobjects.h:201
CDSObject::AddCreateClass
ContainerClass * AddCreateClass(ContainerClass *pClass)
HTTPRequest::Encode
static QString Encode(const QString &sIn)
Definition: httprequest.cpp:1788
CDSObject::m_sParentId
QString m_sParentId
Definition: upnpcdsobjects.h:193
Property
Definition: upnpcdsobjects.h:45
ContainerClass::m_sName
QString m_sName
Definition: upnpcdsobjects.h:138
Resource::Resource
Resource(const QString &sProtocolInfo, const QString &sURI)
Definition: upnpcdsobjects.h:113
Property::m_sNameSpace
QString m_sNameSpace
Definition: upnpcdsobjects.h:49
ContainerClass::m_bIncludeDerived
bool m_bIncludeDerived
Definition: upnpcdsobjects.h:139
Property::AddAttribute
void AddAttribute(const QString &sName, const QString &sValue)
Definition: upnpcdsobjects.h:85
OT_Undefined
@ OT_Undefined
Definition: upnpcdsobjects.h:34
Property::Property
Property(const QString &sName, const QString &sNameSpace="", bool bRequired=false, const QString &sValue="", bool bMultiValue=false)
Definition: upnpcdsobjects.h:56
NameValues
Definition: upnputil.h:88
FilterMap
QMap< uint, int > FilterMap
Definition: ExternalSignalMonitor.h:13
Property::m_bMultiValue
bool m_bMultiValue
Definition: upnpcdsobjects.h:51
Property::m_sValue
QString m_sValue
Definition: upnpcdsobjects.h:92
Property::SetValue
void SetValue(const QString &value)
Definition: upnpcdsobjects.h:70
Properties
QMap< QString, Property * > Properties
Definition: upnpcdsobjects.h:95
Resource::m_sProtocolInfo
QString m_sProtocolInfo
Definition: upnpcdsobjects.h:106
CDSObjects
QList< CDSObject * > CDSObjects
Definition: upnpcdsobjects.h:96
ContainerClass::m_sClass
QString m_sClass
Definition: upnpcdsobjects.h:137
Property::m_bRequired
bool m_bRequired
Definition: upnpcdsobjects.h:50
referencecounter.h
CDSObject::m_sId
QString m_sId
Definition: upnpcdsobjects.h:192
Classes
QList< ContainerClass * > Classes
Definition: upnpcdsobjects.h:153
CDSObject::m_properties
Properties m_properties
Definition: upnpcdsobjects.h:211
CDSObject::m_sClass
QString m_sClass
Definition: upnpcdsobjects.h:195
UPNP_PUBLIC
#define UPNP_PUBLIC
Definition: upnpexp.h:9
CDSObject::AddSearchClass
ContainerClass * AddSearchClass(ContainerClass *pClass)
OT_Res
@ OT_Res
Definition: upnpcdsobjects.h:37
OT_Container
@ OT_Container
Definition: upnpcdsobjects.h:35
Property::m_lstAttributes
NameValues m_lstAttributes
Definition: upnpcdsobjects.h:52
CDSObject::m_resources
Resources m_resources
Definition: upnpcdsobjects.h:216
ObjectTypes
ObjectTypes
Definition: upnpcdsobjects.h:33
ContainerClass::ContainerClass
ContainerClass(const QString &sClass, const QString &sName, bool bIncludeDerived)
Definition: upnpcdsobjects.h:143
CDSObject::m_SearchClass
Classes m_SearchClass
Definition: upnpcdsobjects.h:206
httprequest.h
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:27
Resources
QList< Resource * > Resources
Definition: upnpcdsobjects.h:127
upnpexp.h
CDSObject::m_CreateClass
Classes m_CreateClass
Definition: upnpcdsobjects.h:207