voipplugins/sipconnectionprovider/src/scpvmbxhandler.cpp
changeset 0 a4daefaec16c
child 15 43658d24f35d
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:  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 EIncorrectSettings:
       
   265                 {
       
   266                 iSubService.HandleConnectionEvent( EScpRegistrationFailed );
       
   267                 }
       
   268                 break;
       
   269 
       
   270             case ENoMemory:
       
   271             case ESmsError:
       
   272                 {
       
   273                 // :
       
   274                 // Error handling for VMBx errors
       
   275                 // In network error case we should change the state to connecting +
       
   276                 // "service not respondig" error
       
   277                 SCPLOGSTRING( "Error message from VMBx interface" ) 
       
   278                 }
       
   279                 break;
       
   280 
       
   281             default:
       
   282                 {
       
   283                 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrGeneral ) );
       
   284                 }
       
   285             }
       
   286         }
       
   287     }
       
   288     
       
   289 // -----------------------------------------------------------------------------
       
   290 // CScpVmbxHandler::SubServiceType
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TCCHSubserviceType CScpVmbxHandler::SubServiceType() const
       
   294     {
       
   295     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::SubServiceType", this );
       
   296 
       
   297     return ECCHVMBxSub;
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CScpVmbxHandler::HandleSipConnectionEvent
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CScpVmbxHandler::HandleSipConnectionEvent( TUint32 aProfileId,
       
   305                                                 TScpConnectionEvent aEvent )
       
   306     {
       
   307     SCPLOGSTRING4( "CScpVmbxHandler[0x%x]::HandleSipConnectionEvent id: %d event: %d",
       
   308                    this, aProfileId, aEvent );
       
   309     
       
   310     TInt result = KErrNone;
       
   311     
       
   312     if( iSubService.SipProfileId() == aProfileId &&
       
   313         iSubService.EnableRequestedState() != CScpSubService::EScpNoRequest )
       
   314         {
       
   315         if ( EScpRoaming == aEvent )
       
   316             {
       
   317             SCPLOGSTRING( "CScpVmbxHandler - EScpRoaming -> unsubscribe" );
       
   318             TRAP( result, UnsubscribeL() );
       
   319             SCPLOGSTRING2( "CScpVmbxHandler - unsubscribe error: %d", result );
       
   320             }
       
   321         
       
   322         if( aEvent == EScpRegistered &&
       
   323             iSubService.EnableRequestedState() == CScpSubService::EScpEnabled )
       
   324             {
       
   325             TRAP( result, SubscribeL() )
       
   326 
       
   327             SCPLOGSTRING2( "Subscribe result: %d", result ); 
       
   328         
       
   329             if( result == KErrNone )
       
   330                 {
       
   331                 // Still connecting the service
       
   332                 aEvent = EScpNetworkFound;
       
   333                 }
       
   334             else
       
   335                 {
       
   336                 if ( iSubService.IsRoaming() && KErrAlreadyExists == result )
       
   337                     {
       
   338                     // There's still unsubscribe ongoing, we have to wait
       
   339                     // ipvoicemailengine event EUnsubscribed and try to 
       
   340                     // make subscribe again
       
   341                     SCPLOGSTRING( "Resubscribe later" ); 
       
   342                     iResubscribe = ETrue;
       
   343                     // Still connecting the service
       
   344                     aEvent = EScpNetworkFound;
       
   345                     }
       
   346                 else
       
   347                     {
       
   348                     aEvent = EScpRegistrationFailed;
       
   349                     }
       
   350                 }
       
   351             }
       
   352         else if( aEvent == EScpDeregistered &&
       
   353                  iSubService.EnableRequestedState() == CScpSubService::EScpDisabled ||
       
   354                  iSubService.EnableRequestedState() == CScpSubService::EScpRefreshed )
       
   355             {
       
   356             CancelDisableTimer();
       
   357             }
       
   358 
       
   359         iSubService.HandleConnectionEvent( aEvent );
       
   360         }        
       
   361     }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CScpVmbxHandler::SubscribeL
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 void CScpVmbxHandler::SubscribeL()
       
   368     {
       
   369     SCPLOGSTRING2( "CScpVmbxHandler[0x%x]::SubscribeL", this );
       
   370 
       
   371     TUint32 sipProfileId = iSubService.SipProfileId();
       
   372     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   373 
       
   374     CScpSipConnection* sipConnection = profileHandler.GetSipConnection( sipProfileId );
       
   375 
       
   376     if( sipConnection )
       
   377         {
       
   378         CIpVmbxInterface& vmbxInterface = profileHandler.VmbxInterfaceL( *this );
       
   379 
       
   380         // It must be possible to add observers for the vmbx interface
       
   381 
       
   382         vmbxInterface.SubscribeL( iSubService.SubServiceId(), 
       
   383                                   sipConnection->SipProfile() );
       
   384         }
       
   385     else
       
   386         {
       
   387         User::LeaveIfError( KErrNotFound );
       
   388         }
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CScpVmbxHandler::ForceDisable
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 TInt CScpVmbxHandler::ForceVmbxServiceDisable( TAny* aSelf )
       
   396     {
       
   397     SCPLOGSTRING( "CScpVmbxHandler[0x%x]::ForceVmbxServiceDisable" );
       
   398 
       
   399     CScpVmbxHandler* self = static_cast<CScpVmbxHandler*>( aSelf );
       
   400 
       
   401     self->CancelDisableTimer();
       
   402     self->DeregisterProfile();
       
   403 
       
   404     return 1;
       
   405     }
       
   406 
       
   407 
       
   408 //  End of File