|
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: Encapsulates cps liw service |
|
15 * |
|
16 */ |
|
17 |
|
18 // System include files |
|
19 #include <LiwServiceHandler.h> |
|
20 #include <LiwVariant.h> |
|
21 #include <LiwGenericParam.h> |
|
22 #include <bamdesca.h> |
|
23 |
|
24 // User include files |
|
25 #include "publisherinfo.h" |
|
26 #include "publishermap.h" |
|
27 #include "cpswrapper.h" |
|
28 #include "cpsconst.h" |
|
29 #include "cpsobserver.h" |
|
30 |
|
31 namespace cpswrapper |
|
32 { |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // ----------------------------------------------------------------------- |
|
37 // CCpsWrapper::NewL() |
|
38 // ----------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CCpsWrapper* CCpsWrapper::NewL( MCpsWrapperObserver& aObserver ) |
|
41 { |
|
42 CCpsWrapper* self = CCpsWrapper::NewLC( aObserver ); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------- |
|
48 // CCpsWrapper::NewLC() |
|
49 // ----------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CCpsWrapper* CCpsWrapper::NewLC(MCpsWrapperObserver& aObserver) |
|
52 { |
|
53 CCpsWrapper* self = new ( ELeave ) CCpsWrapper( aObserver ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------- |
|
60 // CCpsWrapper::ConstructL() |
|
61 // ----------------------------------------------------------------------- |
|
62 // |
|
63 void CCpsWrapper::ConstructL() |
|
64 { |
|
65 iServiceHandler = CLiwServiceHandler::NewL(); |
|
66 |
|
67 RCriteriaArray interestList; |
|
68 |
|
69 // Attach to CPS: |
|
70 iCpsService = CLiwCriteriaItem::NewL( 1, KCPSConfigurationIf, KCPS ); |
|
71 iCpsService->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
72 |
|
73 interestList.AppendL( iCpsService ); |
|
74 iServiceHandler->AttachL( interestList ); |
|
75 interestList.Reset(); |
|
76 |
|
77 CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() ); |
|
78 CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() ); |
|
79 |
|
80 iServiceHandler->ExecuteServiceCmdL( |
|
81 *iCpsService, |
|
82 inParamList, |
|
83 outParamList ); |
|
84 |
|
85 TInt pos( 0 ); |
|
86 |
|
87 outParamList.FindFirst( pos, KCPSConfigurationIf ); |
|
88 |
|
89 if ( pos != KErrNotFound ) |
|
90 { |
|
91 iCpsInterface = (outParamList)[pos].Value().AsInterface(); |
|
92 inParamList.Reset(); |
|
93 outParamList.Reset(); |
|
94 } |
|
95 else |
|
96 { |
|
97 inParamList.Reset(); |
|
98 outParamList.Reset(); |
|
99 User::Leave( KErrNotFound ); |
|
100 } |
|
101 |
|
102 StartListeningPublisherRegistryL(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------- |
|
106 // CCpsWrapper::CCpsWrapper() |
|
107 // ----------------------------------------------------------------------- |
|
108 // |
|
109 CCpsWrapper::CCpsWrapper( MCpsWrapperObserver& aObserver ) |
|
110 : iObserver( aObserver ), |
|
111 iCpsInterface( NULL ) |
|
112 { |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------- |
|
116 // CCpsWrapper::~CCpsWrapper() |
|
117 // ----------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C CCpsWrapper::~CCpsWrapper() |
|
120 { |
|
121 iObservers.ResetAndDestroy(); |
|
122 if ( iCpsInterface ) |
|
123 { |
|
124 // Close interface |
|
125 iCpsInterface->Close(); |
|
126 } |
|
127 |
|
128 if ( iServiceHandler && iCpsService ) |
|
129 { |
|
130 // Detach services from the handler |
|
131 RCriteriaArray interestList; |
|
132 |
|
133 TRAP_IGNORE( interestList.AppendL( iCpsService ); |
|
134 iServiceHandler->DetachL( interestList ); ); |
|
135 |
|
136 interestList.Reset(); |
|
137 } |
|
138 |
|
139 delete iCpsService; |
|
140 delete iServiceHandler; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------- |
|
144 // CCpsWrapper::GetTemplatedPublishersL() |
|
145 // ----------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C CPublisherMap* CCpsWrapper::GetTemplatedPublishersL() |
|
148 { |
|
149 CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() ); |
|
150 CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() ); |
|
151 |
|
152 TLiwGenericParam type( KType, TLiwVariant( KPublisher16 ) ); |
|
153 inParamList.AppendL( type ); |
|
154 |
|
155 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
156 |
|
157 filter->InsertL( KContentType, TLiwVariant( KHSTemplate ) ); |
|
158 |
|
159 //append filter to input param |
|
160 TLiwGenericParam item( KFilter, TLiwVariant( filter )); |
|
161 inParamList.AppendL( item ); |
|
162 |
|
163 // Get all the publiser from CPS with publiser id ai3templatewidget |
|
164 iCpsInterface->ExecuteCmdL( KGetList, inParamList, outParamList ); |
|
165 |
|
166 inParamList.Reset(); |
|
167 |
|
168 CleanupStack::PopAndDestroy(filter); |
|
169 |
|
170 TInt pos(0); |
|
171 |
|
172 outParamList.FindFirst( pos, KResults ); |
|
173 |
|
174 CPublisherMap* publishers = CPublisherMap::NewL(); |
|
175 CleanupStack::PushL( publishers ); |
|
176 |
|
177 if ( pos != KErrNotFound ) |
|
178 { |
|
179 //extract iterator on results list |
|
180 TLiwVariant variant( outParamList[pos].Value() ); |
|
181 CLiwIterable* iterable( variant.AsIterable() ); |
|
182 iterable->Reset(); |
|
183 |
|
184 //get all the templated widget publishers |
|
185 while ( iterable->NextL( variant ) ) |
|
186 { |
|
187 //extract content map |
|
188 CLiwDefaultMap *publisherMap = CLiwDefaultMap::NewLC(); |
|
189 variant.Get( *publisherMap ); |
|
190 variant.Reset(); |
|
191 CPublisherInfo* publisherInfo = CPublisherInfo::NewLC(); |
|
192 if ( publisherMap->FindL( KPublisher, variant ) ) |
|
193 { |
|
194 publisherInfo->SetPublisherIdL( variant.AsDes() ); |
|
195 variant.Reset(); |
|
196 } |
|
197 |
|
198 if ( publisherMap->FindL( KDataMap, variant) ) |
|
199 { |
|
200 CLiwDefaultMap* dataMap = CLiwDefaultMap::NewLC(); |
|
201 variant.Get( *dataMap ); |
|
202 variant.Reset(); |
|
203 if ( dataMap->FindL( KTemplateType, variant) ) |
|
204 { |
|
205 publisherInfo->SetTemplateTypeL( variant.AsDes() ); |
|
206 variant.Reset(); |
|
207 } |
|
208 |
|
209 if ( dataMap->FindL( KWidgetName, variant ) ) |
|
210 { |
|
211 publisherInfo->SetWidgetNameL( variant.AsDes() ); |
|
212 variant.Reset(); |
|
213 } |
|
214 |
|
215 if ( dataMap->FindL( KMaxWidgets, variant ) ) |
|
216 { |
|
217 publisherInfo->SetMaxWidgets( |
|
218 variant.AsTInt32() ); |
|
219 variant.Reset(); |
|
220 } |
|
221 else |
|
222 { |
|
223 // Use default value 1 |
|
224 publisherInfo->SetMaxWidgets( 1 ); |
|
225 } |
|
226 |
|
227 if ( dataMap->FindL( KWidgetDesc, variant ) ) |
|
228 { |
|
229 publisherInfo->SetDescriptionL( variant.AsDes() ); |
|
230 variant.Reset(); |
|
231 } |
|
232 |
|
233 if ( dataMap->FindL( KWidgetIcon, variant ) ) |
|
234 { |
|
235 publisherInfo->SetLogoIconL( variant.AsDes() ); |
|
236 variant.Reset(); |
|
237 } |
|
238 |
|
239 CleanupStack::PopAndDestroy( dataMap ); |
|
240 } |
|
241 publisherInfo->SetContentTypeL( KHSTemplate() ); |
|
242 publishers->AddPublisherInfoL( publisherInfo ); |
|
243 CleanupStack::Pop( publisherInfo ); |
|
244 |
|
245 variant.Reset(); |
|
246 CleanupStack::PopAndDestroy( publisherMap ); |
|
247 } |
|
248 } |
|
249 GetWRTWidgetsL( *publishers ); |
|
250 |
|
251 CleanupStack::Pop( publishers ); |
|
252 |
|
253 outParamList.Reset(); |
|
254 |
|
255 return publishers; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------- |
|
259 // CCpsWrapper::GetWRTWidgetsL() |
|
260 // ----------------------------------------------------------------------- |
|
261 // |
|
262 void CCpsWrapper::GetWRTWidgetsL(CPublisherMap& aPublisherMap) |
|
263 { |
|
264 CLiwGenericParamList& inParamList( iServiceHandler->InParamListL() ); |
|
265 CLiwGenericParamList& outParamList( iServiceHandler->OutParamListL() ); |
|
266 |
|
267 TLiwGenericParam type( KType, TLiwVariant( KPublisher16 ) ); |
|
268 inParamList.AppendL( type ); |
|
269 |
|
270 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
271 |
|
272 filter->InsertL( KPublisher, TLiwVariant( KWRTPublisher )); |
|
273 filter->InsertL( KContentType, TLiwVariant( KWRTTemplate ) ); |
|
274 |
|
275 //append filter to input param |
|
276 TLiwGenericParam item( KFilter, TLiwVariant( filter )); |
|
277 inParamList.AppendL( item ); |
|
278 |
|
279 // Get all the publiser from CPS with publiser id ai3templatewidget |
|
280 iCpsInterface->ExecuteCmdL( KGetList, inParamList, outParamList ); |
|
281 |
|
282 inParamList.Reset(); |
|
283 |
|
284 CleanupStack::PopAndDestroy(filter); |
|
285 |
|
286 TInt pos(0); |
|
287 |
|
288 outParamList.FindFirst( pos, KResults ); |
|
289 |
|
290 if ( pos != KErrNotFound ) |
|
291 { |
|
292 //extract iterator on results list |
|
293 TLiwVariant variant( outParamList[pos].Value() ); |
|
294 CLiwIterable* iterable( variant.AsIterable() ); |
|
295 iterable->Reset(); |
|
296 |
|
297 //get all the templated widget publishers |
|
298 while ( iterable->NextL( variant ) ) |
|
299 { |
|
300 //extract content map |
|
301 CLiwDefaultMap *publisherMap = CLiwDefaultMap::NewLC(); |
|
302 variant.Get( *publisherMap ); |
|
303 variant.Reset(); |
|
304 CPublisherInfo* publisherInfo = CPublisherInfo::NewLC(); |
|
305 if ( publisherMap->FindL( KContentId, variant ) ) |
|
306 { |
|
307 publisherInfo->SetPublisherIdL( variant.AsDes() ); |
|
308 variant.Reset(); |
|
309 } |
|
310 |
|
311 if ( publisherMap->FindL( KDataMap, variant) ) |
|
312 { |
|
313 CLiwDefaultMap* dataMap = CLiwDefaultMap::NewLC(); |
|
314 variant.Get( *dataMap ); |
|
315 variant.Reset(); |
|
316 if ( dataMap->FindL( KWidgetInfo, variant ) ) |
|
317 { |
|
318 CLiwDefaultMap* widgetInfoMap = CLiwDefaultMap::NewLC(); |
|
319 variant.Get( *widgetInfoMap ); |
|
320 if ( widgetInfoMap->FindL( KTemplateType, variant) ) |
|
321 { |
|
322 publisherInfo->SetTemplateTypeL( variant.AsDes() ); |
|
323 variant.Reset(); |
|
324 } |
|
325 if ( widgetInfoMap->FindL( KWidgetName, variant ) ) |
|
326 { |
|
327 publisherInfo->SetWidgetNameL( variant.AsDes() ); |
|
328 variant.Reset(); |
|
329 } |
|
330 if ( widgetInfoMap->FindL( KWidgetDesc, variant ) ) |
|
331 { |
|
332 publisherInfo->SetDescriptionL( variant.AsDes() ); |
|
333 variant.Reset(); |
|
334 } |
|
335 if ( widgetInfoMap->FindL( KWidgetIcon, variant ) ) |
|
336 { |
|
337 publisherInfo->SetLogoIconL( variant.AsDes() ); |
|
338 variant.Reset(); |
|
339 } |
|
340 |
|
341 CleanupStack::PopAndDestroy( widgetInfoMap ); |
|
342 } |
|
343 CleanupStack::PopAndDestroy( dataMap ); |
|
344 } |
|
345 publisherInfo->SetContentTypeL( KWRTTemplate() ); |
|
346 publisherInfo->SetMaxWidgets(1); |
|
347 aPublisherMap.AddPublisherInfoL( publisherInfo ); |
|
348 CleanupStack::Pop( publisherInfo ); |
|
349 |
|
350 variant.Reset(); |
|
351 CleanupStack::PopAndDestroy( publisherMap ); |
|
352 } |
|
353 } |
|
354 outParamList.Reset(); |
|
355 |
|
356 } |
|
357 // ----------------------------------------------------------------------- |
|
358 // CCpsWrapper::RequestForNotificationL() |
|
359 // ----------------------------------------------------------------------- |
|
360 // |
|
361 void CCpsWrapper::RequestForNotificationL( |
|
362 const TDesC& aPublisher, |
|
363 const TDesC& aContentType, |
|
364 const TDesC& aContentId, |
|
365 const TDesC8& aOperation, |
|
366 const TDesC& aRegistry) |
|
367 { |
|
368 CCpsObserver* observer = CCpsObserver::NewLC( this ); |
|
369 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
370 |
|
371 filter->InsertL( KPublisher, TLiwVariant( aPublisher ) ); |
|
372 filter->InsertL( KContentType, TLiwVariant( aContentType ) ); |
|
373 filter->InsertL( KContentId, TLiwVariant( aContentId ) ); |
|
374 filter->InsertL( KOperation, TLiwVariant( aOperation )); |
|
375 |
|
376 observer->RegisterL( filter, aRegistry ); |
|
377 iObservers.AppendL( observer ); |
|
378 |
|
379 CleanupStack::PopAndDestroy(filter); |
|
380 CleanupStack::Pop( observer ); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------- |
|
384 // CCpsWrapper::StartListeningPublisherRegistryL() |
|
385 // ----------------------------------------------------------------------- |
|
386 // |
|
387 void CCpsWrapper::StartListeningPublisherRegistryL() |
|
388 { |
|
389 // Start Listening all the HS template using widgets unregistration |
|
390 RequestForNotificationL( KAll, KHSTemplate, KAll, KDelete, KPublisher16 ); |
|
391 |
|
392 // Start Listening all the WRT widgets unregistration |
|
393 RequestForNotificationL( KAll, KWRTTemplate, KAll, KDelete, KPublisher16 ); |
|
394 |
|
395 // Start Listening all the WRT widgets registrations |
|
396 RequestForNotificationL( KAll, KWRTTemplate, KAll, KAdd, KPublisher16 ); |
|
397 |
|
398 // Start Listening all the HS template widgets registrations |
|
399 RequestForNotificationL( KAll, KHSTemplate, KAll, KAdd, KPublisher16 ); |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------- |
|
403 // CCpsWrapper::HandleChangedPublisherL() |
|
404 // ----------------------------------------------------------------------- |
|
405 // |
|
406 void CCpsWrapper::HandleChangedPublisherL(const TDesC& aPublisher, |
|
407 const TDesC& aOperation) |
|
408 { |
|
409 if ( aOperation == KDelete16 ) |
|
410 { |
|
411 iObserver.NotifyWidgetUnregisteredL( aPublisher ); |
|
412 } |
|
413 else if ( aOperation == KAdd16 ) |
|
414 { |
|
415 iObserver.NotifyWidgetRegisteredL(); |
|
416 } |
|
417 } |
|
418 } |
|
419 |
|
420 // End of file |