|
1 /** @file |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Database for MediaServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef UPNPMETADATASTORAGE_H |
|
21 #define UPNPMETADATASTORAGE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <d32dbms.h> |
|
27 #include <s32file.h> |
|
28 #include <upnperrors.h> |
|
29 #include <xmlengdom.h> |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CUpnpObjectBean; |
|
33 class CUpnpElementBean; |
|
34 class CUpnpAttributeBean; |
|
35 class CUpnpResourcesBean; |
|
36 |
|
37 // CLASS DECLARATION |
|
38 |
|
39 /** |
|
40 * Metadata storage |
|
41 * |
|
42 * @lib avcontentdirectory.lib |
|
43 * @since Series 60 3.0 |
|
44 */ |
|
45 class CUpnpMetadataStorage : public CBase |
|
46 { |
|
47 public: // Constructors and destructor |
|
48 |
|
49 /** |
|
50 * Two-phased constructor. |
|
51 */ |
|
52 static CUpnpMetadataStorage* NewL(const TDesC& aDatabaseFileName); |
|
53 static CUpnpMetadataStorage* NewLC(const TDesC& aDatabaseFileName); |
|
54 |
|
55 /** |
|
56 * Destructor. |
|
57 */ |
|
58 virtual ~CUpnpMetadataStorage(); |
|
59 |
|
60 public: // New functions |
|
61 |
|
62 /** |
|
63 * Deletes object from database |
|
64 * @since Series S60 3.0 |
|
65 * @param aObjId id of the object to be deleted |
|
66 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
67 */ |
|
68 TBool IsContainerL(TInt aObjId); |
|
69 void DeleteResourcesL(RArray<TInt>& aObjList); |
|
70 void AddResourceL(CUpnpResourcesBean* aResBean, TInt aObjId); |
|
71 TUpnpErrorCode DoDeleteObjectL(TInt aObjId, TBool aDeleteResource, TBool aDeleteRef=ETrue ); |
|
72 void InsertIntoAttributeTableL(TInt aElmId, CUpnpAttributeBean* aAtrBn, TInt aObjId, TInt aAtrId); |
|
73 TInt InsertIntoElementTableL(TInt aObjId, CUpnpElementBean* aElmBn, TInt aElmId); |
|
74 TInt InsertIntoObjectTableL(TInt aContainer, CUpnpObjectBean* aObjBn); |
|
75 /** |
|
76 * @since Series S60 3.1 |
|
77 * @param aObjId |
|
78 * @return RDbView |
|
79 */ |
|
80 RDbView GetObjViewL(TInt aObjId); |
|
81 |
|
82 /** |
|
83 * |
|
84 * @since Series S60 3.1 |
|
85 */ |
|
86 void BeginTransactionL(); |
|
87 |
|
88 /** |
|
89 * |
|
90 * @since Series S60 3.1 |
|
91 */ |
|
92 void CommitTransactionL(); |
|
93 |
|
94 /** |
|
95 * |
|
96 * @since Series S60 3.1 |
|
97 */ |
|
98 void RollbackTransactionL(); |
|
99 |
|
100 /** |
|
101 * Getter |
|
102 * @since Series S30 3.1 |
|
103 * @param aObjectID |
|
104 * @param aAll |
|
105 * @return RDbView |
|
106 */ |
|
107 RDbView GetElementsViewL(TInt aObjectID, TBool aAll); |
|
108 |
|
109 /** |
|
110 * Getter |
|
111 * @since Series S30 3.1 |
|
112 * @param aElementID |
|
113 * @param aAll |
|
114 * @return RDbView |
|
115 */ |
|
116 RDbView GetAttributesViewL(TInt aElementID, TBool aAll); |
|
117 |
|
118 /** |
|
119 * Getter |
|
120 * @since Series S30 3.2 |
|
121 * @param aObjectID |
|
122 * @param aAll |
|
123 * @return RDbView |
|
124 */ |
|
125 RDbView GetAttributesViewByObjectIdL( TInt aObjectID, TBool aAll ); |
|
126 |
|
127 /** |
|
128 * Getter |
|
129 * @since Series S30 3.1 |
|
130 * @param aAttrNameID |
|
131 * @param aAttrVal |
|
132 * @return |
|
133 */ |
|
134 TInt GetElmIdForAttrL(const TDesC8& aAttrName, const TDesC8& aAttrVal); |
|
135 |
|
136 /** |
|
137 * Getter |
|
138 * @since Series S30 3.1 |
|
139 * @param aAttrName |
|
140 * @param aAttrVal |
|
141 * @return |
|
142 */ |
|
143 TInt GetElmIdForAttrLikeL(const TDesC8& aAttrName, const TDesC8& aAttrVal); |
|
144 |
|
145 /** |
|
146 * |
|
147 * @since Series S30 3.1 |
|
148 * @param aResVal |
|
149 * @param aObjId |
|
150 */ |
|
151 void DeleteResElL(const TDesC& aResVal, TInt ObjId); |
|
152 |
|
153 /** |
|
154 * Getter |
|
155 * @since Series S30 3.1 |
|
156 * @param aResVal |
|
157 * @return RDbView |
|
158 */ |
|
159 RDbView GetViewOfObjectListForResL(const TDesC& aResVal); |
|
160 |
|
161 /** |
|
162 * Getter |
|
163 * @since Series S30 3.1 |
|
164 * @param aElmName |
|
165 * @param aElmValue |
|
166 * @return RDbView |
|
167 */ |
|
168 RDbView GetViewOfElmIdByNameAndValL(const TDesC& aElmName, const TDesC& aElmValue); |
|
169 |
|
170 /** |
|
171 * Getter |
|
172 * @since Series S30 3.1 |
|
173 * @param aAttrName |
|
174 * @param aAttrVal |
|
175 * @return RDbView |
|
176 */ |
|
177 RDbView GetAttrViewL(const TDesC8& aAttrName, const TDesC8& aAttrVal); |
|
178 |
|
179 /** |
|
180 * Getter |
|
181 * @since Series S30 3.1 |
|
182 * @param aElmId |
|
183 * @param aAttrName |
|
184 * @return RDbView |
|
185 */ |
|
186 RDbView GetAttrViewL(TInt aElmId, const TDesC8& aAttrName); |
|
187 |
|
188 /** |
|
189 * Getter |
|
190 * @since Series S30 3.2 |
|
191 * @param aBjectId |
|
192 * @param aAttrName |
|
193 * @return RDbView |
|
194 */ |
|
195 RDbView GetAttrViewByObjectIdL(TInt aBjectId, const TDesC8& aAttrName); |
|
196 |
|
197 /** |
|
198 * |
|
199 * @since Series S30 3.1 |
|
200 * @param aSqlQuery |
|
201 * @return RDbView |
|
202 */ |
|
203 RDbView PrepareViewL(const TDesC& aSqlQuery); |
|
204 |
|
205 /** |
|
206 * Getter |
|
207 * @since Series S30 3.1 |
|
208 * @param aSqlQuery |
|
209 * @return RDbView |
|
210 */ |
|
211 RDbView GetEvaluatedViewL(const TDesC& aSqlQuery); |
|
212 HBufC8* GetObjectPathL(TInt aObjId); |
|
213 HBufC8* GetObjectTitleL(TInt aObjId); |
|
214 void ExecuteL(const TDesC& aSqlCommand); |
|
215 CUpnpResourcesBean* GetResourceL(TInt64 aResId); |
|
216 void DeleteResourceByObjIdL(TInt aObjId, TBool aDeleteFile=ETrue); |
|
217 void DeleteResourceByResIdL(TInt64 aResId, TBool aDeleteFile=ETrue); |
|
218 void DeleteObjectsL(TInt aObjId); |
|
219 void DeleteElementsL(TInt aObjId); |
|
220 void DeleteAttributesL(TInt aObjId); |
|
221 void DeleteReferencesL(TInt aObjId,RArray<TInt>& aRefList); |
|
222 |
|
223 /** |
|
224 * Performs object deletion; a transaction should be started before calling this function |
|
225 * @since Series S60 3.0 |
|
226 * @param id of the object to be deleted |
|
227 * @param aObjId aCd pointer to the ContentDirectory object - it provides a function which deletes |
|
228 * a file from the private directory |
|
229 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
230 */ |
|
231 TInt DoDeleteObjectL(TInt aObjId,RArray<TInt>& aRefList, |
|
232 RArray<TInt>& aResList, TBool aDeleteResource, TBool aLocal, TBool aDeleteRef = ETrue ); |
|
233 |
|
234 /** |
|
235 * Checks the restrictions of the parent object of the given object. |
|
236 * @since Series S60 3.0 |
|
237 * @param aObjId object's id |
|
238 * @return returns EUpnpOk if object with the given id exists in database and is a "non restricted conainer" |
|
239 */ |
|
240 TUpnpErrorCode CheckParentRestrictionL(TInt aObjId); |
|
241 |
|
242 /** |
|
243 * Deletes object from database |
|
244 * @since Series S60 3.0 |
|
245 * @param aObjId id of the object to be deleted |
|
246 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
247 */ |
|
248 TUpnpErrorCode DeleteObjectL(TInt aObjId,RArray<TInt>& aRefList, TBool aDeleteResource, |
|
249 TBool aLocal = EFalse, TBool aDeleteRef = ETrue ); |
|
250 |
|
251 |
|
252 /** |
|
253 * Gets the descriptor value of the specified column in the rowset. |
|
254 * @since Series S60 3.0 |
|
255 * @param aRowset rowset object |
|
256 * @param aColNo the number of the column to be get the value of |
|
257 * @return descriptor containing the value of the specified column, |
|
258 * the caller should delete it when it is no longer needed |
|
259 */ |
|
260 HBufC8* GetColDesValFromRowSetL(RDbRowSet aRowset, TDbColNo aColNo); |
|
261 |
|
262 /** |
|
263 * Gets the value of childCount property for the given object. |
|
264 * @since Series S60 3.0 |
|
265 * @param aObjId object's id |
|
266 * @return value of childCount property |
|
267 */ |
|
268 TInt GetChildCountL(TInt aObjId); |
|
269 |
|
270 /** |
|
271 * Gets the parent object's id of the object with given id. |
|
272 * @since Series S60 3.0 |
|
273 * @param aObjId child object id |
|
274 * @return perent object id |
|
275 */ |
|
276 TInt GetParentIdL(TInt aObjId); |
|
277 |
|
278 /** |
|
279 * Gets the id of the object which the element with given id belongs to. |
|
280 * @since Series S60 3.0 |
|
281 * @param aId element's id |
|
282 * @return object's id |
|
283 */ |
|
284 TInt GetObjIdForElmIdL(TInt aId); |
|
285 |
|
286 /** |
|
287 * Gets id of reffered object |
|
288 * @since Series S60 3.0 |
|
289 * @param aObjectId object id |
|
290 * @return reffered object id. |
|
291 */ |
|
292 TInt ReferedObjectIdL( TInt aObjectId ); |
|
293 |
|
294 /** |
|
295 * Gets the next free id in the specified table |
|
296 * @since Series S60 3.0 |
|
297 * @param aName name of the table |
|
298 * @return TInt next free id in the specified table |
|
299 */ |
|
300 TInt GetNextKeyL(const TDesC8& aName); |
|
301 TInt GetNextKeyL(const TDesC8& aName, TInt aAmount); |
|
302 /** |
|
303 * Gets the next free id in the specified table |
|
304 * @since Series S60 3.0 |
|
305 * @param aName name of the table |
|
306 * @return TInt next free id in the specified table |
|
307 */ |
|
308 TInt NextKeyL(const TDesC8& aName); |
|
309 |
|
310 /** |
|
311 * Insert object's data into 'object' table |
|
312 * @since Series S60 3.0 |
|
313 * @param aElement TXmlEngElement of the object to be added |
|
314 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
315 */ |
|
316 void InsertObjectIntoObjectTableL(const TXmlEngElement& aElement); |
|
317 |
|
318 /** |
|
319 * Inserts single attribute into the database |
|
320 * @since Series S60 3.0 |
|
321 * @param aAttr TXmlEngAttr of the attribute to be inserted |
|
322 * @param aElmId id of the element this attribute belongs to |
|
323 * 2param aIsRequired |
|
324 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
325 */ |
|
326 void InsertAttributeL(const TXmlEngAttr aAttr, TInt aElmId, TBool aIsRequired, TInt aObjId); |
|
327 |
|
328 /** |
|
329 * Inserts element into database |
|
330 * @since Series S60 3.0 |
|
331 * @param aElementel TXmlEngElement of the element to be inserted |
|
332 * @param aObjId id of the object this element belongs to |
|
333 */ |
|
334 TInt InsertElementL(const TXmlEngElement& aElementel, TInt aObjId); |
|
335 |
|
336 /** |
|
337 * Gets the database view of the named element of the specified object. |
|
338 * @since Series S60 3.0 |
|
339 * @param aObjId object's id |
|
340 * @param aElName name of the element which we want to get the view of |
|
341 * @return ?description |
|
342 */ |
|
343 RDbView GetElementViewL(TInt aObjId, const TDesC8& aElName); |
|
344 |
|
345 /** |
|
346 * Adds an attribute from object table to the object's main element. |
|
347 * @since Series S60 3.0 |
|
348 * @param aElement object's element |
|
349 * @param aId object's id |
|
350 * @param aName name of the attribute which is to be added |
|
351 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
352 */ |
|
353 TUpnpErrorCode AddMainTagAttrL(TXmlEngElement aElement, TInt aId, const TDesC8& aName); |
|
354 |
|
355 |
|
356 /** |
|
357 * Gets the list direct children of object with specified id |
|
358 * @since Series S60 3.0 |
|
359 * @param aParentId id of the parent object |
|
360 * @param aList an array to be filled with object |
|
361 * @return EUpnpOk, if successful; Otherwise, one of the other Upnp error codes. |
|
362 */ |
|
363 TUpnpErrorCode GetObjectListL(TInt aParentId, RArray<TInt>& aList); |
|
364 TUpnpErrorCode GetItemListL(TInt aParentId, RArray<TInt>& aList); |
|
365 TUpnpErrorCode GetContainerListL(TInt aParentId, RArray<TInt>& aList); |
|
366 |
|
367 /** |
|
368 * Checks if object with the given id exists, is a container and its 'restricted' attribute has value of 'false' |
|
369 * @since Series S60 3.0 |
|
370 * @param aObjId id of the object to be checked |
|
371 * @return returns EUpnpOk if object with the given id exists in database and is a "non restricted conainer" |
|
372 */ |
|
373 TUpnpErrorCode CheckObjectRestrictionL(TInt aObjId); |
|
374 |
|
375 /** |
|
376 * Recovers the database. |
|
377 * @since Series S60 3.1 |
|
378 * @return Standard error code |
|
379 */ |
|
380 TInt RecoverDatabase(); |
|
381 |
|
382 /** |
|
383 * Recreates the database file. |
|
384 * @since Series S60 3.1 |
|
385 */ |
|
386 void RecreateDatabaseFileL(); |
|
387 |
|
388 /** |
|
389 * Checks if all database columns in each table have propper definitions. |
|
390 * If not, it leaves with KErrCorrupt. |
|
391 * @since Series S60 3.2 |
|
392 */ |
|
393 void CheckDatabaseL(); |
|
394 |
|
395 /** |
|
396 * Handles DB error |
|
397 * Tries to recover, if fails tries to recreate |
|
398 * @since Series S60 3.2 |
|
399 * @return TInt - KErrNone if succed |
|
400 */ |
|
401 TInt HandleDbError( TInt aError ); |
|
402 |
|
403 /** |
|
404 * Returns DB creation status |
|
405 * @since Series S60 3.2 |
|
406 * @return TBool |
|
407 */ |
|
408 TBool IsDbCreated(); |
|
409 |
|
410 |
|
411 private: |
|
412 |
|
413 /** |
|
414 * C++ default constructor. |
|
415 */ |
|
416 CUpnpMetadataStorage(); |
|
417 |
|
418 /** |
|
419 * By default Symbian 2nd phase constructor is private. |
|
420 */ |
|
421 void ConstructL(const TDesC& aDatabaseFileName); |
|
422 |
|
423 private: |
|
424 |
|
425 void CompactDbL(); |
|
426 TInt AddSubObjectsL(TInt aObjId, RArray<TInt>& aObjList, RArray<TInt>& aResList, TBool aLocal); |
|
427 |
|
428 /** |
|
429 * Compare two column sets (type, maxsize and attributes). Used by CheckDatabaseL() function. |
|
430 * Leaves with KErrCorrupt when columns are not agree. |
|
431 * @since Series S60 3.2 |
|
432 * @param aColSet1 First column set to compare |
|
433 * @param aColSet2 Second column set to compare |
|
434 */ |
|
435 void CompareDbColSetsL( CDbColSet *aColSet1, CDbColSet *aColSet2 ); |
|
436 |
|
437 /** |
|
438 * Deletes the file |
|
439 * @since Series S30 3.1 |
|
440 * @param aPath |
|
441 */ |
|
442 void DeleteFileL(const TDesC& aPath); |
|
443 |
|
444 /** |
|
445 * |
|
446 * @since Series S30 3.1 |
|
447 * @param aElement |
|
448 * @return descriptor pointer |
|
449 */ |
|
450 HBufC8* CreatePathValL(const TXmlEngElement& aElement); |
|
451 HBufC8* CreatePathValL(TInt aParentId); |
|
452 /** |
|
453 * Opens database |
|
454 * @since Series S30 3.1 |
|
455 * @param aDatabaseFileName |
|
456 */ |
|
457 void OpenDbL( const TFileName& aDatabaseFileName ); |
|
458 |
|
459 /** |
|
460 * |
|
461 * @since Series S30 3.1 |
|
462 * @param aWeight |
|
463 */ |
|
464 void DbChangedL(TInt aWeight); |
|
465 |
|
466 private: |
|
467 |
|
468 // For use of iFileStore |
|
469 RFs iFsSession; |
|
470 // For database operations |
|
471 RDbStoreDatabase iDatabase; |
|
472 TBool iIsOpen; |
|
473 // For creating and opening database files |
|
474 CFileStore* iFileStore; |
|
475 // compact counter |
|
476 TInt iCompactCounter; |
|
477 |
|
478 }; |
|
479 |
|
480 #endif // UPNPMETADATASTORAGE_H |
|
481 |
|
482 // End of File |