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