1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
/*
* File: object.h
* Author: savop
*
* Created on 11. September 2009, 20:39
*/
#ifndef _OBJECT_H
#define _OBJECT_H
#include "database.h"
#include "../common.h"
#include "../misc/util.h"
#include <string.h>
#include <vdr/tools.h>
#include <map>
#include <vector>
#include <upnp/ixml.h>
struct cUPnPObjectID {
int _ID;
cUPnPObjectID():_ID(-1){}
cUPnPObjectID(long ID){ _ID = (int)ID; }
cUPnPObjectID(int ID){ _ID = ID; }
cUPnPObjectID &operator=(long ID){ _ID = ID; return *this; }
cUPnPObjectID &operator=(int ID){ _ID = ID; return *this; }
cUPnPObjectID &operator=(const cUPnPObjectID& ID){ if(this != &ID){ _ID = ID._ID; } return *this; }
cUPnPObjectID &operator++(){ _ID++; return *this; }
cUPnPObjectID operator++(int){ cUPnPObjectID old = *this; _ID++; return old; }
cUPnPObjectID operator--(int){ cUPnPObjectID old = *this; _ID--; return old; }
cUPnPObjectID &operator--(){ _ID--; return *this; }
bool operator!=(long ID){ return _ID != ID; }
bool operator==(long ID){ return _ID == ID; }
bool operator!=(int ID){ return _ID != ID; }
bool operator==(int ID){ return _ID == ID; }
bool operator!=(const cUPnPObjectID& ID){ return *this == ID; }
bool operator==(const cUPnPObjectID& ID){ return *this == ID; }
operator unsigned int(){ return (unsigned int)_ID; }
operator int(){ return _ID; }
operator long(){ return (long)_ID; }
const char* operator*(){ char* buf; return asprintf(&buf,"%d",_ID)?buf:NULL; }
};
struct cClass {
cString ID;
bool includeDerived;
bool operator==(const cClass &cmp){ return (!strcasecmp(cmp.ID,ID) && includeDerived==cmp.includeDerived); }
bool operator!=(const cClass &cmp){ return !(*this==cmp); }
};
class cUPnPResource : public cListObject {
friend class cUPnPResourceMediator;
friend class cUPnPResources;
private:
unsigned int mResourceID;
cUPnPObjectID mObjectID;
int mResourceType;
cString mResource;
cString mDuration;
cString mResolution;
cString mProtocolInfo;
cString mContentType;
cString mImportURI;
unsigned long mSize;
unsigned int mBitrate;
unsigned int mSampleFrequency;
unsigned int mBitsPerSample;
unsigned int mNrAudioChannels;
unsigned int mColorDepth;
cUPnPResource();
public:
unsigned int getID() const { return this->mResourceID; }
const char* getResource() const { return this->mResource; }
const char* getDuration() const { return this->mDuration; }
const char* getResolution() const { return this->mResolution; }
const char* getProtocolInfo() const { return this->mProtocolInfo; }
const char* getContentType() const { return this->mContentType; }
const char* getImportURI() const { return this->mImportURI; }
int getResourceType() const { return this->mResourceType; }
unsigned long getSize() const { return this->mSize; }
off64_t getFileSize() const;
time_t getLastModification() const;
unsigned int getBitrate() const { return this->mBitrate; }
unsigned int getSampleFrequency() const { return this->mSampleFrequency; }
unsigned int getBitsPerSample() const { return this->mBitsPerSample; }
unsigned int getNrAudioChannels() const { return this->mNrAudioChannels; }
unsigned int getColorDepth() const { return this->mColorDepth; }
};
class cUPnPClassObject;
class cUPnPObjectMediator;
class cUPnPContainerMediator;
class cUPnPClassContainer;
class cUPnPObjects : public cList<cUPnPClassObject> {
public:
cUPnPObjects();
virtual ~cUPnPObjects();
void SortBy(const char* Property, bool Descending = false);
};
class cUPnPClassObject : public cListObject {
friend class cMediaDatabase;
friend class cUPnPObjectMediator;
friend class cUPnPClassContainer;
private:
bool mDeleted; // is this Objected marked as deleted
protected:
time_t mLastModified;
cUPnPObjectID mID; // The object ID
cUPnPClassObject* mParent;
cString mClass; // Class (Who am I?)
cString mTitle; // Object title
cString mCreator; // Creator of this object
bool mRestricted; // Ability of changing metadata?
int mWriteStatus; // Ability of writing resources?
cList<cUPnPResource>* mResources; // The resources of this object
cHash<cUPnPResource>* mResourcesID;
IXML_Document* mDIDLFragment;
cString mSortCriteria;
bool mSortDescending;
cUPnPClassObject();
int setID(cUPnPObjectID ID);
int setParent(cUPnPClassContainer* Parent);
int setClass(const char* Class);
void setModified(void){ this->mLastModified = time(NULL); }
public:
time_t modified() const { return this->mLastModified; }
virtual ~cUPnPClassObject();
virtual int Compare(const cListObject& ListObject) const;
virtual cStringList* getPropertyList();
virtual bool getProperty(const char* Property, char** Value) const ;
virtual bool setProperty(const char* Property, const char* Value);
virtual cUPnPClassContainer* getContainer(){ return NULL; }
virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter) = 0;
bool isContainer(){ return this->getContainer()==NULL?false:true; }
void setSortCriteria(const char* Property, bool Descending = false);
void clearSortCriteria();
/******* Setter *******/
int setTitle(const char* Title);
int setCreator(const char* Creator);
int setRestricted(bool Restricted);
int setWriteStatus(int Status);
int setResources(cList<cUPnPResource>* Resources);
int addResource(cUPnPResource* Resource);
int removeResource(cUPnPResource* Resource);
/******* Getter *******/
cUPnPObjectID getID() const { return this->mID; }
cUPnPObjectID getParentID() const { return this->mParent?this->mParent->getID():cUPnPObjectID(-1); }
cUPnPClassContainer* getParent() const { return (cUPnPClassContainer*)this->mParent; }
const char* getTitle() const { return this->mTitle; }
const char* getClass() const { return this->mClass; }
const char* getCreator() const { return this->mCreator; }
bool isRestricted() const { return this->mRestricted; }
int getWriteStatus() const { return this->mWriteStatus; }
cUPnPResource* getResource(unsigned int ResourceID) const { return this->mResourcesID->Get(ResourceID); }
cList<cUPnPResource>* getResources() const { return this->mResources; }
};
class cUPnPClassItem : public cUPnPClassObject {
friend class cMediaDatabase;
friend class cUPnPObjectMediator;
friend class cUPnPItemMediator;
protected:
// cUPnPObjectID mReferenceID;
cUPnPClassItem* mReference;
cUPnPClassItem();
public:
virtual ~cUPnPClassItem(){};
virtual cStringList* getPropertyList();
virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter);
virtual bool setProperty(const char* Property, const char* Value);
virtual bool getProperty(const char* Property, char** Value) const;
/******** Setter ********/
int setReference(cUPnPClassItem* Reference);
/******** Getter ********/
cUPnPClassItem* getReference() const { return this->mReference; }
cUPnPObjectID getReferenceID() const { return this->mReference?this->mReference->getID():cUPnPObjectID(-1); }
};
typedef std::vector<cClass> tClassVector;
class cUPnPClassContainer : public cUPnPClassObject {
friend class cMediaDatabase;
friend class cUPnPObjectMediator;
friend class cUPnPContainerMediator;
protected:
cString mContainerType;
tClassVector mSearchClasses;
tClassVector mCreateClasses;
bool mSearchable;
unsigned int mUpdateID;
cUPnPObjects* mChildren;
cHash<cUPnPClassObject>* mChildrenID;
void update();
int setUpdateID(unsigned int UID);
cUPnPClassContainer();
public:
virtual ~cUPnPClassContainer();
virtual cStringList* getPropertyList();
virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter);
virtual bool setProperty(const char* Property, const char* Value);
virtual bool getProperty(const char* Property, char** Value) const;
virtual cUPnPClassContainer* getContainer(){ return this; }
void addObject(cUPnPClassObject* Object);
void removeObject(cUPnPClassObject* Object);
cUPnPClassObject* getObject(cUPnPObjectID ID) const;
cUPnPObjects* getObjectList() const { return this->mChildren; }
int addSearchClass(cClass SearchClass);
int delSearchClass(cClass SearchClass);
int addCreateClass(cClass CreateClass);
int delCreateClass(cClass CreateClass);
/******** Setter ********/
int setContainerType(const char* Type);
int setSearchClasses(std::vector<cClass> SearchClasses);
int setCreateClasses(std::vector<cClass> CreateClasses);
int setSearchable(bool Searchable);
/******** Getter ********/
const char* getContainerType() const { return this->mContainerType; }
const std::vector<cClass>* getSearchClasses() const { return &(this->mSearchClasses); }
const std::vector<cClass>* getCreateClasses() const { return &(this->mCreateClasses); }
bool isSearchable() const { return this->mSearchable; }
unsigned int getChildCount() const { return this->mChildren->Count(); }
unsigned int getUpdateID() const { return this->mUpdateID; }
bool isUpdated();
};
class cUPnPClassVideoItem : public cUPnPClassItem {
friend class cMediaDatabase;
friend class cUPnPObjectMediator;
friend class cUPnPVideoItemMediator;
protected:
cString mGenre; // Genre
cString mDescription; // Description
cString mLongDescription; // a longer description
cString mPublishers; // CSV of Publishers
cString mLanguage; // RFC 1766 Language code
cString mRelations; // Relation to other contents
cString mProducers; // CSV of Producers
cString mRating; // Rating (for parential control)
cString mActors; // CSV of Actors
cString mDirectors; // CSV of Directors
cUPnPClassVideoItem();
public:
virtual ~cUPnPClassVideoItem();
//virtual cString createDIDLFragment(cStringList* Filter);
virtual cStringList* getPropertyList();
virtual bool setProperty(const char* Property, const char* Value);
virtual bool getProperty(const char* Property, char** Value) const;
/******** Setter ********/
int setLongDescription(const char* LongDescription);
int setDescription(const char* Description);
int setPublishers(const char* Publishers);
int setGenre(const char* Genre);
int setLanguage(const char* Language);
int setRelations(const char* Relations);
int setDirectors(const char* Directors);
int setActors(const char* Actors);
int setProducers(const char* Producers);
int setRating(const char* Rating);
/******** Getter ********/
const char* getGenre() const { return this->mGenre; }
const char* getLongDescription() const { return this->mLongDescription; }
const char* getDescription() const { return this->mDescription; }
const char* getPublishers() const { return this->mPublishers; }
const char* getLanguage() const { return this->mLanguage; }
const char* getRelations() const { return this->mRelations; }
const char* getActors() const { return this->mActors; }
const char* getProducers() const { return this->mProducers; }
const char* getDirectors() const { return this->mDirectors; }
const char* getRating() const { return this->mRating; }
};
class cUPnPClassVideoBroadcast : public cUPnPClassVideoItem {
friend class cMediaDatabase;
friend class cUPnPObjectMediator;
friend class cUPnPVideoBroadcastMediator;
protected:
cString mIcon;
cString mRegion;
int mChannelNr;
cString mChannelName;
cUPnPClassVideoBroadcast();
public:
virtual ~cUPnPClassVideoBroadcast();
//virtual cString createDIDLFragment(cStringList* Filter);
virtual cStringList* getPropertyList();
virtual bool setProperty(const char* Property, const char* Value);
virtual bool getProperty(const char* Property, char** Value) const;
/******** Setter ********/
int setIcon(const char* IconURI);
int setRegion(const char* Region);
int setChannelNr(int ChannelNr);
int setChannelName(const char* ChannelName);
/******** Getter ********/
const char* getIcon() const { return this->mIcon; }
const char* getRegion() const { return this->mRegion; }
int getChannelNr() const { return this->mChannelNr; }
const char* getChannelName() const { return this->mChannelName; }
};
class cMediatorInterface {
public:
virtual ~cMediatorInterface(){};
virtual cUPnPClassObject* createObject(const char* Title, bool Restricted) = 0;
virtual cUPnPClassObject* getObject(cUPnPObjectID ID) = 0;
virtual int saveObject(cUPnPClassObject* Object) = 0;
virtual int deleteObject(cUPnPClassObject* Object) = 0;
virtual int clearObject(cUPnPClassObject* Object) = 0;
};
typedef std::map<const char*, cMediatorInterface*, strCmp> tMediatorMap;
class cUPnPObjectFactory {
private:
static cUPnPObjectFactory* mInstance;
cSQLiteDatabase* mDatabase;
tMediatorMap mMediators;
cMediatorInterface* findMediatorByID(cUPnPObjectID ID);
cMediatorInterface* findMediatorByClass(const char* Class);
cUPnPObjectFactory();
public:
static cUPnPObjectFactory* getInstance();
void registerMediator(const char* UPnPClass, cMediatorInterface* Mediator);
void unregisterMediator(const char* UPnPClass, bool freeMediator=true);
cUPnPClassObject* createObject(const char* UPnPClass, const char* Title, bool Restricted=true);
cUPnPClassObject* getObject(cUPnPObjectID ID);
int saveObject(cUPnPClassObject* Object);
int deleteObject(cUPnPClassObject* Object);
int clearObject(cUPnPClassObject* Object);
};
class cMediaDatabase;
class cUPnPObjectMediator : public cMediatorInterface {
protected:
cSQLiteDatabase* mDatabase;
cMediaDatabase* mMediaDatabase;
cUPnPObjectMediator(cMediaDatabase* MediaDatabase);
virtual int initializeObject(cUPnPClassObject* Object, const char* Class, const char* Title, bool Restricted);
virtual int objectToDatabase(cUPnPClassObject* Object);
virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
public:
virtual ~cUPnPObjectMediator();
virtual cUPnPClassObject* createObject(const char* Title, bool Restricted);
virtual cUPnPClassObject* getObject(cUPnPObjectID);
virtual int saveObject(cUPnPClassObject* Object);
virtual int deleteObject(cUPnPClassObject* Object);
virtual int clearObject(cUPnPClassObject* Object);
};
class cUPnPItemMediator : public cUPnPObjectMediator {
protected:
virtual int objectToDatabase(cUPnPClassObject* Object);
virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
public:
cUPnPItemMediator(cMediaDatabase* MediaDatabase);
virtual ~cUPnPItemMediator(){};
virtual cUPnPClassItem* createObject(const char* Title, bool Restricted);
virtual cUPnPClassItem* getObject(cUPnPObjectID ID);
};
class cUPnPVideoItemMediator : public cUPnPItemMediator {
protected:
virtual int objectToDatabase(cUPnPClassObject* Object);
virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
public:
cUPnPVideoItemMediator(cMediaDatabase* MediaDatabase);
virtual ~cUPnPVideoItemMediator(){};
virtual cUPnPClassVideoItem* createObject(const char* Title, bool Restricted);
virtual cUPnPClassVideoItem* getObject(cUPnPObjectID ID);
};
class cUPnPVideoBroadcastMediator : public cUPnPVideoItemMediator {
protected:
virtual int objectToDatabase(cUPnPClassObject* Object);
virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
public:
cUPnPVideoBroadcastMediator(cMediaDatabase* MediaDatabase);
virtual ~cUPnPVideoBroadcastMediator(){};
virtual cUPnPClassVideoBroadcast* createObject(const char* Title, bool Restricted);
virtual cUPnPClassVideoBroadcast* getObject(cUPnPObjectID ID);
};
class cUPnPContainerMediator : public cUPnPObjectMediator {
protected:
virtual int objectToDatabase(cUPnPClassObject* Object);
virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
public:
cUPnPContainerMediator(cMediaDatabase* MediaDatabase);
virtual ~cUPnPContainerMediator(){};
virtual cUPnPClassContainer* createObject(const char* Title, bool Restricted);
virtual cUPnPClassContainer* getObject(cUPnPObjectID ID);
};
#endif /* _OBJECT_H */
|