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