presencefwsimpleadpt/src/simplepluginconnection.cpp
branchGCC_SURGE
changeset 28 d9861ae9169c
parent 23 77cb48a03620
parent 26 04ca1926b01c
equal deleted inserted replaced
23:77cb48a03620 28:d9861ae9169c
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    SIMPLE Protocol implementation for Presence Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 
       
    23 #include <ximpstatus.h>
       
    24 #include <ximpserviceinfo.h>
       
    25 #include <ximpcontextclientinfo.h>
       
    26 #include <ximpprotocolconnectionhost.h>
       
    27 #include <ximpfeatureinfo.h>
       
    28 #include <ximpidentity.h>
       
    29 #include <ximperrors.hrh>
       
    30 #include <presenceerrors.hrh>
       
    31 
       
    32 #include <protocolpresencedatahost.h>
       
    33 
       
    34 #include "simplepluginconnection.h"
       
    35 #include "simplepluginsession.h"
       
    36 #include "simpleplugindebugutils.h"
       
    37 #include "simplepluginauthorization.h"
       
    38 #include "simplepluginwinfo.h"
       
    39 #include "simplepluginpublisher.h"
       
    40 #include "simplepluginwatcher.h"
       
    41 #include "simpleplugingroups.h"
       
    42 #include "simplepluginxdmutils.h"
       
    43 #include "simplepluginvariation.h"
       
    44 #include "msimplepluginconnectionobs.h"
       
    45 #include "msimplepluginsettings.h"
       
    46 #include "simpleerrors.h"
       
    47 
       
    48 class MXIMPObjectFactory;
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CSimplePluginConnection::CSimplePluginConnection
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CSimplePluginConnection::CSimplePluginConnection()
       
    58 : iSipPresentity(NULL)
       
    59     {
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CSimplePluginConnection::NewL
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CSimplePluginConnection* CSimplePluginConnection::NewL( 
       
    67     const MXIMPServiceInfo& aServiceInfo,
       
    68     const MXIMPContextClientInfo& aClientCtxInfo )
       
    69     {
       
    70     CSimplePluginConnection* self = new( ELeave ) CSimplePluginConnection(  );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL( aServiceInfo, aClientCtxInfo );
       
    73     CleanupStack::Pop( self );    
       
    74     return self;
       
    75     }
       
    76     
       
    77 // ---------------------------------------------------------------------------
       
    78 // CSimplePluginConnection::ConstructL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CSimplePluginConnection::ConstructL( 
       
    82     const MXIMPServiceInfo& aServiceInfo,
       
    83     const MXIMPContextClientInfo& /* aClientCtxInfo */ )
       
    84     {                  
       
    85     iSession = CSimplePluginSession::NewL( aServiceInfo, *this ); 
       
    86    
       
    87     iAuth = CSimplePluginAuthorization::NewL( *this );   
       
    88         
       
    89     iPublisher = CSimplePluginPublisher::NewL(
       
    90         *this, *this,        
       
    91         *iSession->SimpleConnection() ); 
       
    92         
       
    93     iWatcher = CSimplePluginWatcher::NewL(
       
    94         *this, *this,
       
    95         *iSession->SimpleConnection() ); 
       
    96         
       
    97     iGroups = CSimplePluginGroups::NewL( 
       
    98         *this );
       
    99     
       
   100     iPluginWinfo = CSimplePluginWinfo::NewL( 
       
   101         *this, *(iSession->SimpleConnection()));  
       
   102         
       
   103     iVariation = CSimplePluginVariation::NewL();    
       
   104     iVariation->InitL();      
       
   105     }    
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CSimplePluginConnection::~CSimplePluginConnection
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CSimplePluginConnection::~CSimplePluginConnection()
       
   112     {     
       
   113     
       
   114     delete iSipPresentity;
       
   115     
       
   116     delete iVariation;                   
       
   117     delete iPluginWinfo;    
       
   118     delete iWatcher;
       
   119     delete iPublisher;
       
   120     delete iAuth;   
       
   121     delete iGroups; 
       
   122     delete iSession;       
       
   123     
       
   124     delete iXdmUtils;    
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CSimplePluginConnection::PrimeHost
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CSimplePluginConnection::PrimeHost( MXIMPProtocolConnectionHost& aHost )
       
   132     {
       
   133     iConnectionHost = &aHost;
       
   134     iAuth->SetDataHost( iConnectionHost->ProtocolPresenceDataHost().AuthorizationDataHost() );
       
   135     }
       
   136     
       
   137     
       
   138 // ---------------------------------------------------------------------------
       
   139 // CSimplePluginConnection::ProtocolPresenceFeatures
       
   140 // ---------------------------------------------------------------------------
       
   141 //  
       
   142 MProtocolPresenceFeatures& CSimplePluginConnection::ProtocolPresenceFeatures()
       
   143     {
       
   144     return *this;
       
   145     }
       
   146     
       
   147 /*<branchInfo originator="gronoff" since="08-06-06" category="new_feature" error=”none”>
       
   148 <pf_5250_OFF_CYCLE_SW_INT>
       
   149 </branchInfo>*/
       
   150 // BRANCH 08-06-17 : gronoff
       
   151 // ---------------------------------------------------------------------------
       
   152 // CPresencePluginConnection::GetProtocolInterface()
       
   153 // ---------------------------------------------------------------------------
       
   154 // 
       
   155 TAny* CSimplePluginConnection::GetProtocolInterface( TInt /*aInterfaceId*/ )
       
   156 	{
       
   157 	return NULL;
       
   158 	}
       
   159 // BRANCH_END 08-06-17 : gronoff   
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CSimplePluginConnection::PresenceWatching
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 MProtocolPresenceWatching& CSimplePluginConnection::PresenceWatching()
       
   166     {   
       
   167     return *iWatcher;
       
   168     }
       
   169 // ---------------------------------------------------------------------------
       
   170 // CSimplePluginConnection::PresencePublishing
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 MProtocolPresencePublishing& CSimplePluginConnection::PresencePublishing()
       
   174     {
       
   175     return *iPublisher;
       
   176     }
       
   177 // ---------------------------------------------------------------------------
       
   178 // CSimplePluginConnection::PresentityGroups
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 MProtocolPresentityGroups& CSimplePluginConnection::PresentityGroups()
       
   182     {
       
   183     return *iGroups;
       
   184     }
       
   185 // ---------------------------------------------------------------------------
       
   186 // CSimplePluginConnection::PresenceAuthorization
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 MProtocolPresenceAuthorization& CSimplePluginConnection::PresenceAuthorization()
       
   190     {      
       
   191     return *iAuth;
       
   192     }
       
   193     
       
   194     
       
   195 // ---------------------------------------------------------------------------
       
   196 // CSimplePluginConnection::OpenSessionL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CSimplePluginConnection::OpenSessionL(
       
   200     const TInt& aSettingsId,
       
   201     TXIMPRequestId aReqId )
       
   202     {
       
   203 #ifdef _DEBUG
       
   204     PluginLogger::Log(_L("PluginConnection: OpenSessionL"));
       
   205 #endif             
       
   206     iPrFwId = aReqId;
       
   207     TRAPD( err, iSession->OpenSessionL( aSettingsId )); 
       
   208     if ( err )
       
   209         {
       
   210         User::Leave( CSimplePluginConnection::HarmonizeErrorCode( err ));
       
   211         }     
       
   212     }  
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CSimplePluginConnection::OpenSessionL
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CSimplePluginConnection::OpenSessionL( 
       
   219     const MXIMPContextClientInfo& /*aClientCtxInfo*/,
       
   220     TXIMPRequestId /*aReqId*/ )
       
   221     {   
       
   222 #ifdef _DEBUG
       
   223     PluginLogger::Log(_L("PluginConnection: OpenSessionL - error: not supported"));
       
   224 #endif    
       
   225     User::Leave( KErrNotSupported );           
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CSimplePluginConnection::CloseSession
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CSimplePluginConnection::CloseSession( 
       
   233     const MXIMPContextClientInfo& /*aClientCtxInfo*/,
       
   234     TXIMPRequestId aReqId )
       
   235     {
       
   236 #ifdef _DEBUG
       
   237     PluginLogger::Log(_L("PluginConnection: CloseSession"));
       
   238 #endif          
       
   239     iPrFwId = aReqId;
       
   240     
       
   241     delete iPluginWinfo;
       
   242     iPluginWinfo = NULL;    
       
   243     delete iWatcher;
       
   244     iWatcher = NULL;
       
   245     delete iPublisher;
       
   246     iPublisher = NULL;
       
   247     delete iAuth;    
       
   248     iAuth = NULL;
       
   249     delete iSession;    
       
   250     iSession = NULL;
       
   251     delete iGroups;
       
   252     iGroups = NULL; 
       
   253     delete iXdmUtils;
       
   254     iXdmUtils = NULL; 
       
   255     
       
   256     CompleteReq( iPrFwId, KErrNone );          
       
   257     }
       
   258 // ---------------------------------------------------------------------------
       
   259 // CSimplePluginConnection::GetSupportedFeaturesL
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CSimplePluginConnection::GetSupportedFeaturesL( CDesC8Array& aFeatures ) const
       
   263     {
       
   264     // first empty the whole array
       
   265     aFeatures.Reset();   
       
   266     using namespace NXIMPFeature::Presence;    
       
   267     aFeatures.AppendL( KPublish );
       
   268     aFeatures.AppendL( KFetch );    
       
   269     aFeatures.AppendL( KSubscribe );    
       
   270     aFeatures.AppendL( KUnsubscribe  );    
       
   271     }
       
   272     
       
   273 // ---------------------------------------------------------------------------
       
   274 // CSimplePluginConnection::CompleteReq
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CSimplePluginConnection::CompleteReq( TReqType aType, TInt aStatus )
       
   278     {
       
   279 #ifdef _DEBUG
       
   280     PluginLogger::Log(_L("PluginConnection: CompleteReq stat=%d"), aStatus);
       
   281 #endif         
       
   282 
       
   283     TInt retVal = HarmonizeErrorCode( aStatus );
       
   284     
       
   285     // Return immediately if PrimeHost() is not called. This is for testing purposes. 
       
   286     if ( !iConnectionHost )
       
   287         {
       
   288         iPrFwId = TXIMPRequestId(); 
       
   289         return;
       
   290         }
       
   291                       
       
   292     switch ( aType )
       
   293         {
       
   294         case EOpenSess:
       
   295 #ifdef _DEBUG
       
   296     PluginLogger::Log(
       
   297         _L("PluginConnection: callback HandleRequestCompleted stat=%d"), retVal);
       
   298     PluginLogger::Log(
       
   299         _L("PluginConnection: ------------------------------------------------1"));        
       
   300 #endif          
       
   301             iConnectionHost->HandleRequestCompleted( iPrFwId, retVal );
       
   302             iPrFwId = TXIMPRequestId();             
       
   303             break;
       
   304         default: 
       
   305             break;   
       
   306         };
       
   307     }
       
   308         
       
   309 // ---------------------------------------------------------------------------
       
   310 // CSimplePluginConnection::CompleteReq
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 void CSimplePluginConnection::CompleteReq( TXIMPRequestId aReqId, TInt aStatus )
       
   314     {    
       
   315 #ifdef _DEBUG
       
   316     PluginLogger::Log(_L("PluginConnection: CompleteReq stat=%d"), aStatus);
       
   317 #endif
       
   318 
       
   319     TInt retVal = HarmonizeErrorCode( aStatus );
       
   320                    
       
   321     // Return immediately if PrimeHost() is not called. This is for testing purposes.
       
   322     if ( !iConnectionHost )
       
   323         {
       
   324         return;
       
   325         }  
       
   326 #ifdef _DEBUG
       
   327     PluginLogger::Log(
       
   328         _L("PluginConnection: callback HandleRequestCompleted stat=%d"), retVal);
       
   329     PluginLogger::Log(
       
   330         _L("PluginConnection: ------------------------------------------------2"));        
       
   331 #endif              
       
   332     iConnectionHost->HandleRequestCompleted( aReqId, retVal );
       
   333     } 
       
   334     
       
   335 // ---------------------------------------------------------------------------
       
   336 // CSimplePluginConnection::CompleteWinfoReq
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CSimplePluginConnection::CompleteWinfoReq( TXIMPRequestId aReqId, TInt aStatus )
       
   340     {    
       
   341 #ifdef _DEBUG
       
   342     PluginLogger::Log(_L("PluginConnection: CompleteWinfoReq stat=%d"), aStatus);
       
   343 #endif
       
   344 
       
   345     if ( iAuth && iAuth->HandleIfMine( aReqId, aStatus ))
       
   346         {
       
   347         // Nothing to do, the request in not complete yet
       
   348 #ifdef _DEBUG
       
   349         PluginLogger::Log(_L("PluginConnection: CompleteWinfoReq waits ***"), aStatus);
       
   350 #endif         
       
   351         }
       
   352     else
       
   353         {
       
   354 #ifdef _DEBUG
       
   355         PluginLogger::Log(_L("PluginConnection: CompleteWinfoReq completes ***"), aStatus);
       
   356 #endif        
       
   357         CompleteReq( aReqId, aStatus );
       
   358         }
       
   359     }                  
       
   360      
       
   361 // ---------------------------------------------------------------------------
       
   362 // CSimplePluginConnection::ObjectFactory
       
   363 // ---------------------------------------------------------------------------
       
   364 // 
       
   365 MXIMPObjectFactory& CSimplePluginConnection::ObjectFactory()
       
   366     {
       
   367     return iConnectionHost->ObjectFactory();
       
   368     }
       
   369     
       
   370 // ---------------------------------------------------------------------------
       
   371 // CSimplePluginConnection::PresenceObjectFactory
       
   372 // ---------------------------------------------------------------------------
       
   373 // 
       
   374 MPresenceObjectFactory& CSimplePluginConnection::PresenceObjectFactory()
       
   375     {
       
   376     return iConnectionHost->ProtocolPresenceDataHost().PresenceObjectFactory();    
       
   377     }     
       
   378   
       
   379 // ---------------------------------------------------------------------------
       
   380 // CSimplePluginConnection::Host
       
   381 // ---------------------------------------------------------------------------
       
   382 //     
       
   383 MXIMPProtocolConnectionHost* CSimplePluginConnection::Host()
       
   384     {
       
   385     return iConnectionHost;
       
   386     }
       
   387     
       
   388 // ---------------------------------------------------------------------------
       
   389 // CSimplePluginConnection::CurrentDomain
       
   390 // ---------------------------------------------------------------------------
       
   391 //     
       
   392 TPtrC16 CSimplePluginConnection::CurrentDomain()
       
   393     {
       
   394     return iSession->CurrentDomain();    
       
   395     } 
       
   396     
       
   397 // ---------------------------------------------------------------------------
       
   398 // CSimplePluginConnection::Variation
       
   399 // ---------------------------------------------------------------------------
       
   400 //     
       
   401 CSimplePluginVariation& CSimplePluginConnection::Variation()
       
   402     {
       
   403     return *iVariation; 
       
   404     }        
       
   405            
       
   406 // ---------------------------------------------------------------------------
       
   407 // CSimplePluginConnection::CurrentSipPresentity
       
   408 // ---------------------------------------------------------------------------
       
   409 // 
       
   410 TPtrC16 CSimplePluginConnection::CurrentSipPresentity()
       
   411     {       
       
   412     delete iSipPresentity;
       
   413     iSipPresentity = NULL;    
       
   414     TRAPD( err, iSipPresentity = HBufC16::NewL( iSession->CurrentSipPresentity().Length() ));
       
   415         
       
   416     if ( !err )
       
   417         {                
       
   418         iSipPresentity->Des().Copy( iSession->CurrentSipPresentity() );
       
   419         return iSipPresentity->Des();
       
   420         }
       
   421     else
       
   422         {
       
   423         return TPtrC16();
       
   424         }        
       
   425     }     
       
   426     
       
   427 // ---------------------------------------------------------------------------
       
   428 // CSimplePluginConnection::CurrentSipPresentit8
       
   429 // ---------------------------------------------------------------------------
       
   430 // 
       
   431 TPtrC8 CSimplePluginConnection::CurrentSipPresentity8()
       
   432     {
       
   433     return iSession->CurrentSipPresentity();
       
   434     } 
       
   435             
       
   436 // ---------------------------------------------------------------------------
       
   437 // CSimplePluginConnection::XdmUtilsL
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 CSimplePluginXdmUtils* CSimplePluginConnection::XdmUtilsL()
       
   441     {
       
   442     if ( !iXdmUtils )
       
   443         {                
       
   444         iXdmUtils = CSimplePluginXdmUtils::NewL( 
       
   445             *this, iSession->XdmSettingsId() );
       
   446         }
       
   447     return iXdmUtils;
       
   448     }
       
   449             
       
   450 // ---------------------------------------------------------------------------
       
   451 // CSimplePluginConnection::WinfoHandlerL
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 CSimplePluginWinfo* CSimplePluginConnection::WinfoHandlerL()
       
   455     {
       
   456     if ( !iPluginWinfo )
       
   457         {
       
   458         iPluginWinfo = CSimplePluginWinfo::NewL( 
       
   459             *this, *(iSession->SimpleConnection() ));
       
   460         }
       
   461     iPluginWinfo->SetHost( iConnectionHost );
       
   462     return iPluginWinfo;
       
   463     }
       
   464     
       
   465 // ---------------------------------------------------------------------------
       
   466 // CSimplePluginConnection::WinfoTerminatedL
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CSimplePluginConnection::WinfoTerminatedL( TInt aReason )
       
   470     {
       
   471     // Pass the information to iAuth and iPublisher,
       
   472     // so that they can call PrFw Plugin Data Host callbacks.
       
   473     iAuth->WinfoTerminatedL( aReason );
       
   474     iPublisher->WinfoTerminatedL( aReason );
       
   475     }  
       
   476     
       
   477 // ---------------------------------------------------------------------------
       
   478 // CSimplePluginConnection::WinfoNotification
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CSimplePluginConnection::WinfoNotification( MSimpleWinfo& aWinfo )
       
   482     {
       
   483     TRAP_IGNORE( iPublisher->WinfoNotificationL( aWinfo ));    
       
   484     TRAP_IGNORE( iAuth->WinfoNotificationL( aWinfo ));
       
   485     }      
       
   486             
       
   487 // ---------------------------------------------------------------------------
       
   488 // CSimplePluginConnection::GetInterface
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 TAny* CSimplePluginConnection::GetInterface(
       
   492         TInt32 aInterfaceId,
       
   493         TIfGetOps aOptions )
       
   494     {
       
   495     if ( aInterfaceId == GetInterfaceId() )
       
   496         {
       
   497         // caller wants this interface
       
   498         MXIMPProtocolConnection* myIf = this;
       
   499         return myIf;
       
   500         }
       
   501     if( aOptions == MXIMPBase::EPanicIfUnknown )
       
   502         {
       
   503         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   504         }  
       
   505     return NULL;
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 // CSimplePluginConnection::GetInterface
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 const TAny* CSimplePluginConnection::GetInterface(
       
   513     TInt32 aInterfaceId,
       
   514     TIfGetOps aOptions ) const
       
   515     {
       
   516     if ( aInterfaceId == GetInterfaceId() )
       
   517         {
       
   518         // caller wants this interface
       
   519         const MXIMPProtocolConnection* myIf = this;
       
   520         return myIf;
       
   521         }
       
   522     if( aOptions == MXIMPBase::EPanicIfUnknown )
       
   523         {
       
   524         User::Panic( _L("CSimplePlugin"), KErrExtensionNotSupported );
       
   525         }  
       
   526     return NULL;
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // CSimplePluginConnection::GetInterfaceId
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 TInt32 CSimplePluginConnection::GetInterfaceId() const
       
   534     {
       
   535     return MXIMPProtocolConnection::KInterfaceId;
       
   536     }
       
   537     
       
   538 // ---------------------------------------------------------------------------
       
   539 // CSimplePluginConnection::HarmonizeErrorCode
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 TInt CSimplePluginConnection::HarmonizeErrorCode( TInt aStatus )
       
   543     {    
       
   544 
       
   545     TInt retVal = aStatus;
       
   546 
       
   547     // Convert error codes outsise e32err.h error range into PrFw errors.
       
   548 
       
   549     switch ( aStatus )
       
   550         {
       
   551         case KSimpleErrAuthorization:
       
   552             retVal = KPresenceErrNotEnoughCredits;
       
   553             break;
       
   554         case KSimpleErrTimeout:
       
   555         case KErrTimedOut:
       
   556             retVal = KXIMPErrServicRequestTimeouted;
       
   557             break;            
       
   558         default:
       
   559             {
       
   560             if ( aStatus < KSimplePluginGeneralErrorLow )
       
   561                 {
       
   562                 retVal = KXIMPErrServiceGeneralError;
       
   563                 }
       
   564             }
       
   565             break;                                
       
   566         };
       
   567         
       
   568     return retVal;    
       
   569     }
       
   570 
       
   571 
       
   572 // End of file
       
   573