|
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, const 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 RemoveAllFromCache(); |
|
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 /** |
|
129 * Get data index of the first name field |
|
130 */ |
|
131 TInt GetFirstNameIndex() const; |
|
132 |
|
133 /** |
|
134 * Get data index of the last name field |
|
135 */ |
|
136 TInt GetLastNameIndex() const; |
|
137 |
|
138 private: |
|
139 |
|
140 /** |
|
141 * Constructor |
|
142 */ |
|
143 CPcsCache(); |
|
144 |
|
145 /** |
|
146 * Second phase constructor |
|
147 */ |
|
148 void ConstructL(CPcsAlgorithm2* aAlgorithm, const TDesC& aURI, |
|
149 CPcsKeyMap& aKeyMap, TUint8 aUriId); |
|
150 |
|
151 /** |
|
152 * Utility function to add a contact to the pool |
|
153 */ |
|
154 void AddToPoolL(TUint64& aPoolMap, CPsData& aData); |
|
155 |
|
156 /** |
|
157 * Utility function |
|
158 */ |
|
159 void SetPoolMap(TUint64& aPoolMap, TInt aArrayIndex); |
|
160 |
|
161 /** |
|
162 * Utility function |
|
163 */ |
|
164 TBool GetPoolMap(TUint64& aPoolMap, TInt aArrayIndex); |
|
165 |
|
166 /** |
|
167 * Gets all the first characters of the words in the data field according |
|
168 * to which the contact should be inserted into cache. |
|
169 */ |
|
170 void GetFirstCharsForDataL( const TDesC& aData, RArray<TChar>& aFirstChars ) const; |
|
171 |
|
172 /** |
|
173 * Gets all the pool IDs matching the given characters. If there are two predictive |
|
174 * keyboards available, then pool IDs are given according to both keyboards. |
|
175 */ |
|
176 void GetPoolIdsForCharsL( const RArray<TChar>& aChars, RArray<TInt>& aPoolIds ) const; |
|
177 |
|
178 /** |
|
179 * Utility function |
|
180 */ |
|
181 void ComputeIndexOrder(); |
|
182 private: |
|
183 |
|
184 CPcsAlgorithm2* iAlgorithm; |
|
185 |
|
186 /* |
|
187 * Array of key maps |
|
188 */ |
|
189 typedef RPointerArray<CPcsPoolElement> R_PTR_ARRAY; |
|
190 RPointerArray<R_PTR_ARRAY> iKeyArr; |
|
191 |
|
192 /* |
|
193 * Hashmaps to remember the location of a contact in the pools |
|
194 */ |
|
195 RHashMap<TInt, TUint64> iCacheInfo; |
|
196 |
|
197 /* |
|
198 * Master pool of all contacts in this cache |
|
199 */ |
|
200 RPointerArray<CPsData> iMasterPool; |
|
201 |
|
202 /* |
|
203 * Master pool backup of all contacts in this cache when sortorder changed |
|
204 */ |
|
205 RPointerArray<CPsData> iMasterPoolBackup; |
|
206 |
|
207 /* |
|
208 * Not owned |
|
209 */ |
|
210 CPcsKeyMap* iKeyMap; |
|
211 |
|
212 /** |
|
213 * Owned. Refer to the database URI this cache is for. |
|
214 */ |
|
215 HBufC* iURI; |
|
216 |
|
217 /** |
|
218 * Internal URI id for this cache |
|
219 */ |
|
220 TInt8 iUriId; |
|
221 |
|
222 /** |
|
223 * Current status of this cache |
|
224 */ |
|
225 TInt iCacheStatus; |
|
226 |
|
227 /** |
|
228 * List of data fields (mapped to VPbk ids) supported by this cache |
|
229 */ |
|
230 RArray<TInt> iDataFields; |
|
231 /** |
|
232 * Sort order of data fields expected by the clients |
|
233 */ |
|
234 RArray<TInt> iSortOrder; |
|
235 |
|
236 /** |
|
237 * Order of indexes determined by correlating iDataFields and iSortOrder |
|
238 * Each CPsData data element fields need to be compared in this order |
|
239 * to get the client expected sort order for this cache. |
|
240 */ |
|
241 RArray<TInt> iIndexOrder; |
|
242 |
|
243 }; |
|
244 |
|
245 #endif // __CPCS_CACHE_ALGORITHM2_H__ |
|
246 // End of file |