voipplugins/sipconnectionprovider/src/scpservicehandlerbase.cpp
changeset 0 a4daefaec16c
child 9 bddb6d4447db
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Base class of protocol profile handlers.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "scpservicehandlerbase.h"
       
    20 #include "scpprofilehandler.h"
       
    21 #include "scputility.h"
       
    22 #include "scplogger.h"
       
    23 #include "scpservicestorage.h"
       
    24 #include "scpsubservice.h"
       
    25 
       
    26 // If sub service disconnection fails a timeout for
       
    27 // forced disabled is used.
       
    28 const TInt KDisableTimeout = 5000000;
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CScpServiceHandlerBase::CScpServiceHandlerBase
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CScpServiceHandlerBase::CScpServiceHandlerBase( CScpSubService& aSubService ) :
       
    35     iSubService( aSubService )
       
    36     {
       
    37     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::CScpServiceHandlerBase", this); 
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CScpServiceHandlerBase::~CScpServiceHandlerBase
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CScpServiceHandlerBase::~CScpServiceHandlerBase()
       
    45     {
       
    46     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::~CScpServiceHandlerBase",this); 
       
    47 
       
    48     delete iDisableTimer;
       
    49 
       
    50     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
    51     profileHandler.RemoveObserver( *this );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CScpServiceHandlerBase::BaseConstructL
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CScpServiceHandlerBase::BaseConstructL()
       
    59     {
       
    60     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::BaseConstructL", this );
       
    61 
       
    62     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
    63     profileHandler.AddObserverL( *this );
       
    64     
       
    65     iDisableTimer = CPeriodic::NewL( 0 );
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CScpServiceHandlerBase::RegisterProfileL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CScpServiceHandlerBase::RegisterProfileL()
       
    73     {
       
    74     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::RegisterProfileL", this );
       
    75 
       
    76     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
    77     profileHandler.RegisterProfileL( iSubService.SipProfileId() );
       
    78 
       
    79     CScpSipConnection::TConnectionState currentState = CScpSipConnection::EUnknown;
       
    80     TInt error = KErrNone;
       
    81 
       
    82     profileHandler.GetCurrentState( iSubService.SipProfileId(), 
       
    83                                      currentState,
       
    84                                      error );
       
    85 
       
    86     __ASSERT_DEBUG( currentState != CScpSipConnection::EUnknown, 
       
    87                     User::Panic( KNullDesC, KErrGeneral ) );
       
    88 
       
    89     TScpConnectionEvent event = TScpUtility::ConvertToConnectionEvent( currentState,
       
    90                                                                        error );
       
    91     if ( event == EScpRegistered )
       
    92         {
       
    93         // Sip profile was already registered
       
    94         HandleSipConnectionEvent( iSubService.SipProfileId(), EScpRegistered );
       
    95         }
       
    96     else
       
    97         {
       
    98         iSubService.HandleConnectionEvent( event );
       
    99         }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CScpServiceHandlerBase::DeregisterProfile
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CScpServiceHandlerBase::DeregisterProfile()
       
   107     {
       
   108     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::DeregisterProfile", this );
       
   109 
       
   110     // At this point all the service related disconnection operations
       
   111     // have been finished. Now the SIP profile needs to be disabled
       
   112     iSubService.SetSubServiceDisconnected( ETrue );
       
   113 
       
   114     TInt sipProfileId = iSubService.SipProfileId(); 
       
   115     CScpServiceStorage& storage = iSubService.ServiceStorage();
       
   116 
       
   117     // The SIP profile can be only disabled if
       
   118     // - None of the sub services are in enable state with the same profile
       
   119     // - None of the sub services are doing disconnection with the same profile
       
   120     if ( !storage.IsSubServiceEnabled( sipProfileId ) &&
       
   121          storage.AreAllSubServicesDisconnected( sipProfileId ) )
       
   122         {  
       
   123         CScpSipConnection::TConnectionState currentState = 
       
   124             CScpSipConnection::EUnknown;
       
   125         TInt error( KErrNone );        
       
   126 
       
   127         CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   128         profileHandler.GetCurrentState( sipProfileId, 
       
   129                                          currentState,
       
   130                                          error );        
       
   131 
       
   132         if ( currentState == CScpSipConnection::ERegistering )
       
   133             {
       
   134             profileHandler.CancelRegistration( sipProfileId );
       
   135             }
       
   136         else
       
   137             {
       
   138             profileHandler.UnregisterProfile( sipProfileId );
       
   139             }
       
   140         }
       
   141 
       
   142     StartForcedDisableTimer( CScpServiceHandlerBase::ForceSipProfileDisable );
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CScpServiceHandlerBase::StartForcedDisableTimer
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CScpServiceHandlerBase::StartForcedDisableTimer( TInt (*aFunction)(TAny* aPtr) )
       
   150     {
       
   151     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::StartForcedDisableTimer", this );
       
   152     __ASSERT_DEBUG( !iDisableTimer->IsActive(), 
       
   153                     User::Panic( KNullDesC, KErrGeneral ) );
       
   154 
       
   155     if ( !iDisableTimer->IsActive() )
       
   156         {
       
   157         iDisableTimer->Start( KDisableTimeout, 
       
   158                               0, 
       
   159                               TCallBack( aFunction, this ) );
       
   160         }
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CScpServiceHandlerBase::CancelDisableTimer
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CScpServiceHandlerBase::CancelDisableTimer()
       
   168     {
       
   169     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::CancelDisableTimer", this );
       
   170 
       
   171     if ( iDisableTimer->IsActive() )
       
   172         {
       
   173         iDisableTimer->Cancel();
       
   174         }
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CScpServiceHandlerBase::HandleSipProfileForcedDisable
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CScpServiceHandlerBase::HandleSipProfileForcedDisable()
       
   182     {
       
   183     SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::HandleSipProfileForcedDisable",
       
   184                    this );
       
   185 
       
   186     HandleSipConnectionEvent( iSubService.SipProfileId(), EScpDeregistered );
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CScpServiceHandlerBase::ForceSipProfileDisable
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CScpServiceHandlerBase::ForceSipProfileDisable( TAny* aSelf )
       
   194     {
       
   195     SCPLOGSTRING( "CScpServiceHandlerBase::ForceSipProfileDisable" );
       
   196 
       
   197     CScpServiceHandlerBase* self = static_cast<CScpServiceHandlerBase*>( aSelf );
       
   198     
       
   199     self->CancelDisableTimer();
       
   200     self->HandleSipProfileForcedDisable();
       
   201 
       
   202     return 1;
       
   203     }
       
   204 
       
   205 
       
   206 //  End of File