systemswstubs/startupadaptationstub/src/StartupAdaptationStubModel.cpp
branchRCL_3
changeset 44 b5894bb67e73
parent 35 37b610eb7fe3
equal deleted inserted replaced
35:37b610eb7fe3 44:b5894bb67e73
     1 /*
       
     2 * Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CStartupAdaptationStubModel class definition.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "StartupAdaptationStubModel.h"
       
    22 #include "StartupAdaptationStubDebug.h"
       
    23 #include <f32file.h>
       
    24 
       
    25 // CONSTANTS
       
    26 
       
    27 _LIT( KConfigFile, "C:\\private\\2000D766\\StartupAdaptationStubConf.txt" );
       
    28 const TInt KDefaultDuration( 1 ); // Default command duration in ms.
       
    29 
       
    30 const TInt KGlobalStateChangeIndex( 0 );
       
    31 const TInt KSecurityStateChangeIndex( 1 );
       
    32 const TInt KGlobalStartupModeIndex( 2 );
       
    33 const TInt KSelftestIndex( 3 );
       
    34 const TInt KLanguageListIndex( 4 );
       
    35 const TInt KRTCTimeIndex( 5 );
       
    36 const TInt KSimChangedIndex( 6 );
       
    37 const TInt KSimOwnedIndex( 7 );
       
    38 const TInt KSetAlarmIndex( 8 );
       
    39 const TInt KCancelAlarmIndex( 9 );
       
    40 const TInt KResetIndex( 10 );
       
    41 const TInt KShutdownIndex( 11 );
       
    42 const TInt KRFSIndex( 12 );
       
    43 const TInt KActivateRfIndex( 13 );
       
    44 const TInt KDeactivateRfIndex( 14 );
       
    45 const TInt KHiddenResetIndex( 15 );
       
    46 
       
    47 using namespace StartupAdaptation;
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CStartupAdaptationStubModel::NewL
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CStartupAdaptationStubModel* CStartupAdaptationStubModel::NewL()
       
    57     {
       
    58     RDEBUG( _L( "CStartupAdaptationStubModel::NewL." ) );
       
    59 
       
    60     CStartupAdaptationStubModel* self =
       
    61         new( ELeave ) CStartupAdaptationStubModel();
       
    62 
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop();
       
    66 
       
    67     RDEBUG( _L( "CStartupAdaptationStubModel::NewL finished." ) );
       
    68 
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // Destructor
       
    74 CStartupAdaptationStubModel::~CStartupAdaptationStubModel()
       
    75     {
       
    76     RDEBUG( _L( "CStartupAdaptationStubModel::~CStartupAdaptationStubModel." ) );
       
    77 
       
    78     for ( TInt i = 0; i < KNumResponseLists; i++ )
       
    79         {
       
    80         delete iResponses[i].iList;
       
    81         }
       
    82 
       
    83     RDEBUG( _L( "CStartupAdaptationStubModel::~CStartupAdaptationStubModel finished." ) );
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CStartupAdaptationStubModel::GetGlobalStateChangeResponse
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TInt CStartupAdaptationStubModel::GetGlobalStateChangeResponse()
       
    93     {
       
    94     RDEBUG( _L( "CStartupAdaptationStubModel::GetGlobalStateChangeResponse." ) );
       
    95 
       
    96     TInt response = GetSimpleResponse( KGlobalStateChangeIndex );
       
    97 
       
    98     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetGlobalStateChangeResponse finished with %d." ), response );
       
    99     return response;
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CStartupAdaptationStubModel::GetSecurityStateChangeResponse
       
   105 //
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CStartupAdaptationStubModel::GetSecurityStateChangeResponse(
       
   109     StartupAdaptation::TSecurityStateResponse& aResponse )
       
   110     {
       
   111     RDEBUG( _L( "CStartupAdaptationStubModel::GetSecurityStateChangeResponse." ) );
       
   112 
       
   113     const TInt index = KSecurityStateChangeIndex;
       
   114     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   115 
       
   116     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   117     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   118 
       
   119     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   120     __ASSERT_DEBUG( currentIndex < list.Count() - 2, User::Invariant() );
       
   121 
       
   122     aResponse.iErrorCode = list[currentIndex + 1 ];
       
   123     aResponse.iValue =
       
   124         static_cast<TSecurityStateInfo>( list[currentIndex + 2 ] );
       
   125 
       
   126     UpdateCounter( index );
       
   127 
       
   128     RDEBUG( _L( "CStartupAdaptationStubModel::GetSecurityStateChangeResponse finished." ) );
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CStartupAdaptationStubModel::GetStartupModeResponse
       
   134 //
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CStartupAdaptationStubModel::GetStartupModeResponse(
       
   138     StartupAdaptation::TGlobalStartupModeResponse& aResponse )
       
   139     {
       
   140     RDEBUG( _L( "CStartupAdaptationStubModel::GetStartupModeResponse." ) );
       
   141 
       
   142     const TInt index = KGlobalStartupModeIndex;
       
   143     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   144 
       
   145     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   146     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   147 
       
   148     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   149     __ASSERT_DEBUG( currentIndex < list.Count() - 2, User::Invariant() );
       
   150 
       
   151     aResponse.iErrorCode = list[currentIndex + 1 ];
       
   152     aResponse.iValue =
       
   153         static_cast<TGlobalStartupMode>( list[currentIndex + 2 ] );
       
   154 
       
   155     UpdateCounter( index );
       
   156 
       
   157     RDEBUG( _L( "CStartupAdaptationStubModel::GetStartupModeResponse finished." ) );
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CStartupAdaptationStubModel::GetSelftestResponse
       
   163 //
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 TInt CStartupAdaptationStubModel::GetSelftestResponse()
       
   167     {
       
   168     RDEBUG( _L( "CStartupAdaptationStubModel::GetSelftestResponse." ) );
       
   169 
       
   170     TInt response = GetSimpleResponse( KSelftestIndex );
       
   171 
       
   172     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetSelftestResponse finished with %d." ), response );
       
   173     return response;
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CStartupAdaptationStubModel::GetLanguageListResponse
       
   179 //
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CStartupAdaptationStubModel::GetLanguageListResponse(
       
   183     StartupAdaptation::RLanguageListResponse& aResponse )
       
   184     {
       
   185     RDEBUG( _L( "CStartupAdaptationStubModel::GetLanguageListResponse." ) );
       
   186 
       
   187     const TInt index = KLanguageListIndex;
       
   188     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   189 
       
   190     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   191     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   192 
       
   193     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   194     __ASSERT_DEBUG( currentIndex < list.Count() - iResponses[ index ].iParts,
       
   195                     User::Invariant() );
       
   196 
       
   197     aResponse.iErrorCode = list[ currentIndex + 1 ];
       
   198     for ( TInt i = 0; i < list[ currentIndex + 2 ]; i++ )
       
   199         {
       
   200         aResponse.iLanguages.Append(
       
   201             static_cast<TPreferredLanguage>( list[ currentIndex + i + 3 ] ) );
       
   202         }
       
   203 
       
   204     UpdateCounter( index );
       
   205 
       
   206     RDEBUG( _L( "CStartupAdaptationStubModel::GetLanguageListResponse finished." ) );
       
   207     }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CStartupAdaptationStubModel::GetRTCTimeValidityResponse
       
   212 //
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TInt CStartupAdaptationStubModel::GetRTCTimeValidityResponse()
       
   216     {
       
   217     RDEBUG( _L( "CStartupAdaptationStubModel::GetRTCTimeValidityResponse." ) );
       
   218 
       
   219     TInt response = GetSimpleResponse( KRTCTimeIndex );
       
   220 
       
   221     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetRTCTimeValidityResponse finished with %d." ), response );
       
   222     return response;
       
   223     }
       
   224 
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CStartupAdaptationStubModel::GetSimChangedResponse
       
   228 //
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CStartupAdaptationStubModel::GetSimChangedResponse(
       
   232     StartupAdaptation::TBooleanResponse& aResponse )
       
   233     {
       
   234     RDEBUG( _L( "CStartupAdaptationStubModel::GetSimChangedResponse." ) );
       
   235 
       
   236     const TInt index = KSimChangedIndex;
       
   237     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   238 
       
   239     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   240     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   241 
       
   242     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   243     __ASSERT_DEBUG( currentIndex < list.Count() - 2, User::Invariant() );
       
   244 
       
   245     aResponse.iErrorCode = list[currentIndex + 1];
       
   246     aResponse.iValue = static_cast<TBool>( list[currentIndex + 2 ] );
       
   247 
       
   248     UpdateCounter( index );
       
   249 
       
   250     RDEBUG( _L( "CStartupAdaptationStubModel::GetSimChangedResponse finished." ) );
       
   251     }
       
   252 
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CStartupAdaptationStubModel::GetSimOwnedResponse
       
   256 //
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CStartupAdaptationStubModel::GetSimOwnedResponse(
       
   260     StartupAdaptation::TBooleanResponse& aResponse )
       
   261     {
       
   262     RDEBUG( _L( "CStartupAdaptationStubModel::GetSimOwnedResponse." ) );
       
   263 
       
   264     const TInt index = KSimOwnedIndex;
       
   265     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   266 
       
   267     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   268     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   269 
       
   270     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   271     __ASSERT_DEBUG( currentIndex < list.Count() - 2, User::Invariant() );
       
   272 
       
   273     aResponse.iErrorCode = list[currentIndex + 1 ];
       
   274     aResponse.iValue = static_cast<TBool>( list[currentIndex + 2 ] );
       
   275 
       
   276     UpdateCounter( index );
       
   277 
       
   278     RDEBUG( _L( "CStartupAdaptationStubModel::GetSimOwnedResponse finished." ) );
       
   279     }
       
   280 
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CStartupAdaptationStubModel::GetSetAlarmResponse
       
   284 //
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 TInt CStartupAdaptationStubModel::GetSetAlarmResponse()
       
   288     {
       
   289     RDEBUG( _L( "CStartupAdaptationStubModel::GetSetAlarmResponse." ) );
       
   290 
       
   291     TInt response = GetSimpleResponse( KSetAlarmIndex );
       
   292 
       
   293     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetSetAlarmResponse finished with %d." ), response );
       
   294     return response;
       
   295     }
       
   296 
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CStartupAdaptationStubModel::GetCancelAlarmResponse
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 TInt CStartupAdaptationStubModel::GetCancelAlarmResponse()
       
   304     {
       
   305     RDEBUG( _L( "CStartupAdaptationStubModel::GetCancelAlarmResponse." ) );
       
   306 
       
   307     TInt response = GetSimpleResponse( KCancelAlarmIndex );
       
   308 
       
   309     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetCancelAlarmResponse finished with %d." ), response );
       
   310     return response;
       
   311     }
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CStartupAdaptationStubModel::GetResetResponse
       
   316 //
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 TInt CStartupAdaptationStubModel::GetResetResponse()
       
   320     {
       
   321     RDEBUG( _L( "CStartupAdaptationStubModel::GetResetResponse." ) );
       
   322 
       
   323     TInt response = GetSimpleResponse( KResetIndex );
       
   324 
       
   325     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetResetResponse finished with %d." ), response );
       
   326     return response;
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CStartupAdaptationStubModel::GetShutdownResponse
       
   332 //
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 TInt CStartupAdaptationStubModel::GetShutdownResponse()
       
   336     {
       
   337     RDEBUG( _L( "CStartupAdaptationStubModel::GetShutdownResponse." ) );
       
   338 
       
   339     TInt response = GetSimpleResponse( KShutdownIndex );
       
   340 
       
   341     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetShutdownResponse finished with %d." ), response );
       
   342     return response;
       
   343     }
       
   344 
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CStartupAdaptationStubModel::GetRFSResponse
       
   348 //
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TInt CStartupAdaptationStubModel::GetRFSResponse()
       
   352     {
       
   353     RDEBUG( _L( "CStartupAdaptationStubModel::GetRFSResponse." ) );
       
   354 
       
   355     TInt response = GetSimpleResponse( KRFSIndex );
       
   356 
       
   357     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetRFSResponse finished with %d." ), response );
       
   358     return response;
       
   359     }
       
   360 
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CStartupAdaptationStubModel::GetActivateRfResponse
       
   364 //
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 TInt CStartupAdaptationStubModel::GetActivateRfResponse()
       
   368     {
       
   369     RDEBUG( _L( "CStartupAdaptationStubModel::GetActivateRfResponse." ) );
       
   370 
       
   371     TInt response = GetSimpleResponse( KActivateRfIndex );
       
   372 
       
   373     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetActivateRfResponse finished with %d." ), response );
       
   374     return response;
       
   375     }
       
   376 
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CStartupAdaptationStubModel::GetDeactivateRfResponse
       
   380 //
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 TInt CStartupAdaptationStubModel::GetDeactivateRfResponse()
       
   384     {
       
   385     RDEBUG( _L( "CStartupAdaptationStubModel::GetDeactivateRfResponse." ) );
       
   386 
       
   387     TInt response = GetSimpleResponse( KDeactivateRfIndex );
       
   388 
       
   389     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetDeactivateRfResponse finished with %d." ), response );
       
   390     return response;
       
   391     }
       
   392 
       
   393 
       
   394 // -----------------------------------------------------------------------------
       
   395 // CStartupAdaptationStubModel::GetHiddenResetResponse
       
   396 //
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 void CStartupAdaptationStubModel::GetHiddenResetResponse(
       
   400     StartupAdaptation::TBooleanResponse& aResponse )
       
   401     {
       
   402     RDEBUG( _L( "CStartupAdaptationStubModel::GetHiddenResetResponse." ) );
       
   403 
       
   404     const TInt index = KHiddenResetIndex;
       
   405     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   406 
       
   407     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   408     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   409 
       
   410     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   411     __ASSERT_DEBUG( currentIndex < list.Count() - 2, User::Invariant() );
       
   412 
       
   413     aResponse.iErrorCode = list[currentIndex + 1 ];
       
   414     aResponse.iValue = static_cast<TBool>( list[currentIndex + 2 ] );
       
   415 
       
   416     UpdateCounter( index );
       
   417 
       
   418     RDEBUG( _L( "CStartupAdaptationStubModel::GetHiddenResetResponse finished." ) );
       
   419     }
       
   420 
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // CStartupAdaptationStubModel::GetDurationForNextCall
       
   424 //
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TInt CStartupAdaptationStubModel::GetDurationForNextCall( const TInt aCommandId )
       
   428     {
       
   429     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetDurationForNextCall( %d )" ), aCommandId );
       
   430 
       
   431     TInt index = aCommandId - EGlobalStateChange;
       
   432     if ( aCommandId >= EValidateRTCTime )
       
   433         {
       
   434         // Skip the missing two commands.
       
   435         index -= ( EValidateRTCTime - EGetSIMLanguages );
       
   436         }
       
   437 
       
   438     __ASSERT_DEBUG( iResponses[index].iList != NULL, User::Invariant() );
       
   439 
       
   440     CStructuredList& list = *( ( iResponses[index] ).iList );
       
   441     const TInt currentIndex = CalculateCurrentBaseIndex( index );;
       
   442 
       
   443     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   444     __ASSERT_DEBUG( currentIndex < list.Count(), User::Invariant() );
       
   445 
       
   446     const TInt duration = list[currentIndex];
       
   447 
       
   448     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetDurationForNextCall finished with %d." ), duration );
       
   449     return duration;
       
   450     }
       
   451 
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CStartupAdaptationStubModel::CStartupAdaptationStubModel
       
   455 // C++ default constructor can NOT contain any code, that might leave.
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 CStartupAdaptationStubModel::CStartupAdaptationStubModel()
       
   459     {
       
   460     RDEBUG( _L( "CStartupAdaptationStubModel::CStartupAdaptationStubModel." ) );
       
   461 
       
   462     for ( TInt i = 0; i < KNumResponseLists; i++ )
       
   463         {
       
   464         iResponses[i].iCounter = 0;
       
   465         }
       
   466 
       
   467     iResponses[ KGlobalStateChangeIndex ].iParts = 1;
       
   468     iResponses[ KSecurityStateChangeIndex ].iParts = 2;
       
   469     iResponses[ KGlobalStartupModeIndex ].iParts = 2;
       
   470     iResponses[ KSelftestIndex ].iParts = 1;
       
   471     iResponses[ KLanguageListIndex ].iParts = 16;
       
   472     iResponses[ KRTCTimeIndex ].iParts = 1;
       
   473     iResponses[ KSimChangedIndex ].iParts = 2;
       
   474     iResponses[ KSimOwnedIndex ].iParts = 2;
       
   475     iResponses[ KSetAlarmIndex ].iParts = 1;
       
   476     iResponses[ KCancelAlarmIndex ].iParts = 1;
       
   477     iResponses[ KResetIndex ].iParts = 1;
       
   478     iResponses[ KShutdownIndex ].iParts = 1;
       
   479     iResponses[ KRFSIndex ].iParts = 1;
       
   480     iResponses[ KActivateRfIndex ].iParts = 1;
       
   481     iResponses[ KDeactivateRfIndex ].iParts = 1;
       
   482     iResponses[ KHiddenResetIndex ].iParts = 2;
       
   483 
       
   484     RDEBUG( _L( "CStartupAdaptationStubModel::CStartupAdaptationStubModel finished." ) );
       
   485     }
       
   486 
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CStartupAdaptationStubModel::ConstructL
       
   490 // Symbian 2nd phase constructor can leave.
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 void CStartupAdaptationStubModel::ConstructL()
       
   494     {
       
   495     RDEBUG( _L( "CStartupAdaptationStubModel::ConstructL." ) );
       
   496 
       
   497     for ( TInt i = 0; i < KNumResponseLists; i++ )
       
   498         {
       
   499         iResponses[i].iList =
       
   500             new ( ELeave ) CStructuredList( iResponses[i].iParts + 1 );
       
   501         }
       
   502 
       
   503     TRAPD( errorCode, ReadConfigFileL() );
       
   504     if ( errorCode != KErrNone )
       
   505         {
       
   506         RDEBUG_1( _L( "Configuration file does not exist or is corrupt (error code %d). Initializing to default configuration." ), errorCode );
       
   507 
       
   508         InitToDefaultL();
       
   509         }
       
   510 
       
   511     RDEBUG( _L( "CStartupAdaptationStubModel::ConstructL finished." ) );
       
   512     }
       
   513 
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CStartupAdaptationStubModel::ReadConfigFileL
       
   517 //
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 void CStartupAdaptationStubModel::ReadConfigFileL()
       
   521     {
       
   522     RDEBUG( _L( "CStartupAdaptationStubModel::ReadConfigFileL." ) );
       
   523 
       
   524     RFs fs;
       
   525     User::LeaveIfError( fs.Connect() );
       
   526     CleanupClosePushL( fs );
       
   527 
       
   528     RFile file;
       
   529     User::LeaveIfError( file.Open( fs, KConfigFile, EFileShareReadersOnly ) );
       
   530     CleanupClosePushL( file );
       
   531 
       
   532     TFileText reader;
       
   533     reader.Set( file );
       
   534 
       
   535     TBuf<256> buf;
       
   536     TLex lex( buf );
       
   537 
       
   538     for ( TInt i = 0; i < KNumResponseLists; i++ )
       
   539         {
       
   540         User::LeaveIfError( reader.Read( buf ) );
       
   541 
       
   542         RDEBUG_1( _L( "CStartupAdaptationStubModel: Config line: %S." ), &buf );
       
   543 
       
   544         lex.Assign( buf );
       
   545         ReadStructuredListL(
       
   546             iResponses[ i ].iParts, lex, *( iResponses[ i ].iList ) );
       
   547         }
       
   548 
       
   549     CleanupStack::PopAndDestroy( 2 ); // file, fs
       
   550 
       
   551     RDEBUG( _L( "CStartupAdaptationStubModel::ReadConfigFileL finished." ) );
       
   552     }
       
   553 
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CStartupAdaptationStubModel::InitToDefaultL
       
   557 //
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CStartupAdaptationStubModel::InitToDefaultL()
       
   561     {
       
   562     RDEBUG( _L( "CStartupAdaptationStubModel::InitToDefaultL." ) );
       
   563 
       
   564     for ( TInt i = 0; i < KNumResponseLists; i++ )
       
   565         {
       
   566         iResponses[i].iList->Reset();
       
   567         }
       
   568 
       
   569     iResponses[KGlobalStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   570     iResponses[KGlobalStateChangeIndex].iList->AppendL( KErrNone );
       
   571 
       
   572     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   573     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   574     iResponses[KSecurityStateChangeIndex].iList->AppendL( EYes );
       
   575     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   576     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   577     iResponses[KSecurityStateChangeIndex].iList->AppendL( ENoValue );
       
   578     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   579     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   580     iResponses[KSecurityStateChangeIndex].iList->AppendL( ENo );
       
   581     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   582     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   583     iResponses[KSecurityStateChangeIndex].iList->AppendL( ENo );
       
   584     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   585     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   586     iResponses[KSecurityStateChangeIndex].iList->AppendL( ENo );
       
   587     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   588     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   589     iResponses[KSecurityStateChangeIndex].iList->AppendL( ENoValue );
       
   590     iResponses[KSecurityStateChangeIndex].iList->AppendL( KDefaultDuration );
       
   591     iResponses[KSecurityStateChangeIndex].iList->AppendL( KErrNone );
       
   592     iResponses[KSecurityStateChangeIndex].iList->AppendL( ESimLockOk );
       
   593 
       
   594     iResponses[KGlobalStartupModeIndex].iList->AppendL( KDefaultDuration );
       
   595     iResponses[KGlobalStartupModeIndex].iList->AppendL( KErrNone );
       
   596     iResponses[KGlobalStartupModeIndex].iList->AppendL( ENormal );
       
   597 
       
   598     iResponses[KSelftestIndex].iList->AppendL( KDefaultDuration );
       
   599     iResponses[KSelftestIndex].iList->AppendL( KErrNone );
       
   600 
       
   601     iResponses[KLanguageListIndex].iList->AppendL( KDefaultDuration );
       
   602     iResponses[KLanguageListIndex].iList->AppendL( KErrNotFound );
       
   603     for ( TInt i = 0; i < 15; i++ )
       
   604         {
       
   605         iResponses[KLanguageListIndex].iList->AppendL( 0 );
       
   606         }
       
   607     iResponses[KLanguageListIndex].iList->AppendL( KDefaultDuration );
       
   608     iResponses[KLanguageListIndex].iList->AppendL( KErrNotFound );
       
   609     for ( TInt i = 0; i < 15; i++ )
       
   610         {
       
   611         iResponses[KLanguageListIndex].iList->AppendL( 0 );
       
   612         }
       
   613     iResponses[KLanguageListIndex].iList->AppendL( KDefaultDuration );
       
   614     iResponses[KLanguageListIndex].iList->AppendL( KErrNotFound );
       
   615     for ( TInt i = 0; i < 15; i++ )
       
   616         {
       
   617         iResponses[KLanguageListIndex].iList->AppendL( 0 );
       
   618         }
       
   619 
       
   620     iResponses[KRTCTimeIndex].iList->AppendL( KDefaultDuration );
       
   621     iResponses[KRTCTimeIndex].iList->AppendL( 0 );
       
   622 
       
   623     iResponses[KSimChangedIndex].iList->AppendL( KDefaultDuration );
       
   624     iResponses[KSimChangedIndex].iList->AppendL( KErrNotFound );
       
   625     iResponses[KSimChangedIndex].iList->AppendL( EFalse );
       
   626 
       
   627     iResponses[KSimOwnedIndex].iList->AppendL( KDefaultDuration );
       
   628     iResponses[KSimOwnedIndex].iList->AppendL( KErrNotFound );
       
   629     iResponses[KSimOwnedIndex].iList->AppendL( EFalse );
       
   630 
       
   631     for ( TInt i = 8; i < KNumResponseLists - 1; i++ )
       
   632         {
       
   633         iResponses[i].iList->AppendL( KDefaultDuration );
       
   634         iResponses[i].iList->AppendL( 0 );
       
   635         }
       
   636 
       
   637     iResponses[KHiddenResetIndex].iList->AppendL( KDefaultDuration );
       
   638     iResponses[KHiddenResetIndex].iList->AppendL( KErrNotSupported );
       
   639     iResponses[KHiddenResetIndex].iList->AppendL( EFalse );
       
   640 
       
   641     RDEBUG( _L( "CStartupAdaptationStubModel::InitToDefaultL finished." ) );
       
   642     }
       
   643 
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CStartupAdaptationStubModel::GetSimpleResponse
       
   647 //
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 TInt CStartupAdaptationStubModel::GetSimpleResponse( const TInt aIndex )
       
   651     {
       
   652     RDEBUG( _L( "CStartupAdaptationStubModel::GetSimpleResponse." ) );
       
   653     __ASSERT_DEBUG( iResponses[aIndex].iList != NULL, User::Invariant() );
       
   654 
       
   655     CStructuredList& list = *( ( iResponses[aIndex] ).iList );
       
   656     const TInt currentIndex = CalculateCurrentBaseIndex( aIndex );;
       
   657 
       
   658     RDEBUG_1( _L( "CStartupAdaptationStubModel: count = %d" ), list.Count() );
       
   659 
       
   660     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   661     __ASSERT_DEBUG( currentIndex < list.Count() + 1, User::Invariant() );
       
   662 
       
   663     TInt response = list[currentIndex + 1];
       
   664 
       
   665     UpdateCounter( aIndex );
       
   666 
       
   667     RDEBUG_1( _L( "CStartupAdaptationStubModel::GetSimpleResponse finished with %d." ), response );
       
   668     return response;
       
   669     }
       
   670 
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CStartupAdaptationStubModel::CalculateCurrentBaseIndex
       
   674 //
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 TInt CStartupAdaptationStubModel::CalculateCurrentBaseIndex( const TInt aIndex )
       
   678     {
       
   679     RDEBUG_1( _L( "CStartupAdaptationStubModel::CalculateCurrentBaseIndex( %d )" ), aIndex );
       
   680 
       
   681     const TInt counter = iResponses[aIndex].iCounter;
       
   682     const TInt parts = iResponses[aIndex].iParts;
       
   683     const TInt currentBaseIndex = counter * ( parts + 1 );
       
   684 
       
   685     RDEBUG_1( _L( "CStartupAdaptationStubModel::CalculateCurrentBaseIndex finished with %d." ), currentBaseIndex );
       
   686     return currentBaseIndex;
       
   687     }
       
   688 
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CStartupAdaptationStubModel::UpdateCounter
       
   692 //
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 void CStartupAdaptationStubModel::UpdateCounter( const TInt aIndex )
       
   696     {
       
   697     RDEBUG( _L( "CStartupAdaptationStubModel::UpdateCounter." ) );
       
   698     __ASSERT_DEBUG( iResponses[aIndex].iList != NULL, User::Invariant() );
       
   699 
       
   700     CStructuredList& list = *( ( iResponses[aIndex] ).iList );
       
   701     TInt counter = iResponses[aIndex].iCounter;
       
   702     const TInt parts = iResponses[aIndex].iParts;
       
   703 
       
   704     __ASSERT_DEBUG( list.Count() > 0, User::Invariant() );
       
   705     __ASSERT_DEBUG( counter * ( parts + 1 ) < list.Count(), User::Invariant() );
       
   706 
       
   707     counter++;
       
   708 
       
   709     if ( counter == ( list.Count() / ( parts + 1 ) ) )
       
   710         {
       
   711         iResponses[aIndex].iCounter = 0;
       
   712         }
       
   713     else
       
   714         {
       
   715         iResponses[aIndex].iCounter = counter;
       
   716         }
       
   717 
       
   718     RDEBUG_1( _L( "CStartupAdaptationStubModel::UpdateCounter finished. New counter is %d" ), iResponses[aIndex].iCounter );
       
   719     }
       
   720 
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CStartupAdaptationStubModel::ReadStructuredListL
       
   724 //
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 void CStartupAdaptationStubModel::ReadStructuredListL(
       
   728     const TInt aNumParts,
       
   729     TLex& aLexer,
       
   730     CStructuredList& aList )
       
   731     {
       
   732     RDEBUG( _L( "CStartupAdaptationStubModel::ReadStructuredListL." ) );
       
   733 
       
   734     while ( !aLexer.Eos() )
       
   735         {
       
   736         aList.AppendL( ReadDurationL( aLexer ) );
       
   737 
       
   738         TUint val( 0 );
       
   739         User::LeaveIfError( aLexer.Val( val, EHex ) );
       
   740         aList.AppendL( val );
       
   741 
       
   742         for ( TInt i = 0; i < aNumParts - 1; i++ )
       
   743             {
       
   744             if ( aLexer.Get() != ',' ) User::Leave( KErrCorrupt );
       
   745 
       
   746             User::LeaveIfError( aLexer.Val( val, EHex ) );
       
   747             aList.AppendL( val );
       
   748             }
       
   749 
       
   750         if ( !aLexer.Eos() && aLexer.Get() != ';' ) User::Leave( KErrCorrupt );
       
   751         }
       
   752 
       
   753     if ( aList.Count() == 0 ) User::Leave( KErrCorrupt );
       
   754 
       
   755     RDEBUG_1( _L( "CStartupAdaptationStubModel::ReadStructuredListL finished. List length: %d" ), aList.Count() );
       
   756     }
       
   757 
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CStartupAdaptationStubModel::ReadDurationL
       
   761 //
       
   762 // -----------------------------------------------------------------------------
       
   763 //
       
   764 TInt CStartupAdaptationStubModel::ReadDurationL( TLex& aLexer )
       
   765     {
       
   766     RDEBUG( _L( "CStartupAdaptationStubModel::ReadDurationL." ) );
       
   767 
       
   768     TInt val = KDefaultDuration;
       
   769     if ( aLexer.Peek() == '[' ) // Duration value is written to file
       
   770         {
       
   771         aLexer.Inc();
       
   772         User::LeaveIfError( aLexer.Val( val ) );
       
   773         if ( aLexer.Get() != ']' )
       
   774             {
       
   775             User::Leave( KErrCorrupt );
       
   776             }
       
   777         }
       
   778 
       
   779     RDEBUG_1( _L( "CStartupAdaptationStubModel::ReadDurationL finished with %d." ), val );
       
   780     return val;
       
   781     }