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