voipplugins/sipconnectionprovider/src/scpvoiphandler.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2002-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:  Voip handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32property.h>
       
    20 #include <spdefinitions.h>
       
    21 #include "scpvoiphandler.h"
       
    22 #include "scpprofilehandler.h"
       
    23 #include "scplogger.h"
       
    24 #include "scpsubservice.h"
       
    25 #include "scpservicestorage.h"
       
    26 #include "scpsettinghandler.h"
       
    27 #include "scpsipconnection.h"
       
    28 #include "scputility.h"
       
    29 #include "csipclientresolverutils.h"
       
    30 
       
    31 // : These need to be in some common header
       
    32 const TUid KResolver = { 0x10283140 };
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CScpVoipHandler::CCScpVoipHandler
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CScpVoipHandler::CScpVoipHandler( CScpSubService& aSubService ) :
       
    40     CScpServiceHandlerBase( aSubService )
       
    41     {
       
    42     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::CScpVoipHandler", this );
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CScpVoipHandler::ConstructL
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CScpVoipHandler::ConstructL()
       
    50     {
       
    51     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::ConstructL", this );
       
    52     
       
    53     BaseConstructL();
       
    54     iSipClientResolver = CSipClientResolverUtils::NewL();
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CScpVoipHandler::NewL
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CScpVoipHandler* CScpVoipHandler::NewL( CScpSubService& aSubService )
       
    62     {
       
    63     SCPLOGSTRING( "CScpVoipHandler::NewL" );
       
    64 
       
    65     CScpVoipHandler* self = new(ELeave) CScpVoipHandler( aSubService );
       
    66     CleanupStack::PushL( self );    
       
    67     self->ConstructL();    
       
    68     CleanupStack::Pop( self );
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CScpVoipHandler::~CScpVoipHandler
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CScpVoipHandler::~CScpVoipHandler()
       
    78     {
       
    79     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::~CScpVoipHandler", this );
       
    80     delete iSipClientResolver;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CScpVoipHandler::HandlePropertyChanged
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CScpVoipHandler::HandlePropertyChanged( TInt /* aPropertyValue */)
       
    88     {
       
    89     CScpSipConnection::TConnectionState sipState = CScpSipConnection::EUnknown;
       
    90     TInt sipError = KErrNotFound;
       
    91     CScpSipConnection* sipConnection = 
       
    92         iSubService.ProfileHandler().GetSipConnection( 
       
    93             iSubService.SipProfileId() );
       
    94     if ( sipConnection )
       
    95         {
       
    96         sipConnection->GetState( sipState, sipError );
       
    97         }
       
    98     if (  ECCHEnabled == iSubService.State() && 
       
    99         KErrNone == sipError && CScpSipConnection::ERegistered == sipState )
       
   100         {
       
   101         HandleSipConnectionEvent( iSubService.SipProfileId(), EScpRegistered );
       
   102         }
       
   103     }
       
   104     
       
   105 // -----------------------------------------------------------------------------
       
   106 // CScpVoipHandler::EnableSubServiceL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CScpVoipHandler::EnableSubServiceL()
       
   110     {
       
   111     SCPLOGSTRING4( "CScpVoipHandler[0x%x]::EnableSubServiceL: 0x%x type: %i", 
       
   112                    this, &iSubService, iSubService.SubServiceType() );
       
   113     __ASSERT_DEBUG( iSubService.SubServiceType() == ECCHVoIPSub,
       
   114                     User::Panic( KNullDesC, KErrGeneral ) );
       
   115     
       
   116     CScpServiceHandlerBase::RegisterProfileL();
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CScpVoipHandler::DisableSubService
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TInt CScpVoipHandler::DisableSubService()
       
   124     {
       
   125     SCPLOGSTRING4( "CScpVoipHandler[0x%x]::DisableSubService: 0x%x type: %i", 
       
   126                    this, &iSubService, iSubService.SubServiceType() );
       
   127     __ASSERT_DEBUG( iSubService.SubServiceType() == ECCHVoIPSub,
       
   128                     User::Panic( KNullDesC, KErrGeneral ) ); 
       
   129 
       
   130     TInt result = KErrNone;
       
   131 
       
   132     TCCHSubserviceState subServiceState = iSubService.State();
       
   133 
       
   134     if( subServiceState != ECCHDisabled )
       
   135         {
       
   136         TRAP( result, DeregisterContactHeaderL() )        
       
   137 
       
   138         DeregisterProfile();
       
   139         }
       
   140     else
       
   141         {
       
   142         result = KErrNotSupported;
       
   143         }
       
   144 
       
   145     return result;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CScpVoipHandler::DeregisterContactHeaderL
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CScpVoipHandler::DeregisterContactHeaderL()
       
   153     {
       
   154     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::DeregisterContactHeaderL", this );
       
   155 
       
   156     RBuf8 contactHeaderUser;
       
   157     contactHeaderUser.CleanupClosePushL();
       
   158 
       
   159     GetSipProfileContactHeaderUserL( contactHeaderUser );
       
   160     
       
   161     iSipClientResolver->UnRegisterClientWithUserL( 
       
   162         GetCallProviderImplementationUidL(), contactHeaderUser );
       
   163 
       
   164     CleanupStack::PopAndDestroy( &contactHeaderUser );
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CScpVoipHandler::SubServiceType
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TCCHSubserviceType CScpVoipHandler::SubServiceType() const
       
   172     {
       
   173     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::SubServiceType", this );
       
   174 
       
   175     return ECCHVoIPSub;
       
   176     }
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CScpVoipHandler::HandleSipConnectionEvent
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CScpVoipHandler::HandleSipConnectionEvent( TUint32 aProfileId,
       
   184                                                 TScpConnectionEvent aEvent )
       
   185     {
       
   186     TRAP_IGNORE( HandleSipConnectionEventL( aProfileId,aEvent ));
       
   187     }
       
   188 // -----------------------------------------------------------------------------
       
   189 // CScpVoipHandler::HandleSipConnectionEvent
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CScpVoipHandler::HandleSipConnectionEventL( TUint32 aProfileId,
       
   193                                                 TScpConnectionEvent aEvent )
       
   194     {
       
   195     SCPLOGSTRING4( "CScpVoipHandler[0x%x]::HandleSipConnectionEvent id: %d event: %d",
       
   196         this, aProfileId, aEvent );
       
   197 
       
   198     if( iSubService.SipProfileId() == aProfileId &&
       
   199         iSubService.EnableRequestedState() != CScpSubService::EScpNoRequest )
       
   200         {
       
   201         if( aEvent == EScpRegistered &&
       
   202             iSubService.EnableRequestedState() == CScpSubService::EScpEnabled )
       
   203             {
       
   204             RBuf8 contactHeaderUser;
       
   205             contactHeaderUser.CleanupClosePushL();
       
   206             GetSipProfileContactHeaderUserL( contactHeaderUser );
       
   207             
       
   208             SCPLOGSTRING( "HandleSipConnectionEventL -> register client" );
       
   209             
       
   210             iSipClientResolver->RegisterClientWithUserL( 
       
   211                 GetCallProviderImplementationUidL(), contactHeaderUser, KResolver );
       
   212             
       
   213             CleanupStack::PopAndDestroy( &contactHeaderUser );
       
   214             }
       
   215 
       
   216         iSubService.HandleConnectionEvent( aEvent );
       
   217         }
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CScpVoipHandler::GetSipProfileContactHeaderL
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CScpVoipHandler::GetSipProfileContactHeaderUserL( 
       
   225     RBuf8& aContactHeaderUser ) const
       
   226     {
       
   227     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::GetSipProfileContactHeaderL", this );
       
   228 
       
   229     TUint32 sipProfileId = iSubService.SipProfileId();
       
   230 
       
   231     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   232     CScpSipConnection* sipConnection = 
       
   233         profileHandler.CreateSipConnectionL( sipProfileId );
       
   234     CleanupStack::PushL( sipConnection );
       
   235     
       
   236     if( sipConnection )
       
   237         {
       
   238         User::LeaveIfError( sipConnection->GetContactHeaderUser( aContactHeaderUser ) );
       
   239         __ASSERT_DEBUG( aContactHeaderUser.Length() > 0, 
       
   240         User::Panic( KNullDesC, KErrGeneral ) );
       
   241         }
       
   242     else
       
   243         {
       
   244         User::Leave( KErrNotFound );
       
   245         }
       
   246 
       
   247     CleanupStack::PopAndDestroy( sipConnection );
       
   248     }
       
   249     
       
   250 // -----------------------------------------------------------------------------
       
   251 // CScpVoipHandler::CallProviderImplementationUid
       
   252 // -----------------------------------------------------------------------------
       
   253 //   
       
   254 TUid CScpVoipHandler::GetCallProviderImplementationUidL()
       
   255     {
       
   256     SCPLOGSTRING2( "CScpVoipHandler[0x%x]::GetCallProviderImplementationUidL", this );
       
   257 
       
   258     CScpServiceStorage& serviceStorage = iSubService.ServiceStorage();
       
   259     CScpSettingHandler& settingHandler = serviceStorage.SettingsHandler();
       
   260 
       
   261     TInt impUid = 0;
       
   262     settingHandler.GetSPSettingsIntPropertyL( iSubService.SubServiceId(),
       
   263                                               EPropertyCallProviderPluginId,
       
   264                                               impUid );
       
   265    
       
   266     TUid implementationUid; 
       
   267     implementationUid.iUid = impUid;
       
   268 
       
   269     return implementationUid;
       
   270     }
       
   271     
       
   272 //  End of File