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  virtual ~CDSObject();
225 
226  Property *AddProperty( Property *pProp );
227  QList<Property*> GetProperties( const QString &sName );
228  CDSObject *AddChild ( CDSObject *pChild );
229  CDSObjects GetChildren( void ) { return m_children; }
230  CDSObject *GetChild ( const QString &sID );
231 
232  ContainerClass *AddSearchClass( ContainerClass *pClass );
233  ContainerClass *AddCreateClass( ContainerClass *pClass );
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
QString m_sProtocolInfo
void SetValue(const QString &value)
Classes m_SearchClass
Classes m_CreateClass
Properties m_properties
QString m_sName
QList< CDSObject * > CDSObjects
General purpose reference counter.
QString m_sId
static QString Encode(const QString &sIn)
QMap< uint, int > FilterMap
QMap< QString, Property * > Properties
CDSObjects m_children
QList< Resource * > Resources
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)
void AddAttribute(const QString &sName, const QString &sValue)
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
Resources m_resources
QString m_sTitle
QList< ContainerClass * > Classes
bool m_bRequired
NameValues m_lstAttributes
QString m_sCreator
Resource(const QString &sProtocolInfo, const QString &sURI)
QString m_sClass
bool m_bMultiValue
QString GetValue(void) const