|
1 /* |
|
2 * Copyright (c) 2006-2010 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: IETF SIMPLE Protocol implementation for XIMP Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32svr.h> |
|
21 #include <utf.h> |
|
22 #include <s32strm.h> |
|
23 #include <ximpprotocolconnectionhost.h> |
|
24 #include <ximpidentity.h> |
|
25 #include <ximperrors.hrh> |
|
26 #include <msimpleconnection.h> |
|
27 #include <protocolpresentitygroupsdatahost.h> |
|
28 #include <protocolpresencedatahost.h> |
|
29 #include <ximpobjectcollection.h> |
|
30 #include <ximpobjectfactory.h> |
|
31 #include <presenceobjectfactory.h> |
|
32 #include <escapeutils.h> |
|
33 |
|
34 #include "presencepluginvirtualgroup.h" |
|
35 #include "mpresencepluginconnectionobs.h" |
|
36 #include "presenceplugincommon.h" |
|
37 #include "presencepluginwatcher.h" |
|
38 #include "presencepluginentitywatcher.h" |
|
39 #include "presencepluginxdmutils.h" |
|
40 #include "presenceplugindata.h" |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CPresencePluginWatcher::CPresencePluginWatcher() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CPresencePluginWatcher::CPresencePluginWatcher( |
|
49 MPresencePluginConnectionObs& aObs, |
|
50 MSimpleConnection& aConn, CPresencePluginData* aPresenceData ) |
|
51 : CActive( CActive::EPriorityStandard ), |
|
52 iConnObs(aObs), iConnection(aConn), iPresenceData( aPresenceData ), |
|
53 iXdmState( EPluginIdle ),iCompleted( ETrue ), |
|
54 iOperation( EPluginUndef ) |
|
55 { |
|
56 CActiveScheduler::Add( this ); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CPresencePluginWatcher::NewL() |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CPresencePluginWatcher* CPresencePluginWatcher::NewL( |
|
64 MPresencePluginConnectionObs& aObs, |
|
65 MSimpleConnection& aConn, |
|
66 CPresencePluginData* aPresenceData ) |
|
67 { |
|
68 DP_SDA("CPresencePluginWatcher::NewL"); |
|
69 CPresencePluginWatcher* self = |
|
70 new( ELeave ) CPresencePluginWatcher( aObs, aConn, aPresenceData ); |
|
71 CleanupStack::PushL( self ); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CPresencePluginWatcher::~CPresencePluginWatcher() |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CPresencePluginWatcher::~CPresencePluginWatcher() |
|
81 { |
|
82 iWatchers.ResetAndDestroy(); |
|
83 iWatchers.Close(); |
|
84 iWatcherCandidates.ResetAndDestroy(); |
|
85 delete iPresIdentity; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CPresencePluginWatcher::DoSubscribePresentityPresenceL() |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CPresencePluginWatcher::DoSubscribePresentityPresenceL( |
|
93 const MXIMPIdentity& aPresentityId, |
|
94 const MPresenceInfoFilter& /*aPif*/, |
|
95 TXIMPRequestId aReqId ) |
|
96 { |
|
97 DP_SDA("CPresencePluginWatcher::DoSubscribePresentityPresenceL"); |
|
98 DP_SDA2(" DoSubscribePresentityPresenceL - identity: %S", |
|
99 &aPresentityId.Identity() ); |
|
100 |
|
101 iOperation = EPluginSubscribeSingle; |
|
102 iXdmState = EPluginIdle; |
|
103 |
|
104 SetPresIdentityL( aPresentityId, ETrue ); |
|
105 |
|
106 //Saving reguestID |
|
107 iXIMPId = aReqId; |
|
108 iCompleted = EFalse; |
|
109 |
|
110 HBufC8* pres8 = NULL; |
|
111 pres8 = |
|
112 CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() ); |
|
113 CleanupStack::PushL( pres8 ); // << pres8 |
|
114 |
|
115 CPresencePluginEntityWatcher* watcher = |
|
116 MatchWatcherL( pres8->Des(), ETrue ); |
|
117 watcher->StartSubscribeL( pres8->Des() ); |
|
118 CleanupStack::PopAndDestroy( pres8 ); // >> pres8 |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CPresencePluginWatcher::DoPerformSubscribePresentityPresenceL() |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CPresencePluginWatcher::DoPerformSubscribePresentityPresenceL( |
|
126 const MXIMPIdentity& aPresentityId, |
|
127 TRequestStatus& aStatus ) |
|
128 { |
|
129 DP_SDA( "CPresencePluginWatcher::DoPerformSubscribePresentityPresenceL "); |
|
130 DP_SDA( " -> From list operation"); |
|
131 |
|
132 iOperation = EPluginSubscribeByAdding; |
|
133 iXdmState = EPluginIdle; |
|
134 |
|
135 SetPresIdentityL( aPresentityId, ETrue ); |
|
136 |
|
137 iCompleted = EFalse; |
|
138 |
|
139 HBufC8* pres8 = NULL; |
|
140 pres8 = |
|
141 CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() ); |
|
142 CleanupStack::PushL( pres8 ); // << pres8 |
|
143 |
|
144 // remove escapes |
|
145 HBufC8* encodedUsername = EscapeUtils::EscapeEncodeL( *pres8, EscapeUtils::EEscapeNormal ); |
|
146 CleanupStack::PopAndDestroy( pres8 ); |
|
147 CleanupStack::PushL( encodedUsername ); |
|
148 |
|
149 CPresencePluginEntityWatcher* watcher = |
|
150 MatchWatcherL( encodedUsername->Des(), ETrue ); |
|
151 watcher->StartSubscribeL( encodedUsername->Des(), aStatus ); |
|
152 CleanupStack::PopAndDestroy( encodedUsername ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CPresencePluginWatcher::DoUpdatePresentityPresenceSubscriptionPifL() |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CPresencePluginWatcher::DoUpdatePresentityPresenceSubscriptionPifL( |
|
160 const MXIMPIdentity& /*aPresentityId*/, |
|
161 const MPresenceInfoFilter& /*aPif*/, |
|
162 TXIMPRequestId /*aReqId*/ ) |
|
163 { |
|
164 // Notice: later |
|
165 User::Leave( KXIMPErrServiceRequestTypeNotSupported ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CPresencePluginWatcher::DoUnsubscribePresentityPresenceL() |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CPresencePluginWatcher::DoUnsubscribePresentityPresenceL( |
|
173 const MXIMPIdentity& aPresentityId, |
|
174 TXIMPRequestId aReqId ) |
|
175 { |
|
176 DP_SDA("CPresencePluginWatcher::DoUnsubscribePresentityPresenceL"); |
|
177 SetPresIdentityL( aPresentityId, ETrue ); |
|
178 iXIMPId = aReqId; |
|
179 iCompleted = EFalse; |
|
180 |
|
181 HBufC8* pres8 = NULL; |
|
182 pres8 = |
|
183 CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() ); |
|
184 CleanupStack::PushL( pres8 ); // << pres8 |
|
185 |
|
186 CPresencePluginEntityWatcher* watcher = |
|
187 MatchWatcherL( pres8->Des(), EFalse ); |
|
188 if ( !watcher ) |
|
189 { |
|
190 DP_SDA("DoUnsubscribePresentityPresenceL error"); |
|
191 User::Leave( KErrNotFound ); // Notice: error code |
|
192 } |
|
193 else |
|
194 { |
|
195 DP_SDA("DoUnsubscribePresentityPresenceL stop subscripe"); |
|
196 watcher->StopSubscribeL(); |
|
197 } |
|
198 CleanupStack::PopAndDestroy( pres8 ); // >> pres8 |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CPresencePluginWatcher::DoPerformUnsubscribePresentityPresenceL() |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CPresencePluginWatcher::DoPerformUnsubscribePresentityPresenceL( |
|
206 const MXIMPIdentity& aPresentityId, |
|
207 TRequestStatus& aStatus ) |
|
208 { |
|
209 DP_SDA("CPresencePluginWatcher::DoPerformUnsubscribePresentityPresenceL"); |
|
210 |
|
211 SetPresIdentityL( aPresentityId, ETrue ); |
|
212 iCompleted = EFalse; |
|
213 |
|
214 iOperation = EPluginUnSubscribeByRemoving; |
|
215 |
|
216 HBufC8* pres8 = NULL; |
|
217 pres8 = |
|
218 CnvUtfConverter::ConvertFromUnicodeToUtf8L( iPresIdentity->Des() ); |
|
219 CleanupStack::PushL( pres8 ); // << pres8 |
|
220 |
|
221 CPresencePluginEntityWatcher* watcher = |
|
222 MatchWatcherL( pres8->Des(), EFalse ); |
|
223 if ( !watcher ) |
|
224 { |
|
225 DP_SDA("DoUnsubscribePresentityPresenceL watcher not found"); |
|
226 aStatus = KRequestPending; |
|
227 TRequestStatus* temp = &aStatus; |
|
228 User::RequestComplete( temp, KErrNotFound ); |
|
229 } |
|
230 else |
|
231 { |
|
232 DP_SDA("DoUnsubscribePresentityPresenceL stop subscribe"); |
|
233 watcher->StopSubscribeL( aStatus ); |
|
234 } |
|
235 CleanupStack::PopAndDestroy( pres8 ); // >> pres8 |
|
236 |
|
237 DP_SDA("CPresencePluginWatcher::DoPerformUnsubscribePresentityPresenceL end"); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CPresencePluginWatcher::DoSubscribePresentityGroupMembersPresenceL() |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CPresencePluginWatcher::DoSubscribePresentityGroupMembersPresenceL( |
|
245 const MXIMPIdentity& aGroupId, |
|
246 const MPresenceInfoFilter& /*aPif*/, |
|
247 TXIMPRequestId aReqId ) |
|
248 { |
|
249 DP_SDA("DoSubscribePresentityGroupMembersPresenceL"); |
|
250 //Subscribe all buddys from virtual group |
|
251 |
|
252 iOperation = EPluginSubscribeGroup; |
|
253 iXdmState = EPluginIdle; |
|
254 |
|
255 SetPresIdentityL( aGroupId, EFalse ); |
|
256 iXIMPId = aReqId; |
|
257 iCompleted = EFalse; |
|
258 |
|
259 StartXdmOperationL(); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CPresencePluginWatcher:: |
|
264 // DoUpdatePresentityGroupMembersPresenceSubscriptionPifL() |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CPresencePluginWatcher:: |
|
268 DoUpdatePresentityGroupMembersPresenceSubscriptionPifL( |
|
269 const MXIMPIdentity& /*aGroupId*/, |
|
270 const MPresenceInfoFilter& /*aPif*/, |
|
271 TXIMPRequestId /*aReqId*/ ) |
|
272 { |
|
273 User::Leave( KErrNotSupported ); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CPresencePluginWatcher::DoUnsubscribePresentityGroupMembersPresenceL() |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CPresencePluginWatcher::DoUnsubscribePresentityGroupMembersPresenceL( |
|
281 const MXIMPIdentity& aGroupId, |
|
282 TXIMPRequestId aReqId ) |
|
283 { |
|
284 DP_SDA("DoUnsubscribePresentityGroupMembersPresenceL"); |
|
285 |
|
286 iOperation = EPluginUnsubscribeGroup; |
|
287 iXdmState = EPluginIdle; |
|
288 |
|
289 SetPresIdentityL( aGroupId, EFalse ); |
|
290 iXIMPId = aReqId; |
|
291 iCompleted = EFalse; |
|
292 |
|
293 StartXdmOperationL(); |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CPresencePluginWatcher::GetInterface() |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 TAny* CPresencePluginWatcher::GetInterface( |
|
301 TInt32 aInterfaceId, |
|
302 TIfGetOps aOptions ) |
|
303 { |
|
304 DP_SDA("CPresencePluginWatcher::GetInterface (......) "); |
|
305 if ( aInterfaceId == GetInterfaceId() ) |
|
306 { |
|
307 DP_SDA("GetInterface : aInterfaceId == GetInterfaceId()"); |
|
308 // caller wants this interface |
|
309 MProtocolPresenceWatching* myIf = this; |
|
310 return myIf; |
|
311 } |
|
312 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
313 { |
|
314 DP_SDA("GetInterface: aOptions == MXIMPBase::EPanicIfUnknown"); |
|
315 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
316 } |
|
317 return NULL; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CPresencePluginWatcher::GetInterface() |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 const TAny* CPresencePluginWatcher::GetInterface( |
|
325 TInt32 aInterfaceId, |
|
326 TIfGetOps aOptions ) const |
|
327 { |
|
328 DP_SDA("CPresencePluginWatcher::GetInterface (......) const "); |
|
329 if ( aInterfaceId == GetInterfaceId() ) |
|
330 { |
|
331 DP_SDA("GetInterface : aInterfaceId == GetInterfaceId()"); |
|
332 // caller wants this interface |
|
333 const MProtocolPresenceWatching* myIf = this; |
|
334 return myIf; |
|
335 } |
|
336 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
337 { |
|
338 DP_SDA("GetInterface: aOptions == MXIMPBase::EPanicIfUnknown"); |
|
339 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
340 } |
|
341 return NULL; |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // CPresencePluginWatcher::GetInterfaceId() |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 TInt32 CPresencePluginWatcher::GetInterfaceId() const |
|
349 { |
|
350 DP_SDA("CPresencePluginWatcher::GetInterfaceId() const"); |
|
351 return MProtocolPresenceWatching::KInterfaceId; |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // CPresencePluginWatcher::MatchWatcherL |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 CPresencePluginEntityWatcher* CPresencePluginWatcher::MatchWatcherL( |
|
359 const TDesC8& aPresentityid, TBool aCreate ) |
|
360 { |
|
361 DP_SDA("CPresencePluginWatcher::MatchWatcherL"); |
|
362 DP_SDA2("CPresencePluginWatcher::MatchWatcherL %d", aCreate ) |
|
363 TInt count = iWatchers.Count(); |
|
364 DP_SDA2( "MatchWatcherL watcher count %d", count ); |
|
365 for ( TInt i = 0; i < count; i++ ) |
|
366 { |
|
367 CPresencePluginEntityWatcher* temp = ( iWatchers[i] ); |
|
368 //Check if prentity found from watcher |
|
369 if ( !temp->PresentityId().CompareF( aPresentityid )) |
|
370 { |
|
371 DP_SDA("CPresencePluginWatcher::MatchWatcherL return temp"); |
|
372 return temp; |
|
373 } |
|
374 } |
|
375 if ( !aCreate ) |
|
376 { |
|
377 DP_SDA("CPresencePluginWatcher::MatchWatcherL return NULL"); |
|
378 return NULL; |
|
379 } |
|
380 else |
|
381 { |
|
382 // Run this if like create new wathcer |
|
383 DP_SDA("CPresencePluginWatcher::MatchWatcherL Else"); |
|
384 CPresencePluginEntityWatcher* watcher = |
|
385 CPresencePluginEntityWatcher::NewL( |
|
386 iConnObs, iConnection, *this, iPresenceData ); |
|
387 CleanupStack::PushL( watcher ); |
|
388 iWatcherCandidates.AppendL( watcher ); |
|
389 CleanupStack::Pop(); |
|
390 DP_SDA("CPresencePluginWatcher::MatchWatcherL end"); |
|
391 return watcher; |
|
392 } |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // CPresencePluginWatcher::DeleteWatcher |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 void CPresencePluginWatcher::DeleteWatcher( |
|
400 const TDesC8& aPresentityid ) |
|
401 { |
|
402 DP_SDA( "CPresencePluginWatcher::DeleteWatcher" ); |
|
403 TInt count = iWatchers.Count(); |
|
404 DP_SDA2( "CPresencePluginWatcher::DeleteWatcher count %d", count); |
|
405 |
|
406 for ( TInt i = 0; i < count; i++ ) |
|
407 { |
|
408 CPresencePluginEntityWatcher* temp = ( iWatchers[i] ); |
|
409 if ( !temp->PresentityId().CompareF( aPresentityid ) ) |
|
410 { |
|
411 DP_SDA2( "CPresencePluginWatcher::DeleteWatcher %d", i ); |
|
412 iWatchers.Remove( i ); |
|
413 iWatchers.GranularCompress(); |
|
414 delete temp; |
|
415 temp = NULL; |
|
416 break; // delete all watchers? |
|
417 } |
|
418 } |
|
419 DP_SDA( "CPresencePluginWatcher::DeleteWatcher end" ); |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CPresencePluginWatcher::SetPresIdentityL() |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 void CPresencePluginWatcher::SetPresIdentityL( |
|
427 const MXIMPIdentity& aPresentityId, |
|
428 TBool aFormatUri ) |
|
429 { |
|
430 DP_SDA2("CPresencePluginWatcher::SetPresIdentityL: %S", |
|
431 &aPresentityId.Identity() ); |
|
432 |
|
433 delete iPresIdentity; |
|
434 iPresIdentity = NULL; |
|
435 |
|
436 if( aFormatUri ) |
|
437 { |
|
438 HBufC8* identityCopy = HBufC8::NewLC( KBufSize255 ); |
|
439 TPtr8 identityCopyPtr( identityCopy->Des() ); |
|
440 identityCopyPtr.Copy( aPresentityId.Identity() ); |
|
441 DP_SDA2(" SetPresIdentityL, org identity: %S", identityCopy ); |
|
442 |
|
443 HBufC8* prefixUri = iPresenceData->CreatePresenceUri8LC( |
|
444 identityCopyPtr ); |
|
445 |
|
446 HBufC* prefixUri16 = HBufC::NewLC( KBufSize255 ); |
|
447 TPtr prefixUri16Ptr( prefixUri16->Des() ); |
|
448 prefixUri16Ptr.Copy( *prefixUri ); |
|
449 |
|
450 DP_SDA2("CPresencePluginWatcher::SetPresIdentityL: with prefix: %S", |
|
451 prefixUri16 ); |
|
452 |
|
453 iPresIdentity = prefixUri16; |
|
454 CleanupStack::Pop( prefixUri16 ); |
|
455 CleanupStack::PopAndDestroy( 2, identityCopy ); |
|
456 } |
|
457 else |
|
458 { |
|
459 DP_SDA("CPresencePluginWatcher::SetPresIdentityL, use as it is"); |
|
460 iPresIdentity = aPresentityId.Identity().AllocL(); |
|
461 } |
|
462 } |
|
463 |
|
464 // --------------------------------------------------------------------------- |
|
465 // CPresencePluginWatcher::CompleteXIMPReq() |
|
466 // --------------------------------------------------------------------------- |
|
467 // |
|
468 void CPresencePluginWatcher::CompleteXIMPReq( TInt aStatus ) |
|
469 { |
|
470 DP_SDA("CPresencePluginWatcher::CompleteXIMPReq"); |
|
471 iXdmState = EPluginIdle; |
|
472 if ( iCompleted ) |
|
473 { |
|
474 return; |
|
475 } |
|
476 iCompleted = ETrue; |
|
477 iConnObs.CompleteReq( iXIMPId, aStatus ); |
|
478 iXIMPId = TXIMPRequestId(); |
|
479 DP_SDA("CPresencePluginWatcher::CompleteXIMPReq END"); |
|
480 iOperation = EPluginUndef; |
|
481 } |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // CPresencePluginWatcher::MatchWatcherId |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 TBool CPresencePluginWatcher::MatchWatcherId( |
|
488 const TDesC8& aPresentityId ) const |
|
489 { |
|
490 DP_SDA("CPresencePluginWatcher::MatchWatcherId"); |
|
491 |
|
492 TBool watcherFound( EFalse ); |
|
493 TInt count = iWatchers.Count(); |
|
494 |
|
495 DP_SDA2("CPresencePluginWatcher::MatchWatcherId watcher count %d", count); |
|
496 |
|
497 for ( TInt i = 0; i < count; i++ ) |
|
498 { |
|
499 CPresencePluginEntityWatcher* temp = ( iWatchers[i] ); |
|
500 |
|
501 //Check if ID is found from watcher |
|
502 if ( !temp->PresentityId().CompareF( aPresentityId ) ) |
|
503 { |
|
504 DP_SDA("CPresencePluginWatcher::MatchWatcherId - Match!"); |
|
505 watcherFound = ETrue; |
|
506 } |
|
507 } |
|
508 |
|
509 return watcherFound; |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // CPresencePluginWatcher::CompleteWatcher |
|
514 // --------------------------------------------------------------------------- |
|
515 // |
|
516 void CPresencePluginWatcher::CompleteWatcher( TInt aStatus ) |
|
517 { |
|
518 |
|
519 DP_SDA("CPresencePluginWatcher::CompleteWatcher"); |
|
520 DP_SDA2("CPresencePluginWatcher::CompleteWatcher status %d", aStatus); |
|
521 // start to remove RLS service when needed. |
|
522 if ( iOperation == EPluginUnsubscribeGroup ) |
|
523 { |
|
524 DP_SDA("CompleteWatcher EPluginUnsubscribeGroup"); |
|
525 if ( iXdmState == EPluginIdle ) |
|
526 { |
|
527 TRAPD( err, iXdmUtils->InitializeXdmsOnlyL( iStatus )); |
|
528 if ( err ) |
|
529 { |
|
530 DP_SDA2("CompleteWatcher EPluginUnsubscribeGroup err %d",err); |
|
531 CompleteXIMPReq( err ); |
|
532 } |
|
533 else |
|
534 { |
|
535 DP_SDA("CompleteWatcher EPluginUnsubscribeGroup fetch RLS"); |
|
536 iXdmState = EPluginFetchRls; |
|
537 if( !IsActive() ) |
|
538 { |
|
539 SetActive(); |
|
540 } |
|
541 } |
|
542 return; |
|
543 } |
|
544 } |
|
545 else |
|
546 { |
|
547 DP_SDA("CPresencePluginWatcher::CompleteWatcher complete"); |
|
548 CompleteXIMPReq( aStatus ); |
|
549 } |
|
550 DP_SDA("CPresencePluginWatcher::CompleteWatcher end"); |
|
551 } |
|
552 |
|
553 // --------------------------------------------------------------------------- |
|
554 // CPresencePluginWatcher::StartXdmOperationL |
|
555 // --------------------------------------------------------------------------- |
|
556 // |
|
557 void CPresencePluginWatcher::StartXdmOperationL() |
|
558 { |
|
559 DP_SDA("CPresencePluginWatcher::StartXdmOperationL"); |
|
560 __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) ); |
|
561 if ( !iXdmUtils ) |
|
562 { |
|
563 iXdmUtils = iConnObs.XdmUtilsL(); |
|
564 } |
|
565 iXdmUtils->InitializeXdmsOnlyL( iStatus ); |
|
566 |
|
567 iXdmState = EPluginInitXdm; |
|
568 |
|
569 SetActive(); |
|
570 } |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // CPresencePluginWatcher::DoCancel |
|
574 // --------------------------------------------------------------------------- |
|
575 // |
|
576 void CPresencePluginWatcher::DoCancel( ) |
|
577 { |
|
578 iXdmUtils->Cancel(); |
|
579 } |
|
580 |
|
581 // --------------------------------------------------------------------------- |
|
582 // CPresencePluginWatcher::RunL |
|
583 // --------------------------------------------------------------------------- |
|
584 // |
|
585 void CPresencePluginWatcher::RunL() |
|
586 { |
|
587 |
|
588 TInt status = iStatus.Int(); |
|
589 |
|
590 DP_SDA2("CPresencePluginWatcher::RunL mystatus %d ", status); |
|
591 |
|
592 if ( !status ) |
|
593 { |
|
594 if( iOperation == EPluginUnsubscribeGroup ) |
|
595 { |
|
596 DP_SDA("CPresencePluginWatcher::RunL EPluginUnsubscribeGroup "); |
|
597 UnSubscribeAllL(); |
|
598 } |
|
599 if ( iOperation == EPluginSubscribeGroup ) |
|
600 { |
|
601 //First check we have complete buddy list from server |
|
602 if ( iXdmState == EPluginInitXdm ) |
|
603 { |
|
604 // get members of the list first |
|
605 SubscribeAllL(); |
|
606 return; |
|
607 } |
|
608 } |
|
609 if ( iOperation == EPluginSubscribeSingle ) |
|
610 { |
|
611 DP_SDA("CPresencePluginWatcher::RunL EPluginSubscribeSingle "); |
|
612 if ( iXdmState == EPluginIdle ) |
|
613 { |
|
614 DP_SDA("RunL EPluginSubscribeSingle complete"); |
|
615 iOperation = EPluginUndef; |
|
616 CompleteXIMPReq( status ); |
|
617 } |
|
618 else |
|
619 { |
|
620 iOperation = EPluginUndef; |
|
621 CompleteXIMPReq( status ); |
|
622 } |
|
623 } |
|
624 } |
|
625 else |
|
626 { |
|
627 DP_SDA("CPresencePluginWatcher::RunL error, complete"); |
|
628 CompleteXIMPReq( status ); |
|
629 } |
|
630 DP_SDA("CPresencePluginWatcher::RunL end"); |
|
631 } |
|
632 |
|
633 // --------------------------------------------------------------------------- |
|
634 // CPresencePluginWatcher::SubscribeL |
|
635 // --------------------------------------------------------------------------- |
|
636 // |
|
637 void CPresencePluginWatcher::SubscribeL( const TDesC& aIdentity ) |
|
638 { |
|
639 DP_SDA2("CPresencePluginWatcher::SubscribeL identity: %S", &aIdentity ); |
|
640 |
|
641 MXIMPIdentity* member = iConnObs.ObjectFactory().NewIdentityLC(); |
|
642 member->SetIdentityL( aIdentity ); |
|
643 |
|
644 SetPresIdentityL( *member, EFalse ); |
|
645 |
|
646 HBufC8* pres8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
647 member->Identity() ); |
|
648 CleanupStack::PushL( pres8 ); |
|
649 |
|
650 DP_SDA("CPresencePluginWatcher::SubscribeL try to subsribe"); |
|
651 |
|
652 CPresencePluginEntityWatcher* watcher = MatchWatcherL( |
|
653 pres8->Des(),ETrue ); |
|
654 if ( !watcher ) |
|
655 { |
|
656 DP_SDA("CPresencePluginWatcher::SubscribeL no watcher, create"); |
|
657 watcher = CPresencePluginEntityWatcher::NewL( |
|
658 iConnObs, iConnection, *this, iPresenceData ); |
|
659 CleanupStack::PushL( watcher ); |
|
660 iWatcherCandidates.AppendL( watcher ); |
|
661 CleanupStack::Pop( watcher ); |
|
662 } |
|
663 DP_SDA("CPresencePluginWatcher::SubscribeL do subsribe"); |
|
664 watcher->StartSubscribeL( pres8->Des() ); |
|
665 DP_SDA("CPresencePluginWatcher::SubscribeL do subsribe ok"); |
|
666 |
|
667 CleanupStack::PopAndDestroy( pres8 ); |
|
668 CleanupStack::PopAndDestroy( 1 ); // >> member |
|
669 } |
|
670 |
|
671 // --------------------------------------------------------------------------- |
|
672 // CPresencePluginWatcher::SubscribeAllL |
|
673 // --------------------------------------------------------------------------- |
|
674 // |
|
675 void CPresencePluginWatcher::SubscribeAllL() |
|
676 { |
|
677 DP_SDA("CPresencePluginWatcher::SubscribeAllL"); |
|
678 |
|
679 CDesCArray* subsribed = |
|
680 iConnObs.SubscribedContacts()->GetVirtualIdentityArray(); |
|
681 |
|
682 //Get count |
|
683 TInt count = subsribed->Count(); |
|
684 DP_SDA2( "CPresencePluginWatcher::SubscribeAllL contact count %d", count); |
|
685 |
|
686 //Subsribe contact one by one |
|
687 if( count > 0 ) |
|
688 { |
|
689 for( TInt i = 0;i < count;i++) |
|
690 { |
|
691 DP_SDA2( "SubscribeAllL handle contact no: %d", i ); |
|
692 SubscribeL( subsribed->MdcaPoint( i ) ); |
|
693 } |
|
694 } |
|
695 DP_SDA( "CPresencePluginWatcher::SubscribeAllL end" ); |
|
696 } |
|
697 |
|
698 // --------------------------------------------------------------------------- |
|
699 // CPresencePluginWatcher::UnSubscribeAllL |
|
700 // --------------------------------------------------------------------------- |
|
701 // |
|
702 void CPresencePluginWatcher::UnSubscribeAllL() |
|
703 { |
|
704 DP_SDA("CPresencePluginWatcher::UnSubscribeAllL"); |
|
705 CDesCArray* subsribed = |
|
706 iConnObs.SubscribedContacts()->GetVirtualIdentityArray(); |
|
707 |
|
708 //Get count |
|
709 TInt count = subsribed->Count(); |
|
710 DP_SDA2("CPresencePluginWatcher::UnSubscribeAllL contact count %d",count); |
|
711 //UnSubsribe contact one by one |
|
712 |
|
713 for( TInt i = 0;i < count;i++) |
|
714 { |
|
715 DP_SDA2("UnSubscribeAllL handle contact no: %d",i); |
|
716 //Get identity form array |
|
717 MXIMPIdentity* member = iConnObs.ObjectFactory().NewIdentityLC(); |
|
718 member->SetIdentityL( (*subsribed)[i] ); |
|
719 |
|
720 SetPresIdentityL( *member, EFalse ); |
|
721 |
|
722 HBufC8* pres8 = |
|
723 CnvUtfConverter::ConvertFromUnicodeToUtf8L( member->Identity() ); |
|
724 CleanupStack::PushL( pres8 ); // << pres8 |
|
725 |
|
726 DP_SDA("CPresencePluginWatcher::UnSubscribeAllL try to unsubsribe"); |
|
727 TInt watcherCount = iWatchers.Count(); |
|
728 DP_SDA2("UnSubscribeAllL watcher count %d", watcherCount); |
|
729 |
|
730 TBool notFound( EFalse ); |
|
731 for ( TInt j = 0; j < watcherCount; j++ ) |
|
732 { |
|
733 CPresencePluginEntityWatcher* watcher = |
|
734 MatchWatcherL( pres8->Des(), EFalse ); |
|
735 if ( !watcher ) |
|
736 { |
|
737 DP_SDA("UnSubscribeAllL error not found"); |
|
738 notFound = ETrue; |
|
739 } |
|
740 else |
|
741 { |
|
742 DP_SDA("UnSubscribeAllL stop subscripe"); |
|
743 watcher->StopSubscribeL(); |
|
744 } |
|
745 DP_SDA2("CPresencePluginWatcher: done= handle next = %d", i); |
|
746 } |
|
747 if ( notFound ) |
|
748 { |
|
749 DP_SDA("CPresencePluginWatcher::UnSubscribeAllL cotact not found"); |
|
750 } |
|
751 CleanupStack::PopAndDestroy( pres8 ); |
|
752 CleanupStack::PopAndDestroy( 1 ); // >> member |
|
753 } |
|
754 DP_SDA("CPresencePluginWatcher::UnSubscribeAllL end"); |
|
755 } |
|
756 |
|
757 // --------------------------------------------------------------------------- |
|
758 // CPresencePluginWatcher::RunError |
|
759 // --------------------------------------------------------------------------- |
|
760 // |
|
761 TInt CPresencePluginWatcher::RunError( TInt aError ) |
|
762 { |
|
763 DP_SDA2("CPresencePluginWatcher::RunError = %d", aError); |
|
764 CompleteXIMPReq( aError ); |
|
765 return KErrNone; |
|
766 } |
|
767 |
|
768 // --------------------------------------------------------------------------- |
|
769 // CPresencePluginWatcher::AcceptL() |
|
770 // --------------------------------------------------------------------------- |
|
771 // |
|
772 void CPresencePluginWatcher::AcceptL( const CPresencePluginEntityWatcher* aWatcher ) |
|
773 { |
|
774 DP_SDA( "CPresencePluginWatcher::AcceptL" ); |
|
775 |
|
776 if ( KErrNotFound == iWatchers.Find( aWatcher ) ) |
|
777 { |
|
778 iWatchers.AppendL( aWatcher ); |
|
779 |
|
780 TInt index = iWatcherCandidates.Find( aWatcher ); |
|
781 if ( KErrNotFound != index ) |
|
782 { |
|
783 iWatcherCandidates.Remove( index ); |
|
784 } |
|
785 } |
|
786 } |
|
787 |
|
788 // End of file |