|
1 /* |
|
2 * Copyright (c) 2006-2007 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bautils.h> |
|
20 |
|
21 #include "irbrowsecatagoryitems.h" |
|
22 #include "irbrowsechannelitems.h" |
|
23 #include "ircachecleanup.h" |
|
24 #include "ircachemgmt.h" |
|
25 #include "ircacheobserver.h" |
|
26 #include "irdebug.h" |
|
27 #include "irhttprequestdata.h" |
|
28 #include "irisdspreset.h" |
|
29 #include "irotaupdate.h" |
|
30 #include "irsettings.h" |
|
31 |
|
32 //Default trust period value.24 hrs in secs with which the object is to be initialised |
|
33 const TInt KDefaultInterval = 24*60*60; |
|
34 //granualarity for the arrays |
|
35 //the granualarity value is based on superficial observation of the amount of |
|
36 //data recieved for a particular request |
|
37 const TInt KBrowseGranualarity = 32; |
|
38 const TInt KChannelArrayGranualarity = 32; |
|
39 const TInt KPresetGranualarity = 12; |
|
40 //http length format length |
|
41 // "Sun, 06 Nov 1994 08:49:37 GMT" format |
|
42 const TInt KHttpDateLength = 25; |
|
43 |
|
44 //Max size( critical size ) in Bytes( 90% of the max size ) |
|
45 //critical size is the size that triggers cleanup action |
|
46 const TInt KCacheCriticalSizeLimit = KCacheLimitSize*9/10; |
|
47 |
|
48 //No of rows deleted will be one fourth of the total number of rows |
|
49 const TInt KPercentRowsDeleted = 4; |
|
50 |
|
51 //The indexing size for the column DataId is set to 100 |
|
52 const TInt KDataIdIndexSize = 100; |
|
53 |
|
54 //database file name |
|
55 _LIT( KCacheDbFile,"cacheDb.db" ); |
|
56 |
|
57 //Table Name CacheTable |
|
58 _LIT( KCacheTable,"CacheTable" ); |
|
59 |
|
60 //CacheTable columns |
|
61 _LIT( KRowIndexCol, "RowIndex" ); |
|
62 _LIT( KDataTypeCol, "DataType" ); |
|
63 _LIT( KDataIdCol, "DataId" ); |
|
64 _LIT( KTrustPeriodCol, "TrustPeriod" ); |
|
65 _LIT( KLastModifiedCol, "LastModified" ); |
|
66 _LIT( KLastAccessedCol, "LastAccessed" ); |
|
67 _LIT( KTimeCreation, "Created" ); |
|
68 _LIT( KItemCount, "ItemCount" ); |
|
69 _LIT( KCachedDataCol, "CachedData" ); |
|
70 _LIT( KETagHeader, "ETagHeader" ); |
|
71 |
|
72 //Table Index Names |
|
73 _LIT( KRowIndexColIndex, "IndexRowIndex" ); |
|
74 _LIT( KDataTypeColIndex, "IndexDataType" ); |
|
75 _LIT( KDataIdColIndex, "IndexDataId" ); |
|
76 _LIT( KLastAccessedColIndex, "IndexLastAccessed" ); |
|
77 _LIT( KTimeCreationIndex, "IndexCreated" ); |
|
78 //Field Lengths |
|
79 |
|
80 const TInt KIRObserverArrayGranularity( 2 ); |
|
81 |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Function : OpenL |
|
85 // Standard two phased construction |
|
86 // calls ConstructL() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CIRCacheMgmt* CIRCacheMgmt::OpenL( MIRCacheObserver &aObserver ) |
|
90 { |
|
91 IRLOG_DEBUG( "IRCacheMgmt::OpenL - Entering." ); |
|
92 CIRCacheMgmt* self = reinterpret_cast<CIRCacheMgmt*>( Dll::Tls() ); |
|
93 |
|
94 if ( self ) |
|
95 { |
|
96 User::LeaveIfError( self->Open() ); |
|
97 } |
|
98 else |
|
99 { |
|
100 self = new ( ELeave ) CIRCacheMgmt( aObserver ); |
|
101 CleanupClosePushL( *self ); |
|
102 self->ConstructL(); |
|
103 User::LeaveIfError( Dll::SetTls( self ) ); |
|
104 CleanupStack::Pop( self ); |
|
105 } |
|
106 IRLOG_DEBUG( "IRCacheMgmt::OpenL - Exiting." ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Function : CIRCacheMgmt::~CIRCacheMgmt() |
|
113 // Standard C++ destructor |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 CIRCacheMgmt::~CIRCacheMgmt() |
|
117 { |
|
118 IRLOG_DEBUG( "IRCacheMgmt::~CIRCacheMgmt - Entering." ); |
|
119 //array destruction |
|
120 if ( iPtrPreset ) |
|
121 { |
|
122 iPtrPreset->ResetAndDestroy(); |
|
123 delete iPtrPreset; |
|
124 iPtrPreset = NULL; |
|
125 } |
|
126 if ( iPtrCategory ) |
|
127 { |
|
128 iPtrCategory->ResetAndDestroy(); |
|
129 } |
|
130 |
|
131 delete iPtrCategory; |
|
132 iPtrCategory = NULL; |
|
133 if ( iPtrChannel ) |
|
134 { |
|
135 iPtrChannel->ResetAndDestroy(); |
|
136 } |
|
137 |
|
138 delete iPtrChannel; |
|
139 iPtrChannel = NULL; |
|
140 if ( iSettings ) |
|
141 { |
|
142 iSettings->Close(); |
|
143 } |
|
144 if ( iOTA ) |
|
145 { |
|
146 delete iOTA; |
|
147 iOTA = NULL; |
|
148 } |
|
149 iLogoData.Close(); |
|
150 CloseDb(); |
|
151 iCacheDb.Close(); |
|
152 delete iCleanup; |
|
153 iFsSession.Close(); |
|
154 iCacheObservers.Close(); |
|
155 Dll::FreeTls(); |
|
156 IRLOG_DEBUG( "IRCacheMgmt::~CIRCacheMgmt - Exiting." ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // Function : CIRCacheMgmt::CIRCacheMgmt() |
|
161 // Standard C++ constructor |
|
162 // sets the trust period to 24hrs( default ) |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 CIRCacheMgmt::CIRCacheMgmt ( MIRCacheObserver &aObserver ) |
|
166 :iCacheObserver( aObserver ), |
|
167 iCacheObservers( KIRObserverArrayGranularity ) |
|
168 { |
|
169 IRLOG_DEBUG( "IRCacheMgmt::CIRCacheMgmt - Entering." ); |
|
170 //default trust period initially set to 24 hrs |
|
171 //to be fetched from central repository |
|
172 iTrustPeriod = TTimeIntervalSeconds( KDefaultInterval ); |
|
173 IRLOG_DEBUG( "IRCacheMgmt::CIRCacheMgmt - Exiting." ); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // Function : CIRCacheMgmt::ConstructL() |
|
178 // Standard two phased construction |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CIRCacheMgmt::ConstructL() |
|
182 { |
|
183 IRLOG_DEBUG( "IRCacheMgmt::ConstructL - Entering." ); |
|
184 User::LeaveIfError( iFsSession.Connect() ); |
|
185 //array construction |
|
186 iPtrPreset = new ( ELeave ) CArrayPtrFlat<CIRIsdsPreset>( |
|
187 KPresetGranualarity ); |
|
188 iPtrCategory = new ( ELeave ) CArrayPtrFlat<CIRBrowseCatagoryItems>( |
|
189 KBrowseGranualarity ); |
|
190 iPtrChannel = new ( ELeave ) CArrayPtrFlat<CIRBrowseChannelItems>( |
|
191 KChannelArrayGranualarity ); |
|
192 iOTA = CIROTAUpdate::NewL(); |
|
193 iSettings = CIRSettings::OpenL(); |
|
194 iDatabaseFileName = iSettings->PrivatePath(); |
|
195 iDatabaseFileName.Append( KCacheDbFile ); |
|
196 CreateDbConditionalL(); |
|
197 iCleanup = CIRCacheCleanup::NewL( *this ); |
|
198 RemoveOtaInfoL(); |
|
199 IRLOG_DEBUG( "IRCacheMgmt::ConstructL - Exiting." ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Function : CIRCacheMgmt::CreateDbConditionalL( |
|
204 // Creates dbms conditionally( only if not yet created ) |
|
205 // calls CreateDb() |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CIRCacheMgmt::CreateDbConditionalL() |
|
209 { |
|
210 IRLOG_DEBUG( "IRCacheMgmt::CreateDbConditionalL - Entering." ); |
|
211 TInt err=KErrNone; |
|
212 if ( !BaflUtils::FileExists( iFsSession, iDatabaseFileName ) ) |
|
213 { |
|
214 err=CreateDb(); |
|
215 if ( KErrNone != err ) |
|
216 { |
|
217 User::Leave( err ); |
|
218 } |
|
219 } |
|
220 IRLOG_DEBUG( "IRCacheMgmt::CreateDbConditionalL - Exiting." ); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // Function : CIRCacheMgmt::CreateDb() |
|
225 // Creates the tables |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 TInt CIRCacheMgmt::CreateDb() |
|
229 { |
|
230 IRLOG_DEBUG( "IRCacheMgmt::CreateDb - Entering." ); |
|
231 CloseDb(); |
|
232 TInt err = iCacheDb.Replace( iFsSession,iDatabaseFileName ); |
|
233 if ( ( err != 0 ) ) |
|
234 { |
|
235 return err; //unable to create file |
|
236 } |
|
237 TRAP( err,//trap start |
|
238 CreateCacheTableL(); |
|
239 CreateCacheIndexL(); |
|
240 )//trap end |
|
241 IRLOG_DEBUG( "IRCacheMgmt::CreateDb - Exiting." ); |
|
242 return err; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // Function : CIRCacheMgmt::OpenCacheDb() |
|
247 // Opens both the databases |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CIRCacheMgmt::OpenCacheDb() |
|
251 { |
|
252 IRLOG_DEBUG( "CIRCacheMgmt::OpenCacheDb - Entering" ); |
|
253 CloseDb(); |
|
254 TInt error = KErrNone; |
|
255 if ( !BaflUtils::FileExists( iFsSession, iDatabaseFileName ) ) |
|
256 { |
|
257 //if file doesn't exist function leaves with error code |
|
258 //KErrNotFound |
|
259 return KErrNotFound; |
|
260 } |
|
261 //try and open the db |
|
262 error = iCacheDb.Open( iFsSession,iDatabaseFileName ); |
|
263 //return if error |
|
264 if ( KErrNone != error ) |
|
265 { |
|
266 return error; |
|
267 } |
|
268 //check if damaged |
|
269 if ( iCacheDb.IsDamaged() ) |
|
270 { |
|
271 //if data base is damaged then |
|
272 //try to recover |
|
273 error = iCacheDb.Recover(); |
|
274 return error; |
|
275 } |
|
276 |
|
277 iOpen = ETrue; |
|
278 |
|
279 IRLOG_DEBUG( "CIRCacheMgmt::OpenCacheDb - Exiting." ); |
|
280 return KErrNone; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // Function : CIRCacheMgmt::CloseDb() |
|
285 // Closes the database |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CIRCacheMgmt::CloseDb() |
|
289 { |
|
290 IRLOG_DEBUG( "IRCacheMgmt::CloseDb - Entering." ); |
|
291 iCacheDb.Close(); |
|
292 iOpen = EFalse; |
|
293 IRLOG_DEBUG( "IRCacheMgmt::CloseDb - Exiting." ); |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // Function : CIRCacheMgmt::CheckCache() |
|
298 // API Exposed to Isds Client to check and get the cached items. |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 EXPORT_C void CIRCacheMgmt::CheckCacheL( TInt aType,const TDesC& aName, |
|
302 TBool aForceGet,TInt& aReturn ) |
|
303 { |
|
304 IRLOG_DEBUG( "CIRCacheMgmt::CheckCacheL - Entering" ); |
|
305 //opens the db if not open already |
|
306 if ( !iOpen ) |
|
307 { |
|
308 TInt error = OpenCacheDb(); |
|
309 if ( KErrNone != error ) |
|
310 { |
|
311 aReturn = ENotCached; |
|
312 return; |
|
313 } |
|
314 } |
|
315 |
|
316 //calls the function FetchCacheIfAvailable() passing the appropriate |
|
317 //type and id |
|
318 |
|
319 switch( aType ) |
|
320 { |
|
321 case ECatagory: |
|
322 case EChannels: |
|
323 case EPresets: |
|
324 case EOtaInfo: |
|
325 case ELogo: |
|
326 { |
|
327 TRAP_IGNORE( FetchCacheIfAvailableL( aType,aName,aForceGet,aReturn ) ) |
|
328 break; |
|
329 } |
|
330 |
|
331 default: |
|
332 { |
|
333 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
334 { |
|
335 iCacheObservers[i]->CacheFailed(); |
|
336 } |
|
337 aReturn = ENotCached; |
|
338 break; |
|
339 } |
|
340 } |
|
341 CloseDb(); |
|
342 IRLOG_DEBUG( "CIRCacheMgmt::CheckCacheL - Exiting." ); |
|
343 } |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // Function : CIRCacheMgmt::FetchCacheIfAvailable() |
|
347 // Fetches the cache if available |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 //generic function to check the validity of the cache |
|
351 void CIRCacheMgmt::FetchCacheIfAvailableL( TInt aType,const TDesC& aId, |
|
352 TBool aForceGet,TInt& aReturnVal ) |
|
353 { |
|
354 //Algo**** |
|
355 //1.check the cache table for a request type |
|
356 //2.if the query returns a row,check for validity |
|
357 //3.if invalid( stale ) do a conditional get |
|
358 //4.if valid use cache |
|
359 IRLOG_DEBUG( "CIRCacheMgmt::FetchCacheIfAvailableL - Entering" ); |
|
360 //SELECT * FROM KCacheTable WHERE KDataTypeCol = aType AND KDataIdCol=aId |
|
361 _LIT( query, "SELECT * FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
362 |
|
363 HBufC* sqlQuery = HBufC::NewLC( query().Length() + KCacheTable().Length() + |
|
364 KDataTypeCol().Length() + KDataIdCol().Length() + |
|
365 KDefaultRealWidth + aId.Length() ); |
|
366 |
|
367 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
368 aType,&KDataIdCol,&aId ); |
|
369 |
|
370 IRLOG_DEBUG2( "CIRCacheMgmt::FetchCacheIfAvailableL - \ |
|
371 Going to evaluate SQL query: %S", sqlQuery ); |
|
372 |
|
373 RDbView cacheView; |
|
374 User::LeaveIfError( cacheView.Prepare( iCacheDb,*sqlQuery ) ); |
|
375 CleanupStack::PopAndDestroy( sqlQuery ); |
|
376 CleanupClosePushL( cacheView ); |
|
377 User::LeaveIfError( cacheView.EvaluateAll() ); |
|
378 |
|
379 //if no row match the query there is no cahche available for |
|
380 //that particular |
|
381 //request |
|
382 if ( cacheView.IsEmptyL() ) |
|
383 { |
|
384 //Return ENotCached |
|
385 aReturnVal = ENotCached; |
|
386 } |
|
387 else |
|
388 { |
|
389 cacheView.FirstL(); |
|
390 cacheView.GetL(); |
|
391 CDbColSet* columns = cacheView.ColSetL(); |
|
392 TTime creationTime = cacheView.ColTime( |
|
393 columns->ColNo( KTimeCreation ) ); |
|
394 |
|
395 TInt cacheValidityTime = cacheView.ColInt( |
|
396 columns->ColNo( KTrustPeriodCol ) ); |
|
397 |
|
398 TInt countItems=cacheView.ColInt( columns->ColNo( KItemCount ) ); |
|
399 |
|
400 IRLOG_DEBUG( "CIRCacheMgmt::FetchCacheIfAvailableL - \ |
|
401 can check validity." ); |
|
402 |
|
403 //check if cache is valid |
|
404 //get it any way if it is "forcedget" |
|
405 if ( aForceGet || CheckValidity( creationTime,cacheValidityTime ) ) |
|
406 { |
|
407 //Fetch the cached data |
|
408 //FetchCachedData( type,count,&view ) |
|
409 TRAPD( err,FetchCachedDataL( aType,countItems,cacheView ) ); |
|
410 if ( err!=KErrNone ) |
|
411 { |
|
412 //something goes wrong ,return not cached and fetch new data |
|
413 aReturnVal = ENotCached; |
|
414 } |
|
415 else |
|
416 { |
|
417 //cache usable |
|
418 aReturnVal = ECacheUseable; |
|
419 } |
|
420 } |
|
421 else |
|
422 { |
|
423 iLastModified = cacheView.ColTime( |
|
424 columns->ColNo( KLastModifiedCol ) ); |
|
425 |
|
426 iETag = cacheView.ColDes8( columns->ColNo( KETagHeader ) ); |
|
427 aReturnVal = ECacheNotValid; |
|
428 cacheView.Close(); |
|
429 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
430 { |
|
431 iCacheObservers[i]->CacheInvalid(); |
|
432 } |
|
433 } |
|
434 delete columns; |
|
435 } |
|
436 CleanupStack::PopAndDestroy( &cacheView ); |
|
437 IRLOG_DEBUG( "CIRCacheMgmt::FetchCacheIfAvailableL - Exiting." ); |
|
438 |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // Function : CIRCacheMgmt::FetchCachedDataL() |
|
443 // fetches the cached data from the table into the cached structures |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CIRCacheMgmt::FetchCachedDataL( TInt aType,TInt aCountItems, |
|
447 RDbView& aCacheView ) |
|
448 { |
|
449 //Algo**** |
|
450 //fetch the data and internalize into appropriate structure |
|
451 |
|
452 IRLOG_DEBUG( "CIRCacheMgmt::FetchCachedDataL - Entering" ); |
|
453 CDbColSet* columns = aCacheView.ColSetL(); |
|
454 TInt columnNo = columns->ColNo( KCachedDataCol ); |
|
455 delete columns; |
|
456 switch( aType ) |
|
457 { |
|
458 case ECatagory: |
|
459 { |
|
460 //Internalize the category items into the |
|
461 //CIRBrowseCatagoryItems array |
|
462 RDbColReadStream instream; |
|
463 instream.OpenLC( aCacheView, columnNo ); |
|
464 CIRBrowseCatagoryItems* ptr; |
|
465 if ( iPtrCategory ) |
|
466 { |
|
467 iPtrCategory->ResetAndDestroy(); |
|
468 } |
|
469 else |
|
470 { |
|
471 break; |
|
472 } |
|
473 for ( TInt iter = 0; iter < aCountItems; iter++ ) |
|
474 { |
|
475 ptr=CIRBrowseCatagoryItems::NewL(); |
|
476 CleanupStack::PushL( ptr ); |
|
477 instream>>*ptr; |
|
478 iPtrCategory->AppendL( ptr ); |
|
479 CleanupStack::Pop( ptr ); |
|
480 } |
|
481 CleanupStack::PopAndDestroy( &instream ); |
|
482 //update the last accessed time |
|
483 UpdateLastAccessedTimeL( aCacheView ); |
|
484 aCacheView.Close(); |
|
485 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
486 { |
|
487 iCacheObservers[i]->CachedStructureL( ECatagory ); |
|
488 } |
|
489 break; |
|
490 } |
|
491 case EChannels: |
|
492 { |
|
493 //Internalize the channel items into |
|
494 //the CIRBrowseChannelItems array |
|
495 RDbColReadStream instream; |
|
496 instream.OpenLC( aCacheView, columnNo ); |
|
497 if ( iPtrChannel ) |
|
498 { |
|
499 iPtrChannel->ResetAndDestroy(); |
|
500 } |
|
501 CIRBrowseChannelItems *ptr; |
|
502 for ( TInt iter = 0; iter < aCountItems; iter++ ) |
|
503 { |
|
504 ptr = CIRBrowseChannelItems::NewL(); |
|
505 CleanupStack::PushL( ptr ); |
|
506 instream>>*ptr; |
|
507 if ( iPtrChannel ) |
|
508 { |
|
509 iPtrChannel->AppendL( ptr ); |
|
510 } |
|
511 CleanupStack::Pop( ptr ); |
|
512 } |
|
513 CleanupStack::PopAndDestroy( &instream ); |
|
514 //update the last accessed time |
|
515 UpdateLastAccessedTimeL( aCacheView ); |
|
516 aCacheView.Close(); |
|
517 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
518 { |
|
519 iCacheObservers[i]->CachedStructureL( EChannels ); |
|
520 } |
|
521 break; |
|
522 } |
|
523 case EPresets: |
|
524 { |
|
525 //Internalize the preset into the CIRIsdsPreset object |
|
526 RDbColReadStream instream; |
|
527 instream.OpenLC( aCacheView, columnNo ); |
|
528 if ( iPtrPreset ) |
|
529 { |
|
530 iPtrPreset->ResetAndDestroy(); |
|
531 } |
|
532 CIRIsdsPreset *ptr; |
|
533 for ( TInt iter = 0; iter < aCountItems; iter++ ) |
|
534 { |
|
535 ptr = CIRIsdsPreset::NewL(); |
|
536 CleanupStack::PushL( ptr ); |
|
537 instream>>*ptr; |
|
538 if ( iPtrPreset ) |
|
539 { |
|
540 iPtrPreset->AppendL( ptr ); |
|
541 } |
|
542 CleanupStack::Pop( ptr ); |
|
543 } |
|
544 CleanupStack::PopAndDestroy( &instream ); |
|
545 //update the last accessed time |
|
546 UpdateLastAccessedTimeL( aCacheView ); |
|
547 aCacheView.Close(); |
|
548 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
549 { |
|
550 iCacheObservers[i]->CachedStructureL( EPresets ); |
|
551 } |
|
552 break; |
|
553 } |
|
554 case EOtaInfo: |
|
555 { |
|
556 //Internalize the ota info into the CIROTAUpdate object |
|
557 RDbColReadStream instream; |
|
558 instream.OpenLC( aCacheView, columnNo ); |
|
559 if ( iOTA ) |
|
560 { |
|
561 delete iOTA; |
|
562 iOTA = NULL; |
|
563 iOTA = CIROTAUpdate::NewL(); |
|
564 instream>>*iOTA; |
|
565 } |
|
566 |
|
567 CleanupStack::PopAndDestroy( &instream ); |
|
568 //update the last accessed time |
|
569 UpdateLastAccessedTimeL( aCacheView ); |
|
570 aCacheView.Close(); |
|
571 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
572 { |
|
573 iCacheObservers[i]->CachedStructureL( EOtaInfo ); |
|
574 } |
|
575 break; |
|
576 } |
|
577 case ELogo: |
|
578 { |
|
579 //get the logo data from the cache |
|
580 TInt logoSize = aCacheView.ColSize( columnNo ); |
|
581 iLogoData.Close(); |
|
582 iLogoData.Zero(); |
|
583 iLogoData.CreateL( logoSize ); |
|
584 |
|
585 RDbColReadStream instream; |
|
586 instream.OpenLC( aCacheView, columnNo ); |
|
587 instream.ReadL( iLogoData,aCacheView.ColLength( columnNo ) ); |
|
588 CleanupStack::PopAndDestroy( &instream ); |
|
589 //update the last accessed time |
|
590 UpdateLastAccessedTimeL( aCacheView ); |
|
591 aCacheView.Close(); |
|
592 for ( TInt i = 0; i < iCacheObservers.Count(); i++ ) |
|
593 { |
|
594 iCacheObservers[i]->CachedStructureL( ELogo ); |
|
595 } |
|
596 break; |
|
597 } |
|
598 default: |
|
599 { |
|
600 aCacheView.Close(); |
|
601 } |
|
602 } |
|
603 IRLOG_DEBUG( "CIRCacheMgmt::FetchCachedDataL - Exiting." ); |
|
604 } |
|
605 // --------------------------------------------------------------------------- |
|
606 //updates the last accessed field to aid in deletion of old unused data |
|
607 // |
|
608 // --------------------------------------------------------------------------- |
|
609 // |
|
610 void CIRCacheMgmt::UpdateLastAccessedTimeL( RDbView &aCacheView ) |
|
611 { |
|
612 IRLOG_DEBUG( "IRCacheMgmt::UpdateTrustPeriod - Entering." ); |
|
613 //update the last accessed col |
|
614 CDbColSet* columns = aCacheView.ColSetL(); |
|
615 TInt updateColNo = columns->ColNo( KLastAccessedCol ); |
|
616 delete columns; |
|
617 TTime currentTime; |
|
618 currentTime.UniversalTime(); |
|
619 //update the current time value |
|
620 aCacheView.GetL(); |
|
621 aCacheView.UpdateL(); |
|
622 aCacheView.SetColL( updateColNo,currentTime ); |
|
623 aCacheView.PutL(); |
|
624 IRLOG_DEBUG( "IRCacheMgmt::UpdateTrustPeriod - Exiting." ); |
|
625 } |
|
626 |
|
627 // --------------------------------------------------------------------------- |
|
628 // Function : CIRCacheMgmt::CheckValidity() |
|
629 // Checks the freshness of the cache |
|
630 // --------------------------------------------------------------------------- |
|
631 // |
|
632 TBool CIRCacheMgmt::CheckValidity( const TTime& aCreateTime, |
|
633 TInt aTrustPeriod ) const |
|
634 { |
|
635 //Algo**** |
|
636 //1.get the last creation time from the table for the request |
|
637 //2.calculate creation-time + trust-period < current-time * |
|
638 //3.if true the cache is valid |
|
639 //4.else do conditional-get |
|
640 IRLOG_DEBUG( "CIRCacheMgmt::CheckValidity - Entering" ); |
|
641 TTimeIntervalSeconds trustPeriod( aTrustPeriod ); |
|
642 TTimeIntervalSeconds diff; |
|
643 TTime currentDeviceTime; |
|
644 currentDeviceTime.UniversalTime(); |
|
645 currentDeviceTime.SecondsFrom( aCreateTime,diff ); |
|
646 //Has the cache expired |
|
647 if ( diff<trustPeriod ) |
|
648 { |
|
649 IRLOG_DEBUG( "CIRCacheMgmt::CheckValidity - Exiting (1)." ); |
|
650 return ETrue; |
|
651 } |
|
652 //Else return false |
|
653 else |
|
654 { |
|
655 IRLOG_DEBUG( "CIRCacheMgmt::CheckValidity - Exiting (2)." ); |
|
656 return EFalse; |
|
657 } |
|
658 } |
|
659 |
|
660 |
|
661 // --------------------------------------------------------------------------- |
|
662 // Function : CIRCacheMgmt::CacheCategoryItemsL() |
|
663 // Caches the category array of data.By externalizing it into a file. |
|
664 // --------------------------------------------------------------------------- |
|
665 // |
|
666 |
|
667 EXPORT_C void CIRCacheMgmt::CacheCategoryItemsL( |
|
668 CArrayPtrFlat<CIRBrowseCatagoryItems>& aPtrCategory, |
|
669 const TDesC& aName, const CIRHttpResponseData& aResponseHeaders ) |
|
670 { |
|
671 //Algo**** |
|
672 //1.check if similar request is cached |
|
673 //2.delete if similar request is already present |
|
674 //3.prepare a view for insertion |
|
675 //4.push in the requested data as serialized data |
|
676 |
|
677 IRLOG_DEBUG( "IRCacheMgmt::CacheCategoryItemsL - Entering" ); |
|
678 TInt error = OpenCacheDb(); |
|
679 if ( KErrNone != error ) |
|
680 { |
|
681 //no problems if this function returns here. |
|
682 //normal flow won't get affected. |
|
683 //only a particular request wont get cached |
|
684 return; |
|
685 } |
|
686 |
|
687 //clear similar data from the cache table before updating it with fresh data |
|
688 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
689 _LIT( query,"DELETE FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
690 HBufC* sqlQuery = HBufC::NewLC( query().Length() + KDataTypeCol().Length() + |
|
691 KCacheTable().Length() + KDataIdCol().Length() + |
|
692 KDefaultRealWidth + aName.Length() ); |
|
693 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
694 ECatagory,&KDataIdCol,&aName ); |
|
695 iCacheDb.Begin(); |
|
696 //deletes a similar record if it existed. |
|
697 //no problem if it did not exist |
|
698 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
699 CleanupStack::PopAndDestroy( sqlQuery ); |
|
700 iCacheDb.Commit(); |
|
701 |
|
702 //get the cached data view for preset column to update with fresh data. |
|
703 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
704 _LIT( query1,"SELECT * FROM %S WHERE %S = %d" ); |
|
705 HBufC* sqlQuery1 = HBufC::NewLC( query1().Length() + |
|
706 KDataTypeCol().Length() + |
|
707 KCacheTable().Length() + |
|
708 KDefaultRealWidth ); |
|
709 sqlQuery1->Des().Format( query1,&KCacheTable,&KDataTypeCol,ECatagory ); |
|
710 |
|
711 RDbView cacheTableView; |
|
712 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery1 ) ); |
|
713 CleanupStack::PopAndDestroy( sqlQuery1 ); |
|
714 CleanupClosePushL( cacheTableView ); |
|
715 |
|
716 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
717 |
|
718 //prepare insertion values |
|
719 //will go into last accessed aswell as the creation time fields |
|
720 TTime currentTime; |
|
721 currentTime.UniversalTime(); |
|
722 TInt countItems=aPtrCategory.Count(); |
|
723 TInt maxAge; |
|
724 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
725 { |
|
726 maxAge=iTrustPeriod.Int(); |
|
727 } |
|
728 else |
|
729 { |
|
730 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
731 conv.Val( maxAge ); |
|
732 maxAge = maxAge * KDefaultInterval; |
|
733 } |
|
734 CDbColSet* columns = cacheTableView.ColSetL(); |
|
735 CleanupStack::PushL( columns ); |
|
736 //write stream |
|
737 RDbColWriteStream writeStream; |
|
738 //start insertion into the view |
|
739 //insert a new row |
|
740 cacheTableView.InsertL(); |
|
741 //set values |
|
742 cacheTableView.SetColL( columns->ColNo( KDataTypeCol ), ECatagory ); |
|
743 cacheTableView.SetColL( columns->ColNo( KDataIdCol ), aName ); |
|
744 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
745 cacheTableView.SetColL( columns->ColNo( KItemCount ), countItems ); |
|
746 //to be set only if available |
|
747 cacheTableView.SetColL( columns->ColNo( KLastModifiedCol ), |
|
748 aResponseHeaders.iLastModified ); |
|
749 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
750 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
751 //open stream |
|
752 writeStream.OpenLC( cacheTableView,columns->ColNo( KCachedDataCol ) ); |
|
753 for ( TInt iter = 0; iter < countItems; iter++ ) |
|
754 { |
|
755 aPtrCategory[iter]->ExternalizeL( writeStream ); |
|
756 } |
|
757 writeStream.CommitL(); |
|
758 CleanupStack::PopAndDestroy( &writeStream ); |
|
759 cacheTableView.PutL(); |
|
760 CleanupStack::PopAndDestroy( columns ); |
|
761 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
762 CloseDb(); |
|
763 IRLOG_DEBUG( "IRCacheMgmt::CacheCategoryItemsL - Exiting." ); |
|
764 |
|
765 } |
|
766 |
|
767 // --------------------------------------------------------------------------- |
|
768 // Function : CIRCacheMgmt::CacheChannelItemsL() |
|
769 // Caches the channel objects array of data.By externalizing it into a file.. |
|
770 // --------------------------------------------------------------------------- |
|
771 // |
|
772 |
|
773 EXPORT_C void CIRCacheMgmt::CacheChannelItemsL( |
|
774 CArrayPtrFlat<CIRBrowseChannelItems>& aPtrChannel, |
|
775 const TDesC& aName,const CIRHttpResponseData& aResponseHeaders ) |
|
776 { |
|
777 //Algo**** |
|
778 //1.check if similar request is cached |
|
779 //2.delete if similar request is already present |
|
780 //3.prepare a view for insertion |
|
781 //4.push in the cached data request as serialized data |
|
782 IRLOG_DEBUG( "CIRCacheMgmt::CacheChannelItemsL - Entering" ); |
|
783 |
|
784 TInt error = OpenCacheDb(); |
|
785 if ( KErrNone != error ) |
|
786 { |
|
787 //no problems if this function returns here. |
|
788 //normal flow won't get affected. |
|
789 //only a particular request wont get cached |
|
790 return; |
|
791 } |
|
792 |
|
793 //convert the id information of descriptor to int value for comparision |
|
794 //clear data from the cache table before updating it with fresh data |
|
795 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
796 _LIT( query,"DELETE FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
797 HBufC* sqlQuery = HBufC::NewLC( query().Length() + KDataTypeCol().Length() + |
|
798 KCacheTable().Length() + KDataIdCol().Length() + |
|
799 KDefaultRealWidth + aName.Length() ); |
|
800 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
801 EChannels,&KDataIdCol,&aName ); |
|
802 iCacheDb.Begin(); |
|
803 //deletes a similar record if it existed. |
|
804 //no problem if it did not exist |
|
805 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
806 CleanupStack::PopAndDestroy( sqlQuery ); |
|
807 iCacheDb.Commit(); |
|
808 |
|
809 //get the cached data view for preset column to update with fresh data. |
|
810 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
811 _LIT( query1,"SELECT * FROM %S WHERE %S = %d" ); |
|
812 HBufC* sqlQuery1 = HBufC::NewLC( query1().Length() + |
|
813 KDataTypeCol().Length() + |
|
814 KCacheTable().Length() + KDefaultRealWidth ); |
|
815 RDbView cacheTableView; |
|
816 sqlQuery1->Des().Format( query1,&KCacheTable,&KDataTypeCol,EChannels ); |
|
817 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery1 ) ); |
|
818 CleanupStack::PopAndDestroy( sqlQuery1 ); |
|
819 CleanupClosePushL( cacheTableView ); |
|
820 |
|
821 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
822 |
|
823 //prepare insertion values |
|
824 //will go into last accessed aswell as the creation time fields |
|
825 TTime currentTime; |
|
826 currentTime.UniversalTime(); |
|
827 TInt countItems=aPtrChannel.Count(); |
|
828 TInt maxAge; |
|
829 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
830 { |
|
831 maxAge=iTrustPeriod.Int(); |
|
832 } |
|
833 else |
|
834 { |
|
835 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
836 conv.Val( maxAge ); |
|
837 maxAge = maxAge * KDefaultInterval; |
|
838 } |
|
839 TBuf<KHttpDateLength>lastModified; |
|
840 |
|
841 CDbColSet* columns = cacheTableView.ColSetL(); |
|
842 CleanupStack::PushL( columns ); |
|
843 //write stream |
|
844 RDbColWriteStream writeStream; |
|
845 |
|
846 //start insertion into the view |
|
847 //insert a new row |
|
848 cacheTableView.InsertL(); |
|
849 //set values |
|
850 cacheTableView.SetColL( columns->ColNo( KDataTypeCol ), EChannels ); |
|
851 cacheTableView.SetColL( columns->ColNo( KDataIdCol ), aName ); |
|
852 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
853 cacheTableView.SetColL( columns->ColNo( KItemCount ), countItems ); |
|
854 //to be set only if available |
|
855 cacheTableView.SetColL( columns->ColNo( KLastModifiedCol ), |
|
856 aResponseHeaders.iLastModified ); |
|
857 // |
|
858 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
859 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
860 //open stream |
|
861 writeStream.OpenLC( cacheTableView,columns->ColNo( KCachedDataCol ) ); |
|
862 for ( TInt iter = 0; iter < countItems; iter++ ) |
|
863 { |
|
864 aPtrChannel[iter]->ExternalizeL( writeStream ); |
|
865 } |
|
866 writeStream.CommitL(); |
|
867 CleanupStack::PopAndDestroy( &writeStream ); |
|
868 cacheTableView.PutL(); |
|
869 CleanupStack::PopAndDestroy( columns ); |
|
870 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
871 CloseDb(); |
|
872 IRLOG_DEBUG( "CIRCacheMgmt::CacheChannelItemsL - Exiting." ); |
|
873 |
|
874 } |
|
875 |
|
876 // --------------------------------------------------------------------------- |
|
877 // Function : CIRCacheMgmt::CachePresetItemL() |
|
878 // Caches the preset object .By externalizing it into a file. |
|
879 //multiple presets can be cached at one time |
|
880 // --------------------------------------------------------------------------- |
|
881 // |
|
882 |
|
883 EXPORT_C void CIRCacheMgmt::CachePresetItemL( |
|
884 CArrayPtrFlat<CIRIsdsPreset>& aPtrPresets, |
|
885 const TDesC& aName,const CIRHttpResponseData& aResponseHeaders ) |
|
886 { |
|
887 //Algo**** |
|
888 //1.check if similar request is cached |
|
889 //2.delete if similar request is already present |
|
890 //3.prepare a view for insertion |
|
891 //4.push in the cached data request as serialized data |
|
892 IRLOG_DEBUG( "CIRCacheMgmt::CachePresetItemL - Entering" ); |
|
893 |
|
894 TInt error = OpenCacheDb(); |
|
895 if ( KErrNone != error ) |
|
896 { |
|
897 //no problems if this function returns here. |
|
898 //normal flow won't get affected. |
|
899 //only a particular request wont get cached |
|
900 return; |
|
901 } |
|
902 //convert the id information of descriptor to int value for comparision |
|
903 //clear data from the cache table before updating it with fresh data |
|
904 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
905 _LIT( query,"DELETE FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
906 HBufC* sqlQuery = HBufC::NewLC( query().Length() + |
|
907 KDataTypeCol().Length() + |
|
908 KCacheTable().Length() + KDataIdCol().Length() + |
|
909 KDefaultRealWidth + aName.Length() ); |
|
910 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
911 EPresets,&KDataIdCol,&aName ); |
|
912 iCacheDb.Begin(); |
|
913 //deletes a similar record if it existed. |
|
914 //no problem if it did not exist |
|
915 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
916 CleanupStack::PopAndDestroy( sqlQuery ); |
|
917 iCacheDb.Commit(); |
|
918 |
|
919 //get the cached data view for preset column to update with fresh data. |
|
920 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
921 _LIT( query1,"SELECT * FROM %S WHERE %S = %d" ); |
|
922 HBufC* sqlQuery1 = HBufC::NewLC( query1().Length() + |
|
923 KDataTypeCol().Length() + |
|
924 KCacheTable().Length() + KDefaultRealWidth ); |
|
925 sqlQuery1->Des().Format( query1,&KCacheTable,&KDataTypeCol,EPresets ); |
|
926 RDbView cacheTableView; |
|
927 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery1 ) ); |
|
928 CleanupStack::PopAndDestroy( sqlQuery1 ); |
|
929 CleanupClosePushL( cacheTableView ); |
|
930 |
|
931 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
932 |
|
933 //prepare insertion values |
|
934 //will go into last accessed aswell as the creation time fields |
|
935 TTime currentTime; |
|
936 currentTime.UniversalTime(); |
|
937 |
|
938 TInt maxAge; |
|
939 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
940 { |
|
941 maxAge=iTrustPeriod.Int(); |
|
942 } |
|
943 else |
|
944 { |
|
945 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
946 conv.Val( maxAge ); |
|
947 maxAge = maxAge * KDefaultInterval; |
|
948 } |
|
949 TBuf<KHttpDateLength>lastModified; |
|
950 //default time set to 24hrs |
|
951 //use iTrustPeriod |
|
952 //type set to EPresets |
|
953 //id set to dataId |
|
954 //last modified time kept null |
|
955 //item count set to 1 |
|
956 CDbColSet* columns = cacheTableView.ColSetL(); |
|
957 CleanupStack::PushL( columns ); |
|
958 //write stream |
|
959 RDbColWriteStream writeStream; |
|
960 TInt countItems; |
|
961 countItems = aPtrPresets.Count(); |
|
962 //start insertion into the view |
|
963 //insert a new row |
|
964 cacheTableView.InsertL(); |
|
965 //set values |
|
966 cacheTableView.SetColL( columns->ColNo( KDataTypeCol ), EPresets ); |
|
967 cacheTableView.SetColL( columns->ColNo( KDataIdCol ), aName ); |
|
968 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
969 cacheTableView.SetColL( columns->ColNo( KItemCount ), countItems ); |
|
970 //to be set only if available |
|
971 cacheTableView.SetColL( columns->ColNo( KLastModifiedCol ), |
|
972 aResponseHeaders.iLastModified ); |
|
973 // |
|
974 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
975 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
976 //open stream |
|
977 writeStream.OpenLC( cacheTableView,columns->ColNo( KCachedDataCol ) ); |
|
978 for ( TInt iter = 0; iter < countItems; iter++ ) |
|
979 { |
|
980 aPtrPresets[iter]->ExternalizeL( writeStream ); |
|
981 } |
|
982 writeStream.CommitL(); |
|
983 CleanupStack::PopAndDestroy( &writeStream ); |
|
984 cacheTableView.PutL(); |
|
985 |
|
986 CleanupStack::PopAndDestroy( columns ); |
|
987 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
988 CloseDb(); |
|
989 IRLOG_DEBUG( "CIRCacheMgmt::CachePresetItemL - Exiting." ); |
|
990 } |
|
991 // --------------------------------------------------------------------------- |
|
992 // Function : CIRCacheMgmt::CacheOtaInfoL() |
|
993 // Caches the OTA information .By externalizing it into a db. |
|
994 // --------------------------------------------------------------------------- |
|
995 // |
|
996 |
|
997 EXPORT_C void CIRCacheMgmt::CacheOtaInfoL( const CIROTAUpdate& aOta, |
|
998 const TDesC& aName, |
|
999 const CIRHttpResponseData& aResponseHeaders ) |
|
1000 { |
|
1001 //Algo**** |
|
1002 //1.check if similar request is cached |
|
1003 //2.delete if similar request is already present |
|
1004 //3.prepare a view for insertion |
|
1005 //4.push in the cached data request as serialized data |
|
1006 IRLOG_DEBUG( "CIRCacheMgmt::CacheOtaInfoL - Entering" ); |
|
1007 |
|
1008 TInt error = OpenCacheDb(); |
|
1009 if ( KErrNone != error ) |
|
1010 { |
|
1011 //no problems if this function returns here. |
|
1012 //normal flow won't get affected. |
|
1013 //only a particular request wont get cached |
|
1014 return; |
|
1015 } |
|
1016 //convert the id information of descriptor to int value for comparision |
|
1017 //clear data from the cache table before updating it with fresh data |
|
1018 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
1019 _LIT( query,"DELETE FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
1020 HBufC* sqlQuery = HBufC::NewLC( query().Length() + |
|
1021 KDataTypeCol().Length() + |
|
1022 KCacheTable().Length() + KDataIdCol().Length() + |
|
1023 KDefaultRealWidth + aName.Length() ); |
|
1024 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
1025 EOtaInfo,&KDataIdCol,&aName ); |
|
1026 |
|
1027 User::LeaveIfError( iCacheDb.Begin() ); |
|
1028 //deletes a similar record if it existed. |
|
1029 //no problem if it did not exist |
|
1030 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
1031 CleanupStack::PopAndDestroy( sqlQuery ); |
|
1032 iCacheDb.Commit(); |
|
1033 |
|
1034 //get the cached data view for preset column to update with fresh data. |
|
1035 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
1036 _LIT( query1,"SELECT * FROM %S WHERE %S = %d" ); |
|
1037 HBufC* sqlQuery1 = HBufC::NewLC( query1().Length() + |
|
1038 KDataTypeCol().Length() + |
|
1039 KCacheTable().Length() + KDefaultRealWidth ); |
|
1040 |
|
1041 sqlQuery1->Des().Format( query1,&KCacheTable,&KDataTypeCol,EOtaInfo ); |
|
1042 RDbView cacheTableView; |
|
1043 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery1 ) ); |
|
1044 CleanupStack::PopAndDestroy( sqlQuery1 ); |
|
1045 CleanupClosePushL( cacheTableView ); |
|
1046 |
|
1047 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
1048 |
|
1049 //prepare insertion values |
|
1050 //will go into last accessed aswell as the creation time fields |
|
1051 TTime currentTime; |
|
1052 currentTime.UniversalTime(); |
|
1053 |
|
1054 TInt maxAge; |
|
1055 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
1056 { |
|
1057 maxAge=iTrustPeriod.Int(); |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
1062 conv.Val( maxAge ); |
|
1063 maxAge = maxAge * KDefaultInterval; |
|
1064 } |
|
1065 TBuf<KHttpDateLength>lastModified; |
|
1066 //default time set to 24hrs |
|
1067 //use iTrustPeriod |
|
1068 //type set to EPresets |
|
1069 //id set to dataId |
|
1070 //last modified time kept null |
|
1071 //item count set to 1 |
|
1072 CDbColSet* columns = cacheTableView.ColSetL(); |
|
1073 CleanupStack::PushL( columns ); |
|
1074 //write stream |
|
1075 RDbColWriteStream writeStream; |
|
1076 //start insertion into the view |
|
1077 //insert a new row |
|
1078 cacheTableView.InsertL(); |
|
1079 //set values |
|
1080 cacheTableView.SetColL( columns->ColNo( KDataTypeCol ), EOtaInfo ); |
|
1081 cacheTableView.SetColL( columns->ColNo( KDataIdCol ), aName ); |
|
1082 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
1083 cacheTableView.SetColL( columns->ColNo( KItemCount ), 1 ); |
|
1084 //to be set only if available |
|
1085 cacheTableView.SetColL( columns->ColNo( KLastModifiedCol ), |
|
1086 aResponseHeaders.iLastModified ); |
|
1087 // |
|
1088 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
1089 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
1090 //open stream |
|
1091 writeStream.OpenLC( cacheTableView,columns->ColNo( KCachedDataCol ) ); |
|
1092 aOta.ExternalizeL( writeStream ); |
|
1093 writeStream.CommitL(); |
|
1094 CleanupStack::PopAndDestroy( &writeStream ); |
|
1095 cacheTableView.PutL(); |
|
1096 |
|
1097 CleanupStack::PopAndDestroy( columns ); |
|
1098 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
1099 CloseDb(); |
|
1100 IRLOG_DEBUG( "CIRCacheMgmt::CacheOtaInfoL - Exiting." ); |
|
1101 } |
|
1102 |
|
1103 // --------------------------------------------------------------------------- |
|
1104 // Function : CIRCacheMgmt::CacheLogoL() |
|
1105 // Caches the logo data .By externalizing it into a db. |
|
1106 // --------------------------------------------------------------------------- |
|
1107 // |
|
1108 EXPORT_C void CIRCacheMgmt::CacheLogoL( const TDesC8& aData, const TDesC& aUrl, |
|
1109 const CIRHttpResponseData& aResponseHeaders ) |
|
1110 { |
|
1111 //Algo**** |
|
1112 //1.check if similar request is cached |
|
1113 //2.delete if similar request is already present |
|
1114 //3.prepare a view for insertion |
|
1115 //4.push in the cached data request as serialized data |
|
1116 IRLOG_DEBUG( "CIRCacheMgmt::CacheLogoL - Entering" ); |
|
1117 |
|
1118 |
|
1119 TInt error = OpenCacheDb(); |
|
1120 if ( KErrNone != error ) |
|
1121 { |
|
1122 //no problems if this function returns here. |
|
1123 //normal flow won't get affected. |
|
1124 //only a particular request wont get cached |
|
1125 return; |
|
1126 } |
|
1127 //convert the id information of descriptor to int value for comparision |
|
1128 //clear data from the cache table before updating it with fresh data |
|
1129 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
1130 _LIT( query,"DELETE FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
1131 HBufC* sqlQuery = HBufC::NewLC( query().Length() + KDataTypeCol().Length() + |
|
1132 KCacheTable().Length() + KDataIdCol().Length() + |
|
1133 KDefaultRealWidth + aUrl.Length() ); |
|
1134 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
1135 ELogo,&KDataIdCol,&aUrl ); |
|
1136 iCacheDb.Begin(); |
|
1137 //deletes a similar record if it existed. |
|
1138 //no problem if it did not exist |
|
1139 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
1140 CleanupStack::PopAndDestroy( sqlQuery ); |
|
1141 iCacheDb.Commit(); |
|
1142 |
|
1143 //get the cached data view for preset column to update with fresh data. |
|
1144 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
1145 _LIT( query1,"SELECT * FROM %S WHERE %S = %d" ); |
|
1146 HBufC* sqlQuery1 = HBufC::NewLC( query1().Length() + KDataTypeCol().Length() + |
|
1147 KCacheTable().Length() + KDefaultRealWidth ); |
|
1148 sqlQuery1->Des().Format( query1,&KCacheTable,&KDataTypeCol,ELogo ); |
|
1149 RDbView cacheTableView; |
|
1150 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery1 ) ); |
|
1151 CleanupStack::PopAndDestroy( sqlQuery1 ); |
|
1152 CleanupClosePushL( cacheTableView ); |
|
1153 |
|
1154 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
1155 |
|
1156 //prepare insertion values |
|
1157 //will go into last accessed aswell as the creation time fields |
|
1158 TTime currentTime; |
|
1159 currentTime.UniversalTime(); |
|
1160 |
|
1161 TInt maxAge; |
|
1162 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
1163 { |
|
1164 maxAge=iTrustPeriod.Int(); |
|
1165 } |
|
1166 else |
|
1167 { |
|
1168 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
1169 conv.Val( maxAge ); |
|
1170 maxAge = maxAge * KDefaultInterval; |
|
1171 } |
|
1172 TBuf<KHttpDateLength>lastModified; |
|
1173 //default time set to 24hrs |
|
1174 //use iTrustPeriod |
|
1175 //type set to ELogo |
|
1176 //id set to dataId |
|
1177 //last modified time kept null |
|
1178 //item count set to 1 |
|
1179 CDbColSet* columns = cacheTableView.ColSetL(); |
|
1180 CleanupStack::PushL( columns ); |
|
1181 //write stream |
|
1182 //start insertion into the view |
|
1183 //insert a new row |
|
1184 cacheTableView.InsertL(); |
|
1185 //set values |
|
1186 cacheTableView.SetColL( columns->ColNo( KDataTypeCol ), ELogo ); |
|
1187 cacheTableView.SetColL( columns->ColNo( KDataIdCol ), aUrl ); |
|
1188 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
1189 cacheTableView.SetColL( columns->ColNo( KItemCount ), 1 ); |
|
1190 //to be set only if available |
|
1191 cacheTableView.SetColL( columns->ColNo( KLastModifiedCol ), |
|
1192 aResponseHeaders.iLastModified ); |
|
1193 // |
|
1194 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
1195 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
1196 cacheTableView.SetColL( columns->ColNo( KCachedDataCol ), aData ); |
|
1197 |
|
1198 cacheTableView.SetColL( columns->ColNo( KETagHeader ), |
|
1199 aResponseHeaders.iETag ); |
|
1200 |
|
1201 cacheTableView.PutL(); |
|
1202 |
|
1203 |
|
1204 CleanupStack::PopAndDestroy( columns ); |
|
1205 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
1206 CloseDb(); |
|
1207 IRLOG_DEBUG( "CIRCacheMgmt::CacheLogoL - Exiting." ); |
|
1208 |
|
1209 } |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 // --------------------------------------------------------------------------- |
|
1215 // Function : CIRCacheMgmt::CreateCacheTableL() |
|
1216 // creates the cache table |
|
1217 // --------------------------------------------------------------------------- |
|
1218 // |
|
1219 //CacheTable |
|
1220 // ----------------------------------------------------------------------------------------------------- |
|
1221 //| RowIndex|DataType|DataId|TrustPeriod|LastModified |LastAccessed|Created|ItemCount|CachedData| |
|
1222 //------------------------------------------------------------------------------------------------ |
|
1223 //| auto |TInt |DesC |TInt |TDesC/DateTime|TTime |Time |TInt | Streamed | |
|
1224 //|increment|0,1,2,NotNull|NotNull| NotNull | | | | | Data | |
|
1225 //------------------------------------------------------------------------------------------------------ |
|
1226 void CIRCacheMgmt::CreateCacheTableL() |
|
1227 { |
|
1228 IRLOG_DEBUG( "IRCacheMgmt::CreateCacheTableL - Entering." ); |
|
1229 //the row index column which autoincrements |
|
1230 TDbCol rowIndexCol( KRowIndexCol, EDbColInt32 ); |
|
1231 rowIndexCol.iAttributes = TDbCol::EAutoIncrement; |
|
1232 |
|
1233 //the datatype column,to identify between ECatagory = 0,EChannels=1,EPresets=2 |
|
1234 TDbCol dataTypeCol( KDataTypeCol, EDbColInt32 ); |
|
1235 dataTypeCol.iAttributes = TDbCol::ENotNull; |
|
1236 |
|
1237 //the dataID column,to uniquely identify the cached data |
|
1238 TDbCol dataId( KDataIdCol, EDbColLongText16 ); |
|
1239 dataId.iAttributes = TDbCol::ENotNull; |
|
1240 |
|
1241 //the trust period column to calculate cache validity |
|
1242 TDbCol trustPeriodCol( KTrustPeriodCol, EDbColInt32 ); |
|
1243 |
|
1244 //the lastmodified column to fetch data conditionally |
|
1245 TDbCol lastModifiedCol( KLastModifiedCol, EDbColDateTime ); |
|
1246 |
|
1247 |
|
1248 //the last accessed column used for table clean-up |
|
1249 TDbCol creationTimeCol( KTimeCreation, EDbColDateTime ); |
|
1250 |
|
1251 //the time of creation saved to calculate the cache validity |
|
1252 TDbCol lastAccessedCol( KLastAccessedCol, EDbColDateTime ); |
|
1253 |
|
1254 //the number of items in the data field |
|
1255 TDbCol itemCountCol( KItemCount, EDbColInt32 ); |
|
1256 |
|
1257 //the data column to store cached data |
|
1258 //The column stores a potentially large amount of Unicode text data. |
|
1259 TDbCol cachedDataCol( KCachedDataCol, EDbColLongText8 ); |
|
1260 |
|
1261 //the ETag header received along with the logo data |
|
1262 TDbCol etagHeader( KETagHeader, EDbColText8 ); |
|
1263 |
|
1264 //colset |
|
1265 CDbColSet* cacheTablerColSet = CDbColSet::NewLC(); |
|
1266 //populate colset |
|
1267 cacheTablerColSet->AddL( rowIndexCol ); |
|
1268 cacheTablerColSet->AddL( dataTypeCol ); |
|
1269 cacheTablerColSet->AddL( dataId ); |
|
1270 cacheTablerColSet->AddL( trustPeriodCol ); |
|
1271 cacheTablerColSet->AddL( lastModifiedCol ); |
|
1272 cacheTablerColSet->AddL( creationTimeCol ); |
|
1273 cacheTablerColSet->AddL( lastAccessedCol ); |
|
1274 cacheTablerColSet->AddL( itemCountCol ); |
|
1275 cacheTablerColSet->AddL( cachedDataCol ); |
|
1276 cacheTablerColSet->AddL( etagHeader ); |
|
1277 |
|
1278 // Create the CacheTable table |
|
1279 User::LeaveIfError( iCacheDb.CreateTable( KCacheTable, *cacheTablerColSet ) ); |
|
1280 |
|
1281 CleanupStack::PopAndDestroy( cacheTablerColSet ); |
|
1282 IRLOG_DEBUG( "IRCacheMgmt::CreateCacheTableL - Exiting." ); |
|
1283 } |
|
1284 |
|
1285 // --------------------------------------------------------------------------- |
|
1286 // Function : CIRCacheMgmt::CreateCacheIndexL() |
|
1287 // creates the indices for cache table |
|
1288 // --------------------------------------------------------------------------- |
|
1289 // |
|
1290 void CIRCacheMgmt::CreateCacheIndexL() |
|
1291 { |
|
1292 IRLOG_DEBUG( "IRCacheMgmt::CreateCacheIndexL - Entering." ); |
|
1293 TDbKeyCol rowIndexCol( KRowIndexCol ); |
|
1294 TDbKeyCol dataTypeCol( KDataTypeCol ); |
|
1295 TDbKeyCol dataIdCol( KDataIdCol,KDataIdIndexSize ); |
|
1296 TDbKeyCol timeCreationCol( KTimeCreation ); |
|
1297 TDbKeyCol lastAccessedCol( KLastAccessedCol ); |
|
1298 |
|
1299 CDbKey* index; |
|
1300 //index on the auto increment row id |
|
1301 index = CDbKey::NewLC(); |
|
1302 index->AddL( rowIndexCol ); |
|
1303 User::LeaveIfError( iCacheDb.CreateIndex( KRowIndexColIndex, KCacheTable, |
|
1304 *index ) ); |
|
1305 CleanupStack::PopAndDestroy( index ); |
|
1306 |
|
1307 //index on the datatype column |
|
1308 index = CDbKey::NewLC(); |
|
1309 index->AddL( dataTypeCol ); |
|
1310 User::LeaveIfError( iCacheDb.CreateIndex( KDataTypeColIndex, KCacheTable, |
|
1311 *index ) ); |
|
1312 CleanupStack::PopAndDestroy( index ); |
|
1313 |
|
1314 //index on the data id column |
|
1315 index = CDbKey::NewLC(); |
|
1316 index->AddL( dataIdCol ); |
|
1317 User::LeaveIfError( iCacheDb.CreateIndex( KDataIdColIndex, KCacheTable, |
|
1318 *index ) ); |
|
1319 CleanupStack::PopAndDestroy( index ); |
|
1320 |
|
1321 //index on the time of record creation column |
|
1322 index = CDbKey::NewLC(); |
|
1323 index->AddL( timeCreationCol ); |
|
1324 User::LeaveIfError( iCacheDb.CreateIndex( KTimeCreationIndex, KCacheTable, |
|
1325 *index ) ); |
|
1326 CleanupStack::PopAndDestroy( index ); |
|
1327 |
|
1328 //index on the last accessed column |
|
1329 index = CDbKey::NewLC(); |
|
1330 index->AddL( lastAccessedCol ); |
|
1331 User::LeaveIfError( iCacheDb.CreateIndex( KLastAccessedColIndex, KCacheTable, |
|
1332 *index ) ); |
|
1333 CleanupStack::PopAndDestroy( index ); |
|
1334 IRLOG_DEBUG( "IRCacheMgmt::CreateCacheIndexL - Exiting." ); |
|
1335 } |
|
1336 // --------------------------------------------------------------------------- |
|
1337 //void CIRCacheMgmt::UpdateTrustPeriod() |
|
1338 //updates the trust period for a not-modified responce |
|
1339 // --------------------------------------------------------------------------- |
|
1340 |
|
1341 // |
|
1342 EXPORT_C void CIRCacheMgmt::UpdateTrustPeriodL( TInt aType, const TDesC& aName, |
|
1343 CIRHttpResponseData& aResponseHeaders ) |
|
1344 { |
|
1345 IRLOG_DEBUG( "IRCacheMgmt::UpdateTrustPeriodL - Entering" ); |
|
1346 TInt error = OpenCacheDb(); |
|
1347 if ( KErrNone != error ) |
|
1348 { |
|
1349 IRLOG_ERROR2( "IRCacheMgmt::UpdateTrustPeriodL - \ |
|
1350 Error while opening cache DB (%d).", error ); |
|
1351 //no problems if this function returns here. |
|
1352 //normal flow won't get affected. |
|
1353 //only a particular request wont get cached |
|
1354 return; |
|
1355 } |
|
1356 |
|
1357 //SELECT * FROM KCacheTable WHERE KDataTypeCol = TYPE AND KDataIdCol = DATAID |
|
1358 _LIT( query,"SELECT * FROM %S WHERE %S = %d AND %S = '%S'" ); |
|
1359 HBufC* sqlQuery = HBufC::NewLC( query().Length() + KCacheTable().Length() + |
|
1360 KDataIdCol().Length() + KDataTypeCol().Length() + aName.Length()+ |
|
1361 KDefaultRealWidth ); |
|
1362 |
|
1363 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol, |
|
1364 aType,&KDataIdCol,&aName ); |
|
1365 |
|
1366 //create view |
|
1367 RDbView cacheTableView; |
|
1368 User::LeaveIfError( cacheTableView.Prepare( iCacheDb,*sqlQuery ) ); |
|
1369 CleanupStack::PopAndDestroy( sqlQuery ); |
|
1370 CleanupClosePushL( cacheTableView ); |
|
1371 |
|
1372 User::LeaveIfError( cacheTableView.EvaluateAll() ); |
|
1373 |
|
1374 //prepare the update data |
|
1375 //will go into last accessed aswell as the creation time fields |
|
1376 TTime currentTime; |
|
1377 currentTime.UniversalTime(); |
|
1378 //get the new trust period from the headers |
|
1379 TInt maxAge; |
|
1380 if ( aResponseHeaders.iMaxAge.Length() == 0 ) |
|
1381 { |
|
1382 maxAge=iTrustPeriod.Int(); |
|
1383 } |
|
1384 else |
|
1385 { |
|
1386 TLex8 conv( aResponseHeaders.iMaxAge ); |
|
1387 conv.Val( maxAge ); |
|
1388 maxAge = maxAge * KDefaultInterval; |
|
1389 } |
|
1390 CDbColSet* columns = cacheTableView.ColSetL(); |
|
1391 CleanupStack::PushL( columns ); |
|
1392 cacheTableView.FirstL(); |
|
1393 if ( cacheTableView.AtRow() ) |
|
1394 { |
|
1395 cacheTableView.UpdateL(); |
|
1396 //update values |
|
1397 cacheTableView.SetColL( columns->ColNo( KTrustPeriodCol ), maxAge ); |
|
1398 cacheTableView.SetColL( columns->ColNo( KLastAccessedCol ), currentTime ); |
|
1399 cacheTableView.SetColL( columns->ColNo( KTimeCreation ), currentTime ); |
|
1400 cacheTableView.PutL(); |
|
1401 } |
|
1402 |
|
1403 CleanupStack::PopAndDestroy( columns ); |
|
1404 CleanupStack::PopAndDestroy( &cacheTableView ); |
|
1405 CloseDb(); |
|
1406 IRLOG_DEBUG( "IRCacheMgmt::UpdateTrustPeriod - Exiting." ); |
|
1407 } |
|
1408 |
|
1409 // --------------------------------------------------------------------------- |
|
1410 // Used to dcontrol the cache table size by compacting and clearing up unused items |
|
1411 // --------------------------------------------------------------------------- |
|
1412 // |
|
1413 void CIRCacheMgmt::CheckSizeL() |
|
1414 { |
|
1415 IRLOG_DEBUG( "IRCacheMgmt::CheckSizeL - Entering." ); |
|
1416 OpenCacheDb(); |
|
1417 RDbDatabase::TSize dbSize = iCacheDb.Size(); |
|
1418 iCacheDbSize = dbSize.iSize; |
|
1419 TInt size = CacheSize(); |
|
1420 if ( size >= KCacheCriticalSizeLimit ) |
|
1421 { |
|
1422 RemoveOldUnusedDataL(); |
|
1423 OpenCacheDb(); |
|
1424 iCacheDb.Compact(); |
|
1425 //refresh the size information |
|
1426 dbSize = iCacheDb.Size(); |
|
1427 iCacheDbSize = dbSize.iSize; |
|
1428 } |
|
1429 CloseDb(); |
|
1430 IRLOG_DEBUG( "IRCacheMgmt::CheckSizeL - Exiting." ); |
|
1431 } |
|
1432 |
|
1433 // --------------------------------------------------------------------------- |
|
1434 // Used to control the cache table size by compacting and clearing up unused items |
|
1435 // --------------------------------------------------------------------------- |
|
1436 // |
|
1437 void CIRCacheMgmt::RemoveOldUnusedDataL() |
|
1438 { |
|
1439 IRLOG_DEBUG( "IRCacheMgmt::RemoveOldUnusedDataL - Entering." ); |
|
1440 OpenCacheDb(); |
|
1441 RDbTable cacheTable; |
|
1442 //open the table in updatable mode |
|
1443 User::LeaveIfError( cacheTable.Open( iCacheDb, KCacheTable, |
|
1444 cacheTable.EUpdatable ) ); |
|
1445 CleanupClosePushL( cacheTable ); |
|
1446 cacheTable.Reset(); |
|
1447 //set index as the last accessed time |
|
1448 cacheTable.SetIndex( KLastAccessedCol ); |
|
1449 //begin transaction |
|
1450 iCacheDb.Begin(); |
|
1451 // no of rows deleted is one fourth of the total number of rows |
|
1452 TInt deleteRows = cacheTable.CountL()/KPercentRowsDeleted; |
|
1453 TInt inc = 0; |
|
1454 //delete incrementally |
|
1455 for ( cacheTable.FirstL(); ( ( inc < deleteRows ) && cacheTable.AtRow() ); inc++ ) |
|
1456 { |
|
1457 cacheTable.GetL(); |
|
1458 cacheTable.DeleteL(); |
|
1459 cacheTable.NextL(); |
|
1460 } |
|
1461 //commit transaction |
|
1462 iCacheDb.Commit(); |
|
1463 CleanupStack::PopAndDestroy( &cacheTable ); |
|
1464 CloseDb(); |
|
1465 IRLOG_DEBUG( "IRCacheMgmt::RemoveOldUnusedDataL - Exiting." ); |
|
1466 } |
|
1467 |
|
1468 // --------------------------------------------------------------------------- |
|
1469 // Used to get the cache table size |
|
1470 // --------------------------------------------------------------------------- |
|
1471 // |
|
1472 TInt CIRCacheMgmt::CacheSize() |
|
1473 { |
|
1474 IRLOG_DEBUG( "IRCacheMgmt::CacheSize - Entering." ); |
|
1475 OpenCacheDb(); |
|
1476 RDbDatabase::TSize dbSize = iCacheDb.Size(); |
|
1477 iCacheDbSize = dbSize.iSize; |
|
1478 CloseDb(); |
|
1479 IRLOG_DEBUG( "IRCacheMgmt::CacheSize - Exiting." ); |
|
1480 return iCacheDbSize; |
|
1481 } |
|
1482 // --------------------------------------------------------------------------- |
|
1483 //remove OTA info from cache if data is not valid any longer |
|
1484 // --------------------------------------------------------------------------- |
|
1485 EXPORT_C void CIRCacheMgmt::RemoveOtaInfoL() |
|
1486 { |
|
1487 IRLOG_DEBUG( "IRCacheMgmt::RemoveOtaInfoL - Entering." ); |
|
1488 //check if the silence period param is set. |
|
1489 //if not set that means the cached ota info if present is not valid. |
|
1490 if ( iSettings->GetSilencePeriodL() == 0 ) |
|
1491 { |
|
1492 TInt error = OpenCacheDb(); |
|
1493 if ( KErrNone != error ) |
|
1494 { |
|
1495 //no problems if this function returns here. |
|
1496 //normal flow won't get affected. |
|
1497 //only a particular request wont get cached |
|
1498 return; |
|
1499 } |
|
1500 //clear data from the cache table |
|
1501 //DELETE FROM KCacheTable WHERE KDataTypeCol = TYPE |
|
1502 _LIT( query,"DELETE FROM %S WHERE %S = %d" ); |
|
1503 HBufC* sqlQuery = HBufC::NewLC( query().Length() + |
|
1504 KDataTypeCol().Length() + |
|
1505 KCacheTable().Length() + KDataIdCol().Length() ); |
|
1506 sqlQuery->Des().Format( query,&KCacheTable,&KDataTypeCol,EOtaInfo ); |
|
1507 User::LeaveIfError( iCacheDb.Begin() ); |
|
1508 //no problem if it did not exist |
|
1509 iCacheDb.Execute( *sqlQuery,EDbCompareNormal ); |
|
1510 CleanupStack::PopAndDestroy( sqlQuery ); |
|
1511 iCacheDb.Commit(); |
|
1512 CloseDb(); |
|
1513 } |
|
1514 IRLOG_DEBUG( "IRCacheMgmt::RemoveOtaInfoL - Exiting." ); |
|
1515 } |
|
1516 |
|
1517 |
|
1518 |
|
1519 // --------------------------------------------------------------------------- |
|
1520 // Adds a cache observer |
|
1521 // --------------------------------------------------------------------------- |
|
1522 // |
|
1523 EXPORT_C void CIRCacheMgmt::AddObserverL( MIRCacheObserver* aObserver ) |
|
1524 { |
|
1525 IRLOG_DEBUG( "IRCacheMgmt::AddObserverL - Entering." ); |
|
1526 iCacheObservers.AppendL( aObserver ); |
|
1527 IRLOG_DEBUG( "IRCacheMgmt::AddObserverL - Exiting." ); |
|
1528 } |
|
1529 |
|
1530 // --------------------------------------------------------------------------- |
|
1531 // Removes a cache observer |
|
1532 // --------------------------------------------------------------------------- |
|
1533 // |
|
1534 EXPORT_C void CIRCacheMgmt::RemoveObserver( MIRCacheObserver* aObserver ) |
|
1535 { |
|
1536 IRLOG_DEBUG( "IRCacheMgmt::RemoveObserver - Entering." ); |
|
1537 TInt objectIndex = iCacheObservers.Find( aObserver ); |
|
1538 |
|
1539 if ( objectIndex != KErrNotFound ) |
|
1540 { |
|
1541 iCacheObservers.Remove( objectIndex ); |
|
1542 } |
|
1543 IRLOG_DEBUG( "IRCacheMgmt::RemoveObserver - Exiting." ); |
|
1544 } |