30
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 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: Plug-in main class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <liwservicehandler.h>
|
|
20 |
#include <liwvariant.h>
|
|
21 |
#include <liwgenericparam.h>
|
|
22 |
#include <s32mem.h>
|
|
23 |
#include "sapidata.h"
|
|
24 |
#include "sapidataobserver.h"
|
|
25 |
#include "sapidatapluginconst.h"
|
|
26 |
|
|
27 |
// Constants
|
|
28 |
_LIT8( KErrorCode, "ErrorCode" );
|
|
29 |
_LIT8( KTransactionId, "TransactionID" );
|
|
30 |
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
// Constructor
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
CSapiDataObserver::CSapiDataObserver ()
|
|
36 |
{
|
|
37 |
|
|
38 |
}
|
|
39 |
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
// Destructor
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
CSapiDataObserver ::~CSapiDataObserver ()
|
|
45 |
{
|
|
46 |
TRAP_IGNORE( ReleaseL() );
|
|
47 |
iInterface = NULL;
|
|
48 |
iData = NULL;
|
|
49 |
}
|
|
50 |
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
// Register for notifications
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
void CSapiDataObserver::RegisterL( CLiwDefaultMap* aFilter,
|
|
56 |
const TDesC& aRegistry,
|
|
57 |
TUint aOptions )
|
|
58 |
{
|
|
59 |
CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
|
|
60 |
CleanupStack::PushL( inParamList );
|
|
61 |
|
|
62 |
CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
|
|
63 |
CleanupStack::PushL( outParamList );
|
|
64 |
|
|
65 |
// Fill in input list for RequestNotification command
|
|
66 |
inParamList->AppendL(
|
|
67 |
TLiwGenericParam( KType, TLiwVariant( aRegistry ) ) );
|
|
68 |
|
|
69 |
inParamList->AppendL(
|
|
70 |
TLiwGenericParam( KFilter ,TLiwVariant( aFilter ) ) );
|
|
71 |
|
|
72 |
TRAP_IGNORE( iInterface->ExecuteCmdL(
|
|
73 |
KRequestNotification,
|
|
74 |
*inParamList,
|
|
75 |
*outParamList,
|
|
76 |
aOptions,
|
|
77 |
this ) );
|
|
78 |
|
|
79 |
TInt pos( 0 );
|
|
80 |
|
|
81 |
const TLiwGenericParam* outParam(
|
|
82 |
outParamList->FindFirst( pos, KErrorCode ) );
|
|
83 |
|
|
84 |
if ( outParam )
|
|
85 |
{
|
|
86 |
TInt retval( outParam->Value().AsTInt32() );
|
|
87 |
|
|
88 |
if( retval == KErrNone )
|
|
89 |
{
|
|
90 |
pos = 0;
|
|
91 |
outParam = outParamList->FindFirst( pos, KTransactionId );
|
|
92 |
|
|
93 |
if ( outParam )
|
|
94 |
{
|
|
95 |
iTransactionId = outParam->Value().AsTInt32();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
CleanupStack::PopAndDestroy( 2, inParamList );
|
|
101 |
}
|
|
102 |
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
// Sing off to notification
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
void CSapiDataObserver::ReleaseL()
|
|
108 |
{
|
|
109 |
if( !iInterface )
|
|
110 |
{
|
|
111 |
return;
|
|
112 |
}
|
|
113 |
|
|
114 |
CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
|
|
115 |
CleanupStack::PushL( inParamList );
|
|
116 |
|
|
117 |
CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL();
|
|
118 |
CleanupStack::PushL( outParamList );
|
|
119 |
|
|
120 |
inParamList->AppendL( TLiwGenericParam( KTransactionId,
|
|
121 |
TLiwVariant( iTransactionId ) ) );
|
|
122 |
|
|
123 |
TRAP_IGNORE( iInterface->ExecuteCmdL(
|
|
124 |
KRequestNotification,
|
|
125 |
*inParamList,
|
|
126 |
*outParamList,
|
|
127 |
KLiwOptCancel,
|
|
128 |
this ));
|
|
129 |
|
|
130 |
|
|
131 |
CleanupStack::PopAndDestroy( 2, inParamList );
|
|
132 |
}
|
|
133 |
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
// Factory method construction
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
CSapiDataObserver * CSapiDataObserver::NewL( MLiwInterface* aInterface, CSapiData* aData )
|
|
139 |
{
|
|
140 |
CSapiDataObserver * self = new (ELeave) CSapiDataObserver();
|
|
141 |
CleanupStack::PushL( self );
|
|
142 |
self->ConstructL( aInterface, aData );
|
|
143 |
CleanupStack::Pop( self );
|
|
144 |
return self;
|
|
145 |
}
|
|
146 |
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
// 2n phase constructor
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CSapiDataObserver::ConstructL( MLiwInterface* aInterface, CSapiData* aData )
|
|
152 |
{
|
|
153 |
iData = aData;
|
|
154 |
iInterface = aInterface;
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
// Handles Published content notification
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
//
|
|
161 |
TInt CSapiDataObserver::HandleNotifyL(
|
|
162 |
TInt aErrorCode,
|
|
163 |
TInt /*aEventId*/,
|
|
164 |
CLiwGenericParamList& aEventParamList,
|
|
165 |
const CLiwGenericParamList& /*aInParamList*/ )
|
|
166 |
{
|
|
167 |
|
|
168 |
// Is plugin active to refresh the published data
|
|
169 |
TInt count(0);
|
|
170 |
TInt pos(0);
|
|
171 |
const TLiwGenericParam* param(NULL);
|
|
172 |
CLiwDefaultList* listOfMaps = CLiwDefaultList::NewLC();
|
|
173 |
param = aEventParamList.FindFirst(pos,KChangeInfo);
|
|
174 |
if( param )
|
|
175 |
{
|
|
176 |
User::LeaveIfError( param->Value().Get( *listOfMaps ) );
|
|
177 |
count = listOfMaps->Count();
|
|
178 |
}
|
|
179 |
TLiwVariant variant;
|
|
180 |
// Extract the data from the map
|
|
181 |
for(TInt i = 0;i < count; i++)
|
|
182 |
{
|
|
183 |
listOfMaps->AtL(i,variant);
|
|
184 |
HBufC* operation = NULL;
|
|
185 |
|
|
186 |
CLiwDefaultMap *map = CLiwDefaultMap::NewLC();
|
|
187 |
variant.Get( *map );
|
|
188 |
TBool found;
|
|
189 |
found = map->FindL( KOperation, variant );
|
|
190 |
if (found)
|
|
191 |
{
|
|
192 |
operation = variant.AsDes().AllocLC();
|
|
193 |
}
|
|
194 |
variant.Reset();
|
|
195 |
if( operation && ( operation->Des() != KOperationExecute ) )
|
|
196 |
{
|
|
197 |
// Nothing to update for execute action
|
|
198 |
HBufC* publisher = NULL;
|
|
199 |
HBufC* contentType = NULL;
|
|
200 |
HBufC* contentId = NULL;
|
|
201 |
found = map->FindL( KPublisherId, variant );
|
|
202 |
if (found)
|
|
203 |
{
|
|
204 |
publisher = variant.AsDes().AllocLC();
|
|
205 |
}
|
|
206 |
variant.Reset();
|
|
207 |
found = map->FindL( KFLAG, variant );
|
|
208 |
if ( found)
|
|
209 |
{
|
|
210 |
// notification from publisher registry
|
|
211 |
if ( operation->Des() != KOperationDelete )
|
|
212 |
{
|
|
213 |
iData->UpdatePublisherStatusL( *publisher );
|
|
214 |
}
|
|
215 |
}
|
|
216 |
else if ( iData->IsPluginActive() )
|
|
217 |
{
|
|
218 |
// notification from content registry
|
|
219 |
found = map->FindL( KContentType, variant );
|
|
220 |
if( found )
|
|
221 |
{
|
|
222 |
contentType = variant.AsDes().AllocLC();
|
|
223 |
}
|
|
224 |
variant.Reset();
|
|
225 |
|
|
226 |
// content id
|
|
227 |
found = map->FindL( KContentId, variant );
|
|
228 |
if( found )
|
|
229 |
{
|
|
230 |
contentId = variant.AsDes().AllocLC();
|
|
231 |
}
|
|
232 |
variant.Reset();
|
|
233 |
|
|
234 |
// Data map. Optional.
|
|
235 |
CLiwDefaultMap* dataMap = NULL;
|
|
236 |
|
|
237 |
found = map->FindL( KDataMap, variant);
|
|
238 |
if( found )
|
|
239 |
{
|
|
240 |
TPtrC8 data = variant.AsData();
|
|
241 |
RDesReadStream datastrm ( data );
|
|
242 |
CleanupClosePushL( datastrm );
|
|
243 |
dataMap = CLiwDefaultMap::NewLC( datastrm );
|
|
244 |
// There is no CLiwDefaultMap::NewL( RReadStream )
|
|
245 |
// so, must do some work with cleanup stack here.
|
|
246 |
CleanupStack::Pop( dataMap );
|
|
247 |
CleanupStack::PopAndDestroy(); // datastrm
|
|
248 |
dataMap->PushL();
|
|
249 |
}
|
|
250 |
|
|
251 |
iData->RefreshL( *publisher,
|
|
252 |
*contentType,
|
|
253 |
*contentId,
|
|
254 |
*operation,
|
|
255 |
dataMap );
|
|
256 |
|
|
257 |
if( dataMap )
|
|
258 |
{
|
|
259 |
CleanupStack::PopAndDestroy( dataMap );
|
|
260 |
}
|
|
261 |
|
|
262 |
if( contentId )
|
|
263 |
{
|
|
264 |
CleanupStack::PopAndDestroy( contentId );
|
|
265 |
}
|
|
266 |
|
|
267 |
if( contentType )
|
|
268 |
{
|
|
269 |
CleanupStack::PopAndDestroy( contentType );
|
|
270 |
}
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
// remember update if plugin is in suspend mode
|
|
275 |
iData->SetUpdateNeeded( ETrue );
|
|
276 |
}
|
|
277 |
variant.Reset();
|
|
278 |
if ( publisher )
|
|
279 |
{
|
|
280 |
CleanupStack::PopAndDestroy( publisher );
|
|
281 |
}
|
|
282 |
}
|
|
283 |
if ( operation )
|
|
284 |
{
|
|
285 |
CleanupStack::PopAndDestroy( operation );
|
|
286 |
}
|
|
287 |
CleanupStack::PopAndDestroy( map );
|
|
288 |
}
|
|
289 |
CleanupStack::PopAndDestroy( listOfMaps );
|
|
290 |
|
|
291 |
return aErrorCode;
|
|
292 |
}
|
|
293 |
|