|
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: Fota adapter's DB header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __NSMLDMFOTAADAPTERDB_H |
|
23 #define __NSMLDMFOTAADAPTERDB_H |
|
24 |
|
25 // INCLUDE FILES |
|
26 |
|
27 #include <e32std.h> |
|
28 #include <e32base.h> |
|
29 #include <d32dbms.h> |
|
30 #include <f32file.h> |
|
31 #include <SyncMLDef.h> |
|
32 #include <fotaengine.h> |
|
33 #include <fotaConst.h> |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // null final result value |
|
38 const TInt KNSmlFotaNullResult = 0; |
|
39 |
|
40 // Database name & location |
|
41 const TInt KNSmlFotaAdapterDbDrive = EDriveC; |
|
42 _LIT( KNSmlFotaAdapterDbName, "c:nsmldmfotaadapter.db" ); |
|
43 |
|
44 // Table and column names |
|
45 _LIT( KNSmlTableFwMgmtObject, "FwMgmtObject" ); |
|
46 _LIT( KNSmlFwMgmtObjectId, "PkgId" ); |
|
47 _LIT( KNSmlFwMgmtObjectName, "PkgName" ); |
|
48 _LIT( KNSmlFwMgmtObjectVersion, "PkgVersion" ); |
|
49 _LIT( KNSmlFwMgmtObjectUrl, "PkgURL" ); |
|
50 _LIT( KNSmlFwMgmtObjectMgmtUri, "MgmtURI" ); |
|
51 _LIT( KNSmlFwMgmtObjectProfileId, "ProfileId" ); |
|
52 _LIT( KNSmlFwMgmtObjectServerId, "ServerId" ); |
|
53 _LIT( KNSmlFwMgmtObjectResult, "FinalResult" ); |
|
54 _LIT( KNSmlFwMgmtObjectCorrelator, "Correlator" ); |
|
55 |
|
56 // SQL statements |
|
57 _LIT( KNSmlCreateFwMgmtObjectTable, "CREATE TABLE FwMgmtObject ( PkgId \ |
|
58 COUNTER NOT NULL, PkgName CHAR(%d), PkgVersion CHAR(%d), PkgURL LONG VARCHAR, \ |
|
59 MgmtURI CHAR(%d), ProfileId INTEGER, ServerId CHAR(%d), FinalResult INTEGER, \ |
|
60 Correlator CHAR(%d) )" ); |
|
61 |
|
62 _LIT( KNSmlGetFwMgmtObject, "SELECT * FROM FwMgmtObject WHERE PkgId = %d" ); |
|
63 |
|
64 _LIT( KNSmlGetUnfinishedFwMgmtObjects, "SELECT * FROM FwMgmtObject \ |
|
65 WHERE FinalResult = %d" ); |
|
66 |
|
67 _LIT( KNSmlGetUnfinishedFwMgmtObjectByServerId, "SELECT * FROM FwMgmtObject \ |
|
68 WHERE FinalResult = %d AND ServerId = '%S' AND NOT (MgmtURI = '')" ); |
|
69 |
|
70 _LIT( KNSmlDeleteFwMgmtObject,"DELETE FROM FwMgmtObject WHERE PkgId = %d"); |
|
71 |
|
72 // Max. lengths of string fields in FwMgmtObject |
|
73 const TInt KNSmlMaxMgmtUriLength = 60; |
|
74 const TInt KNSmlMaxServerIdLength = 150; |
|
75 const TInt KNSmlMaxCorrelatorLength = 150; |
|
76 |
|
77 // Estimate of url size used in max row size (OOD checks) |
|
78 const TInt KNSmlPkgURLLengthEstimate = 350; |
|
79 |
|
80 // space needed for above integers in buffer |
|
81 const TInt KNSmlFwMgmtObjectIntLength = 4; |
|
82 |
|
83 // space needed for an integer in buffer |
|
84 const TInt KNSmlFwMgmtObjectIntegerLength = 10; |
|
85 |
|
86 // Size of empty Fota database in bytes (+ additional treshold) |
|
87 const TInt KNSmlFotaAdapterEmptyDbSize = 350; |
|
88 |
|
89 // Estimated maximum size of FwMgmtObject table row (+ additional treshold) |
|
90 const TInt KNSmlMaxFwMgmtObjectRowSize = KFotaMaxPkgNameLength + |
|
91 KFotaMaxPkgVersionLength + |
|
92 KNSmlPkgURLLengthEstimate + |
|
93 KNSmlMaxMgmtUriLength + |
|
94 KNSmlMaxServerIdLength + |
|
95 KNSmlMaxCorrelatorLength + 115; |
|
96 |
|
97 // TYPEDEFS |
|
98 typedef TInt TNSmlDmFwObjectId; |
|
99 typedef RArray<TNSmlDmFwObjectId> RNSmlDmFwObjectArray; |
|
100 |
|
101 |
|
102 |
|
103 // CLASS DECLARATION |
|
104 |
|
105 /** |
|
106 * CNSmlDmFotaAdapterDb provides an interface for accessing Fota database. |
|
107 * |
|
108 * @lib nsmldmfotaadapter.lib |
|
109 * |
|
110 */ |
|
111 class CNSmlDmFotaAdapterDb : public CBase |
|
112 { |
|
113 |
|
114 public: |
|
115 |
|
116 /** |
|
117 * Two-phased constructor. |
|
118 * @return A pointer to the newly created instance. |
|
119 */ |
|
120 static CNSmlDmFotaAdapterDb* NewL(); |
|
121 |
|
122 /** |
|
123 * Two-phased constructor. Pushes the pointer onto the CleanupStack. |
|
124 * @return A pointer to the newly created instance. |
|
125 */ |
|
126 static CNSmlDmFotaAdapterDb* NewLC(); |
|
127 |
|
128 /** |
|
129 * Destructor. |
|
130 */ |
|
131 virtual ~CNSmlDmFotaAdapterDb(); |
|
132 |
|
133 /** |
|
134 * Adds a new row (i.e. firmware object) to the FwMgmtObject table. |
|
135 * The values in each column are left NULL, except FinalResult to |
|
136 * KNSmlFotaNullResult. |
|
137 * Leaves with KErrDiskFull, if OOD check fails. |
|
138 * @return The id of the new fw object in Fota database. |
|
139 */ |
|
140 TNSmlDmFwObjectId AddFwObjectL(); |
|
141 |
|
142 /** |
|
143 * Deletes a firmware object from FwMgmtObject table. |
|
144 * @param aId The identifier of the object to be deleted. |
|
145 * @return KErrNone if the object was successfully deleted, KErrNotFound if |
|
146 * the object was not found from database. |
|
147 */ |
|
148 TInt DeleteFwObjectL( const TNSmlDmFwObjectId aId ); |
|
149 |
|
150 /** |
|
151 * Finds all the firmware objects that have null final result and sets |
|
152 * the ids of those objetcs to aArray. |
|
153 * @param aArray that on return contains the ids. |
|
154 */ |
|
155 void GetEmptyFinalResultsL( RNSmlDmFwObjectArray& aArray ); |
|
156 |
|
157 /** |
|
158 * Finds all the firmware objects that have null final result, server id |
|
159 * equals to given server id and mgmt uri is not empty. Sets the ids of |
|
160 * those objetcs to aArray. |
|
161 * @param aArray Array that on return contains the ids. |
|
162 * @param aServerId The id of the server whose empty final result values |
|
163 * are listed. |
|
164 */ |
|
165 void GetEmptyFinalResultsL( RNSmlDmFwObjectArray& aArray, |
|
166 const TDesC8& aServerId ); |
|
167 |
|
168 /** |
|
169 * Fetches the PkgName field of a firmware object from database. |
|
170 * @param aId The identifier of the object, whose data should be fetched. |
|
171 * @return The value in PkgName field of the object, if object was found. |
|
172 * NULL otherwise. |
|
173 */ |
|
174 HBufC8* PkgNameL( const TNSmlDmFwObjectId aId ); |
|
175 |
|
176 /** |
|
177 * Fetches the PkgVersion field of a firmware object from database. |
|
178 * @param aId The identifier of the object, whose data should be fetched. |
|
179 * @return The value in PkgVersion field of the object, if object was found. |
|
180 * NULL otherwise. |
|
181 */ |
|
182 HBufC8* PkgVersionL( const TNSmlDmFwObjectId aId ); |
|
183 |
|
184 /** |
|
185 * Fetches the PkgURL field of a firmware object from database. |
|
186 * @param aId The identifier of the object, whose data should be fetched. |
|
187 * @return The value in PkgURL field of the object, if object was found. |
|
188 * NULL otherwise. |
|
189 */ |
|
190 HBufC8* PkgUrlL( const TNSmlDmFwObjectId aId ); |
|
191 |
|
192 /** |
|
193 * Fetches the MgmtURI field of a firmware object from database. |
|
194 * @param aId The identifier of the object, whose data should be fetched. |
|
195 * @return The value in MgmtURI field of the object, if object was found. |
|
196 * NULL otherwise. |
|
197 */ |
|
198 HBufC8* MgmtUriL( const TNSmlDmFwObjectId aId ); |
|
199 |
|
200 /** |
|
201 * Fetches the ProfileId field of a firmware object from database. |
|
202 * @param aId The identifier of the object, whose data should be fetched. |
|
203 * @return The value in ProfileId field of the object, if object was found. |
|
204 * KErrNotFound otherwise. |
|
205 */ |
|
206 TSmlProfileId ProfileIdL( const TNSmlDmFwObjectId aId ); |
|
207 |
|
208 /** |
|
209 * Fetches the ServerId field of a firmware object from database. |
|
210 * @param aId The identifier of the object, whose data should be fetched. |
|
211 * @return The value in ServerId field of the object, if object was found. |
|
212 * NULL otherwise. |
|
213 */ |
|
214 HBufC8* ServerIdL( const TNSmlDmFwObjectId aId ); |
|
215 |
|
216 /** |
|
217 * Fetches the FinalResult field of a firmware object from database. |
|
218 * @param aId The identifier of the object, whose data should be fetched. |
|
219 * @return The value in FinalResult field of the object, if object was |
|
220 * found. KErrNotFound otherwise. |
|
221 */ |
|
222 TInt FinalResultL( const TNSmlDmFwObjectId aId ); |
|
223 |
|
224 /** |
|
225 * Fetches the Correlator field of a firmware object from database. |
|
226 * @param aId The identifier of the object, whose data should be fetched. |
|
227 * @return The value in Correlator field of the object, if object was |
|
228 * found. NULL otherwise. |
|
229 */ |
|
230 HBufC8* CorrelatorL( const TNSmlDmFwObjectId aId ); |
|
231 |
|
232 /** |
|
233 * Sets the value of PkgName field of a firmware object. |
|
234 * @param aName The new value for the field. |
|
235 * @param aId The identifier of the object, whose data should be updated. |
|
236 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
237 * object was not found. KErrOverflow, if given name is too large for the |
|
238 * database. |
|
239 */ |
|
240 TInt SetPkgNameL( const TDesC8& aName, const TNSmlDmFwObjectId aId ); |
|
241 |
|
242 /** |
|
243 * Sets the value of PkgVersion field of a firmware object. |
|
244 * @param aVersion The new value for the field. |
|
245 * @param aId The identifier of the object, whose data should be updated. |
|
246 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
247 * object was not found. KErrOverflow, if given version is too large |
|
248 * for the database. |
|
249 */ |
|
250 TInt SetPkgVersionL( const TDesC8& aVersion, const TNSmlDmFwObjectId aId ); |
|
251 |
|
252 /** |
|
253 * Sets the value of PkgURL field of a firmware object. |
|
254 * @param aUrl The new value for the field. |
|
255 * @param aId The identifier of the object, whose data should be updated. |
|
256 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
257 * object was not found. KErrOverflow, if given url is too large for the |
|
258 * database. |
|
259 */ |
|
260 TInt SetPkgUrlL( const TDesC8& aUrl, const TNSmlDmFwObjectId aId ); |
|
261 |
|
262 /** |
|
263 * Sets the value of MgmtURI field of a firmware object. |
|
264 * @param aUri The new value for the field. |
|
265 * @param aId The identifier of the object, whose data should be updated. |
|
266 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
267 * object was not found. KErrOverflow, if given uri is too large for the |
|
268 * database. |
|
269 */ |
|
270 TInt SetMgmtUriL( const TDesC8& aUri, const TNSmlDmFwObjectId aId ); |
|
271 |
|
272 /** |
|
273 * Sets the values of ProfileId and ServerId fields of a firmware object. |
|
274 * @param aProfile The new value for the ProfileId. |
|
275 * @param aServerId The new value for the ServerId. |
|
276 * @param aId The identifier of the object, whose data should be updated. |
|
277 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
278 * object was not found. KErrOverflow, if given server id is too large |
|
279 * for the database. |
|
280 */ |
|
281 TInt SetServerInfoL( const TSmlProfileId aProfile, |
|
282 const TDesC8& aServerId, |
|
283 const TNSmlDmFwObjectId aId ); |
|
284 |
|
285 /** |
|
286 * Sets the value of FinalResult field of a firmware object. |
|
287 * @param aResult The new value for the field. |
|
288 * @param aId The identifier of the object, whose data should be updated. |
|
289 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
290 * object was not found. |
|
291 */ |
|
292 TInt SetFinalResultL( const TInt aResult, const TNSmlDmFwObjectId aId ); |
|
293 |
|
294 /** |
|
295 * Sets the value of Correlator field of a firmware object. |
|
296 * @param aCorrelator The new value for the field. |
|
297 * @param aId The identifier of the object, whose data should be updated. |
|
298 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
299 * object was not found. KErrOverflow, if given correlator is too large |
|
300 * for the database. |
|
301 */ |
|
302 TInt SetCorrelatorL( const TDesC8& aCorrelator, |
|
303 const TNSmlDmFwObjectId aId ); |
|
304 |
|
305 private: |
|
306 |
|
307 /** |
|
308 * Creates Fota database. |
|
309 * @param aFullName Name and path of database. |
|
310 */ |
|
311 void CreateDatabaseL( const TDesC& aFullName ); |
|
312 |
|
313 /** |
|
314 * Sets new value to a text field in a firmware object. This method is used |
|
315 * by the public descriptor setters. |
|
316 * @param aColumn The name of the field to be updated. |
|
317 * @param aValue The new value for the field. |
|
318 * @param aObject The identifier of the object, whose data should be |
|
319 * updated. |
|
320 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
321 * object was not found. |
|
322 */ |
|
323 TInt SetStrValueL( const TDesC& aColumn, |
|
324 const TDesC8& aValue, |
|
325 const TNSmlDmFwObjectId aObject ); |
|
326 |
|
327 /** |
|
328 * Writes using Db streams the new value to a long text field in a |
|
329 * firmware object. This method is used by the public descriptor |
|
330 * setters (PkgURL). |
|
331 * @param aColumn The name of the field to be updated. |
|
332 * @param aValue The new value for the field. |
|
333 * @param aObject The identifier of the object, whose data should |
|
334 * be updated. |
|
335 * @return KErrNone, if the update was successful. KErrNotFound, if |
|
336 * the object was not found. |
|
337 */ |
|
338 TInt SetLongStrValueL( const TDesC& aColumn, |
|
339 const TDesC8& aValue, |
|
340 const TNSmlDmFwObjectId aObject ); |
|
341 |
|
342 /** |
|
343 * Sets new value to a integer field in a firmware object. This method |
|
344 * is used by the public integer setters. |
|
345 * @param aColumn The name of the field to be updated. |
|
346 * @param aValue The new value for the field. |
|
347 * @param aObject The identifier of the object, whose data should be |
|
348 * updated. |
|
349 * @return KErrNone, if the update was successful. KErrNotFound, if the |
|
350 * object was not found. |
|
351 */ |
|
352 TInt SetIntValueL( const TDesC& aColumn, |
|
353 const TInt aValue, |
|
354 const TNSmlDmFwObjectId aObject ); |
|
355 |
|
356 /** |
|
357 * Fetches the value in a text field of a firmware object. This method is |
|
358 * used by the public descriptor getters. |
|
359 * @param aColumn The name of the field where the data should be fetched. |
|
360 * @param aObject The identifier of the object, whose data should be |
|
361 * fetched. |
|
362 * @return The value in the field, if object was found. NULL otherwise. |
|
363 */ |
|
364 HBufC8* StrValueL( const TDesC& aColumn, const TNSmlDmFwObjectId aObject ); |
|
365 |
|
366 /** |
|
367 * Fetches the value in a long text field of a firmware object using Db |
|
368 * streams. This method is used by the public descriptor getters (PkgURL). |
|
369 * @param aColumn The name of the field where the data should be fetched. |
|
370 * @param aObject The identifier of the object, whose data should be |
|
371 * fetched. |
|
372 * @return The value in the field, if object was found. NULL otherwise. |
|
373 */ |
|
374 HBufC8* LongStrValueL( const TDesC& aColumn, |
|
375 const TNSmlDmFwObjectId aObject ); |
|
376 |
|
377 /** |
|
378 * Fetches the value in a integer field of a firmware object. This method |
|
379 * is used by the public integer getters. |
|
380 * @param aColumn The name of the field where the data should be fetched. |
|
381 * @param aObject The identifier of the object, whose data should be |
|
382 * fetched. |
|
383 * @return The value in the field, if object was found. KErrNotFound |
|
384 * otherwise. |
|
385 */ |
|
386 TInt IntValueL( const TDesC& aColumn, const TNSmlDmFwObjectId aObject ); |
|
387 |
|
388 /** |
|
389 * Prepares iView with read-only access rights to a single firmware object. |
|
390 * @param aObject The identifier of the object, whose data is about |
|
391 * to be read. |
|
392 */ |
|
393 void FetchRowL( const TNSmlDmFwObjectId aObject ); |
|
394 |
|
395 /** |
|
396 * Prepares iView with update access rights to a single firmware object. |
|
397 * @param aObject The identifier of the object, whose data is about to |
|
398 * be updated. |
|
399 * @return KErrNone, if there were no errors and iView was successfully |
|
400 * prepared. |
|
401 * KErrNotFound, if the firmware object was not found. |
|
402 */ |
|
403 TInt UpdateRowL( const TNSmlDmFwObjectId aObject ); |
|
404 |
|
405 /** |
|
406 * Makes an SQL query string for getting a row from FwMgmtObject table. |
|
407 * @param aId The identifier of the object, which is used in the SQL query. |
|
408 * @return A string containing the formatted SQL query. |
|
409 */ |
|
410 HBufC* FwMgmtObjectRowSqlLC( TNSmlDmFwObjectId aId ) const; |
|
411 |
|
412 /** |
|
413 * Closes the view and then prepares it with the given values. |
|
414 * @param aSql SQL statement defining the view, which is prepared by |
|
415 * this method. |
|
416 * @param aAccess Permitted operations for the view. |
|
417 */ |
|
418 void PrepareViewL( const TDesC& aSql, RDbRowSet::TAccess aAccess ); |
|
419 |
|
420 /** |
|
421 * Commits update and compacts the database. |
|
422 */ |
|
423 void CommitAndCompact(); |
|
424 |
|
425 /** |
|
426 * Converts a 8-bit descriptor to a 16-bit descriptor, which is allocated |
|
427 * from heap and pushed onto the CleanupStack. |
|
428 * @param aDes Descriptor to be converted. |
|
429 * @return A pointer to the newly allocated copy. |
|
430 */ |
|
431 HBufC* ConvertTo16BitLC( const TDesC8& aDes ) const; |
|
432 |
|
433 /** |
|
434 * Second phase construction. |
|
435 */ |
|
436 void ConstructL(); |
|
437 |
|
438 /** |
|
439 * Constructor. |
|
440 */ |
|
441 CNSmlDmFotaAdapterDb(); |
|
442 |
|
443 private: |
|
444 |
|
445 RDbNamedDatabase iDatabase; |
|
446 RFs iFsSession; |
|
447 RDbs iRdbSession; |
|
448 |
|
449 RDbTable iFwObjectTable; |
|
450 CDbColSet* iColSet; |
|
451 RDbView iView; |
|
452 |
|
453 }; |
|
454 |
|
455 |
|
456 #endif // __NSMLDMFOTAADAPTERDB_H |
|
457 |
|
458 // End of File |