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 <s32mem.h>
|
|
18 |
#include <fbs.h>
|
|
19 |
#include <bautils.h>
|
|
20 |
|
|
21 |
#include "afstoragesynctask.h"
|
|
22 |
#include "afcmd.h"
|
|
23 |
#include "afentry.h"
|
|
24 |
|
|
25 |
_LIT(KUnsupportedStorageSyncTask, "Unsupported sync storage task");
|
|
26 |
|
|
27 |
// -----------------------------------------------------------------------------
|
|
28 |
/**
|
|
29 |
* Handle synchronous data storage requests
|
|
30 |
* @param dataStorage - data storage
|
|
31 |
* @param msg - request message
|
|
32 |
*/
|
|
33 |
void AfStorageSyncTask::ExecuteL(MAfTaskStorage& observers,
|
|
34 |
CAfStorage& dataStorage,
|
|
35 |
const RMessage2& msg)
|
|
36 |
{
|
|
37 |
switch (msg.Function()) {
|
107
|
38 |
case SaveActivity:
|
|
39 |
SaveActivityL(dataStorage, msg);
|
|
40 |
break;
|
99
|
41 |
case RemoveActivity:
|
|
42 |
DeleteActivityL(dataStorage, msg);
|
|
43 |
break;
|
|
44 |
case RemoveApplicationActivities:
|
|
45 |
DeleteApplicationActivitiesL(dataStorage, msg);
|
|
46 |
break;
|
|
47 |
default:
|
|
48 |
//this code shouldn't be called. fatal error: means wrong session implementation
|
|
49 |
User::Panic(KUnsupportedStorageSyncTask, KErrGeneral);
|
|
50 |
};
|
107
|
51 |
if(SaveActivity != msg.Function()) {
|
|
52 |
//function SaveActivityL complete message. DON'T DO THIS HERE
|
|
53 |
msg.Complete(KErrNone);
|
|
54 |
}
|
99
|
55 |
NotifyChangeL(observers, msg);
|
|
56 |
}
|
|
57 |
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
/**
|
107
|
60 |
* Handle saving activiy
|
|
61 |
* @param dataStorage - data storage
|
|
62 |
* @param msg - request message
|
|
63 |
*/
|
|
64 |
void AfStorageSyncTask::SaveActivityL(CAfStorage& dataStorage, const RMessage2& msg)
|
|
65 |
{
|
|
66 |
TPckgBuf<TInt> bitmapHdl(0);
|
|
67 |
CAfEntry *entry = CAfEntry::NewLC(msg);
|
|
68 |
msg.ReadL(1, bitmapHdl);
|
112
|
69 |
|
|
70 |
TInt hdl = bitmapHdl();
|
|
71 |
if (0 >= hdl) {
|
|
72 |
User::Leave(KErrCorrupt);
|
|
73 |
}
|
|
74 |
CFbsBitmap *bitmap = new (ELeave) CFbsBitmap;
|
|
75 |
CleanupStack::PushL(bitmap);
|
|
76 |
User::LeaveIfError(bitmap->Duplicate(hdl));
|
107
|
77 |
|
|
78 |
//all data is retrieved. compleate message to improve response time
|
|
79 |
msg.Complete(KErrNone);
|
112
|
80 |
|
|
81 |
// trap all other leaving methods to prevent completing message in ServiceError
|
|
82 |
TRAP_IGNORE(
|
|
83 |
RBuf thumbnailPath;
|
|
84 |
CleanupClosePushL(thumbnailPath);
|
|
85 |
DeleteActivityScreenshotL(dataStorage,
|
|
86 |
entry->ApplicationId(),
|
|
87 |
entry->ActivityId());
|
|
88 |
|
|
89 |
dataStorage.ThumbnailPathL(thumbnailPath,
|
|
90 |
dataStorage.Fs(),
|
|
91 |
entry->ApplicationId(),
|
|
92 |
entry->ActivityId(),
|
|
93 |
entry->Flags() & CAfEntry::Persistent);
|
|
94 |
|
|
95 |
User::LeaveIfError(bitmap->Save(thumbnailPath));
|
|
96 |
|
|
97 |
entry->SetImageSrcL(thumbnailPath);
|
|
98 |
dataStorage.SaveActivityL(*entry);
|
|
99 |
CleanupStack::PopAndDestroy(&thumbnailPath);
|
|
100 |
)
|
|
101 |
CleanupStack::PopAndDestroy(bitmap);
|
107
|
102 |
CleanupStack::PopAndDestroy(entry);
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
/**
|
99
|
107 |
* Handle removing activity.
|
|
108 |
* @param dataStorage - data storage
|
|
109 |
* @param msg - request message
|
|
110 |
*/
|
|
111 |
void AfStorageSyncTask::DeleteActivityL(CAfStorage& dataStorage,
|
|
112 |
const RMessage2& msg)
|
|
113 |
{
|
|
114 |
CAfEntry *entry = CAfEntry::NewLC(msg);
|
|
115 |
dataStorage.DeleteActivityL(*entry);
|
|
116 |
DeleteActivityScreenshotL(dataStorage,
|
|
117 |
entry->ApplicationId(),
|
|
118 |
entry->ActivityId());
|
|
119 |
CleanupStack::PopAndDestroy(entry);
|
|
120 |
}
|
|
121 |
|
|
122 |
// -----------------------------------------------------------------------------
|
|
123 |
/**
|
|
124 |
* Handle removing activity.
|
|
125 |
* @param dataStorage - data storage
|
|
126 |
* @param msg - request message
|
|
127 |
*/
|
|
128 |
void AfStorageSyncTask::DeleteActivityScreenshotL(CAfStorage& dataStorage,
|
|
129 |
TInt uid,
|
|
130 |
const TDesC &activityName)
|
|
131 |
{
|
|
132 |
RBuf thumbnailPath;
|
|
133 |
CleanupClosePushL(thumbnailPath);
|
|
134 |
dataStorage.ThumbnailPathL(thumbnailPath,
|
|
135 |
dataStorage.Fs(),
|
|
136 |
uid,
|
|
137 |
activityName,
|
|
138 |
TRUE);
|
|
139 |
dataStorage.Fs().Delete(thumbnailPath);
|
|
140 |
thumbnailPath.Zero();
|
|
141 |
dataStorage.ThumbnailPathL(thumbnailPath,
|
|
142 |
dataStorage.Fs(),
|
|
143 |
uid,
|
|
144 |
activityName,
|
|
145 |
FALSE);
|
|
146 |
dataStorage.Fs().Delete(thumbnailPath);
|
|
147 |
thumbnailPath.Zero();
|
|
148 |
CleanupStack::PopAndDestroy(&thumbnailPath);
|
|
149 |
}
|
|
150 |
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
/**
|
|
153 |
* Handle removing all application activities.
|
|
154 |
* @param dataStorage - data storage
|
|
155 |
* @param msg - request message
|
|
156 |
*/
|
|
157 |
void AfStorageSyncTask::DeleteApplicationActivitiesL(CAfStorage& dataStorage,
|
|
158 |
const RMessage2& msg)
|
|
159 |
{
|
|
160 |
CAfEntry *entry = CAfEntry::NewLC(msg);
|
|
161 |
dataStorage.DeleteActivitiesL(*entry);
|
|
162 |
CleanupStack::PopAndDestroy(entry);
|
|
163 |
}
|
|
164 |
|
|
165 |
// -----------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
// -----------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
void AfStorageSyncTask::NotifyChangeL(MAfTaskStorage& observers,
|
|
170 |
const RMessage2& msg)
|
|
171 |
{
|
|
172 |
const RPointerArray<CAfTask> &table(observers.StorageData());
|
|
173 |
for (TInt iter(table.Count() - 1); 0 <= iter; --iter) {
|
|
174 |
table[iter]->BroadcastReceivedL(msg);
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
void AfStorageSyncTask::CreateThumbnailL(const TDesC &path, TInt hdl)
|
|
183 |
{
|
|
184 |
if (0 >= hdl) {
|
|
185 |
User::Leave(KErrCorrupt);
|
|
186 |
}
|
|
187 |
CFbsBitmap *bitmap = new (ELeave) CFbsBitmap;
|
|
188 |
CleanupStack::PushL(bitmap);
|
|
189 |
User::LeaveIfError(bitmap->Duplicate(hdl));
|
|
190 |
User::LeaveIfError(bitmap->Save(path));
|
|
191 |
CleanupStack::PopAndDestroy(bitmap);
|
|
192 |
}
|