psmservices/psmserver/src/engine/psmcenrepstorage.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:  PSM storage for backups and configs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include "psmcenrepstorage.h"
       
    21 #include "psmstoragedefines.h"
       
    22 #include "psmtrace.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CPsmCenRepStorage::NewL
       
    26 // Two-phased constructor.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CPsmCenRepStorage* CPsmCenRepStorage::NewL( TPsmsrvMode aMode, RFs& aFile )
       
    30     {
       
    31     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::NewL()" ) ) );
       
    32 
       
    33     CPsmCenRepStorage* self = new( ELeave ) CPsmCenRepStorage( aMode, aFile );
       
    34     
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38 
       
    39     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::NewL - return 0x%x" ), self ) );
       
    40 
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CPsmCenRepStorage::CPsmCenRepStorage
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CPsmCenRepStorage::CPsmCenRepStorage( TPsmsrvMode aMode, RFs& aFile ) :
       
    51     CPsmStorage( aMode, aFile )
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CPsmCenRepStorage::ConstructL
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CPsmCenRepStorage::ConstructL()
       
    61     {
       
    62     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ConstructL()" ) ) );
       
    63     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ConstructL - return" ) ) );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // Destructor
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CPsmCenRepStorage::~CPsmCenRepStorage()
       
    71     {
       
    72     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::~CPsmCenRepStorage()" ) ) );
       
    73     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::~CPsmCenRepStorage - return") ) );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CPsmCenRepStorage::InitRootElementsL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CPsmCenRepStorage::InitRootElementsL()
       
    81     {
       
    82     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::InitRootElementsL()" ) ) );
       
    83    
       
    84     // Get root element
       
    85     iStorageRoot = iStorageFile.DocumentElement();
       
    86     
       
    87     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::InitRootElementsL() - return" ) ) );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CPsmCenRepStorage::InitConfigL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CPsmCenRepStorage::InitStorageL( const TUint32 aStorageUid )
       
    95     {
       
    96     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::InitStorageL()" ) ) );
       
    97 
       
    98     // Create storage file parser    
       
    99     iDOMImpl.OpenL( );
       
   100     User::LeaveIfError( iStorageParser.Open( iDOMImpl ) );
       
   101     iStorageUid = aStorageUid;
       
   102 
       
   103     // Generate file folder+name+extension
       
   104     TBuf<KPsmMaxPathLength> privatePath( KNullDesC );
       
   105     iFileSession.PrivatePath( privatePath );
       
   106 
       
   107     TBuf<KPsmMaxPathLength> storageFile( KNullDesC );
       
   108     storageFile.Append( KPsmPrivateDrive );
       
   109     storageFile.Append( privatePath );
       
   110     storageFile.Append( KPsmCenRepFolder );
       
   111     storageFile.AppendNumUC( iStorageUid, EHex );
       
   112     storageFile.Append( KPsmStorageExtension );
       
   113 
       
   114     // Initialize PSM config file
       
   115     iStorageFile = iStorageParser.ParseFileL( iFileSession, storageFile );
       
   116     InitRootElementsL();
       
   117     
       
   118     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::InitStorageL() - return" ) ) );
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CPsmCenRepStorage::ListPassiveConfigsL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CPsmCenRepStorage::ListPassiveConfigs( RPassiveConfigList& aList )
       
   126     {
       
   127     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ListPassiveConfigsL()" ) ) );
       
   128     // Read from CenRep directory all the files and generate UIDs from the file names
       
   129 
       
   130     CDir* directory = NULL;
       
   131     TBuf<KPsmMaxPathLength> privatePath( KNullDesC );
       
   132     iFileSession.PrivatePath( privatePath );
       
   133 
       
   134     TBuf<KPsmMaxPathLength> storageFolder( KNullDesC );
       
   135     storageFolder.Append( KPsmPrivateDrive );
       
   136     storageFolder.Append( privatePath );
       
   137     storageFolder.Append( KPsmCenRepFolder );
       
   138 
       
   139     iFileSession.GetDir( storageFolder, 0, 0, *&directory );
       
   140 
       
   141     if ( directory )
       
   142         {
       
   143         // Get file count and loop all files
       
   144         const TInt fileCount( directory->Count() );
       
   145 
       
   146         for ( TInt i = 0; i < fileCount; i++ )
       
   147             {
       
   148             // Get file information
       
   149             const TEntry& file( ( *directory )[i] );
       
   150             // Get file name and change that to UID value
       
   151             TUint32 hexValue( 0 );
       
   152             TUint limit( 0xFFFFFFFF );
       
   153 
       
   154             // Append string into Lex and get value
       
   155             TLex lexValue( file.iName );
       
   156             // Read value
       
   157             lexValue.BoundedVal( hexValue, EHex, limit );
       
   158 
       
   159             aList.Append( hexValue );
       
   160             }
       
   161 
       
   162         // Finally delete directory
       
   163         delete directory;
       
   164         }
       
   165     else
       
   166         {
       
   167         COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ListPassiveConfigsL() - No files found" ) ) );
       
   168         }
       
   169 
       
   170     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ListPassiveConfigsL() - return" ) ) );
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CPsmCenRepStorage::ListPassiveConfigSetL
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CPsmCenRepStorage::ListPassiveConfigSetL( RConfigInfoArray& aPsmConfigArray )
       
   178     {
       
   179     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ListPassiveConfigSetL()" ) ) );
       
   180 
       
   181     // Read configuration information from config files and generate config array    
       
   182     CPsmStorage::CreateConfigArrayL( aPsmConfigArray, iMode );
       
   183 
       
   184     COMPONENT_TRACE( ( _L( "PSM Server - CPsmCenRepStorage::ListPassiveConfigSetL() - return" ) ) );
       
   185     }
       
   186 
       
   187 // End of file