|
1 /* |
|
2 * Copyright (c) 2008 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: CCPLiwMap - class used in Content Publisher |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef C_CPLIWIDSMAP_H |
|
19 #define C_CPLIWIDSMAP_H |
|
20 |
|
21 #include <liwvariant.h> |
|
22 #include <sqldb.h> |
|
23 #include "cpglobals.h" |
|
24 |
|
25 class RDesReadStream; |
|
26 class CCPSecurityPolicy; |
|
27 |
|
28 // CLASS DECLARATION |
|
29 /** |
|
30 * Base Map class for Publisher Registry and Content |
|
31 * |
|
32 * @lib cputils.dll |
|
33 * @since S60 v5.0 |
|
34 */ |
|
35 class CCPLiwMap : public CLiwMap |
|
36 { |
|
37 |
|
38 protected: |
|
39 |
|
40 /** |
|
41 * Enum defining the properties of filter. |
|
42 */ |
|
43 enum TCPProperties |
|
44 { |
|
45 EPublisher = 1, |
|
46 EContentType = 2, |
|
47 EContentId = 4, |
|
48 EFlag = 8, |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Enum defining the sort ordering. |
|
53 */ |
|
54 enum TCPSortOrder |
|
55 { |
|
56 ECPRecent = 1, // 0001 |
|
57 ECPPublisher = 2, // 0010 |
|
58 ECPContent = 4, // 0100 |
|
59 ECPContentId = 8 // 1000 |
|
60 }; |
|
61 |
|
62 public: |
|
63 |
|
64 friend class CCpStorageEngine; |
|
65 |
|
66 /** |
|
67 * Two-phased constructor. |
|
68 */ |
|
69 IMPORT_C static CCPLiwMap* NewL( RDesReadStream& aStream ); |
|
70 |
|
71 /** |
|
72 * Two-phased constructor. |
|
73 */ |
|
74 IMPORT_C static CCPLiwMap* NewL( const CLiwGenericParamList& aList ); |
|
75 |
|
76 /** |
|
77 * Used by client to serialize this object |
|
78 * |
|
79 * @return object serialized to binary |
|
80 */ |
|
81 IMPORT_C HBufC8* PackForServerLC() const; |
|
82 |
|
83 /** |
|
84 * Reset map |
|
85 */ |
|
86 IMPORT_C void Reset( ) const; |
|
87 |
|
88 /** |
|
89 * Leaves when Add data operation is not possible due |
|
90 * to missing of some parameter |
|
91 */ |
|
92 virtual void IsValidForAddL( ) const; |
|
93 |
|
94 /** |
|
95 * Leaves when Execute Action operation is not possible due |
|
96 * to missing of some parameter |
|
97 */ |
|
98 IMPORT_C void IsValidForActionL( ) const; |
|
99 |
|
100 /** |
|
101 * Leaves when RequestNotification operation is not possible due |
|
102 * to missing of some parameter |
|
103 */ |
|
104 IMPORT_C void IsValidForNotificationL( ) const; |
|
105 |
|
106 /** |
|
107 * Fetches value for property(key) from internal map |
|
108 * |
|
109 * @param aProperty name of the property ( key ) |
|
110 * @param aResult target descriptor for fetching operation |
|
111 * @return ETrue is property found or EFalse if not |
|
112 */ |
|
113 IMPORT_C TBool GetPropertyL( const TDesC8& aProperty, |
|
114 RBuf& aResult ) const; |
|
115 |
|
116 /** |
|
117 * Fetches value for property(key) from internal map |
|
118 * |
|
119 * @param aProperty name of the property ( key ) |
|
120 * @param aResult target binary for fetching operation |
|
121 * @return ETrue is property found or EFalse if not |
|
122 */ |
|
123 IMPORT_C TBool GetPropertyL( const TDesC8& aProperty, |
|
124 RBuf8& aResult ) const; |
|
125 |
|
126 /** |
|
127 * Fetches value for property(key) from internal map |
|
128 * |
|
129 * @param aProperty name of the property ( key ) |
|
130 * @param aResult target integer for fetching operation |
|
131 * @return ETrue is property found or EFalse if not |
|
132 */ |
|
133 IMPORT_C TBool GetProperty( const TDesC8& aProperty, |
|
134 TInt32& aResult ) const; |
|
135 |
|
136 |
|
137 /** |
|
138 * Setter for security policy |
|
139 * |
|
140 * @param aPolicy security policy |
|
141 */ |
|
142 IMPORT_C void SetSecurityL( const RMessage2& aMessage ); |
|
143 |
|
144 /** |
|
145 * Destructor. |
|
146 */ |
|
147 virtual ~CCPLiwMap(); |
|
148 |
|
149 /** |
|
150 * Check if IDs are valid for Delete operation |
|
151 */ |
|
152 virtual void IsValidForDeleteL() const =0; |
|
153 |
|
154 /** |
|
155 * Check if IDs are valid for GetList operation |
|
156 */ |
|
157 virtual void IsValidForGetListL() const =0; |
|
158 |
|
159 /** |
|
160 * |
|
161 * @return ETrue if supported, EFalse if not |
|
162 */ |
|
163 virtual TBool ActivateActionSupport( ) const = 0; |
|
164 |
|
165 /** |
|
166 * |
|
167 * @return ETrue if activate flag is set, EFalse if not |
|
168 */ |
|
169 virtual TBool GetActivateInfo( ) const = 0; |
|
170 |
|
171 |
|
172 public: |
|
173 |
|
174 // from base class CLiwMap |
|
175 /** |
|
176 * Inserts a key-value pair element to the map collection. If |
|
177 * the specified key already exists, it will be removed from |
|
178 * the collection and the new key-value pair will be added to the |
|
179 * map. |
|
180 * |
|
181 * @param aKey the key to be stored |
|
182 * @param aValue the value associated with the key to be stored |
|
183 */ |
|
184 void InsertL( const TDesC8& aKey, const TLiwVariant& aValue ); |
|
185 |
|
186 /** |
|
187 * Finds a value stored in the map collection based on the key. |
|
188 * |
|
189 * @param aKey the key to be searched |
|
190 * @param aFndValue the value associated with the found key |
|
191 * @return false if there is no key stored; true otherwise |
|
192 */ |
|
193 TBool FindL( const TDesC8& aKey, TLiwVariant& aValue ) const; |
|
194 |
|
195 /** |
|
196 * Returns the number of key-value pair stored in the map collection. |
|
197 * |
|
198 * @return the number of key-value pair stored in the map collection |
|
199 */ |
|
200 TInt Count() const; |
|
201 |
|
202 /** |
|
203 * Returns the key stored at a specified index. |
|
204 * |
|
205 * @param aIndex the index of the key to be found |
|
206 * @param aFndKey the key found at the passed index |
|
207 * |
|
208 * @return true if a key-value entry is found at the passed index; |
|
209 * false otherwise |
|
210 */ |
|
211 TBool AtL( TInt aIndex, TDes8& aFndKey ) const; |
|
212 |
|
213 /** |
|
214 * Removes a key from the map collection. |
|
215 * |
|
216 * @param aKey the key to be removed from the map |
|
217 */ |
|
218 void Remove( const TDesC8& aKey ); |
|
219 |
|
220 /** |
|
221 * Returns the size of the collection. The size is |
|
222 * calculated based on the total numer of key-value elements |
|
223 * and the size of each pair in the collection |
|
224 * |
|
225 * @return the size of the collection |
|
226 */ |
|
227 TInt Size() const; |
|
228 |
|
229 /** |
|
230 * The container managed data values can be serialized to an output |
|
231 * stream. |
|
232 * |
|
233 * @param aOutputStream the output stream to which the data will be streamed |
|
234 */ |
|
235 void ExternalizeL( RWriteStream& aOutputStream ) const; |
|
236 |
|
237 protected: |
|
238 |
|
239 /** |
|
240 * Adds to database current content |
|
241 * |
|
242 * @param aSqlDb handle to database |
|
243 * @param aNotificationList list of notifications to fill in when |
|
244 * something was actually changed in dataabse |
|
245 * |
|
246 * @return id of added entry |
|
247 */ |
|
248 virtual TInt32 AddL( RSqlDatabase aSqlDb, |
|
249 CLiwDefaultList* aNotificationList = 0 ) const= 0; |
|
250 |
|
251 /** |
|
252 * Fetches entries from database |
|
253 * |
|
254 * @param aSqlDb handle to database |
|
255 * @param aList target list for enntries |
|
256 * @param aItemsToDelete ids of entries for removal - |
|
257 * they were found to be expired |
|
258 * |
|
259 * @return number of fetched entries |
|
260 */ |
|
261 virtual TUint GetListL( RSqlDatabase aSqlDb, CLiwGenericParamList* aList, |
|
262 RArray<TInt32>& aItemsToDelete ) const = 0; |
|
263 |
|
264 /** |
|
265 * Removes entries from database |
|
266 * |
|
267 * @param aSqlDb handle to database |
|
268 * @param aNotificationList list of notifications to fill in when |
|
269 * something was actually changed in dataabse |
|
270 */ |
|
271 virtual void RemoveL( RSqlDatabase aSqlDb, |
|
272 CLiwDefaultList* aNotificationList = 0 ) const = 0; |
|
273 |
|
274 /** |
|
275 * Saves results from query to SQLite Server |
|
276 * |
|
277 * @param aStmt handle to SQL statement |
|
278 * @param aList target list for enntries |
|
279 * @param aItemsToDelete ids of entries for removal - |
|
280 * they were found to be expired |
|
281 */ |
|
282 virtual void SaveQueryResultsL( RSqlStatement& aStmt, |
|
283 CLiwGenericParamList& aList, RArray<TInt32>& aItemsToDelete ) const = 0; |
|
284 |
|
285 /** |
|
286 * Updates entry in database |
|
287 * |
|
288 * @param aSqlDb handle to database |
|
289 * @param aNotificationList list of notifications to fill in when |
|
290 * something was actually changed in dataabse |
|
291 */ |
|
292 virtual void UpdateL( RSqlDatabase aSqlDb, TInt32 aId, |
|
293 CLiwDefaultList* aNotificationList = 0 ) const = 0; |
|
294 |
|
295 /** |
|
296 * Performs actuall add operation |
|
297 * |
|
298 * @param aSqlDb handle to database |
|
299 * @param aNotificationList list of notifications to fill in when |
|
300 * something was actually changed in dataabse |
|
301 * |
|
302 * @return id of added entry |
|
303 */ |
|
304 virtual TInt32 AddToDbL( RSqlDatabase aSqlDb, |
|
305 CLiwDefaultList* aNotificationList = 0 ) const = 0; |
|
306 |
|
307 /** |
|
308 * Checks if operation value is proper |
|
309 * |
|
310 * @param aValue contains operation value |
|
311 */ |
|
312 void IsProperOperationL( const TLiwVariant& aValue ) const; |
|
313 |
|
314 |
|
315 /** |
|
316 * Appends GetList filter as strings to SQL query according to aFilter |
|
317 * |
|
318 * @param aQuery SQL query |
|
319 * @param aFilter as enum |
|
320 * |
|
321 */ |
|
322 void AppendGetListFilterL( RBuf& aQuery, TUint& aFilter ) const; |
|
323 |
|
324 /** |
|
325 * Appends Remove filter as strings to SQL query according to aFilter |
|
326 * |
|
327 * @param aQuery SQL query |
|
328 * @param aFilter as enum |
|
329 * |
|
330 */ |
|
331 void AppendRemoveFilterL( RBuf& aQuery, TUint& aFilter ) const; |
|
332 |
|
333 |
|
334 /** |
|
335 * Appends filter as strings to SQL query according to aFilter |
|
336 * |
|
337 * @param aQuery SQL query |
|
338 * @param aFilter as enum |
|
339 * |
|
340 */ |
|
341 virtual void AppendFilterL( RBuf& aQuery, TUint& aFilter ) const; |
|
342 |
|
343 /** |
|
344 * Prepares SQL query for Add operation |
|
345 * |
|
346 * @param aSqlDb handle to database |
|
347 * @param aStmt handle to SQL statement |
|
348 * @param aQuery SQL query |
|
349 * |
|
350 */ |
|
351 virtual void PrepareStmtforAddL( RSqlDatabase aSqlDb, |
|
352 RSqlStatement& aStmt, const TDesC& aQuery ) const; |
|
353 /** |
|
354 * Appends sorting criteria as strings to SQL query according to aSort |
|
355 * |
|
356 * @param aQuery SQL query |
|
357 * @param aSort sort filter as TInt |
|
358 * |
|
359 */ |
|
360 virtual void AppendSortL( RBuf& aQuery, |
|
361 const TCPSortOrder& aSort ) const = 0; |
|
362 |
|
363 /** |
|
364 * Fills change info map with proper values |
|
365 *aStmt |
|
366 * @param aStmt handle to SQL statement |
|
367 * @param aChangeInfoMap map that will be filed |
|
368 * |
|
369 */ |
|
370 virtual void FillChangeInfoMapL( RSqlStatement& aStmt, |
|
371 CLiwDefaultMap* aMap ) const; |
|
372 |
|
373 protected: |
|
374 |
|
375 /** |
|
376 * Sets all parameters according to provided list |
|
377 * @param aItemMap map with parameters |
|
378 */ |
|
379 void SetL( const CLiwGenericParamList& aInParamList ); |
|
380 |
|
381 /** |
|
382 * Check Get properties |
|
383 * |
|
384 * @return logical sum of TCPProperties of the object |
|
385 */ |
|
386 TUint GetFilterL() const; |
|
387 |
|
388 /** |
|
389 * Check and return sort order |
|
390 * |
|
391 * @return Sort Criteria |
|
392 */ |
|
393 TCPSortOrder GetSortL() const; |
|
394 |
|
395 /** |
|
396 * Check if Publisher name is set |
|
397 * |
|
398 * @return ETrue if Publisher name was set, EFalse if not |
|
399 */ |
|
400 TBool IsPublisherNameL() const; |
|
401 |
|
402 /** |
|
403 * Check if ContentType is set |
|
404 * |
|
405 * @return ETrue if ContentType was set, EFalse if not |
|
406 */ |
|
407 TBool IsContentTypeL() const; |
|
408 |
|
409 /** |
|
410 * Check if ContentId is set |
|
411 * |
|
412 * @return ETrue if ContentId was set, EFalse if not |
|
413 */ |
|
414 TBool IsContentIdL() const; |
|
415 |
|
416 /** |
|
417 * Check if ActionTrigger is set |
|
418 * |
|
419 * @return ETrue if ActionTrigger was set, EFalse if not |
|
420 */ |
|
421 TBool IsTriggerL( ) const; |
|
422 |
|
423 /** |
|
424 * Check if Flag is present |
|
425 * |
|
426 * @return ETrue if ContentId was set, EFalse if not |
|
427 */ |
|
428 TBool IsFlag( ) const; |
|
429 |
|
430 /** |
|
431 * Checks if Id property is present in internal map |
|
432 * |
|
433 */ |
|
434 TBool IsId() const; |
|
435 |
|
436 /** |
|
437 * Checks if property(key) is present in internal map |
|
438 * |
|
439 */ |
|
440 TBool PropertyExists( const TDesC8& aProperty ) const; |
|
441 |
|
442 |
|
443 /** |
|
444 * Fetches entries from database |
|
445 * |
|
446 * @param aSqlDb handle to database |
|
447 * @param aQuery aQuery SQL query |
|
448 * @param aList target list for enntries |
|
449 * @param aItemsToDelete ids of entries for removal - |
|
450 * they were found to be expired |
|
451 * |
|
452 * @return number of fetched entries |
|
453 */ |
|
454 TUint GetListL( RSqlDatabase aSqlDb, const TDesC& aQuery, |
|
455 CLiwGenericParamList* aList, RArray<TInt32>& aItemsToDelete ) const; |
|
456 |
|
457 /** |
|
458 * Removes entries from database |
|
459 * |
|
460 * @param aSqlDb handle to database |
|
461 * @param aQuery SQL query |
|
462 * |
|
463 */ |
|
464 void RemoveL( RSqlDatabase aSqlDb, const TDesC& aQuery ) const; |
|
465 |
|
466 /** |
|
467 * Fetches Ids (Publisher, ContentType, ContentId) from database |
|
468 * |
|
469 * @param aId id entry in database |
|
470 * @param aQuery SQL query |
|
471 * @param aMap map to insert Ids |
|
472 * @param aSqlDb handle to database |
|
473 * |
|
474 */ |
|
475 void FetchIdsL( TInt32 aId, const TDesC& aQuery, CLiwDefaultMap* aMap, |
|
476 RSqlDatabase aSqlDb ) const; |
|
477 |
|
478 /** |
|
479 * Fetches Id from database |
|
480 * |
|
481 * @param aSqlDb handle to database |
|
482 * @param aQuery SQL query |
|
483 * @param aId id entry from database |
|
484 * |
|
485 */ |
|
486 void FetchIdL( RSqlDatabase aSqlDb, |
|
487 const TDesC& aQuery, TInt32& aId ) const; |
|
488 |
|
489 /** |
|
490 * Gets Ids (Id, Publisher, ContentType, ContentId) |
|
491 * of removed entries from database |
|
492 * |
|
493 * @param aSqlDb handle to database |
|
494 * @param aQuery SQL query |
|
495 * @param aList List with ids |
|
496 * |
|
497 */ |
|
498 void GetIdsOfRemovedEntriesL( RSqlDatabase aSqlDb, const TDesC& aQuery, |
|
499 CLiwDefaultList* aList ) const; |
|
500 |
|
501 /** |
|
502 * Saves Ids (Id, Publisher, ContentType, ContentId) from database |
|
503 * |
|
504 * @param aSqlDb handle to database |
|
505 * @param aList List with ids |
|
506 * |
|
507 */ |
|
508 void SaveQueryResultsIdsL( RSqlStatement& aStmt, |
|
509 CLiwDefaultList* aList ) const; |
|
510 |
|
511 /** |
|
512 * Contructs SQL query to select entry |
|
513 * @param aQuery SQL query |
|
514 * |
|
515 */ |
|
516 void ConstructSelectIdL( RBuf& aQuery ) const; |
|
517 |
|
518 /** |
|
519 * Contructs SQL query to select entries for GetList |
|
520 * @param aQuery SQL query |
|
521 * |
|
522 */ |
|
523 void ConstructGetListSelectL( RBuf& aQuery, TBool aGet = ETrue ) const; |
|
524 |
|
525 /** |
|
526 * Contructs SQL query to select entries for Remove |
|
527 * @param aQuery SQL query |
|
528 * |
|
529 */ |
|
530 void ConstructRemoveSelectL( RBuf& aQuery, TBool aGet = ETrue ) const; |
|
531 |
|
532 /** |
|
533 * Binds value to query |
|
534 * @param aQuery SQL query |
|
535 * @param aSqlDb handle to database |
|
536 * |
|
537 */ |
|
538 void BindValueL( const RBuf& aQuery, RSqlStatement& aStmt ) const; |
|
539 |
|
540 /** |
|
541 * Checks if GetList for all items should be done |
|
542 * @param aFilter flag describing which ids are set |
|
543 * @return ETrue if getlist for all items shold be done, EFalse if not |
|
544 */ |
|
545 TBool IsGetListAllL( TUint aFilter ) const; |
|
546 |
|
547 /** |
|
548 * Removes attributes with "All" value from map |
|
549 * @param aFilter filter bit will be reset if any attribute == "all" |
|
550 */ |
|
551 void RemoveAllAttributeL( TUint& aFilter ) const; |
|
552 |
|
553 /** |
|
554 * Leaves if publisher, content type od content_id is not descriptor type. |
|
555 */ |
|
556 void CheckIdentifiersL() const; |
|
557 |
|
558 /** |
|
559 * Leaves if aParameterIndex is negative-error value |
|
560 * or in case of binding error. |
|
561 */ |
|
562 void BindTextL(RSqlStatement& aStmt, TInt aParameterIndex, |
|
563 const TDesC& aParameterText) const; |
|
564 |
|
565 /** |
|
566 * Leaves if aParameterIndex is negative-error value |
|
567 * or in case of binding error. |
|
568 */ |
|
569 void BindBinaryL(RSqlStatement& aStmt, TInt aParameterIndex, |
|
570 const TDesC8& aParameterText) const; |
|
571 |
|
572 /** |
|
573 * Leaves if aParameterIndex is negative-error value |
|
574 * or in case of binding error. |
|
575 */ |
|
576 void BindInt64L(RSqlStatement& aStmt, TInt aParameterIndex, |
|
577 TInt64 aParameterValue) const; |
|
578 |
|
579 /** |
|
580 * Leaves if aParameterIndex is negative-error value |
|
581 * or in case of binding error. |
|
582 */ |
|
583 void BindIntL(RSqlStatement& aStmt, TInt aParameterIndex, |
|
584 TInt aParameterValue) const; |
|
585 |
|
586 /** |
|
587 * Leaves if column index return value is negative. |
|
588 * @return result of RSqlStatement::ColumnIndex |
|
589 */ |
|
590 TInt ColumnIndexL( RSqlStatement& aStmt, const TDesC& aColumnName ) const; |
|
591 protected: |
|
592 |
|
593 /** |
|
594 * C++ default constructor. |
|
595 */ |
|
596 CCPLiwMap(); |
|
597 |
|
598 /** |
|
599 * Perform the second phase construction of a CCPLiwMap object. |
|
600 */ |
|
601 void ConstructL(); |
|
602 |
|
603 protected: |
|
604 // data |
|
605 |
|
606 /* |
|
607 * The underlying generic parameter list |
|
608 * Own. |
|
609 */ |
|
610 CLiwGenericParamList* iMap; |
|
611 |
|
612 /* |
|
613 * Class used for security |
|
614 *Own. |
|
615 */ |
|
616 const CCPSecurityPolicy* iPolicy; |
|
617 |
|
618 }; |
|
619 |
|
620 #endif // C_CPLIWIDSMAP_H |