sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Implements CUpsSession. See class and function definitions for
|
sl@0
|
16 |
* more information.
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include "upsserver.h"
|
sl@0
|
26 |
#include "policycache.h"
|
sl@0
|
27 |
#include <ups/upsdbw.h>
|
sl@0
|
28 |
#include <scs/ipcstream.h>
|
sl@0
|
29 |
#include <scs/nullstream.h>
|
sl@0
|
30 |
#include "pluginmanager.h"
|
sl@0
|
31 |
#include "viewevaluator.h"
|
sl@0
|
32 |
#include "updateevaluator.h"
|
sl@0
|
33 |
#include "policychangeevaluator.h"
|
sl@0
|
34 |
|
sl@0
|
35 |
namespace UserPromptService
|
sl@0
|
36 |
{
|
sl@0
|
37 |
|
sl@0
|
38 |
CUpsSession* CUpsSession::NewL(CUpsServer &aServer)
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Factory function allocates new instance of CUpsSession.
|
sl@0
|
41 |
|
sl@0
|
42 |
@return New, initialized instance of CUpsSession
|
sl@0
|
43 |
which is owned by the caller.
|
sl@0
|
44 |
*/
|
sl@0
|
45 |
{
|
sl@0
|
46 |
CUpsSession* self = new(ELeave) CUpsSession(aServer);
|
sl@0
|
47 |
CleanupStack::PushL(self);
|
sl@0
|
48 |
self->ConstructL(); // CScsSession implementation
|
sl@0
|
49 |
CleanupStack::Pop(self);
|
sl@0
|
50 |
return self;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CUpsSession::CUpsSession(CUpsServer &aServer)
|
sl@0
|
54 |
/**
|
sl@0
|
55 |
This private constructor prevents direct instantiation.
|
sl@0
|
56 |
*/
|
sl@0
|
57 |
: CScsSession(aServer), iDbViewHandle(aServer.iDbHandle, this)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
// empty.
|
sl@0
|
60 |
//RDebug::Printf("0x%x CUpsSession(server %x) (&iDbViewHandle %x)\n", this, &aServer, &iDbViewHandle);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
CUpsSession::~CUpsSession()
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
The base class destructor destroys any remaining subsessions
|
sl@0
|
66 |
or outstanding requests.
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
{
|
sl@0
|
69 |
//RDebug::Printf("0x%x ~CUpsSession (&iDbViewHandle %x)\n", this, &iDbViewHandle);
|
sl@0
|
70 |
CleanupView();
|
sl@0
|
71 |
iServiceConfig.Close();
|
sl@0
|
72 |
|
sl@0
|
73 |
iDbViewHandle.Close();
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
TBool CUpsSession::DoServiceL(TInt aFunction, const RMessage2& aMessage)
|
sl@0
|
77 |
/**
|
sl@0
|
78 |
Implement CScsSession by handling the supplied message.
|
sl@0
|
79 |
|
sl@0
|
80 |
Note the subsession creation command is automatically sent to
|
sl@0
|
81 |
DoCreateSubsessionL, and not this function.
|
sl@0
|
82 |
|
sl@0
|
83 |
@param aFunction Function identifier without SCS code.
|
sl@0
|
84 |
@param aMessage Standard server-side handle to message. Not used.
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
{
|
sl@0
|
87 |
TSessionFunction f = static_cast<TSessionFunction>(aFunction);
|
sl@0
|
88 |
//RDebug::Printf("0x%x CUpsSession::DoServiceL function %d\n", this, f);
|
sl@0
|
89 |
switch (f)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
case EGetClientConfigLength:
|
sl@0
|
92 |
{
|
sl@0
|
93 |
iServiceConfig.Close();
|
sl@0
|
94 |
UpsServer()->iPolicyCache->ServiceConfigL(aMessage.SecureId(), iServiceConfig);
|
sl@0
|
95 |
|
sl@0
|
96 |
TPckgBuf<TInt> lengthBuf;
|
sl@0
|
97 |
lengthBuf() = iServiceConfig.Count();
|
sl@0
|
98 |
aMessage.WriteL(0, lengthBuf);
|
sl@0
|
99 |
return ETrue; // Complete request with KErrNone
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
case EGetClientConfigData:
|
sl@0
|
103 |
{
|
sl@0
|
104 |
TInt count = iServiceConfig.Count();
|
sl@0
|
105 |
for(TInt i=0; i < count; ++i)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
const TServiceConfig &sc = iServiceConfig[i];
|
sl@0
|
108 |
TPtrC8 ptr((TUint8 *) &sc, sizeof(TServiceConfig));
|
sl@0
|
109 |
aMessage.WriteL(0, ptr, i*sizeof(TServiceConfig));
|
sl@0
|
110 |
}
|
sl@0
|
111 |
iServiceConfig.Close();
|
sl@0
|
112 |
return ETrue; // Complete request with KErrNone
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
case EDeleteDatabase:
|
sl@0
|
116 |
TRAPD(err, UpsServer()->iDbHandle->DeleteDatabaseL(UpsServer()->iFs));
|
sl@0
|
117 |
UpsServer()->iDbHandle.Close();
|
sl@0
|
118 |
User::LeaveIfError(err);
|
sl@0
|
119 |
return ETrue; // Complete request with KErrNone
|
sl@0
|
120 |
|
sl@0
|
121 |
case ECreateView:
|
sl@0
|
122 |
{
|
sl@0
|
123 |
if(iManagementView != 0)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
User::Leave(KErrServerBusy);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
CViewEvaluator *viewEvaluator = CViewEvaluator::NewLC(this, aMessage);
|
sl@0
|
129 |
viewEvaluator->TransferToScsFrameworkL();
|
sl@0
|
130 |
CleanupStack::Pop(viewEvaluator); // view now owned by SCS framework
|
sl@0
|
131 |
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
The CViewEvaluator is now responsible for completing the request,
|
sl@0
|
134 |
so we must NOT leave.
|
sl@0
|
135 |
*/
|
sl@0
|
136 |
viewEvaluator->StartEvaluatingView();
|
sl@0
|
137 |
return EFalse; // Do not complete client request - view evaulator will...
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
case ENextMatch:
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if((iManagementView == 0) || (iRecord == 0))
|
sl@0
|
143 |
{
|
sl@0
|
144 |
User::Leave(KErrAbort);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
// Copy the record to arg 0
|
sl@0
|
148 |
RIpcWriteStream ipcstream;
|
sl@0
|
149 |
ipcstream.Open(aMessage, 0);
|
sl@0
|
150 |
CleanupClosePushL(ipcstream);
|
sl@0
|
151 |
|
sl@0
|
152 |
ipcstream << *iRecord;
|
sl@0
|
153 |
|
sl@0
|
154 |
CleanupStack::PopAndDestroy(&ipcstream);
|
sl@0
|
155 |
|
sl@0
|
156 |
// Update arg 1 with the length of the next record.
|
sl@0
|
157 |
PrefetchRecordAndWriteLengthToClientL(aMessage);
|
sl@0
|
158 |
return ETrue; // Complete client request with KErrNone
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
case ECloseView:
|
sl@0
|
162 |
{
|
sl@0
|
163 |
CleanupView();
|
sl@0
|
164 |
return ETrue; // Complete client request with KErrNone
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
case ERemoveDecisions:
|
sl@0
|
168 |
{
|
sl@0
|
169 |
// Read filter from the client arg 0
|
sl@0
|
170 |
RIpcReadStream ipcstream;
|
sl@0
|
171 |
ipcstream.Open(aMessage, 0);
|
sl@0
|
172 |
CleanupClosePushL(ipcstream);
|
sl@0
|
173 |
CDecisionFilter *filter = CDecisionFilter::NewLC();
|
sl@0
|
174 |
ipcstream >> *filter;
|
sl@0
|
175 |
|
sl@0
|
176 |
UpsServer()->iDbHandle->RemoveDecisionsL(*filter);
|
sl@0
|
177 |
|
sl@0
|
178 |
CleanupStack::PopAndDestroy(filter);
|
sl@0
|
179 |
CleanupStack::PopAndDestroy(&ipcstream);
|
sl@0
|
180 |
return ETrue; // Complete client request with KErrNone
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
case EUpdateDecision:
|
sl@0
|
184 |
{
|
sl@0
|
185 |
CUpdateEvaluator *updateEvaluator = CUpdateEvaluator::NewLC(this, aMessage);
|
sl@0
|
186 |
updateEvaluator->TransferToScsFrameworkL();
|
sl@0
|
187 |
CleanupStack::Pop(updateEvaluator); // view now owned by SCS framework
|
sl@0
|
188 |
|
sl@0
|
189 |
/**
|
sl@0
|
190 |
The CViewEvaluator is now responsible for completing the request,
|
sl@0
|
191 |
so we must NOT leave.
|
sl@0
|
192 |
*/
|
sl@0
|
193 |
updateEvaluator->StartUpdate();
|
sl@0
|
194 |
return EFalse; // Do not complete client request - view evaulator will...
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
case EDeleteDecisionsForExe:
|
sl@0
|
198 |
{
|
sl@0
|
199 |
TUid exeSid;
|
sl@0
|
200 |
exeSid.iUid = aMessage.Int0();
|
sl@0
|
201 |
|
sl@0
|
202 |
CDecisionFilter *filter = CDecisionFilter::NewLC();
|
sl@0
|
203 |
filter->SetClientSid(exeSid, EEqual);
|
sl@0
|
204 |
|
sl@0
|
205 |
UpsServer()->iDbHandle->RemoveDecisionsL(*filter);
|
sl@0
|
206 |
|
sl@0
|
207 |
CleanupStack::PopAndDestroy(filter);
|
sl@0
|
208 |
|
sl@0
|
209 |
return ETrue; // Complete client request with KErrNone
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
case ENotifyPluginsMayHaveChanged:
|
sl@0
|
213 |
// Tell plugin manager to unload, and hence reload, plugins ASAP.
|
sl@0
|
214 |
UpsServer()->iPluginManager->Unload();
|
sl@0
|
215 |
return ETrue; // Complete client request with KErrNone
|
sl@0
|
216 |
|
sl@0
|
217 |
case ENotifyPolicyFilesChanged:
|
sl@0
|
218 |
{
|
sl@0
|
219 |
CPolicyChangeEvaluator *changeEvaluator = CPolicyChangeEvaluator::NewLC(UpsServer()->iPolicyCache, this, aMessage);
|
sl@0
|
220 |
changeEvaluator->TransferToScsFrameworkL();
|
sl@0
|
221 |
CleanupStack::Pop(changeEvaluator); // Nnow owned by SCS framework
|
sl@0
|
222 |
|
sl@0
|
223 |
/**
|
sl@0
|
224 |
The CPolicyChangeEvaluator is now responsible for completing the request,
|
sl@0
|
225 |
so we must NOT leave.
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
changeEvaluator->StartUpdate();
|
sl@0
|
228 |
|
sl@0
|
229 |
// Release our reference to the policy cache
|
sl@0
|
230 |
UpsServer()->iPolicyCache.Release();
|
sl@0
|
231 |
|
sl@0
|
232 |
return EFalse; // Do not complete client request - policy change evaluator will...
|
sl@0
|
233 |
}
|
sl@0
|
234 |
BULLSEYE_OFF
|
sl@0
|
235 |
default:
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
BULLSEYE_RESTORE
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
BULLSEYE_OFF
|
sl@0
|
241 |
User::Leave(KErrNotSupported);
|
sl@0
|
242 |
/*lint -unreachable */
|
sl@0
|
243 |
return ETrue;
|
sl@0
|
244 |
BULLSEYE_RESTORE
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
CScsSubsession* CUpsSession::DoCreateSubsessionL(TInt aFunction, const RMessage2& aMessage)
|
sl@0
|
248 |
/**
|
sl@0
|
249 |
Override CScsSession by allocating a new subsession object.
|
sl@0
|
250 |
|
sl@0
|
251 |
@param aFunction Function identifier without SCS code.
|
sl@0
|
252 |
@param aMessage Standard server-side handle to message. Not used.
|
sl@0
|
253 |
@return New, initialized instance of CUpsSubsession, which is
|
sl@0
|
254 |
owned by the caller.
|
sl@0
|
255 |
*/
|
sl@0
|
256 |
{
|
sl@0
|
257 |
TSessionFunction f = static_cast<TSessionFunction>(aFunction);
|
sl@0
|
258 |
|
sl@0
|
259 |
switch (f)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
case ESessSubsessFromThreadId:
|
sl@0
|
262 |
// create a subsession object curried on the supplied thread ID.
|
sl@0
|
263 |
return CUpsSubsession::NewL(*this, aMessage);
|
sl@0
|
264 |
|
sl@0
|
265 |
default:
|
sl@0
|
266 |
User::Leave(KErrNotSupported);
|
sl@0
|
267 |
/*lint -unreachable */
|
sl@0
|
268 |
return 0; // avoid compiler warning
|
sl@0
|
269 |
}
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
void CUpsSession::PrefetchRecordAndWriteLengthToClientL(const RMessagePtr2& aMessage)
|
sl@0
|
273 |
/**
|
sl@0
|
274 |
Retrieve the next record from the iManagementView and return its length to the
|
sl@0
|
275 |
client in arg 1.
|
sl@0
|
276 |
*/
|
sl@0
|
277 |
{
|
sl@0
|
278 |
if(iManagementView == 0)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
User::Leave(KErrEof);
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
TPckgBuf<TUint32> nextRecordLenghthBuf;
|
sl@0
|
284 |
|
sl@0
|
285 |
delete iRecord;
|
sl@0
|
286 |
iRecord = 0;
|
sl@0
|
287 |
TRAPD(err, iRecord = iManagementView->NextDecisionL());
|
sl@0
|
288 |
if((err != KErrNone) || (iRecord == 0))
|
sl@0
|
289 |
{
|
sl@0
|
290 |
nextRecordLenghthBuf() = 0;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
else
|
sl@0
|
293 |
{
|
sl@0
|
294 |
RNullWriteStream nullstream;
|
sl@0
|
295 |
nullstream << *iRecord;
|
sl@0
|
296 |
nextRecordLenghthBuf() = nullstream.BytesWritten();
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
aMessage.WriteL(1, nextRecordLenghthBuf);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
void CUpsSession::CleanupView()
|
sl@0
|
303 |
/**
|
sl@0
|
304 |
Cleanup view objects
|
sl@0
|
305 |
*/
|
sl@0
|
306 |
{
|
sl@0
|
307 |
delete iManagementView;
|
sl@0
|
308 |
iManagementView = 0;
|
sl@0
|
309 |
delete iRecord;
|
sl@0
|
310 |
iRecord = 0;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
void CUpsSession::DbHandleAboutToBeDeleted()
|
sl@0
|
314 |
/**
|
sl@0
|
315 |
Master DB handle is about to be deleted, so we must delete our view now.
|
sl@0
|
316 |
This will also cause the next RUpsManageMent::NextMatchL call to leave.
|
sl@0
|
317 |
*/
|
sl@0
|
318 |
{
|
sl@0
|
319 |
if(iManagementView)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
iManagementView->Cancel();
|
sl@0
|
322 |
CleanupView();
|
sl@0
|
323 |
}
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
} // End of namespace UserPromptService
|
sl@0
|
327 |
// End of file
|