dbcreator/commsdatstartup/Src/cdccommsdatstartup.cpp
changeset 27 489cf6208544
parent 0 5a93021fdf25
child 58 83ca720e2b9a
equal deleted inserted replaced
23:7ec726f93df1 27:489cf6208544
    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"
       
    31 
    30 
    32 #include "cdccommsdatstartup.h"
    31 #include "cdccommsdatstartup.h"
    33 #include "cdccommsdatcreator.h"
    32 #include "cdccommsdatcreator.h"
    34 #include "cdcerrors.h"
    33 #include "cdcerrors.h"
    35 #include "cdclogger.h"
    34 #include "cdclogger.h"
    36 
    35 
    37 
    36 
    38 // CONSTANTS
    37 // CONSTANTS
    39 const TUid KCRUidCommsDb = { 0xcccccc00 };
    38 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 //
    47     CLOG_WRITE( "-----------------------------" );
    47     CLOG_WRITE( "-----------------------------" );
    48     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL" );
    48     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL" );
    49     CLOG_WRITE( "-----------------------------" );
    49     CLOG_WRITE( "-----------------------------" );
    50     
    50     
    51     CheckCreatorUIdL();
    51     CheckCreatorUIdL();
    52 
       
    53     CreateRepositoryL();
       
    54     
       
    55     // Set status to not initialised
       
    56     SetStartupStatusL( ECommsDatInitialisationFailed );
       
    57 
    52 
    58 	CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL()" );
    53 	CLOG_WRITE( "CCdcCommsDatStartup::ResetCommsDatToDefaultL()" );
    59 	// In all RFS cases CommsDat must be reset 
    54 	// In all RFS cases CommsDat must be reset 
    60 	ResetCommsDatToDefaultL();
    55 	ResetCommsDatToDefaultL();
    61 	
    56 	
    69 	CLOG_WRITE( "CCdcCommsDatStartup::CreateTablesL" );
    64 	CLOG_WRITE( "CCdcCommsDatStartup::CreateTablesL" );
    70 	
    65 	
    71 	// In all RFS cases CommsDat tables must be checked/created
    66 	// In all RFS cases CommsDat tables must be checked/created
    72 	cdc->CreateTablesL();
    67 	cdc->CreateTablesL();
    73 	
    68 	
    74     TFileName fileName;
    69     // If variant XML file exists, read it and create settings
    75     GetInputFileNameL( fileName );
    70     TFileName fileName( KVariantXmlFile );
    76         
    71     RFs fs;
    77     // CommsDatCreator feature is supported if input file name
    72     User::LeaveIfError( fs.Connect() );
    78     // lenght is not 0. However file name lenght at least 5. (x.xml)     
    73     RFile file;
    79     if( fileName.Length() > 0 )
    74     if ( KErrNone == file.Open( fs, fileName, EFileRead ) )
    80         {
    75         {
       
    76         file.Close();
    81         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation enabled" );
    77         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation enabled" );
    82         
    78     
    83         TFileName path( _L("Z:\\private\\10281BC3\\" )  );
    79         TRAPD(err, cdc->CreateCommsDatL( fileName ) );
    84         path.Append( fileName );
    80         if ( err != KErrNone )
       
    81             {
       
    82             // CommsDat creation leaved so something must be wrong.
       
    83             // Reset CommsDat and EAP settings.
       
    84             ResetCommsDatToDefaultL();
       
    85             ResetEAPSettingsL();
       
    86             cdc->CreateTablesL();
       
    87             User::Leave( err );
       
    88             }
    85 
    89 
    86 		CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL begin" );
    90         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation done" );
    87 	
       
    88         TRAPD(err, cdc->CreateCommsDatL( path ) );
       
    89         if(err != KErrNone )
       
    90         	{
       
    91         	// CommsDat creation leaved so something must be wrong.
       
    92         	// Reset CommsDat and EAP settings.
       
    93         	ResetCommsDatToDefaultL();
       
    94         	ResetEAPSettingsL();
       
    95         	cdc->CreateTablesL();
       
    96         	User::Leave( err );
       
    97         	}
       
    98 
       
    99         CLOG_WRITE( "CCdcCommsDatStartup::CreateCommsDatL end" );               
       
   100         }
    91         }
   101        else
    92     else
   102        	{
    93         {
   103        	CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation disabled" );
    94         CLOG_WRITE( "CCdcCommsDatStartup::CommsDat generation disabled" );
   104        	}
    95         }
   105         
    96     fs.Close();
   106     // If nothing has leaved then everything is okay (both in disabled and
       
   107     // enabled cases.
       
   108     SetStartupStatusL( ECommsDatInitialised );
       
   109         
    97         
   110     CleanupStack::PopAndDestroy( cdc );
    98     CleanupStack::PopAndDestroy( cdc );
   111     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL end" );
    99     CLOG_WRITE( "CCdcCommsDatStartup::DoStartL end" );
   112     }
       
   113 
       
   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     }
   100     }
   202 
   101 
   203 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
   204 // CCdcCommsDatStartup::CheckCreatorUIdL()
   103 // CCdcCommsDatStartup::CheckCreatorUIdL()
   205 // ----------------------------------------------------------------------------
   104 // ----------------------------------------------------------------------------
   209     // UID of MainRfs
   108     // UID of MainRfs
   210     const TUid KCreatorUid = { 0x102073EA };   
   109     const TUid KCreatorUid = { 0x102073EA };   
   211     
   110     
   212     CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" );
   111     CLOG_WRITE( "CCdcCommsDatStartup::CheckCreatorUIdL" );
   213     
   112     
   214     TUid creatorId = User::CreatorIdentity();
   113     TUid creatorId = User::CreatorSecureId();
   215 
   114 
   216     CLOG_WRITE_FORMAT( "CreatorId : %x", creatorId );
   115     CLOG_WRITE_FORMAT( "CreatorId : %x", creatorId );
   217    
   116    
   218     if( KCreatorUid != creatorId )
   117     if( KCreatorUid != creatorId )
   219         {
   118         {
   227 // CCdcCommsDatStartup::~CCdcCommsDatStartup()
   126 // CCdcCommsDatStartup::~CCdcCommsDatStartup()
   228 // ----------------------------------------------------------------------------
   127 // ----------------------------------------------------------------------------
   229 //   	
   128 //   	
   230 CCdcCommsDatStartup::~CCdcCommsDatStartup()
   129 CCdcCommsDatStartup::~CCdcCommsDatStartup()
   231     {
   130     {
   232     if( iRepository )
       
   233         {
       
   234         delete iRepository;
       
   235         }
       
   236     }
   131     }
   237 
   132 
   238 // ----------------------------------------------------------------------------
   133 // ----------------------------------------------------------------------------
   239 // CCdcCommsDatCreatorRfsPlugin::ResetCommsDatToDefaultL()
   134 // CCdcCommsDatCreatorRfsPlugin::ResetCommsDatToDefaultL()
   240 // ----------------------------------------------------------------------------
   135 // ----------------------------------------------------------------------------