|
1 /* |
|
2 * Copyright (c) 2006 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: IMPS Protocol implementation for Presence Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ximpprotocolconnectionhost.h> |
|
20 #include "CSubscribePresenceWatcherListRequest.h" |
|
21 #include "impsconnectionmanagercontrolif.h" |
|
22 #include "impsdebugprint.h" |
|
23 #include "CImpsPluginAccessHandler.h" |
|
24 #include "CImpsPluginPureDataHandler.h" |
|
25 |
|
26 #include "impsplugintags.h" |
|
27 #include "CPEngXMLParser.h" |
|
28 #include "MPEngXMLParser.h" |
|
29 #include "CPEngXmlSerializer.h" |
|
30 #include "MPEngXmlSerializer.h" |
|
31 #include "CImpsPluginConnectionManager.h" |
|
32 #include "PEngXMLTags.h" |
|
33 |
|
34 #include <ximpobjectfactory.h> |
|
35 #include <protocolpresencedatahost.h> |
|
36 #include <presenceobjectfactory.h> |
|
37 #include <ximpobjectcollection.h> |
|
38 #include <protocolpresentitygroupsdatahost.h> |
|
39 #include <presentitygroupinfo.h> |
|
40 #include <presentitygroupmemberinfo.h> |
|
41 #include <ximpidentity.h> |
|
42 #include <protocolpresencepublishingdatahost.h> |
|
43 #include <presencewatcherinfo.h> |
|
44 #include <ximpdatasubscriptionstate.h> |
|
45 #include "PImpsAdapXMLTools.h" |
|
46 |
|
47 |
|
48 // ======== MEMBER FUNCTIONS ======== |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CSubscribePresenceWatcherListRequest::CSubscribePresenceWatcherListRequest |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CSubscribePresenceWatcherListRequest::CSubscribePresenceWatcherListRequest( |
|
55 MImpsPrtPluginConnectionManager& aConnMan, |
|
56 TXIMPRequestId aRequestId ) : |
|
57 CActive( EPriorityNormal ), |
|
58 iRequestId( aRequestId ), |
|
59 iConnMan( aConnMan ) |
|
60 { |
|
61 IMPS_DP( D_IMPS_LIT( "::CSubscribePresenceWatcherListRequest Start" ) ); |
|
62 CActiveScheduler::Add( this ); |
|
63 |
|
64 IMPS_DP( D_IMPS_LIT( "::CSubscribePresenceWatcherListRequest End" ) ); |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CSubscribePresenceWatcherListRequest::ConstructL |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CSubscribePresenceWatcherListRequest::ConstructL() |
|
73 { |
|
74 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::ConstructL Start-End" ) ); |
|
75 |
|
76 iParser = CreateXMLParserL(); |
|
77 |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CSubscribePresenceWatcherListRequest::NewL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CSubscribePresenceWatcherListRequest* CSubscribePresenceWatcherListRequest::NewL( |
|
86 MImpsPrtPluginConnectionManager& aConnMan, |
|
87 TXIMPRequestId aRequestId ) |
|
88 { |
|
89 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::NewL Start" ) ); |
|
90 |
|
91 CSubscribePresenceWatcherListRequest* self = new( ELeave ) |
|
92 CSubscribePresenceWatcherListRequest( aConnMan, aRequestId ); |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL(); |
|
95 CleanupStack::Pop( self ); |
|
96 |
|
97 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::NewL End" ) ); |
|
98 return self; |
|
99 } |
|
100 |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CSubscribePresenceWatcherListRequest::NewLC |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CSubscribePresenceWatcherListRequest* CSubscribePresenceWatcherListRequest::NewLC( |
|
107 MImpsPrtPluginConnectionManager& aConnMan, |
|
108 TXIMPRequestId aRequestId ) |
|
109 { |
|
110 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::NewLC Start" ) ); |
|
111 |
|
112 CSubscribePresenceWatcherListRequest* self = |
|
113 CSubscribePresenceWatcherListRequest::NewL( aConnMan, aRequestId ); |
|
114 CleanupStack::PushL( self ); |
|
115 |
|
116 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::NewLC End" ) ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CSubscribePresenceWatcherListRequest::~CSubscribePresenceWatcherListRequest |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 CSubscribePresenceWatcherListRequest::~CSubscribePresenceWatcherListRequest() |
|
125 { |
|
126 IMPS_DP( D_IMPS_LIT( "::~CSubscribePresenceWatcherListRequest Start" ) ); |
|
127 |
|
128 delete iResponse; |
|
129 delete iWatcherId; |
|
130 delete iWatcherStatus; |
|
131 CActive::Cancel(); |
|
132 iConnMan.Remove( this ); |
|
133 delete iParser; |
|
134 |
|
135 IMPS_DP( D_IMPS_LIT( "::~CSubscribePresenceWatcherListRequest End" ) ); |
|
136 } |
|
137 |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CSubscribePresenceWatcherListRequest::DoCancel() |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CSubscribePresenceWatcherListRequest::DoCancel() |
|
144 { |
|
145 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::DoCancel Start" ) ); |
|
146 |
|
147 iConnMan.DataHandler().CancelSending( iSendId ); |
|
148 |
|
149 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::DoCancel End" ) ); |
|
150 } |
|
151 |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CSubscribePresenceWatcherListRequest::RunL() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CSubscribePresenceWatcherListRequest::RunL() |
|
158 { |
|
159 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunL Start" ) ); |
|
160 |
|
161 User::LeaveIfError( iStatus.Int() ); |
|
162 |
|
163 iResponse = iConnMan.DataHandler().ResponseL( iSendId ); |
|
164 |
|
165 TPtrC8 resultBlock( NULL, 0 ); |
|
166 TInt wvErrorCode = KErrNone; |
|
167 |
|
168 /* parse the watcherlist content. |
|
169 in watcherlist response there is no status of 200 */ |
|
170 |
|
171 TInt countResults = 0; |
|
172 |
|
173 if ( iParser->DecodeL( *iResponse, KWatcherTag, ETrue ) ) |
|
174 { |
|
175 IMPS_DP( D_IMPS_LIT( "PresenceWatcherListRequest Server did not send the Watcher Tag:" ) ); |
|
176 countResults = iParser->Count(); |
|
177 } |
|
178 |
|
179 if ( iParser->DecodeL( *iResponse, KUserTag, EFalse ) ) |
|
180 { |
|
181 IMPS_DP( D_IMPS_LIT( " Serever did send user tag in response" ) ); |
|
182 countResults = iParser->Count(); |
|
183 } |
|
184 |
|
185 MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory(); |
|
186 MPresenceObjectFactory& prObjFact = |
|
187 iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory(); |
|
188 MXIMPObjectCollection* listOfWatchers = prfwObjFact.NewObjectCollectionLC(); |
|
189 |
|
190 IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) ); |
|
191 |
|
192 IMPS_DP( D_IMPS_LIT( "---------------------Data from presadap1.2 to PresenceFramework-----------" ) ); |
|
193 |
|
194 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunL:Total Watcher:%d " ), countResults ); |
|
195 |
|
196 for ( TInt i = 0 ; i < countResults; ++i ) |
|
197 { |
|
198 MXIMPIdentity* watcherIdentity = prfwObjFact.NewIdentityLC(); |
|
199 MPresenceWatcherInfo* watcherInfo = prObjFact.NewPresenceWatcherInfoLC(); |
|
200 |
|
201 // check user tag |
|
202 if ( iParser->DecodeL( *iResponse, KUserTag, EFalse ) ) |
|
203 { |
|
204 |
|
205 if ( iParser->DecodeL( *iResponse, KUserIDXMLTag, EFalse ) ) |
|
206 { |
|
207 iWatcherId = iParser->ResultAsUnicodeTextL( i ); |
|
208 iWatcherId->Des().Fold(); |
|
209 watcherIdentity->SetIdentityL( *iWatcherId ); |
|
210 watcherInfo->SetWatcherIdL( watcherIdentity ); |
|
211 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunL:wather id:%S " ), iWatcherId ); |
|
212 |
|
213 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunL:watherIdentity:%S " ), & watcherIdentity->Identity() ); |
|
214 |
|
215 IMPS_DP( D_IMPS_LIT( "------------------------------------------------------------------" ) ); |
|
216 |
|
217 } |
|
218 |
|
219 // check clientID tag |
|
220 if ( iParser->DecodeL( *iResponse, KClientIdTag, EFalse ) ) |
|
221 { |
|
222 // check url |
|
223 if ( iParser->DecodeL( *iResponse, KURLTag, EFalse ) ) |
|
224 { |
|
225 // where do we store in the watcher info object? |
|
226 // either parse and store this object locally in the class |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 // check watcher status |
|
232 if ( iParser->DecodeL( *iResponse, KWatcherStatusTag, EFalse ) ) |
|
233 { |
|
234 iWatcherStatus = iParser->ResultAsUnicodeTextL( i ); |
|
235 iWatcherStatus->Des().Fold(); |
|
236 |
|
237 // compare the string with current subscriber and set type |
|
238 _LIT16( KCurrentSubscriber, "CURRENT_SUBSCRIBER" ); |
|
239 |
|
240 // check if the string contains the above substring |
|
241 TInt value = iWatcherStatus->CompareF( KCurrentSubscriber ) ; |
|
242 |
|
243 if ( KErrNone == value ) |
|
244 {// current subscriber |
|
245 watcherInfo->SetWatcherTypeL( MPresenceWatcherInfo::EPresenceSubscriber ); |
|
246 } |
|
247 else |
|
248 { |
|
249 // other type of subscriber |
|
250 watcherInfo->SetWatcherTypeL( MPresenceWatcherInfo::EUnknown ); |
|
251 } |
|
252 } |
|
253 |
|
254 listOfWatchers->AddObjectL( watcherInfo ); |
|
255 delete iWatcherId; |
|
256 iWatcherId = NULL; |
|
257 delete iWatcherStatus; |
|
258 iWatcherStatus = NULL; |
|
259 |
|
260 CleanupStack::Pop( 2 ); // watcherIdentity, watcherInfo |
|
261 |
|
262 } // for loop end |
|
263 |
|
264 // issue internal request to the prfw. |
|
265 iConnMan.HandleToHost().ProtocolPresenceDataHost().PublishingDataHost().HandlePresenceWatcherListL( listOfWatchers ); |
|
266 |
|
267 MXIMPDataSubscriptionState* dataSubscriptionState = prfwObjFact.NewDataSubscriptionStateLC(); |
|
268 |
|
269 dataSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable ); |
|
270 dataSubscriptionState->SetSubscriptionStateL( MXIMPDataSubscriptionState::ESubscriptionActive ); |
|
271 |
|
272 iConnMan.HandleToHost().ProtocolPresenceDataHost().PublishingDataHost().SetPresenceWatcherListDataSubscriptionStateL( |
|
273 dataSubscriptionState, NULL ); |
|
274 CleanupStack::Pop(); // listOfWatchers |
|
275 CleanupStack::Pop(); // dataSubscriptionState |
|
276 |
|
277 |
|
278 IMPS_DP( D_IMPS_LIT( " SubscribePresenceWatcherListL wvErrorCode::%d" ), wvErrorCode ); |
|
279 |
|
280 // complete the request from prfw |
|
281 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, wvErrorCode ); |
|
282 |
|
283 delete this; |
|
284 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunL End" ) ); |
|
285 } |
|
286 |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CSubscribePresenceWatcherListRequest::RunError |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 TInt CSubscribePresenceWatcherListRequest::RunError( TInt aError ) |
|
293 { |
|
294 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunError Start" ) ); |
|
295 |
|
296 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError ); |
|
297 |
|
298 delete this; |
|
299 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::RunError End" ) ); |
|
300 return KErrNone; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CSubscribePresenceWatcherListRequest::SubscribePresenceWatcherListL |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void CSubscribePresenceWatcherListRequest::SubscribePresenceWatcherListL() |
|
308 { |
|
309 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::SubscribePresenceWatcherListL Start" ) ); |
|
310 |
|
311 TPtr8 ptrbuffer( iConnMan.DataHandler().TransferBufferL() ); |
|
312 MPEngXMLSerializer* serializer = CreateXmlSerializerLC( ptrbuffer ); |
|
313 |
|
314 |
|
315 IMPS_DP( D_IMPS_LIT( "SubscribePresenceWatcherListL Manufacture XML " ) ); |
|
316 |
|
317 NImpsAdapXMLTools::AppendTransactionContentTagXmlL( *serializer, iConnMan.GetVersion() ); |
|
318 |
|
319 serializer->StartTagL( KGetWatchers ); |
|
320 |
|
321 serializer->StartTagL( KHistoryPeriod ).NarrowTextL( KHistoryPeriodValue ).EndTagL( KHistoryPeriod ); |
|
322 serializer->StartTagL( KMaxWatcherList ).NarrowTextL( KMaxWatcherListValue ).EndTagL( KMaxWatcherList ); |
|
323 |
|
324 serializer->EndTagL( KGetWatchers ); |
|
325 serializer->EndTagL( KTransactionContent ); |
|
326 |
|
327 CleanupStack::PopAndDestroy(); //serializer |
|
328 |
|
329 iSendId = iConnMan.DataHandler().SendDataL( iStatus ); |
|
330 |
|
331 IMPS_DP( D_IMPS_LIT( " SendData Request id %d " ), iSendId ); |
|
332 // signal the scheduler |
|
333 SetActive(); |
|
334 |
|
335 IMPS_DP( D_IMPS_LIT( "CSubscribePresenceWatcherListRequest::SubscribePresenceWatcherListL End" ) ); |
|
336 } |
|
337 |
|
338 // End of file |