99
|
1 |
/*
|
|
2 |
* Copyright (c) 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "afstorage.h"
|
|
18 |
#include <bautils.h>
|
|
19 |
#include <hash.h>
|
|
20 |
#include <s32mem.h>
|
|
21 |
|
112
|
22 |
#include "afdatabasecleaner.h"
|
99
|
23 |
#include "afqueries.h"
|
|
24 |
#include "afentry.h"
|
|
25 |
|
|
26 |
_LIT(KDbName, "activity.db");
|
|
27 |
_LIT(KDbDrive, "c:");
|
|
28 |
const TInt KMaxPathLength = 256;
|
|
29 |
|
|
30 |
_LIT(KNonPersistent, "non_persistent\\");
|
|
31 |
_LIT(KPersistent, "persistent\\");
|
|
32 |
_LIT(KUidFormat, "%+08x\\");
|
|
33 |
_LIT(KExtFormat, ".mbm");
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
/**
|
|
37 |
* Constructor for performing 1st stage construction
|
|
38 |
* @param session - initialized session to file system
|
|
39 |
*/
|
|
40 |
CAfStorage::CAfStorage(RFs& session)
|
|
41 |
:
|
116
|
42 |
iFsSession(session)
|
|
43 |
{
|
99
|
44 |
// No implementation required
|
116
|
45 |
}
|
99
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
/**
|
|
49 |
* Destructor.
|
|
50 |
*/
|
|
51 |
CAfStorage::~CAfStorage()
|
116
|
52 |
{
|
|
53 |
delete iDatabaseCleaner;
|
|
54 |
iActDb.Close();
|
|
55 |
delete iFileStore;
|
|
56 |
}
|
99
|
57 |
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
/**
|
|
60 |
* Two-phased constructor.
|
|
61 |
* @param session - initialized session to file system
|
|
62 |
*/
|
|
63 |
CAfStorage* CAfStorage::NewL(RFs& session)
|
116
|
64 |
{
|
99
|
65 |
CAfStorage* self = new (ELeave) CAfStorage(session);
|
|
66 |
CleanupStack::PushL(self);
|
|
67 |
self->ConstructL();
|
|
68 |
CleanupStack::Pop(); // self;
|
|
69 |
return self;
|
116
|
70 |
}
|
99
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
/**
|
|
74 |
* EPOC default constructor for performing 2nd stage construction
|
|
75 |
*/
|
|
76 |
void CAfStorage::ConstructL()
|
116
|
77 |
{
|
99
|
78 |
RBuf path;
|
|
79 |
CleanupClosePushL( path );
|
|
80 |
path.CreateL(KMaxPathLength);
|
116
|
81 |
User::LeaveIfError(iFsSession.PrivatePath(path ));
|
99
|
82 |
path.Append(KDbName);
|
|
83 |
path.Insert(0, KDbDrive);
|
116
|
84 |
BaflUtils::EnsurePathExistsL(iFsSession, path);
|
|
85 |
BaflUtils::FileExists(iFsSession, path) ? OpenDbL(path) : CreateDbL(path);
|
99
|
86 |
CleanupStack::PopAndDestroy(&path);
|
116
|
87 |
|
|
88 |
iDatabaseCleaner = new (ELeave) CAfDatabaseCleaner(iActDb);
|
|
89 |
|
99
|
90 |
DeleteNonPersistentActivitiesL();
|
112
|
91 |
RequestCleanup();
|
116
|
92 |
}
|
99
|
93 |
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
/**
|
|
96 |
* Create database and its structure
|
|
97 |
* @param databaseFile - database file path
|
|
98 |
*/
|
|
99 |
void CAfStorage::CreateDbL(const TDesC& databaseFile)
|
116
|
100 |
{
|
|
101 |
iFileStore = CPermanentFileStore::ReplaceL(iFsSession,
|
99
|
102 |
databaseFile,
|
|
103 |
EFileRead|EFileWrite);
|
116
|
104 |
iFileStore->SetTypeL(iFileStore->Layout());// Set file store type
|
|
105 |
TStreamId id = iActDb.CreateL(iFileStore);// Create stream object
|
|
106 |
iFileStore->SetRootL(id);// Keep database id as root of store
|
|
107 |
iFileStore->CommitL();// Complete creation by commiting
|
99
|
108 |
CreateTableL();
|
116
|
109 |
}
|
99
|
110 |
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
/**
|
|
113 |
* Open database
|
|
114 |
* @param databaseFile - database file path
|
|
115 |
*/
|
|
116 |
void CAfStorage::OpenDbL(const TDesC& databaseFile)
|
116
|
117 |
{
|
|
118 |
TRAPD( errNo,
|
|
119 |
iFileStore = CPermanentFileStore::OpenL( iFsSession,
|
|
120 |
databaseFile,
|
|
121 |
EFileRead|EFileWrite );
|
|
122 |
iFileStore->SetTypeL( iFileStore->Layout() ); /* Set file store type*/
|
|
123 |
iActDb.OpenL( iFileStore, iFileStore->Root() );
|
|
124 |
VerifyTableL(); )
|
|
125 |
if( KErrNone != errNo )
|
|
126 |
{
|
|
127 |
//database is corrupted. recreate
|
|
128 |
iActDb.Close();
|
|
129 |
delete iFileStore;
|
|
130 |
iFileStore = 0;
|
|
131 |
CreateDbL( databaseFile );
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
/**
|
|
137 |
* Verify database structure
|
|
138 |
*/
|
|
139 |
void CAfStorage::VerifyDbL()
|
99
|
140 |
{
|
116
|
141 |
TInt errNo(KErrCorrupt);
|
|
142 |
CDbTableNames* tables = iActDb.TableNamesL();
|
|
143 |
CleanupStack::PushL( tables );
|
|
144 |
for( TInt iter(0); iter < tables->Count() && KErrNone != errNo; ++iter )
|
|
145 |
{
|
|
146 |
if( 0 == (*tables)[iter].Compare( KActivityTableName() ) )
|
|
147 |
{
|
|
148 |
VerifyTableL();
|
|
149 |
errNo = KErrNone;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
CleanupStack::PopAndDestroy( tables );
|
|
153 |
User::LeaveIfError( errNo );
|
99
|
154 |
}
|
|
155 |
|
|
156 |
// -----------------------------------------------------------------------------
|
116
|
157 |
CDbColSet* CAfStorage::ExpectedTableLC()
|
|
158 |
{
|
|
159 |
CDbColSet* actColSet = CDbColSet::NewLC();
|
|
160 |
|
|
161 |
TDbCol appName(KApplicationColumnName, EDbColInt64);
|
|
162 |
appName.iAttributes = TDbCol::ENotNull;
|
|
163 |
actColSet->AddL( appName );
|
|
164 |
|
|
165 |
TDbCol actName( KActivityColumnName, EDbColText16 );// Using default length
|
|
166 |
actName.iAttributes = TDbCol::ENotNull;
|
|
167 |
actColSet->AddL( actName );
|
|
168 |
|
|
169 |
// custom name
|
|
170 |
actColSet->AddL( TDbCol( KCustomNameColumnName, EDbColText16 ) );
|
|
171 |
|
|
172 |
TDbCol actFlags( KFlagsColumnName, EDbColInt32 );
|
|
173 |
actFlags.iAttributes = TDbCol::ENotNull;
|
|
174 |
actColSet->AddL(actFlags);
|
|
175 |
|
|
176 |
TDbCol actTimestamp( KTimestampColumnName, EDbColDateTime );
|
|
177 |
actTimestamp.iAttributes = TDbCol::ENotNull;
|
|
178 |
actColSet->AddL(actTimestamp);
|
|
179 |
|
|
180 |
actColSet->AddL( TDbCol( KDataColumnName, EDbColLongBinary ) );// Stream Data
|
|
181 |
|
|
182 |
return actColSet;
|
|
183 |
}
|
|
184 |
|
|
185 |
// -----------------------------------------------------------------------------
|
99
|
186 |
/**
|
|
187 |
* Create database structure
|
|
188 |
*/
|
|
189 |
void CAfStorage::CreateTableL()
|
116
|
190 |
{
|
|
191 |
CDbColSet* actColSet(ExpectedTableLC());
|
|
192 |
// Create the table
|
|
193 |
User::LeaveIfError(iActDb.CreateTable(KActivityTableName,
|
|
194 |
*actColSet));
|
|
195 |
CleanupStack::PopAndDestroy(actColSet);
|
|
196 |
}
|
99
|
197 |
|
116
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
/**
|
|
200 |
* Verify table structure
|
|
201 |
*/
|
|
202 |
void CAfStorage::VerifyTableL()
|
|
203 |
{
|
|
204 |
CDbColSet *currentTable(iActDb.ColSetL(KActivityTableName));
|
|
205 |
CleanupStack::PushL(currentTable);
|
|
206 |
CDbColSet *expectedTable(ExpectedTableLC());
|
|
207 |
for( TInt iter(1); iter <= expectedTable->Count(); ++iter )
|
|
208 |
{
|
|
209 |
const TDbCol& expectedColumn((*expectedTable)[iter]);
|
|
210 |
const TDbCol* currentColumn(currentTable->Col(expectedColumn.iName));
|
|
211 |
if( 0 == currentColumn ||
|
|
212 |
expectedColumn.iAttributes != currentColumn->iAttributes ||
|
|
213 |
expectedColumn.iMaxLength != currentColumn->iMaxLength ||
|
|
214 |
expectedColumn.iType != currentColumn->iType )
|
|
215 |
{
|
|
216 |
User::Leave(KErrCorrupt);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
CleanupStack::PopAndDestroy( expectedTable );
|
|
220 |
CleanupStack::PopAndDestroy( currentTable );
|
|
221 |
}
|
99
|
222 |
// -----------------------------------------------------------------------------
|
|
223 |
/**
|
|
224 |
* Delete non-persistent activities
|
|
225 |
*/
|
|
226 |
void CAfStorage::DeleteNonPersistentActivitiesL()
|
116
|
227 |
{
|
|
228 |
HBufC *query(BuildQueryLC(KDeleteNonPersistentActivities(),
|
|
229 |
CAfEntry::Persistent,
|
|
230 |
KNullDesC));
|
|
231 |
User::LeaveIfError(iActDb.Execute(*query));
|
99
|
232 |
RBuf privatePath;
|
|
233 |
CleanupClosePushL(privatePath);
|
|
234 |
privatePath.CreateL(KMaxPathLength);
|
|
235 |
StoragePathL(privatePath, Fs(), FALSE);
|
|
236 |
CFileMan *fileMan = CFileMan::NewL(Fs());
|
|
237 |
TInt i = fileMan->RmDir(privatePath);
|
|
238 |
delete fileMan;
|
|
239 |
CleanupStack::PopAndDestroy(&privatePath);
|
|
240 |
CleanupStack::PopAndDestroy(query);
|
116
|
241 |
}
|
99
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
/**
|
107
|
245 |
* Save activity
|
|
246 |
* @param entry - activity data
|
|
247 |
*/
|
|
248 |
void CAfStorage::SaveActivityL(CAfEntry &entry)
|
|
249 |
{
|
|
250 |
// @todo check if this can be tidied up
|
|
251 |
//verify if row already exists
|
|
252 |
TInt errNo(KErrNone);
|
|
253 |
RDbView view;
|
|
254 |
CleanupClosePushL(view);
|
|
255 |
TRAP(errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId()));
|
116
|
256 |
if( KErrNone == errNo )
|
|
257 |
{
|
107
|
258 |
// update
|
|
259 |
view.UpdateL();
|
|
260 |
TRAPD(errNo,
|
|
261 |
CDbColSet* colSet = view.ColSetL();
|
|
262 |
CleanupStack::PushL(colSet);
|
|
263 |
|
|
264 |
view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags());
|
119
|
265 |
view.SetColL(colSet->ColNo(KTimestampColumnName), entry.Timestamp());
|
116
|
266 |
view.SetColL(colSet->ColNo(KCustomNameColumnName), entry.CustomActivityName());
|
107
|
267 |
ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName));
|
|
268 |
|
|
269 |
view.PutL();
|
|
270 |
CleanupStack::PopAndDestroy(colSet);)
|
|
271 |
|
116
|
272 |
if (KErrNone != errNo)
|
|
273 |
{
|
107
|
274 |
view.Cancel();
|
|
275 |
User::Leave(errNo);
|
116
|
276 |
}
|
107
|
277 |
}
|
116
|
278 |
else
|
|
279 |
{
|
107
|
280 |
// insert
|
119
|
281 |
|
107
|
282 |
//write table
|
|
283 |
RDbTable table;
|
|
284 |
CleanupClosePushL(table);
|
116
|
285 |
User::LeaveIfError(table.Open(iActDb, KActivityTableName, table.EUpdatable));
|
107
|
286 |
CDbColSet *row = table.ColSetL();
|
|
287 |
CleanupStack::PushL(row);
|
|
288 |
|
|
289 |
table.InsertL();
|
|
290 |
TRAP(errNo,
|
|
291 |
table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId()));
|
|
292 |
table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId());
|
116
|
293 |
table.SetColL(row->ColNo(KCustomNameColumnName), entry.CustomActivityName());
|
107
|
294 |
table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags());
|
119
|
295 |
table.SetColL(row->ColNo(KTimestampColumnName), entry.Timestamp());
|
107
|
296 |
ExternalizeDataL(table, entry, row->ColNo(KDataColumnName));
|
|
297 |
table.PutL();)
|
|
298 |
if (KErrNone != errNo) {
|
|
299 |
table.Cancel();
|
|
300 |
User::Leave(errNo);
|
|
301 |
}
|
|
302 |
CleanupStack::PopAndDestroy(row);
|
|
303 |
CleanupStack::PopAndDestroy(&table);
|
|
304 |
}
|
|
305 |
CleanupStack::PopAndDestroy(&view);
|
|
306 |
}
|
|
307 |
|
|
308 |
// -----------------------------------------------------------------------------
|
|
309 |
/**
|
99
|
310 |
* Delete activity
|
|
311 |
* @param appId - application id
|
|
312 |
* @param actId - activity id
|
|
313 |
*/
|
|
314 |
void CAfStorage::DeleteActivityL(CAfEntry& entry)
|
116
|
315 |
{
|
99
|
316 |
HBufC *query(DeleteRowLC(entry.ApplicationId(), entry.ActivityId()));
|
116
|
317 |
User::LeaveIfError(iActDb.Execute(*query));
|
99
|
318 |
CleanupStack::PopAndDestroy(query);
|
116
|
319 |
}
|
99
|
320 |
|
|
321 |
// -----------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
void CAfStorage::DeleteActivitiesL(CAfEntry& entry)
|
116
|
324 |
{
|
99
|
325 |
HBufC *query(DeleteRowsLC(entry.ApplicationId()));
|
116
|
326 |
User::LeaveIfError(iActDb.Execute(*query));
|
99
|
327 |
RBuf privatePath;
|
|
328 |
CleanupClosePushL(privatePath);
|
|
329 |
privatePath.CreateL(KMaxPathLength);
|
|
330 |
AppStoragePathL(privatePath, Fs(), entry.ApplicationId(), FALSE);
|
|
331 |
CFileMan *fileMan = CFileMan::NewL(Fs());
|
|
332 |
CleanupStack::PushL(fileMan);
|
|
333 |
fileMan->RmDir(privatePath);
|
|
334 |
privatePath.Zero();
|
|
335 |
|
|
336 |
AppStoragePathL(privatePath, Fs(), entry.ApplicationId(), TRUE);
|
|
337 |
fileMan->RmDir(privatePath);
|
|
338 |
|
|
339 |
CleanupStack::PopAndDestroy(fileMan);
|
|
340 |
CleanupStack::PopAndDestroy(&privatePath);
|
|
341 |
CleanupStack::PopAndDestroy(query);
|
116
|
342 |
}
|
99
|
343 |
|
|
344 |
// -----------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
// -----------------------------------------------------------------------------
|
|
347 |
//
|
116
|
348 |
void CAfStorage::AllActivitiesL(RPointerArray<CAfEntry>& dst, TInt aLimit)
|
|
349 |
{
|
|
350 |
ActivitiesL(dst, KSelectRows(), CAfEntry::Public, aLimit);
|
|
351 |
}
|
99
|
352 |
|
|
353 |
// -----------------------------------------------------------------------------
|
|
354 |
/**
|
|
355 |
* Serialize application activity into the buffer
|
|
356 |
* @param dst - destination buffer
|
|
357 |
* @param appId - application id
|
|
358 |
*/
|
|
359 |
void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst,TInt appId)
|
116
|
360 |
{
|
99
|
361 |
HBufC *query(SelectRowsLC(appId));
|
|
362 |
ActivitiesL(dst, *query, CAfEntry::Private);
|
|
363 |
CleanupStack::PopAndDestroy(query);
|
116
|
364 |
}
|
99
|
365 |
|
|
366 |
// -----------------------------------------------------------------------------
|
|
367 |
/**
|
|
368 |
* Serialize application activity into the buffer
|
|
369 |
* @param dst - destination entry
|
|
370 |
* @param src - condition pattern
|
|
371 |
*/
|
|
372 |
void CAfStorage::ActivityL(RPointerArray<CAfEntry> &dst, CAfEntry& src)
|
116
|
373 |
{
|
99
|
374 |
HBufC *query = SelectRowLC(src.ApplicationId(), src.ActivityId());
|
116
|
375 |
ActivitiesL(dst, *query, CAfEntry::Private, 1, ETrue);
|
|
376 |
if( 0 >= dst.Count() )
|
|
377 |
{
|
99
|
378 |
User::Leave(KErrNotFound);
|
116
|
379 |
}
|
99
|
380 |
CleanupStack::PopAndDestroy(query);
|
116
|
381 |
}
|
99
|
382 |
|
|
383 |
// -----------------------------------------------------------------------------
|
|
384 |
/**
|
|
385 |
* Provide initialized file system session
|
|
386 |
* @return file system session
|
|
387 |
*/
|
|
388 |
RFs& CAfStorage::Fs()
|
116
|
389 |
{
|
|
390 |
return iFsSession;
|
|
391 |
}
|
99
|
392 |
|
|
393 |
// -----------------------------------------------------------------------------
|
|
394 |
/**
|
|
395 |
* Format query to select activity row
|
|
396 |
* @param appId - application id
|
|
397 |
* @param actId - activity id
|
|
398 |
* @return formated sql query
|
|
399 |
*/
|
|
400 |
HBufC* CAfStorage::SelectRowLC(TInt appId, const TDesC& actId) const
|
116
|
401 |
{
|
99
|
402 |
return BuildQueryLC(KSelectRow(),appId, actId);
|
116
|
403 |
}
|
99
|
404 |
|
|
405 |
// -----------------------------------------------------------------------------
|
|
406 |
/**
|
|
407 |
* Format query to select activities for application
|
|
408 |
* @param appId - application id
|
|
409 |
* @return formated sql query
|
|
410 |
*/
|
|
411 |
HBufC* CAfStorage::SelectRowsLC(TInt appId) const
|
116
|
412 |
{
|
99
|
413 |
return BuildQueryLC(KSelectAppRows(), appId, KNullDesC);
|
116
|
414 |
}
|
99
|
415 |
|
|
416 |
// -----------------------------------------------------------------------------
|
|
417 |
/**
|
|
418 |
* Format query to delete activity
|
|
419 |
* @param appId - application id
|
|
420 |
* @param actId - activity id
|
|
421 |
* @return formated sql query
|
|
422 |
*/
|
|
423 |
HBufC* CAfStorage::DeleteRowLC(TInt appId, const TDesC& actId) const
|
116
|
424 |
{
|
99
|
425 |
return BuildQueryLC(KDeleteRow(),appId, actId);
|
116
|
426 |
}
|
99
|
427 |
|
|
428 |
// -----------------------------------------------------------------------------
|
|
429 |
/**
|
|
430 |
* Format query to delete activities for application
|
|
431 |
* @param appId - application id
|
|
432 |
* @return formated sql query
|
|
433 |
*/
|
|
434 |
HBufC* CAfStorage::DeleteRowsLC(TInt appId) const
|
116
|
435 |
{
|
99
|
436 |
return BuildQueryLC(KDeleteRows(),appId, KNullDesC);
|
116
|
437 |
}
|
99
|
438 |
|
|
439 |
// -----------------------------------------------------------------------------
|
|
440 |
/**
|
|
441 |
* Format sql query
|
|
442 |
* @format - sql format string
|
|
443 |
* @param appId - application id
|
|
444 |
* @param actId - activity id
|
|
445 |
* @return formated sql query
|
|
446 |
*/
|
|
447 |
HBufC* CAfStorage::BuildQueryLC(const TDesC& format,
|
|
448 |
TInt appId,
|
|
449 |
const TDesC& actId) const
|
116
|
450 |
{
|
99
|
451 |
TBuf<16> appName;
|
|
452 |
appName.AppendNum(appId);
|
|
453 |
RBuf actName;
|
|
454 |
CleanupClosePushL(actName);
|
|
455 |
actName.CreateL(actId.Length());
|
|
456 |
actName.Copy(actId);
|
|
457 |
HBufC* query = HBufC::NewL(format.Length() +
|
|
458 |
appName.Length() +
|
|
459 |
actName.Length() );
|
|
460 |
query->Des().AppendFormat(format, &appName, &actName);
|
|
461 |
CleanupStack::PopAndDestroy(&actName);
|
|
462 |
CleanupStack::PushL(query);
|
|
463 |
return query;
|
116
|
464 |
}
|
99
|
465 |
|
|
466 |
// -----------------------------------------------------------------------------
|
|
467 |
/**
|
|
468 |
* Execute sql query and result serialize into buffer
|
|
469 |
* @param dst - destination result buffer
|
|
470 |
* @param query - sql activity query
|
|
471 |
*/
|
116
|
472 |
void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst, const TDesC& query, CAfEntry::AccessRights rights, TInt limit, TBool deserializeAllData)
|
|
473 |
{
|
99
|
474 |
RDbView view;// Create a view on the database
|
|
475 |
CleanupClosePushL(view);
|
116
|
476 |
User::LeaveIfError(view.Prepare(iActDb, TDbQuery(query), view.EReadOnly));
|
99
|
477 |
User::LeaveIfError(view.EvaluateAll());
|
116
|
478 |
ActivitiesL(dst, view, rights, limit, deserializeAllData);
|
99
|
479 |
CleanupStack::PopAndDestroy(&view);
|
116
|
480 |
}
|
99
|
481 |
|
|
482 |
// -----------------------------------------------------------------------------
|
|
483 |
/**
|
|
484 |
* Return view deserialisd into entries array
|
|
485 |
* @param dst - destination result
|
|
486 |
* @param query - view
|
|
487 |
* @param rights - acess rights
|
|
488 |
*/
|
116
|
489 |
void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst,
|
|
490 |
RDbView& src,
|
|
491 |
CAfEntry::AccessRights rights,
|
|
492 |
TInt limit,
|
|
493 |
TBool deserializeAllData)
|
|
494 |
{
|
99
|
495 |
CDbColSet* row = src.ColSetL();
|
|
496 |
CleanupStack::PushL(row);
|
|
497 |
|
|
498 |
const TInt flagsOffset(row->ColNo(KFlagsColumnName)),
|
|
499 |
applicationOffset(row->ColNo(KApplicationColumnName)),
|
|
500 |
activityOffset(row->ColNo(KActivityColumnName)),
|
116
|
501 |
customNameOffset(row->ColNo(KCustomNameColumnName)),
|
119
|
502 |
dataOffset(row->ColNo(KDataColumnName)),
|
|
503 |
timestampOffset(row->ColNo(KTimestampColumnName));
|
99
|
504 |
|
|
505 |
RBuf activityName;
|
|
506 |
CleanupClosePushL(activityName);
|
|
507 |
|
116
|
508 |
RBuf customName;
|
|
509 |
CleanupClosePushL(customName);
|
|
510 |
|
|
511 |
|
|
512 |
for (src.FirstL(); src.AtRow(); src.NextL())
|
|
513 |
{
|
|
514 |
if ( 0 < limit && dst.Count() >= limit )
|
|
515 |
{
|
99
|
516 |
break;
|
116
|
517 |
}
|
99
|
518 |
src.GetL();
|
|
519 |
ReadDataL(activityName, src, activityOffset);
|
116
|
520 |
ReadDataL(customName, src, customNameOffset);
|
99
|
521 |
|
|
522 |
CAfEntry *entry = CAfEntry::NewLC(src.ColInt32(flagsOffset),
|
|
523 |
src.ColInt64(applicationOffset),
|
|
524 |
activityName,
|
116
|
525 |
customName,
|
99
|
526 |
KNullDesC,
|
|
527 |
KNullDesC8,
|
119
|
528 |
KNullDesC8,
|
|
529 |
src.ColTime(timestampOffset));
|
116
|
530 |
if( CAfEntry::Public == rights &&
|
|
531 |
(entry->Flags() & CAfEntry::Invisible) )
|
|
532 |
{
|
99
|
533 |
CleanupStack::PopAndDestroy(entry);
|
|
534 |
continue;
|
116
|
535 |
}
|
99
|
536 |
InternalizeDataL(*entry, src, dataOffset);
|
|
537 |
|
116
|
538 |
if (!deserializeAllData) {
|
|
539 |
entry->SetDataL(KNullDesC8(), CAfEntry::Public);
|
99
|
540 |
entry->SetDataL(KNullDesC8(), CAfEntry::Private);
|
116
|
541 |
} else {
|
|
542 |
if (CAfEntry::Public == rights) {
|
|
543 |
entry->SetDataL(KNullDesC8(), CAfEntry::Private);
|
|
544 |
}
|
99
|
545 |
}
|
116
|
546 |
|
99
|
547 |
dst.AppendL(entry);
|
|
548 |
CleanupStack::Pop(entry);
|
116
|
549 |
}
|
|
550 |
CleanupStack::PopAndDestroy(&customName);
|
99
|
551 |
CleanupStack::PopAndDestroy(&activityName);
|
|
552 |
CleanupStack::PopAndDestroy(row);
|
116
|
553 |
}
|
99
|
554 |
|
|
555 |
// -----------------------------------------------------------------------------
|
|
556 |
/**
|
|
557 |
* Get activity for update
|
|
558 |
* @param query - destination query result
|
|
559 |
* @param appId - application id
|
|
560 |
* @param actId - activity id
|
|
561 |
*/
|
|
562 |
void CAfStorage::GetActivityForUpdateL(RDbView& view, TInt appId, const TDesC& actId)
|
116
|
563 |
{
|
99
|
564 |
HBufC* query(SelectRowLC(appId, actId));
|
116
|
565 |
User::LeaveIfError(view.Prepare(iActDb, TDbQuery(*query), view.EUpdatable));
|
99
|
566 |
CleanupStack::PopAndDestroy(query);
|
|
567 |
User::LeaveIfError(view.EvaluateAll());
|
116
|
568 |
if( !view.FirstL() )
|
|
569 |
{
|
99
|
570 |
User::Leave(KErrNotFound);
|
116
|
571 |
}
|
99
|
572 |
}
|
|
573 |
|
|
574 |
// -----------------------------------------------------------------------------
|
|
575 |
void CAfStorage::ReadDataL(RBuf& dst, RDbRowSet& src, TInt offset) const
|
116
|
576 |
{
|
99
|
577 |
const TInt length(src.ColLength(offset));
|
|
578 |
CAfEntry::ReallocL(dst, length);
|
|
579 |
RDbColReadStream srcStream;
|
|
580 |
srcStream.OpenLC(src,offset);
|
|
581 |
srcStream.ReadL(dst, src.ColLength(offset));
|
|
582 |
CleanupStack::PopAndDestroy(&srcStream);
|
116
|
583 |
}
|
99
|
584 |
|
|
585 |
// -----------------------------------------------------------------------------
|
|
586 |
void CAfStorage::ExternalizeDataL(RDbRowSet& dst,const CAfEntry &src, TInt offset) const
|
116
|
587 |
{
|
99
|
588 |
RDbColWriteStream dbStream;
|
|
589 |
CleanupClosePushL(dbStream);
|
|
590 |
dbStream.OpenL(dst, offset);
|
|
591 |
src.ExternalizeDataOnlyL(dbStream);
|
|
592 |
CleanupStack::PopAndDestroy(&dbStream);
|
116
|
593 |
}
|
99
|
594 |
|
|
595 |
// -----------------------------------------------------------------------------
|
|
596 |
void CAfStorage::InternalizeDataL(CAfEntry & dst, RDbRowSet& src, TInt offset) const
|
116
|
597 |
{
|
99
|
598 |
RDbColReadStream dbStream;
|
|
599 |
CleanupClosePushL(dbStream);
|
|
600 |
dbStream.OpenL(src, offset);
|
|
601 |
dst.InternalizeDataOnlyL(dbStream);
|
|
602 |
CleanupStack::PopAndDestroy(&dbStream);
|
116
|
603 |
}
|
99
|
604 |
|
|
605 |
// -----------------------------------------------------------------------------
|
|
606 |
//
|
|
607 |
// -----------------------------------------------------------------------------
|
|
608 |
//
|
|
609 |
void CAfStorage::StoragePathL(RBuf &dst,
|
|
610 |
RFs& fileSystem,
|
|
611 |
TBool persistent)
|
116
|
612 |
{
|
|
613 |
if (dst.MaxLength() < KMaxPathLength)
|
|
614 |
{
|
99
|
615 |
dst.ReAllocL(KMaxPathLength);
|
116
|
616 |
}
|
99
|
617 |
dst.Zero();
|
|
618 |
User::LeaveIfError(fileSystem.PrivatePath(dst));
|
116
|
619 |
if(persistent)
|
|
620 |
{
|
99
|
621 |
dst.Append(KPersistent);
|
116
|
622 |
}
|
|
623 |
else
|
|
624 |
{
|
|
625 |
dst.Append(KNonPersistent);
|
|
626 |
}
|
99
|
627 |
}
|
|
628 |
|
|
629 |
// -----------------------------------------------------------------------------
|
|
630 |
//
|
|
631 |
// -----------------------------------------------------------------------------
|
|
632 |
//
|
|
633 |
void CAfStorage::AppStoragePathL(RBuf &dst,
|
|
634 |
RFs& fileSystem,
|
|
635 |
TInt uid,
|
|
636 |
TBool persistent)
|
116
|
637 |
{
|
99
|
638 |
StoragePathL(dst, fileSystem, persistent);
|
|
639 |
|
|
640 |
//Format activity path
|
|
641 |
dst.AppendFormat( KUidFormat, uid);
|
|
642 |
}
|
|
643 |
|
|
644 |
// -----------------------------------------------------------------------------
|
|
645 |
//
|
|
646 |
// -----------------------------------------------------------------------------
|
|
647 |
//
|
|
648 |
void CAfStorage::ThumbnailPathL(RBuf &dst,
|
|
649 |
RFs& fileSystem,
|
|
650 |
TInt uid,
|
|
651 |
const TDesC &activityName,
|
|
652 |
TBool persistent)
|
|
653 |
{
|
|
654 |
RBuf8 buff8;
|
|
655 |
CleanupClosePushL(buff8);
|
|
656 |
buff8.CreateL(activityName.Length());
|
|
657 |
buff8.Copy(activityName);
|
|
658 |
HBufC8 *activityHash = Md5HexDigestL(buff8);
|
|
659 |
CleanupStack::PopAndDestroy(&buff8);
|
|
660 |
CleanupStack::PushL(activityHash);
|
|
661 |
|
|
662 |
AppStoragePathL(dst, fileSystem, uid, persistent);
|
|
663 |
|
|
664 |
RBuf hash16;
|
|
665 |
CleanupClosePushL(hash16);
|
|
666 |
hash16.CreateL(KMaxPathLength);
|
|
667 |
hash16.Copy(*activityHash);
|
|
668 |
dst.Append(hash16);//reuse already allocated buffer to convert 8 -> 16
|
|
669 |
CleanupStack::PopAndDestroy(&hash16);
|
|
670 |
dst.Append(KExtFormat());
|
|
671 |
CleanupStack::PopAndDestroy(activityHash);
|
|
672 |
|
|
673 |
BaflUtils::EnsurePathExistsL(fileSystem, dst);
|
|
674 |
}
|
|
675 |
|
|
676 |
// -----------------------------------------------------------------------------
|
|
677 |
//
|
|
678 |
// -----------------------------------------------------------------------------
|
|
679 |
//
|
|
680 |
HBufC8* CAfStorage::Md5HexDigestL(const TDesC8 &string)
|
116
|
681 |
{
|
99
|
682 |
_LIT8(KMd5HexFormat, "%+02x");
|
|
683 |
CMD5* md5 = CMD5::NewL();
|
|
684 |
CleanupStack::PushL(md5);
|
|
685 |
|
|
686 |
TPtrC8 hashedSig(md5->Hash(string));
|
|
687 |
|
|
688 |
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
|
|
689 |
TPtr8 bufPtr = buf->Des();
|
|
690 |
|
|
691 |
for(TInt i(0); i< hashedSig.Length(); ++i) {
|
|
692 |
bufPtr.AppendFormat(KMd5HexFormat,hashedSig[i]);
|
|
693 |
}
|
|
694 |
CleanupStack::PopAndDestroy(md5);
|
|
695 |
return buf;
|
116
|
696 |
}
|
112
|
697 |
|
|
698 |
// -----------------------------------------------------------------------------
|
|
699 |
/**
|
|
700 |
* Cancel ongoing cleanup if one is in progress.
|
|
701 |
* @return ETrue if the database cleanup was in progress, EFalse otherwise
|
|
702 |
*/
|
|
703 |
TBool CAfStorage::InterruptCleanup()
|
116
|
704 |
{
|
|
705 |
if( iDatabaseCleaner->IsActive() )
|
|
706 |
{
|
|
707 |
iDatabaseCleaner->Cancel();
|
112
|
708 |
return ETrue;
|
116
|
709 |
}
|
|
710 |
else
|
|
711 |
{
|
112
|
712 |
return EFalse;
|
116
|
713 |
}
|
112
|
714 |
}
|
|
715 |
|
|
716 |
// -----------------------------------------------------------------------------
|
|
717 |
/**
|
|
718 |
* Start database cleanup
|
|
719 |
*/
|
|
720 |
void CAfStorage::RequestCleanup()
|
116
|
721 |
{
|
|
722 |
iDatabaseCleaner->StartCleanup();
|
|
723 |
}
|