persistentstorage/centralrepository/cenrepsrv/srvres.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include <bautils.h> // BaflUtils::GetSystemDrive
    19 #include <bautils.h> // BaflUtils::GetSystemDrive
    20 #ifdef SYMBIAN_BAFL_SYSUTIL
    20 #ifdef SYMBIAN_BAFL_SYSUTIL
    21 #include <bafl/sysutil.h>
    21 #include <bafl/sysutil.h>
    22 #endif
    22 #endif
    23 RFs TServerResources::iFs;
    23 RFs TServerResources::iFs;
    24 
    24 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
    25 HBufC* TServerResources::iPmaDirectory;
       
    26 #endif
    25 HBufC* TServerResources::iRomDirectory;
    27 HBufC* TServerResources::iRomDirectory;
    26 HBufC* TServerResources::iDataDirectory;
    28 HBufC* TServerResources::iDataDirectory;
    27 HBufC* TServerResources::iInstallDirectory;
    29 HBufC* TServerResources::iInstallDirectory;
    28 HBufC* TServerResources::iBURDirectory;
    30 HBufC* TServerResources::iBURDirectory;
    29 
    31 
    33 HBufC* TServerResources::iTrnsExt;
    35 HBufC* TServerResources::iTrnsExt;
    34 
    36 
    35 TUint8 TServerResources::iPersistsVersion;
    37 TUint8 TServerResources::iPersistsVersion;
    36 
    38 
    37 RArray<TOwnerIdMapping> TServerResources::iOwnerIdLookUpTable;
    39 RArray<TOwnerIdMapping> TServerResources::iOwnerIdLookUpTable;
       
    40 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
    41 RArray<TUid> TServerResources::iPMADriveRepositories;
       
    42 #endif
    38 
    43 
    39 CRepositoryCacheManager* TServerResources::iCacheManager;
    44 CRepositoryCacheManager* TServerResources::iCacheManager;
    40 CObservable* TServerResources::iObserver;
    45 CObservable* TServerResources::iObserver;
    41 
    46 
    42 
    47 
   194 	    case EPersists:
   199 	    case EPersists:
   195 	        {
   200 	        {
   196 	        directory.Copy(iDataDirectory->Des());
   201 	        directory.Copy(iDataDirectory->Des());
   197 	        }
   202 	        }
   198 	    	break;
   203 	    	break;
       
   204 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   205         case EPma:
       
   206             {
       
   207             directory.Copy(iPmaDirectory->Des());               
       
   208             }
       
   209             break;
       
   210 #endif
   199 	    case EInstall:
   211 	    case EInstall:
   200 	        {
   212 	        {
   201 	        directory.Copy(iInstallDirectory->Des());
   213 	        directory.Copy(iInstallDirectory->Des());
   202 	        }
   214 	        }
   203 	    	break;
   215 	    	break;
   251     aFullFileName = fullFileName.AllocL(); 
   263     aFullFileName = fullFileName.AllocL(); 
   252     }
   264     }
   253 
   265 
   254 void TServerResources::InitialiseL()
   266 void TServerResources::InitialiseL()
   255 	{
   267 	{
   256 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
   268     
   257 	iPersistsVersion = KPersistFormatVersion;	// Version 0 of persists
   269 #ifndef SYMBIAN_INCLUDE_APP_CENTRIC
   258 #else
   270     #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
   259 	iPersistsVersion = KPersistFormatSupportsIndMetaIndicator;
   271         iPersistsVersion = KPersistFormatVersion;	// Version 1 of persists
       
   272     #else
       
   273         iPersistsVersion = KPersistFormatSupportsIndMetaIndicator; // Version 2 of persists. 
       
   274     #endif	
       
   275 #else	
       
   276     iPersistsVersion = KPersistFormatSupportsPma; // Version 3 of persists.	
   260 #endif	
   277 #endif	
   261 	User::LeaveIfError(iFs.Connect());
   278 	User::LeaveIfError(iFs.Connect());
   262 
   279 
   263 	// get system drive
   280 	// get system drive
   264 	_LIT(KDriveMask, "_:");
   281 	_LIT(KDriveMask, "_:");
   265 	TDriveName systemDrive(KDriveMask);
   282 	TDriveName systemDrive(KDriveMask);
   266 	systemDrive[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
   283 	systemDrive[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
   267 		
   284 
   268 	_LIT(KRomDrive, "z:");			// This may not always be z:
   285 	_LIT(KRomDrive, "z:");                 // This may not always be z:
   269 	_LIT(KPersistsDir, "persists\\");
   286 	_LIT(KPersistsDir, "persists\\");      // Location of persisted keyspaces.
   270 	_LIT(KBURDir, "bur\\");
   287 	_LIT(KBURDir, "bur\\");
   271 
   288 
       
   289 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   290 #ifdef SYMBIAN_CENTREP_PMA_TEST
       
   291     _LIT(KProtectedDir, "protected\\");    // Location of the PMA keyspaces, when SYMBIAN_CENTREP_PMA_TEST is defined.            
       
   292 #else
       
   293     _LIT(KPmaDrive, "g:");                 // Protected Memory Area (PMA) drive. 
       
   294 #endif
       
   295 #endif
   272 	
   296 	
   273 	// File extensions
   297 	// File extensions
   274 	
   298 	
   275 	_LIT(KIniFileExtension, ".txt");
   299 	_LIT(KIniFileExtension, ".txt");
   276 	_LIT(KExternalizedPersistsFileExt, ".cre");
   300 	_LIT(KExternalizedPersistsFileExt, ".cre");
   316 	TInt r = iFs.MkDirAll(*iInstallDirectory);
   340 	TInt r = iFs.MkDirAll(*iInstallDirectory);
   317 	if(r!=KErrNone && r!=KErrAlreadyExists)
   341 	if(r!=KErrNone && r!=KErrAlreadyExists)
   318 		{
   342 		{
   319 		User::Leave(r);		
   343 		User::Leave(r);		
   320 		}
   344 		}
       
   345 
   321 	//
   346 	//
   322 	// Writeable-drive data directory
   347 	// Writeable-drive data directory
   323 	//
   348 	//
   324 
       
   325 	iDataDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KPersistsDir().Length());
   349 	iDataDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KPersistsDir().Length());
   326 	ptr.Set(iDataDirectory->Des());
   350 	ptr.Set(iDataDirectory->Des());
   327 	ptr.Append(systemDrive);
   351 	ptr.Append(systemDrive);
   328 	ptr.Append(path);
   352 	ptr.Append(path);
   329 	ptr.Append(KPersistsDir);
   353 	ptr.Append(KPersistsDir);
   330 	
   354 	
   331 	r = iFs.MkDirAll(*iDataDirectory);
   355 	r = iFs.MkDirAll(*iDataDirectory);
   332 	if(r!=KErrNone && r!=KErrAlreadyExists)
   356 	if(r!=KErrNone && r!=KErrAlreadyExists)
   333 		User::Leave(r);
   357 		User::Leave(r);
   334 
   358 
   335 	//
   359 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
   336 	// Writeable-drive backup/restore directory
   360 	//
       
   361     // Protected Memory Area (PMA) drive cenrep directory.
       
   362 	//
       
   363 #ifdef SYMBIAN_CENTREP_PMA_TEST
       
   364 	// Should ONLY be used during development. 
       
   365 	iPmaDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KPersistsDir().Length()+KProtectedDir().Length());
       
   366     ptr.Set(iPmaDirectory->Des());
       
   367 	ptr.Append(systemDrive);
       
   368     ptr.Append(path);    
       
   369     ptr.Append(KPersistsDir);	
       
   370     ptr.Append(KProtectedDir);		
       
   371 #else
       
   372 	// Should be used for production devices.
       
   373     iPmaDirectory = HBufC::NewL(KPmaDrive().Length()+pathLen);
       
   374     ptr.Set(iPmaDirectory->Des()); 
       
   375     ptr.Append(KPmaDrive);
       
   376     ptr.Append(path);    
       
   377 #endif
       
   378 
       
   379     r = iFs.MkDirAll(*iPmaDirectory);
       
   380     if(r!=KErrNone && r!=KErrAlreadyExists)
       
   381         {
       
   382 #ifdef SYMBIAN_CENTREP_PMA_TEST
       
   383         User::Leave(r); 
       
   384 #else
       
   385         // Must panic the server if the drive is not available.
       
   386         Panic(EPmaDriveNotAvailable);
       
   387 #endif     
       
   388         }
       
   389 
       
   390     // Generate PMA drive array.
       
   391     TFileName searchFileFormat;
       
   392     searchFileFormat.Append(*(TServerResources::iPmaDirectory));
       
   393     searchFileFormat.Append(_L("????????.cre"));
       
   394     CDir* entryList=NULL;
       
   395     User::LeaveIfError(TServerResources::iFs.GetDir(searchFileFormat,KEntryAttNormal,ESortByName,entryList));
       
   396     CleanupStack::PushL(entryList);
       
   397     iPMADriveRepositories.Reset();
       
   398     TInt fileCount = entryList->Count();
       
   399     TLex parser;
       
   400     TUint32 uidNum;
       
   401     for (TInt i=0; i<fileCount; i++)
       
   402         {
       
   403         parser.Assign((*entryList)[i].iName.Left(8));
       
   404         User::LeaveIfError(parser.Val(uidNum,EHex));
       
   405         iPMADriveRepositories.InsertInOrder( TUid::Uid(uidNum), TLinearOrder<TUid>(TServerResources::CompareUids) );
       
   406         }
       
   407     CleanupStack::PopAndDestroy(entryList);
       
   408 
       
   409 #endif // SYMBIAN_INCLUDE_APP_CENTRIC
       
   410 	
       
   411 	//
       
   412 	// Writeable-drive backup/restore directory.
   337 	//
   413 	//
   338 	iBURDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KBURDir().Length());
   414 	iBURDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KBURDir().Length());
   339 	ptr.Set(iBURDirectory->Des());
   415 	ptr.Set(iBURDirectory->Des());
   340 	ptr.Append(systemDrive);
   416 	ptr.Append(systemDrive);
   341 	ptr.Append(path);
   417 	ptr.Append(path);
   371 	// Observer
   447 	// Observer
   372 	iObserver = CObservable::NewLC();
   448 	iObserver = CObservable::NewLC();
   373 	CleanupStack::Pop();
   449 	CleanupStack::Pop();
   374 	
   450 	
   375 	iOwnerIdLookUpTable.Reset();
   451 	iOwnerIdLookUpTable.Reset();
   376 
   452 	}
   377 	}
   453 
   378 
   454 
   379 void TServerResources::Close()
   455 void TServerResources::Close()
   380 	{
   456 	{
   381 	delete iObserver;
   457 	delete iObserver;
   382 	delete iCacheManager;
   458 	delete iCacheManager;
   383 	delete iInstallDirectory;
   459 	delete iInstallDirectory;
   384 	delete iDataDirectory;
   460 	delete iDataDirectory;
   385 	delete iRomDirectory;
   461 	delete iRomDirectory;
       
   462 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   463 	delete iPmaDirectory;
       
   464 #endif
   386 	delete iBURDirectory;
   465 	delete iBURDirectory;
   387 	delete iIniExt;
   466 	delete iIniExt;
   388 	delete iCreExt;
   467 	delete iCreExt;
   389 	delete iTrnsExt;
   468 	delete iTrnsExt;
   390 	iFs.Close();
   469 	iFs.Close();
   391 
   470 
   392 	iCacheManager=NULL;
   471 	iCacheManager=NULL;
   393 	iInstallDirectory=NULL;
   472 	iInstallDirectory=NULL;
   394 	iDataDirectory=NULL;
   473 	iDataDirectory=NULL;
   395 	iRomDirectory=NULL;
   474 	iRomDirectory=NULL;
       
   475 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   476 	iPmaDirectory=NULL;
       
   477 #endif
   396 	iBURDirectory=NULL;	
   478 	iBURDirectory=NULL;	
   397 	iIniExt=NULL;	
   479 	iIniExt=NULL;	
   398 	iCreExt=NULL;	
   480 	iCreExt=NULL;	
   399 	iTrnsExt=NULL;	
   481 	iTrnsExt=NULL;	
   400 	
   482 	
   401 	iOwnerIdLookUpTable.Close() ;
   483 	iOwnerIdLookUpTable.Close() ;
       
   484 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   485 	iPMADriveRepositories.Close();
       
   486 #endif
   402 	}
   487 	}
   403 	
   488 	
   404 TInt TServerResources::GetUid(TEntry& aEntry, TUid& aUid)
   489 TInt TServerResources::GetUid(TEntry& aEntry, TUid& aUid)
   405 	{
   490 	{
   406 		const TInt KUidLen = 8;
   491 		const TInt KUidLen = 8;
   418 			}
   503 			}
   419 			
   504 			
   420 	return KErrNone;
   505 	return KErrNone;
   421 	}
   506 	}
   422 
   507 
       
   508 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   509 TInt TServerResources::CompareUids (const TUid& aUid1, const TUid& aUid2) 
       
   510 	{
       
   511 	if (aUid1.iUid < aUid2.iUid)
       
   512 		return -1 ;
       
   513 	else if (aUid1.iUid > aUid2.iUid)
       
   514 		return 1 ;
       
   515 	else
       
   516 		return 0 ;
       
   517 	}
       
   518 #endif
       
   519 
   423 TInt TOwnerIdMapping::CompareUids (const TOwnerIdMapping& aOwnerIdMapping1, const TOwnerIdMapping& aOwnerIdMapping2) 
   520 TInt TOwnerIdMapping::CompareUids (const TOwnerIdMapping& aOwnerIdMapping1, const TOwnerIdMapping& aOwnerIdMapping2) 
   424 	{
   521 	{
   425 	if (aOwnerIdMapping1.iRepUid < aOwnerIdMapping2.iRepUid)
   522 	if (aOwnerIdMapping1.iRepUid < aOwnerIdMapping2.iRepUid)
   426 		return -1 ;
   523 		return -1 ;
   427 	else if (aOwnerIdMapping1.iRepUid > aOwnerIdMapping2.iRepUid)
   524 	else if (aOwnerIdMapping1.iRepUid > aOwnerIdMapping2.iRepUid)