appinstaller/AppMngr2/src/appmngr2logdatabase.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Implements CAppMngr2LogDatabase class to access installation log
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2logdatabase.h"        // CAppMngr2LogDatabase
       
    20 #include "appmngr2logdatabaseentry.h"   // CAppMngr2LogDatabaseEntry
       
    21 #include <SWInstLogTaskParam.h>         // KLogReadTableSQL
       
    22 
       
    23 _LIT( KLogSecureFormat, "SECURE%S" );
       
    24 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CAppMngr2LogDatabase::CAppMngr2LogDatabase()
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CAppMngr2LogDatabase::CAppMngr2LogDatabase()
       
    33     {
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CAppMngr2LogDatabase::NewL()
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CAppMngr2LogDatabase* CAppMngr2LogDatabase::NewL()
       
    41     {
       
    42     CAppMngr2LogDatabase* self = new (ELeave) CAppMngr2LogDatabase;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CAppMngr2LogDatabase::Entries()
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 const RPointerArray<CAppMngr2LogDatabaseEntry>& CAppMngr2LogDatabase::Entries() const
       
    54     {
       
    55     return iEntries;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CAppMngr2LogDatabase::ConstructL()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CAppMngr2LogDatabase::ConstructL()
       
    63     {
       
    64     User::LeaveIfError( iDbSession.Connect() );
       
    65 
       
    66     HBufC* formatString = HBufC::NewLC( KLogSecureFormat().Length() +
       
    67             SwiUI::KLogAccessPolicyUid.Name().Length() );
       
    68     TPtr ptr( formatString->Des() );
       
    69     TUidName uidStr = SwiUI::KLogAccessPolicyUid.Name();
       
    70     ptr.Format( KLogSecureFormat, &uidStr );
       
    71 
       
    72     TInt err = iLogDb.Open( iDbSession, SwiUI::KLogDatabaseName, *formatString );
       
    73     CleanupStack::PopAndDestroy( formatString );
       
    74     if( err == KErrNone )
       
    75         {
       
    76         RDbView view;
       
    77         User::LeaveIfError( view.Prepare( iLogDb, TDbQuery( SwiUI::KLogReadTableSQL ),
       
    78                 view.EReadOnly ) );
       
    79         CleanupClosePushL( view );
       
    80         
       
    81         view.EvaluateAll();
       
    82         for( view.FirstL(); view.AtRow(); view.NextL() )
       
    83             {
       
    84             CAppMngr2LogDatabaseEntry* entry = CAppMngr2LogDatabaseEntry::NewL( view );
       
    85             CleanupStack::PushL( entry );
       
    86             iEntries.AppendL( entry );      // takes ownership
       
    87             CleanupStack::Pop( entry );
       
    88             }
       
    89     
       
    90         CleanupStack::PopAndDestroy( &view );
       
    91         }
       
    92     else
       
    93         {
       
    94         // handle "database not found" like "database is empty"
       
    95         if( err != KErrNotFound && err != KErrPathNotFound )
       
    96             {
       
    97             User::Leave( err );
       
    98             }
       
    99         }
       
   100     
       
   101     iLogDb.Close();
       
   102     iDbSession.Close();
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CAppMngr2LogDatabase::~CAppMngr2LogDatabase()
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CAppMngr2LogDatabase::~CAppMngr2LogDatabase()
       
   110     {
       
   111     iEntries.ResetAndDestroy();
       
   112     iLogDb.Close();
       
   113     iDbSession.Close();
       
   114     }
       
   115