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
|
/*
* File: metadata.h
* Author: savop
*
* Created on 28. Mai 2009, 21:14
*/
#ifndef _METADATA_H
#define _METADATA_H
#include <vdr/tools.h>
#include <vdr/channels.h>
#include <vdr/recording.h>
#include "../common.h"
#include "database.h"
#include "object.h"
#include "resources.h"
/**
* The result set of a request
*
* This contains the results of a previous \e Browse or \e Search request.
*/
struct cUPnPResultSet {
int mNumberReturned; ///< The number of returned matches
int mTotalMatches; ///< The total amount of matches
const char* mResult; ///< The DIDL-Lite fragment
};
/**
* The media database
*
* This class is the global object manager. It holds every object in a local cache.
* Only this class is allowed to create new objects.
*
* @see cUPnPClassObject
*/
class cMediaDatabase : public cThread {
friend class cUPnPServer;
friend class cUPnPObjectMediator;
private:
unsigned int mSystemUpdateID;
cUPnPObjectFactory* mFactory;
cHash<cUPnPClassObject>* mObjects;
cSQLiteDatabase* mDatabase;
cUPnPObjectID mLastInsertObjectID;
cUPnPObjectID getNextObjectID();
void cacheObject(cUPnPClassObject* Object);
int prepareDatabase();
#ifndef WITHOUT_TV
int loadChannels();
void updateChannelEPG();
#endif
#ifndef WITHOUT_RECORDS
int loadRecordings();
void updateRecordings();
#endif
bool init();
void updateSystemID();
virtual void Action();
public:
/**
* Returns the SystemUpdateID
*
* This returns the \e SystemUpdateID. This changes whenever anything changed
* within the content directory. This value will be sent through the UPnP
* network every 2 seconds.
*
* @return the SystemUpdateID
*/
unsigned int getSystemUpdateID();
/**
* Returns a CSV list with ContainerUpdateIDs
*
* This list contains an unordered list of ordered pairs of ContainerID and
* its ContainerUpdateID. It contains only recent changes which are not yet
* beeing evented. This means that evented updates will be removed from list.
*
* @return CSV list of ContainerUpdateIDs
*/
const char* getContainerUpdateIDs();
/**
* Constructor
*
* This creates an instance of the media database.
*/
cMediaDatabase();
virtual ~cMediaDatabase();
/**
* Add a Fastfind
*
* This creates a \e Fastfind entry. It is a string which can be used to
* relocate a objectID. Usually this is a file name or another ID with which
* the related object can be found.
*
* @return returns
* - \bc -1, if the creation was successful
* - \bc 0, otherwise
*/
int addFastFind(
cUPnPClassObject* Object, ///< the object, which should be registered
const char* FastFind ///< the string with which the object shall be
///< relocated
);
/**
* Finds a object by Fastfind
*
* This returns the object via the \e Fastfind string. The object must be
* previosly registered via \c cMediaDatabase::addFastFind().
*
* It tries to find the object in the internal object cache. If this fails,
* the object will be loaded from the database.
*
* @see cMediaDatabase::addFastFind
* @return The object associated with FastFind
*/
cUPnPClassObject* getObjectByFastFind(
const char* FastFind ///< the string with which the object shall be
///< relocated
);
/**
* Finds a object by its ObjectID
*
* This returns the object via its \e ObjectID.
*
* It tries to find the object in the internal object cache. If this fails,
* the object will be loaded from the database.
*
* @return The object associated with FastFind
*/
cUPnPClassObject* getObjectByID(
cUPnPObjectID ID ///< The ObjectID of the requested object
);
/**
* Performs a browse on the database
*
* This performs a browse request on the database and returns a structure
* containing the matching count and DIDL-Lite fragement which is sent to
* the control point.
*
* @return returns an integer representing one of the following:
* - \bc UPNP_CDS_E_INVALID_SORT_CRITERIA, when the sort criteria is malformed
* - \bc UPNP_CDS_E_CANT_PROCESS_REQUEST, when there is an internal error while
* processing the request
* - \bc UPNP_CDS_E_NO_SUCH_OBJECT, when the requested ObjectID does not exist
* - \bc UPNP_SOAP_E_ACTION_FAILED, when the action failed due any reasons
* - \bc UPNP_E_SUCCESS, if the request was successful
*/
int browse(
OUT cUPnPResultSet** Results, ///< the result of the request
IN const char* ID, ///< the objectID of the request
IN bool BrowseMetadata, ///< \b true to browse metadata, \b false otherwise
IN const char* Filter = "*", ///< the filter applied to the returned metadata
IN unsigned int Offset = 0, ///< the starting offset
IN unsigned int Count = 0, ///< maximum count returned
IN const char* SortCriteria = "" ///< sorts the results before returning them
);
/**
* Performs a search on the database
*
* This performs a search request on the database and returns a structure
* containing the matching count and DIDL-Lite fragement which is sent to
* the control point.
*
* @note
* The submitted ID must be a ContainerID. Searches are performed only
* in this container.
*
* @return returns an integer representing one of the following:
* - \bc UPNP_CDS_E_INVALID_SORT_CRITERIA, when the sort criteria is malformed
* - \bc UPNP_CDS_E_CANT_PROCESS_REQUEST, when there is an internal error while
* processing the request
* - \bc UPNP_CDS_E_NO_SUCH_OBJECT, when the requested ObjectID does not exist
* - \bc UPNP_SOAP_E_ACTION_FAILED, when the action failed due any reasons
* - \bc UPNP_E_SUCCESS, if the request was successful
*/
int search(
OUT cUPnPResultSet** Results, ///< the result of the request
IN const char* ID, ///< the ContainerID
IN const char* Search, ///< the search string
IN const char* Filter = "*", ///< the filter applied to the returned metadata
IN unsigned int Offset = 0, ///< the starting offset
IN unsigned int Count = 0, ///< maximum count returned
IN const char* SortCriteria = "" ///< sorts the results before returning them
);
};
#endif /* _METADATA_H */
|