dbcreator/commsdatstartup/Src/cdccommsdatstartup.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 57 05bc53fe583b
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
    25 #include <s32strm.h>
    25 #include <s32strm.h>
    26 #include <s32file.h>
    26 #include <s32file.h>
    27 #include <etelpckt.h>
    27 #include <etelpckt.h>
    28 
    28 
    29 #include <centralrepository.h>
    29 #include <centralrepository.h>
       
    30 #include "cdccommsdatcreatorcrkeys.h"
    30 
    31 
    31 #include "cdccommsdatstartup.h"
    32 #include "cdccommsdatstartup.h"
    32 #include "cdccommsdatcreator.h"
    33 #include "cdccommsdatcreator.h"
    33 #include "cdcerrors.h"
    34 #include "cdcerrors.h"
    34 #include "cdclogger.h"
    35 #include "cdclogger.h"
    35 
    36 
    36 
    37 
    37 // CONSTANTS
    38 // CONSTANTS
    38 const TUid KCRUidCommsDb = { 0xcccccc00 };
    39 const TUid KCRUidCommsDb = { 0xcccccc00 };
    39 _LIT( KVariantXmlFile, "Z:\\private\\10281BC3\\VariantData_commsdat.xml" );
       
    40 
    40 
    41 //------------------------------------------------
    41 //------------------------------------------------
    42 // CCdcCommsDatStartup::DoStartL
    42 // CCdcCommsDatStartup::DoStartL
    43 //------------------------------------------------
    43 //------------------------------------------------
    44 //
    44 //
    48     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL" );
    48     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL" );
    49     CLOG_WRITE( "-----------------------------" );
    49     CLOG_WRITE( "-----------------------------" );
    50     
    50     
    51     CheckCreatorUIdL();
    51     CheckCreatorUIdL();
    52 
    52 
       
    53     CreateRepositoryL();
       
    54     
       
    55     // Set status to not initialised
       
    56     SetStartupStatusL( ECommsDatInitialisationFailed );
       
    57 
    53 	CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL()" );
    58 	CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL()" );
    54 	// In all RFS cases CommsDat must be reset 
    59 	// In all RFS cases CommsDat must be reset 
    55 	ResetCommsDatToDefaultL();
    60 	ResetCommsDatToDefaultL();
    56 	
    61 	
    57 	// Reset EAP settings databases
    62 	// Reset EAP settings databases
    64 	CLOG_WRITE( "CCdcCommsDatStartup::CreateTablesL" );
    69 	CLOG_WRITE( "CCdcCommsDatStartup::CreateTablesL" );
    65 	
    70 	
    66 	// In all RFS cases CommsDat tables must be checked/created
    71 	// In all RFS cases CommsDat tables must be checked/created
    67 	cdc->CreateTablesL();
    72 	cdc->CreateTablesL();
    68 	
    73 	
    69     // If variant XML file exists, read it and create settings
    74     TFileName fileName;
    70     TFileName fileName( KVariantXmlFile );
    75     GetInputFileNameL( fileName );
    71     RFs fs;
    76         
    72     User::LeaveIfError( fs.Connect() );
    77     // CommsDatCreator feature is supported if input file name
    73     RFile file;
    78     // lenght is not 0. However file name lenght at least 5. (x.xml)     
    74     if ( KErrNone == file.Open( fs, fileName, EFileRead ) )
    79     if( fileName.Length() > 0 )
    75         {
    80         {
    76         file.Close();
       
    77         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation enabled" );
    81         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation enabled" );
    78     
    82         
    79         TRAPD(err, cdc->CreateCommsDatL( fileName ) );
    83         TFileName path( _L("Z:\\private\\10281BC3\\" )  );
    80         if ( err != KErrNone )
    84         path.Append( fileName );
    81             {
    85 
    82             // CommsDat creation leaved so something must be wrong.
    86 		CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL begin" );
    83             // Reset CommsDat and EAP settings.
    87 	
    84             ResetCommsDatToDefaultL();
    88         TRAPD(err, cdc->CreateCommsDatL( path ) );
    85             ResetEAPSettingsL();
    89         if(err != KErrNone )
    86             cdc->CreateTablesL();
    90         	{
    87             User::Leave( err );
    91         	// CommsDat creation leaved so something must be wrong.
    88             }
    92         	// Reset CommsDat and EAP settings.
    89 
    93         	ResetCommsDatToDefaultL();
    90         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation done" );
    94         	ResetEAPSettingsL();
    91         }
    95         	cdc->CreateTablesL();
    92     else
    96         	User::Leave( err );
    93         {
    97         	}
    94         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation disabled" );
    98 
    95         }
    99         CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL end" );               
    96     fs.Close();
   100         }
       
   101        else
       
   102        	{
       
   103        	CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation disabled" );
       
   104        	}
       
   105         
       
   106     // If nothing has leaved then everything is okay (both in disabled and
       
   107     // enabled cases.
       
   108     SetStartupStatusL( ECommsDatInitialised );
    97         
   109         
    98     CleanupStack::PopAndDestroy( cdc );
   110     CleanupStack::PopAndDestroy( cdc );
    99     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL end" );
   111     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL end" );
   100     }
   112     }
   101 
   113 
   102 // ----------------------------------------------------------------------------
   114 // ----------------------------------------------------------------------------
       
   115 // CCdcCommsDatStartup::CreateRepositoryL()
       
   116 // ----------------------------------------------------------------------------
       
   117 //    
       
   118 void CCdcCommsDatStartup::CreateRepositoryL()
       
   119     {
       
   120     CLOG_WRITE( "CCdcCommsDatStartup::CreateRepositoryL()" );
       
   121 
       
   122     TRAPD( err, iRepository = CRepository::NewL( KCRUidCommsDatCreator ) );
       
   123     
       
   124     // Log is important now, because repository cannot contain the 
       
   125     // error value if it cannot be used 
       
   126     if( err != KErrNone )
       
   127         {
       
   128         CLOG_WRITE_FORMAT( "Repository could not created err : %d", err );
       
   129         User::Leave( err );
       
   130         }
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CCdcCommsDatStartup::SetStartupStatusL()
       
   135 // ----------------------------------------------------------------------------
       
   136 //    
       
   137 void CCdcCommsDatStartup::SetStartupStatusL( TInt aResult )
       
   138     {
       
   139     CLOG_WRITE_FORMAT( "CCdcCommsDatStartup::SetStartupStatusL() %d", aResult );
       
   140 
       
   141     TInt err = iRepository->Set( KCommsDatCreatorStartupStatus, aResult );
       
   142     if( err != KErrNone )
       
   143         {
       
   144         CLOG_WRITE_FORMAT( 
       
   145                 "Value could not write to repository err : %d", err );
       
   146         User::Leave( err );
       
   147         }
       
   148 
       
   149     CLOG_WRITE_FORMAT( "CCdcCommsDatStartup::SetStartupStatusL() %d", aResult );
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------------------------------
       
   153 // CCdcCommsDatStartup::GetInputFileNameL()
       
   154 // ----------------------------------------------------------------------------
       
   155 //    
       
   156 void CCdcCommsDatStartup::GetInputFileNameL( TFileName &aFileName )
       
   157     {
       
   158     CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL()" );
       
   159 
       
   160     TInt err = iRepository->Get( KCommsDatCreatorInputFileName, aFileName );
       
   161     if( err != KErrNone )
       
   162         {
       
   163         CLOG_WRITE_FORMAT(
       
   164                  "Value could not red from repository err : %d", err );
       
   165         User::Leave( err );
       
   166         }
       
   167 
       
   168     CLOG_WRITE( "Input filename red" );
       
   169 
       
   170     HBufC *fileName = aFileName.AllocLC();
       
   171 
       
   172     CLOG_WRITE_FORMAT( "Input filename value : %S", fileName );
       
   173     
       
   174     CleanupStack::PopAndDestroy( fileName );
       
   175     
       
   176     // Check if file exists. If it doesn't reset filename.
       
   177     RFs fs;
       
   178     err = fs.Connect();//check
       
   179     
       
   180     if( err == KErrNone )
       
   181     	{
       
   182     	RFile file;
       
   183     
       
   184     	TFileName path( _L("Z:\\private\\10281BC3\\" )  );
       
   185     	path.Append( aFileName );
       
   186 
       
   187     	err = file.Open(fs, path, EFileRead);
       
   188     	if( err != KErrNone )
       
   189     	{
       
   190 	    	CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL() File does not exist");
       
   191   	  	aFileName.Zero();
       
   192     	}
       
   193     	else
       
   194     	{
       
   195     		file.Close();
       
   196     	}
       
   197     	fs.Close();
       
   198     	}
       
   199     
       
   200     CLOG_WRITE( "CCdcCommsDatStartup::GetInputFileNameL()" );
       
   201     }
       
   202 
       
   203 // ----------------------------------------------------------------------------
   103 // CCdcCommsDatStartup::CheckCreatorUIdL()
   204 // CCdcCommsDatStartup::CheckCreatorUIdL()
   104 // ----------------------------------------------------------------------------
   205 // ----------------------------------------------------------------------------
   105 //   	
   206 //   	
   106 void CCdcCommsDatStartup::CheckCreatorUIdL()
   207 void CCdcCommsDatStartup::CheckCreatorUIdL()
   107     {
   208     {
   108     // UID of MainRfs
   209     // UID of MainRfs
   109     const TUid KCreatorUid = { 0x102073EA };   
   210     const TUid KCreatorUid = { 0x102073EA };   
   110     
   211     
   111     CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" );
   212     CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" );
   112     
   213     
   113     TUid creatorId = User::CreatorSecureId();
   214     TUid creatorId = User::CreatorIdentity();
   114 
   215 
   115     CLOG_WRITE_FORMAT( "CreatorId : %x", creatorId );
   216     CLOG_WRITE_FORMAT( "CreatorId : %x", creatorId );
   116    
   217    
   117     if( KCreatorUid != creatorId )
   218     if( KCreatorUid != creatorId )
   118         {
   219         {
   126 // CCdcCommsDatStartup::~CCdcCommsDatStartup()
   227 // CCdcCommsDatStartup::~CCdcCommsDatStartup()
   127 // ----------------------------------------------------------------------------
   228 // ----------------------------------------------------------------------------
   128 //   	
   229 //   	
   129 CCdcCommsDatStartup::~CCdcCommsDatStartup()
   230 CCdcCommsDatStartup::~CCdcCommsDatStartup()
   130     {
   231     {
       
   232     if( iRepository )
       
   233         {
       
   234         delete iRepository;
       
   235         }
   131     }
   236     }
   132 
   237 
   133 // ----------------------------------------------------------------------------
   238 // ----------------------------------------------------------------------------
   134 // CCdcCommsDatCreatorRfsPlugin::ResetCommsDatToDefaultL()
   239 // CCdcCommsDatCreatorRfsPlugin::ResetCommsDatToDefaultL()
   135 // ----------------------------------------------------------------------------
   240 // ----------------------------------------------------------------------------