|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // MACRO DEFINITION |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef __MSVENTRYFREEPOOL_H__ |
|
19 #define __MSVENTRYFREEPOOL_H__ |
|
20 |
|
21 |
|
22 /** |
|
23 * HEADER FILES |
|
24 */ |
|
25 #include <e32base.h> |
|
26 #include "msvcacheentry.h" |
|
27 #include "msvcachevisiblefolder.h" |
|
28 |
|
29 #if !defined(MSVSEARCHSORTCACHEMANAGER_H_) |
|
30 #include "msvsearchsortcachemanager.h" |
|
31 #endif |
|
32 |
|
33 |
|
34 class CMsvIndexAdapter; |
|
35 |
|
36 |
|
37 /** |
|
38 * The class provides implementation for pool of unused CMsvCacheEntry. |
|
39 * It is a singleton class. A CMsvIndexAdapter instance should create and |
|
40 * delete the instance of this class. It reads a msgcache.ini file which |
|
41 * stores amount of CMsvCacheEntry to be created at startup. The file |
|
42 * can be configured by licencees. |
|
43 * The destructor is made private so that only friend function can delete |
|
44 * the instance of this class. Moreover static function Destroy() should |
|
45 * be called to delete the instance of the class. |
|
46 * |
|
47 @internalComponent |
|
48 @prototype |
|
49 */ |
|
50 |
|
51 NONSHARABLE_CLASS (CMsvEntryFreePool): public CBase |
|
52 { |
|
53 public: |
|
54 static CMsvEntryFreePool* Instance(); |
|
55 CMsvCacheEntry* EntryL(); |
|
56 void ReleaseEntry(CMsvCacheEntry* aMsvCacheEntry, TBool aBypassTransaction = EFalse); |
|
57 void ReleaseEntrySet(RPointerArray<CMsvCacheEntry>& aMsvCacheEntryArray); |
|
58 void DoReleaseEntrySetL(RPointerArray<CMsvCacheEntry>& aMsvCacheEntryArray); |
|
59 void SetEssentialParam(TDblQue<CMsvCacheVisibleFolder>* aEntryCache, CMsvIndexAdapter* aAdapterObj); |
|
60 inline void BeginTransaction(); |
|
61 void RollbackTransaction(); |
|
62 void CommitTransaction(); |
|
63 inline TInt ExcessMemoryAllocated(); |
|
64 inline void RecordExcessMemoryL(CMsvCacheEntry* aEntry); |
|
65 void FlushExcessMemory(); |
|
66 void RoutineFreePoolCleanUpL(); |
|
67 void ReleaseEntryWithoutTransaction(CMsvCacheEntry* aMsvCacheEntry); |
|
68 |
|
69 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE |
|
70 inline TInt GetMaximumCacheSize(); |
|
71 inline TInt GetGranularity(); |
|
72 inline TInt GetCacheThreshold(); |
|
73 inline TInt GetCacheNumberOfEntriesCreated(); |
|
74 inline TInt GetNumberOfEntriesPresentInFreePool(); |
|
75 inline TInt GetMaxEntries(); |
|
76 inline TInt GetUsedEntriesCount(); |
|
77 #endif |
|
78 |
|
79 |
|
80 private: |
|
81 static CMsvEntryFreePool* CreateL(TDblQue<CMsvCacheVisibleFolder>* aEntryCache = NULL); |
|
82 CMsvEntryFreePool(TDblQue<CMsvCacheVisibleFolder>* aEntryCache); |
|
83 CMsvEntryFreePool(const CMsvEntryFreePool&); |
|
84 ~CMsvEntryFreePool(); |
|
85 void ConstructL(); |
|
86 void SwapEntriesL(TInt aEntriesToSwap); |
|
87 TInt ConvertMemToEntry(TInt aMem); |
|
88 TBool IsAllocationRequiredL(); |
|
89 void AllocateMemoryL(); |
|
90 TInt CacheSizeL(); |
|
91 |
|
92 #ifdef _DEBUG |
|
93 static void Destroy(CMsvEntryFreePool* aFreePoolInstance); |
|
94 #endif |
|
95 |
|
96 private: |
|
97 static CMsvEntryFreePool* iMsvEntryFreePool; |
|
98 RPointerArray<CMsvCacheEntry>* iMsvEntries; |
|
99 RPointerArray<CMsvCacheEntry> iUsedCacheEntries; |
|
100 |
|
101 // Reference to catch object. |
|
102 // Needed for entry swapping. |
|
103 TDblQue<CMsvCacheVisibleFolder>* iEntryCache; |
|
104 CMsvIndexAdapter* iAdapter; |
|
105 |
|
106 // Needed for transaction. |
|
107 RPointerArray<CMsvCacheEntry> iMsvTmpEntries; |
|
108 TBool isTransactionOpen; |
|
109 |
|
110 TInt iMsvMaximumCacheSize; |
|
111 //TInt iMsvGranularity; |
|
112 TInt iMsvCacheThreshold; |
|
113 TInt iMsvCacheNumberOfEntriesCreated; |
|
114 |
|
115 TInt iMsvInitialCacheSize; |
|
116 TInt iMsvCacheIncrement; |
|
117 TInt iMsvPercentageAllocated; |
|
118 TInt iMsvCacheSize; |
|
119 TInt iMsvSearchSortCache; |
|
120 TInt iMsvMaxEntries; |
|
121 |
|
122 /** |
|
123 * FRIEND CLASSES: |
|
124 * These classes can access destructor and Destroy(). |
|
125 */ |
|
126 friend class CMsvIndexAdapter; |
|
127 friend class CMsvServer; |
|
128 friend class CMSvSearchSortCacheManager; |
|
129 |
|
130 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE |
|
131 TBool iReleaseError; |
|
132 TInt iReleaseErrorOffset; |
|
133 friend class CTestEntryFreePool; |
|
134 friend class CTestDbAdapter; |
|
135 friend class CTestIndexTableEntry; |
|
136 friend class CTestVisibleFolder; |
|
137 #endif |
|
138 }; |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 /** |
|
145 *********** INLINE FUNCTIONS ************ |
|
146 */ |
|
147 |
|
148 void CMsvEntryFreePool::BeginTransaction() |
|
149 { |
|
150 isTransactionOpen = ETrue; |
|
151 } |
|
152 |
|
153 |
|
154 TInt CMsvEntryFreePool::ExcessMemoryAllocated() |
|
155 { |
|
156 if (iMsvMaxEntries < iMsvCacheNumberOfEntriesCreated) |
|
157 { |
|
158 return (iMsvCacheNumberOfEntriesCreated - iMsvMaxEntries); |
|
159 } |
|
160 return NULL; |
|
161 } |
|
162 |
|
163 |
|
164 /** |
|
165 * RecordExcessMemoryL() |
|
166 */ |
|
167 void CMsvEntryFreePool::RecordExcessMemoryL(CMsvCacheEntry* aEntry) |
|
168 { |
|
169 if(aEntry) |
|
170 { |
|
171 iUsedCacheEntries.AppendL(aEntry); |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 |
|
177 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE |
|
178 TInt CMsvEntryFreePool::GetMaximumCacheSize() |
|
179 { |
|
180 return iMsvMaximumCacheSize; |
|
181 } |
|
182 |
|
183 |
|
184 TInt CMsvEntryFreePool::GetCacheThreshold() |
|
185 { |
|
186 return iMsvCacheThreshold; |
|
187 } |
|
188 |
|
189 |
|
190 TInt CMsvEntryFreePool::GetCacheNumberOfEntriesCreated() |
|
191 { |
|
192 return iMsvCacheNumberOfEntriesCreated; |
|
193 } |
|
194 |
|
195 |
|
196 TInt CMsvEntryFreePool::GetNumberOfEntriesPresentInFreePool() |
|
197 { |
|
198 return iMsvEntries->Count(); |
|
199 } |
|
200 |
|
201 TInt CMsvEntryFreePool::GetMaxEntries() |
|
202 { |
|
203 return iMsvMaxEntries; |
|
204 } |
|
205 |
|
206 TInt CMsvEntryFreePool::GetUsedEntriesCount() |
|
207 { |
|
208 return iUsedCacheEntries.Count(); |
|
209 } |
|
210 |
|
211 #endif |
|
212 |
|
213 |
|
214 |
|
215 #endif |