phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CCustomStore.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 store that uses ETel custom API due to cache in TSY
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCustomStore.h"
       
    22 
       
    23 #include <VPbkDebug.h>
       
    24 #include "CPhone.h"
       
    25 #include "CCacheReadyNotificationCmd.h"
       
    26 #include "CCacheStatusCmd.h"
       
    27 #include "CSequentialCompositeCmd.h"
       
    28 #include "CParallelCompositeCmd.h"
       
    29 
       
    30 namespace VPbkSimStoreImpl {
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CCustomStore::CCustomStore
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CCustomStore::CCustomStore( TStoreParams& aParams )
       
    41 :   CBasicStore( aParams )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCustomStore::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CCustomStore::ConstructL()
       
    51     {
       
    52     CBasicStore::ConstructL();
       
    53     }
       
    54     
       
    55 // Destructor
       
    56 CCustomStore::~CCustomStore()
       
    57     {
       
    58     CancelRequests();
       
    59     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
    60         "VPbkSimStoreImpl: RMmCustomAPI::Close"));
       
    61     iCustomAPI.Close();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CCustomStore::OpenETelStoreL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CCustomStore::OpenETelStoreL()
       
    69     {
       
    70     CBasicStore::OpenETelStoreL();
       
    71     User::LeaveIfError( iCustomAPI.Open( Phone().ETelPhone() ) );
       
    72     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
    73         "VPbkSimStoreImpl: RMmCustomAPI::Open handle %d"),
       
    74         iCustomAPI.SubSessionHandle());
       
    75     }
       
    76 
       
    77 void CCustomStore::CloseETelStore()
       
    78     {
       
    79     CBasicStore::CloseETelStore();
       
    80     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
    81         "VPbkSimStoreImpl: RMmCustomAPI::Close handle %d"),
       
    82         iCustomAPI.SubSessionHandle());
       
    83     iCustomAPI.Close();
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCustomStore::CreateInitCommandL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 MVPbkSimCommand* CCustomStore::CreateInitCommandL( 
       
    91         MVPbkSimCommandObserver& aObserver )
       
    92     {
       
    93     // Create a init command chain
       
    94     CCompositeCmdBase* cmdChain = CSequentialCompositeCmd::NewLC();
       
    95     cmdChain->AddObserverL( aObserver );
       
    96     
       
    97     // Add notication command that waits until the TSY cache is ready if
       
    98     // the cache is not ready
       
    99     AddTSYCacheReadyCmdToChainL( *cmdChain );
       
   100 
       
   101     // Get phonebook information to know the current state of the phonebook
       
   102     AddGetInfoCmdToChainL( *cmdChain );
       
   103 
       
   104     // Start reading contacts after the total amount of contacts is known
       
   105     AddMultipleReadCmdToChainL( *cmdChain, KErrNotFound, KErrNotFound );
       
   106 
       
   107     CleanupStack::Pop( cmdChain );
       
   108     return cmdChain;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CCustomStore::AddTSYCacheReadyCmdToChainL
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CCustomStore::AddTSYCacheReadyCmdToChainL( CCompositeCmdBase& aCmdChain )
       
   116     {
       
   117     // Create a parallel composite to ensure that we don't jam
       
   118     // to TSY cache waiting. We must use both cache status command and
       
   119     // cache ready notification command and they must also co-operate.
       
   120     // The composite completes when the first subcommand tells it that
       
   121     // cache is ready.
       
   122     CCompositeCmdBase* composite = CParallelCompositeCmd::NewLC(
       
   123             CParallelCompositeCmd::EFirstSubCommandDone );
       
   124     
       
   125     CCacheStatusCmd* statusCmd = CCacheStatusCmd::NewLC( *this, iCacheStatus );
       
   126     // Notification command needs to re-execute CCacheStatusCmd in some
       
   127     // situation.
       
   128     CCacheReadyNotificationCmd* notifyCmd = 
       
   129         CCacheReadyNotificationCmd::NewLC( *this, iCacheStatus, *statusCmd );
       
   130     // The order of subcommand has a meaning. TSY must get notification
       
   131     // request before cache status request. Otherwise there is a possiblity
       
   132     // that we miss the notification and the request never completes.
       
   133     composite->AddSubCommandL( notifyCmd );
       
   134     CleanupStack::Pop( notifyCmd );
       
   135     composite->AddSubCommandL( statusCmd );
       
   136     CleanupStack::Pop( statusCmd );
       
   137     
       
   138     aCmdChain.AddSubCommandL( composite );
       
   139     CleanupStack::Pop( composite );
       
   140     }
       
   141 } // namespace VPbkSimStoreImpl
       
   142 //  End of File