34
|
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: Content Publishing Service interface.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "contentpublisher.h"
|
|
19 |
|
|
20 |
#include <liwservicehandler.h>
|
|
21 |
#include <liwvariant.h>
|
|
22 |
#include <liwgenericparam.h>
|
|
23 |
#include "xmluicontroller.h"
|
|
24 |
#include "appui.h"
|
|
25 |
#include "onlineofflinehelper.h"
|
|
26 |
|
|
27 |
using namespace AiXmlUiController;
|
|
28 |
|
|
29 |
_LIT8( KCPService, "Service.ContentPublishing" );
|
|
30 |
_LIT8( KCPInterface, "IDataSource" );
|
|
31 |
|
|
32 |
_LIT8( KType, "type" );
|
|
33 |
_LIT( KCpData, "cp_data" );
|
|
34 |
|
|
35 |
_LIT8( KPublisherId, "publisher" );
|
|
36 |
_LIT8( KContentTypeId, "content_type" );
|
|
37 |
_LIT8( KContentId, "content_id" );
|
|
38 |
_LIT8( KResults, "results" );
|
|
39 |
|
|
40 |
_LIT(KAI3HSPublisher,"ai3homescreen");
|
|
41 |
_LIT(KContentType,"wideimage");
|
|
42 |
|
|
43 |
_LIT8( KAPStatus, "apstatus");
|
|
44 |
_LIT(KNetwork, "network");
|
|
45 |
|
|
46 |
_LIT(KPublisher16, "publisher");
|
|
47 |
|
|
48 |
|
|
49 |
_LIT8( KRequestNotification, "RequestNotification" );
|
|
50 |
_LIT8( KDataMap, "data_map" );
|
|
51 |
|
|
52 |
_LIT8( KItem, "item" );
|
|
53 |
_LIT8( KAdd, "Add" );
|
|
54 |
_LIT8( KGetList, "GetList" );
|
|
55 |
_LIT8( KFilter, "filter" );
|
|
56 |
_LIT8( KWidth, "width");
|
|
57 |
_LIT8( KHeight, "height");
|
|
58 |
_LIT8( KChangeInfo, "change_info" );
|
|
59 |
|
|
60 |
// ============================ LOCAL FUNCTIONS ===============================
|
|
61 |
|
|
62 |
|
|
63 |
static void DoResetAndDestroy( TAny* aPtr )
|
|
64 |
{
|
|
65 |
__ASSERT_DEBUG( aPtr, User::Invariant() );
|
|
66 |
reinterpret_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy();
|
|
67 |
}
|
|
68 |
|
|
69 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
70 |
|
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
// Two-phased constructor. Can leave.
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CContentPublisher* CContentPublisher::NewL(CXmlUiController& aUiController)
|
|
77 |
{
|
|
78 |
CContentPublisher* self = new (ELeave) CContentPublisher(aUiController);
|
|
79 |
CleanupStack::PushL( self );
|
|
80 |
self->ConstructL();
|
|
81 |
CleanupStack::Pop();
|
|
82 |
return self;
|
|
83 |
}
|
|
84 |
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
// Destructor
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
CContentPublisher::~CContentPublisher()
|
|
90 |
{
|
|
91 |
TRAP_IGNORE(UnRegisterListenerL());
|
|
92 |
if( iCpsInterface )
|
|
93 |
{
|
|
94 |
iCpsInterface->Close();
|
|
95 |
iCpsInterface = NULL;
|
|
96 |
}
|
|
97 |
if( iServiceHandler )
|
|
98 |
{
|
|
99 |
iServiceHandler->Reset();
|
|
100 |
delete iServiceHandler;
|
|
101 |
iServiceHandler = NULL;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
// C++ default constructor. Must not leave.
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
CContentPublisher::CContentPublisher(CXmlUiController& aUiController): iUiController( aUiController )
|
|
110 |
{
|
|
111 |
}
|
|
112 |
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
// 2nd phase constructor. Can leave.
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
void CContentPublisher::ConstructL()
|
|
118 |
{
|
|
119 |
InitCpsInterfaceL();
|
|
120 |
RegisterListenerL();
|
|
121 |
}
|
|
122 |
|
|
123 |
// -----------------------------------------------------------------------------
|
|
124 |
// Publishes a given width and height to Content Publishing Service
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
void CContentPublisher::PublishSizeL( const TDesC& aElementName,
|
|
128 |
TInt aWidth, TInt aHeight )
|
|
129 |
{
|
|
130 |
AddDataL( KAI3HSPublisher() ,KContentType(), aElementName,
|
|
131 |
aWidth, KWidth, aHeight, KHeight );
|
|
132 |
}
|
|
133 |
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
// Uses the CPS interface to add given data
|
|
136 |
// -----------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
void CContentPublisher::AddDataL(
|
|
139 |
const TDesC& aPublisherId, const TDesC& aContentType, const TDesC& aContentId,
|
|
140 |
const TInt aData1, const TDesC8& aDataKey1,
|
|
141 |
const TInt aData2, const TDesC8& aDataKey2 )
|
|
142 |
{
|
|
143 |
CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
|
|
144 |
CLiwGenericParamList& outparam = iServiceHandler->OutParamListL();
|
|
145 |
|
|
146 |
TLiwGenericParam cptype( KType, TLiwVariant( KCpData ));
|
|
147 |
cptype.PushL();
|
|
148 |
|
|
149 |
inparam.AppendL( cptype );
|
|
150 |
|
|
151 |
CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
|
|
152 |
CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
|
|
153 |
|
|
154 |
// Add data to data map
|
|
155 |
map->InsertL( aDataKey1, TLiwVariant( aData1 ));
|
|
156 |
map->InsertL( aDataKey2, TLiwVariant( aData2 ));
|
|
157 |
|
|
158 |
// Create content data map
|
|
159 |
cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
|
|
160 |
cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType ));
|
|
161 |
cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
|
|
162 |
cpdatamap->InsertL( KDataMap, TLiwVariant(map) );
|
|
163 |
|
|
164 |
TLiwGenericParam item( KItem, TLiwVariant( cpdatamap ));
|
|
165 |
item.PushL();
|
|
166 |
|
|
167 |
inparam.AppendL( item );
|
|
168 |
|
|
169 |
iCpsInterface->ExecuteCmdL( KAdd , inparam, outparam);
|
|
170 |
|
|
171 |
CleanupStack::PopAndDestroy( &item );
|
|
172 |
CleanupStack::PopAndDestroy( map );
|
|
173 |
CleanupStack::PopAndDestroy( cpdatamap );
|
|
174 |
CleanupStack::PopAndDestroy( &cptype );
|
|
175 |
|
|
176 |
outparam.Reset();
|
|
177 |
inparam.Reset();
|
|
178 |
}
|
|
179 |
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
// Uses the CPS interface to get data
|
|
182 |
// -----------------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
void CContentPublisher::GetDataL(
|
|
185 |
const TDesC& aPublisherId, const TDesC& aContentType, const TDesC& aContentId,
|
|
186 |
CLiwDefaultMap* aOutDataMap)
|
|
187 |
{
|
|
188 |
CLiwGenericParamList& inParamList = iServiceHandler->InParamListL();
|
|
189 |
CLiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
|
|
190 |
|
|
191 |
TLiwGenericParam type( KType, TLiwVariant( KCpData ) );
|
|
192 |
inParamList.AppendL( type );
|
|
193 |
|
|
194 |
CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC();
|
|
195 |
|
|
196 |
// Create content data map
|
|
197 |
cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId ));
|
|
198 |
cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType ));
|
|
199 |
cpdatamap->InsertL( KContentId, TLiwVariant( aContentId ));
|
|
200 |
|
|
201 |
//append filter to input param
|
|
202 |
TLiwGenericParam item( KFilter, TLiwVariant( cpdatamap ));
|
|
203 |
inParamList.AppendL( item );
|
|
204 |
CleanupStack::PopAndDestroy( cpdatamap );
|
|
205 |
|
|
206 |
iCpsInterface->ExecuteCmdL( KGetList, inParamList, outParamList);
|
|
207 |
|
|
208 |
type.Reset();
|
|
209 |
item.Reset();
|
|
210 |
inParamList.Reset();
|
|
211 |
|
|
212 |
//extracts data map
|
|
213 |
TInt pos = 0;
|
|
214 |
outParamList.FindFirst( pos, KResults );
|
|
215 |
if( pos != KErrNotFound )
|
|
216 |
// results present
|
|
217 |
{
|
|
218 |
//extract iterator on results list
|
|
219 |
TLiwVariant variant = (outParamList)[pos].Value();
|
|
220 |
variant.PushL();
|
|
221 |
CLiwIterable* iterable = variant.AsIterable();
|
|
222 |
iterable->Reset();
|
|
223 |
//get next result
|
|
224 |
if( iterable->NextL( variant ) )
|
|
225 |
{
|
|
226 |
//extract content map
|
|
227 |
CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
|
|
228 |
variant.Get( *map );
|
|
229 |
if( map->FindL( KDataMap, variant) )
|
|
230 |
{
|
|
231 |
variant.Get( *aOutDataMap );
|
|
232 |
}
|
|
233 |
CleanupStack::PopAndDestroy( map );
|
|
234 |
}
|
|
235 |
iterable->Reset();
|
|
236 |
CleanupStack::PopAndDestroy( &variant );
|
|
237 |
variant.Reset();
|
|
238 |
}
|
|
239 |
outParamList.Reset();
|
|
240 |
|
|
241 |
}
|
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
// Gets the CPS messaging interface
|
|
245 |
// -----------------------------------------------------------------------------
|
|
246 |
//
|
|
247 |
void CContentPublisher::InitCpsInterfaceL()
|
|
248 |
{
|
|
249 |
if( !iServiceHandler )
|
|
250 |
{
|
|
251 |
iServiceHandler = CLiwServiceHandler::NewL();
|
|
252 |
}
|
|
253 |
|
|
254 |
CLiwGenericParamList& inParam = iServiceHandler->InParamListL();
|
|
255 |
CLiwGenericParamList& outParam = iServiceHandler->OutParamListL();
|
|
256 |
|
|
257 |
RCriteriaArray a;
|
|
258 |
TCleanupItem item( DoResetAndDestroy, &a );
|
|
259 |
CleanupStack::PushL( item );
|
|
260 |
|
|
261 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface,
|
|
262 |
KCPService );
|
|
263 |
crit->SetServiceClass( TUid::Uid(KLiwClassBase) );
|
|
264 |
|
|
265 |
a.AppendL(crit);
|
|
266 |
|
|
267 |
CleanupStack::Pop( crit );
|
|
268 |
|
|
269 |
iServiceHandler->AttachL(a);
|
|
270 |
iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam );
|
|
271 |
|
|
272 |
CleanupStack::PopAndDestroy(); // item;
|
|
273 |
|
|
274 |
// find service interface
|
|
275 |
TInt pos = 0;
|
|
276 |
MLiwInterface* msgInterface = NULL;
|
|
277 |
outParam.FindFirst( pos, KCPInterface );
|
|
278 |
if ( pos != KErrNotFound )
|
|
279 |
{
|
|
280 |
msgInterface = (outParam)[pos].Value().AsInterface();
|
|
281 |
}
|
|
282 |
outParam.Reset();
|
|
283 |
inParam.Reset();
|
|
284 |
iCpsInterface = msgInterface;
|
|
285 |
}
|
|
286 |
|
|
287 |
void CContentPublisher::RegisterListenerL()
|
|
288 |
{
|
|
289 |
CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
|
|
290 |
CLiwGenericParamList& outparam = iServiceHandler->OutParamListL();
|
|
291 |
CLiwDefaultMap* reqFilter = CLiwDefaultMap::NewLC();
|
|
292 |
|
|
293 |
// Listen all the information(contentId) from publisher
|
|
294 |
reqFilter->InsertL( KPublisherId, TLiwVariant( KAI3HSPublisher ));
|
|
295 |
reqFilter->InsertL( KContentTypeId, TLiwVariant(KPublisher16 ));
|
|
296 |
|
|
297 |
// Type of the registry (content registry)
|
|
298 |
inparam.AppendL(TLiwGenericParam(KType, TLiwVariant(KCpData)));
|
|
299 |
// fill in input list for RequestNotification command
|
|
300 |
inparam.AppendL(TLiwGenericParam(KFilter, TLiwVariant(reqFilter)));
|
|
301 |
|
|
302 |
TRAP_IGNORE( iCpsInterface->ExecuteCmdL(
|
|
303 |
KRequestNotification,
|
|
304 |
inparam,
|
|
305 |
outparam,
|
|
306 |
0,
|
|
307 |
this ) );
|
|
308 |
|
|
309 |
outparam.Reset();
|
|
310 |
inparam.Reset();
|
|
311 |
CleanupStack::PopAndDestroy(reqFilter );
|
|
312 |
}
|
|
313 |
|
|
314 |
void CContentPublisher::UnRegisterListenerL()
|
|
315 |
{
|
|
316 |
CLiwGenericParamList& inparam = iServiceHandler->InParamListL();
|
|
317 |
CLiwGenericParamList& outparam = iServiceHandler->OutParamListL();
|
|
318 |
|
|
319 |
// Unregister the reuqest notification
|
|
320 |
TRAP_IGNORE( iCpsInterface->ExecuteCmdL(
|
|
321 |
KRequestNotification,
|
|
322 |
inparam,
|
|
323 |
outparam,
|
|
324 |
KLiwOptCancel,
|
|
325 |
this ) );
|
|
326 |
|
|
327 |
outparam.Reset();
|
|
328 |
inparam.Reset();
|
|
329 |
}
|
|
330 |
|
|
331 |
TInt CContentPublisher::HandleNotifyL(
|
|
332 |
TInt aErrorCode,
|
|
333 |
TInt /*aEventId*/,
|
|
334 |
CLiwGenericParamList& aEventParamList,
|
|
335 |
const CLiwGenericParamList& /*aInParamList*/ )
|
|
336 |
{
|
|
337 |
TInt pos( 0 );
|
|
338 |
aEventParamList.FindFirst(pos, KChangeInfo);
|
|
339 |
if (pos != KErrNotFound)
|
|
340 |
{
|
|
341 |
// Get list of maps
|
|
342 |
TLiwVariant variant = (aEventParamList)[pos].Value();
|
|
343 |
variant.PushL();
|
|
344 |
const CLiwList* changeMapsList = variant.AsList();
|
|
345 |
// Iter through list content
|
|
346 |
for (TInt i = 0; i < changeMapsList->Count() ; ++i)
|
|
347 |
{
|
|
348 |
if ( changeMapsList->AtL(i, variant) )
|
|
349 |
{
|
|
350 |
const CLiwMap* map = variant.AsMap();
|
|
351 |
if( map->FindL( KPublisherId, variant) )
|
|
352 |
{
|
|
353 |
HBufC* publisher = variant.AsDes().AllocLC();
|
|
354 |
if ( publisher && ( publisher->Des() == KAI3HSPublisher )
|
|
355 |
&& map->FindL( KContentTypeId, variant) )
|
|
356 |
{
|
|
357 |
HBufC* contentType = variant.AsDes().AllocLC();
|
|
358 |
if ( contentType && ( contentType->Des() == KPublisher16 )
|
|
359 |
&& map->FindL( KContentId, variant ) )
|
|
360 |
{
|
|
361 |
HBufC* contentId = variant.AsDes().AllocLC();
|
|
362 |
if ( contentId )
|
|
363 |
{
|
|
364 |
HandlePublisherInfoL( *contentId );
|
|
365 |
}
|
|
366 |
CleanupStack::PopAndDestroy( contentId );
|
|
367 |
}
|
|
368 |
CleanupStack::PopAndDestroy( contentType );
|
|
369 |
}
|
|
370 |
CleanupStack::PopAndDestroy( publisher );
|
|
371 |
}
|
|
372 |
}
|
|
373 |
}
|
|
374 |
CleanupStack::PopAndDestroy(&variant);
|
|
375 |
}
|
|
376 |
return aErrorCode;
|
|
377 |
}
|
|
378 |
|
|
379 |
void CContentPublisher::HandlePublisherInfoL( const TDesC& aPubInfo)
|
|
380 |
{
|
|
381 |
//Currently HS will handle only network status update form publisher
|
|
382 |
if ( aPubInfo == KNetwork )
|
|
383 |
{
|
|
384 |
_LIT( KOffline, "hs_offline" );
|
|
385 |
CLiwDefaultMap *outDataMap = CLiwDefaultMap::NewLC();
|
|
386 |
GetDataL( KAI3HSPublisher(), KPublisher16, KNetwork(), outDataMap );
|
|
387 |
TLiwVariant variant;
|
|
388 |
variant.PushL();
|
|
389 |
if ( outDataMap->FindL(KAPStatus, variant))
|
|
390 |
{
|
|
391 |
iUiController.AppUi()->Helper()->HandleConnectionQueryL(variant.AsDes());
|
|
392 |
}
|
|
393 |
CleanupStack::PopAndDestroy( &variant );
|
|
394 |
CleanupStack::PopAndDestroy(outDataMap);
|
|
395 |
}
|
|
396 |
}
|
|
397 |
// END OF FILE
|