metadataengine/server/src/mdsserver.cpp
branchRCL_3
changeset 15 3cebc1a84278
parent 14 646a02f170b9
child 17 50de4d668bb6
equal deleted inserted replaced
14:646a02f170b9 15:3cebc1a84278
    33 #include "mdcserializationbuffer.h"
    33 #include "mdcserializationbuffer.h"
    34 
    34 
    35 __DEFINE_LOGGER
    35 __DEFINE_LOGGER
    36 
    36 
    37 const TInt64 KDiskSpaceGarbageCollectorThreshold = 1024*1024; // 1 MB
    37 const TInt64 KDiskSpaceGarbageCollectorThreshold = 1024*1024; // 1 MB
    38 const TInt64 KDiskFullThreshold = 1024*50; // 50 kB
       
    39 
    38 
    40 _LIT( KSchema, "schema.mde" );
    39 _LIT( KSchema, "schema.mde" );
    41 _LIT( KDefaultImportProfile, "defaultimportfile.mde" );
    40 _LIT( KDefaultImportProfile, "defaultimportfile.mde" );
    42 _LIT( KBackupRegistration, "backup_registration.xml" );
    41 _LIT( KBackupRegistration, "backup_registration.xml" );
    43 _LIT( KSchemaPath, "z:\\private\\200009F3\\schema.mde" );
    42 _LIT( KSchemaPath, "z:\\private\\200009F3\\schema.mde" );
   154     KMdsRanges,
   153     KMdsRanges,
   155     KMdsElementsIndex,
   154     KMdsElementsIndex,
   156     NULL //mdsElements
   155     NULL //mdsElements
   157     };
   156     };
   158 
   157 
       
   158 // ======================= LOCAL FUNCTIONS ================================
       
   159 
       
   160 void CheckAndInitializeFileL( RFs& aFs, TBuf<KMaxFileName>& aFile, const TDesC16& aFilePath,
       
   161                                             RFileReadStream& aTempFile, CFileMan* aFileMan )
       
   162     {
       
   163     __LOG1( ELogAlways, "CheckAndInitializeFileL() - handling file %S", &aFilePath );
       
   164     const TInt err = aTempFile.Open( aFs, aFile, EFileRead | EFileShareAny );
       
   165     __LOG1( ELogAlways, "CheckAndInitializeFileL() - open file error %d", err );
       
   166     aTempFile.Close();
       
   167     if ( err != KErrNone )
       
   168         {
       
   169         if ( err == KErrNotFound )
       
   170             {
       
   171             // Path found but not schema.mde, copy schema.m
       
   172             const TInt error = aFileMan->Copy( aFilePath, aFile, CFileMan::EOverWrite );
       
   173             __LOG1( ELogAlways, "CheckAndInitializeFileL() - copy file error %d", error );
       
   174             }
       
   175         else if ( err == KErrPathNotFound)
       
   176             {
       
   177             // Create private dir
       
   178             User::LeaveIfError( aFs.CreatePrivatePath( EDriveC ) );
       
   179             
       
   180             // Copy schema.mde
       
   181             const TInt error = aFileMan->Copy( aFilePath, aFile, CFileMan::EOverWrite );
       
   182             __LOG1( ELogAlways, "CheckAndInitializeFileL() - copy file error %d", error );
       
   183             }    
       
   184         }    
       
   185     }
       
   186 
       
   187 // ======================= MEMBER FUNCTIONS ===============================
   159 
   188 
   160 CPolicyServer::TCustomResult CMdSServer::CustomSecurityCheckL(
   189 CPolicyServer::TCustomResult CMdSServer::CustomSecurityCheckL(
   161         const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/ )
   190         const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/ )
   162     {
   191     {
   163     CPolicyServer::TCustomResult securityCheckResult = EFail;
   192     CPolicyServer::TCustomResult securityCheckResult = EFail;
   323 void CMdSServer::ConstructL()
   352 void CMdSServer::ConstructL()
   324     {
   353     {
   325     __INIT_LOGGER;
   354     __INIT_LOGGER;
   326     StartL( KMdSServerName );
   355     StartL( KMdSServerName );
   327     __LOGLB( ELogAlways, "Server start" );
   356     __LOGLB( ELogAlways, "Server start" );
       
   357 
       
   358     RProcess process;
       
   359     process.SetPriority( EPriorityBackground );
       
   360     process.Close();
   328     
   361     
   329     CheckInitSriptL();
   362     CheckInitSriptL();
   330     
   363     
   331     iLockList = CMdSObjectLockList::NewL();
   364     iLockList = CMdSObjectLockList::NewL();
   332     CMdSSqLiteConnection* conn = CMdSSqLiteConnection::NewLC();
   365     CMdSSqLiteConnection* conn = CMdSSqLiteConnection::NewLC();
   869     
   902     
   870     backupRegistration.Copy( privatePath );
   903     backupRegistration.Copy( privatePath );
   871     backupRegistration.Append( KBackupRegistration );
   904     backupRegistration.Append( KBackupRegistration );
   872     
   905     
   873     CFileMan* fileMan = CFileMan::NewL( fs );
   906     CFileMan* fileMan = CFileMan::NewL( fs );
   874     CleanupStack::PushL( fileMan);
   907     CleanupStack::PushL( fileMan );
   875     
   908     
   876     TInt err = tmpFile.Open( fs, schema, EFileRead | EFileShareAny );
   909     CheckAndInitializeFileL( fs, schema, KSchemaPath(), tmpFile, fileMan );
   877     __LOG1( ELogAlways, "open schema.mde %d", err );
   910     
   878     tmpFile.Close();
   911     CheckAndInitializeFileL( fs, defaultImportProfile, KDefaultImportProfilePath(), tmpFile, fileMan );    
   879     if ( err != KErrNone )
   912     
   880         {
   913     CheckAndInitializeFileL( fs, backupRegistration, KBackupRegistrationPath(), tmpFile, fileMan );
   881         if ( err == KErrNotFound )
       
   882             {
       
   883             // Path found but not schema.mde, copy schema.m
       
   884             const TInt error = fileMan->Copy( KSchemaPath, schema, CFileMan::EOverWrite );
       
   885             __LOG1( ELogAlways, "copy schema.mde %d", error );
       
   886             }
       
   887         else if ( err == KErrPathNotFound)
       
   888             {
       
   889             // Create private dir
       
   890             User::LeaveIfError( fs.CreatePrivatePath( EDriveC ) );
       
   891             
       
   892             // Copy schema.mde
       
   893             const TInt error = fileMan->Copy( KSchemaPath, schema, CFileMan::EOverWrite );
       
   894             __LOG1( ELogAlways, "copy schema.mde %d", error );
       
   895             }    
       
   896         }
       
   897 
       
   898     err = tmpFile.Open( fs, defaultImportProfile, EFileRead | EFileShareAny );
       
   899     __LOG1( ELogAlways, "open defaultimportprofile.mde %d", err );
       
   900     tmpFile.Close();
       
   901     if ( err != KErrNone )
       
   902         {
       
   903         if ( err == KErrNotFound )
       
   904             {
       
   905             // Path found but not schema.mde, copy schema.m
       
   906             const TInt error1 = fileMan->Copy( KDefaultImportProfilePath, defaultImportProfile, CFileMan::EOverWrite );
       
   907             __LOG1( ELogAlways, "copy defaultimportprofile.mde %d", error1 );
       
   908             }
       
   909         else if ( err == KErrPathNotFound)
       
   910             {
       
   911             // Create private dir
       
   912             User::LeaveIfError( fs.CreatePrivatePath( EDriveC ) );
       
   913              
       
   914             // Copy schema.mde
       
   915             const TInt error1 = fileMan->Copy( KDefaultImportProfilePath, defaultImportProfile, CFileMan::EOverWrite );
       
   916             __LOG1( ELogAlways, "copy defaultimportprofile.mde %d", error1 );
       
   917             }    
       
   918         }    
       
   919     
       
   920     err = tmpFile.Open( fs, backupRegistration, EFileRead | EFileShareAny );
       
   921     __LOG1( ELogAlways, "open backup_registration.xml %d", err );
       
   922     tmpFile.Close();
       
   923     if ( err != KErrNone )
       
   924         {
       
   925         if ( err == KErrNotFound )
       
   926             {
       
   927             // Path found but not schema.mde, copy schema.m
       
   928             const TInt error2 = fileMan->Copy( KBackupRegistrationPath, backupRegistration, CFileMan::EOverWrite );
       
   929             __LOG1( ELogAlways, "copy backup_registration.xml %d", error2 );
       
   930             }
       
   931         else if ( err == KErrPathNotFound)
       
   932             {
       
   933             // Create private dir
       
   934             User::LeaveIfError( fs.CreatePrivatePath( EDriveC ) );
       
   935             
       
   936             // Copy schema.mde
       
   937             const TInt error2 = fileMan->Copy( KBackupRegistrationPath, backupRegistration, CFileMan::EOverWrite );
       
   938             __LOG1( ELogAlways, "copy backup_registration.xml %d", error2 );
       
   939             }    
       
   940         }   
       
   941 
   914 
   942     CleanupStack::PopAndDestroy( 2 ); //fileman, fs
   915     CleanupStack::PopAndDestroy( 2 ); //fileman, fs
   943     }
   916     }
   944 
   917 
   945 // ========================== OTHER EXPORTED FUNCTIONS =========================
   918 // ========================== OTHER EXPORTED FUNCTIONS =========================