30
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: Interface to HSPS service
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// SYSTEM INCLUDES
|
|
19 |
#include <eikenv.h>
|
|
20 |
#include <eikappui.h>
|
|
21 |
#include <eikapp.h>
|
|
22 |
#include <bldvariant.hrh>
|
|
23 |
|
|
24 |
#include <hspsdomattribute.h>
|
|
25 |
#include <mhspsdomlistitem.h>
|
|
26 |
#include <hspsdomlist.h>
|
|
27 |
#include <hspsdomdepthiterator.h>
|
|
28 |
#include <hspsdomnode.h>
|
|
29 |
#include <hspsdefinitionrepository.h>
|
|
30 |
#include <hspsresource.h>
|
|
31 |
|
|
32 |
#include "hspsconfigurationservice.h"
|
|
33 |
#include "hspsxmlelements.h"
|
|
34 |
#include "hspscallback.h"
|
|
35 |
#include "hspsserviceutilities.h"
|
|
36 |
|
|
37 |
#ifdef HSPS_LOG_ACTIVE
|
|
38 |
#include <hspsodtdump.h>
|
|
39 |
#include <hspslogbusfile.h>
|
|
40 |
#endif
|
|
41 |
|
|
42 |
// ======== LOCAL CONSTANTS ========
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
// Two-phased constructor.
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
EXPORT_C CHspsConfigurationService* CHspsConfigurationService::NewL()
|
|
51 |
{
|
|
52 |
CHspsConfigurationService* self = new (ELeave) CHspsConfigurationService;
|
|
53 |
CleanupStack::PushL( self );
|
|
54 |
self->ConstructL();
|
|
55 |
CleanupStack::Pop( self );
|
|
56 |
return self;
|
|
57 |
}
|
|
58 |
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
// Destructor.
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CHspsConfigurationService::~CHspsConfigurationService()
|
|
64 |
{
|
|
65 |
iProperty.Close();
|
|
66 |
iPluginIds.Close();
|
|
67 |
if(iHspsRequestClient)
|
|
68 |
{
|
|
69 |
iHspsRequestClient->hspsCancelGetODTUpdate();
|
|
70 |
}
|
|
71 |
|
|
72 |
if( iCallback )
|
|
73 |
{
|
|
74 |
delete iCallback;
|
|
75 |
iCallback = NULL;
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
delete iHspsRequestClient;
|
|
80 |
delete iHspsODT;
|
|
81 |
delete iNotifyParams;
|
|
82 |
}
|
|
83 |
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
// Constructor.
|
|
86 |
// ---------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CHspsConfigurationService::CHspsConfigurationService() :
|
|
89 |
iODTVersion( 0 )
|
|
90 |
{
|
|
91 |
}
|
|
92 |
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
// Two-phased constructor.
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
void CHspsConfigurationService::ConstructL()
|
|
98 |
{
|
|
99 |
iHspsODT = ChspsODT::NewL();
|
|
100 |
iHspsRequestClient = ChspsRequestClient::NewL( *this );
|
|
101 |
iNotifyParams = ChspsRequestNotificationParams::NewL();
|
|
102 |
iPluginIds.Reset();
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
// Gets requested configuration.
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
EXPORT_C ChspsDomDocument& CHspsConfigurationService::GetDOML()
|
|
109 |
{
|
|
110 |
if( !iHspsODT ||
|
|
111 |
!iHspsODT->DomDocument().RootNode() )
|
|
112 |
{
|
|
113 |
//Odt is not parsed, leave.
|
|
114 |
User::Leave( KErrNotFound );
|
|
115 |
}
|
|
116 |
|
|
117 |
if( iODTVersion < 1 )
|
|
118 |
{
|
|
119 |
GetODTL( iHspsODT->RootUid() );
|
|
120 |
}
|
|
121 |
|
|
122 |
// Get app uid/key
|
|
123 |
TInt key = 0;
|
|
124 |
GetAppUidL( key );
|
|
125 |
if( key < 1 )
|
|
126 |
{
|
|
127 |
User::Leave( KErrNotFound );
|
|
128 |
}
|
|
129 |
|
|
130 |
if( iODTVersion < 1 )
|
|
131 |
{
|
|
132 |
User::LeaveIfError(
|
|
133 |
iProperty.Attach(
|
|
134 |
KPropertyHspsCat,
|
|
135 |
key )
|
|
136 |
);
|
|
137 |
User::LeaveIfError(
|
|
138 |
iProperty.Get(
|
|
139 |
KPropertyHspsCat,
|
|
140 |
key,
|
|
141 |
iODTVersion )
|
|
142 |
);
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
// Check whether the ODT needs to be updated
|
|
147 |
TInt latestVersion( -1 );
|
|
148 |
User::LeaveIfError(
|
|
149 |
iProperty.Get(
|
|
150 |
KPropertyHspsCat,
|
|
151 |
key,
|
|
152 |
latestVersion )
|
|
153 |
);
|
|
154 |
if( latestVersion != iODTVersion )
|
|
155 |
{
|
|
156 |
GetODTL( iHspsODT->RootUid() );
|
|
157 |
iODTVersion = latestVersion;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
return iHspsODT->DomDocument();
|
|
162 |
}
|
|
163 |
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
// Gets application configuration ODT
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
EXPORT_C void CHspsConfigurationService::GetODTL( const TInt aAppUid )
|
|
168 |
{
|
|
169 |
#ifdef HSPS_LOG_ACTIVE
|
|
170 |
if( iLogBus )
|
|
171 |
{
|
|
172 |
iLogBus->LogText( _L( "CHspsConfigurationService::GetODTL" ) );
|
|
173 |
}
|
|
174 |
#endif
|
|
175 |
|
|
176 |
// Fetch application configuration
|
|
177 |
ThspsServiceCompletedMessage retOdt = iHspsRequestClient->hspsGetODT(
|
|
178 |
aAppUid,
|
|
179 |
*iHspsODT );
|
|
180 |
if ( retOdt != EhspsGetODTSuccess )
|
|
181 |
{
|
|
182 |
#ifdef HSPS_LOG_ACTIVE
|
|
183 |
if( iLogBus )
|
|
184 |
{
|
|
185 |
iLogBus->LogText( _L( "CHspsConfigurationService::GetActiveConfigurationL(): - Failed to find a configuration" ) );
|
|
186 |
}
|
|
187 |
#endif
|
|
188 |
|
|
189 |
User::Leave( KErrNotFound );
|
|
190 |
}
|
|
191 |
else
|
|
192 |
{
|
|
193 |
// ODT is now valid.
|
|
194 |
|
|
195 |
/*
|
|
196 |
// Start observing ODT changes
|
|
197 |
if ( EhspsServiceRequestSheduled != iHspsRequestClient->hspsGetODTUpdate() )
|
|
198 |
{
|
|
199 |
#ifdef HSPS_LOG_ACTIVE
|
|
200 |
if( iLogBus )
|
|
201 |
{
|
|
202 |
iLogBus->LogText( _L( "CHspsConfigurationService::GetActiveConfigurationL(): - Failed to start observing" ) );
|
|
203 |
}
|
|
204 |
#endif
|
|
205 |
|
|
206 |
User::Leave( KErrGeneral );
|
|
207 |
}
|
|
208 |
*/
|
|
209 |
}
|
|
210 |
|
|
211 |
#ifdef HSPS_LOG_ACTIVE
|
|
212 |
if( iHspsODT && iLogBus )
|
|
213 |
{
|
|
214 |
ChspsOdtDump::Dump( *iHspsODT, *iLogBus );
|
|
215 |
}
|
|
216 |
#endif
|
|
217 |
}
|
|
218 |
|
|
219 |
// -----------------------------------------------------------------------------
|
|
220 |
// Gets application UID of active configuration
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
EXPORT_C void CHspsConfigurationService::GetAppUidL(
|
|
223 |
TInt& aAppUid )
|
|
224 |
{
|
|
225 |
if( !iHspsODT ||
|
|
226 |
!iHspsODT->DomDocument().RootNode() )
|
|
227 |
{
|
|
228 |
//Odt is not parsed, leave.
|
|
229 |
User::Leave( KErrNotFound );
|
|
230 |
}
|
|
231 |
aAppUid = iHspsODT->RootUid();
|
|
232 |
}
|
|
233 |
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
// Set log bus.
|
|
236 |
// -----------------------------------------------------------------------------
|
|
237 |
#ifdef HSPS_LOG_ACTIVE
|
|
238 |
EXPORT_C void CHspsConfigurationService::SetLogBus( ChspsLogBus* aLogBus )
|
|
239 |
{
|
|
240 |
iLogBus = aLogBus;
|
|
241 |
}
|
|
242 |
#else
|
|
243 |
EXPORT_C void CHspsConfigurationService::SetLogBus( ChspsLogBus* /*aLogBus*/ )
|
|
244 |
{
|
|
245 |
}
|
|
246 |
#endif
|
|
247 |
|
|
248 |
// -----------------------------------------------------------------------------
|
|
249 |
// See header for comments.
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
EXPORT_C void CHspsConfigurationService::InvalidateODT()
|
|
252 |
{
|
|
253 |
iODTVersion = 0;
|
|
254 |
}
|
|
255 |
|
|
256 |
// -----------------------------------------------------------------------------
|
|
257 |
// Gets application configuration family
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
EXPORT_C void CHspsConfigurationService::GetFamilyL(
|
|
260 |
TUint32& aFamily )
|
|
261 |
{
|
|
262 |
if( !iHspsODT ||
|
|
263 |
!iHspsODT->DomDocument().RootNode() )
|
|
264 |
{
|
|
265 |
//Odt is not parsed, leave.
|
|
266 |
User::Leave( KErrNotFound );
|
|
267 |
}
|
|
268 |
aFamily = iHspsODT->Family();
|
|
269 |
}
|
|
270 |
|
|
271 |
// -----------------------------------------------------------------------------
|
|
272 |
// Gets application UID of active configuration
|
|
273 |
// -----------------------------------------------------------------------------
|
|
274 |
EXPORT_C TInt CHspsConfigurationService::RegisterObserverL(CHspsReqNotifCallback* aCallBack )
|
|
275 |
{
|
|
276 |
|
|
277 |
if( !aCallBack )
|
|
278 |
{
|
|
279 |
return KErrArgument;
|
|
280 |
}
|
|
281 |
if ( !iHspsRequestClient )
|
|
282 |
{
|
|
283 |
// Not suppose tp happen since iHspsRequestClient is created during service attach
|
|
284 |
return KErrGeneral;
|
|
285 |
}
|
|
286 |
|
|
287 |
if( iCallback )
|
|
288 |
{
|
|
289 |
return KErrInUse;
|
|
290 |
}
|
|
291 |
|
|
292 |
iHspsRequestClient->hspsCancelGetODTUpdate();
|
|
293 |
if( !iCallback )
|
|
294 |
{
|
|
295 |
iCallback = aCallBack;
|
|
296 |
}
|
|
297 |
|
|
298 |
// Start observing ODT changes
|
|
299 |
|
|
300 |
if ( EhspsServiceRequestSheduled != iHspsRequestClient->hspsGetODTUpdate() )
|
|
301 |
{
|
|
302 |
#ifdef HSPS_LOG_ACTIVE
|
|
303 |
if( iLogBus )
|
|
304 |
{
|
|
305 |
iLogBus->LogText( _L( "CHspsConfigurationService::GetActiveConfigurationL(): - Failed to start observing" ) );
|
|
306 |
}
|
|
307 |
#endif
|
|
308 |
|
|
309 |
return KErrGeneral;
|
|
310 |
}
|
|
311 |
return KErrNone;
|
|
312 |
}
|
|
313 |
// -----------------------------------------------------------------------------
|
|
314 |
// Gets application UID of active configuration
|
|
315 |
// -----------------------------------------------------------------------------
|
|
316 |
EXPORT_C void CHspsConfigurationService::UnRegisterObserverL()
|
|
317 |
{
|
|
318 |
|
|
319 |
if ( !iHspsRequestClient )
|
|
320 |
{
|
|
321 |
// Not suppose tp happen since iHspsRequestClient is created during service attach
|
|
322 |
User::Leave( KErrGeneral );
|
|
323 |
}
|
|
324 |
iHspsRequestClient->hspsCancelGetODTUpdate();
|
|
325 |
|
|
326 |
if(iCallback)
|
|
327 |
{
|
|
328 |
delete iCallback;
|
|
329 |
iCallback = NULL;
|
|
330 |
}
|
|
331 |
}
|
|
332 |
// ---------------------------------------------------------------------------
|
|
333 |
// Hsps client request service observer
|
|
334 |
// ---------------------------------------------------------------------------
|
|
335 |
//
|
|
336 |
void CHspsConfigurationService::HandlehspsRequestClientMessageL( ThspsServiceCompletedMessage aMessage,
|
|
337 |
ChspsRequestNotificationParams& aParams )
|
|
338 |
{
|
|
339 |
if( aMessage == EhspsGetODTUpdateStatus || aMessage == EhspsGetODTUpdateHot )
|
|
340 |
{
|
|
341 |
if(iCallback)
|
|
342 |
{
|
|
343 |
if( !ParseNotificationDataL(aParams) )
|
|
344 |
{
|
|
345 |
// Invalidate member ODT for specific events.
|
|
346 |
if( iNotifyParams->iEvent != EhspsCacheUpdate &&
|
|
347 |
iNotifyParams->iEvent != EhspsClean &&
|
|
348 |
iNotifyParams->iEvent != EhspsNoEvent )
|
|
349 |
{
|
|
350 |
InvalidateODT();
|
|
351 |
}
|
|
352 |
|
|
353 |
// Notify.
|
|
354 |
iCallback->NotifyResultL( KErrNone, *iNotifyParams, iPluginIds );
|
|
355 |
|
|
356 |
// Reset.
|
|
357 |
iPluginIds.Reset();
|
|
358 |
iNotifyParams->ResetData();
|
|
359 |
|
|
360 |
}
|
|
361 |
}
|
|
362 |
}
|
|
363 |
if(aMessage == EhspsServiceRequestError)
|
|
364 |
{
|
|
365 |
// Invalidate ODT.
|
|
366 |
InvalidateODT();
|
|
367 |
|
|
368 |
if(iCallback)
|
|
369 |
{
|
|
370 |
iCallback->NotifyResultL( KErrGeneral, *iNotifyParams, iPluginIds);
|
|
371 |
iPluginIds.Reset();
|
|
372 |
iNotifyParams->ResetData();
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
iHspsRequestClient->hspsCancelGetODTUpdate();
|
|
377 |
if( EhspsServiceRequestSheduled != iHspsRequestClient->hspsGetODTUpdate() )
|
|
378 |
{
|
|
379 |
User::Leave( KErrGeneral );
|
|
380 |
}
|
|
381 |
|
|
382 |
}
|
|
383 |
|
|
384 |
// ---------------------------------------------------------------------------
|
|
385 |
// Sends events to observers
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
TInt CHspsConfigurationService::ParseNotificationDataL( ChspsRequestNotificationParams& aParams )
|
|
389 |
{
|
|
390 |
TInt err = KErrNone;
|
|
391 |
|
|
392 |
// Get client's appuid
|
|
393 |
const TInt appUid = iHspsODT->RootUid();
|
|
394 |
|
|
395 |
// If this is a broadcast to all clients
|
|
396 |
if( aParams.iAppUid == 0 )
|
|
397 |
{
|
|
398 |
// Send widget was installed, uninstalled or updated notifications only
|
|
399 |
if ( aParams.iEvent != EhspsODTAdded
|
|
400 |
&& aParams.iEvent != EhspsClean
|
|
401 |
&& aParams.iEvent != EhspsODTUpdated )
|
|
402 |
{
|
|
403 |
// Block other notifications
|
|
404 |
err = KErrGeneral;
|
|
405 |
}
|
|
406 |
}
|
|
407 |
else if ( appUid != aParams.iAppUid )
|
|
408 |
{
|
|
409 |
// Block notifications which were sent to other clients
|
|
410 |
err = KErrGeneral;
|
|
411 |
}
|
|
412 |
|
|
413 |
if( !err )
|
|
414 |
{
|
|
415 |
iPluginIds.Reset();
|
|
416 |
iNotifyParams->iEvent = aParams.iEvent;
|
|
417 |
iNotifyParams->iAppUid = aParams.iAppUid;
|
|
418 |
iNotifyParams->iOrigUid = aParams.iOrigUid;
|
|
419 |
iNotifyParams->iAppConfUid = aParams.iAppConfUid;
|
|
420 |
iNotifyParams->iPluginUid = aParams.iPluginUid;
|
|
421 |
iNotifyParams->iCount = aParams.iCount;
|
|
422 |
|
|
423 |
for(TInt i=0; i < iNotifyParams->iCount; i++ )
|
|
424 |
{
|
|
425 |
iPluginIds.Append( aParams.iPluginIds[i] );
|
|
426 |
}
|
|
427 |
|
|
428 |
iNotifyParams->SetNameL(aParams.Name());
|
|
429 |
}
|
|
430 |
|
|
431 |
return err;
|
|
432 |
}
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
|