simpledatamodeladapter/src/presenceplugingroup.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     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 <ximpdatasubscriptionstate.h>
       
    21 #include <protocolpresentitygroupsdatahost.h>
       
    22 #include <protocolpresencedatahost.h>
       
    23 #include <ximpobjectfactory.h>
       
    24 #include <presenceobjectfactory.h>
       
    25 #include <ximpstatus.h>
       
    26 #include <ximpidentity.h>
       
    27 #include <ximpobjectcollection.h>
       
    28 #include <XdmErrors.h>
       
    29 #include <presentitygroupinfo.h>
       
    30 #include <presentitygroupmemberinfo.h>
       
    31 #include <utf.h>
       
    32 #include <avabilitytext.h>
       
    33 
       
    34 #include "mpresencepluginconnectionobs.h"
       
    35 #include "presenceplugingroup.h"
       
    36 #include "presencepluginxdmutils.h"
       
    37 #include "presenceplugincommon.h"
       
    38 #include "presencepluginvirtualgroup.h"
       
    39 #include "presenceplugindata.h"
       
    40 #include "presencepluginwatcher.h"
       
    41 #include "presencepluginauthorization.h"
       
    42 #include "presencepluginutility.h"
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CPresencePluginGroups::CPresencePluginGroups
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CPresencePluginGroups::CPresencePluginGroups(
       
    51     MPresencePluginConnectionObs& aObs,
       
    52     CPresencePluginVirtualGroup* aSubscribedBuddies,
       
    53     CPresencePluginData* aPresenceData ):
       
    54   	CActive( CActive::EPriorityStandard ),
       
    55   	iConnObs(aObs),
       
    56   	iOperation( ENoOperation),
       
    57   	iState( EPluginIdle ), iCompleted( ETrue ),
       
    58   	iSubscribedBuddies( aSubscribedBuddies ),
       
    59   	iPresenceData( aPresenceData )
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62     }
       
    63     
       
    64 // ---------------------------------------------------------------------------
       
    65 // CPresencePluginGroups::NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CPresencePluginGroups* CPresencePluginGroups::NewL(
       
    69     MPresencePluginConnectionObs& aObs,
       
    70     CPresencePluginVirtualGroup* aSubscribedBuddies,
       
    71     CPresencePluginData* aPresenceData )
       
    72     {
       
    73     CPresencePluginGroups* self =
       
    74         CPresencePluginGroups::NewLC( 
       
    75              aObs,
       
    76              aSubscribedBuddies,
       
    77              aPresenceData );    
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CPresencePluginGroups::NewLC
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CPresencePluginGroups* CPresencePluginGroups::NewLC(
       
    87     MPresencePluginConnectionObs& aObs,
       
    88     CPresencePluginVirtualGroup* aSubscribedBuddies,
       
    89     CPresencePluginData* aPresenceData )
       
    90     {
       
    91     CPresencePluginGroups* self =
       
    92         new( ELeave ) CPresencePluginGroups( 
       
    93              aObs,
       
    94              aSubscribedBuddies,
       
    95              aPresenceData );
       
    96     CleanupStack::PushL( self );
       
    97     return self;
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // CPresencePluginGroups::~CPresencePluginGroups
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CPresencePluginGroups::~CPresencePluginGroups()
       
   105     {
       
   106     DP_SDA("CPresencePluginGroups::~CPresencePluginGroups");
       
   107     Cancel();
       
   108     delete iPresIdentity;
       
   109     delete iDisplayName;
       
   110     DP_SDA("CPresencePluginGroups::~CPresencePluginGroups end");
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CPresencePluginGroups::DoSubscribePresentityGroupListL
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CPresencePluginGroups::DoSubscribePresentityGroupListL(
       
   118     TXIMPRequestId aReqId )
       
   119     {
       
   120     DP_SDA("CPresencePluginGroups::DoSubscribePresentityGroupListL");
       
   121     iCompleted = EFalse;
       
   122     // List of lists under buddylist
       
   123     StartXdmOperationL( aReqId, EGetListOfLists );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CPresencePluginGroups::DoUnsubscribePresentityGroupListL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CPresencePluginGroups::DoUnsubscribePresentityGroupListL(
       
   131     TXIMPRequestId /*aReqId*/ )
       
   132     {
       
   133     User::Leave( KErrNotSupported );
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CPresencePluginGroups::DoCreatePresentityGroupL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CPresencePluginGroups::DoCreatePresentityGroupL(
       
   141     const MXIMPIdentity& /*aGroupId*/,
       
   142     const TDesC16& /*aDisplayName*/,
       
   143     TXIMPRequestId /*aReqId*/ )
       
   144     {
       
   145     User::Leave( KErrNotSupported );
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CPresencePluginGroups::DoDeletePresentityGroupL
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CPresencePluginGroups::DoDeletePresentityGroupL(
       
   153     const MXIMPIdentity& /*aGroupId*/,
       
   154     TXIMPRequestId /*aReqId*/ )
       
   155     {
       
   156     User::Leave( KErrNotSupported );
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CPresencePluginGroups::DoUpdatePresentityGroupDisplayNameL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CPresencePluginGroups::DoUpdatePresentityGroupDisplayNameL(
       
   164     const MXIMPIdentity& /*aGroupId*/,
       
   165     const TDesC16& /*aDisplayName*/,
       
   166     TXIMPRequestId /*aReqId*/ )
       
   167     {
       
   168     // Notice: later
       
   169     User::Leave( KErrNotSupported );
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CPresencePluginGroups::DoSubscribePresentityGroupContentL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CPresencePluginGroups::DoSubscribePresentityGroupContentL(
       
   177     const MXIMPIdentity& aGroupId,
       
   178     TXIMPRequestId aReqId )
       
   179     {
       
   180     DP_SDA("CPresencePluginGroups::DoSubscribePresentityGroupContentL");
       
   181     iCompleted = EFalse;
       
   182     // List of lists under buddylist
       
   183     StartXdmOperationL( aGroupId, aReqId, EGetListContent );
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CPresencePluginGroups::DoUnsubscribePresentityGroupContentL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CPresencePluginGroups::DoUnsubscribePresentityGroupContentL(
       
   191     const MXIMPIdentity& /*aGroupId*/,
       
   192     TXIMPRequestId aReqId )
       
   193     {
       
   194     DP_SDA("CPresencePluginGroups::DoUnsubscribePresentityGroupContentL");
       
   195     
       
   196     iXIMPId = aReqId;
       
   197     iConnObs.WatcherHandlerL()->UnSubscribeAllL();    
       
   198     iCompleted = EFalse;
       
   199     CompleteXIMPReq( KErrNone );
       
   200     DP_SDA("CPresencePluginGroups::DoUnsubscribePresentityGroupContentL out");
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CPresencePluginGroups::DoAddPresentityGroupMemberL
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CPresencePluginGroups::DoAddPresentityGroupMemberL(
       
   208     const MXIMPIdentity& aGroupId,
       
   209     const MXIMPIdentity& aMemberId,
       
   210     const TDesC16& /*aMemberDisplayName*/,
       
   211     TXIMPRequestId aReqId )
       
   212     {
       
   213     DP_SDA("CPresencePluginGroups::DoAddPresentityGroupMemberL");
       
   214     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrNotReady ) );
       
   215     
       
   216     SetPresIdentityL( aMemberId, ETrue );
       
   217     
       
   218     iCompleted = EFalse;
       
   219     iXIMPId = aReqId;
       
   220         
       
   221     if( !aGroupId.Identity().Compare( KPresenceBuddyList ) )
       
   222         {
       
   223         DP_SDA("CPresencePluginGroups::DoAddPresentityGroupMemberL - buddylist");
       
   224         TBool contactIsBlocked = EFalse;
       
   225         RPointerArray<MXIMPIdentity> blockedList;
       
   226         CleanupStack::PushL( TCleanupItem(
       
   227             TPresencePluginUtility::ResetAndDestroyIdentities,
       
   228             &blockedList ) );
       
   229         iXdmUtils->SubscribeBlockListL( blockedList );
       
   230         DP_SDA2( "CPresencePluginGroups::DoAddPresentityGroupMemberL - blockedList.Count = %d",
       
   231             blockedList.Count() );
       
   232         
       
   233         for ( TInt i( 0 ); i < blockedList.Count() && !contactIsBlocked; i++ ) 
       
   234             {
       
   235             if ( 0 == blockedList[i]->Identity().Compare( aMemberId.Identity() ) )
       
   236                 {
       
   237                 // contact found from blocked list
       
   238                 contactIsBlocked = ETrue;
       
   239                 }
       
   240             }
       
   241         CleanupStack::PopAndDestroy( &blockedList );
       
   242         
       
   243         if ( contactIsBlocked )
       
   244             {
       
   245             DP_SDA( "CPresencePluginGroups::DoAddPresentityGroupMemberL - contact is Blocked" );
       
   246             iOperation = EUnblockInAddPresentityGroupMember;
       
   247             iConnObs.InternalPresenceAuthorization().
       
   248                 DoPerformCancelPresenceBlockFromPresentityL(
       
   249                     aMemberId, iStatus  );
       
   250             SetActive();
       
   251             }
       
   252         else
       
   253             {
       
   254             DP_SDA( "CPresencePluginGroups::DoAddPresentityGroupMemberL - contact is not Blocked" );
       
   255             iOperation = EAddPresentityGroupMember;
       
   256             // write pending to presence cache
       
   257             TBuf<20> buf;
       
   258             buf.Copy( KPendingRequestExtensionValue );
       
   259             iPresenceData->WriteStatusToCacheL( aMemberId.Identity(), 
       
   260                 MPresenceBuddyInfo2::ENotAvailable,
       
   261                 buf,
       
   262                 KNullDesC() );
       
   263             iConnObs.WatcherHandlerL()->DoPerformSubscribePresentityPresenceL( 
       
   264                 aMemberId, iStatus );
       
   265             SetActive();
       
   266             }
       
   267         }
       
   268     else if ( !aGroupId.Identity().Compare( KPresenceBlockedList ) )
       
   269         {
       
   270         DP_SDA("CPresencePluginGroups::DoAddPresentityGroupMemberL - blockedlist");
       
   271         iOperation = EBlockPresentityGroupMember;
       
   272         iConnObs.InternalPresenceAuthorization().
       
   273             DoPerformBlockPresenceForPresentityL( aMemberId, iStatus );
       
   274         SetActive();
       
   275         }
       
   276     else
       
   277         {
       
   278         DP_SDA("CPresencePluginGroups::DoAddPresentityGroupMemberL - unknown, leave");
       
   279         User::Leave( KErrNotSupported );
       
   280         }
       
   281     
       
   282     DP_SDA("CPresencePluginGroups::DoAddPresentityGroupMemberL out");
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // CPresencePluginGroups::DoRemovePresentityGroupMemberL
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CPresencePluginGroups::DoRemovePresentityGroupMemberL(
       
   290     const MXIMPIdentity& aGroupId,
       
   291     const MXIMPIdentity& aMemberId,
       
   292     TXIMPRequestId aReqId )
       
   293     {
       
   294     DP_SDA("CPresencePluginGroups::DoRemovePresentityGroupMemberL");
       
   295     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrNotReady ) );
       
   296 
       
   297     SetPresIdentityL( aMemberId, ETrue );
       
   298     
       
   299     iCompleted = EFalse;
       
   300     iXIMPId = aReqId;
       
   301     iOperation = ERemovePresentityGroupMember;
       
   302     
       
   303     if( !aGroupId.Identity().Compare( KPresenceBuddyList ) )
       
   304         {
       
   305         DP_SDA( "DoRemovePresentityGroupMemberL - buddylist" );
       
   306         iConnObs.WatcherHandlerL()->DoPerformUnsubscribePresentityPresenceL( 
       
   307             aMemberId, iStatus );
       
   308         SetActive();
       
   309         }
       
   310     else if ( !aGroupId.Identity().Compare( KPresenceBlockedList ) )
       
   311         {
       
   312         DP_SDA( "DoRemovePresentityGroupMemberL - blockedlist" );
       
   313         // Contact blocking is not cancelled when blocked contact is removed
       
   314         // user can remove blocking from blocked list later
       
   315         DeletePersonCacheL();
       
   316         CompleteXIMPReq( KErrNone );
       
   317         }
       
   318     else
       
   319         {
       
   320         DP_SDA("DoRemovePresentityGroupMemberL - unknown, leave");
       
   321         User::Leave( KErrNotSupported );
       
   322         }
       
   323         
       
   324     DP_SDA("CPresencePluginGroups::DoRemovePresentityGroupMemberL out");    
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CPresencePluginGroups::DoUpdatePresentityGroupMemberDisplayNameL
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CPresencePluginGroups::DoUpdatePresentityGroupMemberDisplayNameL(
       
   332     const MXIMPIdentity& /*aGroupId*/,
       
   333     const MXIMPIdentity& /*aMemberId*/,
       
   334     const TDesC16& /*aMemberDisplayName*/,
       
   335     TXIMPRequestId /*aReqId*/ )
       
   336     {
       
   337     DP_SDA("CPresencePluginGroups::DoUpdatePresentityGroupMemberDisplayNameL");
       
   338     // Notice: Later
       
   339     User::Leave( KErrNotSupported );
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // CPresencePluginGroups::DoCancel()
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 void CPresencePluginGroups::DoCancel(  )
       
   347     {
       
   348     if ( iOperation != ENoOperation )
       
   349         {
       
   350         iXdmUtils->Cancel();
       
   351         }
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CPresencePluginGroups::RunL()
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 void CPresencePluginGroups::RunL()
       
   359     {
       
   360     DP_SDA("CPresencePluginGroups::RunL");
       
   361     TInt myStatus = iStatus.Int();
       
   362     DP_SDA2("CPresencePluginGroups::RunL myStatus %d", myStatus );
       
   363     
       
   364     if ( !myStatus && !iCompleted )
       
   365         {
       
   366         DP_SDA("CPresencePluginGroups::RunL !myStatus");
       
   367         // OK response
       
   368         CallActualXdmOperationL( myStatus );
       
   369         }
       
   370     else if ( KErrNotFound == myStatus && !iCompleted )
       
   371         {
       
   372         DP_SDA("CPresencePluginGroups::RunL KErrNotFound == myStatus");
       
   373         
       
   374         // DoPerformUnsubscribePresentityPresenceL didn't find watcher
       
   375         // so it did not execute StopSubscribeL from the watcher. Still
       
   376         // presentity group member has to be removed.
       
   377         CallActualXdmOperationL( KErrNone );
       
   378         }
       
   379     else if ( !myStatus && iCompleted )
       
   380         {
       
   381         DP_SDA("CPresencePluginGroups::RunL SEND COMPLETE");
       
   382         CompleteXIMPReq( myStatus );
       
   383         }
       
   384     else
       
   385         {
       
   386         if ( iOperation == EDeletePresentityGroup && iState ==
       
   387         	EPluginCommitRls )
       
   388             {
       
   389             DP_SDA("CPresencePluginGroups::RunL CallActualXdmOperation");
       
   390             CallActualXdmOperationL( myStatus );
       
   391             }
       
   392         else
       
   393             {
       
   394             DP_SDA("CPresencePluginGroups::RunL SEND COMPLETE 2");
       
   395             // Other errors terminated the show
       
   396             CompleteXIMPReq( myStatus );
       
   397             }
       
   398         }
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CPresencePluginGroups::CallActualXdmOperationL
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CPresencePluginGroups::CallActualXdmOperationL( TInt aCompleteStatus )
       
   406     {
       
   407     DP_SDA("CPresencePluginGroups::CallActualXdmOperationL");
       
   408         
       
   409     DP_SDA2("CallActualXdmOperationL iOperation %d", iOperation);
       
   410     switch ( iOperation )
       
   411         {
       
   412         case EGetListOfLists:
       
   413             {
       
   414             DP_SDA("PluginGroups::CallActualXdmOperationL EGetListOfLists");
       
   415             iOperation = EGetListOfLists;
       
   416             GetListOfListsL();
       
   417             }
       
   418             break;
       
   419         
       
   420         case EGetListContent:
       
   421             {
       
   422             DP_SDA("PluginGroups::CallActualXdmOperationL EGetListContent");
       
   423             iOperation = EGetListContent;
       
   424             GetListContentL();
       
   425             }
       
   426             break;
       
   427             
       
   428         case EAddPresentityGroupMember:
       
   429             {
       
   430             DP_SDA(" CallActualXdmOperationL EAddPresentityGroupMember");
       
   431             
       
   432             iOperation = EGrantPresentityGroupMember;
       
   433             MXIMPIdentity* newIdentity = 
       
   434                 iConnObs.ObjectFactory().NewIdentityLC();
       
   435             newIdentity->SetIdentityL( *iPresIdentity );
       
   436             
       
   437             iConnObs.InternalPresenceAuthorization().
       
   438                 DoPerformGrantPresenceForPresentityL( *newIdentity, iStatus );
       
   439             CleanupStack::PopAndDestroy(); // >> newIdentity
       
   440             SetActive();
       
   441             }
       
   442             break;
       
   443             
       
   444         case ERemovePresentityGroupMember:
       
   445             {
       
   446             DP_SDA(" CallActualXdmOperationL ERemovePresentityGroupMember");
       
   447             iOperation = EWithdrawGrantFromMember;
       
   448             MXIMPIdentity* newIdentity = iConnObs.ObjectFactory().NewIdentityLC();
       
   449             newIdentity->SetIdentityL( *iPresIdentity );
       
   450             iConnObs.InternalPresenceAuthorization().
       
   451                 DoPerformWithdrawPresGrantFromPresentityL( 
       
   452                     *newIdentity, iStatus );
       
   453             CleanupStack::PopAndDestroy(); // >> newIdentity
       
   454             SetActive();
       
   455             }
       
   456             break;
       
   457             
       
   458         case EGrantPresentityGroupMember:
       
   459             {
       
   460             DP_SDA(" CallActualXdmOperationL EGrantPresentityGroupMember");
       
   461             CompleteXIMPReq( aCompleteStatus );
       
   462             }
       
   463             break;
       
   464             
       
   465         case EWithdrawGrantFromMember:
       
   466             {
       
   467             DP_SDA(" CallActualXdmOperationL EWithdrawGrantFromMember");
       
   468             if ( !aCompleteStatus )
       
   469                 {
       
   470                 DP_SDA(" -> succesfully unblocked, store to cache");
       
   471                 DeletePersonCacheL();                
       
   472                 DP_SDA(" -> store info to cache done");                
       
   473                 }            
       
   474             CompleteXIMPReq( aCompleteStatus );
       
   475             }
       
   476             break;
       
   477             
       
   478         case EBlockPresentityGroupMember:
       
   479             {
       
   480             DP_SDA(" CallActualXdmOperationL EBlockPresentityGroupMember");
       
   481             if ( !aCompleteStatus )
       
   482                 {
       
   483                 DP_SDA(" -> succesfully blocked, store to cache");
       
   484 
       
   485                 DP_SDA(" -> strip prefix from uri");
       
   486                 HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( 
       
   487                     *iPresIdentity );
       
   488                 DP_SDA(" -> store info to cache");
       
   489                 
       
   490                 TBuf<20> buf;
       
   491                 buf.Copy( KBlockedExtensionValue );
       
   492                                 
       
   493                 iPresenceData->WriteStatusToCacheL( *withoutPrefix, 
       
   494                     MPresenceBuddyInfo2::EUnknownAvailability,
       
   495                     buf,
       
   496                     KNullDesC() );
       
   497                 
       
   498                 CleanupStack::PopAndDestroy( withoutPrefix );
       
   499                 DP_SDA(" -> store info to cache done");
       
   500                 }
       
   501             CompleteXIMPReq( aCompleteStatus );
       
   502             }
       
   503             break;
       
   504             
       
   505         case EUnblockPresentityGroupMember:
       
   506             {
       
   507             DP_SDA(" CallActualXdmOperationL EUnblockPresentityGroupMember");
       
   508             if ( !aCompleteStatus )
       
   509                 {
       
   510                 DP_SDA(" -> succesfully unblocked, store to cache");
       
   511                 DeletePersonCacheL();                
       
   512                 DP_SDA(" -> store info to cache done");                
       
   513                 }            
       
   514             CompleteXIMPReq( aCompleteStatus );
       
   515             }
       
   516             break;
       
   517             
       
   518         case EUnblockInAddPresentityGroupMember:
       
   519             {
       
   520             DP_SDA(" CallActualXdmOperationL EUnblockInAddPresentityGroupMember");
       
   521             iOperation = EAddPresentityGroupMember;
       
   522             MXIMPIdentity* newIdentity = iConnObs.ObjectFactory().NewIdentityLC();
       
   523             newIdentity->SetIdentityL( *iPresIdentity );
       
   524             
       
   525             TBuf<20> buf;
       
   526             buf.Copy( KPendingRequestExtensionValue );
       
   527             iPresenceData->WriteStatusToCacheL( *iPresIdentity,
       
   528                 MPresenceBuddyInfo2::ENotAvailable,
       
   529                 buf, KNullDesC() );
       
   530             
       
   531             iConnObs.WatcherHandlerL()->DoPerformSubscribePresentityPresenceL( 
       
   532                 *newIdentity, iStatus );
       
   533             CleanupStack::PopAndDestroy(); // >> newIdentity
       
   534             SetActive();
       
   535             }
       
   536             break;
       
   537             
       
   538         default:
       
   539             User::Leave( KErrNotSupported );
       
   540             break;
       
   541         }
       
   542     DP_SDA("CPresencePluginGroups::CallActualXdmOperationL end");
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 // CPresencePluginGroups::RunError
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 TInt CPresencePluginGroups::RunError( TInt aError )
       
   550     {
       
   551     DP_SDA("CPresencePluginGroups::RunError SEND COMPLETE");
       
   552     // complete the open request
       
   553     CompleteXIMPReq( aError );
       
   554     return KErrNone;
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 // CPresencePluginGroups::GetInterface()
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 TAny* CPresencePluginGroups::GetInterface(
       
   562     TInt32 aInterfaceId,
       
   563     TIfGetOps aOptions )
       
   564     {
       
   565     if ( aInterfaceId == GetInterfaceId() )
       
   566         {
       
   567         // caller wants this interface
       
   568         MProtocolPresentityGroups* myIf = this;
       
   569         return myIf;
       
   570         }
       
   571     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   572         {
       
   573         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   574         }
       
   575     return NULL;
       
   576     }
       
   577 
       
   578 // ---------------------------------------------------------------------------
       
   579 // CPresencePluginGroups::GetInterface()
       
   580 // ---------------------------------------------------------------------------
       
   581 //
       
   582 const TAny* CPresencePluginGroups::GetInterface(
       
   583     TInt32 aInterfaceId,
       
   584     TIfGetOps aOptions ) const
       
   585     {
       
   586     if ( aInterfaceId == GetInterfaceId() )
       
   587         {
       
   588         // caller wants this interface
       
   589         const MProtocolPresentityGroups* myIf = this;
       
   590         return myIf;
       
   591         }
       
   592     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   593         {
       
   594         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   595         }
       
   596     return NULL;
       
   597     }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // CPresencePluginGroups::GetInterfaceId()
       
   601 // ---------------------------------------------------------------------------
       
   602 //
       
   603 TInt32 CPresencePluginGroups::GetInterfaceId() const
       
   604     {
       
   605     return MProtocolPresentityGroups::KInterfaceId;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // CPresencePluginGroups::SetPresIdentityL()
       
   610 // ---------------------------------------------------------------------------
       
   611 //
       
   612 void CPresencePluginGroups::SetPresIdentityL(
       
   613      const MXIMPIdentity& aPresentityId,
       
   614      TBool aFormatUri )
       
   615     {
       
   616     DP_SDA2("CPresencePluginGroups::SetPresIdentityL: %S", 
       
   617         &aPresentityId.Identity() ); 
       
   618      
       
   619     delete iPresIdentity;
       
   620     iPresIdentity = NULL;
       
   621      
       
   622     if ( aFormatUri )
       
   623         {
       
   624         DP_SDA("CPresencePluginGroups::SetPresIdentityL, format uri");
       
   625 
       
   626         HBufC8* identityCopy = HBufC8::NewLC( KBufSize255 );
       
   627         TPtr8 identityCopyPtr( identityCopy->Des() );
       
   628         identityCopyPtr.Copy( aPresentityId.Identity() );
       
   629     
       
   630         HBufC8* prefixUri = iPresenceData->CreatePresenceUri8LC( 
       
   631             identityCopyPtr );
       
   632     
       
   633         HBufC* prefixUri16 = HBufC::NewLC( KBufSize255 );
       
   634         TPtr prefixUri16Ptr( prefixUri16->Des() );
       
   635         prefixUri16Ptr.Copy( *prefixUri );
       
   636     
       
   637         iPresIdentity = prefixUri16;
       
   638         CleanupStack::Pop( prefixUri16 );
       
   639         CleanupStack::PopAndDestroy( prefixUri );
       
   640         CleanupStack::PopAndDestroy( identityCopy );
       
   641         }
       
   642     else
       
   643         {
       
   644         DP_SDA("CPresencePluginGroups::SetPresIdentityL, use as it is");
       
   645         iPresIdentity = aPresentityId.Identity().AllocL();
       
   646         }
       
   647     }
       
   648 
       
   649 // ---------------------------------------------------------------------------
       
   650 // CPresencePluginGroups::StartXdmOperationL
       
   651 // ---------------------------------------------------------------------------
       
   652 //
       
   653 void CPresencePluginGroups::StartXdmOperationL(
       
   654     TXIMPRequestId aReqId,
       
   655     TPluginGroupsOperation aOperation )
       
   656     {
       
   657     DP_SDA("StartXdmOperationL StartXdmOperationL two param");
       
   658     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   659     iXIMPId = aReqId;
       
   660     iOperation = aOperation;
       
   661     StartXdmOperationL();
       
   662     DP_SDA("StartXdmOperationL StartXdmOperationL two param end");
       
   663     }
       
   664 
       
   665 // ---------------------------------------------------------------------------
       
   666 // CPresencePluginGroups::StartXdmOperationL
       
   667 // ---------------------------------------------------------------------------
       
   668 //
       
   669 void CPresencePluginGroups::StartXdmOperationL(
       
   670     const MXIMPIdentity& aId,
       
   671     TXIMPRequestId aReqId,
       
   672     TPluginGroupsOperation aOperation )
       
   673     {
       
   674     DP_SDA("StartXdmOperationL StartXdmOperationL three param");
       
   675     __ASSERT_DEBUG( !IsActive(), User::Leave( KErrCorrupt ) );
       
   676     SetPresIdentityL( aId, EFalse );
       
   677     iXIMPId = aReqId;
       
   678     iOperation = aOperation;
       
   679     StartXdmOperationL();
       
   680     }
       
   681   
       
   682 // ---------------------------------------------------------------------------
       
   683 // CPresencePluginGroups::StartXdmOperationL
       
   684 // ---------------------------------------------------------------------------
       
   685 //
       
   686 void CPresencePluginGroups::StartXdmOperationL()
       
   687     {
       
   688     if ( !iXdmUtils )
       
   689         {
       
   690         DP_SDA("CPresencePluginGroups::StartXdmOperationL Get xdmUtils");
       
   691         iXdmUtils = iConnObs.XdmUtilsL();
       
   692         }
       
   693     DP_SDA("CPresencePluginGroups::StartXdmOperationL StartXdmOperationL");
       
   694     
       
   695     iXdmUtils->InitializeXdmL( iStatus );
       
   696     iState = EPluginInitXdm;
       
   697     DP_SDA("CPresencePluginGroups::StartXdmOperationL SetActive");
       
   698     SetActive();
       
   699     }
       
   700 
       
   701 // ---------------------------------------------------------------------------
       
   702 // CPresencePluginGroups::GetListOfListsL
       
   703 // ---------------------------------------------------------------------------
       
   704 //
       
   705 void CPresencePluginGroups::GetListOfListsL()
       
   706     {
       
   707     DP_SDA("CPresencePluginGroups::GetListOfListsL");
       
   708 
       
   709     RPointerArray<MXIMPIdentity> subscribed;
       
   710     CleanupClosePushL( subscribed );
       
   711 
       
   712     iXdmUtils->SubscribeBuddyListL( subscribed );
       
   713 	DP_SDA("CPresencePluginGroups::GetListOfListsL SubscribeBudyList Ready");
       
   714 	
       
   715     MXIMPObjectCollection* coll =
       
   716         iConnObs.ObjectFactory().NewObjectCollectionLC();    // << coll
       
   717         
       
   718     TInt count = subscribed.Count();
       
   719     DP_SDA2("CPresencePluginGroups::GetListOfListsL soul count %d", count);
       
   720     
       
   721     for ( TInt i = 0; i < count; i++ )
       
   722         {
       
   723         MXIMPIdentity* currId = subscribed[i];
       
   724         MPresentityGroupInfo* sInfo =
       
   725             iConnObs.PresenceObjectFactoryOwn().NewPresentityGroupInfoLC();
       
   726         sInfo->SetGroupIdL( currId ); // ownership is taken
       
   727         sInfo->SetGroupDisplayNameL( currId->Identity() );
       
   728         
       
   729         coll->AddObjectL( sInfo );      // ownership is taken
       
   730         CleanupStack::Pop();                                // >> bInfo
       
   731         }
       
   732     DP_SDA("SubscribeBudyList For ready SEND COMPLETE continue");    
       
   733      
       
   734     CompleteXIMPReq( KErrNone );
       
   735     
       
   736      // Callback for subscription state (terminated).
       
   737     MXIMPDataSubscriptionState* myState =
       
   738         iConnObs.ObjectFactory().NewDataSubscriptionStateLC();
       
   739         
       
   740     MXIMPStatus* myStatus = iConnObs.ObjectFactory().NewStatusLC();
       
   741     
       
   742     // Notice: consider XIMP error codes
       
   743     myStatus->SetResultCode( KErrNone );
       
   744     myState->SetSubscriptionStateL(
       
   745         MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   746         
       
   747     MProtocolPresentityGroupsDataHost& dataHost =
       
   748          iConnObs.ProtocolPresenceHost().GroupsDataHost();
       
   749     
       
   750     dataHost.SetPresentityGroupListDataSubscriptionStateL(
       
   751         myState, myStatus );
       
   752         
       
   753     dataHost.HandlePresentityGroupListL( coll );    
       
   754 
       
   755     CleanupStack::Pop( 3 ); // >> myState, myStatus, coll
       
   756    	CleanupStack::Pop( &subscribed );
       
   757    	DP_SDA("CPresencePluginGroups::GetListOfListsL end"); 
       
   758     }
       
   759 
       
   760 // ---------------------------------------------------------------------------
       
   761 // CPresencePluginGroups::GetListContentL
       
   762 // ---------------------------------------------------------------------------
       
   763 //
       
   764 void CPresencePluginGroups::GetListContentL()
       
   765     {
       
   766     DP_SDA("CPresencePluginGroups::GetListContentL");
       
   767     
       
   768     if( !iPresIdentity->Compare( KPresenceBuddyList ) )
       
   769         {
       
   770         DP_SDA("CPresencePluginGroups::GetListContentL - get buddies");
       
   771         DoGetSubscribedBuddyListL();
       
   772         
       
   773         // Consider waiting complete for each subscribe before completing
       
   774         CompleteXIMPReq( KErrNone ); 
       
   775         }
       
   776     else if( !iPresIdentity->Compare( KPresenceSubcribedBuddys ) )
       
   777     	{
       
   778     	//Subscribe subscribed buddyes virtual group
       
   779     	DP_SDA("GetListContentL KPresenceSubcribedBuddys");
       
   780     	DoGetSubscribedBuddyListL();
       
   781     	}
       
   782     else
       
   783     	{
       
   784     	DP_SDA("CPresencePluginGroups::GetListContentL Wrong list name");	
       
   785         User::Leave( KErrNotFound );
       
   786         }
       
   787     }
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // CPresencePluginGroups::DoGetBuddyListL()
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 void CPresencePluginGroups::DoGetBuddyListL()
       
   794     {
       
   795     DP_SDA("CPresencePluginGroups::DoGetBuddyListL KPresenceBuddyList");
       
   796     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   797     MProtocolPresentityGroupsDataHost& dataHost =
       
   798         iConnObs.ProtocolPresenceHost().GroupsDataHost();
       
   799     
       
   800     MXIMPObjectCollection* entities =
       
   801     	myFactory.NewObjectCollectionLC();          // << entities
       
   802     iXdmUtils->GetEntitiesInListL( iPresIdentity->Des(), *entities );
       
   803     DP_SDA("DoGetBuddyListL entities get ready SEND COMPLETE");
       
   804     
       
   805     // callback for data
       
   806     DP_SDA("CPresencePluginGroups::DoGetBuddyListL callback data");
       
   807     MXIMPIdentity* id = myFactory.NewIdentityLC();  // << id
       
   808     id->SetIdentityL( iPresIdentity->Des() );
       
   809     dataHost.HandlePresentityGroupContentL( id, entities );
       
   810     CleanupStack::Pop();// >> id
       
   811     CleanupStack::Pop();// >> entities
       
   812     DP_SDA("CPresencePluginGroups::DoGetBuddyListL callback ready");
       
   813 
       
   814     // Callback for subscription state (terminated).
       
   815     DP_SDA("CPresencePluginGroups::DoGetBuddyListL terminated ");
       
   816     id = myFactory.NewIdentityLC();  // << id
       
   817     id->SetIdentityL( iPresIdentity->Des() );
       
   818     MXIMPDataSubscriptionState* myState =
       
   819     myFactory.NewDataSubscriptionStateLC();
       
   820     MXIMPStatus* myStatus = myFactory.NewStatusLC();
       
   821     // Notice: consider XIMP error codes
       
   822     myStatus->SetResultCode( KErrNone );
       
   823     myState->SetSubscriptionStateL(
       
   824     		MXIMPDataSubscriptionState::ESubscriptionInactive );
       
   825     
       
   826     dataHost.SetPresentityGroupContentDataSubscriptionStateL(
       
   827     	id, myState, myStatus );
       
   828   
       
   829     DP_SDA("CPresencePluginGroups::DoGetBuddyListL Pop");
       
   830 	CleanupStack::Pop( 3 );
       
   831 	
       
   832     DP_SDA("CPresencePluginGroups::DoGetBuddyListL end");
       
   833     }
       
   834     
       
   835 // ---------------------------------------------------------------------------
       
   836 // CPresencePluginGroups::DoGetSubscribedBuddyListL()
       
   837 // ---------------------------------------------------------------------------
       
   838 //
       
   839 void CPresencePluginGroups::DoGetSubscribedBuddyListL()
       
   840     {
       
   841     DP_SDA("CPresencePluginGroups::DoGetSubscribedBuddyListL");
       
   842     MXIMPObjectFactory& myFactory = iConnObs.ObjectFactory();
       
   843     MProtocolPresentityGroupsDataHost& dataHost =
       
   844         iConnObs.ProtocolPresenceHost().GroupsDataHost();
       
   845     
       
   846     // Get internal list content
       
   847     MXIMPObjectCollection* entities =
       
   848     	myFactory.NewObjectCollectionLC();          // << entities
       
   849     iXdmUtils->GetEntitiesInListL( iPresIdentity->Des(), *entities );
       
   850     DP_SDA("DoGetBuddyListL entities get ready SEND COMPLETE");
       
   851     CleanupStack::PopAndDestroy();	// entities
       
   852     
       
   853     // start getting virtualEntities
       
   854     MXIMPObjectCollection* virtualEntities =
       
   855         myFactory.NewObjectCollectionLC();// << virtualEntities
       
   856 
       
   857     iSubscribedBuddies->GetVirtualEntitiesL( *virtualEntities );
       
   858     
       
   859     DP_SDA("CPresencePluginGroups::DoGetSubscribedBuddyListL - subscribe all");
       
   860     iConnObs.WatcherHandlerL()->SubscribeAllL();
       
   861     DP_SDA("CPresencePluginGroups::DoGetSubscribedBuddyListL - subscribe all ok");
       
   862 
       
   863     // callback for data
       
   864     DP_SDA("DoGetSubscribedBuddyListL callback data");
       
   865     MXIMPIdentity* id = myFactory.NewIdentityLC();  // << id
       
   866     id->SetIdentityL( iPresIdentity->Des() );
       
   867     dataHost.HandlePresentityGroupContentL( id, virtualEntities );
       
   868     CleanupStack::Pop();                            // >> id
       
   869     CleanupStack::Pop();                            // >> entities
       
   870     DP_SDA("DoGetSubscribedBuddyListL callback ready");
       
   871 
       
   872     // Callback for subscription state (terminated).
       
   873     DP_SDA("CPresencePluginGroups::DoGetSubscribedBuddyListL terminated");
       
   874     id = myFactory.NewIdentityLC();  // << id
       
   875     id->SetIdentityL( iPresIdentity->Des() );
       
   876     MXIMPDataSubscriptionState* myState =
       
   877     	myFactory.NewDataSubscriptionStateLC();
       
   878     MXIMPStatus* myStatus = myFactory.NewStatusLC();
       
   879     // Notice: consider XIMP error codes
       
   880     myStatus->SetResultCode( KErrNone );
       
   881     myState->SetSubscriptionStateL(
       
   882     		MXIMPDataSubscriptionState::ESubscriptionActive );
       
   883     dataHost.SetPresentityGroupContentDataSubscriptionStateL(
       
   884     	id, myState, myStatus );
       
   885     
       
   886 	CleanupStack::Pop( 3 );
       
   887 	
       
   888     DP_SDA("DoGetSubscribedBuddyListL - KPresenceOnlineBuddy case end");
       
   889     }
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 // CPresencePluginGroups::CompleteXIMPReq
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 void CPresencePluginGroups::CompleteXIMPReq( TInt aStatus )
       
   896     {
       
   897     DP_SDA("CPresencePluginGroups::CompleteXIMPReq");
       
   898     if ( iCompleted  )
       
   899         {
       
   900         DP_SDA("CPresencePluginGroups::CompleteXIMPReq return");
       
   901         return;
       
   902         }
       
   903 
       
   904     iCompleted = ETrue;
       
   905     iOperation = ENoOperation;
       
   906     iConnObs.CompleteReq( iXIMPId, aStatus );
       
   907     iXIMPId = TXIMPRequestId();
       
   908     DP_SDA("CPresencePluginGroups::CompleteXIMPReq end");
       
   909     }
       
   910 
       
   911 // ---------------------------------------------------------------------------
       
   912 // CPresencePluginGroups::DeletePersonCacheL
       
   913 // ---------------------------------------------------------------------------
       
   914 //
       
   915 void CPresencePluginGroups::DeletePersonCacheL()
       
   916     {
       
   917     DP_SDA("CPresencePluginGroups::DeletePersonCacheL");
       
   918     DP_SDA(" -> strip prefix from uri");
       
   919     HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
       
   920     iPresenceData->DeletePresenceL( *withoutPrefix );
       
   921     CleanupStack::PopAndDestroy( withoutPrefix );
       
   922     DP_SDA("CPresencePluginGroups::DeletePersonCacheL out");
       
   923     }
       
   924 
       
   925 // End of file