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 
32 typedef enum
33 {
36  OT_Item = 2,
37  OT_Res = 3
38 
39 } ObjectTypes;
40 
42 //
44 
45 class Property
46 {
47  public:
48 
49  QString m_sName;
50  QString m_sNameSpace;
51  bool m_bRequired {false};
52  bool m_bMultiValue {false};
54 
55  public:
56 
57  explicit Property( const QString &sName,
58  const QString &sNameSpace = "",
59  bool bRequired = false,
60  const QString &sValue = "",
61  bool bMultiValue = false
62  )
63  {
64  m_sName = sName;
65  m_sNameSpace = sNameSpace;
66  m_bRequired = bRequired;
67  m_sValue = HTTPRequest::Encode(sValue);
68  m_bMultiValue = bMultiValue;
69  }
70 
71  void SetValue(const QString &value)
72  {
73  m_sValue = value;
74  }
75 
76  QString GetValue(void) const
77  {
78  return m_sValue;
79  }
80 
81  QString GetEncodedValue(void) const
82  {
84  }
85 
86  void AddAttribute( const QString &sName,
87  const QString &sValue )
88  {
89  m_lstAttributes.push_back(NameValue(sName, HTTPRequest::Encode(sValue)));
90  }
91 
92  protected:
93  QString m_sValue;
94 };
95 
96 typedef QMap<QString,Property*> Properties;
97 typedef QList<CDSObject*> CDSObjects;
98 
100 //
102 
103 class Resource
104 {
105  public:
106 
108  QString m_sURI;
109 
111 
112  public:
113 
114  Resource( const QString &sProtocolInfo,
115  const QString &sURI )
116  {
117  m_sProtocolInfo = sProtocolInfo;
118  m_sURI = HTTPRequest::Encode(sURI);
119  }
120 
121  void AddAttribute( const QString &sName,
122  const QString &sValue )
123  {
124  m_lstAttributes.push_back(NameValue(sName, HTTPRequest::Encode(sValue)));
125  }
126 };
127 
128 typedef QList<Resource*> Resources;
129 
131 //
133 
135 {
136  public:
137 
138  QString m_sClass;
139  QString m_sName;
141 
142  public:
143 
144  ContainerClass( const QString &sClass,
145  const QString &sName,
146  bool bIncludeDerived )
147  {
148  m_sClass = sClass;
149  m_sName = sName;
150  m_bIncludeDerived = bIncludeDerived;
151  }
152 };
153 
154 typedef QList<ContainerClass*> Classes;
155 
180 typedef QStringList FilterMap;
181 
183 
185 {
186  public:
187  short m_nUpdateId {1};
188 
190 
191  // Required
192 
193  QString m_sId;
194  QString m_sParentId;
195  QString m_sTitle;
196  QString m_sClass;
197  bool m_bRestricted {true};
198  bool m_bSearchable {false};
199 
200  // Optional
201 
202  QString m_sCreator;
203  QString m_sWriteStatus {"PROTECTED"};
204 
205  // Only appropriate for Container Classes
206 
209 
210  //
211 
214  uint32_t m_nChildCount {0};
215  uint32_t m_nChildContainerCount {0};
216 
218 
219 
220  public:
221 
222  explicit CDSObject( const QString &sId = "-1",
223  const QString &sTitle = "",
224  const QString &sParentId = "-1" );
225  virtual ~CDSObject();
226 
227  Property *AddProperty( Property *pProp );
228  QList<Property*> GetProperties( const QString &sName );
229  CDSObject *AddChild ( CDSObject *pChild );
230  CDSObjects GetChildren( void ) { return m_children; }
231  CDSObject *GetChild ( const QString &sID );
232 
233  ContainerClass *AddSearchClass( ContainerClass *pClass );
234  ContainerClass *AddCreateClass( ContainerClass *pClass );
235 
236  void SetPropValue( const QString &sName, const QString &sValue,
237  const QString &type = "" );
238  QString GetPropValue( const QString &sName ) const;
239  QString toXml ( FilterMap &filter,
240  bool ignoreChildren = false ) const;
241  void toXml ( QTextStream &os, FilterMap &filter,
242  bool ignoreChildren = false ) const;
243 
244  uint32_t GetChildCount( void ) const;
245  void SetChildCount( uint32_t nCount );
246 
247  uint32_t GetChildContainerCount( void ) const;
248  void SetChildContainerCount( uint32_t nCount );
249 
250  Resource *AddResource( const QString& sProtocol, const QString& sURI );
251 
252  public:
253 
254  static CDSObject *CreateItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
255  static CDSObject *CreateContainer ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
256  static CDSObject *CreateAudioItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
257  static CDSObject *CreateMusicTrack ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
258  static CDSObject *CreateAudioBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
259  static CDSObject *CreateAudioBook ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
260  static CDSObject *CreateVideoItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
261  static CDSObject *CreateMovie ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
262  static CDSObject *CreateVideoBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
263  static CDSObject *CreateMusicVideoClip ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
264  static CDSObject *CreateImageItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
265  static CDSObject *CreatePhoto ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
266  static CDSObject *CreatePlaylistItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
267  static CDSObject *CreateTextItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
268  static CDSObject *CreateAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
269  static CDSObject *CreateMusicAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
270  static CDSObject *CreatePhotoAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
271  static CDSObject *CreateGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
272  static CDSObject *CreateMusicGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
273  static CDSObject *CreateMovieGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
274  static CDSObject *CreatePlaylistContainer( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
275  static CDSObject *CreatePerson ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
276  static CDSObject *CreateMusicArtist ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
277  static CDSObject *CreateStorageSystem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
278  static CDSObject *CreateStorageVolume ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
279  static CDSObject *CreateStorageFolder ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
280 
281  private:
282  bool FilterContains( const FilterMap &filter, const QString &name ) const;
283 
284 };
285 
286 #endif
QString m_sProtocolInfo
void SetValue(const QString &value)
Classes m_SearchClass
Classes m_CreateClass
Properties m_properties
QString m_sName
General purpose reference counter.
QString m_sId
static QString Encode(const QString &sIn)
QList< CDSObject * > CDSObjects
QList< Resource * > Resources
CDSObjects m_children
ContainerClass(const QString &sClass, const QString &sName, bool bIncludeDerived)
QString m_sParentId
QString m_sNameSpace
QString m_sValue
void AddAttribute(const QString &sName, const QString &sValue)
QString GetEncodedValue(void) const
QString m_sURI
CDSObjects GetChildren(void)
const char * name
Definition: ParseText.cpp:328
void AddAttribute(const QString &sName, const QString &sValue)
QList< ContainerClass * > Classes
ObjectTypes
Property(const QString &sName, const QString &sNameSpace="", bool bRequired=false, const QString &sValue="", bool bMultiValue=false)
#define UPNP_PUBLIC
Definition: upnpexp.h:9
NameValues m_lstAttributes
QMap< uint, int > FilterMap
Resources m_resources
QStringList FilterMap
NOTE FilterMap contains a list of what should be included, not what should be excluded.
QString m_sTitle
bool m_bRequired
NameValues m_lstAttributes
QString m_sCreator
Resource(const QString &sProtocolInfo, const QString &sURI)
QMap< QString, Property * > Properties
QString m_sClass
bool m_bMultiValue
QString GetValue(void) const