simpledatamodeladapter/src/presencepluginconnection.cpp
branchRCL_3
changeset 18 fbd2e7cec7ef
equal deleted inserted replaced
17:2669f8761a99 18:fbd2e7cec7ef
       
     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 <badesca.h>
       
    20 #include <ximpbase.h>
       
    21 #include <ximpserviceinfo.h>
       
    22 #include <protocolpresencefeatures.h>
       
    23 #include <cprotocolimfeatures.h>
       
    24 #include <protocolpresencedatahost.h>
       
    25 #include <presenceobjectfactory.h>  
       
    26 
       
    27 #include <ximpcontextclientinfo.h>		
       
    28 #include <protocolpresenceauthorization.h>  
       
    29 #include <ximpprotocolconnectionhost.h>			   
       
    30 #include <ximpfeatureinfo.h> //for etc. KPublish
       
    31 #include <msimpleconnection.h> //Part of Registration API from SIMPLE engine
       
    32 #include <msimpleconnectionobserver.h>//Connection callback methods
       
    33 #include <presenceinfo.h>
       
    34 
       
    35 #include "presencepluginconnection.h"
       
    36 #include "presencepluginsession.h" 
       
    37 #include "mpresencepluginconnectionobs.h"   
       
    38 #include "presencepluginwatcher.h"
       
    39 #include "presencepluginauthorization.h"
       
    40 #include "presencepluginwinfo.h"
       
    41 #include "presencepluginpublisher.h"
       
    42 #include "presenceplugingroup.h"
       
    43 #include "presencepluginxdmutils.h"
       
    44 #include "presencepluginvirtualgroup.h"
       
    45 #include "presenceconnectioninfo.h"
       
    46 #include "presenceplugindata.h"
       
    47 
       
    48 #include "simpleimpluginuids.hrh" //KImplUidSimpleImPlugin
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CPresencePluginConnection::CPresencePluginConnection()
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CPresencePluginConnection::CPresencePluginConnection( ): 
       
    57 	CActive( CActive::EPriorityHigh ), iSipPresentity(NULL),
       
    58     iStopPublishState( EFalse ), iGrantListSubs( EFalse ), iStopPublishCall( EFalse ),
       
    59     iTerminatedCall( EFalse )
       
    60     {
       
    61     DP_SDA("CPresencePluginConnection::CPresencePluginConnection");
       
    62     CActiveScheduler::Add(this);
       
    63     iOwnTupleId = 0;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CPresencePluginConnection::NewL()
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CPresencePluginConnection* CPresencePluginConnection::NewL(
       
    71     const MXIMPServiceInfo& aServiceInfo,
       
    72     const MXIMPContextClientInfo& aClientCtxInfo )
       
    73     {
       
    74     DP_SDA("CPresencePluginConnection::NewL");
       
    75     CPresencePluginConnection* self = 
       
    76         new( ELeave ) CPresencePluginConnection( );
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aServiceInfo, aClientCtxInfo );
       
    79     CleanupStack::Pop( self );    
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CPresencePluginConnection::NewL() loaded
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CPresencePluginConnection* CPresencePluginConnection::NewL(
       
    88     const MXIMPServiceInfo& aServiceInfo,
       
    89     const MXIMPContextClientInfo& aClientCtxInfo,
       
    90     const TDesC8& aETag )
       
    91     {
       
    92     DP_SDA("CPresencePluginConnection::NewL loaded");
       
    93     CPresencePluginConnection* self = 
       
    94         new( ELeave ) CPresencePluginConnection( );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL( aServiceInfo, aClientCtxInfo, aETag );
       
    97     CleanupStack::Pop( self );    
       
    98     return self;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CPresencePluginConnection::ConstructL() loaded
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CPresencePluginConnection::ConstructL(
       
   106     const MXIMPServiceInfo& aServiceInfo,
       
   107     const MXIMPContextClientInfo& /*aClientCtxInfo*/,
       
   108     const TDesC8& aETag )
       
   109     {
       
   110     DP_SDA("CPresencePluginConnection::ConstructL loaded");
       
   111     
       
   112     iETag = aETag.AllocL();                  
       
   113     
       
   114     iSession = CPresencePluginSession::NewL( aServiceInfo, *this );
       
   115             
       
   116     // create instance from data class
       
   117     iPresenceData = CPresencePluginData::NewL( *this,
       
   118         aServiceInfo.IapId() ); 
       
   119     
       
   120     DP_SDA("ConstructL create subscribed buddy list loaded ");  
       
   121     // create another virtual group for all subscribed buddyes
       
   122     iSubscribedBuddys =
       
   123         CPresencePluginVirtualGroup::NewL( *this, 
       
   124         KPresenceBuddyList(),
       
   125         iPresenceData );
       
   126 
       
   127     iAuth = CPresencePluginAuthorization::NewL( *this, iPresenceData );
       
   128     
       
   129     iPublisher = CPresencePluginPublisher::NewL(
       
   130                *this,        
       
   131                *iSession->SimpleConnection(),
       
   132                iPresenceData );
       
   133     
       
   134     iWatcher = CPresencePluginWatcher::NewL(
       
   135                *this,
       
   136                *iSession->SimpleConnection(),
       
   137                iPresenceData ); 
       
   138     
       
   139     iGroups = CPresencePluginGroups::NewL( 
       
   140         *this, iSubscribedBuddys, iPresenceData );
       
   141     
       
   142     iPluginWinfo = CPresencePluginWinfo::NewL( 
       
   143                  *this, *(iSession->SimpleConnection() ));
       
   144     
       
   145     }    
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CPresencePluginConnection::ConstructL()
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CPresencePluginConnection::ConstructL(
       
   152     const MXIMPServiceInfo& aServiceInfo,
       
   153     const MXIMPContextClientInfo& /*aClientCtxInfo*/ )
       
   154     {
       
   155     DP_SDA("CPresencePluginConnection::ConstructL");
       
   156      
       
   157     iETag = KNullDesC8().AllocL();                  
       
   158     
       
   159     iSession = CPresencePluginSession::NewL( aServiceInfo, *this );
       
   160             
       
   161     // create instance from data class
       
   162     iPresenceData = CPresencePluginData::NewL( *this, 
       
   163         aServiceInfo.IapId() ); 
       
   164 
       
   165     DP_SDA("ConstructL create subscribed buddy list");	
       
   166     // create another virtual group for all subscribed buddyes
       
   167     iSubscribedBuddys =
       
   168     	CPresencePluginVirtualGroup::NewL( 
       
   169     	    *this, KPresenceBuddyList(), iPresenceData );
       
   170 
       
   171     iAuth = CPresencePluginAuthorization::NewL( *this, iPresenceData );
       
   172     
       
   173     iPublisher = CPresencePluginPublisher::NewL(
       
   174                *this,        
       
   175                *iSession->SimpleConnection(),
       
   176                iPresenceData );
       
   177     
       
   178     iWatcher = CPresencePluginWatcher::NewL(
       
   179                *this,
       
   180                *iSession->SimpleConnection(),
       
   181                iPresenceData ); 
       
   182       
       
   183     iGroups = CPresencePluginGroups::NewL( 
       
   184         *this, iSubscribedBuddys, iPresenceData );
       
   185     
       
   186     iPluginWinfo = CPresencePluginWinfo::NewL( 
       
   187                  *this, *(iSession->SimpleConnection() ));   
       
   188                                       
       
   189     }    
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CPresencePluginConnection::~CPresencePluginConnection()
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 CPresencePluginConnection::~CPresencePluginConnection()
       
   196     {
       
   197     DP_SDA("CPresencePluginConnection::~CPresencePluginConnection");
       
   198     
       
   199     Cancel();
       
   200     
       
   201     delete iSipPresentity;
       
   202     iSipPresentity = NULL;
       
   203     
       
   204     delete iPluginWinfo;
       
   205     iPluginWinfo = NULL;
       
   206     
       
   207     delete iWatcher;
       
   208     iWatcher = NULL;
       
   209     
       
   210     delete iPublisher;
       
   211     iPublisher = NULL;
       
   212     
       
   213     delete iAuth;
       
   214     iAuth = NULL;
       
   215     
       
   216     delete iGroups;
       
   217     iGroups = NULL;
       
   218     
       
   219     delete iSession;
       
   220     iSession = NULL;
       
   221     
       
   222     delete iImFeatures;
       
   223     
       
   224     REComSession::FinalClose();
       
   225     
       
   226     delete iSubscribedBuddys;
       
   227     delete iPresenceData;
       
   228     
       
   229     delete iETag;
       
   230     iETag = NULL;
       
   231     DP_SDA("CPresencePluginConnection::~CPresencePluginConnection end");
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CPresencePluginConnection::PrimeHost
       
   236 // ---------------------------------------------------------------------------
       
   237 //  
       
   238 void CPresencePluginConnection::PrimeHost( 
       
   239     MXIMPProtocolConnectionHost& aHost )
       
   240     {
       
   241     DP_SDA("CPresencePluginConnection::PrimeHost");
       
   242     iConnectionHost = &aHost;
       
   243     iAuth->SetDataHost( 
       
   244         iConnectionHost->ProtocolPresenceDataHost().AuthorizationDataHost() );  
       
   245     }
       
   246     
       
   247 // ---------------------------------------------------------------------------
       
   248 // CPresencePluginConnection::GetOnlineBuddyGroup()
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 CPresencePluginVirtualGroup* CPresencePluginConnection::SubscribedContacts( )
       
   252     {
       
   253     return iSubscribedBuddys;
       
   254     }
       
   255     
       
   256 // ---------------------------------------------------------------------------
       
   257 // CPresencePluginConnection::GetSessionStatus()
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 TBool CPresencePluginConnection::GetSessionStatus( )
       
   261     {
       
   262     return iSession->ConnectionStatus();
       
   263     }
       
   264     
       
   265 // ---------------------------------------------------------------------------
       
   266 // CPresencePluginConnection::TupleIdGet()
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 TInt CPresencePluginConnection::GetTupleId() const
       
   270     {
       
   271     DP_SDA("CPresencePluginConnection::TupleIdGet");
       
   272     return iOwnTupleId;
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CPresencePluginConnection::GetEtag()
       
   277 // ---------------------------------------------------------------------------
       
   278 //    
       
   279 const TDesC8& CPresencePluginConnection::GetETag() const
       
   280     {
       
   281     DP_SDA("CPresencePluginConnection::GetETag");
       
   282     
       
   283     if( !iETag )
       
   284         {
       
   285         DP_SDA2("CPresencePluginConnection::GetETag empty ??? %S", iConnectionArray->GetConnectionEtag() );
       
   286         return  KNullDesC8();
       
   287         }
       
   288 
       
   289     return *iETag;
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CPresencePluginConnection::SetETag()
       
   294 // ---------------------------------------------------------------------------
       
   295 //    
       
   296 void CPresencePluginConnection::SetETag( const TDesC8& aETag )
       
   297     {
       
   298     DP_SDA("CPresencePluginConnection::SetETag");
       
   299     delete iETag;
       
   300     iETag = NULL;
       
   301         
       
   302     TRAP_IGNORE( ( iETag = aETag.AllocL() ) );
       
   303     //Add etag also in connectionArray
       
   304     iConnectionArray->SetConnectionETag( *iETag );
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CPresencePluginConnection::SetConnectionArray()
       
   309 // ---------------------------------------------------------------------------
       
   310 //    
       
   311 void CPresencePluginConnection::SetConnectionArray( 
       
   312 		CPresenceConnectionInfo* aArray )
       
   313     {
       
   314     DP_SDA("CPresencePluginConnection::SetConnectionArray");
       
   315     iConnectionArray = aArray;
       
   316     iConnectionArray->SetConnectionStatus( EActive );
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CPresencePluginConnection::GetConnectionArray()
       
   321 // ---------------------------------------------------------------------------
       
   322 //    
       
   323 CPresenceConnectionInfo* CPresencePluginConnection::GetConnectionArray( )
       
   324     {
       
   325     DP_SDA("CPresencePluginConnection::GetConnectionArray");
       
   326     return iConnectionArray;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CPresencePluginConnection::TupleIdGet()
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 TInt32 CPresencePluginConnection::GetPresenceSetId() const
       
   334     {
       
   335     DP_SDA("CPresencePluginConnection::GetPresenceSetId");
       
   336     return iSession->GetPresenceSetId();
       
   337     }
       
   338     
       
   339 // ---------------------------------------------------------------------------
       
   340 // CPresencePluginConnection::TupleIdGet()
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CPresencePluginConnection::SetTupleId( const TInt aTupleId )
       
   344     {
       
   345     DP_SDA("CPresencePluginConnection::TupleIdSet");
       
   346     iOwnTupleId = aTupleId;
       
   347     }
       
   348     
       
   349 // ---------------------------------------------------------------------------
       
   350 // CPresencePluginConnection::GetStopPublishState()
       
   351 // ---------------------------------------------------------------------------
       
   352 //    
       
   353 TBool CPresencePluginConnection::GetStopPublishState()
       
   354     {
       
   355     DP_SDA2("::GetStopPublishState = %d", (TInt)iStopPublishState );
       
   356     return iStopPublishState;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CPresencePluginConnection::SetStopPublishState()
       
   361 // ---------------------------------------------------------------------------
       
   362 // 
       
   363 void CPresencePluginConnection::SetStopPublishState( TBool aState )
       
   364     {
       
   365     DP_SDA2("SetStopPublishState : aState = %d ",  (TInt)aState );
       
   366     iStopPublishState = aState;
       
   367     }
       
   368             
       
   369 // ---------------------------------------------------------------------------
       
   370 // CPresencePluginConnection::PresenceWatching
       
   371 // ---------------------------------------------------------------------------
       
   372 //    
       
   373 MProtocolPresenceDataHost& CPresencePluginConnection::ProtocolPresenceHost()
       
   374     {
       
   375     DP_SDA("CPresencePluginConnection::ProtocolPresenceHost");
       
   376     return iConnectionHost->ProtocolPresenceDataHost();
       
   377     }
       
   378      
       
   379 // ---------------------------------------------------------------------------
       
   380 // CPresencePluginConnection::PresenceWatching
       
   381 // ---------------------------------------------------------------------------
       
   382 //    
       
   383 MProtocolPresenceWatching& CPresencePluginConnection::PresenceWatching()
       
   384     {
       
   385     DP_SDA("CPresencePluginConnection::PresenceWatching");
       
   386     return *iWatcher;
       
   387     }
       
   388     
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPresencePluginConnection::PresencePublishing
       
   391 // ---------------------------------------------------------------------------
       
   392 //   
       
   393  MProtocolPresencePublishing& CPresencePluginConnection::PresencePublishing()
       
   394     {
       
   395     return *iPublisher;
       
   396     }
       
   397     
       
   398 // ---------------------------------------------------------------------------
       
   399 // CPresencePluginConnection::PresentityGroups
       
   400 // ---------------------------------------------------------------------------
       
   401 //   
       
   402 MProtocolPresentityGroups& CPresencePluginConnection::PresentityGroups()
       
   403     {
       
   404     return *iGroups;
       
   405     }
       
   406     
       
   407 // ---------------------------------------------------------------------------
       
   408 // CPresencePluginConnection::PresenceAuthorization
       
   409 // ---------------------------------------------------------------------------
       
   410 //   
       
   411 MProtocolPresenceAuthorization& 
       
   412     CPresencePluginConnection::PresenceAuthorization()
       
   413     {
       
   414     DP_SDA2("CPresencePluginConnection::PresenceAuthorization %x", iAuth);
       
   415     return *iAuth;
       
   416     }
       
   417     
       
   418 // ---------------------------------------------------------------------------
       
   419 // CPresencePluginConnection::InternalPresenceAuthorization
       
   420 // ---------------------------------------------------------------------------
       
   421 //       
       
   422 CPresencePluginAuthorization& 
       
   423     CPresencePluginConnection::InternalPresenceAuthorization()
       
   424     {
       
   425     DP_SDA2("CPresencePluginConnection::InternalPresenceAuthorization %x", iAuth);
       
   426     return *iAuth;
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // CPresencePluginConnection::OpenSessionL
       
   431 // ---------------------------------------------------------------------------
       
   432 //     
       
   433 void CPresencePluginConnection::OpenSessionL( 
       
   434     const MXIMPContextClientInfo& /*aClientCtxInfo*/,
       
   435     TXIMPRequestId aReqId )
       
   436     {
       
   437     DP_SDA("CPresencePluginConnection::OpenSessionL");
       
   438     iGrantListSubs = ETrue; 
       
   439     iTerminatedCall = EFalse;
       
   440     iXIMPId = aReqId;
       
   441     iSession->OpenSessionL();         
       
   442     }
       
   443     
       
   444 // ---------------------------------------------------------------------------
       
   445 // CPresencePluginConnection::OpenSessionL
       
   446 // ---------------------------------------------------------------------------
       
   447 // 
       
   448 void CPresencePluginConnection::OpenSessionL( const TInt& /*aSettingsId*/,
       
   449     TXIMPRequestId aReqId )
       
   450     {
       
   451     DP_SDA("CPresencePluginConnection::OpenSessionL 2 ");
       
   452     iXIMPId = aReqId;
       
   453     iGrantListSubs = ETrue; 
       
   454     iTerminatedCall = EFalse;
       
   455     iSession->OpenSessionL( ); 
       
   456     }
       
   457     
       
   458 // ---------------------------------------------------------------------------
       
   459 // CPresencePluginConnection::CloseSession
       
   460 // ---------------------------------------------------------------------------
       
   461 //    
       
   462 void CPresencePluginConnection::CloseSession( 
       
   463     const MXIMPContextClientInfo& /*aContextClient*/,
       
   464     TXIMPRequestId aReqId )
       
   465     {
       
   466     DP_SDA("CPresencePluginConnection::CloseSession begin");
       
   467     
       
   468     TBool completeXimpRequestNow( EFalse );
       
   469     iConnectionArray->DecreaseClientCount();
       
   470     iXIMPId = aReqId;
       
   471         
       
   472     // Client count can´t be negative. Increase if goes negative.
       
   473     // This happens for example in network lost case.
       
   474     // This method is called then because connection is terminated and
       
   475     // for all clients which have done unbind. But here we cannot tell
       
   476     // if this method is called by clients unbind or connection termination
       
   477     // therefore this workaround needed.
       
   478     if ( iConnectionArray->ClientCount() < 0 )
       
   479         {        
       
   480         completeXimpRequestNow = ETrue;
       
   481         iConnectionArray->IncreaseClientCount();
       
   482         }
       
   483     
       
   484     // In case there is no more clients we cannot complete Ximp request
       
   485     // right away. We have to stop publish first, Ximp request completion is
       
   486     // handled in RunL after that is done.
       
   487     if( KErrNone == iConnectionArray->ClientCount() && 
       
   488         (EActive == iConnectionArray->GetConnectionStatus()) )
       
   489         {       
       
   490         completeXimpRequestNow = EFalse; // request is completed later in RunL
       
   491         iGrantListSubs = EFalse;
       
   492         
       
   493         //Start stopPublish request
       
   494         DeRegister();
       
   495         }
       
   496         
       
   497     if ( !iStopPublishCall )
       
   498        {
       
   499        completeXimpRequestNow = ETrue;
       
   500        }
       
   501     
       
   502     if ( completeXimpRequestNow )
       
   503         {
       
   504         CompleteReq( iXIMPId, KErrNone );
       
   505         }
       
   506 
       
   507     DP_SDA("CPresencePluginConnection::CloseSession end");
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // CPresencePluginConnection::GetSupportedFeaturesL
       
   512 // ---------------------------------------------------------------------------
       
   513 //     
       
   514 void CPresencePluginConnection::GetSupportedFeaturesL( 
       
   515     CDesC8Array& aFeatures ) const
       
   516     {
       
   517     DP_SDA("CPresencePluginConnection::GetSupportedFeaturesL");
       
   518     // first empty the whole array
       
   519     aFeatures.Reset();   
       
   520     using namespace NXIMPFeature::Presence;    
       
   521     aFeatures.AppendL( KPublish );
       
   522     aFeatures.AppendL( KSubscribe );    
       
   523     aFeatures.AppendL( KUnsubscribe );  
       
   524     aFeatures.AppendL( KAddContact );
       
   525     aFeatures.AppendL( KDeleteContact );
       
   526     aFeatures.AppendL( KFetch );
       
   527     aFeatures.AppendL( KBlock );
       
   528     aFeatures.AppendL( KUnBlock );
       
   529     
       
   530     if( iImFeatures )
       
   531         {
       
   532         using namespace NXIMPFeature::InstantMessage;
       
   533         aFeatures.AppendL( KInstantMessage );
       
   534         }
       
   535     }
       
   536 
       
   537 //*****************************************************************************
       
   538 //*  FROM MPresencePluginConnectionObs
       
   539 //*****************************************************************************  
       
   540 // ---------------------------------------------------------------------------
       
   541 // CPresencePluginConnection::CompleteReq()
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CPresencePluginConnection::CompleteReq( TReqType aType, TInt aStatus )
       
   545     {
       
   546     DP_SDA("CPresencePluginConnection::CompleteReq");
       
   547     // Return immediately if PrimeHost() is not called.
       
   548     if ( !iConnectionHost )
       
   549         {
       
   550         DP_SDA("CPresencePluginConnection::CompleteReq !iConnectionHost");
       
   551         iXIMPId = TXIMPRequestId(); 
       
   552         return;
       
   553         }
       
   554                       
       
   555     switch ( aType )
       
   556         {
       
   557         case EOpenSess:
       
   558             {
       
   559             DP_SDA("CPresencePluginConnection::CompleteReq EOpenSess");          
       
   560             iConnectionHost->HandleRequestCompleted( iXIMPId, aStatus );
       
   561             iXIMPId = TXIMPRequestId();
       
   562             //Set connection status to connection Array
       
   563             iConnectionArray->SetConnectionStatus( EActive );
       
   564             }
       
   565             break;
       
   566         case ECloseSess:
       
   567             {
       
   568             DP_SDA("CPresencePluginConnection::CompleteReq ECloseSess"); 
       
   569             iConnectionArray->DecreaseClientCount();
       
   570             CompleteReq( iXIMPId, aStatus );
       
   571             iConnectionArray->SetConnectionStatus( ENotActive );
       
   572             }
       
   573             break;
       
   574         default:
       
   575             DP_SDA("CPresencePluginConnection::CompleteReq DEFAULT");  
       
   576             break;   
       
   577         };
       
   578     DP_SDA("CPresencePluginConnection::CompleteReq end"); 
       
   579     }
       
   580         
       
   581 // ---------------------------------------------------------------------------
       
   582 // CPresencePluginConnection::CompleteReq()
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 void CPresencePluginConnection::CompleteReq( 
       
   586     TXIMPRequestId aReqId,
       
   587     TInt aStatus )
       
   588     { 
       
   589     DP_SDA2("CPresencePluginConnection::CompleteReq status %d", aStatus); 
       
   590     // Return immediately if PrimeHost() is not called.
       
   591     if ( !iConnectionHost )
       
   592         {
       
   593         DP_SDA("CPresencePluginConnection::CompleteReq return"); 
       
   594         return;
       
   595         }               
       
   596     DP_SDA("CPresencePluginConnection::CompleteReq complete");               
       
   597     iConnectionHost->HandleRequestCompleted( aReqId, aStatus );
       
   598     } 
       
   599 
       
   600 // ---------------------------------------------------------------------------
       
   601 // CPresencePluginConnection::ObjectFactory()
       
   602 // ---------------------------------------------------------------------------
       
   603 // 
       
   604 MXIMPObjectFactory& CPresencePluginConnection::ObjectFactory()
       
   605     {
       
   606     DP_SDA("CPresencePluginConnection::ObjectFactory");
       
   607     return iConnectionHost->ObjectFactory();
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // CPresencePluginConnection::Host
       
   612 // ---------------------------------------------------------------------------
       
   613 //     
       
   614 MXIMPProtocolConnectionHost* CPresencePluginConnection::Host()
       
   615     {
       
   616     DP_SDA("CPresencePluginConnection::Host");
       
   617     return iConnectionHost;
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // CPresencePluginConnection:CurrentDomain
       
   622 // ---------------------------------------------------------------------------
       
   623 //     
       
   624 TPtrC16 CPresencePluginConnection::CurrentDomain()
       
   625     {
       
   626     return iSession->CurrentDomain();    
       
   627     } 
       
   628      
       
   629 // ---------------------------------------------------------------------------
       
   630 // CPresencePluginConnection::CurrentSipPresentit8()
       
   631 // ---------------------------------------------------------------------------
       
   632 // 
       
   633 TPtrC8 CPresencePluginConnection::CurrentSipPresentity8()
       
   634     {
       
   635     return iSession->CurrentSipPresentity();
       
   636     } 
       
   637     
       
   638 // ---------------------------------------------------------------------------
       
   639 // CPresencePluginConnection:XdmUtilsL
       
   640 // ---------------------------------------------------------------------------
       
   641 //
       
   642 CPresencePluginXdmUtils* CPresencePluginConnection::XdmUtilsL()
       
   643     {
       
   644     DP_SDA("CPresencePluginConnection::XdmUtilsL");
       
   645     return iSession->XdmUtilsL();
       
   646     } 
       
   647     
       
   648 // ---------------------------------------------------------------------------
       
   649 // CPresencePluginConnection::WinfoHandlerL()
       
   650 // ---------------------------------------------------------------------------
       
   651 //
       
   652 CPresencePluginWinfo* CPresencePluginConnection::WinfoHandlerL()
       
   653     {
       
   654     DP_SDA("CPresencePluginConnection::WinfoHandlerL");
       
   655     if ( !iPluginWinfo )
       
   656         {
       
   657         iPluginWinfo = CPresencePluginWinfo::NewL( 
       
   658             *this, *(iSession->SimpleConnection() ));
       
   659         }
       
   660     
       
   661     iPluginWinfo->SetHost( iConnectionHost );
       
   662     return iPluginWinfo;
       
   663     }
       
   664     
       
   665 // ---------------------------------------------------------------------------
       
   666 // CPresencePluginConnection::WatcherHandlerL()
       
   667 // ---------------------------------------------------------------------------
       
   668 //    
       
   669  CPresencePluginWatcher* CPresencePluginConnection::WatcherHandlerL()
       
   670     {
       
   671     DP_SDA("CPresencePluginConnection::WatcherHandlerL");  
       
   672     if ( !iWatcher )
       
   673         {
       
   674         DP_SDA("CPresencePluginConnection::WatcherHandlerL: if ( !iWatcher )");  
       
   675         iWatcher = CPresencePluginWatcher::NewL(
       
   676             *this,
       
   677             *iSession->SimpleConnection(),
       
   678             iPresenceData );
       
   679         }
       
   680     return iWatcher;
       
   681     }
       
   682 // ---------------------------------------------------------------------------
       
   683 // CPresencePluginConnection::WinfoTerminatedL()
       
   684 // ---------------------------------------------------------------------------
       
   685 //
       
   686 void CPresencePluginConnection::WinfoTerminatedL( TInt aReason )
       
   687     {
       
   688     DP_SDA("CPresencePluginConnection::WinfoTerminatedL");  
       
   689     // Pass the information to iAuth and iPublisher,
       
   690     // so that they can call XIMP Plugin Data Host callbacks.
       
   691     iAuth->WinfoTerminatedL( aReason );
       
   692     iPublisher->WinfoTerminatedL( aReason );
       
   693     }  
       
   694     
       
   695 // ---------------------------------------------------------------------------
       
   696 // CPresencePluginConnection::WinfoNotification()
       
   697 // ---------------------------------------------------------------------------
       
   698 //
       
   699 void CPresencePluginConnection::WinfoNotification( MSimpleWinfo& aWinfo )
       
   700     {
       
   701     DP_SDA("CPresencePluginConnection::WinfoNotification");  
       
   702     TRAP_IGNORE( iPublisher->WinfoNotificationL( aWinfo  ));
       
   703     TRAP_IGNORE( iAuth->WinfoNotificationL( aWinfo ));
       
   704     }      
       
   705         
       
   706 // ---------------------------------------------------------------------------
       
   707 // CPresencePluginConnection::GetInterface()
       
   708 // ---------------------------------------------------------------------------
       
   709 //
       
   710 TAny* CPresencePluginConnection::GetInterface(
       
   711     TInt32 aInterfaceId,
       
   712     TIfGetOps aOptions )
       
   713     { 
       
   714     DP_SDA("CPresencePluginConnection::GetInterface()");  
       
   715     if ( aInterfaceId == GetInterfaceId() )
       
   716         {
       
   717         DP_SDA("CPresencePluginConnection::GetInterface()if ");
       
   718         // caller wants this interface 
       
   719         return this;
       
   720         }
       
   721     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   722         {
       
   723         DP_SDA("CPresencePluginConnection::GetInterface() panic");  
       
   724         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   725         }  
       
   726     return NULL;
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------------------------
       
   730 // CPresencePluginConnection::GetInterface()
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 const TAny* CPresencePluginConnection::GetInterface(
       
   734     TInt32 aInterfaceId,
       
   735     TIfGetOps aOptions ) const
       
   736     {
       
   737     DP_SDA("CPresencePluginConnection::GetInterface() const ");  
       
   738     if ( aInterfaceId == GetInterfaceId() )
       
   739         {
       
   740         DP_SDA("CPresencePluginConnection::GetInterface()2 ");  
       
   741         // caller wants this interface
       
   742         return const_cast<CPresencePluginConnection*>(this);
       
   743         }
       
   744     if ( aOptions == MXIMPBase::EPanicIfUnknown )
       
   745         {
       
   746         DP_SDA("CPresencePluginConnection::GetInterface()panic 2");  
       
   747         User::Panic( KPluginName, KErrExtensionNotSupported );
       
   748         }  
       
   749     return NULL;
       
   750     }
       
   751 
       
   752 // ---------------------------------------------------------------------------
       
   753 // CPresencePluginConnection::GetInterfaceId()
       
   754 // ---------------------------------------------------------------------------
       
   755 //
       
   756 TInt32 CPresencePluginConnection::GetInterfaceId() const
       
   757     {
       
   758     DP_SDA("CPresencePluginConnection::GetInterfaceId() const ");  
       
   759     return MXIMPProtocolConnection::KInterfaceId;
       
   760     }
       
   761 
       
   762 // ---------------------------------------------------------------------------
       
   763 // CPresencePluginConnection::ProtocolPresenceFeatures()
       
   764 // ---------------------------------------------------------------------------
       
   765 //    
       
   766 MProtocolPresenceFeatures& CPresencePluginConnection::
       
   767     ProtocolPresenceFeatures()           
       
   768     {
       
   769     DP_SDA("CPresencePluginConnection::ProtocolPresenceFeatures() ");  
       
   770     return *this;
       
   771     }
       
   772     
       
   773 // ---------------------------------------------------------------------------
       
   774 // CPresencePluginConnection::PresenceObjectFactory()
       
   775 // ---------------------------------------------------------------------------
       
   776 // 
       
   777 MPresenceObjectFactory& CPresencePluginConnection::PresenceObjectFactoryOwn()
       
   778     {
       
   779     DP_SDA("CPresencePluginConnection::PresenceObjectFactoryOwn() ");  
       
   780     return iConnectionHost->
       
   781         ProtocolPresenceDataHost().PresenceObjectFactory();    
       
   782     }  
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // CPresencePluginConnection::GrandListState()
       
   786 // ---------------------------------------------------------------------------
       
   787 // 
       
   788 TBool CPresencePluginConnection::GrandListState( )
       
   789     {
       
   790     DP_SDA2("GrandListState : iGrantListSubs = %d", (TInt)iGrantListSubs );
       
   791     return iGrantListSubs;
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // CPresencePluginConnection::IsStopPublishCalled()
       
   796 // ---------------------------------------------------------------------------
       
   797 // 
       
   798 TBool CPresencePluginConnection::IsStopPublishCalled( )
       
   799     {
       
   800     DP_SDA("CPresencePluginConnection::IsStopPublishCalled");
       
   801     return iStopPublishCall;
       
   802     }
       
   803 
       
   804 // ---------------------------------------------------------------------------
       
   805 // CPresencePluginConnection::TerminateConnectionL()
       
   806 // ---------------------------------------------------------------------------
       
   807 // 
       
   808 void CPresencePluginConnection::TerminateConnectionL( )
       
   809     {
       
   810     DP_SDA("CPresencePluginConnection::TerminateConnectionL");
       
   811     iConnectionHost->HandleConnectionTerminated( NULL );
       
   812     iConnectionArray->SetConnectionStatus( ETerminated );
       
   813     DP_SDA("CPresencePluginConnection::TerminateConnectionL Done");
       
   814     }
       
   815 
       
   816 // ---------------------------------------------------------------------------
       
   817 // CPresencePluginConnection::DeRegister()
       
   818 // ---------------------------------------------------------------------------
       
   819 // 
       
   820 void CPresencePluginConnection::DeRegister( )
       
   821     {
       
   822     DP_SDA("CPresencePluginConnection::Deregister");
       
   823     
       
   824     DP_SDA(" -> CloseSession, delete permanent pres data");
       
   825     TRAP_IGNORE( iPresenceData->DeletePresenceVariablesL( ServiceId() ) );
       
   826     
       
   827     // Try to stop publish only if we have successfully published
       
   828     if ( iPublisher->Published() )
       
   829         {
       
   830         DP_SDA("CloseSession call stopPublish");
       
   831         TRAP_IGNORE( iPublisher->StopPublishL( iStatus ) );
       
   832         iStopPublishCall = ETrue;
       
   833         SetActive();
       
   834         }
       
   835     
       
   836     DP_SDA("CPresencePluginConnection::Deregister Done");
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // CPresencePluginConnection::CreateImFeaturesPlugin()
       
   841 // ---------------------------------------------------------------------------
       
   842 //
       
   843 void CPresencePluginConnection::CreateImFeaturesPluginL( )
       
   844     {
       
   845     if ( !iImFeatures )
       
   846         {
       
   847         DP_SDA("Creating SimpleImPlugin");
       
   848         
       
   849         CSimpleImFeatures::TSimpleImPluginInitParams imPluginInitParams( 
       
   850             *this,
       
   851             *iSession->SimpleConnection(),
       
   852             iSession->ServiceId() );
       
   853         
       
   854         iImFeatures = static_cast<CSimpleImFeatures*> ( 
       
   855             CProtocolImFeatures::NewL( TUid::Uid(KImplUidSimpleImPlugin),
       
   856             &imPluginInitParams ) );
       
   857         
       
   858         DP_SDA("Creating SimpleImPlugin done");
       
   859         }
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // CPresencePluginConnection::DeleteImFeaturesPlugin()
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 void CPresencePluginConnection::DeleteImFeaturesPlugin( )
       
   867     {
       
   868     if ( iImFeatures )
       
   869         {
       
   870         DP_SDA("Deleting SimpleImPlugin");
       
   871         
       
   872         delete iImFeatures;
       
   873         iImFeatures = NULL;      
       
   874         REComSession::FinalClose();
       
   875         
       
   876         DP_SDA("Deleting SimpleImPlugin done");
       
   877         }
       
   878     }
       
   879 
       
   880 // ---------------------------------------------------------------------------
       
   881 // CPresencePluginConnection::DoCancel()
       
   882 // ---------------------------------------------------------------------------
       
   883 //
       
   884 void CPresencePluginConnection::DoCancel(  )
       
   885     {
       
   886     DP_SDA("CPresencePluginConnection::DoCancel CANCEL");
       
   887     iPublisher->Cancel();
       
   888     }
       
   889 
       
   890 // ---------------------------------------------------------------------------
       
   891 // CPresencePluginConnection::RunL()
       
   892 // ---------------------------------------------------------------------------
       
   893 //
       
   894 void CPresencePluginConnection::RunL(  )
       
   895     {
       
   896     DP_SDA("CPresencePluginConnection::RunL");
       
   897     TInt status = iStatus.Int();
       
   898     DP_SDA2("CPresencePluginConnection::RunL status %d", status );
       
   899     
       
   900     if ( iStopPublishCall )
       
   901         {
       
   902         DP_SDA("CPresencePluginConnection::RunL complete");     
       
   903         
       
   904         iStopPublishCall = EFalse;
       
   905         CompleteReq( iXIMPId, status );      
       
   906         
       
   907         DP_SDA("CPresencePluginConnection::RunL --> REMOVE CACHE");
       
   908         iPresenceData->RemoveCacheL();
       
   909         
       
   910         DP_SDA("CPresencePluginConnection::RunL --> Delete im plugin");
       
   911         DeleteImFeaturesPlugin();
       
   912         }
       
   913     }
       
   914 
       
   915 // ---------------------------------------------------------------------------
       
   916 // CPresencePluginConnection::RunError
       
   917 // ---------------------------------------------------------------------------
       
   918 //
       
   919 TInt CPresencePluginConnection::RunError( TInt /*aError*/ )
       
   920     {
       
   921     DP_SDA("CPresencePluginConnection::RunError"); 
       
   922     return KErrNone;
       
   923     }
       
   924 
       
   925 // ---------------------------------------------------------------------------
       
   926 // CPresencePluginConnection::GroupsL()
       
   927 // ---------------------------------------------------------------------------
       
   928 // 
       
   929 CPresencePluginGroups& CPresencePluginConnection::GroupsL()
       
   930 	{
       
   931 	User::LeaveIfNull( iGroups );
       
   932 	return *iGroups;
       
   933 	}
       
   934     
       
   935 // ---------------------------------------------------------------------------
       
   936 // CPresencePluginConnection::ServiceId()
       
   937 // ---------------------------------------------------------------------------
       
   938 // 	
       
   939 TInt& CPresencePluginConnection::ServiceId()
       
   940     {
       
   941     return iSession->ServiceId();
       
   942     }
       
   943 	
       
   944 // ---------------------------------------------------------------------------
       
   945 // CPresencePluginConnection::GetProtocolInterface()
       
   946 // ---------------------------------------------------------------------------
       
   947 // 
       
   948 TAny* CPresencePluginConnection::GetProtocolInterface( TInt aInterfaceId )
       
   949 	{
       
   950 	DP_SDA("CPresencePluginConnection::GetProtocolInterface");
       
   951 	
       
   952 	if( aInterfaceId == CProtocolImFeatures::KInterfaceId )
       
   953         {
       
   954         TInt err( KErrNone );
       
   955         
       
   956         if ( !iImFeatures )
       
   957             {
       
   958             DP_SDA("    --> Create im features plugin");           
       
   959             TRAP( err, CreateImFeaturesPluginL() );
       
   960             }
       
   961         
       
   962         if ( !err )
       
   963             {
       
   964             DP_SDA("    --> get interface");
       
   965             
       
   966             return iImFeatures->GetInterface( 
       
   967                 aInterfaceId, MXIMPBase::EPanicIfUnknown );
       
   968             }
       
   969         else
       
   970             {
       
   971             DP_SDA("    --> Creating im features plugin failed");
       
   972             return NULL;
       
   973             }
       
   974         }
       
   975 	else
       
   976         {
       
   977 	    return NULL;
       
   978         }
       
   979 	}
       
   980     
       
   981 // End of file