|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "wrtharvesterpublisherobserver.h" |
|
22 #include "wrtharvester.h" |
|
23 |
|
24 #include "wrtharvesterconst.h" |
|
25 |
|
26 #include <LiwServiceHandler.h> |
|
27 #include <LiwVariant.h> |
|
28 #include <LiwGenericParam.h> |
|
29 |
|
30 _LIT8( KCPContentInterface, "IContentPublishing" ); |
|
31 _LIT8( KCPService, "Service.ContentPublishing" ); |
|
32 |
|
33 // ============================================================================= |
|
34 // -------------------------------------------------------------------------- |
|
35 // Cleanup utility for RPointerArray |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 static void DoCleanup( TAny* aPtr ) |
|
39 { |
|
40 __ASSERT_DEBUG( aPtr, User::Invariant() ); |
|
41 static_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy(); |
|
42 } |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS ============================== |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // Constructor |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 CWrtHarvesterPublisherObserver::CWrtHarvesterPublisherObserver( CWrtHarvester* aHarvester ) |
|
51 : iHarvester( aHarvester ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // Two-phased constructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CWrtHarvesterPublisherObserver* CWrtHarvesterPublisherObserver::NewLC( |
|
60 const TDesC& aName, CWrtHarvester* aHarvester ) |
|
61 { |
|
62 CWrtHarvesterPublisherObserver* self( |
|
63 new( ELeave ) CWrtHarvesterPublisherObserver( aHarvester ) ); |
|
64 |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL( aName ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Destructor |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CWrtHarvesterPublisherObserver::~CWrtHarvesterPublisherObserver() |
|
75 { |
|
76 ReleaseLiw(); |
|
77 delete iName; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 void CWrtHarvesterPublisherObserver::ConstructL( const TDesC& aName ) |
|
85 { |
|
86 iName = aName.AllocL(); |
|
87 InitLiwL(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CWrtHarvesterPublisherObserver::HandleNotifyL |
|
92 // |
|
93 // Handles Published content notification |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 TInt CWrtHarvesterPublisherObserver::HandleNotifyL( |
|
97 TInt /*aErrorCode */, |
|
98 TInt /*aEventId*/, |
|
99 CLiwGenericParamList& aEventParamList, |
|
100 const CLiwGenericParamList& /*aInParamList*/ ) |
|
101 { |
|
102 TInt pos(0); |
|
103 |
|
104 aEventParamList.FindFirst(pos, KChangeInfo); |
|
105 if (pos != KErrNotFound) |
|
106 { |
|
107 // Get list of maps |
|
108 TLiwVariant variant = (aEventParamList)[pos].Value(); |
|
109 variant.PushL(); |
|
110 const CLiwList* changeMapsList = variant.AsList(); |
|
111 |
|
112 TPtrC publisher; |
|
113 TPtrC operation; |
|
114 TPtrC8 trigger; |
|
115 |
|
116 // Iter through list content |
|
117 for (TInt i = 0; i < changeMapsList->Count(); ++i) |
|
118 { |
|
119 if ( changeMapsList->AtL( i, variant )) |
|
120 { |
|
121 const CLiwMap* map = variant.AsMap(); |
|
122 |
|
123 // Check what triggered a notification |
|
124 variant.Reset(); |
|
125 if ( map->FindL( KOperation, variant )) |
|
126 { |
|
127 operation.Set( variant.AsDes()); |
|
128 } |
|
129 if ( operation == KExecute ) |
|
130 { |
|
131 variant.Reset(); |
|
132 if( map->FindL( KActionTrigger, variant )) |
|
133 { |
|
134 trigger.Set( variant.AsData()); |
|
135 } |
|
136 TLiwVariant pubVariant; |
|
137 if( map->FindL( KContentId, pubVariant) ) |
|
138 { |
|
139 publisher.Set( pubVariant.AsDes()); |
|
140 } |
|
141 pubVariant.PushL(); |
|
142 if( publisher.Length() && trigger.Length()) |
|
143 { |
|
144 iHarvester->HandlePublisherNotificationL( publisher, trigger ); |
|
145 } |
|
146 CleanupStack::PopAndDestroy( &pubVariant ); |
|
147 } |
|
148 } |
|
149 } |
|
150 CleanupStack::PopAndDestroy( &variant ); |
|
151 } |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CWrtHarvesterPublisherObserver::RegisterL |
|
157 // |
|
158 // Register for notifications |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CWrtHarvesterPublisherObserver::RegisterL( CLiwDefaultMap* aFilter ) |
|
162 { |
|
163 CLiwGenericParamList* inParamList( CLiwGenericParamList::NewLC() ); |
|
164 CLiwGenericParamList* outParamList( CLiwGenericParamList::NewLC() ); |
|
165 |
|
166 // Fill in input list for RequestNotification command |
|
167 inParamList->AppendL(TLiwGenericParam(KType,TLiwVariant( KPubData ))); |
|
168 inParamList->AppendL(TLiwGenericParam(KFilter ,TLiwVariant( aFilter ))); |
|
169 |
|
170 iInterface->ExecuteCmdL( KRequestNotification, *inParamList, |
|
171 *outParamList, 0, this ); |
|
172 |
|
173 CleanupStack::PopAndDestroy( outParamList ); |
|
174 CleanupStack::PopAndDestroy( inParamList ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CWrtHarvesterPublisherObserver::Name |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 const TDesC& CWrtHarvesterPublisherObserver::Name() |
|
182 { |
|
183 return *iName; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CWrtHarvesterPublisherObserver::ReleaseL |
|
188 // |
|
189 // Sing off to notification |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CWrtHarvesterPublisherObserver::ReleaseL() |
|
193 { |
|
194 if( iInterface ) |
|
195 { |
|
196 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
197 CleanupStack::PushL( inParamList ); |
|
198 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL(); |
|
199 CleanupStack::PushL( outParamList ); |
|
200 |
|
201 iInterface->ExecuteCmdL( KRequestNotification, *inParamList, *outParamList, |
|
202 KLiwOptCancel, this ); |
|
203 |
|
204 CleanupStack::PopAndDestroy( outParamList ); |
|
205 CleanupStack::PopAndDestroy( inParamList ); |
|
206 } |
|
207 } |
|
208 |
|
209 |
|
210 // ------------------------------------------------------------------------ |
|
211 // CWrtHarvesterPublisherObserver::InitLiwL |
|
212 // |
|
213 // Init LIW interface. |
|
214 // ------------------------------------------------------------------------ |
|
215 void CWrtHarvesterPublisherObserver::InitLiwL() |
|
216 { |
|
217 if ( !iLiwHandler ) |
|
218 { |
|
219 TInt error( KErrNone ); |
|
220 CLiwGenericParamList* in( NULL ); |
|
221 CLiwGenericParamList* out( NULL ); |
|
222 CLiwCriteriaItem* criterion( NULL ); |
|
223 |
|
224 RCriteriaArray array( 1 ); |
|
225 TCleanupItem cleanup( DoCleanup, &array ); |
|
226 CleanupStack::PushL( cleanup ); |
|
227 |
|
228 // Do the basic initialization. |
|
229 iLiwHandler = CLiwServiceHandler::NewL(); |
|
230 |
|
231 // Get iCPSIface. |
|
232 in = CLiwGenericParamList::NewLC(); |
|
233 out = CLiwGenericParamList::NewLC(); |
|
234 |
|
235 criterion = CLiwCriteriaItem::NewL( |
|
236 KLiwCmdAsStr, |
|
237 KCPContentInterface, |
|
238 KCPService ); |
|
239 |
|
240 error = array.Append( criterion ); |
|
241 if ( error ) |
|
242 { |
|
243 delete criterion; |
|
244 criterion = NULL; |
|
245 User::Leave( error ); |
|
246 } |
|
247 |
|
248 criterion->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
249 |
|
250 iLiwHandler->AttachL( array ); |
|
251 iLiwHandler->ExecuteServiceCmdL( *criterion, *in, *out ); |
|
252 |
|
253 out->FindFirst( error, KCPContentInterface ); |
|
254 User::LeaveIfError( error ); |
|
255 |
|
256 iInterface = (*out)[ error ].Value().AsInterface(); |
|
257 |
|
258 CleanupStack::PopAndDestroy( 3 ); |
|
259 } |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CWrtHarvesterPublisherObserver::ReleaseLiw |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CWrtHarvesterPublisherObserver::ReleaseLiw() |
|
267 { |
|
268 if ( iInterface ) |
|
269 { |
|
270 iInterface->Close(); |
|
271 iInterface = NULL; |
|
272 } |
|
273 |
|
274 delete iLiwHandler; |
|
275 iLiwHandler = NULL; |
|
276 } |
|
277 |
|
278 // End of File |
|
279 |