ximpfw/presence/srcpresenceoperations/presencewatching/operationunsubscribepresentitypresence.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:  Presentity presence unsubscription operation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnection.h>
       
    20 #include <protocolpresencewatching.h>
       
    21 #include <protocolpresencefeatures.h>
       
    22 
       
    23 #include "operationunsubscribepresentitypresence.h"
       
    24 #include "presenceinfofilterimp.h"
       
    25 #include "ximpidentityimp.h"
       
    26 #include "ximpobjecthelpers.h"
       
    27 #include "presencedatacacheimp.h"
       
    28 #include "ximppanics.h"
       
    29 #include "operationsynthesisesubscriptionevent.h"
       
    30 #include "ximphost.h"
       
    31 #include "ximpstatusimp.h"
       
    32 #include "ximppsccontextimp.h"
       
    33 #include "protocolpresencedatahostimp.h"
       
    34 
       
    35 #include "ximptrace.h"
       
    36 // ============================ MEMBER FUNCTIONS =============================
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // COperationUnsubscribePresentityPresence::COperationUnsubscribePresentityPresence()
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C COperationUnsubscribePresentityPresence::COperationUnsubscribePresentityPresence()
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // COperationUnsubscribePresentityPresence::~COperationUnsubscribePresentityPresence()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 COperationUnsubscribePresentityPresence::~COperationUnsubscribePresentityPresence()
       
    52     {
       
    53     delete iIdentity;
       
    54     if( iSubItem )
       
    55         {
       
    56         iSubItem->Close();
       
    57         }
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // COperationUnsubscribePresentityPresence::ConstructL()
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void COperationUnsubscribePresentityPresence::ConstructL( const TDesC8& aParamPck )
       
    65     {
       
    66     iIdentity = CXIMPIdentityImp::NewLC();
       
    67     CleanupStack::Pop( iIdentity );
       
    68     TXIMPObjectPacker< CXIMPIdentityImp >::UnPackL( *iIdentity, aParamPck );
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // COperationUnsubscribePresentityPresence::ProcessL()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void COperationUnsubscribePresentityPresence::ProcessL()
       
    77     {
       
    78     TRACE(_L("COperationUnsubscribePresentityPresence::ProcessL()" ) );
       
    79     CXIMPOperationBase::ProcessL();
       
    80 
       
    81     CPresentityPresenceSubscriptionItem& subItem =
       
    82                 iMyHost->PresenceDataAccess().PresenceDataCache().PresentityPresenceSubscriptionItemLC( *iIdentity );
       
    83     CleanupStack::Pop(); // subItem
       
    84     iSubItem = &subItem;
       
    85 
       
    86     iSubscriptionStatus = iSubItem->SubscriptionStatus( iContext );
       
    87 
       
    88     MProtocolPresenceWatching& watching = iMyHost->GetConnection().ProtocolPresenceFeatures().PresenceWatching();
       
    89 
       
    90     iContext->SetPresenceInfoFilterL( MXIMPPscContext::EPresentityPresenceFilter,
       
    91             NULL, iIdentity );
       
    92 
       
    93     switch( iSubscriptionStatus )
       
    94         {
       
    95         case CPresentityPresenceSubscriptionItem::ESubscribedForCtxOnly:
       
    96             {
       
    97             TRACE(_L("COperationUnsubscribePresentityPresence::ProcessL() DoUnsubscribePresentityPresenceL" ) );
       
    98             TInt err ( KErrNone );
       
    99             // If this fails, subscription needs to be removed anyway,
       
   100             // if everything went ok, subscription is removed in RequestCompleted
       
   101             TRAP( err, watching.DoUnsubscribePresentityPresenceL( *iIdentity, iReqId ) );
       
   102             if ( KErrNone != err )
       
   103                 {
       
   104                 iSubItem->RemoveSubscriber( iContext );
       
   105                 User::Leave( err );
       
   106                 }
       
   107             break;
       
   108             }
       
   109 
       
   110         case CPresentityPresenceSubscriptionItem::ESubscribedForCtxAndOthers:
       
   111             {
       
   112             CPresenceInfoFilterImp* pifWithoutCtx =
       
   113                 iSubItem->CollectSubscriptionPifWithoutCtxL( iContext );
       
   114             CleanupStack::PushL( pifWithoutCtx );
       
   115 
       
   116             if ( iSubItem->SubscriptionPif().Contains( *pifWithoutCtx ) )
       
   117                 {
       
   118                 TRACE(_L("COperationUnsubscribePresentityPresence::ProcessL() DoUpdatePresentityPresenceSubscriptionPifL" ) );
       
   119                 TInt err ( KErrNone );
       
   120                 // If this fails, subscription needs to be removed anyway,
       
   121                 // if everything went ok, subscription is removed in RequestCompleted
       
   122                 TRAP( err, watching.DoUpdatePresentityPresenceSubscriptionPifL( *iIdentity, *pifWithoutCtx, iReqId ) );
       
   123                 if ( KErrNone != err )
       
   124                     {
       
   125                     iSubItem->RemoveSubscriber( iContext );
       
   126                     User::Leave( err );
       
   127                     }
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 TRACE(_L("COperationUnsubscribePresentityPresence::ProcessL() FakeCompleteRequest 1" ) );
       
   132                 iMyHost->FakeCompleteRequest( iReqId, KErrNone );
       
   133                 }
       
   134 
       
   135             CleanupStack::PopAndDestroy( pifWithoutCtx );
       
   136             break;
       
   137             }
       
   138 
       
   139         case CPresentityPresenceSubscriptionItem::ENotSubscribedAtAll:
       
   140         case CPresentityPresenceSubscriptionItem::ESubscribedForOtherCtxOnly:
       
   141             {
       
   142             TRACE(_L("COperationUnsubscribePresentityPresence::ProcessL() FakeCompleteRequest 2" ) );
       
   143             iMyHost->FakeCompleteRequest( iReqId, KErrNone );
       
   144             break;
       
   145             }
       
   146             
       
   147         XIMP_DEFAULT_CASE_UNSUPPORTED( NXIMPPrivPanic::EInvalidSubscriptionStatus );            
       
   148         }
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // COperationUnsubscribePresentityPresence::RequestCompleted()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void COperationUnsubscribePresentityPresence::RequestCompletedL()
       
   156     {
       
   157     TRACE(_L("COperationUnsubscribePresentityPresence::RequestCompletedL()" ) );
       
   158     CXIMPOperationBase::RequestCompletedL();
       
   159     TRACE_1(_L("COperationUnsubscribePresentityPresence::RequestCompletedL() result=%d" ),iStatusObj->ResultCode() );
       
   160     if( iStatusObj->ResultCode() == KErrNone )
       
   161         {
       
   162         switch( iSubscriptionStatus )
       
   163             {
       
   164             case CPresentityPresenceSubscriptionItem::ESubscribedForCtxOnly:
       
   165             case CPresentityPresenceSubscriptionItem::ESubscribedForCtxAndOthers:
       
   166                 {
       
   167                 TRACE(_L("COperationUnsubscribePresentityPresence::RequestCompletedL() removing context" ) );
       
   168                 iSubItem->RemoveSubscriber( iContext );
       
   169                 break;
       
   170                 }
       
   171             
       
   172             case CPresentityPresenceSubscriptionItem::ENotSubscribedAtAll:
       
   173             case CPresentityPresenceSubscriptionItem::ESubscribedForOtherCtxOnly:
       
   174                 {
       
   175                 TRACE(_L("COperationUnsubscribePresentityPresence::RequestCompletedL() nothing to do" ) );
       
   176                 break;
       
   177                 }
       
   178             
       
   179             XIMP_DEFAULT_CASE_UNSUPPORTED( NXIMPPrivPanic::EInvalidSubscriptionStatus );
       
   180             }
       
   181 
       
   182         SynthesiseEventL();
       
   183         }
       
   184     }
       
   185 
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // COperationUnsubscribePresentityPresence::Type()
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TInt COperationUnsubscribePresentityPresence::Type() const
       
   192     {
       
   193     return NPresenceOps::EPrUnsubscribePresentityPresence;
       
   194     }
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // COperationUnsubscribePresentityPresence::SynthesiseEventL()
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void COperationUnsubscribePresentityPresence::SynthesiseEventL()
       
   202     {
       
   203     COperationSynthesiseSubscriptionEvent* synthOp =
       
   204             new ( ELeave ) COperationSynthesiseSubscriptionEvent(
       
   205                              COperationSynthesiseSubscriptionEvent::EPresentityPresence, EFalse );
       
   206     CleanupStack::PushL( synthOp );
       
   207     synthOp->BaseConstructL( TXIMPRequestId(), iContext );
       
   208     synthOp->ConstructL( *iIdentity );
       
   209     iMyHost->AddNewOperationL( *synthOp );
       
   210     CleanupStack::Pop( synthOp );
       
   211     }
       
   212 
       
   213 
       
   214 // End of file