188 // CThumbnailStore::CThumbnailStore() |
188 // CThumbnailStore::CThumbnailStore() |
189 // C++ default constructor can NOT contain any code, that might leave. |
189 // C++ default constructor can NOT contain any code, that might leave. |
190 // --------------------------------------------------------------------------- |
190 // --------------------------------------------------------------------------- |
191 // |
191 // |
192 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): |
192 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): |
193 iFs( aFs ), iDrive( aDrive ), iBatchItemCount(0), iImei(aImei), iServer(aServer), iDiskFull(EFalse) |
193 iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), |
|
194 iServer(aServer), iDiskFull(EFalse) |
194 { |
195 { |
195 // no implementation required |
196 // no implementation required |
196 } |
197 } |
197 |
198 |
198 |
199 |
206 TN_DEBUG1( "CThumbnailStore::ConstructL()" ); |
207 TN_DEBUG1( "CThumbnailStore::ConstructL()" ); |
207 |
208 |
208 #ifdef _DEBUG |
209 #ifdef _DEBUG |
209 iThumbCounter = 0; |
210 iThumbCounter = 0; |
210 #endif |
211 #endif |
|
212 |
|
213 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
|
214 TPtr pathPtr = databasePath->Des(); |
|
215 User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar )); |
|
216 pathPtr.Append( iDriveChar ); |
|
217 pathPtr.Append( KThumbnailDatabaseName ); |
|
218 |
|
219 //start disk space monitor |
|
220 iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, |
|
221 KDiskFullThreshold, |
|
222 pathPtr ); |
|
223 |
|
224 CleanupStack::PopAndDestroy( databasePath ); |
|
225 |
|
226 TN_DEBUG2( "CThumbnailStore::ConstructL() drive: %d", iDrive ); |
|
227 |
|
228 OpenDatabaseL(); |
|
229 |
|
230 // to monitor device activity |
|
231 iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle); |
|
232 iActivityManager->Start(); |
|
233 |
|
234 // once in every mount |
|
235 iDeleteThumbs = ETrue; |
|
236 iCheckFilesExist = ETrue; |
|
237 iLastCheckedRowID = -1; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // OpenDatabaseL database file |
|
242 // --------------------------------------------------------------------------- |
|
243 TInt CThumbnailStore::OpenDatabaseFileL() |
|
244 { |
|
245 TN_DEBUG1( "CThumbnailStore::OpenDatabaseFile()" ); |
211 |
246 |
212 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
247 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
213 TPtr pathPtr = databasePath->Des(); |
248 TPtr pathPtr = databasePath->Des(); |
214 TChar driveChar = 0; |
249 TChar driveChar = 0; |
215 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
250 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
216 pathPtr.Append( driveChar ); |
251 pathPtr.Append( driveChar ); |
217 pathPtr.Append( KThumbnailDatabaseName ); |
252 pathPtr.Append( KThumbnailDatabaseName ); |
218 |
253 |
219 //start disk space monitor |
|
220 iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, |
|
221 KDiskFullThreshold, |
|
222 pathPtr ); |
|
223 |
|
224 CleanupStack::PopAndDestroy( databasePath ); |
|
225 |
|
226 OpenDatabaseL(); |
|
227 |
|
228 // to monitor device activity |
|
229 iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle); |
|
230 iActivityManager->Start(); |
|
231 |
|
232 // once in every mount |
|
233 iDeleteThumbs = ETrue; |
|
234 iCheckFilesExist = ETrue; |
|
235 iLastCheckedRowID = -1; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // OpenDatabaseL database file |
|
240 // --------------------------------------------------------------------------- |
|
241 TInt CThumbnailStore::OpenDatabaseFileL() |
|
242 { |
|
243 TN_DEBUG1( "CThumbnailStore::OpenDatabaseFile()" ); |
|
244 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
|
245 TPtr pathPtr = databasePath->Des(); |
|
246 TChar driveChar = 0; |
|
247 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
|
248 pathPtr.Append( driveChar ); |
|
249 pathPtr.Append( KThumbnailDatabaseName ); |
|
250 |
|
251 TInt ret = iDatabase.Open( pathPtr ); |
254 TInt ret = iDatabase.Open( pathPtr ); |
252 CleanupStack::PopAndDestroy( databasePath ); |
255 CleanupStack::PopAndDestroy( databasePath ); |
253 return ret; |
256 return ret; |
254 } |
257 } |
255 |
258 |
256 // --------------------------------------------------------------------------- |
259 // --------------------------------------------------------------------------- |
257 // OpenDatabaseL database |
260 // OpenDatabaseL database |
258 // --------------------------------------------------------------------------- |
261 // --------------------------------------------------------------------------- |
259 TInt CThumbnailStore::OpenDatabaseL() |
262 TInt CThumbnailStore::OpenDatabaseL() |
260 { |
263 { |
261 TN_DEBUG1( "CThumbnailStore::OpenDatabaseL()" ); |
264 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() drive: %d", iDrive ); |
262 |
265 |
263 iDatabase.Close(); |
266 iDatabase.Close(); |
264 |
267 |
265 TBool newDatabase(EFalse); |
268 TBool newDatabase(EFalse); |
266 TInt error = KErrNone; |
269 TInt error = KErrNone; |
267 |
270 |
268 TInt err = OpenDatabaseFileL(); |
271 TInt err = OpenDatabaseFileL(); |
269 |
272 |
270 if ( err == KErrNotFound ) |
273 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() -- err = %d", err); |
271 { |
274 |
272 // db not found, create new |
275 if ( err == KErrNotFound ) |
273 RecreateDatabaseL( EFalse); |
276 { |
274 newDatabase = ETrue; |
277 // db not found, create new |
275 err = KErrNone; |
278 RecreateDatabaseL( EFalse); |
276 } |
279 newDatabase = ETrue; |
277 else if ( err == KErrNone) |
280 err = KErrNone; |
278 { |
281 } |
279 // db found, check version and rowids |
282 else if ( err == KErrNone) |
280 error = CheckVersionL(); |
283 { |
281 if(error == KErrNone) |
284 // db found, check version and rowids |
282 { |
285 error = CheckVersionL(); |
283 error = CheckRowIDsL(); |
286 if(error == KErrNone) |
284 } |
287 { |
285 } |
288 error = CheckRowIDsL(); |
|
289 } |
|
290 } |
286 |
291 |
287 TN_DEBUG3( "CThumbnailStore::ConstructL() -- error = %d, err = %d", error, err); |
292 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() -- error = %d", error); |
288 |
293 |
289 // if wrong version, corrupted database or other error opening db |
294 // if wrong version, corrupted database or other error opening db |
290 if ( error == KErrNotSupported || (err != KErrNone && err != KErrNotFound) ) |
295 if ( error == KErrNotSupported || (err != KErrNone && err != KErrNotFound) ) |
291 { |
296 { |
292 RecreateDatabaseL( ETrue); |
297 RecreateDatabaseL( ETrue); |
352 |
357 |
353 // add tables |
358 // add tables |
354 TRAPD(tableError, CreateTablesL() ); |
359 TRAPD(tableError, CreateTablesL() ); |
355 |
360 |
356 if(!tableError) |
361 if(!tableError) |
357 { |
362 { |
358 TRAPD(err, AddVersionAndImeiL()); |
363 TRAPD(err, AddVersionAndImeiL()); |
359 if (err == KSqlErrCorrupt) |
364 if (err == KSqlErrCorrupt) |
360 { |
365 { |
361 RecreateDatabaseL( ETrue); |
366 RecreateDatabaseL( ETrue); |
362 } |
367 } |
363 User::LeaveIfError(err); |
368 User::LeaveIfError(err); |
364 } |
369 } |
365 |
370 |
366 err = iDatabase.Exec( KThumbnailCreateTempInfoTable ); |
371 err = iDatabase.Exec( KThumbnailCreateTempInfoTable ); |
367 #ifdef _DEBUG |
372 |
368 if(err < 0) |
373 #ifdef _DEBUG |
369 { |
374 if(err < 0) |
370 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
375 { |
371 TN_DEBUG2( "CThumbnailStore::ConstructL() KThumbnailCreateTempInfoTable %S" , &errorMsg); |
376 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
372 } |
377 TN_DEBUG2( "CThumbnailStore::PrepareDbL() KThumbnailCreateTempInfoTable %S" , &errorMsg); |
|
378 } |
373 #endif |
379 #endif |
|
380 |
374 User::LeaveIfError( err ); |
381 User::LeaveIfError( err ); |
375 |
382 |
376 err = iDatabase.Exec( KThumbnailCreateTempInfoDataTable ); |
383 err = iDatabase.Exec( KThumbnailCreateTempInfoDataTable ); |
377 #ifdef _DEBUG |
384 |
378 if(err < 0) |
385 #ifdef _DEBUG |
379 { |
386 if(err < 0) |
380 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
387 { |
381 TN_DEBUG2( "CThumbnailStore::ConstructL() KThumbnailCreateTempInfoDataTable %S" , &errorMsg); |
388 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
382 } |
389 TN_DEBUG2( "CThumbnailStore::PrepareDbL() KThumbnailCreateTempInfoDataTable %S" , &errorMsg); |
|
390 } |
383 #endif |
391 #endif |
384 User::LeaveIfError( err ); |
392 |
|
393 User::LeaveIfError( err ); |
385 } |
394 } |
386 |
395 |
387 // --------------------------------------------------------------------------- |
396 // --------------------------------------------------------------------------- |
388 // Create database tables |
397 // Create database tables |
389 // --------------------------------------------------------------------------- |
398 // --------------------------------------------------------------------------- |
413 User::LeaveIfError( err ); |
422 User::LeaveIfError( err ); |
414 } |
423 } |
415 |
424 |
416 void CThumbnailStore::RecreateDatabaseL(const TBool aDelete) |
425 void CThumbnailStore::RecreateDatabaseL(const TBool aDelete) |
417 { |
426 { |
418 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL()" ); |
427 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() drive: %d", iDrive ); |
419 |
428 |
420 TVolumeInfo volumeinfo; |
429 TVolumeInfo volumeinfo; |
421 iFs.Volume(volumeinfo, iDrive); |
430 iFs.Volume(volumeinfo, iDrive); |
422 TUint id = volumeinfo.iUniqueID; |
431 TUint id = volumeinfo.iUniqueID; |
423 TBuf<50> mediaid; |
432 TBuf<50> mediaid; |
424 mediaid.Num(id); |
433 mediaid.Num(id); |
425 |
434 |
426 // delete db and create new |
435 // delete db and create new |
427 iDatabase.Close(); |
436 iDatabase.Close(); |
428 |
437 |
|
438 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() database closed" ); |
|
439 |
429 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
440 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
430 TPtr pathPtr = databasePath->Des(); |
441 TPtr pathPtr = databasePath->Des(); |
431 TChar driveChar = 0; |
442 User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar )); |
432 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
443 pathPtr.Append( iDriveChar ); |
433 pathPtr.Append( driveChar ); |
|
434 pathPtr.Append( KThumbnailDatabaseName ); |
444 pathPtr.Append( KThumbnailDatabaseName ); |
435 |
445 |
436 TInt err(KErrNone); |
446 TInt err(KErrNone); |
437 |
447 |
438 if(aDelete) |
448 if(aDelete) |
439 { |
449 { |
440 iDatabase.Delete(pathPtr); |
450 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() delete database" ); |
|
451 TInt del = iDatabase.Delete(pathPtr); |
|
452 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() deleted database, err: %d", del ); |
441 } |
453 } |
442 |
454 |
443 const TDesC8& config = KThumbnailSqlConfig; |
455 const TDesC8& config = KThumbnailSqlConfig; |
444 |
456 |
445 RSqlSecurityPolicy securityPolicy; |
457 RSqlSecurityPolicy securityPolicy; |
446 CleanupClosePushL( securityPolicy ); |
458 CleanupClosePushL( securityPolicy ); |
447 securityPolicy.Create( KThumbnailDatabaseSecurityPolicy ); |
459 securityPolicy.CreateL( KThumbnailDatabaseSecurityPolicy ); |
448 |
460 |
|
461 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() create new" ); |
|
462 |
449 TRAP(err, iDatabase.CreateL( pathPtr, securityPolicy, &config )); |
463 TRAP(err, iDatabase.CreateL( pathPtr, securityPolicy, &config )); |
|
464 |
|
465 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- database created err = %d", err ); |
|
466 |
450 CleanupStack::PopAndDestroy( &securityPolicy ); |
467 CleanupStack::PopAndDestroy( &securityPolicy ); |
451 |
468 CleanupStack::PopAndDestroy( databasePath ); |
452 |
|
453 #ifdef _DEBUG |
|
454 if(err < 0) |
|
455 { |
|
456 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
457 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg); |
|
458 } |
|
459 #endif |
|
460 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- database created err = %d", err ); |
|
461 User::LeaveIfError( err ); |
469 User::LeaveIfError( err ); |
462 CleanupStack::PopAndDestroy( databasePath ); |
|
463 |
470 |
464 RFile64 file; |
471 RFile64 file; |
465 file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
472 file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
466 file.Close(); |
473 file.Close(); |
467 |
474 |
1668 TInt CThumbnailStore::MaintenanceTimerCallBack(TAny* aAny) |
1691 TInt CThumbnailStore::MaintenanceTimerCallBack(TAny* aAny) |
1669 { |
1692 { |
1670 CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny ); |
1693 CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny ); |
1671 |
1694 |
1672 self->iMaintenanceTimer->Cancel(); |
1695 self->iMaintenanceTimer->Cancel(); |
|
1696 |
|
1697 TInt MPXHarvesting(0); |
|
1698 TInt DaemonProcessing(0); |
|
1699 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
|
1700 if(ret != KErrNone || MPXHarvesting) |
|
1701 { |
|
1702 TN_DEBUG3( "CThumbnailStore::MaintenanceTimerCallBack() KMPXHarvesting err == %d, MPXHarvesting == %d", ret, MPXHarvesting); |
|
1703 self->iIdle = EFalse; |
|
1704 } |
|
1705 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() KMPXHarvesting == %d", MPXHarvesting); |
|
1706 |
|
1707 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
|
1708 if(ret != KErrNone || DaemonProcessing) |
|
1709 { |
|
1710 TN_DEBUG3( "CThumbnailStore::MaintenanceTimerCallBack() KDaemonProcessing err == %d, DaemonProcessing == %d", ret, DaemonProcessing); |
|
1711 self->iIdle = EFalse; |
|
1712 } |
|
1713 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() DaemonProcessing == %d", DaemonProcessing); |
1673 |
1714 |
1674 if (self->iIdle) |
1715 if (self->iIdle) |
1675 { |
1716 { |
1676 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive); |
1717 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive); |
1677 |
1718 |
2168 } |
2206 } |
2169 else |
2207 else |
2170 { |
2208 { |
2171 TInt MPXHarvesting(0); |
2209 TInt MPXHarvesting(0); |
2172 TInt DaemonProcessing(0); |
2210 TInt DaemonProcessing(0); |
|
2211 |
2173 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
2212 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
2174 if(!ret) |
2213 if(ret != KErrNone || MPXHarvesting) |
|
2214 { |
|
2215 TN_DEBUG3( "CThumbnailStore::ActivityChanged() KMPXHarvesting err == %d, MPXHarvesting == %d", ret, MPXHarvesting); |
|
2216 iIdle = EFalse; |
2175 return; |
2217 return; |
2176 |
2218 } |
2177 TN_DEBUG2( "CThumbnailStore::ActivityChanged() KMPXHarvesting == %d", KMPXHarvesting); |
|
2178 |
2219 |
2179 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
2220 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
2180 |
2221 if(ret != KErrNone || DaemonProcessing) |
2181 if(!ret) |
2222 { |
|
2223 TN_DEBUG3( "CThumbnailStore::ActivityChanged() KDaemonProcessing err == %d DaemonProcessing == %d", ret, DaemonProcessing ); |
|
2224 iIdle = EFalse; |
2182 return; |
2225 return; |
2183 |
|
2184 TN_DEBUG2( "CThumbnailStore::ActivityChanged() DaemonProcessing == %d", DaemonProcessing); |
|
2185 |
|
2186 if(!MPXHarvesting && !DaemonProcessing) |
|
2187 { |
|
2188 TN_DEBUG1( "CThumbnailStore::ActivityChanged() - starting maintenance"); |
|
2189 iIdle = ETrue; |
|
2190 StartMaintenance(); |
|
2191 } |
2226 } |
|
2227 |
|
2228 TN_DEBUG1( "CThumbnailStore::ActivityChanged() - starting maintenance"); |
|
2229 iIdle = ETrue; |
|
2230 StartMaintenance(); |
2192 } |
2231 } |
2193 } |
2232 } |
2194 |
2233 |
2195 // CThumbnailStoreDiskSpaceNotifierAO class |
2234 // CThumbnailStoreDiskSpaceNotifierAO class |
2196 |
2235 |