ximpfw/presence/srcpresenceoperations/presencewatching/operationsubscribepresentitygroupmemberspresence.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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: implementation of COperationSubscribePresentityGroupMembersPresence
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnection.h>
       
    20 #include <protocolpresencewatching.h>
       
    21 #include <protocolpresencefeatures.h>
       
    22 
       
    23 #include "operationsubscribepresentitygroupmemberspresence.h"
       
    24 #include "presenceinfofilterimp.h"
       
    25 #include "ximpidentityimp.h"
       
    26 #include "ximpobjecthelpers.h"
       
    27 #include "presencedatacacheimp.h"
       
    28 #include "documentutils.h"
       
    29 #include "ximprestrictedobjectcollectionimp.h"
       
    30 #include "operationsynthesisesubscriptionevent.h"
       
    31 #include "ximphost.h"
       
    32 #include "ximpstatusimp.h"
       
    33 #include "ximppsccontextimp.h"
       
    34 #include "ximppanics.h"
       
    35 #include "protocolpresencedatahostimp.h"
       
    36 
       
    37 #include "ximptrace.h"
       
    38 // ============================ MEMBER FUNCTIONS =============================
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // COperationSubscribePresentityGroupMembersPresence::COperationSubscribePresentityGroupMembersPresence()
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C COperationSubscribePresentityGroupMembersPresence::COperationSubscribePresentityGroupMembersPresence()
       
    45     {
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // COperationSubscribePresentityGroupMembersPresence::~COperationSubscribePresentityGroupMembersPresence()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 COperationSubscribePresentityGroupMembersPresence::~COperationSubscribePresentityGroupMembersPresence()
       
    54     {
       
    55     delete iMergedPif;
       
    56     delete iPif;
       
    57     delete iGroupId;
       
    58     if( iSubItem )
       
    59         {
       
    60         iSubItem->Close();
       
    61         }
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // COperationSubscribePresentityGroupMembersPresence::ConstructL()
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void COperationSubscribePresentityGroupMembersPresence::ConstructL( const TDesC8& aParamPck )
       
    69     {
       
    70     RXIMPObjOwningPtrArray< HBufC8 > packArray;
       
    71     CleanupClosePushL( packArray );
       
    72     TXIMPHBuf8Packer::UnPackArrayL( packArray, aParamPck );
       
    73 
       
    74     iGroupId = CXIMPIdentityImp::NewLC();
       
    75     CleanupStack::Pop( iGroupId );
       
    76     TXIMPObjectPacker< CXIMPIdentityImp >::UnPackL( *iGroupId, *( packArray[ 0 ] ) );
       
    77 
       
    78     iPif = CPresenceInfoFilterImp::NewLC();
       
    79     CleanupStack::Pop( iPif );
       
    80     TXIMPObjectPacker< CPresenceInfoFilterImp >::UnPackL( *iPif, *( packArray[ 1 ] ) );
       
    81 
       
    82     CleanupStack::PopAndDestroy(); // packArray    
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // COperationSubscribePresentityGroupMembersPresence::ProcessL()
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void COperationSubscribePresentityGroupMembersPresence::ProcessL()
       
    91     {
       
    92     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - begin" ) );
       
    93     CXIMPOperationBase::ProcessL();
       
    94     
       
    95     CPresentityGroupMembersPresenceSubscriptionItem& subItem =  
       
    96                 iMyHost->PresenceDataAccess().PresenceDataCache().PresentityGroupMembersPresenceSubscriptionItemLC( *iGroupId );
       
    97     CleanupStack::Pop(); // subItem
       
    98     iSubItem = &subItem;
       
    99 
       
   100     // Get the subscription status
       
   101     // Notice that if there is more than one client and clients are using identity
       
   102     // which will alternate for request complete, this will affect wrong logic mapping
       
   103     // for subscription operation. 
       
   104     
       
   105     // For example: Client 1 is subscription "name" and server alters it to name@domain.com
       
   106     // Client 2 subscribes with "name" and it will get subscription status ENotSubscribedAtAll
       
   107     // when it should get ESubscribedForOtherCtxOnly.
       
   108     iSubscriptionStatus = iSubItem->SubscriptionStatus( iContext );
       
   109 
       
   110     MProtocolPresenceWatching& watching = iMyHost->GetConnection().ProtocolPresenceFeatures().PresenceWatching();
       
   111 
       
   112     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - start action" ) );
       
   113     
       
   114     switch( iSubscriptionStatus )
       
   115         {
       
   116         case CPresentityGroupMembersPresenceSubscriptionItem::ENotSubscribedAtAll:
       
   117             {
       
   118             TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - case CPresentityGroupMembersPresenceSubscriptionItem::ENotSubscribedAtAll" ) );
       
   119             
       
   120             iMergedPif = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneL( *iPif );
       
   121             watching.DoSubscribePresentityGroupMembersPresenceL( *iGroupId,
       
   122                                                                    *iMergedPif,
       
   123                                                                    iReqId );
       
   124             break;
       
   125             }
       
   126         case CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForOtherCtxOnly:
       
   127             {
       
   128             TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - case CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForOtherCtxOnly" ) );
       
   129             
       
   130             // Aggregate subscription and context pifs
       
   131             // Check aggregate and if needed.. update subscription
       
   132             iMergedPif = DocumentUtils::InfoFilterUnionL( iSubItem->SubscriptionPif(), *iPif );
       
   133             if( iMergedPif->Contains( iSubItem->SubscriptionPif() ) )
       
   134                 {
       
   135                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() -  if( iMergedPif->Contains( iSubItem->SubscriptionPif() ) ) " ) );                            
       
   136                             
       
   137                 watching.DoUpdatePresentityGroupMembersPresenceSubscriptionPifL( *iGroupId, 
       
   138                                                                                 *iMergedPif, 
       
   139                                                                                 iReqId );
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - iMyHost->FakeCompleteRequest" ) );                            
       
   144                 iMyHost->FakeCompleteRequest( iReqId, KErrNone );
       
   145                 }
       
   146             break;
       
   147             }
       
   148         case CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForCtxOnly:
       
   149         case CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForCtxAndOthers:
       
   150             {
       
   151             TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - case CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForCtxOnly and ESubscribedForCtxAndOthers" ) );
       
   152             
       
   153             CPresenceInfoFilterImp* oldPif = 
       
   154                     iContext->PresenceInfoFilter( MXIMPPscContext::EPresentityGroupMemberPresenceFilter, iGroupId );
       
   155             CPresenceInfoFilterImp& oldMergedPif = iSubItem->SubscriptionPif();
       
   156             TBool makeUnion( EFalse );
       
   157             if( !oldPif )
       
   158                 {
       
   159                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() no old pif" ) );
       
   160                 makeUnion = ETrue;
       
   161                 }
       
   162             else if ( *oldPif != *iPif ) 
       
   163                 {
       
   164                 makeUnion = ETrue;
       
   165                 }
       
   166             if( makeUnion )
       
   167                 {
       
   168                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - if( *oldPif != *iPif )" ) );                            
       
   169                 
       
   170                 iDoNotForce = ETrue;
       
   171                 CPresenceInfoFilterImp* withoutPif = 
       
   172                             iSubItem->CollectSubscriptionPifWithoutCtxL( iContext );
       
   173                 iMergedPif = DocumentUtils::InfoFilterUnionL( *withoutPif, *iPif );
       
   174                 }
       
   175             else
       
   176                 {
       
   177                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() -  iMergedPif = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneL( oldMergedPif );" ) );                            
       
   178                 
       
   179                 iMergedPif = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneL( oldMergedPif );
       
   180                 }
       
   181                 
       
   182             if( iMergedPif->Contains( oldMergedPif ) )
       
   183                 {
       
   184                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() -  if( iMergedPif->Contains( oldMergedPif ) )" ) );                            
       
   185                 
       
   186                 iDoNotForce = ETrue;
       
   187                 watching.DoUpdatePresentityGroupMembersPresenceSubscriptionPifL( *iGroupId, *iMergedPif, iReqId );
       
   188                 }
       
   189             else
       
   190                 {
       
   191                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() -  iMyHost->FakeCompleteRequest( iReqId, KErrNone );" ) );                            
       
   192                 
       
   193                 iMyHost->FakeCompleteRequest( iReqId, KErrNone );
       
   194                 }
       
   195             break;
       
   196             }
       
   197         
       
   198         XIMP_DEFAULT_CASE_UNSUPPORTED( NXIMPPrivPanic::EInvalidSubscriptionStatus );            
       
   199         }
       
   200         
       
   201     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::ProcessL() - end" ) );
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // COperationSubscribePresentityGroupMembersPresence::RequestCompletedL()
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void COperationSubscribePresentityGroupMembersPresence::RequestCompletedL()
       
   210     {
       
   211     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL() - begin" ) );
       
   212     CXIMPOperationBase::RequestCompletedL();
       
   213 
       
   214     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL() : after CXIMPOperationBase::RequestCompletedL" ) );
       
   215     if( iStatusObj->ResultCode() == KErrNone )
       
   216         {
       
   217         TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL() : iStatusObj->ResultCode() == KErrNone " ) );
       
   218         
       
   219         if( iSubscriptionStatus == 
       
   220                     CPresentityGroupMembersPresenceSubscriptionItem::ENotSubscribedAtAll )
       
   221             {
       
   222             TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL() : iSubscriptionStatus == ENotSubscribedAtAll " ) );
       
   223             
       
   224             MXIMPBase* object = NULL; 
       
   225             iObjCollection->GetByType( object, MXIMPIdentity::KInterfaceId );
       
   226             if( object )
       
   227                 {
       
   228                 TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL got altered identity()"));
       
   229                 delete iGroupId;
       
   230                 iGroupId = TXIMPGetImpClassOrPanic< CXIMPIdentityImp >::From( *object );
       
   231 
       
   232                 // Got altered identity. If it differs from original
       
   233                 // we'll create a new subscription item and close the old.
       
   234                 CPresentityGroupMembersPresenceSubscriptionItem& altSubItem = 
       
   235                     iMyHost->PresenceDataAccess().PresenceDataCache().PresentityGroupMembersPresenceSubscriptionItemLC( *iGroupId );
       
   236 
       
   237                 iSubItem->Close();
       
   238                 iSubItem = &altSubItem;
       
   239 
       
   240                 CleanupStack::Pop(); // altSubItem                    
       
   241                 }            
       
   242             }
       
   243             
       
   244         TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL() : before iSubItem->AddSubscriberL"));            
       
   245         TRACE_1(_L(" iSubscriptionStatus = %d" ), (TInt)iSubscriptionStatus );  
       
   246         if( iSubscriptionStatus == 
       
   247                     CPresentityGroupMembersPresenceSubscriptionItem::ENotSubscribedAtAll ||
       
   248             iSubscriptionStatus == 
       
   249                     CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForOtherCtxOnly )
       
   250             {
       
   251             iSubItem->AddSubscriberL( iContext );        
       
   252             TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL():  iSubItem->AddSubscriberL( iContext ) called:  " ) );     
       
   253             }
       
   254             
       
   255         iContext->SetPresenceInfoFilterL( MXIMPPscContext::EPresentityGroupMemberPresenceFilter,
       
   256                 iPif, iGroupId );
       
   257         iPif = NULL;
       
   258         iSubItem->SetSubscriptionPif( iMergedPif );
       
   259         iMergedPif = NULL;
       
   260 
       
   261         SynthesiseEventL();
       
   262         }
       
   263     
       
   264     TRACE(_L("COperationSubscribePresentityGroupMembersPresence::RequestCompletedL():  end " ) );        
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // COperationSubscribePresentityGroupMembersPresence::Type()
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TInt
       
   272     COperationSubscribePresentityGroupMembersPresence::Type() const
       
   273     {
       
   274     return NPresenceOps::EPrSubscribePresentityGroupMembersPresence;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // COperationSubscribePresentityGroupMembersPresence::SynthesiseEventL()
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void COperationSubscribePresentityGroupMembersPresence::SynthesiseEventL()
       
   282     {
       
   283     TBool force = 
       
   284     ( iSubscriptionStatus == CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForCtxOnly ||
       
   285       iSubscriptionStatus == CPresentityGroupMembersPresenceSubscriptionItem::ESubscribedForCtxAndOthers ) ? ETrue : EFalse;
       
   286     TRACE_1(_L("COperationSubscribePresentityGroupMembersPresence::SynthesiseEventL - force=%d" ) , force);
       
   287     COperationSynthesiseSubscriptionEvent* synthOp =
       
   288         new ( ELeave ) COperationSynthesiseSubscriptionEvent(
       
   289             COperationSynthesiseSubscriptionEvent::EPresentityGroupMembersPresence, force && !iDoNotForce );
       
   290     CleanupStack::PushL( synthOp );    
       
   291     synthOp->BaseConstructL( TXIMPRequestId(), iContext );
       
   292     synthOp->ConstructL( *iGroupId );
       
   293     iMyHost->AddNewOperationL( *synthOp );
       
   294     CleanupStack::Pop( synthOp );    
       
   295     }
       
   296 
       
   297 
       
   298 
       
   299 // End of file