phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/inc/CMultipleReadCmd.h
changeset 0 e686773b3f54
child 9 0d28c1c5b6dd
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 class that can read multiple contacts from ETel store.
       
    15 *                Uses ETel RMobilePhoneBookStore Read
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef VPBKSIMSTOREIMPL_CMULTIPLEREADCMD_H
       
    22 #define VPBKSIMSTOREIMPL_CMULTIPLEREADCMD_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <MVPbkSimCommand.h>
       
    26 #include <e32base.h>
       
    27 #include <etelmm.h>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CVPbkETelCntConverter;
       
    31 class CVPbkSimContactBuf;
       
    32 
       
    33 namespace VPbkSimStoreImpl {
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class CBasicStore;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 
       
    40 /**
       
    41 *  A class that can read multiple contacts from ETel store.
       
    42 *
       
    43 */
       
    44 NONSHARABLE_CLASS(CMultipleReadCmd) : public CActive,
       
    45                                       public MVPbkSimCommand
       
    46     {
       
    47     public:  // Constructors and destructor
       
    48         
       
    49         /**
       
    50         * Two-phased constructor. Reads all contacts from ETel.
       
    51         * @param aBasicStore the parent store for the contacts
       
    52         * @return a new instance of this class
       
    53         */
       
    54         static CMultipleReadCmd* NewLC( CBasicStore& aBasicStore );
       
    55         
       
    56         /**
       
    57         * Two-phased constructor.
       
    58         * @param aBasicStore the parent store for the contacts
       
    59         * @param aFirstIndexToRead the first ETel index to read ( >=1 )
       
    60         * @param aLastIndexToRead the last ETel index to read 
       
    61         * @return a new instance of this class
       
    62         */
       
    63         static CMultipleReadCmd* NewLC( CBasicStore& aBasicStore, 
       
    64                 TInt aFirstIndexToRead, TInt aLastIndexToRead );
       
    65         
       
    66         /**
       
    67         * Two-phased constructor.
       
    68         * 
       
    69         * This constructor is for the case that command is created before
       
    70         * the index is known.
       
    71         * @param aBasicStore the parent store for the contacts
       
    72         * @param aIndexToRead a reference to the index to read
       
    73         * @return a new instance of this class
       
    74         */
       
    75         static CMultipleReadCmd* NewLC( CBasicStore& aBasicStore, 
       
    76                 TInt& aIndexToRead );
       
    77 
       
    78         /**
       
    79         * Destructor.
       
    80         */
       
    81         virtual ~CMultipleReadCmd();
       
    82 
       
    83     public: // Functions from base classes
       
    84 
       
    85         /**
       
    86         * From MVPbkSimCommand
       
    87         */
       
    88         void Execute();
       
    89 
       
    90         /**
       
    91         * From MVPbkSimCommand
       
    92         */
       
    93         void AddObserverL( MVPbkSimCommandObserver& aObserver );
       
    94 
       
    95         /**
       
    96         * From MVPbkSimCommand
       
    97         */
       
    98         void CancelCmd();
       
    99         
       
   100     private: // Functions from base classes
       
   101         /**
       
   102         * From CActive
       
   103         */
       
   104         void RunL();
       
   105         
       
   106         /**
       
   107         * From CActive
       
   108         */
       
   109         void DoCancel();
       
   110         
       
   111         /**
       
   112         * From CActive
       
   113         */
       
   114         TInt RunError( TInt aError );
       
   115         
       
   116     private:    // Construction
       
   117 
       
   118         /**
       
   119         * C++ constructor.
       
   120         */
       
   121         CMultipleReadCmd( CBasicStore& aBasicStore,
       
   122             TInt aFirstIndexToRead, TInt aLastIndexToRead );
       
   123         
       
   124         /**
       
   125         * C++ constructor.
       
   126         */
       
   127         CMultipleReadCmd::CMultipleReadCmd( CBasicStore& aBasicStore, 
       
   128                 TInt& aIndexToRead );
       
   129             
       
   130         /**
       
   131         * By default Symbian 2nd phase constructor is private.
       
   132         */
       
   133         void ConstructL();
       
   134 
       
   135     private:    // New functions
       
   136         /// Completes the active object with given result
       
   137         void DoDummyRequest( TInt aResult );
       
   138         /// Does the ETel request
       
   139         void DoRequest();
       
   140         /// Checks that is buffer growing without control
       
   141         TBool IsBufferSizeInSane();
       
   142         /// Enlarges the buffer if it wasn't big enough
       
   143         void EnlargeBufferL();
       
   144         /// Converts contact from buffer
       
   145         void ConvertContactsL();
       
   146         /// Returns ETrue if buffer was big enough
       
   147         TBool WasBufferBigEnough();
       
   148         /// Inserts contacts to contact array
       
   149         void UpdateContactArrayL();
       
   150         /// Fills buffer with zeros and sets the length to zero
       
   151         void ResetBuffer();
       
   152 
       
   153     private:    // Data
       
   154         /// The parent store
       
   155         CBasicStore& iBasicStore;
       
   156         /// The first ETel index to read, minimum is 1, not zero.
       
   157         TInt iFirstIndexToRead;
       
   158         /// The amount contacts that is tried to read at once
       
   159         TInt iLastIndexToRead;
       
   160         /// The index to read in the case the index is not known when
       
   161         /// the command is created.
       
   162         const TInt& iIndexToRead;
       
   163         /// Own: a buffer for ETel contacts
       
   164         HBufC8* iBuffer;
       
   165         /// A pointer to the buffer
       
   166         TPtr8 iBufferPtr;
       
   167         /// Own: converts ETel contacts to own format
       
   168         CVPbkETelCntConverter* iCntConverter;
       
   169         /// an array for the contacts. Owns contact until contact array
       
   170         /// takes the ownership
       
   171         RPointerArray<CVPbkSimContactBuf> iCntArray;
       
   172         /// Ref: only one observer supported
       
   173         MVPbkSimCommandObserver* iObserver;
       
   174     };
       
   175 } // namespace VPbkSimStoreImpl
       
   176 #endif      // VPBKSIMSTOREIMPL_CMULTIPLEREADCMD_H
       
   177             
       
   178 // End of File