backsteppingsrv/src/bsconfiguration.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 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:  Class keeps BS configuration
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h> //FileExists
       
    20 #include <xcfwtree.h>
       
    21 #include <xcfwengine.h>
       
    22 #include <gecoobjectbase.h>
       
    23 #include <gecodefaultobject.h>
       
    24 
       
    25 #include "bsdebug.h"
       
    26 #include "bsconfiguration.h"
       
    27 
       
    28 _LIT(KConfigurationFile, "bs_config.xml" );
       
    29 _LIT(KCDrive, "C");
       
    30 _LIT(KZDrive, "Z");
       
    31 
       
    32 _LIT(KDelimiter, ":");
       
    33 _LIT(KTrueValue, "1");
       
    34 _LIT(KHexStart,"0x");
       
    35 
       
    36 _LIT(KAppNode, "app");
       
    37 
       
    38 _LIT(KUidAttribute, "uid");
       
    39 _LIT(KResetAttribute, "reset");
       
    40 _LIT(KIgnoredAttribute, "ignored");
       
    41 _LIT(KIgnoredIfStartedFromAttribute, "ignoredIfStartedFrom");
       
    42 _LIT(KResetIfThruAttribute, "resetIfThru");
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // C++ default constructor can NOT contain any code, that might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CBSConfiguration::CBSConfiguration()
       
    51     {
       
    52     // No implementation required
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // Destructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CBSConfiguration::~CBSConfiguration()
       
    60     {
       
    61     delete iContentTree;
       
    62     delete iContentEngine;
       
    63 
       
    64     iResetApps.Close( );
       
    65     iIgnoredApps.Close( );
       
    66     iIgnoredIfStartedFrom.Close( );
       
    67     iResetIfThru.Close( );
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CBSConfiguration* CBSConfiguration::NewLC()
       
    75     {
       
    76     CBSConfiguration* self = new (ELeave)CBSConfiguration();
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // Two-phased constructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CBSConfiguration* CBSConfiguration::NewL()
       
    87     {
       
    88     CBSConfiguration* self = CBSConfiguration::NewLC( );
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // Symbian 2nd phase constructor can leave.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CBSConfiguration::ConstructL()
       
    98     {
       
    99     iContentTree = CXCFWTree::NewL( );
       
   100     iContentEngine = CXCFWEngine::NewL( this );
       
   101 
       
   102     RFs fileSession;
       
   103 
       
   104     User::LeaveIfError( fileSession.Connect( ) );
       
   105     CleanupClosePushL( fileSession );
       
   106 
       
   107     TFileName configPath;
       
   108 
       
   109     User::LeaveIfError( fileSession.PrivatePath( configPath ) );
       
   110     configPath.Insert( 0, KDelimiter );
       
   111     configPath.Insert( 0, KCDrive );
       
   112     configPath.Append( KConfigurationFile );
       
   113 
       
   114     // first check if file exists on c drive 
       
   115     if ( !BaflUtils::FileExists( fileSession, configPath ) )
       
   116         {
       
   117         // read from z drive 
       
   118         configPath[0] = KZDrive()[0];
       
   119         }
       
   120 
       
   121     CleanupStack::PopAndDestroy( &fileSession );
       
   122 
       
   123     iContentEngine->LoadL( *iContentTree, configPath );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // 
       
   128 // -----------------------------------------------------------------------------
       
   129 //    
       
   130 TBool CBSConfiguration::IsReset( TUid aApp )
       
   131     {
       
   132     return iResetApps.Find( aApp.iUid ) != KErrNotFound;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // 
       
   137 // -----------------------------------------------------------------------------
       
   138 //        
       
   139 TBool CBSConfiguration::IsIgnored( TUid aApp )
       
   140     {
       
   141     return iIgnoredApps.Find( aApp.iUid ) != KErrNotFound;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // 
       
   146 // -----------------------------------------------------------------------------
       
   147 //        
       
   148 TBool CBSConfiguration::IsIgnoredIfStartedFrom( TUid aApp )
       
   149     {
       
   150     return iIgnoredIfStartedFrom.Find( aApp.iUid ) != KErrNotFound;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // 
       
   155 // -----------------------------------------------------------------------------
       
   156 //        
       
   157 RArray<TInt>& CBSConfiguration::ResetIfThruList()
       
   158     {
       
   159     return iResetIfThru;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // 
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CBSConfiguration::LoadConfigurationL()
       
   167     {
       
   168     // get root node
       
   169     MXCFWNode* root = iContentTree->Root( );
       
   170 
       
   171     // list of fetched nodes
       
   172     RNodeArray nodes;
       
   173     CleanupClosePushL( nodes );
       
   174 
       
   175     // handle entries
       
   176     iContentTree->GetNodesOfTypeL( KAppNode, nodes, root, ETrue );
       
   177 
       
   178     for ( TInt i = 0; i < nodes.Count( ); i++ )
       
   179         {
       
   180         CGECODefaultObject* object =
       
   181                 static_cast<CGECODefaultObject*>(nodes[i]->Data( ));
       
   182         TPtrC uidVal;
       
   183         TPtrC resetVal;
       
   184         TPtrC ignoredVal;
       
   185         TPtrC ignoredIfStartedFromVal;
       
   186         TPtrC resetIfThruVal;
       
   187         object->GetAttribute( KUidAttribute, uidVal );
       
   188         object->GetAttribute( KResetAttribute, resetVal );
       
   189         object->GetAttribute( KIgnoredAttribute, ignoredVal );
       
   190         object->GetAttribute( KIgnoredIfStartedFromAttribute,
       
   191             ignoredIfStartedFromVal );
       
   192         object->GetAttribute( KResetIfThruAttribute, resetIfThruVal );
       
   193 
       
   194         TInt uid = Str2Int( uidVal );
       
   195 
       
   196         if ( resetVal.Compare( KTrueValue ) == 0 )
       
   197             iResetApps.AppendL( uid );
       
   198 
       
   199         if ( ignoredVal.Compare( KTrueValue ) == 0 )
       
   200             iIgnoredApps.AppendL( uid );
       
   201 
       
   202         if ( ignoredIfStartedFromVal.Compare( KTrueValue ) == 0 )
       
   203             iIgnoredIfStartedFrom.AppendL( uid );
       
   204 
       
   205         if ( resetIfThruVal.Compare( KTrueValue ) == 0 )
       
   206             iResetIfThru.AppendL( uid );
       
   207         }
       
   208 
       
   209 #ifdef _DEBUG    
       
   210 
       
   211     for ( TInt i = 0; i< iResetApps.Count( ); i++ )
       
   212         DEBUG(("\tiResetApps[%d] = %X)", i, iResetApps[i]));
       
   213 
       
   214     for ( TInt i = 0; i< iIgnoredApps.Count( ); i++ )
       
   215         DEBUG(("\tiIgnoredApps[%d] = %X)", i, iIgnoredApps[i]));
       
   216 
       
   217     for ( TInt i = 0; i< iIgnoredIfStartedFrom.Count( ); i++ )
       
   218         DEBUG(("\tiIgnoredIfStartedFrom[%d] = %X)", i, iIgnoredIfStartedFrom[i]));
       
   219 
       
   220     for ( TInt i = 0; i< iResetIfThru.Count( ); i++ )
       
   221         DEBUG(("\tiResetIfThru[%d] = %X)", i, iResetIfThru[i]));
       
   222 
       
   223 #endif
       
   224 
       
   225     // clean up
       
   226     CleanupStack::PopAndDestroy( &nodes );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // 
       
   231 // -----------------------------------------------------------------------------
       
   232 //   
       
   233 TInt CBSConfiguration::Str2Int( const TDesC& aStr )
       
   234     {
       
   235     // if a string starts from '0x' then convert aStr from hex to int.
       
   236     // else send aStr to the StrDec2Uint
       
   237 
       
   238     TInt position(aStr.Find( KHexStart ) );
       
   239     TInt ret(KErrArgument);
       
   240     if ( position == 0 )
       
   241         {
       
   242         // is hex
       
   243         TPtrC string(aStr.Mid( KHexStart().Length( ) ) );
       
   244 
       
   245         TLex lexer(string);
       
   246         TUint val;
       
   247         lexer.Val( val, EHex );
       
   248         ret = val;
       
   249         }
       
   250     else
       
   251         {
       
   252         TLex lexer(aStr);
       
   253         lexer.Val( ret );
       
   254         }
       
   255     return ret;
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // From class MXCFWEngineObserver
       
   260 // 
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CBSConfiguration::HandleEngineEventL( TXCFWEngineEvent aEvent )
       
   264     {
       
   265     // handle completion
       
   266     if ( aEvent == EEvtParsingComplete )
       
   267         {
       
   268         LoadConfigurationL( );
       
   269         }
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // From class MXCFWEngineObserver
       
   274 // 
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CBSConfiguration::HandleEngineErrorL( TInt /*aErrorCode*/)
       
   278     {
       
   279     }