|
1 /* |
|
2 * Copyright (c) 2004 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: Implements one store entry of the storage server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __CPENGDATAENTRY_H__ |
|
21 #define __CPENGDATAENTRY_H__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "PEngStorageGlobals.h" |
|
27 |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class RFs; |
|
31 class MPEngHandlerListenSIDs; |
|
32 |
|
33 /** |
|
34 * Implements one store entry of the storage server |
|
35 * Store entries are collected by the Storage folders |
|
36 * @since 3.0 |
|
37 */ |
|
38 |
|
39 class CPEngDataEntry |
|
40 : public CBase |
|
41 { |
|
42 public: // Constructors and destructor |
|
43 |
|
44 /** |
|
45 * Two-phased constructor. |
|
46 */ |
|
47 static CPEngDataEntry* NewL( RFs& aFs, |
|
48 const TDesC& aTempFolder, |
|
49 const TDesC& aKey, |
|
50 TPEngStorageType aType ); |
|
51 |
|
52 /** |
|
53 * Two-phased constructor. |
|
54 */ |
|
55 static CPEngDataEntry* NewLC( RFs& aFs, |
|
56 const TDesC& aTempFolder, |
|
57 const TDesC& aKey, |
|
58 TPEngStorageType aType ); |
|
59 |
|
60 /** |
|
61 * Destructor. |
|
62 */ |
|
63 virtual ~CPEngDataEntry(); |
|
64 |
|
65 public: // New functions of the base class |
|
66 |
|
67 /** |
|
68 * Returns the data of this entry |
|
69 * Function leaves with KErrNotFound if data is NULL pointer |
|
70 * Otherwise not other leave is allowed |
|
71 * |
|
72 * @since 3.0 |
|
73 * @return descriptor with data of store entry. |
|
74 */ |
|
75 const TDesC8& DataL() const; |
|
76 |
|
77 /** |
|
78 * Returns the key of this entry. |
|
79 * |
|
80 * @since 3.0 |
|
81 * @return descriptor with the key |
|
82 */ |
|
83 const TDesC& Key() const; |
|
84 |
|
85 /** |
|
86 * Return pointer to key buffer, needed when ordering entries in B-tree. |
|
87 * |
|
88 * @since 3.0 |
|
89 * @return pointer to key buffer. |
|
90 */ |
|
91 HBufC** KeyBuffer(); |
|
92 |
|
93 /** |
|
94 * Get Lock Status |
|
95 * |
|
96 * @since 3.0 |
|
97 * @param aPriority priority of the lock status to check |
|
98 * @return lock status |
|
99 */ |
|
100 TBool LockStatus( TPengStorageLockPriority aPriority ) const; |
|
101 |
|
102 /** |
|
103 * Get lock count |
|
104 * Get lock count, no matter the priority of the lock |
|
105 * |
|
106 * @since 3.0 |
|
107 * @return count |
|
108 */ |
|
109 TInt LockCount() const; |
|
110 |
|
111 /** |
|
112 * Increase Lock count of if client is allowed |
|
113 * |
|
114 * @since 3.0 |
|
115 * @param aSessionID ID of the Session command came from |
|
116 * @param aSubSessionID ID of the Sub-session command came from |
|
117 * @param aPriority priority of the lock command |
|
118 * |
|
119 */ |
|
120 TInt IncreaseLockCountL( TInt32 aSessionID, |
|
121 TInt aSubSessionID, |
|
122 TPengStorageLockPriority aPriority ); |
|
123 |
|
124 /** |
|
125 * Decrease Lock count of if client is allowed |
|
126 * |
|
127 * @since 3.0 |
|
128 * @param aSessionID ID of the Session command came from |
|
129 * @param aSubSessionID ID of the Sub-session command came from |
|
130 */ |
|
131 TInt DecreaseLockCountL( TBool aNotifyActive, |
|
132 TInt32 aSessionID, |
|
133 TInt aSubSessionID, |
|
134 CPEngDataEntry*& aNotifEntry ); |
|
135 |
|
136 /** |
|
137 * Returns Current version of the store entry |
|
138 * |
|
139 * @since 3.0 |
|
140 * @return current version number |
|
141 */ |
|
142 TInt Version() const; |
|
143 |
|
144 /** |
|
145 * Returns Time of the last modification |
|
146 * |
|
147 * @since 3.0 |
|
148 * @return time |
|
149 */ |
|
150 const TTime& LastModification() const; |
|
151 |
|
152 /** |
|
153 * Asserts that store entry's storage type is required one. |
|
154 * If not, leaves with KErrArgument. |
|
155 * |
|
156 * @since 3.0 |
|
157 * @param aType The supposed storage type. |
|
158 */ |
|
159 void AssertStorageTypeL( TPEngStorageType aType ) const; |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 public: // New functions of the base class with default implementation |
|
165 |
|
166 /** |
|
167 * Set entry data, owner ship of the passed buffer is called by |
|
168 * the function. Descriptor buffer is in the clean up stack |
|
169 * and should be poped/destroyed when when it is not needed. |
|
170 * If derived class defines own implementation of this function |
|
171 * CheckVersionNumberL() should be called before any operation |
|
172 * and UpdateVersionNumber() on the end of the new implementation |
|
173 * before function returns to caller. See CheckVersionNumberL() |
|
174 * and UpdateVersionNumber() description |
|
175 * |
|
176 * Default implementation check Version, deletes old buffer, |
|
177 * adopts new buffer, and updates version number |
|
178 * |
|
179 * @since 3.0 |
|
180 * @param aData data buffer to be set to store entry |
|
181 * function takes ownership of the buffer descriptor |
|
182 * @param aType data type for check it, also Version check |
|
183 * is determined from the type |
|
184 * @return if notification needs to be scheduled, return valid pointer |
|
185 */ |
|
186 virtual const CPEngDataEntry* |
|
187 SetDataLX( HBufC8* aNewData, |
|
188 TPEngStorageType aType, |
|
189 TBool aNotifyActive, |
|
190 TInt32 aSessionID, |
|
191 TInt aSubSessionID ); |
|
192 |
|
193 /** |
|
194 * Deletes store entry from storage |
|
195 * Derived version can do additional cleaning if needed |
|
196 * |
|
197 * Default implementation removes permanent part of the store |
|
198 * entry, if there is, from the file system |
|
199 * @since 3.0 |
|
200 */ |
|
201 virtual void DeleteStoreEntry(); |
|
202 |
|
203 |
|
204 /** |
|
205 * Set hashed path of the store entry |
|
206 * Function takes ownership of the passed des buffer |
|
207 * |
|
208 * @since 3.0 |
|
209 * @param aPath new hached path |
|
210 */ |
|
211 virtual void SetHashedPath( HBufC* aPath ); |
|
212 |
|
213 /** |
|
214 * Initializes store entry. This function checks the type |
|
215 * of thes store entry and load data from disc if needed |
|
216 * This call always follows construction of the store entry |
|
217 * before store entry si added to the tree. |
|
218 * If store entry does not exists (for example for permanents entry) |
|
219 * , function returns EFalse, so caller is informed that |
|
220 * this entry has not meaning to be held if some data will not be |
|
221 * stored into it |
|
222 * |
|
223 * @return ETrue if store entry has content |
|
224 * @since 3.0 |
|
225 */ |
|
226 virtual TBool InitializeStoreEntryL(); |
|
227 |
|
228 public: // new functions for observing support |
|
229 |
|
230 /** |
|
231 * |
|
232 * @since 3.0 |
|
233 */ |
|
234 void AddObserverL( MPEngHandlerListenSIDs& aObserver ); |
|
235 |
|
236 /** |
|
237 * |
|
238 * @since 3.0 |
|
239 */ |
|
240 void RemoveObserver( MPEngHandlerListenSIDs& aObserver ); |
|
241 |
|
242 |
|
243 protected: // help functions of base class |
|
244 |
|
245 /** |
|
246 * Checks version number of passed data and internal buffer |
|
247 * if they do not match. |
|
248 * and function leave with KErrAccessDenied |
|
249 * Version control flag is taken in account |
|
250 * |
|
251 * @since 3.0 |
|
252 * @param aNewData data buffer. |
|
253 * @param aVersionControl flag is version if checked ETrue = yes |
|
254 */ |
|
255 void CheckVersionNumberL( const TDesC8& aNewData, TPEngStorageType aType ); |
|
256 |
|
257 /** |
|
258 * Checks if passed sub-session is correct or not, in case lock |
|
259 * is active. Function leave with KErrLocked if passed information |
|
260 * does not match if lock was activated from passed sub-session, |
|
261 * function does nothing |
|
262 * |
|
263 * @since 3.0 |
|
264 * @param aSessionID session |
|
265 * @param aSubSessionID sub-session |
|
266 */ |
|
267 void CheckLockSubSessionL( TInt32 aSessionID, TInt aSubSessionID ); |
|
268 |
|
269 /** |
|
270 * Updates version number of the Store Entry |
|
271 * This suppose to be called when SetDataL function is called |
|
272 * |
|
273 * @since 3.0 |
|
274 * @param aData is data buffer. |
|
275 */ |
|
276 void UpdateVersionNumber(); |
|
277 |
|
278 protected: // private constructors |
|
279 |
|
280 /** |
|
281 * C++ default constructor. |
|
282 */ |
|
283 CPEngDataEntry( RFs& aFs, |
|
284 const TDesC& aTempFolder, |
|
285 TPEngStorageType aType ); |
|
286 |
|
287 /** |
|
288 * Symbian second phase constructor |
|
289 */ |
|
290 void BaseConstructL( const TDesC& aKey ); |
|
291 |
|
292 private: // new private functions |
|
293 |
|
294 void UpdatePermanentPartL( const TDesC8& aNewData ); |
|
295 |
|
296 void TrySeekPermanentPartL( RReadStream& aStream, TInt& aPermanentDataLength ) const; |
|
297 |
|
298 |
|
299 HBufC8* PermanentFromFileOrNullL() const; |
|
300 |
|
301 void NotifyUpdate(); |
|
302 |
|
303 protected: // Protected Data to allow derivation |
|
304 |
|
305 /// REF: File server reference |
|
306 RFs& iFs; |
|
307 |
|
308 /// REF: Temp folder of the storage |
|
309 const TDesC& iTempFolder; |
|
310 |
|
311 /// OWN: Storage Type |
|
312 const TPEngStorageType iType; |
|
313 |
|
314 /// OWN: Storage ID of the Storage Entry |
|
315 HBufC* iKey; |
|
316 |
|
317 /// OWN: Hashed Store ID with the path |
|
318 HBufC* iHashedPath; |
|
319 |
|
320 /// OWN: Data of the stored entry |
|
321 HBufC8* iData; |
|
322 |
|
323 /// OWN: Last time entry was modified |
|
324 TTime iModified; |
|
325 |
|
326 /// OWN: Version count of the the entry ( used for confirmation) |
|
327 TInt32 iVersion; |
|
328 |
|
329 /// OWN: Flag if entry is locked, ETrue = Entry locked |
|
330 TInt iLockCount; |
|
331 |
|
332 /// OWN: Lock Session |
|
333 TInt iLockSession; |
|
334 |
|
335 /// OWN: Lock Sub-session |
|
336 TInt iLockSubSession; |
|
337 |
|
338 /// OWN: Lock Priority |
|
339 TPengStorageLockPriority iLockPriority; |
|
340 |
|
341 /// OWN: List of observers |
|
342 /// Entries not owned |
|
343 RPointerArray<MPEngHandlerListenSIDs> iObservers; |
|
344 }; |
|
345 |
|
346 #endif |