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