voipplugins/sipconnectionprovider/src/scpvmbxhandler.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     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:  Vmbx handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ipvmbxinterface.h"
       
    20 #include "scpvmbxhandler.h"
       
    21 #include "scplogger.h"
       
    22 #include "scpservice.h"
       
    23 #include "scpsubservice.h"
       
    24 #include "scpservicestorage.h"
       
    25 #include "scputility.h"
       
    26 #include "scpsipconnection.h"
       
    27 #include "scpprofilehandler.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CScpVmbxHandler::CCScpVmbxHandler
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CScpVmbxHandler::CScpVmbxHandler( CScpSubService& aSubService ) :
       
    34     CScpServiceHandlerBase( aSubService )
       
    35     {
       
    36     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::CScpVmbxHandler", this );
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CScpVmbxHandler::ConstructL
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CScpVmbxHandler::ConstructL()
       
    44     {
       
    45     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::ConstructL", this );
       
    46 
       
    47     BaseConstructL();
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CScpVmbxHandler::NewL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CScpVmbxHandler* CScpVmbxHandler::NewL( CScpSubService& aSubService )
       
    55     {
       
    56     SCPLOGSTRING( "CScpVmbxHandler::NewL" );
       
    57 
       
    58     CScpVmbxHandler* self = new(ELeave) CScpVmbxHandler( aSubService );
       
    59     CleanupStack::PushL( self );    
       
    60     self->ConstructL();    
       
    61     CleanupStack::Pop( self );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CScpVmbxHandler::~CScpVmbxHandler
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CScpVmbxHandler::~CScpVmbxHandler()
       
    71     {
       
    72     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::~CScpVmbxHandler", this );
       
    73     
       
    74     if ( !IsAnotherVmbxSubServiceAlreadyEnabled() )
       
    75         {
       
    76         iSubService.ProfileHandler().DeleteVmbxInterface();
       
    77         }
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CScpVmbxHandler::EnableSubServiceL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CScpVmbxHandler::EnableSubServiceL()
       
    85     {
       
    86     SCPLOGSTRING4( "CScpVmbxHandler[0x%x]::EnableSubServiceL: 0x%x type: %i", 
       
    87                    this, &iSubService, iSubService.SubServiceType() );
       
    88     __ASSERT_DEBUG( iSubService.SubServiceType() == ECCHVMBxSub,
       
    89                     User::Panic( KNullDesC, KErrGeneral ) );
       
    90 
       
    91     // Only one enabled vmbx service is allowed at a time.
       
    92     if( IsAnotherVmbxSubServiceAlreadyEnabled() )
       
    93         {
       
    94         User::Leave( KErrInUse );
       
    95         }
       
    96 
       
    97     CScpServiceHandlerBase::RegisterProfileL();
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CScpVmbxHandler::IsAnotherVmbxSubServiceAlreadyEnabled
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TBool CScpVmbxHandler::IsAnotherVmbxSubServiceAlreadyEnabled() const
       
   105     {
       
   106     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::IsAnotherVmbxSubServiceAlreadyEnabled", this );
       
   107 
       
   108     TBool result = EFalse;
       
   109 
       
   110     CScpServiceStorage& storage = iSubService.ServiceStorage();
       
   111     RArray<TInt> ids;
       
   112 
       
   113     storage.GetSubServiceIds( ECCHVMBxSub, ids );
       
   114 
       
   115     TInt count( ids.Count() );
       
   116 
       
   117     for ( TInt i( 0 ); i < count; i++ )
       
   118         {
       
   119         CScpSubService* subService = storage.GetSubService( ids[i] );
       
   120 
       
   121         if ( subService && ECCHDisabled != subService->State() )
       
   122             {
       
   123             result = ETrue;
       
   124             break;
       
   125             }
       
   126         }
       
   127 
       
   128     ids.Close();
       
   129     return result;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CScpVmbxHandler::DisableSubService
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TInt CScpVmbxHandler::DisableSubService()
       
   137     {
       
   138     SCPLOGSTRING4( "CScpVmbxHandler[0x%x]::DisableSubService: 0x%x type: %i", 
       
   139                    this, &iSubService, iSubService.SubServiceType() );
       
   140     __ASSERT_DEBUG( iSubService.SubServiceType() == ECCHVMBxSub,
       
   141                     User::Panic( KNullDesC, KErrGeneral ) );  
       
   142 
       
   143     TInt result = KErrNone;
       
   144 
       
   145     if( iSubService.State() != ECCHDisabled )
       
   146         {
       
   147         TRAP( result, UnsubscribeL() );
       
   148 
       
   149         if( result == KErrNone )
       
   150             {
       
   151             // Deregister if still connecting and subscribed message 
       
   152             // not yet received
       
   153             if( iSubService.State() == ECCHConnecting )
       
   154                 {
       
   155                 DeregisterProfile();
       
   156                 }
       
   157             else
       
   158                 {
       
   159                 StartForcedDisableTimer( CScpVmbxHandler::ForceVmbxServiceDisable );
       
   160                 }
       
   161             }
       
   162         else
       
   163             {
       
   164             DeregisterProfile();
       
   165             }
       
   166         }
       
   167     else
       
   168         {
       
   169         result = KErrNotSupported;
       
   170         }
       
   171 
       
   172     return result;
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CScpVmbxHandler::UnsubscribeL
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CScpVmbxHandler::UnsubscribeL()
       
   180     {
       
   181     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::UnsubscribeL", this );
       
   182 
       
   183     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   184 
       
   185     // Unsubscribe is not called when refreshing the connection
       
   186     if( iSubService.EnableRequestedState() != CScpSubService::EScpRefreshed )
       
   187         {
       
   188         CIpVmbxInterface& vmbxInterface = profileHandler.VmbxInterfaceL( *this );
       
   189         vmbxInterface.UnsubscribeL( iSubService.SubServiceId() );
       
   190         }
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CScpVmbxHandler::HandleMessage
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CScpVmbxHandler::HandleMessage( TUint32 aServiceId, TVmbxMessage aMessage )
       
   198     {
       
   199     SCPLOGSTRING4( "CScpVmbxHandler[0x%x]::HandleMessage: id: %d message: %d", 
       
   200                    this, aServiceId, aMessage );
       
   201 
       
   202     TInt result = KErrNone;
       
   203     
       
   204     if( iSubService.SubServiceId() == aServiceId )
       
   205         {
       
   206         switch( aMessage )
       
   207             {
       
   208             case ESubscribed:
       
   209                 {
       
   210                 iSubService.HandleConnectionEvent( EScpRegistered );
       
   211                 }
       
   212                 break;
       
   213 
       
   214             case EUnsubscribed:
       
   215                 {
       
   216                 // Check if disable was requested
       
   217                 if( iSubService.EnableRequestedState() == CScpSubService::EScpDisabled )
       
   218                     {
       
   219                     CancelDisableTimer();
       
   220                     DeregisterProfile();
       
   221                     }
       
   222                 else
       
   223                     {
       
   224                     if ( iResubscribe )
       
   225                         {
       
   226                         iResubscribe = EFalse;
       
   227                         TRAP( result, SubscribeL() )
       
   228                         SCPLOGSTRING2( "Subscribe result: %d", result ); 
       
   229                         
       
   230                         if( result == KErrNone )
       
   231                             {
       
   232                             // Still connecting the service
       
   233                             iSubService.HandleConnectionEvent( EScpNetworkFound );
       
   234                             }
       
   235                         else if ( KErrAlreadyExists == result )
       
   236                             {
       
   237                             iSubService.HandleConnectionEvent( EScpRegistrationPending );
       
   238                             }
       
   239                         else
       
   240                             {
       
   241                             iSubService.HandleConnectionEvent( EScpRegistrationFailed );
       
   242                             }
       
   243                         }
       
   244                     else
       
   245                         {
       
   246                         // Connection to VMBx server lost
       
   247                         iSubService.HandleConnectionEvent( EScpDeregistered );
       
   248                         }
       
   249                     }
       
   250                 }
       
   251                 break;
       
   252 
       
   253             case ENetworkError:
       
   254                 {
       
   255                 // Network lost errors may have already been reported
       
   256                 if( iSubService.LastReportedError() == KErrNone )
       
   257                     {
       
   258                     // Connection to VMBx server lost
       
   259                     iSubService.HandleConnectionEvent( EScpRegistrationFailed );
       
   260                     }
       
   261                 break;
       
   262                 }
       
   263                 
       
   264             case EFatalNetworkError:
       
   265                 {
       
   266                 // In case of fatal network error forced disable is done to
       
   267                 // SIP profile.
       
   268                 PerformInstantForceSipProfileDisable();
       
   269                 break;
       
   270                 }
       
   271 
       
   272             case EIncorrectSettings:
       
   273                 {
       
   274                 iSubService.HandleConnectionEvent( EScpRegistrationFailed );
       
   275                 }
       
   276                 break;
       
   277 
       
   278             case ENoMemory:
       
   279             case ESmsError:
       
   280                 {
       
   281                 // :
       
   282                 // Error handling for VMBx errors
       
   283                 // In network error case we should change the state to connecting +
       
   284                 // "service not respondig" error
       
   285                 SCPLOGSTRING( "Error message from VMBx interface" ) 
       
   286                 }
       
   287                 break;
       
   288 
       
   289             default:
       
   290                 {
       
   291                 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrGeneral ) );
       
   292                 }
       
   293             }
       
   294         }
       
   295     }
       
   296     
       
   297 // -----------------------------------------------------------------------------
       
   298 // CScpVmbxHandler::SubServiceType
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TCCHSubserviceType CScpVmbxHandler::SubServiceType() const
       
   302     {
       
   303     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::SubServiceType", this );
       
   304 
       
   305     return ECCHVMBxSub;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CScpVmbxHandler::HandleSipConnectionEvent
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CScpVmbxHandler::HandleSipConnectionEvent( TUint32 aProfileId,
       
   313                                                 TScpConnectionEvent aEvent )
       
   314     {
       
   315     SCPLOGSTRING4( "CScpVmbxHandler[0x%x]::HandleSipConnectionEvent id: %d event: %d",
       
   316                    this, aProfileId, aEvent );
       
   317     
       
   318     TInt result = KErrNone;
       
   319     
       
   320     if( iSubService.SipProfileId() == aProfileId &&
       
   321         iSubService.EnableRequestedState() != CScpSubService::EScpNoRequest )
       
   322         {
       
   323         if ( EScpRoaming == aEvent )
       
   324             {
       
   325             SCPLOGSTRING( "CScpVmbxHandler - EScpRoaming -> unsubscribe" );
       
   326             TRAP( result, UnsubscribeL() );
       
   327             SCPLOGSTRING2( "CScpVmbxHandler - unsubscribe error: %d", result );
       
   328             }
       
   329         
       
   330         if( aEvent == EScpRegistered &&
       
   331             iSubService.EnableRequestedState() == CScpSubService::EScpEnabled )
       
   332             {
       
   333             TRAP( result, SubscribeL() )
       
   334 
       
   335             SCPLOGSTRING2( "Subscribe result: %d", result ); 
       
   336         
       
   337             if( result == KErrNone )
       
   338                 {
       
   339                 // Still connecting the service
       
   340                 aEvent = EScpNetworkFound;
       
   341                 }
       
   342             else
       
   343                 {
       
   344                 if ( iSubService.IsRoaming() && KErrAlreadyExists == result )
       
   345                     {
       
   346                     // There's still unsubscribe ongoing, we have to wait
       
   347                     // ipvoicemailengine event EUnsubscribed and try to 
       
   348                     // make subscribe again
       
   349                     SCPLOGSTRING( "Resubscribe later" ); 
       
   350                     iResubscribe = ETrue;
       
   351                     // Still connecting the service
       
   352                     aEvent = EScpNetworkFound;
       
   353                     }
       
   354                 else
       
   355                     {
       
   356                     aEvent = EScpRegistrationFailed;
       
   357                     }
       
   358                 }
       
   359             }
       
   360         else if( aEvent == EScpDeregistered &&
       
   361                  iSubService.EnableRequestedState() == CScpSubService::EScpDisabled ||
       
   362                  iSubService.EnableRequestedState() == CScpSubService::EScpRefreshed )
       
   363             {
       
   364             CancelDisableTimer();
       
   365             }
       
   366 
       
   367         iSubService.HandleConnectionEvent( aEvent );
       
   368         }        
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CScpVmbxHandler::SubscribeL
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CScpVmbxHandler::SubscribeL()
       
   376     {
       
   377     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::SubscribeL", this );
       
   378 
       
   379     TUint32 sipProfileId = iSubService.SipProfileId();
       
   380     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   381 
       
   382     CScpSipConnection* sipConnection = profileHandler.GetSipConnection( sipProfileId );
       
   383 
       
   384     if( sipConnection )
       
   385         {
       
   386         CIpVmbxInterface& vmbxInterface = profileHandler.VmbxInterfaceL( *this );
       
   387 
       
   388         // It must be possible to add observers for the vmbx interface
       
   389 
       
   390         vmbxInterface.SubscribeL( iSubService.SubServiceId(), 
       
   391                                   sipConnection->SipProfile() );
       
   392         }
       
   393     else
       
   394         {
       
   395         User::LeaveIfError( KErrNotFound );
       
   396         }
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CScpVmbxHandler::ForceDisable
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 TInt CScpVmbxHandler::ForceVmbxServiceDisable( TAny* aSelf )
       
   404     {
       
   405     SCPLOGSTRING( "CScpVmbxHandler[0x%x]::ForceVmbxServiceDisable" );
       
   406 
       
   407     CScpVmbxHandler* self = static_cast<CScpVmbxHandler*>( aSelf );
       
   408 
       
   409     self->CancelDisableTimer();
       
   410     self->DeregisterProfile();
       
   411 
       
   412     return 1;
       
   413     }
       
   414 
       
   415 
       
   416 //  End of File