89
|
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 |
|
|
18 |
#include "hsactivitydbclient_p.h"
|
|
19 |
#include "hsactivitydbasyncrequest_p.h"
|
|
20 |
#include "hsactivityglobals.h"
|
|
21 |
#include "hsserializer.h"
|
|
22 |
|
|
23 |
// -----------------------------------------------------------------------------
|
|
24 |
//
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
//
|
|
27 |
HsActivityDbClientPrivate::HsActivityDbClientPrivate(HsActivityDbAsyncRequestObserver& observer)
|
|
28 |
{
|
|
29 |
mAsyncDataHandler = HsActivityDbAsyncRequestPrivate::NewL(observer, *this);
|
|
30 |
}
|
|
31 |
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
HsActivityDbClientPrivate::~HsActivityDbClientPrivate()
|
|
37 |
{
|
|
38 |
delete mAsyncDataHandler;
|
|
39 |
Close();
|
|
40 |
}
|
|
41 |
|
|
42 |
// -----------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
int HsActivityDbClientPrivate::connect()
|
|
47 |
{
|
|
48 |
TRAPD(errNo, connectL());
|
|
49 |
return errNo;
|
|
50 |
}
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
int HsActivityDbClientPrivate::addActivity(const QVariantHash &activity)
|
|
57 |
{
|
|
58 |
TRAPD( errNo, execSimpleRequestL(AddActivity, activity);)
|
|
59 |
return errNo;
|
|
60 |
}
|
|
61 |
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
int HsActivityDbClientPrivate::updateActivity(const QVariantHash &activity)
|
|
67 |
{
|
|
68 |
TRAPD( errNo, execSimpleRequestL(UpdateActivity, activity);)
|
|
69 |
return errNo;
|
|
70 |
}
|
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
int HsActivityDbClientPrivate::removeActivity(const QVariantHash &activity)
|
|
77 |
{
|
|
78 |
TRAPD( errNo, execSimpleRequestL(RemoveActivity, activity);)
|
|
79 |
return errNo;
|
|
80 |
}
|
|
81 |
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
int HsActivityDbClientPrivate::removeApplicationActivities(const QVariantHash &activity)
|
|
87 |
{
|
|
88 |
TRAPD( errNo, execSimpleRequestL(RemoveApplicationActivities, activity);)
|
|
89 |
return errNo;
|
|
90 |
}
|
|
91 |
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
int HsActivityDbClientPrivate::activities(QList<QVariantHash>& result)
|
|
97 |
{
|
|
98 |
TRAPD(errNo, activitiesL(result));
|
|
99 |
return errNo;
|
|
100 |
}
|
|
101 |
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
int HsActivityDbClientPrivate::applicationActivities(QList<QVariantHash>& result,
|
|
107 |
const QVariantHash & condition)
|
|
108 |
{
|
|
109 |
TRAPD(errNo, applicationActivitiesL(result, condition));
|
|
110 |
return errNo;
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
int HsActivityDbClientPrivate::waitActivity(const QVariantHash &activity)
|
|
119 |
{
|
|
120 |
TRAPD( errNo, waitActivityL(activity);)
|
|
121 |
return errNo;
|
|
122 |
}
|
|
123 |
|
|
124 |
// -----------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
// -----------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
int HsActivityDbClientPrivate::launchActivity(const QVariantHash &activity)
|
|
129 |
{
|
|
130 |
TRAPD( errNo, execSimpleRequestL(LaunchActivity, activity);)
|
|
131 |
return errNo;
|
|
132 |
}
|
|
133 |
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
// -----------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
int HsActivityDbClientPrivate::cancelWaitActivity()
|
|
139 |
{
|
|
140 |
return SendReceive(CancelWait, TIpcArgs());
|
|
141 |
}
|
|
142 |
|
|
143 |
// -----------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
void HsActivityDbClientPrivate::startServerL()
|
|
148 |
{
|
|
149 |
RProcess server;
|
|
150 |
const TUidType uid(KNullUid, KNullUid, KActivityServerUid);
|
|
151 |
User::LeaveIfError(server.Create( KActivityServerName, KNullDesC, uid));
|
|
152 |
TRequestStatus stat;
|
|
153 |
server.Rendezvous( stat );
|
|
154 |
if ( stat != KRequestPending ) {
|
|
155 |
server.Kill(0);
|
|
156 |
} else {
|
|
157 |
server.Resume();
|
|
158 |
}
|
|
159 |
User::WaitForRequest(stat);
|
|
160 |
int errNo = (EExitPanic == server.ExitType()) ?
|
|
161 |
KErrGeneral : stat.Int();
|
|
162 |
if(KErrCancel == errNo) {
|
|
163 |
errNo = KErrNone;
|
|
164 |
}
|
|
165 |
server.Close();
|
|
166 |
User::LeaveIfError(errNo);
|
|
167 |
}
|
|
168 |
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
void HsActivityDbClientPrivate::connectL()
|
|
174 |
{
|
|
175 |
const int asyncMessageSlots(4);
|
|
176 |
const int maxRetry(4);
|
|
177 |
|
|
178 |
TInt retry = maxRetry;
|
|
179 |
TInt errNo(KErrNone);
|
|
180 |
do {
|
|
181 |
errNo = CreateSession( KActivityServerName, TVersion( 0, 0, 0 ), asyncMessageSlots );
|
|
182 |
if( KErrNotFound != errNo && KErrServerTerminated != errNo) {
|
|
183 |
retry =0;
|
|
184 |
} else {
|
|
185 |
TRAP(errNo, startServerL());
|
|
186 |
if (KErrNone != errNo && KErrAlreadyExists != errNo) {
|
|
187 |
retry =0;
|
|
188 |
}
|
|
189 |
}
|
|
190 |
} while(--retry > 0);
|
|
191 |
User::LeaveIfError(errNo);
|
|
192 |
}
|
|
193 |
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
void HsActivityDbClientPrivate::execSimpleRequestL(int function, const QVariantHash &activity)
|
|
199 |
{
|
|
200 |
RBuf8 data;
|
|
201 |
CleanupClosePushL(data);
|
|
202 |
data.CreateL(256);
|
|
203 |
data << activity;
|
|
204 |
User::LeaveIfError(SendReceive(function, TIpcArgs(&data)));
|
|
205 |
CleanupStack::PopAndDestroy(&data);
|
|
206 |
}
|
|
207 |
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
// -----------------------------------------------------------------------------
|
|
211 |
//
|
|
212 |
void HsActivityDbClientPrivate::requestedActivityNameL(QString& result,
|
|
213 |
const QVariantHash &activity)
|
|
214 |
{
|
|
215 |
RBuf8 data;
|
|
216 |
TPckgBuf<int> sizeBuf;
|
|
217 |
CleanupClosePushL(data);
|
|
218 |
data.CreateL(256);
|
|
219 |
data << activity;
|
|
220 |
User::LeaveIfError(SendReceive(RequestedActivityName, TIpcArgs(&data,&sizeBuf)));
|
|
221 |
if(sizeBuf() > data.MaxSize()) {
|
|
222 |
data.ReAlloc(sizeBuf());
|
|
223 |
}
|
|
224 |
User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
|
|
225 |
result = QString::fromAscii(reinterpret_cast<const char*>(data.Ptr()),
|
|
226 |
data.Length());
|
|
227 |
CleanupStack::PopAndDestroy(&data);
|
|
228 |
}
|
|
229 |
|
|
230 |
// -----------------------------------------------------------------------------
|
|
231 |
//
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
void HsActivityDbClientPrivate::activitiesL(QList<QVariantHash>& result)
|
|
235 |
{
|
|
236 |
RBuf8 data;
|
|
237 |
TPckgBuf<int> sizeBuf;
|
|
238 |
CleanupClosePushL(data);
|
|
239 |
data.CreateL(256);
|
|
240 |
User::LeaveIfError(SendReceive(Activities, TIpcArgs(&data, &sizeBuf)));
|
|
241 |
if(sizeBuf() > data.MaxSize()) {
|
|
242 |
data.ReAlloc(sizeBuf());
|
|
243 |
}
|
|
244 |
User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
|
|
245 |
result << data;
|
|
246 |
CleanupStack::PopAndDestroy(&data);
|
|
247 |
}
|
|
248 |
|
|
249 |
// -----------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
// -----------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
void HsActivityDbClientPrivate::applicationActivitiesL(QList<QVariantHash>& result,
|
|
254 |
const QVariantHash & condition)
|
|
255 |
{
|
|
256 |
RBuf8 data;
|
|
257 |
TPckgBuf<int> sizeBuf;
|
|
258 |
CleanupClosePushL(data);
|
|
259 |
data.CreateL(256);
|
|
260 |
data << condition;
|
|
261 |
User::LeaveIfError(SendReceive(ApplicationActivities, TIpcArgs(&data, &sizeBuf)));
|
|
262 |
if(sizeBuf() > data.MaxSize()) {
|
|
263 |
data.ReAlloc(sizeBuf());
|
|
264 |
}
|
|
265 |
User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
|
|
266 |
result << data;
|
|
267 |
CleanupStack::PopAndDestroy(&data);
|
|
268 |
}
|
|
269 |
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
// -----------------------------------------------------------------------------
|
|
273 |
//
|
|
274 |
void HsActivityDbClientPrivate::waitActivityL(const QVariantHash &activity)
|
|
275 |
{
|
|
276 |
if(mAsyncDataHandler->IsActive()) {
|
|
277 |
User::Leave(KErrServerBusy);
|
|
278 |
} else {
|
|
279 |
mAsyncDataHandler->waitActivity(activity);
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
// -----------------------------------------------------------------------------
|
|
284 |
//
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void HsActivityDbClientPrivate::getData(RBuf8& data)
|
|
288 |
{
|
|
289 |
SendReceive(GetData, TIpcArgs(&data));
|
|
290 |
}
|
|
291 |
|
|
292 |
// -----------------------------------------------------------------------------
|
|
293 |
//
|
|
294 |
// -----------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
void HsActivityDbClientPrivate::sendDataAsync(int func,
|
|
297 |
const TIpcArgs &data,
|
|
298 |
TRequestStatus& status)
|
|
299 |
{
|
|
300 |
SendReceive(func, data, status);
|
|
301 |
}
|