|
1 /* |
|
2 * Copyright (c) 2005-2009 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: This is Manipulation engine to manage adding,* |
|
15 */ |
|
16 |
|
17 #ifndef __MDSMANIPULATIONENGINE_H__ |
|
18 #define __MDSMANIPULATIONENGINE_H__ |
|
19 |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "mdscommoninternal.h" |
|
23 #include "mdsgarbagecollector.h" |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class CMdSSchema; |
|
27 class CMdsSchema; |
|
28 class CMdSNotifier; |
|
29 class CMdSServerSession; |
|
30 class CMdSObjectLockList; |
|
31 class CMdCSerializationBuffer; |
|
32 class CMdSSqlObjectManipulate; |
|
33 |
|
34 // CONSTANT DECLARATION |
|
35 const TInt KGarbageCollectionDelay = 60; // test 1 minute |
|
36 |
|
37 // CLASS DECLARATION |
|
38 |
|
39 /** |
|
40 * CMdSManipulationEngine. |
|
41 * Class for manipulating metadata database entries. |
|
42 */ |
|
43 class CMdSManipulationEngine : public CBase, public MMdSGarbageCollectorObserver |
|
44 { |
|
45 public: // Constructors and destructors |
|
46 |
|
47 /** |
|
48 * NewL. |
|
49 * Two-phased constructor. |
|
50 * @param aObjectManipulate pointer to object manipulator |
|
51 * @return Pointer to created CMdSManipulationEngine object. |
|
52 */ |
|
53 static CMdSManipulationEngine* NewL( CMdsSchema& aSchema, |
|
54 CMdSNotifier& aNotifier, CMdSObjectLockList& aLockList ); |
|
55 |
|
56 /** |
|
57 * NewLC. |
|
58 * Two-phased constructor. |
|
59 * @param aObjectManipulate pointer to object manipulator |
|
60 * @return Pointer to created CMdSManipulationEngine object. |
|
61 */ |
|
62 static CMdSManipulationEngine* NewLC( CMdsSchema& aSchema, |
|
63 CMdSNotifier& aNotifier, CMdSObjectLockList& aLockList ); |
|
64 |
|
65 /** |
|
66 * ~CMdSManipulationEngine. |
|
67 * Destructor. |
|
68 */ |
|
69 virtual ~CMdSManipulationEngine(); |
|
70 |
|
71 public: |
|
72 |
|
73 /** |
|
74 * Adds object to DB from serialized buffer and put a result item IDs |
|
75 * to result buffer |
|
76 */ |
|
77 void AddL( CMdCSerializationBuffer& aBuffer, |
|
78 CMdCSerializationBuffer& aResultBuffer, |
|
79 const CMdSServerSession* aServerSession ); |
|
80 |
|
81 /** |
|
82 * Removes items from the database |
|
83 * @param aBuffer serialized TMdCItemIds object |
|
84 * @param aSuccessfulBuffer successfully removed objects |
|
85 */ |
|
86 void RemoveL( CMdCSerializationBuffer& aBuffer, |
|
87 CMdCSerializationBuffer& aSuccessfulBuffer ); |
|
88 |
|
89 /** |
|
90 * Updates items to database |
|
91 */ |
|
92 void UpdateL( CMdCSerializationBuffer& aBuffer, |
|
93 CMdCSerializationBuffer& aResultBuffer ); |
|
94 |
|
95 /** |
|
96 * Gets object id, object def and flags in serialization buffer. |
|
97 * @param aResultBufferSize size of result buffer |
|
98 * @param aUri object URI |
|
99 * @param aNamespaceDefId namespace id |
|
100 * |
|
101 * @return serialization buffer that contains object id, object def id and object flags |
|
102 */ |
|
103 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
104 const TDesC& aUri, TDefId aNamespaceDefId ); |
|
105 |
|
106 /** |
|
107 * Gets object def and flags in serialization buffer. |
|
108 * @param aResultBufferSize size of result buffer |
|
109 * @param aId object id |
|
110 * @param aNamespaceDefId namespace id |
|
111 * |
|
112 * @return serialization buffer that contains object def id and object flags |
|
113 */ |
|
114 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
115 TItemId aId, TDefId aNamespaceDefId ); |
|
116 |
|
117 /** |
|
118 * Gets object def and flags in serialization buffer. |
|
119 * @param aResultBufferSize size of result buffer |
|
120 * @param aIds list of object ids in serialization buffer |
|
121 * @param aNamespaceDefId namespace id |
|
122 * |
|
123 * @return serialization buffer that contains object id, object def id and object flags for |
|
124 * all objects |
|
125 */ |
|
126 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
127 CMdCSerializationBuffer& aIds, TDefId aNamespaceDefId ); |
|
128 |
|
129 /** |
|
130 * Give a reference to the manipulator object |
|
131 */ |
|
132 CMdSSqlObjectManipulate& Manipulate(); |
|
133 |
|
134 /** |
|
135 * Give a reference to the manipulator object |
|
136 */ |
|
137 CMdSGarbageCollector& GarbageCollector(); |
|
138 |
|
139 /** |
|
140 * Add memory card media ID |
|
141 * @param aMediaId Memory card's media ID |
|
142 */ |
|
143 void AddMemoryCardL(TUint32 aMediaId); |
|
144 |
|
145 /** |
|
146 * Get the lastest memory card's media ID |
|
147 * @param aMediaId Returned the latest memory card's media ID |
|
148 * @leave KErrNotFound Not memory cards exist at all |
|
149 */ |
|
150 void GetMemoryCardL(TUint32& aMediaId); |
|
151 |
|
152 /** |
|
153 * Checks if memory card's with given media ID exists |
|
154 * @param aMediaId memory card's media ID |
|
155 * @return memory card exists or not |
|
156 */ |
|
157 TBool CheckMemoryCardL(TUint32 aMediaId); |
|
158 |
|
159 /** |
|
160 * Set media's media ID, drive and present state to DB. |
|
161 * |
|
162 * @param aMediaId media ID |
|
163 * @param aMediaId drive |
|
164 * @param aMediaId present state |
|
165 */ |
|
166 void SetMediaL(TUint32 aMediaId, TChar aDrive, TBool aPresentState); |
|
167 |
|
168 /** |
|
169 * Check if the media's with given media ID exist in DB and return |
|
170 * drive and present state. |
|
171 * |
|
172 * @param aMediaId given media ID |
|
173 * @param aMediaId drive |
|
174 * @param aMediaId present state |
|
175 * |
|
176 * @return does media exist |
|
177 */ |
|
178 TBool GetMediaL(TUint32 aMediaId, TChar& aDrive, TBool& aPresentState); |
|
179 |
|
180 /** |
|
181 * Get present medias' media IDs and drives. |
|
182 * |
|
183 * @param aMediaInfoBuffer buffer where media infos are written |
|
184 * |
|
185 * @return present media count |
|
186 */ |
|
187 TInt32 GetPresentMediasL(TDes8& aMediaInfoBuffer); |
|
188 |
|
189 /** |
|
190 * Sets files object to present state. |
|
191 * @param aMediaId Memory card's media ID |
|
192 * @param aFileCount File count |
|
193 * @param aUris Files' URIs |
|
194 * @param aFileInfos Files' file infos |
|
195 * @param aResults TFilePresentStates results (casted to TUint8) |
|
196 */ |
|
197 void SetFilesToPresentL(TUint32 aMediaId, TUint32 aFileCount, |
|
198 CMdCSerializationBuffer& aUris, CMdCSerializationBuffer& aFileInfos, |
|
199 CMdCSerializationBuffer& aResults); |
|
200 |
|
201 |
|
202 /** |
|
203 * Sets all file objects which has given media ID to not present state. |
|
204 * @param aMediaId Memory card's media ID |
|
205 * @param aStartUp start up not present |
|
206 */ |
|
207 void SetFilesToNotPresentL(TUint32 aMediaId, TBool aStartUp); |
|
208 |
|
209 /** |
|
210 * Removes all file objects which has given media ID and are in not |
|
211 * present. |
|
212 * |
|
213 * @param aMediaId Memory card's Media ID |
|
214 * @param aStartUp start up not present |
|
215 */ |
|
216 void RemoveFilesNotPresentL(TUint32 aMediaId, TBool aStartUp); |
|
217 |
|
218 /** |
|
219 * Get schema version |
|
220 */ |
|
221 void GetSchemaVersionL(TInt& aMajorVersion, TInt& aMinorVersion); |
|
222 |
|
223 /** |
|
224 * Set object to "present" state bu GUID |
|
225 * |
|
226 * @leave KErrNotFound MdE can't find object in "not present" state |
|
227 * with matching GUID |
|
228 */ |
|
229 void SetObjectToPresentByGuidL( |
|
230 const TInt64& aGuidHigh, const TInt64& aGuidLow ); |
|
231 |
|
232 /** |
|
233 * Change a path of a media object to another. |
|
234 * @param aOldPath old path |
|
235 * @param aNewPath new path |
|
236 */ |
|
237 void ChangePathL(const TDesC& aOldPath, const TDesC& aNewPath); |
|
238 |
|
239 /** |
|
240 * Updates C drive media id for all objects with the old media id. |
|
241 */ |
|
242 void ChangeMediaIdL(); |
|
243 |
|
244 /** |
|
245 * Adds new relation definition to the DB. |
|
246 * @param aNamespaceId namespace id |
|
247 * @param aRelationDefName name of the new relation def |
|
248 */ |
|
249 void AddRelationDefL( TDefId aNamespaceId, const TDesC& aRelationDefName ); |
|
250 |
|
251 /** |
|
252 * Adds new event definition to the DB. |
|
253 * @param aNamespaceId namespace id |
|
254 * @param aEventDefName name of the new event def |
|
255 */ |
|
256 void AddEventDefL( TDefId aNamespaceId, const TDesC& aEventDefName ); |
|
257 |
|
258 /** |
|
259 * Set the "pending" flag for objects. The pending flag means that composing to binary is |
|
260 * pending for the object. |
|
261 * @param aObjectIds list of object ids |
|
262 */ |
|
263 void SetPendingL(const RArray<TItemId>& aObjectIds); |
|
264 |
|
265 /** |
|
266 * Resets the "pending" flag for objects. |
|
267 * @param aObjectIds list of object ids. |
|
268 */ |
|
269 void ResetPendingL(const RArray<TItemId>& aObjectIds); |
|
270 |
|
271 /** |
|
272 * Gets count of objects pending. |
|
273 * @param aObjectDefId type of objects |
|
274 * @return count of pending objects |
|
275 */ |
|
276 TInt GetPendingCountL( TDefId aObjectDefId ); |
|
277 |
|
278 /** |
|
279 * Gets ids of pending objects of type defined with aObjectDefId. |
|
280 * @param aObjectDefId objects definition id |
|
281 * @param aBufferSize max count of object ids in aObjectIds |
|
282 * @param aObjectIds on return contains ids of pending objects |
|
283 * |
|
284 * @return 1 if there were more pending objects than could be appended to the array, |
|
285 * 0 otherwise |
|
286 */ |
|
287 TInt GetPendingL( TDefId aObjectDefId, TInt aBufferSize, |
|
288 RArray<TItemId>& aObjectIds ); |
|
289 |
|
290 protected: |
|
291 TBool StartGarbageCollectionL(); |
|
292 |
|
293 private: // Constructors and destructors |
|
294 |
|
295 /** |
|
296 * CMdSManipulationEngine. |
|
297 * C++ default constructor. |
|
298 * @param . |
|
299 */ |
|
300 CMdSManipulationEngine( CMdsSchema& aSchema, CMdSNotifier& aNotifier, |
|
301 CMdSObjectLockList& aLockList ); |
|
302 |
|
303 /** |
|
304 * ConstructL. |
|
305 * 2nd phase constructor. |
|
306 */ |
|
307 void ConstructL(); |
|
308 |
|
309 private: // Methods for own use |
|
310 |
|
311 private: // Data |
|
312 |
|
313 /** |
|
314 * Object adding, removing and modification. |
|
315 * Provides DB coding. |
|
316 */ |
|
317 CMdSSqlObjectManipulate* iManipulate; |
|
318 |
|
319 /** |
|
320 * Schema |
|
321 */ |
|
322 CMdsSchema& iSchema; |
|
323 |
|
324 /** |
|
325 * Notifier |
|
326 */ |
|
327 CMdSNotifier& iNotifier; |
|
328 |
|
329 CMdSGarbageCollector* iGarbageCollector; |
|
330 |
|
331 CMdSObjectLockList& iLockList; |
|
332 }; |
|
333 |
|
334 #endif //__MDSMANIPULATIONENGINE_H__ |