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: IETF SIMPLE Protocol implementation for XIMP Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <utf.h> |
|
21 #include <ximpdatasubscriptionstate.h> |
|
22 #include <protocolpresencepublishingdatahost.h> |
|
23 #include <protocolpresencedatahost.h> |
|
24 #include <ximpobjectfactory.h> |
|
25 #include <presenceobjectfactory.h> |
|
26 #include <presenceinfo.h> |
|
27 #include <personpresenceinfo.h> |
|
28 #include <ximpprotocolconnectionhost.h> |
|
29 #include <ximpstatus.h> |
|
30 #include <ximperrors.hrh> |
|
31 #include <ximpidentity.h> |
|
32 #include <ximpobjectcollection.h> |
|
33 #include <presencewatcherinfo.h> |
|
34 #include <simpleutils.h> // For KSimplePDM |
|
35 #include <simplefactory.h> |
|
36 #include <msimpledocument.h> |
|
37 #include <msimplepublisher.h> |
|
38 #include <msimplewatcher.h> |
|
39 #include <msimplewinfo.h> |
|
40 #include <msimpleelement.h> |
|
41 #include <msimpleconnection.h> |
|
42 #include <simpleerrors.h> |
|
43 #include <avabilitytext.h> |
|
44 |
|
45 #include "presenceplugincommon.h" |
|
46 #include "presencepluginpublisher.h" |
|
47 #include "presencepluginwinfo.h" |
|
48 #include "presenceplugindata.h" |
|
49 #include "presencepluginxdmutils.h" |
|
50 #include "presencepluginwatcherinfo.h" |
|
51 #include "presenceplugincommon.h" |
|
52 |
|
53 // ======== MEMBER FUNCTIONS ======== |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CPresencePluginPublisher::CPresencePluginPublisher() |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CPresencePluginPublisher::CPresencePluginPublisher( |
|
60 MPresencePluginConnectionObs& aObs, |
|
61 MSimpleConnection& aConn ) |
|
62 : CActive( CActive::EPriorityStandard ), |
|
63 iConnObs(aObs), iConnection(aConn), |
|
64 iPublisher( NULL ), iWatcher( NULL ), |
|
65 iSubscribed(EFalse), iSubscribedOwn(EFalse), |
|
66 iPublished(EFalse), iRePublish(EFalse), |
|
67 iWatcherList( CPresencePluginWatcherInfo::LinkOffset() ) |
|
68 { |
|
69 DP_SDA("CPresencePluginPublisher::CPresencePluginPublisher "); |
|
70 CActiveScheduler::Add(this); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CPresencePluginPublisher::ConstructL() |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CPresencePluginPublisher::ConstructL( CPresencePluginData* aPresenceData ) |
|
78 { |
|
79 DP_SDA("CPresencePluginPublisher::ConstructL "); |
|
80 iWatcher = TSimpleFactory::NewWatcherL( iConnection, *this ); |
|
81 iPublisher = TSimpleFactory::NewPublisherL( iConnection, *this ); |
|
82 iPresenceData = aPresenceData; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CPresencePluginPublisher::NewL() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CPresencePluginPublisher* CPresencePluginPublisher::NewL( |
|
90 MPresencePluginConnectionObs& aObs, |
|
91 MSimpleConnection& aConn, |
|
92 CPresencePluginData* aPresenceData ) |
|
93 { |
|
94 CPresencePluginPublisher* self = |
|
95 new( ELeave ) CPresencePluginPublisher( aObs, aConn ); |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL( aPresenceData ); |
|
98 CleanupStack::Pop( self ); |
|
99 return self; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CPresencePluginPublisher::~CPresencePluginPublisher() |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CPresencePluginPublisher::~CPresencePluginPublisher() |
|
107 { |
|
108 DP_SDA("CPresencePluginPublisher::~CPresencePluginPublisher"); |
|
109 |
|
110 if ( iDocument ) |
|
111 { |
|
112 iDocument->Close(); |
|
113 } |
|
114 |
|
115 if ( iPublisher ) |
|
116 { |
|
117 iPublisher->Close(); |
|
118 } |
|
119 |
|
120 if ( iWatcher ) |
|
121 { |
|
122 iWatcher->Close(); |
|
123 } |
|
124 |
|
125 DeleteWatchers(); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CPresencePluginPublisher::DeleteWatchers |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void CPresencePluginPublisher::DeleteWatchers() |
|
133 { |
|
134 DP_SDA("CPresencePluginPublisher::DeleteWatchers"); |
|
135 // Delete all buffered transaction requests |
|
136 TDblQueIter<CPresencePluginWatcherInfo> rIter( iWatcherList ); |
|
137 rIter.SetToFirst(); |
|
138 |
|
139 while ( rIter ) |
|
140 { |
|
141 DP_SDA("CPresencePluginPublisher::DeleteWatchers while"); |
|
142 CPresencePluginWatcherInfo* w = rIter; |
|
143 rIter++; |
|
144 // delete wathcer info |
|
145 w->Destroy(); |
|
146 } |
|
147 DP_SDA("CPresencePluginPublisher::DeleteWatchers end"); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CPresencePluginPublisher::AddWatcherIfNotExistsL |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CPresencePluginPublisher::AddWatcherIfNotExistsL( |
|
155 const TDesC8& aId, |
|
156 const TDesC& aSipId ) |
|
157 { |
|
158 DP_SDA("CPresencePluginPublisher::AddWatcherIfNotExistsL"); |
|
159 // Delete all buffered transaction requests |
|
160 TDblQueIter<CPresencePluginWatcherInfo> rIter( iWatcherList ); |
|
161 rIter.SetToFirst(); |
|
162 |
|
163 TBool found(EFalse); |
|
164 |
|
165 while ( rIter ) |
|
166 { |
|
167 CPresencePluginWatcherInfo* w = rIter; |
|
168 rIter++; |
|
169 found = w->Match( aId, aSipId ); |
|
170 if ( found ) |
|
171 { |
|
172 DP_SDA("CPresencePluginPublisher::AddWatcherIfNotExistsL found"); |
|
173 break; |
|
174 } |
|
175 } |
|
176 if ( !found ) |
|
177 { |
|
178 DP_SDA("CPresencePluginPublisher::AddWatcherIfNotExistsL !found"); |
|
179 CPresencePluginWatcherInfo* w = |
|
180 CPresencePluginWatcherInfo::NewL( aId, aSipId ); |
|
181 iWatcherList.AddLast( *w ); |
|
182 } |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CPresencePluginPublisher::RemoveWatcherIfExistsL |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CPresencePluginPublisher::RemoveWatcherIfExists( |
|
190 const TDesC8& aId, const TDesC& aSipId ) |
|
191 { |
|
192 DP_SDA("CPresencePluginPublisher::RemoveWatcherIfExistsL"); |
|
193 // Delete all buffered transaction requests |
|
194 TDblQueIter<CPresencePluginWatcherInfo> rIter( iWatcherList ); |
|
195 rIter.SetToFirst(); |
|
196 |
|
197 TBool found(EFalse); |
|
198 |
|
199 while ( rIter ) |
|
200 { |
|
201 CPresencePluginWatcherInfo* w = rIter; |
|
202 rIter++; |
|
203 // delete wathcer info |
|
204 found = w->Match( aId, aSipId ); |
|
205 if ( found ) |
|
206 { |
|
207 w->Destroy(); |
|
208 break; |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CPresencePluginPublisher::DoPublishOwnPresenceL() |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CPresencePluginPublisher::DoPublishOwnPresenceL( |
|
218 const MPresenceInfo& aOwnPresence, |
|
219 TXIMPRequestId aReqId ) |
|
220 { |
|
221 DP_SDA("CPresencePluginPublisher::DoPublishOwnPresenceL"); |
|
222 const MPersonPresenceInfo* persInfo = aOwnPresence.PersonPresence(); |
|
223 if ( !persInfo ) |
|
224 { |
|
225 // Notice: error codes |
|
226 CompleteXIMPReq( KErrArgument ); |
|
227 return; |
|
228 } |
|
229 InitializeSimpleDocumentL( ); |
|
230 AddSimpleDocumentPersL( persInfo ); |
|
231 |
|
232 StartXdmOperationL( aReqId ); |
|
233 iOperation = EPublishOwn; |
|
234 DP_SDA("CPresencePluginPublisher::DoPublishOwnPresenceL end"); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CPresencePluginPublisher::DoSubscribeOwnPresenceL() |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CPresencePluginPublisher::DoSubscribeOwnPresenceL( |
|
242 const MPresenceInfoFilter& /*aPif*/, // notice: later |
|
243 TXIMPRequestId aReqId ) |
|
244 { |
|
245 DP_SDA("CPresencePluginPublisher::DoSubscribeOwnPresenceL"); |
|
246 StartXdmOperationL( aReqId ); |
|
247 iOperation = ESubscribeOwn; |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // CPresencePluginPublisher::DoUpdateOwnPresenceSubscriptionPifL() |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CPresencePluginPublisher::DoUpdateOwnPresenceSubscriptionPifL( |
|
255 const MPresenceInfoFilter& /*aPif*/, |
|
256 TXIMPRequestId /*aReqId*/ ) |
|
257 { |
|
258 // Notice: later |
|
259 User::Leave( KErrNotSupported ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CPresencePluginPublisher::DoUnsubscribeOwnPresenceL() |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CPresencePluginPublisher::DoUnsubscribeOwnPresenceL( |
|
267 TXIMPRequestId aReqId ) |
|
268 { |
|
269 DP_SDA("CPresencePluginPublisher::DoUnsubscribeOwnPresenceL"); |
|
270 iSubscribedOwn = EFalse; |
|
271 iSimpleId = iWatcher->UnsubscribeL(); |
|
272 iXIMPId = aReqId; |
|
273 iOperation = EUnsubscribeOwn; |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CPresencePluginPublisher::DoSubscribePresenceWatcherListL() |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CPresencePluginPublisher::DoSubscribePresenceWatcherListL( |
|
281 TXIMPRequestId aReqId ) |
|
282 { |
|
283 DP_SDA("CPresencePluginPublisher::DoSubscribePresenceWatcherListL"); |
|
284 if ( !iSubscribed ) |
|
285 { |
|
286 DP_SDA("DoSubscribePresenceWatcherListL !Subscribed"); |
|
287 iConnObs.WinfoHandlerL()->SubscribeWinfoListL( aReqId ); |
|
288 iSubscribed = ETrue; |
|
289 iXIMPId = aReqId; |
|
290 iOperation = ESubscribeWinfo; |
|
291 } |
|
292 else |
|
293 { |
|
294 DP_SDA("DoSubscribePresenceWatcherListL else"); |
|
295 iXIMPId = aReqId; |
|
296 iOperation = ESubscribeWinfo; |
|
297 CompleteXIMPReq( KErrNone ); |
|
298 } |
|
299 DP_SDA("CPresencePluginPublisher::DoSubscribePresenceWatcherListL end"); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CPresencePluginPublisher::DoUnsubscribePresenceWatcherListL() |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CPresencePluginPublisher::DoUnsubscribePresenceWatcherListL( |
|
307 TXIMPRequestId aReqId ) |
|
308 { |
|
309 DP_SDA("CPresencePluginPublisher::DoUnsubscribePresenceWatcherListL"); |
|
310 if ( iSubscribed ) |
|
311 { |
|
312 DP_SDA("DoUnsubscribePresenceWatcherListL: if ( iSubscribed ) - begin"); |
|
313 iConnObs.WinfoHandlerL()->UnsubscribeWinfoListL( aReqId ); |
|
314 iSubscribed = EFalse; |
|
315 iXIMPId = aReqId; |
|
316 iOperation = EUnsubscribeWinfo; |
|
317 DP_SDA("DoUnsubscribePresenceWatcherListL: if ( iSubscribed ) - end"); |
|
318 |
|
319 } |
|
320 else |
|
321 { |
|
322 DP_SDA("DoUnsubscribePresenceWatcherListL: iSubscribed ) is false"); |
|
323 iXIMPId = aReqId; |
|
324 iOperation = EUnsubscribeWinfo; //hameed |
|
325 CompleteXIMPReq( KErrNone ); |
|
326 } |
|
327 } |
|
328 |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // CPresencePluginPublisher::PublishReqCompleteL() |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 void CPresencePluginPublisher::PublishReqCompleteL( |
|
335 TInt /*aOpid*/, |
|
336 TInt aStatus ) |
|
337 { |
|
338 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL"); |
|
339 // Notice: make 415 error code conversion here and other |
|
340 //SIP code -> XIMP conversions |
|
341 DP_SDA2("PublishReqCompleteL STATUS %d",aStatus ); |
|
342 |
|
343 if( iConnObs.GetSessionStatus() ) |
|
344 { |
|
345 DP_SDA2("PublishReqComp stopState %d",iConnObs.GetStopPublishState()); |
|
346 if ( !aStatus && !iConnObs.GetStopPublishState() ) |
|
347 { |
|
348 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL ETrue"); |
|
349 iPublished = ETrue; |
|
350 iConnObs.SetStopPublishState( ETrue ); |
|
351 } |
|
352 // Save E-Tag |
|
353 if( !aStatus ) |
|
354 { |
|
355 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL Save ETAG"); |
|
356 TBuf8<KBufSize255> buf; |
|
357 buf.Copy( iPublisher->SIPETag() ); |
|
358 iConnObs.SetETag( buf ); |
|
359 iPresenceData->StoreDocumentIdL( iConnObs.ServiceId(), buf ); |
|
360 } |
|
361 //Do not complete if error republish is true. XIMPFW is not knowing we |
|
362 //are sending republish. |
|
363 if( EFalse == iRePublish && !aStatus ) |
|
364 { |
|
365 //Complete Publish request |
|
366 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL complete"); |
|
367 if( !(iConnObs.IsStopPublishCalled()) ) |
|
368 { |
|
369 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL complete normal"); |
|
370 // successfull Online / others: store status to cache |
|
371 StoreOwnStatusToCacheL( ); |
|
372 CompleteXIMPReq( aStatus ); |
|
373 } |
|
374 //Complete stopPublish and close session if stopPublish is called |
|
375 if( iConnObs.IsStopPublishCalled() ) |
|
376 { |
|
377 DP_SDA("PublishReqCompleteL complete closeSession"); |
|
378 // successfull Online / others: store status to cache |
|
379 StoreOwnStatusToCacheL( ); |
|
380 //Complete close session |
|
381 CompleteClientReq( aStatus ); |
|
382 } |
|
383 } |
|
384 if( EFalse == iRePublish && ( KSimpleErrTemporary == aStatus ) ) |
|
385 { |
|
386 DP_SDA("PublishReqCompleteL KSimpleErrTemporary"); |
|
387 // Make new publish request without ETag |
|
388 CreatePublisherL(); |
|
389 iSimpleId = iPublisher->StartPublishL( *iDocument, ETrue ); |
|
390 } |
|
391 |
|
392 else |
|
393 { |
|
394 //Set rePublish flag back to false. |
|
395 iRePublish = EFalse; |
|
396 } |
|
397 } |
|
398 else |
|
399 { |
|
400 //Run this case if connection is not good any more |
|
401 DP_SDA("PublishReqCompleteL No connect CANCEL"); |
|
402 Cancel(); |
|
403 } |
|
404 DP_SDA("CPresencePluginPublisher::PublishReqCompleteL end"); |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // CPresencePluginPublisher::PublishTerminatedL() |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 void CPresencePluginPublisher::PublishTerminatedL( TInt aOpid ) |
|
412 { |
|
413 DP_SDA("CPresencePluginPublisher::PublishTerminatedL"); |
|
414 DP_SDA2("CPresencePluginPublisher::PublishTerminatedL opID %d",aOpid ); |
|
415 DP_SDA2("PublishTerminatedL iSimpleId %d",iSimpleId ); |
|
416 DP_SDA2("PublishTerminatedL iStatus %d",iStatus.Int() ); |
|
417 |
|
418 if ( iSimpleId == aOpid && iConnObs.GetSessionStatus() ) |
|
419 { |
|
420 DP_SDA("CPresencePluginPublisher::PublishTerminatedL NewPublish"); |
|
421 CreatePublisherL(); |
|
422 TRAPD( error , iSimpleId = iPublisher->StartPublishL( |
|
423 *iDocument, ETrue ) ); |
|
424 if ( KErrNone == error ) |
|
425 { |
|
426 DP_SDA("PublishTerminatedL NewPublish KErrNone"); |
|
427 iRePublish = ETrue; |
|
428 iConnObs.SetStopPublishState( EFalse ); |
|
429 } |
|
430 } |
|
431 else |
|
432 { |
|
433 DP_SDA("CPresencePluginPublisher::PublishTerminatedL else"); |
|
434 iPublished = EFalse; |
|
435 if( iPublisher ) |
|
436 { |
|
437 iPublisher->Close(); |
|
438 iPublisher = NULL; |
|
439 } |
|
440 } |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // CPresencePluginPublisher::WatcherReqCompleteL() |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 void CPresencePluginPublisher::WatcherReqCompleteL( TInt /*aOpid*/, |
|
448 TInt aStatus ) |
|
449 { |
|
450 DP_SDA("CPresencePluginPublisher::WatcherReqCompleteL"); |
|
451 if ( !aStatus ) |
|
452 { |
|
453 iSubscribedOwn = ETrue; |
|
454 } |
|
455 |
|
456 CompleteXIMPReq( aStatus ); |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // CPresencePluginPublisher::WatcherNotificationL() |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 void CPresencePluginPublisher::WatcherNotificationL( |
|
464 MSimpleDocument& aDocument ) |
|
465 { |
|
466 // Notice: Do not need to check the expiration here since |
|
467 // WatcherTerminatedL is called then too. |
|
468 DP_SDA("CPresencePluginPublisher::WatcherNotificationL"); |
|
469 |
|
470 MProtocolPresencePublishingDataHost& publishHost = |
|
471 iConnObs.ProtocolPresenceHost().PublishingDataHost(); |
|
472 |
|
473 MPresenceInfo* prInfo = |
|
474 iConnObs.PresenceObjectFactoryOwn().NewPresenceInfoLC();// << prInfo |
|
475 |
|
476 iPresenceData->NotifyToPrInfoL( |
|
477 iConnObs.ObjectFactory(), |
|
478 iConnObs.PresenceObjectFactoryOwn(), |
|
479 aDocument, |
|
480 *prInfo ); |
|
481 |
|
482 // XIMP Host API callbacks |
|
483 |
|
484 publishHost.HandleSubscribedOwnPresenceL( prInfo ); |
|
485 CleanupStack::Pop(); // >> prInfo |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------------------------- |
|
489 // CPresencePluginPublisher::WatcherListNotificationL() |
|
490 // --------------------------------------------------------------------------- |
|
491 // |
|
492 void CPresencePluginPublisher::WatcherListNotificationL( |
|
493 MSimplePresenceList& /*aList*/ ) |
|
494 { |
|
495 //Do nothing now |
|
496 DP_SDA("CPresencePluginPublisher::WatcherListNotificationL EMPTY"); |
|
497 } |
|
498 |
|
499 // --------------------------------------------------------------------------- |
|
500 // CPresencePluginPublisher::WatcherTerminatedL() |
|
501 // --------------------------------------------------------------------------- |
|
502 // |
|
503 void CPresencePluginPublisher::WatcherTerminatedL( |
|
504 TInt /*aOpId*/, TInt aReason ) |
|
505 { |
|
506 DP_SDA("CPresencePluginPublisher::WatcherTerminatedL"); |
|
507 |
|
508 iSubscribedOwn = EFalse; |
|
509 |
|
510 MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory(); |
|
511 MProtocolPresencePublishingDataHost& publishHost = |
|
512 iConnObs.ProtocolPresenceHost().PublishingDataHost(); |
|
513 |
|
514 MXIMPDataSubscriptionState *state = |
|
515 myFactory.NewDataSubscriptionStateLC(); |
|
516 MXIMPStatus* status = myFactory.NewStatusLC(); |
|
517 state->SetSubscriptionStateL( |
|
518 MXIMPDataSubscriptionState::ESubscriptionInactive ); |
|
519 |
|
520 status->SetResultCode( aReason ); |
|
521 publishHost.SetOwnPresenceDataSubscriptionStateL( state, status ); |
|
522 CleanupStack::Pop( 2 ); // status, state |
|
523 |
|
524 DP_SDA("CPresencePluginPublisher::WatcherTerminatedL - end"); |
|
525 } |
|
526 |
|
527 // --------------------------------------------------------------------------- |
|
528 // CPresencePluginPublisher::CompleteXIMPReq() |
|
529 // --------------------------------------------------------------------------- |
|
530 // |
|
531 void CPresencePluginPublisher::CompleteXIMPReq( TInt aStatus ) |
|
532 { |
|
533 DP_SDA("CPresencePluginPublisher::CompleteXIMPReq"); |
|
534 DP_SDA2("CompleteXIMPReq: iOperation = %d",(TInt) iOperation ); |
|
535 // Notice: should this yield active scheduler??? |
|
536 if ( iOperation != ENoOperation ) |
|
537 { |
|
538 DP_SDA("CPresencePluginPublisher::CompleteXIMPReq complete"); |
|
539 iOperation = ENoOperation; |
|
540 iConnObs.CompleteReq( iXIMPId, aStatus ); |
|
541 iXIMPId = TXIMPRequestId(); |
|
542 } |
|
543 DP_SDA("CPresencePluginPublisher::CompleteXIMPReq end"); |
|
544 } |
|
545 |
|
546 // --------------------------------------------------------------------------- |
|
547 // CPresencePluginPublisher::CompleteClientReq() |
|
548 // --------------------------------------------------------------------------- |
|
549 // |
|
550 void CPresencePluginPublisher::CompleteClientReq( TInt aStatus ) |
|
551 { |
|
552 DP_SDA2("CPresencePluginPublisher::CompleteClientReq status %d ", aStatus); |
|
553 iOperation = ENoOperation; |
|
554 TRequestStatus* s = iClientStatus; |
|
555 User::RequestComplete( s, aStatus ); |
|
556 DP_SDA("CPresencePluginPublisher::CompleteClientReq end"); |
|
557 } |
|
558 |
|
559 // --------------------------------------------------------------------------- |
|
560 // CPresencePluginPublisher::DoCancel() |
|
561 // --------------------------------------------------------------------------- |
|
562 // |
|
563 void CPresencePluginPublisher::DoCancel( ) |
|
564 { |
|
565 DP_SDA("CPresencePluginPublisher::DoCancel CANCEL"); |
|
566 iXdmUtils->Cancel(); |
|
567 iPublisher->Close(); |
|
568 } |
|
569 |
|
570 // --------------------------------------------------------------------------- |
|
571 // CPresencePluginPublisher::RunL() |
|
572 // --------------------------------------------------------------------------- |
|
573 // |
|
574 void CPresencePluginPublisher::RunL( ) |
|
575 { |
|
576 DP_SDA("CPresencePluginPublisher::RunL"); |
|
577 TInt status = iStatus.Int(); |
|
578 DP_SDA2("CPresencePluginPublisher::RunL status %d", status ); |
|
579 if ( !status ) |
|
580 { |
|
581 |
|
582 if ( iOperation == ESubscribeOwn ) |
|
583 { |
|
584 DP_SDA("CPresencePluginPublisher::RunL Subscribe Own"); |
|
585 iSimpleId = iWatcher->SubscribeL( |
|
586 iConnObs.CurrentSipPresentity8(), |
|
587 NULL, // aFilter <-> aPif |
|
588 ETrue, EFalse ); |
|
589 } |
|
590 else if( iOperation == EPublishOwn ) |
|
591 { |
|
592 DP_SDA("CPresencePluginPublisher::RunL MakePublishReqL"); |
|
593 MakePublishReqL(); |
|
594 } |
|
595 } |
|
596 else |
|
597 { |
|
598 DP_SDA("CPresencePluginPublisher::RunL complete"); |
|
599 CompleteXIMPReq( status ); |
|
600 } |
|
601 } |
|
602 |
|
603 // --------------------------------------------------------------------------- |
|
604 // CPresencePluginPublisher::RunError |
|
605 // --------------------------------------------------------------------------- |
|
606 // |
|
607 TInt CPresencePluginPublisher::RunError( TInt aError ) |
|
608 { |
|
609 DP_SDA2("CPresencePluginPublisher::RunError %d",aError ); |
|
610 |
|
611 CompleteXIMPReq( aError ); |
|
612 return KErrNone; |
|
613 } |
|
614 |
|
615 // --------------------------------------------------------------------------- |
|
616 // CPresencePluginPublisher::GetInterface() |
|
617 // --------------------------------------------------------------------------- |
|
618 // |
|
619 TAny* CPresencePluginPublisher::GetInterface( |
|
620 TInt32 aInterfaceId, |
|
621 TIfGetOps aOptions ) |
|
622 { |
|
623 DP_SDA("CPresencePluginPublisher::GetInterface"); |
|
624 |
|
625 if ( aInterfaceId == GetInterfaceId() ) |
|
626 { |
|
627 // caller wants this interface |
|
628 MProtocolPresencePublishing* myIf = this; |
|
629 return myIf; |
|
630 } |
|
631 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
632 { |
|
633 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
634 } |
|
635 return NULL; |
|
636 } |
|
637 |
|
638 // --------------------------------------------------------------------------- |
|
639 // CPresencePluginPublisher::GetInterface() |
|
640 // --------------------------------------------------------------------------- |
|
641 // |
|
642 const TAny* CPresencePluginPublisher::GetInterface( |
|
643 TInt32 aInterfaceId, |
|
644 TIfGetOps aOptions ) const |
|
645 { |
|
646 DP_SDA("CPresencePluginPublisher::GetInterface 2 "); |
|
647 |
|
648 if ( aInterfaceId == GetInterfaceId() ) |
|
649 { |
|
650 // caller wants this interface |
|
651 const MProtocolPresencePublishing* myIf = this; |
|
652 return myIf; |
|
653 } |
|
654 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
655 { |
|
656 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
657 } |
|
658 return NULL; |
|
659 } |
|
660 |
|
661 // --------------------------------------------------------------------------- |
|
662 // CPresencePluginPublisher::GetInterfaceId() |
|
663 // --------------------------------------------------------------------------- |
|
664 // |
|
665 TInt32 CPresencePluginPublisher::GetInterfaceId() const |
|
666 { |
|
667 DP_SDA("CPresencePluginPublisher::GetInterfaceId"); |
|
668 |
|
669 return MProtocolPresencePublishing::KInterfaceId; |
|
670 } |
|
671 |
|
672 // --------------------------------------------------------------------------- |
|
673 // CPresencePluginPublisher::InitializeSimpleDocumentL() |
|
674 // --------------------------------------------------------------------------- |
|
675 // |
|
676 void CPresencePluginPublisher::InitializeSimpleDocumentL( ) |
|
677 { |
|
678 _LIT8 ( KCipidNS, "urn:ietf:params:xml:ns:pidf:cipid" ); |
|
679 _LIT8 ( KCipidCP, "c" ); |
|
680 if ( iDocument ) |
|
681 { |
|
682 DP_SDA("CPresencePluginPublisher:: deletedocument"); |
|
683 iDocument->Close(); |
|
684 iDocument = NULL; |
|
685 iDocument = TSimpleFactory::NewDocumentL(); |
|
686 } |
|
687 else |
|
688 { |
|
689 DP_SDA("CPresencePluginPublisher:: create document"); |
|
690 iDocument = TSimpleFactory::NewDocumentL(); |
|
691 } |
|
692 iDocument->AddNamespaceL( KSimplePDM, KSimpleNsPDM ); |
|
693 iDocument->AddNamespaceL( KSimpleRPID, KSimpleNsRPID ); |
|
694 iDocument->AddNamespaceL( KCipidCP, KCipidNS ); |
|
695 } |
|
696 |
|
697 // --------------------------------------------------------------------------- |
|
698 // CPresencePluginPublisher::AddSimpleDocumentPersL() |
|
699 // --------------------------------------------------------------------------- |
|
700 // |
|
701 void CPresencePluginPublisher::AddSimpleDocumentPersL( |
|
702 const MPersonPresenceInfo* aInfo ) |
|
703 { |
|
704 TInt tupleId = iConnObs.GetTupleId(); |
|
705 |
|
706 DP_SDA2("AddSimpleDocumentPersL tuple id get: %d", tupleId); |
|
707 if ( tupleId == 0 ) |
|
708 { |
|
709 DP_SDA("AddSimpleDocumentPersL tuple generate"); |
|
710 tupleId = iPresenceData->GenerateTupleId(); |
|
711 iConnObs.SetTupleId(tupleId); |
|
712 } |
|
713 |
|
714 iPresenceData->AddPrPersToSimpleDocumentL( |
|
715 aInfo, *iDocument, iConnObs.CurrentSipPresentity8(), tupleId ); |
|
716 } |
|
717 |
|
718 // --------------------------------------------------------------------------- |
|
719 // CPresencePluginPublisher::StopPublishL() |
|
720 // --------------------------------------------------------------------------- |
|
721 // |
|
722 void CPresencePluginPublisher::StopPublishL( TRequestStatus& aStatus ) |
|
723 { |
|
724 DP_SDA2("StopPublish - begin : iPublished= %d ",(TInt) iPublished); |
|
725 |
|
726 aStatus = KRequestPending; |
|
727 iClientStatus = &aStatus; |
|
728 |
|
729 if ( iConnObs.GetStopPublishState() && iPublished ) |
|
730 { |
|
731 DP_SDA("CPresencePluginPublisher::StopPublish really Stop"); |
|
732 TRAPD( error, iPublisher->StopPublishL( iConnObs.GetETag() );); |
|
733 DP_SDA2("StopPublish iPublisher->StopPublishL : error = %d ", error ); |
|
734 if ( KErrNone != error ) |
|
735 { |
|
736 if( iPublisher ) |
|
737 { |
|
738 DP_SDA("StopPublish delete and recreate publisher"); |
|
739 iPublisher->Close(); |
|
740 iPublisher = NULL; |
|
741 DP_SDA("StopPublish really Stop try again 1 "); |
|
742 iPublisher = |
|
743 TSimpleFactory::NewPublisherL( iConnection, *this ); |
|
744 DP_SDA("StopPublish really Stop try again 2 "); |
|
745 error = KErrGeneral; |
|
746 TRAP( error, iPublisher->StopPublishL( iConnObs.GetETag() );); |
|
747 DP_SDA2("StopPublishL 2nd try : error = %d ", error ); |
|
748 if ( KErrNone != error ) |
|
749 { |
|
750 DP_SDA("StopPublish TWO TIME Error, last try without tag "); |
|
751 TRAP( error, iPublisher->StopPublishL(); ); |
|
752 DP_SDA2("StopPublishL 3rd try : error = %d ", error ); |
|
753 } |
|
754 } |
|
755 } |
|
756 iConnObs.SetStopPublishState( ETrue ); |
|
757 iPublished = EFalse; |
|
758 } |
|
759 DP_SDA("CPresencePluginPublisher::StopPublish- end"); |
|
760 } |
|
761 |
|
762 // --------------------------------------------------------------------------- |
|
763 // CPresencePluginPublisher::MakePublishReqL() |
|
764 // --------------------------------------------------------------------------- |
|
765 // |
|
766 void CPresencePluginPublisher::MakePublishReqL( ) |
|
767 { |
|
768 DP_SDA("CPresencePluginPublisher::MakePublishReqL"); |
|
769 |
|
770 if ( !iPublished ) |
|
771 { |
|
772 DP_SDA("CPresencePluginPublisher::MakePublishReqL 1"); |
|
773 CreatePublisherL(); |
|
774 |
|
775 DP_SDA(" -> MakePublishReqL, check for old doc id"); |
|
776 HBufC8* oldDocumentId = HBufC8::NewLC( KBufSize255 ); |
|
777 TPtr8 oldDocumentIdPtr( oldDocumentId->Des() ); |
|
778 TRAPD( error, iPresenceData->ReadDocumentIdL( |
|
779 iConnObs.ServiceId(), oldDocumentIdPtr ) ); |
|
780 DP_SDA2(" -> MakePublishReqL, doc id error: %d", error ); |
|
781 if ( !error ) |
|
782 { |
|
783 DP_SDA(" -> MakePublishReqL, publish with old id"); |
|
784 iSimpleId = iPublisher->ContinuePublishL( |
|
785 *iDocument, ETrue, oldDocumentIdPtr ); |
|
786 } |
|
787 else |
|
788 { |
|
789 DP_SDA(" -> MakePublishReqL, publish with new id"); |
|
790 iSimpleId = iPublisher->StartPublishL( *iDocument, ETrue ); |
|
791 } |
|
792 CleanupStack::PopAndDestroy( oldDocumentId ); |
|
793 } |
|
794 else |
|
795 { |
|
796 DP_SDA("CPresencePluginPublisher::MakePublishReqL 2"); |
|
797 CreatePublisherL(); |
|
798 DP_SDA("CPresencePluginPublisher::MakePublishReqL Continue Publish"); |
|
799 iSimpleId = |
|
800 iPublisher->ContinuePublishL( |
|
801 *iDocument ,ETrue, iConnObs.GetETag() ); |
|
802 DP_SDA("CPresencePluginPublisher::MakePublishReqL modifyed"); |
|
803 } |
|
804 |
|
805 DP_SDA("CPresencePluginPublisher::MakePublishReqL end"); |
|
806 } |
|
807 |
|
808 // --------------------------------------------------------------------------- |
|
809 // CPresencePluginPublisher::StartXdmOperationL |
|
810 // --------------------------------------------------------------------------- |
|
811 // |
|
812 void CPresencePluginPublisher::StartXdmOperationL( |
|
813 TXIMPRequestId aReqId ) |
|
814 { |
|
815 DP_SDA("CPresencePluginPublisher::StartXdmOperationL"); |
|
816 __ASSERT_DEBUG( !IsActive(), User::Leave( KErrNotReady ) ); |
|
817 iXIMPId = aReqId; |
|
818 if ( !iXdmUtils ) |
|
819 { |
|
820 DP_SDA("StartXdmOperationL Initialize XDMUtils"); |
|
821 iXdmUtils = iConnObs.XdmUtilsL(); |
|
822 } |
|
823 |
|
824 // Allways check those XDM files are ok / |
|
825 //publish seems to be jam if xdm not initialized ? |
|
826 iXdmUtils->InitializeXdmL( iStatus ); |
|
827 SetActive(); |
|
828 DP_SDA("CPresencePluginPublisher::StartXdmOperationL end"); |
|
829 } |
|
830 |
|
831 // --------------------------------------------------------------------------- |
|
832 // CPresencePluginPublisher::WinfoNotificationL() |
|
833 // --------------------------------------------------------------------------- |
|
834 // |
|
835 void CPresencePluginPublisher::WinfoNotificationL( |
|
836 MSimpleWinfo& aWinfo ) |
|
837 { |
|
838 DP_SDA("CPresencePluginPublisher::WinfoNotificationL"); |
|
839 |
|
840 RPointerArray<MSimpleElement> elems; |
|
841 CleanupClosePushL( elems ); // << elems |
|
842 TInt err = aWinfo.SimpleElementsL( elems ); |
|
843 User::LeaveIfError( err ); |
|
844 TInt count = elems.Count(); |
|
845 |
|
846 DP_SDA2("WinfoNotificationL elems count%d", count); |
|
847 |
|
848 __ASSERT_ALWAYS( count == 1, User::Leave( KErrCorrupt ) ); |
|
849 |
|
850 using namespace NPresencePlugin::NPresence; |
|
851 |
|
852 const TDesC8* stateVal = aWinfo.AttrValue( KPresenceState8 ); |
|
853 |
|
854 if ( stateVal && !stateVal->CompareF( KPresenceFull8 )) //state full |
|
855 { |
|
856 // full winfo-list is received (New empty list ) |
|
857 DP_SDA("CPresencePluginPublisher::WinfoNotificationL full list found"); |
|
858 DeleteWatchers(); |
|
859 } |
|
860 else |
|
861 { |
|
862 DP_SDA("PluginPublisher: state != full"); |
|
863 // Test if state is partitial |
|
864 if ( stateVal && !stateVal->CompareF( KPresencePartial8 )) |
|
865 { |
|
866 DP_SDA("PluginPublisher: state = partitial"); |
|
867 } |
|
868 } |
|
869 |
|
870 MSimpleElement* elem = elems[0]; |
|
871 TPtrC8 p8 = elem->LocalName(); |
|
872 err = p8.CompareF( KPresenceWatcherList8 ); |
|
873 DP_SDA2("WinfoNotificationL KPresenceWatcherList8 err %d", err); |
|
874 User::LeaveIfError( err ); |
|
875 DP_SDA("WinfoNotificationL KPresenceWatcherList8 continue"); |
|
876 |
|
877 //Get elemets from document |
|
878 err = elem->SimpleElementsL( elems ); |
|
879 User::LeaveIfError( err ); |
|
880 DP_SDA2("WinfoNotificationL get elems err %d", err); |
|
881 //Make collect from active watchers |
|
882 CollectWatchersL( elems ); |
|
883 |
|
884 CDesCArrayFlat* watchers = MakeCurrentWatcherListLC();// << watchers |
|
885 MXIMPObjectCollection *actives = |
|
886 iConnObs.ObjectFactory().NewObjectCollectionLC();// << actives |
|
887 |
|
888 // Create MXIMPPresenceWatcherInfo entities for |
|
889 // all active watchers and add to actives. |
|
890 TInt wCount = watchers->MdcaCount(); |
|
891 DP_SDA2("CPresencePluginPublisher::WinfoNotificationL wCount %d", wCount); |
|
892 for ( TInt j = 0; j < wCount; j++ ) |
|
893 { |
|
894 // create MXIMPPresenceWatcherInfo object |
|
895 MPresenceWatcherInfo* wInfo = |
|
896 iConnObs.PresenceObjectFactoryOwn(). |
|
897 NewPresenceWatcherInfoLC();// << wInfo |
|
898 |
|
899 MXIMPIdentity* identity = |
|
900 iConnObs.ObjectFactory().NewIdentityLC();// << identity |
|
901 |
|
902 identity->SetIdentityL( watchers->MdcaPoint( j ) ); |
|
903 wInfo->SetWatcherIdL( identity ); |
|
904 CleanupStack::Pop( );// >> identity |
|
905 |
|
906 wInfo->SetWatcherDisplayNameL( watchers->MdcaPoint( j ) ); |
|
907 wInfo->SetWatcherTypeL( MPresenceWatcherInfo::EPresenceSubscriber ); |
|
908 |
|
909 actives->AddObjectL( wInfo ); |
|
910 CleanupStack::Pop( ); // >> wInfo |
|
911 } |
|
912 |
|
913 MProtocolPresencePublishingDataHost& publishHost = |
|
914 iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost(); |
|
915 |
|
916 publishHost.HandlePresenceWatcherListL( actives ); |
|
917 |
|
918 CleanupStack::Pop(); // >> actives |
|
919 CleanupStack::PopAndDestroy( watchers ); // >> watchers |
|
920 |
|
921 CleanupStack::PopAndDestroy( &elems ); // >> elems |
|
922 DP_SDA("CPresencePluginPublisher::WinfoNotificationL end"); |
|
923 } |
|
924 |
|
925 // --------------------------------------------------------------------------- |
|
926 // CPresencePluginPublisher::WinfoTerminatedL() |
|
927 // --------------------------------------------------------------------------- |
|
928 // |
|
929 void CPresencePluginPublisher::WinfoTerminatedL( TInt aReason ) |
|
930 { |
|
931 DP_SDA("CPresencePluginPublisher::WinfoTerminatedL - begin"); |
|
932 |
|
933 // call SetPresenceWatcherListDataSubscriptionStateL |
|
934 iSubscribed = EFalse; |
|
935 |
|
936 MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory(); |
|
937 MProtocolPresencePublishingDataHost& publishHost = |
|
938 iConnObs.Host()->ProtocolPresenceDataHost().PublishingDataHost(); |
|
939 MXIMPDataSubscriptionState *state = |
|
940 myFactory.NewDataSubscriptionStateLC(); |
|
941 |
|
942 MXIMPStatus* status = myFactory.NewStatusLC(); |
|
943 state->SetSubscriptionStateL( |
|
944 MXIMPDataSubscriptionState::ESubscriptionInactive ); |
|
945 |
|
946 state->SetDataStateL( MXIMPDataSubscriptionState::EDataUnavailable ); |
|
947 status->SetResultCode( aReason ); |
|
948 publishHost.SetPresenceWatcherListDataSubscriptionStateL( state, status ); |
|
949 CleanupStack::Pop( 2 ); // status, state |
|
950 DP_SDA("CPresencePluginPublisher::WinfoTerminatedL - end"); |
|
951 } |
|
952 |
|
953 // --------------------------------------------------------------------------- |
|
954 // CPresencePluginPublisher::NewETagL() |
|
955 // --------------------------------------------------------------------------- |
|
956 // |
|
957 void CPresencePluginPublisher::NewETagL( const TDesC8& aVal ) |
|
958 { |
|
959 DP_SDA("CPresencePluginPublisher::NewETagL"); |
|
960 // Set ETag value |
|
961 DP_SDA("CPresencePluginPublisher::NewETagL Set ETag"); |
|
962 TBuf8<KBufSize255> buf; |
|
963 buf.Copy( aVal ); |
|
964 iConnObs.SetETag( buf ); |
|
965 buf.Zero(); |
|
966 } |
|
967 |
|
968 // --------------------------------------------------------------------------- |
|
969 // CPresencePluginPublisher::MakeCurrentWatcherListLC |
|
970 // --------------------------------------------------------------------------- |
|
971 // |
|
972 CDesCArrayFlat* CPresencePluginPublisher::MakeCurrentWatcherListLC() |
|
973 { |
|
974 DP_SDA("CPresencePluginPublisher::MakeCurrentWatcherListLC - begin"); |
|
975 // No one should be added more than once |
|
976 const TInt KMyGran = 10; |
|
977 CDesCArrayFlat* watchers = new (ELeave) CDesCArrayFlat( KMyGran ); |
|
978 CleanupStack::PushL( watchers ); // << watchers |
|
979 |
|
980 // add user only once here. |
|
981 TDblQueIter<CPresencePluginWatcherInfo> rIter( iWatcherList ); |
|
982 rIter.SetToFirst(); |
|
983 |
|
984 while ( rIter ) |
|
985 { |
|
986 CPresencePluginWatcherInfo* w = rIter; |
|
987 rIter++; |
|
988 |
|
989 TInt dummy = 0; |
|
990 // Zero -> Found |
|
991 if ( watchers->Find( w->SipId(), dummy )) |
|
992 { |
|
993 watchers->AppendL( w->SipId() ); |
|
994 } |
|
995 } |
|
996 |
|
997 DP_SDA("CPresencePluginPublisher::MakeCurrentWatcherListLC - end"); |
|
998 return watchers; |
|
999 } |
|
1000 |
|
1001 // --------------------------------------------------------------------------- |
|
1002 // CPresencePluginPublisher::CollectWatchers |
|
1003 // --------------------------------------------------------------------------- |
|
1004 // |
|
1005 void CPresencePluginPublisher::CollectWatchersL( |
|
1006 RPointerArray<MSimpleElement>& aElems ) |
|
1007 { |
|
1008 using namespace NPresencePlugin::NPresence; |
|
1009 HBufC* nodeContent = NULL; |
|
1010 |
|
1011 TInt count = aElems.Count(); |
|
1012 DP_SDA2("CPresencePluginPublisher::CollectWatchers elem count %d",count); |
|
1013 |
|
1014 for ( TInt i = 0; i < count; i++ ) |
|
1015 { |
|
1016 MSimpleElement* elem = aElems[i]; |
|
1017 TPtrC8 p8( elem->LocalName()); |
|
1018 |
|
1019 if (!( p8.CompareF( KPresenceWatcher8 ))) |
|
1020 { |
|
1021 DP_SDA("CPresencePluginPublisher::CollectWatchers watchers found"); |
|
1022 const TDesC8* pp8 = elem->AttrValue( KPresenceStatus8 ); |
|
1023 // Active wathers here |
|
1024 if ( pp8 && !pp8->CompareF( KPresenceActive8 )) |
|
1025 { |
|
1026 DP_SDA("CollectWatchers: ACTIVE found"); |
|
1027 // save id since there may be multiple subscriptions |
|
1028 // from a single watcher SIP identity. |
|
1029 const TDesC8* pId8 = elem->AttrValue( KPresenceId8 ); |
|
1030 |
|
1031 // Build collection of grant requests |
|
1032 // Find the child node containing the SIP entity |
|
1033 nodeContent = elem->ContentUnicodeL(); |
|
1034 CleanupStack::PushL( nodeContent );// << nodeContent |
|
1035 |
|
1036 AddWatcherIfNotExistsL( |
|
1037 pId8 ? *pId8 : KNullDesC8, nodeContent->Des() ); |
|
1038 |
|
1039 CleanupStack::PopAndDestroy( nodeContent ); //>> nodeContent |
|
1040 } |
|
1041 // Terminated wathers here |
|
1042 else if ( pp8 && !pp8->CompareF( KPresenceTerminated8 )) |
|
1043 { |
|
1044 DP_SDA("CollectWatchers: Terminated"); |
|
1045 const TDesC8* pId8 = elem->AttrValue( KPresenceId8 ); |
|
1046 |
|
1047 // Remove terminated from iWatcherList |
|
1048 nodeContent = elem->ContentUnicodeL(); |
|
1049 CleanupStack::PushL( nodeContent );// << nodeContent |
|
1050 |
|
1051 RemoveWatcherIfExists( |
|
1052 pId8 ? *pId8 : KNullDesC8, nodeContent->Des() ); |
|
1053 |
|
1054 CleanupStack::PopAndDestroy( nodeContent );// >> nodeContent |
|
1055 } |
|
1056 } |
|
1057 } |
|
1058 } |
|
1059 |
|
1060 // --------------------------------------------------------------------------- |
|
1061 // CPresencePluginPublisher::CreatePublisherL() |
|
1062 // --------------------------------------------------------------------------- |
|
1063 // |
|
1064 void CPresencePluginPublisher::CreatePublisherL() |
|
1065 { |
|
1066 DP_SDA("CPresencePluginPublisher::CreatePublisherL"); |
|
1067 if( iPublisher ) |
|
1068 { |
|
1069 DP_SDA("CPresencePluginPublisher::CreatePublisherL create"); |
|
1070 iPublisher->Close(); |
|
1071 iPublisher = NULL; |
|
1072 iPublisher = TSimpleFactory::NewPublisherL( iConnection, *this ); |
|
1073 } |
|
1074 DP_SDA("CPresencePluginPublisher::CreatePublisherL end"); |
|
1075 } |
|
1076 |
|
1077 // --------------------------------------------------------------------------- |
|
1078 // CPresencePluginPublisher::StoreOwnStatusToCacheL |
|
1079 // --------------------------------------------------------------------------- |
|
1080 // |
|
1081 void CPresencePluginPublisher::StoreOwnStatusToCacheL() |
|
1082 { |
|
1083 DP_SDA("CPresencePluginPublisher::StoreOwnStatusToCacheL" ); |
|
1084 |
|
1085 using namespace NPresencePlugin::NPresence; |
|
1086 using namespace NPresencePlugin::NPresenceStates; |
|
1087 using namespace NPresenceInfo::NFieldType; |
|
1088 |
|
1089 DP_SDA(" CPresencePluginPublisher -> convert uri" ); |
|
1090 HBufC* entityUri = |
|
1091 CnvUtfConverter::ConvertToUnicodeFromUtf8L( |
|
1092 *iDocument->EntityURI() ); |
|
1093 CleanupStack::PushL( entityUri ); |
|
1094 |
|
1095 DP_SDA(" CPresencePluginPublisher -> strip prefix" ); |
|
1096 HBufC16* prefixStripped = iPresenceData->RemovePrefixLC( |
|
1097 *entityUri ); |
|
1098 |
|
1099 DP_SDA(" CPresencePluginPublisher -> fetch simple elements" ); |
|
1100 RPointerArray<MSimpleElement> simpleElements; |
|
1101 CleanupClosePushL( simpleElements ); |
|
1102 DP_SDA(" CPresencePluginPublisher -> do fetch simple elements" ); |
|
1103 TInt error = iDocument->SimpleElementsL( simpleElements ); |
|
1104 DP_SDA2(" CPresencePluginPublisher -> fetch error: %d", error ); |
|
1105 User::LeaveIfError( error ); |
|
1106 TBool handled = EFalse; |
|
1107 DP_SDA2(" CPresencePluginPublisher -> element count: %d", |
|
1108 simpleElements.Count() ); |
|
1109 |
|
1110 MSimpleElement* basicSimpleElem(NULL); |
|
1111 MSimpleElement* noteSimpleElem(NULL); |
|
1112 |
|
1113 TBuf<KBufSize100> activitiesContentBuf; |
|
1114 TBool activitiesHandled( EFalse ); |
|
1115 |
|
1116 for( TInt index = 0 ; index < simpleElements.Count() ; index++ ) |
|
1117 { |
|
1118 DP_SDA(" CPresencePluginPublisher -> check for person element" ); |
|
1119 // Check for person element |
|
1120 if (!( simpleElements[index]->LocalName().CompareF( KPresencePerson8 )) || |
|
1121 !( simpleElements[index]->LocalName().CompareF( KPresenceTuple8 )) ) |
|
1122 { |
|
1123 DP_SDA(" CPresencePluginPublisher -> person/tuple element found" ); |
|
1124 RPointerArray<MSimpleElement> personSubElems; |
|
1125 CleanupClosePushL( personSubElems ); |
|
1126 simpleElements[index]->SimpleElementsL( personSubElems ); |
|
1127 DP_SDA2(" CPresencePluginPublisher -> person/tuple sub elemen count: %d", |
|
1128 personSubElems.Count() ); |
|
1129 |
|
1130 for ( TInt j = 0; j < personSubElems.Count(); j++ ) |
|
1131 { |
|
1132 DP_SDA(" CPresencePluginPublisher -> check for status/activities element"); |
|
1133 if ( !personSubElems[j]->LocalName().CompareF( KPresenceStatus8 ) || |
|
1134 !personSubElems[j]->LocalName().CompareF( KPresenceActivities8 )) |
|
1135 { |
|
1136 DP_SDA(" CPresencePluginPublisher -> status/activities element found"); |
|
1137 //Get childs |
|
1138 RPointerArray<MSimpleElement> basicElems; |
|
1139 CleanupClosePushL( basicElems ); |
|
1140 |
|
1141 personSubElems[j]->SimpleElementsL( basicElems ); |
|
1142 DP_SDA2(" CPresencePluginPublisher -> child elem count: %d", |
|
1143 basicElems.Count() ); |
|
1144 for ( TInt k = 0; k < basicElems.Count(); k++ ) |
|
1145 { |
|
1146 DP_SDA(" CPresencePluginPublisher -> check child elems"); |
|
1147 if ( !basicElems[k]->LocalName().CompareF( |
|
1148 KPresenceBasic8 )) |
|
1149 { |
|
1150 DP_SDA(" -> basic element found"); |
|
1151 basicSimpleElem = basicElems[k]; |
|
1152 } |
|
1153 else if ( basicSimpleElem && |
|
1154 !basicElems[k]->LocalName().CompareF( KPresenceActivities8 ) ) |
|
1155 { |
|
1156 DP_SDA(" -> activities found from basic elem"); |
|
1157 RPointerArray<MSimpleElement> activitiesElems; |
|
1158 CleanupClosePushL( activitiesElems ); |
|
1159 |
|
1160 DP_SDA(" -> get activities"); |
|
1161 basicElems[k]->SimpleElementsL( activitiesElems ); |
|
1162 DP_SDA2(" -> activities count: %d", |
|
1163 activitiesElems.Count() ); |
|
1164 if ( activitiesElems.Count() ) |
|
1165 { |
|
1166 DP_SDA(" -> get activities, multiple, use last"); |
|
1167 TInt lastActiviesIndex = |
|
1168 ( activitiesElems.Count() - 1 ); |
|
1169 activitiesContentBuf.Copy( |
|
1170 activitiesElems[lastActiviesIndex]->LocalName() ); |
|
1171 activitiesHandled = ETrue; |
|
1172 DP_SDA(" -> activity elem ok"); |
|
1173 } |
|
1174 CleanupStack::PopAndDestroy( &activitiesElems ); |
|
1175 } |
|
1176 else if ( basicSimpleElem && |
|
1177 !personSubElems[j]->LocalName().CompareF( KPresenceActivities8 ) ) |
|
1178 { |
|
1179 DP_SDA(" -> activities found from person elem"); |
|
1180 RPointerArray<MSimpleElement> activitiesElems; |
|
1181 CleanupClosePushL( activitiesElems ); |
|
1182 |
|
1183 DP_SDA(" -> get activities"); |
|
1184 personSubElems[j]->SimpleElementsL( activitiesElems ); |
|
1185 DP_SDA2(" -> activities count: %d", |
|
1186 activitiesElems.Count() ); |
|
1187 if ( activitiesElems.Count() ) |
|
1188 { |
|
1189 DP_SDA(" -> get activities, multiple, use last"); |
|
1190 TInt lastActiviesIndex = |
|
1191 ( activitiesElems.Count() - 1 ); |
|
1192 activitiesContentBuf.Copy( |
|
1193 activitiesElems[lastActiviesIndex]->LocalName() ); |
|
1194 activitiesHandled = ETrue; |
|
1195 DP_SDA2(" -> activities len: %d", |
|
1196 activitiesContentBuf.Length() ); |
|
1197 DP_SDA(" -> activity elem ok"); |
|
1198 } |
|
1199 CleanupStack::PopAndDestroy( &activitiesElems ); |
|
1200 } |
|
1201 } |
|
1202 CleanupStack::PopAndDestroy( &basicElems ); |
|
1203 } |
|
1204 } |
|
1205 CleanupStack::PopAndDestroy( &personSubElems ); |
|
1206 } |
|
1207 else if ( !simpleElements[index]->LocalName().CompareF( KPresenceNote8 )) |
|
1208 { |
|
1209 DP_SDA(" CPresencePluginPublisher -> note element found" ); |
|
1210 noteSimpleElem = simpleElements[index]; |
|
1211 } |
|
1212 } |
|
1213 DP_SDA(" CPresencePluginPublisher -> elements handled"); |
|
1214 __ASSERT_ALWAYS( basicSimpleElem, User::Leave( KErrCorrupt ) ); |
|
1215 |
|
1216 if ( !activitiesHandled ) |
|
1217 { |
|
1218 DP_SDA(" -> activities not handled, set unknown"); |
|
1219 activitiesContentBuf.Copy( KPresenceUnknow ); |
|
1220 } |
|
1221 |
|
1222 HBufC* nodeContent = basicSimpleElem->ContentUnicodeL(); |
|
1223 CleanupStack::PushL( nodeContent ); |
|
1224 |
|
1225 HBufC* noteContent = NULL; |
|
1226 if ( noteSimpleElem ) |
|
1227 { |
|
1228 noteContent = noteSimpleElem->ContentUnicodeL(); |
|
1229 CleanupStack::PushL( noteContent ); |
|
1230 } |
|
1231 else |
|
1232 { |
|
1233 noteContent = KNullDesC().AllocLC(); |
|
1234 } |
|
1235 |
|
1236 MPresenceBuddyInfo2::TAvailabilityValues cacheAvailability = |
|
1237 MPresenceBuddyInfo2::ENotAvailable; |
|
1238 NPresenceInfo::TAvailabilityValues ximpAvailability = |
|
1239 NPresenceInfo::ENotAvailable; |
|
1240 |
|
1241 HBufC* extendedCacheAvailability = HBufC::NewLC( KBufSize255 ); |
|
1242 TPtr extendedCacheAvailabilityPtr( extendedCacheAvailability->Des() ); |
|
1243 if ( nodeContent ) |
|
1244 { |
|
1245 handled = ResolveOwnCacheValues( *nodeContent, |
|
1246 activitiesContentBuf, cacheAvailability, |
|
1247 extendedCacheAvailabilityPtr, ximpAvailability ); |
|
1248 } |
|
1249 |
|
1250 __ASSERT_ALWAYS( handled, User::Leave( KErrCorrupt )); |
|
1251 |
|
1252 DP_SDA(" CPresencePluginPublisher -> write to cache" ); |
|
1253 |
|
1254 DP_SDA2(" CPresencePluginPublisher -> availability: %d", |
|
1255 cacheAvailability ); |
|
1256 DP_SDA2(" CPresencePluginPublisher -> ext availability len: %d", |
|
1257 extendedCacheAvailabilityPtr.Length() ); |
|
1258 |
|
1259 iPresenceData->WriteStatusToCacheL( |
|
1260 *prefixStripped, cacheAvailability, |
|
1261 extendedCacheAvailabilityPtr, *noteContent ); |
|
1262 |
|
1263 // Store publish variables for republish |
|
1264 iPresenceData->StorePresenceOwnPresenceL( |
|
1265 iConnObs.ServiceId(), ximpAvailability, *noteContent ); |
|
1266 |
|
1267 CleanupStack::PopAndDestroy( extendedCacheAvailability ); |
|
1268 CleanupStack::PopAndDestroy( noteContent ); |
|
1269 CleanupStack::PopAndDestroy( nodeContent ); |
|
1270 |
|
1271 DP_SDA(" CPresencePluginPublisher -> attributes handled" ); |
|
1272 CleanupStack::PopAndDestroy( &simpleElements ); |
|
1273 |
|
1274 DP_SDA(" CPresencePluginPublisher -> write to cache ok, cleanup" ); |
|
1275 |
|
1276 // prefixStripped, entityUri |
|
1277 CleanupStack::PopAndDestroy( 2 ); |
|
1278 DP_SDA("CPresencePluginPublisher::StoreOwnStatusToCacheL out" ); |
|
1279 } |
|
1280 |
|
1281 // --------------------------------------------------------------------------- |
|
1282 // CPresencePluginPublisher::ResolveOwnCacheValues |
|
1283 // --------------------------------------------------------------------------- |
|
1284 // |
|
1285 TBool CPresencePluginPublisher::ResolveOwnCacheValues( |
|
1286 const TDesC& aUnicodeContent, |
|
1287 const TDesC& aActivities, |
|
1288 MPresenceBuddyInfo2::TAvailabilityValues& aCacheAvailability, |
|
1289 TPtr& aExtendedCacheAvailability, |
|
1290 NPresenceInfo::TAvailabilityValues& aXimpApiAvailability ) |
|
1291 { |
|
1292 DP_SDA("CPresencePluginPublisher::ResolveOwnCacheValuesL" ); |
|
1293 using namespace NPresencePlugin::NPresence; |
|
1294 using namespace NPresencePlugin::NPresenceStates; |
|
1295 using namespace NPresenceInfo::NFieldType; |
|
1296 |
|
1297 TBool handled = EFalse; |
|
1298 if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1299 !aActivities.CompareF ( KPresenceBusy ) ) |
|
1300 { |
|
1301 DP_SDA(" CPresencePluginPublisher -> busy"); |
|
1302 aCacheAvailability = MPresenceBuddyInfo2::EBusy; |
|
1303 aExtendedCacheAvailability.Copy( KDndState() ); |
|
1304 aXimpApiAvailability = NPresenceInfo::EBusy; |
|
1305 handled = ETrue; |
|
1306 } |
|
1307 // On-The-Phone case |
|
1308 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1309 !aActivities.CompareF ( KPresenceOnThePhone ) ) |
|
1310 { |
|
1311 DP_SDA(" CPresencePluginPublisher -> on-the-phone"); |
|
1312 aCacheAvailability = MPresenceBuddyInfo2::EBusy; |
|
1313 aExtendedCacheAvailability.Copy( KOnPhoneState() ); |
|
1314 aXimpApiAvailability = NPresenceInfo::EOnPhone; |
|
1315 handled = ETrue; |
|
1316 } |
|
1317 //Away case |
|
1318 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1319 !aActivities.CompareF ( KPresenceAway ) ) |
|
1320 { |
|
1321 DP_SDA(" CPresencePluginPublisher -> away"); |
|
1322 aCacheAvailability = MPresenceBuddyInfo2::EBusy; |
|
1323 aExtendedCacheAvailability.Copy( KAwayState() ); |
|
1324 aXimpApiAvailability = NPresenceInfo::EAway; |
|
1325 handled = ETrue; |
|
1326 } |
|
1327 //Dnd case |
|
1328 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1329 !aActivities.CompareF ( KPresenceDoNotDisturb ) ) |
|
1330 { |
|
1331 DP_SDA(" CPresencePluginPublisher -> dnd"); |
|
1332 aCacheAvailability = MPresenceBuddyInfo2::EBusy; |
|
1333 aExtendedCacheAvailability.Copy( KDndState() ); |
|
1334 aXimpApiAvailability = NPresenceInfo::EDoNotDisturb; |
|
1335 handled = ETrue; |
|
1336 } |
|
1337 // Unknown open |
|
1338 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1339 !aActivities.CompareF ( KPresenceUnknow ) ) |
|
1340 { |
|
1341 DP_SDA(" CPresencePluginPublisher -> open"); |
|
1342 aCacheAvailability = MPresenceBuddyInfo2::EAvailable; |
|
1343 aExtendedCacheAvailability.Copy( KDefaultAvailableStatus() ); |
|
1344 aXimpApiAvailability = NPresenceInfo::EAvailable; |
|
1345 handled = ETrue; |
|
1346 } |
|
1347 // available open |
|
1348 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1349 !aActivities.CompareF ( KPresenceAvailable ) ) |
|
1350 { |
|
1351 DP_SDA(" CPresencePluginPublisher -> open"); |
|
1352 aCacheAvailability = MPresenceBuddyInfo2::EAvailable; |
|
1353 aExtendedCacheAvailability.Copy( KDefaultAvailableStatus() ); |
|
1354 aXimpApiAvailability = NPresenceInfo::EAvailable; |
|
1355 handled = ETrue; |
|
1356 } |
|
1357 // available open |
|
1358 else if ( !aUnicodeContent.CompareF( KPresenceOpen ) && |
|
1359 !aActivities.CompareF ( KPresenceOpen ) ) |
|
1360 { |
|
1361 DP_SDA(" CPresencePluginPublisher -> open/open"); |
|
1362 aCacheAvailability = MPresenceBuddyInfo2::EAvailable; |
|
1363 aExtendedCacheAvailability.Copy( KDefaultAvailableStatus() ); |
|
1364 aXimpApiAvailability = NPresenceInfo::EAvailable; |
|
1365 handled = ETrue; |
|
1366 } |
|
1367 //Unknown closed |
|
1368 else if ( !aUnicodeContent.CompareF( KPresenceClosed ) && |
|
1369 !aActivities.CompareF ( KPresenceUnknow ) ) |
|
1370 { |
|
1371 DP_SDA(" CPresencePluginPublisher -> closed"); |
|
1372 aCacheAvailability = MPresenceBuddyInfo2::ENotAvailable; |
|
1373 aExtendedCacheAvailability.Copy( KInvisibleState() ); |
|
1374 aXimpApiAvailability = NPresenceInfo::ENotAvailable; |
|
1375 handled = ETrue; |
|
1376 } |
|
1377 //All other states are closed |
|
1378 else |
|
1379 { |
|
1380 DP_SDA(" CPresencePluginPublisher -> else closed"); |
|
1381 aCacheAvailability = MPresenceBuddyInfo2::ENotAvailable; |
|
1382 aExtendedCacheAvailability.Copy( KInvisibleState() ); |
|
1383 aXimpApiAvailability = NPresenceInfo::ENotAvailable; |
|
1384 handled = ETrue; |
|
1385 } |
|
1386 DP_SDA2("CPresencePluginPublisher::ResolveOwnCacheValuesL out, ret: %d", |
|
1387 handled ); |
|
1388 return handled; |
|
1389 } |
|
1390 |
|
1391 // End of file |
|