predictivesearch/PcsAlgorithm/Algorithm2/inc/CPcsCache.h
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Used to cache the contacts in memory
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CPCS_CACHE_ALGORITHM2_H__
       
    19 #define __CPCS_CACHE_ALGORITHM2_H__
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <e32hashtab.h>
       
    24 
       
    25 #include "CPsData.h"
       
    26 #include "CPcsKeyMap.h"
       
    27 #include "CPcsPoolElement.h"
       
    28 #include "TCacheInfo.h"
       
    29 #include "CPcsDefs.h"
       
    30 
       
    31 class CPcsAlgorithm2;
       
    32 // CLASS DECLARATION
       
    33 class CPcsCache : public CBase
       
    34     {
       
    35 
       
    36 public:
       
    37 
       
    38     /**
       
    39      * Two phase construction
       
    40      */
       
    41     static CPcsCache* NewL(CPcsAlgorithm2* aAlgorithm, TDesC& aURI, 
       
    42                            CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
    43 
       
    44     /**
       
    45      * Virtual destructor
       
    46      */
       
    47     virtual ~CPcsCache();
       
    48 
       
    49     /**
       
    50      * Returns the database URI this cache support
       
    51      */
       
    52     TDesC& GetURI();
       
    53 
       
    54     /**
       
    55      * Get CPcsPoolElement for a key id
       
    56      */
       
    57     void GetContactsForKeyL(TInt aKeyId, RPointerArray<CPcsPoolElement>& aData);
       
    58 
       
    59     /**
       
    60      * Get all cached content
       
    61      */
       
    62     void GetAllContentsL(RPointerArray<CPsData>& aData);
       
    63 
       
    64     /**
       
    65      * Add a data element to the cache
       
    66      */
       
    67     void AddToCacheL(CPsData& aData);
       
    68 
       
    69     /**
       
    70      * Removes a data element from the cache
       
    71      */
       
    72     void RemoveFromCacheL(TInt aItemId);
       
    73 
       
    74     /**
       
    75      * Removes all data elements from the cache
       
    76      */
       
    77     void RemoveAllFromCacheL();
       
    78 
       
    79     /**
       
    80      * Sets data fields to the cache
       
    81      */
       
    82     void SetDataFields(RArray<TInt>& aDataFields);
       
    83 
       
    84     /**
       
    85      * Gets data fields from the cache
       
    86      */
       
    87     void GetDataFields(RArray<TInt>& aDataFields);
       
    88 
       
    89     /**
       
    90      * Updates the caching status for this cache
       
    91      */
       
    92     void UpdateCacheStatus(TInt aStatus);
       
    93 
       
    94     /**
       
    95      * Returns the cache status for this cache
       
    96      */
       
    97     TInt GetCacheStatus();
       
    98 
       
    99     /**
       
   100      * Returns the UriId
       
   101      */
       
   102     TUint8 GetUriId();
       
   103 
       
   104     /**
       
   105      * Returns the URI for this cache
       
   106      */
       
   107     HBufC* GetUri();
       
   108     /**
       
   109      * Sets sort order for data fields
       
   110      */
       
   111     void SetSortOrder(RArray<TInt>& aSortOrder);
       
   112 
       
   113     /**
       
   114      * Gets sort order for data fields
       
   115      */
       
   116     void GetSortOrder(RArray<TInt>& aSortOrder);
       
   117 
       
   118     /**
       
   119      * Get the index order corresponding to the sort order
       
   120      */
       
   121     void GetIndexOrder(RArray<TInt>& aIndexOrder);
       
   122     
       
   123     /**
       
   124      * Resort data according to the new sortorder
       
   125      */
       
   126     void ResortdataInPoolsL();
       
   127 
       
   128 private:
       
   129 
       
   130     /**
       
   131      * Constructor
       
   132      */
       
   133     CPcsCache();
       
   134 
       
   135     /**
       
   136      * Second phase constructor
       
   137      */
       
   138     void ConstructL(CPcsAlgorithm2* aAlgorithm, TDesC& aURI,
       
   139                     CPcsKeyMap& aKeyMap, TUint8 aUriId);
       
   140 
       
   141     /**
       
   142      * Utility function to add a contact to the pool
       
   143      */
       
   144     void AddToPoolL(TInt& aInfo, CPsData& data);
       
   145 
       
   146     /**
       
   147      * Utility function 
       
   148      */
       
   149     void SetPoolMap(TInt& aPoolMap, TInt aPoolId);
       
   150 
       
   151     /**
       
   152      * Utility function 
       
   153      */
       
   154     TBool GetPoolMap(TInt& aPoolMap, TInt arrayIndex);
       
   155 
       
   156     /**
       
   157      * Utility function
       
   158      */
       
   159     void ComputeIndexOrder();
       
   160 private:
       
   161 
       
   162     CPcsAlgorithm2* iAlgorithm;
       
   163 
       
   164     /*
       
   165      * Array of key maps
       
   166      */
       
   167     typedef RPointerArray<CPcsPoolElement> R_PTR_ARRAY;
       
   168     RPointerArray<R_PTR_ARRAY> keyArr;
       
   169 
       
   170     /*
       
   171      * Hashmaps to remember the location of a contact in the pools
       
   172      */
       
   173     RHashMap<TInt, TInt> cacheInfo;
       
   174 
       
   175     /*
       
   176      * Master pool of all contacts in this cache
       
   177      */
       
   178     RPointerArray<CPsData> masterPool;
       
   179     
       
   180     /*
       
   181     * Master pool backup of all contacts in this cache when sortorder changed
       
   182     */
       
   183     RPointerArray<CPsData> masterPoolBackup;  
       
   184 
       
   185     /*
       
   186      * Not owned
       
   187      */
       
   188     CPcsKeyMap* keyMap;
       
   189 
       
   190     /**
       
   191      * Owned. Refer to the database URI this cache is for.
       
   192      */
       
   193     HBufC* iURI;
       
   194 
       
   195     /**
       
   196      * Internal URI id for this cache
       
   197      */
       
   198     TInt8 iUriId;
       
   199 
       
   200     /**
       
   201      * Current status of this cache
       
   202      */
       
   203     TInt iCacheStatus;
       
   204 
       
   205     /**
       
   206      * List of data fields (mapped to VPbk ids) supported by this cache
       
   207      */
       
   208     RArray<TInt> iDataFields;
       
   209     /**
       
   210      * Sort order of data fields expected by the clients
       
   211      */
       
   212     RArray<TInt> iSortOrder;
       
   213 
       
   214     /**
       
   215      * Order of indexes determined by correlating iDataFields and iSortOrder
       
   216      * Each CPsData data element fields need to be compared in this order
       
   217      * to get the client expected sort order for this cache.
       
   218      */
       
   219     RArray<TInt> iIndexOrder;
       
   220 
       
   221     };
       
   222 
       
   223 #endif // __CPCS_CACHE_ALGORITHM2_H__
       
   224 // End of file