convergedconnectionhandler/cchserver/src/cchservicehandler.cpp
changeset 0 a4daefaec16c
child 9 bddb6d4447db
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  CCCHServiceHandler implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <cchclientserver.h>
       
    21 #include <spnotifychange.h>
       
    22 
       
    23 #include "cchservicehandler.h"
       
    24 #include "cchserverbase.h"
       
    25 #include "cchspshandler.h"
       
    26 #include "cchlogger.h"
       
    27 #include "cchpluginhandler.h"
       
    28 #include "cchuihandler.h"
       
    29 #include "cchconnmonhandler.h"
       
    30 #include "cchwlanextension.h"
       
    31 #include "cchcommdbwatcher.h"
       
    32 #include "cchcommdbwatcherobserver.h"
       
    33 
       
    34 // EXTERNAL DATA STRUCTURES
       
    35 // None
       
    36 
       
    37 // EXTERNAL FUNCTION PROTOTYPES
       
    38 // None
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 const TInt KConnectionRecoveryMaxTries = 5;
       
    43 
       
    44 const TInt KCCHFirstRecovery    = 15000000;
       
    45 const TInt KCCHSecondRecovery   = 15000000;
       
    46 const TInt KCCHThirdRecovery    = 30000000;
       
    47 const TInt KCCHFourthRecovery   = 60000000;
       
    48 const TInt KCCHFifthRecovery    = 60000000;
       
    49 
       
    50 const TInt KCCHPluginUnloadTimeout = 5000000;
       
    51 // MACROS
       
    52 // None
       
    53 
       
    54 // LOCAL CONSTANTS AND MACROS
       
    55 // None
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 // None
       
    59 
       
    60 // LOCAL FUNCTION PROTOTYPES
       
    61 // None
       
    62 
       
    63 // FORWARD DECLARATIONS
       
    64 // None.
       
    65 
       
    66 // ============================= LOCAL FUNCTIONS =============================
       
    67 
       
    68 // ============================ MEMBER FUNCTIONS =============================
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCCHServiceHandler::CCCHServiceHandler
       
    72 // C++ default constructor can NOT contain any code, that might leave.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CCCHServiceHandler::CCCHServiceHandler( CCCHServerBase& aServer ) :
       
    76     iServer( aServer ),
       
    77     iConnectionRecoveryTry( 0 ),
       
    78     iCancelNotify( ETrue ) 
       
    79     {
       
    80     // No implementation required
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CCCHServiceHandler::ConstructL
       
    85 // Symbian 2nd phase constructor can leave.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CCCHServiceHandler::ConstructL()
       
    89     {
       
    90     iNotifier = CSPNotifyChange::NewL( *this );
       
    91     iCchUIHandler = CCchUIHandler::NewL( iServer, *this );
       
    92     iPhoneStartupMonitor = CCchPhoneStartupMonitor::NewL( *iCchUIHandler );
       
    93     iConnectionRecoveryTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
       
    94     iCommDbWatcher = CCCHCommDbWatcher::NewL( *this );
       
    95     iPluginUnloadTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
       
    96     iRecoveryInterval.Append( KCCHFirstRecovery );
       
    97     iRecoveryInterval.Append( KCCHSecondRecovery );
       
    98     iRecoveryInterval.Append( KCCHThirdRecovery );
       
    99     iRecoveryInterval.Append( KCCHFourthRecovery );
       
   100     iRecoveryInterval.Append( KCCHFifthRecovery );
       
   101     iWlanExtension = CCchWlanExtension::NewL( );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CCCHServiceHandler::NewL
       
   106 // Two-phased constructor.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CCCHServiceHandler* CCCHServiceHandler::NewL( CCCHServerBase& aServer )
       
   110     {
       
   111     CCCHServiceHandler* self = CCCHServiceHandler::NewLC( aServer );
       
   112     CleanupStack::Pop( self );
       
   113     return self;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CCCHServiceHandler::NewLC
       
   118 // Two-phased constructor.
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CCCHServiceHandler* CCCHServiceHandler::NewLC( CCCHServerBase& aServer )
       
   122     {
       
   123     CCCHServiceHandler* self = new (ELeave) CCCHServiceHandler( aServer );
       
   124     CleanupStack::PushL( self );
       
   125     self->ConstructL();
       
   126     return self;
       
   127     }
       
   128 
       
   129 // Destructor
       
   130 CCCHServiceHandler::~CCCHServiceHandler()
       
   131     {
       
   132     if ( iCchUIHandler )
       
   133         {
       
   134         iCchUIHandler->Destroy();
       
   135         }
       
   136 
       
   137     delete iPhoneStartupMonitor;
       
   138     delete iWlanExtension;
       
   139     delete iConnectionRecoveryTimer;
       
   140     delete iPluginUnloadTimer;
       
   141     delete iCommDbWatcher;
       
   142 
       
   143     if( iNotifier )
       
   144         {
       
   145         iNotifier->Cancel();
       
   146         delete iNotifier;
       
   147         iNotifier = NULL;    
       
   148         }
       
   149 
       
   150     iServiceIds.Close();
       
   151     iServer.PluginHandler().RemoveServiceNotifier( this );
       
   152     iServices.ResetAndDestroy();
       
   153     iServicesInRecovery.Close();
       
   154     iRecoveryInterval.Close();
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CCCHServiceHandler::InitServiceHandlerL
       
   159 // (other items were commented in a header).
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CCCHServiceHandler::InitServiceHandlerL()
       
   163     {
       
   164     CCHLOGSTRING2( "CCCHServiceHandler::InitServiceHandlerL [0x%x]: IN",this );
       
   165     
       
   166     RArray<TUint> serviceIds;
       
   167     CleanupClosePushL( serviceIds );
       
   168     iServer.SPSHandler().GetServiceIdsL( serviceIds );
       
   169     for ( TInt i( 0 ); i < serviceIds.Count(); i++ )
       
   170         {        
       
   171         if ( KErrNotFound == FindService( serviceIds[ i ] ) )
       
   172             {
       
   173             TCCHService service;
       
   174             TRAPD( error, iServer.SPSHandler().GetServiceInfoL( 
       
   175                 serviceIds[ i ], service ) );
       
   176             if ( KErrNone == error )
       
   177                 {
       
   178                 AddServiceL( service );    
       
   179                 }                    
       
   180             }
       
   181         }
       
   182     CleanupStack::PopAndDestroy( &serviceIds );
       
   183     // Subscribe to service change notifies    
       
   184     EnableNotifyChange();
       
   185     
       
   186     CCHLOGSTRING( "CCCHServiceHandler::InitServiceHandlerL: OUT" );
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CCCHServiceHandler::AddServiceL
       
   191 // (other items were commented in a header).
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CCCHServiceHandler::AddServiceL( TCCHService& aService )
       
   195     {
       
   196     CCHLOGSTRING( "CCCHServiceHandler::AddServiceL: IN" );
       
   197     
       
   198     CCCHServiceInfo* cchServiceInfo = CCCHServiceInfo::NewLC( iServer );
       
   199     cchServiceInfo->SetServiceId( aService.iServiceId );
       
   200     cchServiceInfo->SetName( aService.iServiceName );
       
   201     CCHLOGSTRING2( "CCCHServiceHandler::AddServiceL: adding service with %d subservices",aService.iSubservices.Count() );
       
   202     for ( TInt i( 0 ); i < aService.iSubservices.Count(); i++ )
       
   203         {
       
   204         cchServiceInfo->AddSubserviceL( aService.iSubservices[ i ] );
       
   205         }
       
   206         
       
   207     CleanupStack::Pop( cchServiceInfo );
       
   208     iServices.Append( cchServiceInfo );
       
   209     
       
   210     CCHLOGSTRING( "CCCHServiceHandler::AddServiceL: OUT" );
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CCCHServiceHandler::UpdateL
       
   215 // (other items were commented in a header).
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CCCHServiceHandler::UpdateL( TBool aReadSettingTable )
       
   219     {
       
   220     CCHLOGSTRING( "CCCHServiceHandler::UpdateL: IN" );
       
   221     
       
   222     // Read settings from service table
       
   223     if ( aReadSettingTable )
       
   224         {
       
   225         RArray<TUint> serviceIds;
       
   226         CleanupClosePushL( serviceIds );
       
   227         
       
   228         TInt index( KErrNotFound );
       
   229         iServer.SPSHandler().GetServiceIdsL( serviceIds );
       
   230         
       
   231         for ( TInt i( 0 ); i < serviceIds.Count(); i++ )
       
   232             {        
       
   233             index = FindService( serviceIds[ i ] );
       
   234             if ( KErrNotFound != index )
       
   235                 {
       
   236                 iServices[ index ]->UpdateL( ETrue );
       
   237                 }
       
   238             else
       
   239                 {
       
   240                 CCHLOGSTRING2
       
   241                     ( "CCCHSeviceHandler::UpdateL: \
       
   242                         New service found: ServiceId %d", serviceIds[ i ] );
       
   243                 TCCHService service;
       
   244                 TRAPD( error, iServer.SPSHandler().GetServiceInfoL( 
       
   245                     serviceIds[ i ], service ) );
       
   246                 if ( KErrNone == error )
       
   247                     {
       
   248                     AddServiceL( service );
       
   249                     }                
       
   250                 }
       
   251             }
       
   252         if ( serviceIds.Count() < iServices.Count() )
       
   253             {
       
   254             // Remove service's which does not exist anymore            
       
   255             for ( TInt i( 0 ); i < iServices.Count(); i++ )
       
   256                 {            
       
   257                 if ( KErrNotFound == serviceIds.Find( 
       
   258                     iServices[ i ]->GetServiceId( ) ) )
       
   259                     {
       
   260                     CCHLOGSTRING2
       
   261                         ( "CCCHSeviceHandler::UpdateL: \
       
   262                         service removed: ServiceId %d", 
       
   263                         iServices[ i ]->GetServiceId() );
       
   264                     delete iServices[ i ];
       
   265                     iServices.Remove( i );
       
   266                     i--;
       
   267                     StartPluginUnloadTimer( );
       
   268                     }
       
   269                 }
       
   270             }
       
   271         CleanupStack::PopAndDestroy( &serviceIds );
       
   272         }
       
   273     else
       
   274         {
       
   275         for ( TInt i( 0 ); i < iServices.Count(); i++ )
       
   276             {
       
   277             iServices[ i ]->UpdateL();
       
   278             }    
       
   279         }
       
   280     
       
   281     CCHLOGSTRING( "CCCHServiceHandler::UpdateL: OUT" );
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CCCHServiceHandler::IsStartupFlagSet
       
   286 // (other items were commented in a header).
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 TBool CCCHServiceHandler::IsStartupFlagSet() const
       
   290     {
       
   291     TBool ret( EFalse );
       
   292 
       
   293     for ( TInt i( 0 ); i < iServices.Count() && !ret; i++ )
       
   294         {
       
   295         ret = iServices[ i ]->StartupFlagSet();
       
   296         }
       
   297         
       
   298     CCHLOGSTRING2( "CCCHServiceHandler::IsStartupFlagSet: %d", ret );
       
   299     return ret;
       
   300     }
       
   301 
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CCCHServiceHandler::IsRecoveryNeeded
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TBool CCCHServiceHandler::IsRecoveryNeeded( 
       
   309                                const TCCHSubserviceState aState, 
       
   310                                TInt aError )
       
   311     {
       
   312     TBool recover( EFalse );
       
   313     CCHLOGSTRING( "CCCHServiceHandler::IsRecoveryNeeded: IN" );
       
   314     if( !iServer.FeatureManager().OfflineMode() &&
       
   315         ECCHConnecting == aState && ( 
       
   316         KCCHErrorNetworkLost == aError || 
       
   317         KCCHErrorServiceNotResponding == aError ) &&
       
   318         !iConnectionRecoveryTimer->IsActive() )
       
   319         {
       
   320         recover = ETrue;            
       
   321         }
       
   322     CCHLOGSTRING2( "CCCHServiceHandler::IsRecoveryNeeded: OUT, value=%d", recover );
       
   323     return recover;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CCCHServiceHandler::StateChangedL
       
   328 // (other items were commented in a header).
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CCCHServiceHandler::StateChangedL( const TUint aServiceId,
       
   332                                         const TCCHSubserviceType aType,
       
   333                                         const TCCHSubserviceState aState,
       
   334                                         const TInt aError )
       
   335     {
       
   336     
       
   337     CCHLOGSTRING( "CCCHServiceHandler::StateChanged: IN" );
       
   338     CCHLOGSTRING2( "CCCHServiceHandler::StateChanged: service id;        %d",aServiceId );
       
   339     CCHLOGSTRING2( "CCCHServiceHandler::StateChanged: service type;      %d",aType );
       
   340     CCHLOGSTRING2( "CCCHServiceHandler::StateChanged: service new state; %d",aState );
       
   341     CCHLOGSTRING2( "CCCHServiceHandler::StateChanged: service error;     %d",aError );
       
   342     TInt index( FindService( aServiceId ) );
       
   343     if ( KErrNotFound != index )
       
   344         {
       
   345         iServices[ index ]->SetErrorL( aType, aError );
       
   346         iServices[ index ]->SetStateL( aType, aState );
       
   347         //toggle voip indicator & emergency note if needed
       
   348         if( ECCHVoIPSub == aType )
       
   349             {
       
   350             iCchUIHandler->UpdateUI( );
       
   351             }
       
   352         
       
   353         // Check for possible first usage of GPRS (roaming cost warning)
       
   354         TServiceConnectionInfo serviceConnInfo( aServiceId, aType, 0, 0 );
       
   355         GetConnectionInfo( serviceConnInfo );
       
   356         
       
   357         if ( serviceConnInfo.iIapId && ECCHEnabled == aState )
       
   358             {
       
   359             if( !iCommDbWatcher->IsWlanApL( serviceConnInfo.iIapId ) )
       
   360                 {                
       
   361                 iCchUIHandler->CheckGprsFirstUsageL();
       
   362                 }
       
   363             }
       
   364         
       
   365         //unload useless plugins    
       
   366         if( ECCHDisabled == aState )
       
   367             {
       
   368             StartPluginUnloadTimer( );
       
   369             }
       
   370         //start fast recovery if not started
       
   371         else if( IsRecoveryNeeded( aState, aError ) )
       
   372             {
       
   373             CCHLOGSTRING( "CCCHServiceHandler::StateChangedL network lost, starting recovery" );
       
   374             iServicesInRecovery.Append( TServiceSelection( aServiceId, aType ) );
       
   375             StartConnectionRecoveryTimer( CCCHServiceHandler::ConnectionRecoveryEvent );                
       
   376             }
       
   377         //stop fast recovery
       
   378         if( ECCHConnecting != aState && 
       
   379                 KErrNone == aError &&
       
   380                 0 < iServicesInRecovery.Count() )
       
   381             {
       
   382             CCHLOGSTRING( "CCCHServiceHandler::StateChangedL checking if recovery is still needed" );
       
   383             TInt idx = iServicesInRecovery.Find( TServiceSelection( aServiceId, aType ) );
       
   384             if( KErrNotFound != idx )
       
   385                 {
       
   386                 CCHLOGSTRING( "CCCHServiceHandler::StateChangedL this service has recovered, recovery still on..." );
       
   387                 iServicesInRecovery.Remove( idx );
       
   388                 }
       
   389             if( 0 == iServicesInRecovery.Count() )
       
   390                 {
       
   391                 CCHLOGSTRING( "CCCHServiceHandler::StateChangedL all services recovered, stopping recovery" );
       
   392                 CancelConnectionRecoveryTimer();
       
   393                 }
       
   394             }
       
   395         
       
   396         if ( ECCHConnecting != aState || 
       
   397             ECCHConnecting == aState && KErrNone != aError )
       
   398             {
       
   399             // reset startup counter
       
   400             TBool startupFlag( EFalse );
       
   401             iServer.SPSHandler().LoadAtStartUpL( aServiceId, aType, startupFlag );
       
   402             if ( startupFlag )
       
   403                 {
       
   404                 iServer.ResetStartupCounterL();
       
   405                 }
       
   406             }
       
   407         }
       
   408     else
       
   409         {
       
   410         User::Leave( index );
       
   411         }
       
   412     CCHLOGSTRING( "CCCHServiceHandler::StateChanged: OUT" );
       
   413         
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CCCHServiceHandler::StartConnectionRecoveryTimer
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 void CCCHServiceHandler::StartConnectionRecoveryTimer( TInt (*aFunction)(TAny* aPtr) )
       
   421     {
       
   422     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::StartConnectionRecoveryTimer; IN", this );
       
   423     CancelConnectionRecoveryTimer();
       
   424     if( !iConnectionRecoveryTimer->IsActive() )
       
   425         {
       
   426         iConnectionRecoveryTry = 0;
       
   427         iConnectionRecoveryTimer->Start( iRecoveryInterval[ iConnectionRecoveryTry ] , 
       
   428                               0, 
       
   429                               TCallBack( aFunction, this ) );
       
   430         CCHLOGSTRING( "CCCHServiceHandler::StartConnectionRecoveryTimer; recovery timer started");
       
   431         
       
   432         }
       
   433     CCHLOGSTRING( "CCCHServiceHandler::StartConnectionRecoveryTimer; OUT");
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CCCHServiceHandler::CancelConnectionRecoveryTimer
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CCCHServiceHandler::CancelConnectionRecoveryTimer()
       
   441     {
       
   442     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::CancelConnectionRecoveryTimer; IN", this );
       
   443 
       
   444     if( iConnectionRecoveryTimer->IsActive() )
       
   445         {
       
   446         iConnectionRecoveryTimer->Cancel();
       
   447         }
       
   448     CCHLOGSTRING( "CCCHServiceHandler::CancelConnectionRecoveryTimer; OUT" );        
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CCCHServiceHandler::ConnectionRecoveryEvent
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 TInt CCCHServiceHandler::ConnectionRecoveryEvent( TAny* aSelf )
       
   456     {
       
   457     CCHLOGSTRING( "CCCHServiceHandler::ConnectionRecoveryEvent; IN" );
       
   458     CCCHServiceHandler* self = static_cast<CCCHServiceHandler*>( aSelf );
       
   459     self->HandleConnectionRecovery();
       
   460     CCHLOGSTRING( "CCCHServiceHandler::ConnectionRecoveryEvent; OUT" );
       
   461     return 0;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CCCHServiceHandler::HandleConnectionRecovery
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CCCHServiceHandler::HandleConnectionRecovery()
       
   469     {
       
   470     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::HandleConnectionRecovery IN",
       
   471                    this );
       
   472     iConnectionRecoveryTry++;
       
   473     CCHLOGSTRING2( "CCCHServiceHandler::HandleConnectionRecovery; recovery try:%d",iConnectionRecoveryTry );
       
   474     iServer.ConnMonHandler().ScanNetworks( ETrue );    
       
   475     CancelConnectionRecoveryTimer();
       
   476     
       
   477     if( KConnectionRecoveryMaxTries > iConnectionRecoveryTry )
       
   478         {
       
   479         CCHLOGSTRING( "CCCHServiceHandler::HandleConnectionRecovery; recovery continues" );
       
   480         iConnectionRecoveryTimer->Start( iRecoveryInterval[ iConnectionRecoveryTry ], 
       
   481                               0,
       
   482                               TCallBack( CCCHServiceHandler::ConnectionRecoveryEvent, this ) );
       
   483         }
       
   484     else
       
   485         {
       
   486         CCHLOGSTRING( "CCCHServiceHandler::HandleConnectionRecovery; max tries reached, recovery canceled" );
       
   487         }                   
       
   488     CCHLOGSTRING( "CCCHServiceHandler::HandleConnectionRecovery OUT" );
       
   489     }
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // CCCHServiceHandler::StartPluginUnloadTimer
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 void CCCHServiceHandler::StartPluginUnloadTimer( )
       
   496     {
       
   497     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::StartPluginUnloadTimer; IN", this );
       
   498     CancelPluginUnloadTimer();
       
   499     if( !iPluginUnloadTimer->IsActive() )
       
   500         {
       
   501         iPluginUnloadTimer->Start( KCCHPluginUnloadTimeout , 
       
   502                               0, 
       
   503                               TCallBack( CCCHServiceHandler::PluginUnloadEvent, this ) );
       
   504         CCHLOGSTRING( "CCCHServiceHandler::StartPluginUnloadTimer; plugin unload timer started");
       
   505         
       
   506         }
       
   507     CCHLOGSTRING( "CCCHServiceHandler::StartPluginUnloadTimer; OUT");
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CCCHServiceHandler::CancelPluginUnloadTimer
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CCCHServiceHandler::CancelPluginUnloadTimer()
       
   515     {
       
   516     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::CancelPluginUnloadTimer; IN", this );
       
   517 
       
   518     if( iPluginUnloadTimer->IsActive() )
       
   519         {
       
   520         iPluginUnloadTimer->Cancel();
       
   521         }
       
   522     CCHLOGSTRING( "CCCHServiceHandler::CancelPluginUnloadTimer; OUT" );        
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CCCHServiceHandler::PluginUnloadEvent
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 TInt CCCHServiceHandler::PluginUnloadEvent( TAny* aSelf )
       
   530     {
       
   531     CCHLOGSTRING( "CCCHServiceHandler::PluginUnloadEvent; IN" );
       
   532     CCCHServiceHandler* self = static_cast<CCCHServiceHandler*>( aSelf );
       
   533     self->HandlePluginUnload();
       
   534     CCHLOGSTRING( "CCCHServiceHandler::PluginUnloadEvent; OUT" );
       
   535     return 0;
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // CCCHServiceHandler::HandlePluginUnload
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 void CCCHServiceHandler::HandlePluginUnload()
       
   543     {
       
   544     CCHLOGSTRING2( "CCCHServiceHandler[0x%x]::HandlePluginUnload IN",
       
   545                    this );
       
   546     CancelPluginUnloadTimer();
       
   547     TRAP_IGNORE( UnloadDisabledPluginsL( ) );
       
   548     
       
   549     CCHLOGSTRING( "CCCHServiceHandler::HandlePluginUnload OUT" );
       
   550     }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // CCCHServiceHandler::Exists
       
   554 // (other items were commented in a header).
       
   555 // ---------------------------------------------------------------------------
       
   556 //
       
   557 TBool CCCHServiceHandler::Exists( TCCHSubserviceType aType, 
       
   558                                   TCCHSubserviceState aState,
       
   559                                   TInt aError ) const
       
   560     {
       
   561     CCHLOGSTRING3( "CCCHServiceHandler::Exists(%d,%d)",aType,aState );
       
   562     TBool bReturn( EFalse );
       
   563     for( TInt i( 0 ); i < iServices.Count(); i++ )
       
   564         {
       
   565         for ( TInt j( 0 ); j < iServices[ i ]->SubserviceCount(); j++ )
       
   566             {
       
   567             TCCHSubserviceState state = ECCHUninitialized;
       
   568             TInt err = iServices[ i ]->GetStatus(iServices[ i ]->GetSubserviceType( j ), state );
       
   569             if( err == KErrNone )
       
   570                 {
       
   571                 if( aType == iServices[ i ]->GetSubserviceType( j ) && 
       
   572                     aState == state &&
       
   573                     aError == iServices[ i ]->GetError(iServices[ i ]->GetSubserviceType( j ) ) )
       
   574                     {
       
   575                     bReturn = ETrue;
       
   576                     break;
       
   577                     }
       
   578                 }
       
   579             }
       
   580         }
       
   581     CCHLOGSTRING2( "CCCHServiceHandler::Exists returns: %d",bReturn );        
       
   582     return bReturn;
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 // CCCHServiceHandler::LoadPluginsL
       
   587 // (other items were commented in a header).
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 void CCCHServiceHandler::LoadPluginsL()
       
   591     {
       
   592     CCHLOGSTRING( "CCCHServiceHandler::LoadPluginsL: IN" );
       
   593     
       
   594     // Get plugin uids to array;
       
   595     RArray<TUid> uids;
       
   596     CleanupClosePushL( uids );
       
   597     
       
   598     TUid pluginUid( KNullUid );
       
   599         
       
   600     for( TInt i( 0 ); i < iServices.Count(); i++ )
       
   601         {     
       
   602         for ( TInt j( 0 ); j < iServices[ i ]->SubserviceCount(); j++ )
       
   603             {
       
   604             if ( iServices[ i ]->StartupFlagSet( j ) )
       
   605                 {
       
   606                 pluginUid = iServices[ i ]->GetUidL( j );
       
   607     
       
   608                 if ( KErrNotFound == uids.Find( pluginUid ) && 
       
   609                     KNullUid != pluginUid )
       
   610                     {
       
   611                     uids.Append( pluginUid );
       
   612 
       
   613                     TRAP_IGNORE( 
       
   614                         iServer.PluginHandler().LoadPluginsL( pluginUid ) );
       
   615                     
       
   616                     // Set notifier to loaded Plug-ins                        
       
   617                     iServer.PluginHandler().SetServiceNotifier( this );                        
       
   618                     }
       
   619                 // Enable subservice
       
   620                 TServiceSelection selection;
       
   621                 selection.iServiceId = iServices[ i ]->GetServiceId();
       
   622                 selection.iType = iServices[ i ]->GetSubserviceType( j );
       
   623                 EnableService( selection, EFalse );
       
   624                 }           
       
   625             }
       
   626         }        
       
   627     CleanupStack::PopAndDestroy( &uids );    
       
   628     
       
   629     CCHLOGSTRING( "CCCHServiceHandler::LoadPluginsL: OUT" );
       
   630     }
       
   631 
       
   632 // ---------------------------------------------------------------------------
       
   633 // CCCHServiceHandler::UnloadPlugin
       
   634 // (other items were commented in a header).
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 void CCCHServiceHandler::UnloadDisabledPluginsL( )
       
   638     {
       
   639     CCHLOGSTRING( "CCCHServiceHandler::UnloadDisabledPluginsL: IN" );
       
   640     
       
   641     // Get plugin uids to array;
       
   642     RArray<TUid> uidsToBeUnloaded;
       
   643     RArray<TUid> uidsNotToBeUnloaded;
       
   644     CleanupClosePushL( uidsToBeUnloaded );
       
   645     CleanupClosePushL( uidsNotToBeUnloaded );
       
   646     
       
   647     
       
   648     // ...let's go through services & sub services
       
   649     for ( TInt ixSer=0; ixSer < iServices.Count(); ixSer++ )
       
   650         {
       
   651         for ( TInt ixSub=0; ixSub < iServices[ ixSer ]->SubserviceCount(); ixSub++ )
       
   652             {
       
   653             TUid pluginUid( KNullUid );
       
   654             TInt error( KErrNone );
       
   655             TRAP( error, pluginUid = iServices[ ixSer ]->GetUidL( ixSub ));
       
   656             // if subservice was found
       
   657             if( KErrNone == error )
       
   658                 {
       
   659                 
       
   660                 TCCHSubserviceState state = ECCHUninitialized;
       
   661                 
       
   662                 // subservice was found, so don't need to check return value
       
   663                 iServices[ ixSer ]->GetStatus(
       
   664                      iServices[ ixSer ]->GetSubserviceType( ixSub ), state );
       
   665                      
       
   666                 // if non disabled subservice found, add it to non-unload arry                     
       
   667                 if( ECCHDisabled != state )
       
   668                     {
       
   669                     uidsNotToBeUnloaded.Append( pluginUid );
       
   670                     }
       
   671                     
       
   672                 else
       
   673                     {
       
   674                     if( KErrNotFound == uidsToBeUnloaded.Find( pluginUid ) )
       
   675                         {
       
   676                         // the others go to unload array
       
   677                         uidsToBeUnloaded.Append( pluginUid );        
       
   678                         }
       
   679                     }
       
   680                 }
       
   681             }
       
   682         }
       
   683     iServer.PluginHandler().RemoveServiceNotifier( this );
       
   684     for( TInt i=0; i<uidsToBeUnloaded.Count(); i++ )
       
   685         {
       
   686         //unload plugin & set state if not found from non-unloadable array
       
   687         if( KErrNotFound == uidsNotToBeUnloaded.Find( uidsToBeUnloaded[i] ) )
       
   688             {
       
   689             CCHLOGSTRING2(
       
   690                 "CCCHServiceHandler::UnloadDisabledPluginsL; unloading plugin UID:0x%x",
       
   691                     uidsToBeUnloaded[i] );
       
   692             iServer.PluginHandler().UnloadPlugin( uidsToBeUnloaded[i] );
       
   693             }
       
   694         }
       
   695     iServer.PluginHandler().SetServiceNotifier( this );
       
   696     CleanupStack::PopAndDestroy( &uidsNotToBeUnloaded );   
       
   697     CleanupStack::PopAndDestroy( &uidsToBeUnloaded );    
       
   698     CCHLOGSTRING( "CCCHServiceHandler::UnloadDisabledPluginsL: OUT" );
       
   699     }
       
   700 
       
   701 // ---------------------------------------------------------------------------
       
   702 // CCCHServiceHandler::EnableService
       
   703 // (other items were commented in a header).
       
   704 // ---------------------------------------------------------------------------
       
   705 //
       
   706 TInt CCCHServiceHandler::EnableService( 
       
   707     const TServiceSelection aServiceSelection, 
       
   708     const TBool aConnectivityCheck )
       
   709     {
       
   710     CCHLOGSTRING( "CCCHServiceHandler::EnableService: IN" );
       
   711     TInt error( ServiceExist( aServiceSelection ) );
       
   712     TBool connectionOk( EFalse );
       
   713     if ( KErrNotFound != error )
       
   714         {
       
   715         TInt index = error;
       
   716         TRAP( error, connectionOk = IsServiceConnectivityDefinedL( aServiceSelection ) );
       
   717         if( KErrNone == error )
       
   718             {
       
   719             if( connectionOk )
       
   720                 {
       
   721                 if( iCancelNotify )
       
   722                     {
       
   723                     DisableNotifyChange();
       
   724                     }
       
   725          
       
   726                 CCHLOGSTRING3( "CCCHServiceHandler::EnableService: service:%d, type:%d",
       
   727                         aServiceSelection.iServiceId, aServiceSelection.iType );
       
   728     
       
   729                 // If client wants to enable VoIP subservice and VoIP are not supported
       
   730                 // send KErrNotSupported notify to the client
       
   731                 if ( ( ECCHUnknown == aServiceSelection.iType ||
       
   732                        ECCHVoIPSub == aServiceSelection.iType ) &&
       
   733                        iServices[ index ]->SubserviceExist( ECCHVoIPSub ) &&
       
   734                        !iServer.FeatureManager().VoIPSupported() )
       
   735                     {
       
   736                     CCHLOGSTRING( "CCCHServiceHandler::EnableService: No support for VoIP" );
       
   737                     TRAP_IGNORE( iServices[ index ]->SetErrorL( ECCHVoIPSub, KErrNotSupported ) );
       
   738                     TRAP_IGNORE( iServices[ index ]->SetStateL( ECCHVoIPSub, ECCHDisabled ) );
       
   739                     // Enable one by one all subservices except VoIP
       
   740                     if ( ECCHUnknown == aServiceSelection.iType )
       
   741                         {
       
   742                         for ( TInt i( 0 ); i < iServices[ index ]->SubserviceCount(); i++ )
       
   743                             {
       
   744                             if ( ECCHVoIPSub != iServices[ index ]->GetSubserviceType( i ) )
       
   745                                 {
       
   746                                 TRAP( error, iServices[ index ]->EnableL(
       
   747                                     iServices[ index ]->GetSubserviceType( i ),
       
   748                                         aConnectivityCheck, this ) );
       
   749                                 }
       
   750                             }
       
   751                         }
       
   752                     }
       
   753                 else
       
   754                     {
       
   755                     TRAP( error, iServices[ index ]->EnableL( 
       
   756                         aServiceSelection.iType, aConnectivityCheck, this ) );
       
   757                     }
       
   758                 if( iCancelNotify )
       
   759                     {
       
   760                     EnableNotifyChange();
       
   761                     }
       
   762                 if( HasWlanIap( aServiceSelection ) && KErrNone == error )
       
   763                     {
       
   764                     CCHLOGSTRING( "CCCHServiceHandler::EnableService: Launching WLAN scan..." );
       
   765                     TRAP_IGNORE( iWlanExtension->EnableWlanScanL() );
       
   766                     }
       
   767                 // There could be new Plug-ins after EnableL, so we must set
       
   768                 // notifier to loaded Plug-ins
       
   769                 iServer.PluginHandler().SetServiceNotifier( this );
       
   770                 }
       
   771             else
       
   772                 {
       
   773                 error = KCCHErrorAccessPointNotDefined;
       
   774                 }
       
   775             CCHLOGSTRING2
       
   776                     ( "CCCHServiceHandler::EnableService: error: %d", error );
       
   777             }
       
   778         }
       
   779     CCHLOGSTRING( "CCCHServiceHandler::EnableService: OUT" );
       
   780     return error;
       
   781     }
       
   782 
       
   783 // ---------------------------------------------------------------------------
       
   784 // CCCHServiceHandler::DisableService
       
   785 // (other items were commented in a header).
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 TInt CCCHServiceHandler::DisableService( 
       
   789     const TServiceSelection aServiceSelection )
       
   790     {
       
   791     CCHLOGSTRING( "CCCHServiceHandler::DisableService: IN" );
       
   792     TInt error( ServiceExist( aServiceSelection ) );
       
   793     
       
   794     if ( KErrNotFound != error )
       
   795         {
       
   796         TInt index( error );
       
   797         if( iCancelNotify )
       
   798             {
       
   799             DisableNotifyChange();
       
   800             }
       
   801 
       
   802         TRAP( error, iServices[ index ]->DisableL(
       
   803             aServiceSelection.iType ) );
       
   804         
       
   805         DisableWlanScan();
       
   806         if( iCancelNotify )
       
   807             {
       
   808             EnableNotifyChange();            
       
   809             }
       
   810             CCHLOGSTRING2
       
   811                 ( "CCCHServiceHandler::DisableService: error: %d", error );
       
   812         }
       
   813     CCHLOGSTRING2(
       
   814         "CCCHServiceHandler::DisableService: return %d OUT", error );
       
   815     return error;
       
   816     }
       
   817     
       
   818 // ---------------------------------------------------------------------------
       
   819 // CCCHServiceHandler::DisableWlanScan
       
   820 // (other items were commented in a header).
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 void CCCHServiceHandler::DisableWlanScan( )
       
   824     {
       
   825     CCHLOGSTRING( "CCCHServiceHandler::DisableWlanScan: IN" );
       
   826     
       
   827     TBool disableWlanScan( ETrue );
       
   828     TCCHSubserviceState serviceState( ECCHUninitialized );
       
   829     TCCHSubserviceType serviceType( ECCHUnknown );
       
   830     TInt serviceId( 0 );
       
   831     
       
   832      // ...let's go through services & sub services
       
   833     for ( TInt ixSer = 0; ixSer < iServices.Count(); ixSer++ )
       
   834         {
       
   835         for ( TInt ixSub = 0; ixSub < iServices[ ixSer ]->SubserviceCount(); ixSub++ )
       
   836             {
       
   837             serviceType = iServices[ ixSer ]->GetSubserviceType( ixSub );
       
   838             TInt err = iServices[ ixSer ]->GetStatus( serviceType, serviceState );
       
   839             if( err == KErrNone )
       
   840                 {
       
   841                 // if found even one enabled/connecting service, do not deactivate scan
       
   842                 if( ECCHEnabled == serviceState || ECCHConnecting == serviceState )
       
   843                     {
       
   844                     serviceId =  iServices[ ixSer ]->GetServiceId();
       
   845                     
       
   846                     TServiceConnectionInfo serviceConnInfo( serviceId, serviceType, 0, 0 );
       
   847                     GetConnectionInfo( serviceConnInfo );
       
   848                     // existing snap overrides iap
       
   849                     if( serviceConnInfo.iSNAPId != 0 )
       
   850                         {
       
   851                         TInt wlanIaps( 0 );
       
   852                         TInt allIaps( 0 );
       
   853                         TInt error( KErrNone );
       
   854                         TRAP( error, 
       
   855                             {
       
   856                             wlanIaps = iCommDbWatcher->GetIapCountFromSnap( serviceConnInfo.iSNAPId, ETrue, ETrue );
       
   857                             allIaps = iCommDbWatcher->GetIapCountFromSnap( serviceConnInfo.iSNAPId, EFalse );
       
   858                             } );
       
   859                         
       
   860                         // in case of possibility -> WLAN ALR we need to keep the scan active
       
   861                         // in case of possibility -> do not disable wlan scan if there is only one iap 
       
   862                         // and the iap is wlan
       
   863                         if( KErrNone == error )
       
   864                             {
       
   865                             if( 1 <= allIaps && 0 < wlanIaps )
       
   866                                 {
       
   867                                 disableWlanScan = EFalse;
       
   868                                 break;
       
   869                                 }
       
   870                             }
       
   871                         }
       
   872                     else if( serviceConnInfo.iIapId != 0 )
       
   873                         {
       
   874                         TInt error( KErrNone );
       
   875                         TBool isWlanIap( EFalse );
       
   876                         
       
   877                         TRAP( error, isWlanIap = iCommDbWatcher->IsWlanApL( serviceConnInfo.iIapId ) )
       
   878                         CCHLOGSTRING2( "CCCHServiceHandler::DisableWlanScan: error: %d", error );
       
   879                         
       
   880                         if( KErrNone == error)
       
   881                             {
       
   882                             //in case the iap is wlan type, scan is not deactivated
       
   883                             if( isWlanIap )
       
   884                                 {
       
   885                                 disableWlanScan = EFalse;
       
   886                                 break;
       
   887                                 }
       
   888                             }
       
   889                         }
       
   890                     }
       
   891                 }
       
   892             }
       
   893         if( !disableWlanScan )
       
   894             {
       
   895             break;
       
   896             }
       
   897         }            
       
   898     if( disableWlanScan )
       
   899         {
       
   900         CCHLOGSTRING( "CCCHServiceHandler::DisableWlanScan disabling wlan scan..." );
       
   901         
       
   902         TRAP_IGNORE( iWlanExtension->DisableWlanScanL() ) ;
       
   903         }
       
   904     CCHLOGSTRING( "CCCHServiceHandler::DisableWlanScan: OUT" );
       
   905     }
       
   906     
       
   907 // ---------------------------------------------------------------------------
       
   908 // CCCHServiceHandler::SetConnectionInfo
       
   909 // (other items were commented in a header).
       
   910 // ---------------------------------------------------------------------------
       
   911 //
       
   912 TInt CCCHServiceHandler::SetConnectionInfo( 
       
   913     const TServiceConnectionInfo aServiceConnInfo )
       
   914     {
       
   915     CCHLOGSTRING( "CCCHServiceHandler::SetConnectionInfo: IN" );
       
   916     TInt error( KErrNotFound );
       
   917     CCHLOGSTRING2( "CCCHServiceHandler::SetConnectionInfo: serviceId %d",
       
   918         aServiceConnInfo.iServiceSelection.iServiceId );
       
   919     CCHLOGSTRING2( "CCCHServiceHandler::SetConnectionInfo: iType %d",
       
   920         aServiceConnInfo.iServiceSelection.iType );
       
   921     CCHLOGSTRING2( "CCCHServiceHandler::SetConnectionInfo: iSNAPId %d",
       
   922         aServiceConnInfo.iSNAPId );
       
   923     CCHLOGSTRING2( "CCCHServiceHandler::SetConnectionInfo: iIapId %d",
       
   924         aServiceConnInfo.iIapId );
       
   925     CCHLOGSTRING2( "CCCHServiceHandler::SetConnectionInfo: iReserved %d",
       
   926         aServiceConnInfo.iReserved );
       
   927 
       
   928     if ( KErrNotFound != 
       
   929         ( error = FindService( aServiceConnInfo.iServiceSelection.iServiceId ) ) )
       
   930         {
       
   931         TInt index( error );
       
   932         TRAP( error, iServices[ index ]->SetConnectionInfoL( 
       
   933             aServiceConnInfo ) );
       
   934         StartPluginUnloadTimer( );
       
   935         CCHLOGSTRING2
       
   936             ( "CCCHServiceHandler::SetConnectionInfo: error: %d", error );
       
   937         }
       
   938     CCHLOGSTRING( "CCCHServiceHandler::SetConnectionInfo: OUT" );
       
   939     return error;
       
   940     }
       
   941     
       
   942 // ---------------------------------------------------------------------------
       
   943 // CCCHServiceHandler::GetConnectionInfo
       
   944 // (other items were commented in a header).
       
   945 // ---------------------------------------------------------------------------
       
   946 //
       
   947 TInt CCCHServiceHandler::GetConnectionInfo( 
       
   948     TServiceConnectionInfo& aServiceConnInfo )
       
   949     {
       
   950     CCHLOGSTRING( "CCCHServiceHandler::GetConnectionInfo: IN" );
       
   951     TInt error( KErrNotFound );
       
   952     
       
   953     if ( KErrNotFound != 
       
   954         ( error = FindService( aServiceConnInfo.ServiceId() ) ) )
       
   955         {
       
   956         TInt index( error );
       
   957         TRAP( error, iServices[ index ]->GetConnectionInfoL( 
       
   958                 aServiceConnInfo ) );
       
   959         StartPluginUnloadTimer( );
       
   960         CCHLOGSTRING2
       
   961             ( "CCCHServiceHandler::GetConnectionInfo: error: %d", error );
       
   962         }
       
   963     CCHLOGSTRING( "CCCHServiceHandler::GetConnectionInfo: OUT" );
       
   964     return error;
       
   965     }
       
   966 
       
   967 // ---------------------------------------------------------------------------
       
   968 // CCCHServiceHandler::UsesWlanIapL
       
   969 // (other items were commented in a header).
       
   970 // ---------------------------------------------------------------------------
       
   971 //
       
   972 TBool CCCHServiceHandler::UsesWlanIap( 
       
   973     const TServiceSelection& aServiceSelection )
       
   974     {
       
   975     CCHLOGSTRING( "CCCHServiceHandler::UsesWlanIap: IN" );
       
   976     TBool isWlanIap( EFalse );
       
   977     TServiceConnectionInfo serviceConnInfo(
       
   978             aServiceSelection.iServiceId, aServiceSelection.iType, 0, 0 );
       
   979     CCHLOGSTRING3( "CCCHServiceHandler::UsesWlanIap: service:%d, type:%d",
       
   980             aServiceSelection.iServiceId, aServiceSelection.iType );
       
   981     
       
   982     TInt error = GetConnectionInfo( serviceConnInfo );
       
   983     
       
   984     if( KErrNone == error )
       
   985         {
       
   986         
       
   987         CCHLOGSTRING3( "CCCHServiceHandler::UsesWlanIap: snap:%d, snap:%d",
       
   988                 serviceConnInfo.iSNAPId, serviceConnInfo.iIapId );
       
   989         if( 0 != serviceConnInfo.iSNAPId )
       
   990             {
       
   991             CCHLOGSTRING( "CCCHServiceHandler::UsesWlanIapL: SNAP in use" );
       
   992             TInt count( 0 );
       
   993             TRAP( error, count = iCommDbWatcher->GetIapCountFromSnap( serviceConnInfo.iSNAPId, ETrue ));
       
   994             if( KErrNone == error && 0 < count )
       
   995                 {
       
   996                 isWlanIap = ETrue;
       
   997                 }
       
   998             }
       
   999         else if( 0 != serviceConnInfo.iIapId )
       
  1000             {
       
  1001             CCHLOGSTRING( "CCCHServiceHandler::UsesWlanIapL: IAP in use" );
       
  1002            
       
  1003             TRAP( error, isWlanIap = iCommDbWatcher->IsWlanApL( serviceConnInfo.iIapId ) );
       
  1004             CCHLOGSTRING2( "CCCHServiceHandler::UsesWlanIap: error: %d", error );
       
  1005             }
       
  1006 
       
  1007 
       
  1008         }
       
  1009     CCHLOGSTRING2( "CCCHServiceHandler::UsesWlanIap: OUT, value=%d", isWlanIap );
       
  1010     return isWlanIap;
       
  1011     }
       
  1012 
       
  1013 // ---------------------------------------------------------------------------
       
  1014 // CCCHServiceHandler::IsConnectionDefined
       
  1015 // (other items were commented in a header).
       
  1016 // ---------------------------------------------------------------------------
       
  1017 //
       
  1018 TBool CCCHServiceHandler::IsConnectionDefinedL( 
       
  1019     const TServiceSelection& aServiceSelection ) 
       
  1020     {
       
  1021     CCHLOGSTRING( "CCCHServiceHandler::IsConnectionDefined: IN" );
       
  1022     TBool isOk( EFalse );
       
  1023     __ASSERT_DEBUG( aServiceSelection.iType != ECCHUnknown, User::Panic( KNullDesC, KErrGeneral ) );
       
  1024     TServiceConnectionInfo serviceConnInfo(
       
  1025             aServiceSelection.iServiceId, aServiceSelection.iType, 0, 0 );
       
  1026     CCHLOGSTRING3( "CCCHServiceHandler::IsConnectionDefined: service:%d, type:%d",
       
  1027             aServiceSelection.iServiceId, aServiceSelection.iType );
       
  1028     
       
  1029     TInt error = GetConnectionInfo( serviceConnInfo );
       
  1030     User::LeaveIfError( error );
       
  1031     
       
  1032     CCHLOGSTRING3( "CCCHServiceHandler::IsConnectionDefined: snap:%d, snap:%d",
       
  1033             serviceConnInfo.iSNAPId, serviceConnInfo.iIapId );
       
  1034     if( 0 != serviceConnInfo.iSNAPId )
       
  1035         {
       
  1036         TInt count( 0 );
       
  1037         count = iCommDbWatcher->GetIapCountFromSnap( serviceConnInfo.iSNAPId, EFalse, ETrue );
       
  1038         CCHLOGSTRING( "CCCHServiceHandler::IsConnectionDefined: SNAP in use" );
       
  1039         if( KErrNone == error && 0 < count )
       
  1040             {
       
  1041             isOk = ETrue;
       
  1042             }
       
  1043         }
       
  1044     else if( 0 != serviceConnInfo.iIapId )
       
  1045         {
       
  1046         CCHLOGSTRING( "CCCHServiceHandler::IsConnectionDefined: IAP in use" );
       
  1047         isOk = ETrue;
       
  1048         }
       
  1049 
       
  1050     CCHLOGSTRING2( "CCCHServiceHandler::IsConnectionDefined: OUT, value=%d", isOk );
       
  1051     return isOk;
       
  1052     }
       
  1053 
       
  1054 // ---------------------------------------------------------------------------
       
  1055 // CCCHServiceHandler::IsServiceConnectivityDefined
       
  1056 // (other items were commented in a header).
       
  1057 // ---------------------------------------------------------------------------
       
  1058 //
       
  1059 TBool CCCHServiceHandler::IsServiceConnectivityDefinedL( 
       
  1060     const TServiceSelection& aServiceSelection ) 
       
  1061     {
       
  1062     CCHLOGSTRING( "CCCHServiceHandler::IsServiceConnectivityDefined: IN" );
       
  1063     
       
  1064     TBool isOk( EFalse );
       
  1065     TInt error( KErrNone );
       
  1066     TInt index = FindService( aServiceSelection.iServiceId );
       
  1067     if ( KErrNotFound != index )
       
  1068         {
       
  1069         if( ECCHUnknown == aServiceSelection.iType )
       
  1070             {
       
  1071             for( TInt i = 0; i < iServices[ index ]->SubserviceCount(); i++ )
       
  1072                 {
       
  1073                 TRAP( error, isOk = IsConnectionDefinedL( 
       
  1074                         TServiceSelection( aServiceSelection.iServiceId, 
       
  1075                         iServices[ index ]->GetSubserviceType( i ) ) ) ) ;
       
  1076                 if( isOk )
       
  1077                     {
       
  1078                     error = KErrNone;
       
  1079                     break;
       
  1080                     }
       
  1081                 }
       
  1082             }
       
  1083         else
       
  1084             {
       
  1085             TRAP( error, isOk = IsConnectionDefinedL( aServiceSelection ) );
       
  1086             }    
       
  1087         }
       
  1088     CCHLOGSTRING3( 
       
  1089         "CCCHServiceHandler::IsServiceConnectivityDefined: OUT, value=%d, error=%d", isOk, error );
       
  1090     User::LeaveIfError( error );
       
  1091     return isOk;
       
  1092     }
       
  1093 
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // CCCHServiceHandler::HasWlanIap
       
  1097 // (other items were commented in a header).
       
  1098 // ---------------------------------------------------------------------------
       
  1099 //
       
  1100 TBool CCCHServiceHandler::HasWlanIap( 
       
  1101     const TServiceSelection& aServiceSelection )
       
  1102     {
       
  1103     CCHLOGSTRING( "CCCHServiceHandler::HasWlanIap: IN" );
       
  1104     
       
  1105     TBool isWlanIap( EFalse );
       
  1106     TInt index = FindService( aServiceSelection.iServiceId );
       
  1107     if ( KErrNotFound != index )
       
  1108         {
       
  1109         if( ECCHUnknown == aServiceSelection.iType )
       
  1110             {
       
  1111             for( TInt i = 0; i < iServices[ index ]->SubserviceCount(); i++ )
       
  1112                 {
       
  1113                 isWlanIap = UsesWlanIap( 
       
  1114                         TServiceSelection( aServiceSelection.iServiceId, 
       
  1115                         iServices[ index ]->GetSubserviceType( i ) ) ) ;
       
  1116                 if( isWlanIap )
       
  1117                     {
       
  1118                     break;
       
  1119                     }
       
  1120                 }
       
  1121             }
       
  1122         else
       
  1123             {
       
  1124             isWlanIap = UsesWlanIap( aServiceSelection );
       
  1125             }    
       
  1126         StartPluginUnloadTimer( );
       
  1127         }
       
  1128     CCHLOGSTRING2( "CCCHServiceHandler::HasWlanIap: OUT, value=%d", isWlanIap );
       
  1129     return isWlanIap;
       
  1130     }
       
  1131 
       
  1132 // ---------------------------------------------------------------------------
       
  1133 // CCCHServiceHandler::ServiceCountL
       
  1134 // (other items were commented in a header).
       
  1135 // ---------------------------------------------------------------------------
       
  1136 //
       
  1137 void CCCHServiceHandler::ServiceCountL( RMessage2 aMessage ) const
       
  1138     {
       
  1139     CCHLOGSTRING( "CCCHServiceHandler::ServiceCountL: IN" );
       
  1140     
       
  1141     TPckgBuf<TUint32> pckgServiceCount;
       
  1142     aMessage.ReadL( 0, pckgServiceCount );
       
  1143     TCCHSubserviceType type( 
       
  1144         static_cast<TCCHSubserviceType>( aMessage.Int1() ) );
       
  1145     
       
  1146     if ( ECCHUnknown == type )
       
  1147         {
       
  1148         // Count of services
       
  1149         pckgServiceCount() = iServer.SPSHandler().GetServicesCountL();
       
  1150         // Service count back to the client
       
  1151         aMessage.WriteL( 0, pckgServiceCount );
       
  1152         }
       
  1153     else
       
  1154         {
       
  1155         // Count of services which contains subservices
       
  1156         pckgServiceCount() = ServiceCount( type );
       
  1157         // Service count back to the client
       
  1158         aMessage.WriteL( 0, pckgServiceCount );
       
  1159         }        
       
  1160     
       
  1161     CCHLOGSTRING( "CCCHServiceHandler::ServiceCountL: OUT" );
       
  1162     }
       
  1163 
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // CCCHServiceHandler::GetServicesL
       
  1166 // (other items were commented in a header).
       
  1167 // ---------------------------------------------------------------------------
       
  1168 //
       
  1169 void CCCHServiceHandler::GetServicesL( RMessage2 aMessage ) const
       
  1170     {
       
  1171     CCHLOGSTRING( "CCCHServiceHandler::GetServicesL: IN" );
       
  1172     TInt count =  iServices.Count();
       
  1173     TInt index( KErrNotFound );
       
  1174     if ( count )
       
  1175         {
       
  1176         TUint32 serviceId = aMessage.Int0();
       
  1177         TCCHSubserviceType type ( ECCHUnknown );
       
  1178         type = static_cast<TCCHSubserviceType>( aMessage.Int1() );
       
  1179         
       
  1180         if ( KErrNotFound == aMessage.Int0() )
       
  1181             {
       
  1182             serviceId = KErrNone;
       
  1183             }
       
  1184         else if ( serviceId != KErrNone )
       
  1185             {
       
  1186             count = 1;
       
  1187             }
       
  1188                     
       
  1189         CArrayFixFlat<TCCHService>* serviceArray = 
       
  1190             new( ELeave )CArrayFixFlat<TCCHService>( count );
       
  1191         CleanupStack::PushL( serviceArray );
       
  1192         
       
  1193         TCCHService service;
       
  1194         // Get all services
       
  1195         if ( KErrNone == serviceId )
       
  1196             {
       
  1197             if ( type == ECCHUnknown )
       
  1198                 {
       
  1199                 for ( TInt i( 0 ); i < count; i++ )
       
  1200                     {
       
  1201                     iServices[ i ]->FillServiceInfo( service );
       
  1202                     serviceArray->AppendL( service );
       
  1203                     }    
       
  1204                 }
       
  1205             else
       
  1206                 {
       
  1207                 for ( TInt i( 0 ); i < count; i++ )
       
  1208                     {
       
  1209                     if ( iServices[ i ]->SubserviceExist( type ) )
       
  1210                         {
       
  1211                         iServices[ i ]->FillServiceInfo( service );
       
  1212                         serviceArray->AppendL( service );
       
  1213                         }                    
       
  1214                     }
       
  1215                 }
       
  1216             }
       
  1217         // Get specified service
       
  1218         else 
       
  1219             {
       
  1220             if ( type == ECCHUnknown )
       
  1221                 {
       
  1222                 index = FindService( serviceId );
       
  1223                 if ( KErrNotFound != index )
       
  1224                     {
       
  1225                     iServices[ index ]->FillServiceInfo( service );
       
  1226                     serviceArray->AppendL( service );
       
  1227                     }
       
  1228                 }
       
  1229             else
       
  1230                 {
       
  1231                 TServiceSelection selection( serviceId, type ); 
       
  1232                 index = ServiceExist( selection );
       
  1233                 if ( KErrNotFound != index )
       
  1234                     {
       
  1235                     iServices[ index ]->FillServiceInfo( service );
       
  1236                     serviceArray->AppendL( service );
       
  1237                     }
       
  1238                 }
       
  1239             }
       
  1240         
       
  1241         TUint32 length = serviceArray->Count() * sizeof( TCCHService );
       
  1242         
       
  1243         if ( length )
       
  1244             {
       
  1245             TPtrC8 servicePtr;
       
  1246             servicePtr.Set( 
       
  1247                 reinterpret_cast<TText8*>( &( *serviceArray )[ 0 ] ), 
       
  1248                     length );
       
  1249             aMessage.WriteL( 2, servicePtr );                     
       
  1250             }
       
  1251         else
       
  1252             {
       
  1253             User::Leave( KErrNotFound );
       
  1254             }            
       
  1255             
       
  1256         CleanupStack::PopAndDestroy( serviceArray );
       
  1257         }
       
  1258     else
       
  1259         {
       
  1260         User::Leave( KErrNotFound );
       
  1261         }
       
  1262     CCHLOGSTRING( "CCCHServiceHandler::GetServicesL: OUT" );
       
  1263     }
       
  1264 
       
  1265 // ---------------------------------------------------------------------------
       
  1266 // CCCHServiceHandler::GetServiceState
       
  1267 // (other items were commented in a header).
       
  1268 // ---------------------------------------------------------------------------
       
  1269 //    
       
  1270 TInt CCCHServiceHandler::GetServiceState( const RMessage2 aMessage )
       
  1271     {
       
  1272     CCHLOGSTRING( "CCCHServiceHandler::GetServiceStateL: IN" );
       
  1273         
       
  1274     TUint32 serviceId( 0 );
       
  1275     TCCHSubserviceType type ( ECCHUnknown );
       
  1276     TPckgBuf<TCCHSubserviceState> status;
       
  1277     serviceId = aMessage.Int0();
       
  1278     type = static_cast<TCCHSubserviceType>( aMessage.Int1() );
       
  1279     
       
  1280     TInt error( FindService( serviceId ) );
       
  1281     TInt errorState = KErrNone;
       
  1282     
       
  1283     if ( KErrNotFound != error )
       
  1284         {
       
  1285         TInt index( error );
       
  1286         TRAP( error, 
       
  1287             {
       
  1288             aMessage.ReadL( 2, status );
       
  1289             errorState = iServices[ index ]->GetStatus( type, status() );
       
  1290             if( errorState == KErrNone )
       
  1291                 {
       
  1292                 aMessage.WriteL( 2, status );
       
  1293                 }
       
  1294             } );
       
  1295         if( KErrNone == error )
       
  1296             {
       
  1297             if( errorState == KErrNone )
       
  1298                 {
       
  1299                 error = iServices[ index ]->GetError( type );
       
  1300                 }
       
  1301             else
       
  1302                 {
       
  1303                 error = errorState;
       
  1304                 }
       
  1305             }
       
  1306         StartPluginUnloadTimer( );
       
  1307         }
       
  1308     
       
  1309     CCHLOGSTRING2( 
       
  1310         "CCCHServiceHandler::GetServiceStateL: return %d OUT", error );
       
  1311     return error;
       
  1312     }
       
  1313 
       
  1314 // ---------------------------------------------------------------------------
       
  1315 // CCCHServiceHandler::GetServiceState
       
  1316 // (other items were commented in a header).
       
  1317 // ---------------------------------------------------------------------------
       
  1318 //    
       
  1319 TCCHSubserviceState CCCHServiceHandler::ServiceState(
       
  1320         const TUint aServiceId )
       
  1321     {
       
  1322     CCHLOGSTRING( "CCCHServiceHandler::ServiceState: IN" );
       
  1323     
       
  1324     TCCHSubserviceState state( ECCHUninitialized );
       
  1325     TInt error( FindService( aServiceId ) );
       
  1326     
       
  1327     if ( KErrNotFound != error )
       
  1328         {
       
  1329         state = iServices[ error ]->GetState();
       
  1330         }
       
  1331     
       
  1332     CCHLOGSTRING2( 
       
  1333         "CCCHServiceHandler::ServiceState: return %d OUT", state );
       
  1334     return state;
       
  1335     }
       
  1336 
       
  1337 // ---------------------------------------------------------------------------
       
  1338 // CCCHServiceHandler::GetServiceInfo
       
  1339 // (other items were commented in a header).
       
  1340 // ---------------------------------------------------------------------------
       
  1341 //    
       
  1342 TInt CCCHServiceHandler::GetServiceInfo( const RMessage2 aMessage )
       
  1343     {
       
  1344     CCHLOGSTRING( "CCCHServiceHandler::GetServiceInfo: IN" );
       
  1345     TBuf<KCCHMaxProtocolNameLength> buffer;
       
  1346 
       
  1347     TPckgBuf<TServiceConnectionInfo> serviceConnInfoPckg;
       
  1348 
       
  1349     TInt error = KErrNone;
       
  1350     TRAP( error, 
       
  1351         { 
       
  1352         aMessage.ReadL( 0, serviceConnInfoPckg );
       
  1353         } );
       
  1354         
       
  1355     if( error ) 
       
  1356         {
       
  1357         return error;
       
  1358         }
       
  1359    
       
  1360     TServiceConnectionInfo conninfo;
       
  1361      
       
  1362     conninfo.iServiceSelection.iServiceId = serviceConnInfoPckg().iServiceSelection.iServiceId;
       
  1363     conninfo.iServiceSelection.iType      = serviceConnInfoPckg().iServiceSelection.iType;
       
  1364     conninfo.iServiceSelection.iParameter = serviceConnInfoPckg().iServiceSelection.iParameter;
       
  1365   
       
  1366     error = ServiceExist( conninfo.iServiceSelection );
       
  1367     
       
  1368     if ( KErrNotFound != error )
       
  1369         {
       
  1370         TInt index( error );
       
  1371 
       
  1372         if( conninfo.iServiceSelection.iParameter == ECchServiceInfo )
       
  1373             {
       
  1374             TRAP( error, 
       
  1375                 {
       
  1376                 iServices[ index ]->GetServiceInfoL( 
       
  1377                     buffer, conninfo.iServiceSelection.iType );
       
  1378                 aMessage.WriteL( 1, buffer );
       
  1379                 } );
       
  1380             }
       
  1381         StartPluginUnloadTimer( );
       
  1382         }
       
  1383     CCHLOGSTRING2( "CCCHServiceHandler::GetServiceInfo: return %d OUT", error );
       
  1384     return error;
       
  1385     }
       
  1386 
       
  1387 // ---------------------------------------------------------------------------
       
  1388 // CCCHServiceHandler::ReserveService
       
  1389 // (other items were commented in a header).
       
  1390 // ---------------------------------------------------------------------------
       
  1391 //    
       
  1392 TInt CCCHServiceHandler::ReserveService( const RMessage2 aMessage ) 
       
  1393     {
       
  1394     CCHLOGSTRING( "CCCHServiceHandler::ReserveService: IN" );
       
  1395     
       
  1396     TServiceSelection serviceSelection(aMessage.Int0(), 
       
  1397         static_cast<TCCHSubserviceType>( aMessage.Int1() ) );
       
  1398     
       
  1399     TInt error( ServiceExist( serviceSelection ) );
       
  1400     
       
  1401     if ( KErrNotFound != error )
       
  1402         {
       
  1403         TInt index( error );
       
  1404         TRAP( error, 
       
  1405             {
       
  1406             iServices[ index ]->ReserveServiceL( 
       
  1407                 serviceSelection.iType );
       
  1408             } );
       
  1409         }
       
  1410     CCHLOGSTRING2( "CCCHServiceHandler::ReserveService: return %d OUT", error );
       
  1411     return error;
       
  1412     }
       
  1413 
       
  1414 // ---------------------------------------------------------------------------
       
  1415 // CCCHServiceHandler::FreeService
       
  1416 // (other items were commented in a header).
       
  1417 // ---------------------------------------------------------------------------
       
  1418 //    
       
  1419 TInt CCCHServiceHandler::FreeService( const RMessage2& aMessage )
       
  1420     {
       
  1421     CCHLOGSTRING( "CCCHServiceHandler::FreeService: IN" );
       
  1422     
       
  1423     TServiceSelection serviceSelection(aMessage.Int0(), 
       
  1424         static_cast<TCCHSubserviceType>( aMessage.Int1() ) );
       
  1425     
       
  1426     TInt error( ServiceExist( serviceSelection ) );
       
  1427     
       
  1428     if ( KErrNotFound != error )
       
  1429         {
       
  1430         TInt index( error );
       
  1431         TRAP( error, 
       
  1432             {
       
  1433             iServices[ index ]->FreeServiceL( 
       
  1434                 serviceSelection.iType );
       
  1435             } );
       
  1436         }
       
  1437     CCHLOGSTRING2( "CCCHServiceHandler::FreeService: return %d OUT", error );        
       
  1438     return error;
       
  1439     }
       
  1440 
       
  1441 // ---------------------------------------------------------------------------
       
  1442 // CCCHServiceHandler::IsReserved
       
  1443 // (other items were commented in a header).
       
  1444 // ---------------------------------------------------------------------------
       
  1445 //
       
  1446 void CCCHServiceHandler::IsReserved( RMessage2 aMessage ) const
       
  1447     {
       
  1448     CCHLOGSTRING( "CCCHServiceHandler::IsReserved: IN" );
       
  1449     
       
  1450     
       
  1451     TServiceSelection serviceSelection(aMessage.Int0(),
       
  1452         static_cast<TCCHSubserviceType>( aMessage.Int1() ) );
       
  1453     TInt error( KErrNone );
       
  1454             
       
  1455     TPckgBuf<TBool> pckgIsReserved;
       
  1456     TRAP( error, aMessage.ReadL( 2, pckgIsReserved ) );
       
  1457     
       
  1458     error = ServiceExist( serviceSelection );
       
  1459     
       
  1460     if ( KErrNotFound != error )
       
  1461         {
       
  1462         TInt index( error );
       
  1463         TRAP( error, 
       
  1464             {
       
  1465             pckgIsReserved() = iServices[ index ]->IsReservedL( 
       
  1466                 serviceSelection.iType );
       
  1467             } );
       
  1468         }
       
  1469         
       
  1470     
       
  1471     if ( KErrNotFound != error )
       
  1472         {
       
  1473         // Service's reference count back to the client
       
  1474         TRAP( error, aMessage.WriteL( 2, pckgIsReserved ) );
       
  1475         }
       
  1476      
       
  1477     
       
  1478     CCHLOGSTRING( "CCCHServiceHandler::IsReserved: OUT" );
       
  1479     }
       
  1480     
       
  1481 // ---------------------------------------------------------------------------
       
  1482 // CCCHServiceHandler::ServiceExist
       
  1483 // (other items were commented in a header).
       
  1484 // ---------------------------------------------------------------------------
       
  1485 //
       
  1486 TInt CCCHServiceHandler::ServiceExist( TServiceSelection aSelection ) const
       
  1487     {
       
  1488     CCHLOGSTRING( "CCCHServiceHandler::ServiceExist: IN" );
       
  1489     TBool exist( EFalse );
       
  1490     TInt index( FindService( aSelection.iServiceId ) );
       
  1491     
       
  1492     if ( KErrNotFound != index )
       
  1493         {
       
  1494         exist = iServices[ index ]->SubserviceExist( aSelection.iType );
       
  1495         }    
       
  1496     CCHLOGSTRING( "CCCHServiceHandler::ServiceExist: OUT" );
       
  1497     return !exist ? KErrNotFound : index;
       
  1498     }
       
  1499 
       
  1500 // ---------------------------------------------------------------------------
       
  1501 // CCCHServiceHandler::FindService
       
  1502 // (other items were commented in a header).
       
  1503 // ---------------------------------------------------------------------------
       
  1504 //
       
  1505 TInt CCCHServiceHandler::FindService( TUint32 aServiceId ) const
       
  1506     {
       
  1507     TBool exist( EFalse );
       
  1508     TInt index( KErrNotFound );
       
  1509     CCHLOGSTRING2( "CCCHServiceHandler::FindService: serviceId %d",
       
  1510         aServiceId );
       
  1511     for ( TInt i( 0 ); i < iServices.Count() && !exist; i++ )
       
  1512         {
       
  1513         exist = iServices[ i ]->GetServiceId() == aServiceId;
       
  1514         index = i;
       
  1515         }
       
  1516     return !exist ? KErrNotFound : index;
       
  1517     }
       
  1518 // ---------------------------------------------------------------------------
       
  1519 // CCCHServiceHandler::HandleNotifyChange
       
  1520 // (other items were commented in a header).
       
  1521 // ---------------------------------------------------------------------------
       
  1522 //
       
  1523 void CCCHServiceHandler::HandleNotifyChange( TServiceId aServiceId )
       
  1524     {
       
  1525     CCHLOGSTRING( "CCCHServiceHandler::HandleNotifyChange: IN" );
       
  1526     TServiceSelection selection;
       
  1527     selection.iServiceId = aServiceId;
       
  1528     TInt index( ServiceExist( selection ) );
       
  1529     TRAPD( err, 
       
  1530         {
       
  1531         if ( KErrNotFound != index )
       
  1532             {
       
  1533             iServices[ index ]->UpdateL( ETrue );
       
  1534             }
       
  1535         else
       
  1536             {
       
  1537             TCCHService service;
       
  1538             iServer.SPSHandler().GetServiceInfoL( aServiceId, service );
       
  1539             AddServiceL( service );
       
  1540             } 
       
  1541         } );
       
  1542     
       
  1543     //Check if service is already marked as enabled, and enable it
       
  1544     if ( KErrNone == err )
       
  1545         {
       
  1546         index = ServiceExist( selection );
       
  1547         if ( KErrNotFound != index )
       
  1548             {
       
  1549             CCHLOGSTRING( "CCCHServiceHandler::HandleNotifyChange: service found" );
       
  1550             if( iServices[ index ]->StartupFlagSet() && 
       
  1551                 ECCHEnabled != iServices[ index ]->GetState() )
       
  1552                 {
       
  1553                 CCHLOGSTRING( "CCCHServiceHandler::HandleNotifyChange: enabling..." );
       
  1554                 iCancelNotify = EFalse;
       
  1555                 EnableService( selection, EFalse );
       
  1556                 iCancelNotify = ETrue;
       
  1557                 }
       
  1558             }
       
  1559         }
       
  1560     
       
  1561     // If service has removed, err must be other than none 
       
  1562     // and we have to update all services
       
  1563     if ( KErrNone != err )
       
  1564         {
       
  1565         TRAP_IGNORE( UpdateL( ETrue ) );
       
  1566         }
       
  1567     CCHLOGSTRING( "CCCHServiceHandler::HandleNotifyChange: OUT" );
       
  1568     }
       
  1569 
       
  1570 // ---------------------------------------------------------------------------
       
  1571 // CCCHServiceHandler::EnableNotifyChange
       
  1572 // (other items were commented in a header).
       
  1573 // ---------------------------------------------------------------------------
       
  1574 //
       
  1575 void CCCHServiceHandler::EnableNotifyChange()
       
  1576     {
       
  1577     TRACE_ENTRY_POINT;
       
  1578     // Subscribe to service change notifies    
       
  1579     TRAP_IGNORE( iNotifier->NotifyChangeL( iServiceIds ) );
       
  1580     TRACE_EXIT_POINT;
       
  1581     }
       
  1582 // ---------------------------------------------------------------------------
       
  1583 // CCCHServiceHandler::DisableNotifyChange
       
  1584 // (other items were commented in a header).
       
  1585 // ---------------------------------------------------------------------------
       
  1586 //
       
  1587 void CCCHServiceHandler::DisableNotifyChange()
       
  1588     {
       
  1589     TRACE_ENTRY_POINT;
       
  1590     iNotifier->Cancel();
       
  1591     TRACE_EXIT_POINT;
       
  1592     }
       
  1593 // ---------------------------------------------------------------------------
       
  1594 // CCCHServiceHandler::ServiceCount
       
  1595 // (other items were commented in a header).
       
  1596 // ---------------------------------------------------------------------------
       
  1597 //
       
  1598 TInt CCCHServiceHandler::ServiceCount( const TCCHSubserviceType aType ) const
       
  1599     {
       
  1600     CCHLOGSTRING2( "CCCHServiceHandler::ServiceCount: type: %d",aType );
       
  1601     
       
  1602     TInt count( 0 );
       
  1603     
       
  1604     for ( TInt i( 0 ); i < iServices.Count(); i++ )
       
  1605         {
       
  1606         if ( KErrNotFound != iServices[ i ]->FindSubservice( aType ) )
       
  1607             {
       
  1608             count++;    
       
  1609             }
       
  1610         }
       
  1611     
       
  1612     CCHLOGSTRING2( "CCCHServiceHandler::ServiceCount: count: %d", count );
       
  1613     
       
  1614     return count;
       
  1615     }
       
  1616 
       
  1617 // ---------------------------------------------------------------------------
       
  1618 // CCCHServiceHandler::HandleError
       
  1619 // (other items were commented in a header).
       
  1620 // ---------------------------------------------------------------------------
       
  1621 //
       
  1622 void CCCHServiceHandler::HandleError( TInt /*aError*/ )
       
  1623     {
       
  1624     
       
  1625     }
       
  1626 
       
  1627 // ---------------------------------------------------------------------------
       
  1628 // CCCHServiceHandler::HandleWLANIapAdded
       
  1629 // (other items were commented in a header).
       
  1630 // ---------------------------------------------------------------------------
       
  1631 //
       
  1632 void CCCHServiceHandler::HandleWLANIapAdded( TInt aSNAPId )
       
  1633     {
       
  1634     CCHLOGSTRING( "CCCHServiceHandler::HandleWLANIapAdded: IN" );
       
  1635     TBool startScan( EFalse );
       
  1636     TCCHSubserviceState serviceState( ECCHUninitialized );
       
  1637     TCCHSubserviceType serviceType( ECCHUnknown );
       
  1638         
       
  1639     // go through all services & subservices
       
  1640     for( TInt i = 0; i < iServices.Count(); i++ )
       
  1641         {
       
  1642         for ( TInt j = 0; j < iServices[ i ]->SubserviceCount(); j++ )
       
  1643             {
       
  1644             serviceType = iServices[ i ]->GetSubserviceType( j );
       
  1645             TInt error = iServices[ i ]->GetStatus( serviceType, serviceState );
       
  1646             
       
  1647             if( KErrNone == error )
       
  1648                 {
       
  1649                 // if we have a connecting or enabled service 
       
  1650                 if( !iServer.FeatureManager().OfflineMode() &&
       
  1651                     ( ECCHConnecting == serviceState || ECCHEnabled == serviceState ) )
       
  1652                     {
       
  1653                     TUint serviceId = iServices[ i ]->GetServiceId();
       
  1654                     TServiceConnectionInfo serviceConnInfo( serviceId, serviceType, 0, 0 );
       
  1655                     GetConnectionInfo( serviceConnInfo );
       
  1656                     
       
  1657                     // with a snap with new wlan iap, we start wlan scan
       
  1658                     if( aSNAPId == serviceConnInfo.iSNAPId && 0 != aSNAPId )
       
  1659                         {
       
  1660                         startScan = ETrue;                    
       
  1661                         }
       
  1662                     }
       
  1663                 }
       
  1664             }
       
  1665         }
       
  1666     if( startScan )        
       
  1667         {
       
  1668         CCHLOGSTRING( "CCCHServiceHandler::HandleWLANIapAdded; starting wlan scan" );
       
  1669         TRAP_IGNORE( iWlanExtension->ForceEnableWlanScanL() );
       
  1670         iServer.ConnMonHandler().ScanNetworks( ETrue );
       
  1671         }
       
  1672 	CCHLOGSTRING( "CCCHServiceHandler::HandleWLANIapAdded: OUT" );
       
  1673 	}
       
  1674 
       
  1675 // ---------------------------------------------------------------------------
       
  1676 // CCCHServiceHandler::GetSubserviceTypesL
       
  1677 // (other items were commented in a header).
       
  1678 // ---------------------------------------------------------------------------
       
  1679 //
       
  1680 void CCCHServiceHandler::GetSubserviceTypesL( 
       
  1681     const TUint aServiceId, 
       
  1682     RArray<TCCHSubserviceType>& aSubserviceTypes ) const
       
  1683     {
       
  1684     TInt index( FindService( aServiceId ) );
       
  1685     if ( KErrNotFound != index )
       
  1686         {
       
  1687         aSubserviceTypes.Reset();
       
  1688         for ( TInt i( 0 ); i < iServices[ index ]->SubserviceCount(); i++ )
       
  1689             {
       
  1690             CCHLOGSTRING2( "    Service contains subservice: %d", 
       
  1691                 iServices[ index ]->GetSubserviceType( i ) );
       
  1692             
       
  1693             aSubserviceTypes.Append( 
       
  1694                     iServices[ index ]->GetSubserviceType( i ) );
       
  1695             }
       
  1696         }
       
  1697     else
       
  1698         {
       
  1699         User::Leave( KErrNotFound );
       
  1700         }
       
  1701     }
       
  1702     
       
  1703 // ---------------------------------------------------------------------------
       
  1704 // CCCHServiceHandler::SetStartupFlag
       
  1705 // (other items were commented in a header).
       
  1706 // ---------------------------------------------------------------------------
       
  1707 //
       
  1708 TInt CCCHServiceHandler::SetStartupFlag(
       
  1709     TServiceSelection aSelection,
       
  1710     TBool aLoadAtStartUp ) const
       
  1711     {
       
  1712     TInt exist( FindService( aSelection.iServiceId ) );
       
  1713     if ( KErrNotFound != exist )
       
  1714         {
       
  1715         exist = iServices[ exist ]->SetStartupFlag( 
       
  1716             aSelection.iType, aLoadAtStartUp ); 
       
  1717         }
       
  1718     return exist;
       
  1719     }
       
  1720 
       
  1721 // ---------------------------------------------------------------------------
       
  1722 // CCCHServiceHandler::HandleRestartL
       
  1723 // (other items were commented in a header).
       
  1724 // ---------------------------------------------------------------------------
       
  1725 //
       
  1726 void CCCHServiceHandler::HandleRestartL()
       
  1727     {
       
  1728     // In restart situation all services and subservices goes to 
       
  1729     // disabled state, after restart we will make reregistration 
       
  1730     CCHLOGSTRING( "CCHServiceHandler::HandleRestartL() IN" );
       
  1731     for ( TInt i( 0 ); i < iServices.Count(); i++ )
       
  1732         {
       
  1733         for ( TInt j( 0 ); j < iServices[ i ]->SubserviceCount(); j++ )
       
  1734             {
       
  1735             iServices[ i ]->GetSubserviceL( 
       
  1736                 iServices[ i ]->GetSubserviceType( j ) ).SetError( KErrCancel );
       
  1737             iServices[ i ]->GetSubserviceL( 
       
  1738                 iServices[ i ]->GetSubserviceType( j ) ).SetState( ECCHDisabled );
       
  1739             iServices[ i ]->GetSubserviceL( 
       
  1740                 iServices[ i ]->GetSubserviceType( j ) ).StatusChanged();
       
  1741             }
       
  1742         }
       
  1743     CCHLOGSTRING( "CCHServiceHandler::HandleRestartL() OUT" );
       
  1744     }
       
  1745 
       
  1746 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
  1747 
       
  1748 //  End of File