phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CCacheStatusCmd.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A command that queries the current TSY cache status.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCacheStatusCmd.h"
       
    22 
       
    23 #include <VPbkDebug.h>
       
    24 #include "CCustomStore.h"
       
    25 #include "VPbkSimStoreImplError.h"
       
    26 
       
    27 namespace VPbkSimStoreImpl {
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCacheStatusCmd::CCacheStatusCmd
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CCacheStatusCmd::CCacheStatusCmd( CCustomStore& aStore, 
       
    38         RMmCustomAPI::TPndCacheStatus& aCacheStatus )
       
    39         :   CActive( EPriorityStandard ),
       
    40             iStore( aStore ),
       
    41             iCacheStatus( aCacheStatus )
       
    42     {
       
    43     CActiveScheduler::Add( this );
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CCacheStatusCmd::NewLC
       
    48 // Two-phased constructor.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CCacheStatusCmd* CCacheStatusCmd::NewLC( CCustomStore& aStore, 
       
    52         RMmCustomAPI::TPndCacheStatus& aCacheStatus )
       
    53     {
       
    54     CCacheStatusCmd* self = 
       
    55         new( ELeave ) CCacheStatusCmd( aStore, aCacheStatus );
       
    56     CleanupStack::PushL( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // Destructor
       
    61 CCacheStatusCmd::~CCacheStatusCmd()
       
    62     {
       
    63     CancelCmd();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CCacheStatusCmd::Execute
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CCacheStatusCmd::Execute()
       
    71     {
       
    72     __ASSERT_DEBUG( iObserver,
       
    73         VPbkSimStoreImpl::Panic( EPreCondCCacheStatusCmdExecute ) );
       
    74         
       
    75     iStoreName.Copy(iStore.ETelName());
       
    76     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
    77         "VPbkSimStoreImpl: RMmCustomAPI::GetPndCacheStatus h%d request %S"),
       
    78         iStore.CustomAPI().SubSessionHandle(),&iStore.ETelName());
       
    79     iStore.CustomAPI().GetPndCacheStatus( iStatus, iCacheStatus, iStoreName);
       
    80     SetActive();
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CCacheStatusCmd::AddObserverL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CCacheStatusCmd::AddObserverL( MVPbkSimCommandObserver& aObserver )
       
    88     {
       
    89     __ASSERT_DEBUG( !iObserver,
       
    90         VPbkSimStoreImpl::Panic( EPreCondCCacheStatusCmdAddObserverL ) );
       
    91     iObserver = &aObserver;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CCacheStatusCmd::CancelCmd
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CCacheStatusCmd::CancelCmd()
       
    99     {
       
   100     CActive::Cancel();
       
   101     }
       
   102         
       
   103 // -----------------------------------------------------------------------------
       
   104 // CCacheStatusCmd::RunL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CCacheStatusCmd::RunL()
       
   108     {
       
   109     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   110         "VPbkSimStoreImpl: RMmCustomAPI::GetPndCacheStatus h%d complete %d,\
       
   111         store %S, iCacheStatus %d"),
       
   112         iStore.CustomAPI().SubSessionHandle(), iStatus.Int(),
       
   113         &iStoreName, iCacheStatus);
       
   114     
       
   115     if ( iStatus.Int() == KErrNone )
       
   116         {
       
   117         switch ( iCacheStatus )
       
   118             {
       
   119             case RMmCustomAPI::ECacheNotReady:
       
   120                 {
       
   121                 // It's CCacheReadyNotificationCmd's responsibility
       
   122                 // to handle cache waiting. Don't complete command because
       
   123                 // it would complete the composite command. 
       
   124                 break;
       
   125                 }
       
   126             case RMmCustomAPI::ECacheReady:
       
   127             case RMmCustomAPI::ECacheNotUsed:
       
   128                 {
       
   129                 // ok, just complete the command and proceed.
       
   130                 iObserver->CommandDone( *this );
       
   131                 break;
       
   132                 }
       
   133             case RMmCustomAPI::ECacheFailed:
       
   134                 {
       
   135                 // Cache failed but the reason is not known.
       
   136                 iObserver->CommandError( *this, KErrUnknown );
       
   137                 }
       
   138             }
       
   139         }
       
   140     else
       
   141         {
       
   142         iObserver->CommandError( *this, iStatus.Int() );
       
   143         }
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CCacheStatusCmd::RunL
       
   148 // -----------------------------------------------------------------------------
       
   149 //    
       
   150 void CCacheStatusCmd::DoCancel()
       
   151     {
       
   152     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   153         "VPbkSimStoreImpl: RMmCustomAPI::GetPndCacheStatus h%d Cancel"),
       
   154         iStore.CustomAPI().SubSessionHandle());
       
   155     iStore.CustomAPI().CancelAsyncRequest( ECustomGetPndCacheStatusIPC );
       
   156     }
       
   157 
       
   158 } // namespace VPbkSimStoreImpl
       
   159 //  End of File