convergedconnectionhandler/cchclientapi/src/cchuiapiimpl.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2008-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:  Implementation of class CCchUiApiImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cchuilogger.h"
       
    20 #include "cchuiapiimpl.h"
       
    21 #include "cchuiobserver.h"
       
    22 #include "cchuispshandler.h"
       
    23 #include "cchuicchhandler.h"
       
    24 #include "cchuinotehandler.h"
       
    25 #include "cchuiclientobserver.h"
       
    26 #include "cchuiconnectionhandler.h"
       
    27 
       
    28 const TInt KServiceNameMaxLength = 255;
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Constructor
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CCchUiApiImpl* CCchUiApiImpl::NewL( CCch& aCch )
       
    37     {
       
    38     CCchUiApiImpl* cchUiApiImpl = 
       
    39         new ( ELeave ) CCchUiApiImpl();
       
    40     CleanupStack::PushL( cchUiApiImpl );
       
    41     cchUiApiImpl->ConstructL( aCch );
       
    42     CleanupStack::Pop( cchUiApiImpl ); 
       
    43     return cchUiApiImpl;
       
    44     }    
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Constructor
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CCchUiApiImpl::CCchUiApiImpl(): 
       
    51     iReEnableService( EFalse ),
       
    52     iRemovableConnection( KErrNone ),
       
    53     iObservedService( 0 )
       
    54     {
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Constructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CCchUiApiImpl::ConstructL( CCch& aCch )
       
    62     {
       
    63     iCCHHandler = CCchUiCchHandler::NewL( aCch );    
       
    64     iSpsHandler = CCchUiSpsHandler::NewL();
       
    65     iNoteController = CCCHUiNoteHandler::NewL( *this );
       
    66     iConnectionHandler = CCchUiConnectionHandler::NewL( 
       
    67         *iCCHHandler, *iSpsHandler );
       
    68     // voip sub service is by default the supported one. 
       
    69     // Client can overwrite these
       
    70     iAllowedSubServices.AppendL( ECCHVoIPSub );   
       
    71     
       
    72     iLastOperationResult = 
       
    73           MCchUiObserver::ECchUiClientOperationResultNotSet;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CCchUiApiImpl::~CCchUiApiImpl()
       
    81     {    
       
    82     if ( iObservedService && iCCHHandler )
       
    83         {
       
    84         TRAP_IGNORE( iCCHHandler->StopObservingL( 
       
    85            iObservedService, *this ) );
       
    86         }
       
    87     
       
    88     iAllowedNotes.Close();
       
    89     iAllowedSubServices.Close();    
       
    90     iObservervedServices.Close();
       
    91     iObservers.ResetAndDestroy();
       
    92     iObservers.Close();
       
    93     delete iCCHHandler;
       
    94     delete iNoteController;
       
    95     delete iSpsHandler;
       
    96     delete iConnectionHandler;      
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // AddObserver.
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CCchUiApiImpl::AddObserverL( MCchUiObserver& aObserver  )
       
   104     {
       
   105     CCHUIDEBUG( "CCchUiApiImpl::AddObserver - IN"); 
       
   106         
       
   107     // Check if already exists
       
   108     TBool alreadyExists = EFalse;
       
   109     for ( TInt i( 0 ) ; i < iObservers.Count() ; i++ )
       
   110         {        
       
   111         if ( &aObserver == &iObservers[ i ]->Observer() )
       
   112             {
       
   113             CCHUIDEBUG( "AddObserver - already exists");           
       
   114             alreadyExists = ETrue;
       
   115             }
       
   116         }
       
   117     
       
   118     if ( !alreadyExists )
       
   119         {
       
   120         CCHUIDEBUG( "AddObserver - add observer"); 
       
   121         
       
   122         CCchUiClientObserver* capsulatedObs = 
       
   123             CCchUiClientObserver::NewLC( aObserver );
       
   124         
       
   125         iObservers.AppendL( capsulatedObs );     
       
   126         CleanupStack::Pop( capsulatedObs );
       
   127         } 
       
   128     
       
   129     CCHUIDEBUG( "CCchUiApiImpl::AddObserver - OUT");
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // RemoveObserver.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CCchUiApiImpl::RemoveObserver( MCchUiObserver& aObserver  )
       
   137     {
       
   138     for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   139         {
       
   140         if ( &aObserver == &iObservers[ i ]->Observer() )
       
   141             {           
       
   142             delete iObservers[ i ];
       
   143             iObservers.Remove( i );
       
   144                
       
   145             CCHUIDEBUG( "RemoveObserver - observer removed" );
       
   146             }
       
   147         }
       
   148     iObservers.Compress();
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Show dialog.
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CCchUiApiImpl::ShowDialogL( 
       
   156     TUint32 aServiceId, 
       
   157     MCchUiObserver::TCchUiDialogType aDialog )
       
   158     {
       
   159     CCHUIDEBUG2( "CCchUiApiImpl::ShowDialogL - aServiceId: %d", 
       
   160         aServiceId );            
       
   161     CCHUIDEBUG2( "CCchUiApiImpl::ShowDialogL - aDialog: %d", 
       
   162         aDialog );      
       
   163     
       
   164     TInt err( KErrNone );
       
   165     
       
   166     // Get current connection iap id
       
   167     TInt iapId( KErrNone );
       
   168     iCCHHandler->GetCurrentConnectionIapIdL(
       
   169         aServiceId, ECCHUnknown, iapId, err );
       
   170     
       
   171     // Get current service username
       
   172     RBuf userName;
       
   173     CleanupClosePushL( userName );
       
   174     userName.CreateL( KServiceNameLength );
       
   175     iCCHHandler->GetUsernameL( aServiceId, userName, err );
       
   176     
       
   177     if ( KErrNone == err || KErrNotFound == err )
       
   178         {
       
   179         CCHUIDEBUG( "ShowDialogL -Launch note" );
       
   180         iNoteController->LaunchNoteL( aDialog, aServiceId, iapId, userName );
       
   181         }
       
   182     else // leave if error code other that KErrNone or KErrNotFound
       
   183         {
       
   184         CCHUIDEBUG2( "ShowDialogL - leave with err=%d", err );
       
   185         User::Leave( err );
       
   186         }
       
   187     
       
   188     CleanupStack::PopAndDestroy( &userName );
       
   189     }
       
   190     
       
   191 // ---------------------------------------------------------------------------
       
   192 // Get currently showing dialog.
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CCchUiApiImpl::ConfigureVisualizationL( 
       
   196     RArray<MCchUiObserver::TCchUiDialogType>& aAllowedNotes,
       
   197     RArray<TCCHSubserviceType>& aAllowedSubServices )
       
   198     {
       
   199     CCHUIDEBUG( "CCchUiApiImpl::ConfigureVisualizationL - IN" );
       
   200     
       
   201     CCHUIDEBUG2( "ConfigureVisualizationL - aAllowedNotes count=%d", 
       
   202         aAllowedNotes.Count() );
       
   203     CCHUIDEBUG2( "ConfigureVisualizationL - aAllowedSubServices count=%d", 
       
   204         aAllowedSubServices.Count() );
       
   205     
       
   206     TBool subServicesHandled = EFalse;
       
   207     TBool dialogsHandled = EFalse;
       
   208     
       
   209     // Reset old data
       
   210     iAllowedNotes.Reset();
       
   211     iAllowedSubServices.Reset();
       
   212 
       
   213     if ( KErrNotFound != aAllowedNotes.Find( 
       
   214         MCchUiObserver::ECchUiDialogTypeNotSet ) )
       
   215         {
       
   216         CCHUIDEBUG( "ConfigureVisualizationL - all dialogs are supported" );
       
   217         dialogsHandled = ETrue;
       
   218         }
       
   219     
       
   220     for ( TInt noteIndex = 0 ; 
       
   221           noteIndex < aAllowedNotes.Count() && !dialogsHandled ; 
       
   222           noteIndex++ )
       
   223         {
       
   224         CCHUIDEBUG2( "ConfigureVisualizationL - appending allowed note: %d",
       
   225             aAllowedNotes[ noteIndex ] );
       
   226         iAllowedNotes.AppendL( aAllowedNotes[ noteIndex ] );
       
   227         }
       
   228     
       
   229     if ( KErrNotFound != aAllowedSubServices.Find( ECCHUnknown ) )
       
   230         {
       
   231         CCHUIDEBUG( 
       
   232             "ConfigureVisualizationL - all sub services are supported" );
       
   233         iAllowedSubServices.AppendL( ECCHUnknown );
       
   234         subServicesHandled = ETrue;
       
   235         }
       
   236     for ( TInt servIndex = 0 ; 
       
   237           servIndex < aAllowedSubServices.Count() && subServicesHandled ; 
       
   238           servIndex++ )
       
   239         {
       
   240         CCHUIDEBUG2( 
       
   241             "ConfigureVisualizationL - appending allowed sub service: %d", 
       
   242             aAllowedSubServices[ servIndex ] );
       
   243         iAllowedSubServices.AppendL( aAllowedSubServices[ servIndex ] );
       
   244         }    
       
   245     
       
   246     CCHUIDEBUG( "CCchUiApiImpl::ConfigureVisualizationL - OUT" );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Cancel notes/dialogs.
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CCchUiApiImpl::CancelNotes()
       
   254     {
       
   255     CCHUIDEBUG( "CCchUiApiImpl::CancelNotes" );            
       
   256     iNoteController->CancelOldNotes();
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // Manual enable has proceeded
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CCchUiApiImpl::ManualEnableResultL( 
       
   264     TUint aServiceId, 
       
   265     TInt aEnableResult )
       
   266     {
       
   267     CCHUIDEBUG( "CCchUiApiImpl::ManualEnableResultL - IN" );    
       
   268         
       
   269     if ( KErrNone == aEnableResult )
       
   270         {
       
   271         CCHUIDEBUG( "ManualEnableStartedL - start observing service" );
       
   272         iCCHHandler->StartObservingL( aServiceId, *this );   
       
   273           
       
   274         iObservedService = aServiceId;
       
   275                
       
   276         // Check if id already exists in observed services
       
   277         TInt err = iObservervedServices.Find( aServiceId ); 
       
   278                
       
   279         // Append id only if it is not found.
       
   280         if ( KErrNotFound == err )
       
   281             {
       
   282             CCHUIDEBUG( "ManualEnableStartedL - add to observerd services" );
       
   283             iObservervedServices.AppendL( aServiceId );
       
   284             }   
       
   285         }
       
   286     else
       
   287         {
       
   288         HandleManualEnableErrorL( aServiceId, aEnableResult );
       
   289         }
       
   290     
       
   291     CCHUIDEBUG( "CCchUiApiImpl::ManualEnableStartedL - OUT" );    
       
   292     }    
       
   293    
       
   294 // ---------------------------------------------------------------------------
       
   295 // Manual enable error handling.
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CCchUiApiImpl::HandleManualEnableErrorL( 
       
   299     TUint aServiceId, 
       
   300     TInt aEnableResult )
       
   301     {
       
   302     CCHUIDEBUG( "CCchUiApiImpl::HandleManualEnableErrorL - IN" );    
       
   303     CCHUIDEBUG2( "  ---> aEnableResult: %d", aEnableResult );
       
   304     
       
   305     MCchUiObserver::TCchUiDialogType dialogType = 
       
   306         MCchUiObserver::ECchUiDialogTypeNotSet;
       
   307     
       
   308     switch ( aEnableResult )
       
   309         {
       
   310         case KCCHErrorAccessPointNotDefined:
       
   311             {
       
   312             dialogType = MCchUiObserver::ECchUiDialogTypeNoConnectionDefined;
       
   313             }
       
   314             break;
       
   315         case KCCHErrorAuthenticationFailed:
       
   316             {
       
   317             dialogType = MCchUiObserver::ECchUiDialogTypeAuthenticationFailed;    
       
   318             }
       
   319             break;
       
   320         case KCCHErrorInvalidSettings:
       
   321             {
       
   322             dialogType = MCchUiObserver::ECchUiDialogTypeDefectiveSettings;            
       
   323             }
       
   324             break;
       
   325             
       
   326         case KCCHErrorBandwidthInsufficient:
       
   327             {
       
   328             dialogType = MCchUiObserver::ECchUiDialogTypeErrorInConnection; 
       
   329             }
       
   330             break;
       
   331         case KCCHErrorInvalidIap:
       
   332         case KCCHErrorNetworkLost:
       
   333         case KCCHErrorServiceNotResponding:
       
   334             {
       
   335             dialogType = MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable;
       
   336             }
       
   337             break;           
       
   338         default:
       
   339             break;
       
   340         }
       
   341     
       
   342     // show dialog if dialog type set and dialog allowed
       
   343     if ( ( MCchUiObserver::ECchUiDialogTypeNotSet != dialogType ) &&
       
   344         ( DialogIsAllowed( dialogType ) ) )
       
   345         {
       
   346         ShowDialogL( aServiceId, dialogType );
       
   347         }
       
   348     
       
   349     CCHUIDEBUG( "CCchUiApiImpl::HandleManualEnableErrorL - OUT" );    
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // Handle dialog completed situation.
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void CCchUiApiImpl::DialogCompletedL( 
       
   357     TInt aCompleteCode, 
       
   358     TCCHUiNotifierParams aResultParams )
       
   359     {
       
   360     CCHUIDEBUG( "CCchUiApiImpl::DialogCompletedL - IN");            
       
   361     CCHUIDEBUG2( "DialogCompletedL - complete code=%d", aCompleteCode );            
       
   362     CCHUIDEBUG2( "DialogCompletedL - dialog mode=%d", 
       
   363             aResultParams.iDialogMode  );        
       
   364     
       
   365     switch ( aResultParams.iDialogMode )
       
   366         {        
       
   367         case MCchUiObserver::ECchUiDialogTypeUsernamePasswordFailed:
       
   368             {
       
   369             // Show username/password query.
       
   370             __ASSERT_ALWAYS( DialogIsAllowed( 
       
   371                 MCchUiObserver::ECchUiDialogTypeAuthenticationFailed ), 
       
   372                 User::Leave( KErrNotSupported ) );
       
   373             
       
   374             CancelNotes();
       
   375             ShowDialogL( 
       
   376                 aResultParams.iServiceId, 
       
   377                 MCchUiObserver::ECchUiDialogTypeAuthenticationFailed );
       
   378             }
       
   379             break; 
       
   380         case MCchUiObserver::ECchUiDialogTypeAuthenticationFailed:
       
   381             {
       
   382             DoHandleAuthenticationFailedCompleteL( 
       
   383                 aCompleteCode, aResultParams );
       
   384             }
       
   385             break;  
       
   386         case MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable:
       
   387         case MCchUiObserver::ECchUiDialogTypeNoConnectionDefined:        
       
   388             {
       
   389             DoHandleNoConnectionsCompleteL( 
       
   390                 aCompleteCode, aResultParams );
       
   391             }
       
   392             break;
       
   393         
       
   394         case MCchUiObserver::ECchUiDialogTypeDefectiveSettings:
       
   395             {
       
   396             // Defective settings is permanent type of condition.
       
   397             iCCHHandler->DisableL( aResultParams.iServiceId );
       
   398             iLastOperationResult = 
       
   399                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   400             }
       
   401             break;           
       
   402         case MCchUiObserver::ECchUiDialogTypeErrorInConnection:
       
   403             {
       
   404             // Show confirm change connection query
       
   405             __ASSERT_ALWAYS( DialogIsAllowed( 
       
   406                 MCchUiObserver::ECchUiDialogTypeConfirmChangeConnection ), 
       
   407                 User::Leave( KErrNotSupported ) );
       
   408                         
       
   409             CancelNotes();
       
   410             ShowDialogL( 
       
   411                 aResultParams.iServiceId, 
       
   412                 MCchUiObserver::ECchUiDialogTypeConfirmChangeConnection );
       
   413             }
       
   414             break;
       
   415         case MCchUiObserver::ECchUiDialogTypeConfirmChangeConnection:
       
   416             {
       
   417             DoHandleConfirmChangeConnectionCompleteL( 
       
   418                 aCompleteCode, aResultParams );
       
   419             }
       
   420             break;
       
   421         case MCchUiObserver::ECchUiDialogTypeChangeConnection:
       
   422             {
       
   423             DoHandleChangeConnectionCompleteL( 
       
   424                 aCompleteCode, aResultParams );
       
   425             }
       
   426             break;            
       
   427         default:
       
   428             CCHUIDEBUG( "DialogCompletedL - default switch case" );  
       
   429             break;    
       
   430         }    
       
   431     
       
   432     CCHUIDEBUG( "CCchUiApiImpl::DialogCompletedL - OUT" );  
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // Checks if specific note is allowed
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 TBool CCchUiApiImpl::DialogIsAllowed( 
       
   440     MCchUiObserver::TCchUiDialogType aDialog )
       
   441     {
       
   442     CCHUIDEBUG( "CCchUiApiImpl::DialogIsAllowed");
       
   443     CCHUIDEBUG2( "CCchUiApiImpl::DialogIsAllowed - allowed notes count=%d", 
       
   444         iAllowedNotes.Count() );
       
   445     CCHUIDEBUG2( "CCchUiApiImpl::DialogIsAllowed - aDialog find result=%d", 
       
   446         iAllowedNotes.Find( aDialog ) );
       
   447     
       
   448     TBool ret = EFalse;
       
   449     if ( !iAllowedNotes.Count() ) return ETrue; // not configured, all allowed
       
   450     else if ( KErrNotFound != iAllowedNotes.Find( 
       
   451         MCchUiObserver::ECchUiDialogTypeNotSet ) ) return ETrue;
       
   452     else if ( KErrNotFound != iAllowedNotes.Find( aDialog ) ) return ETrue;
       
   453     
       
   454     CCHUIDEBUG2( "DialogIsAllowed - return: %d", ret );
       
   455     return ret;            
       
   456     }
       
   457 
       
   458 // ---------------------------------------------------------------------------
       
   459 // Checks if specific sub service  is allowed
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 TBool CCchUiApiImpl::SubServiceIsAllowed( TCCHSubserviceType aSubService )
       
   463     {
       
   464     CCHUIDEBUG( "CCchUiApiImpl::SubServiceIsAllowed");            
       
   465     
       
   466     CCHUIDEBUG2( "SubServiceIsAllowed - allowed subserv=%d", 
       
   467         iAllowedSubServices.Count() );
       
   468     CCHUIDEBUG2( "SubServiceIsAllowed - aSubService find=%d", 
       
   469         iAllowedSubServices.Find( aSubService ) );
       
   470     CCHUIDEBUG2( "SubServiceIsAllowed - all supported=%d", 
       
   471         iAllowedSubServices.Find( ECCHUnknown ) );
       
   472     
       
   473     // If subservice type is ECCHUnknown -> subservice is allowed, other
       
   474     // types are checked from array.
       
   475     TBool allowed = EFalse;
       
   476     TInt result = iAllowedSubServices.Find( aSubService );
       
   477     
       
   478     if ( ECCHUnknown == aSubService )
       
   479         {
       
   480         allowed = ETrue;
       
   481         }
       
   482     else if ( KErrNotFound != result )
       
   483         {
       
   484         allowed = ETrue;
       
   485         }
       
   486     else
       
   487         {
       
   488         allowed = EFalse;
       
   489         }
       
   490 
       
   491     CCHUIDEBUG2( "SubServiceIsAllowed - return: %d", allowed );
       
   492     return allowed;
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 // Checks subservice state is allowed for showing dialogs.
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 TBool CCchUiApiImpl::StateIsAllowed( const TCCHSubserviceState aState )
       
   500     {
       
   501     CCHUIDEBUG( "CCchUiApiImpl::StateIsAllowed");  
       
   502     
       
   503     TBool allowed( EFalse );
       
   504     
       
   505     switch ( aState )
       
   506         {
       
   507         case ECCHUninitialized:
       
   508         case ECCHDisabled:
       
   509         case ECCHDisconnecting:
       
   510             {
       
   511             CCHUIDEBUG( "CCchUiApiImpl::StateIsAllowed: Not allowed");
       
   512             }
       
   513             break;           
       
   514         case ECCHConnecting:
       
   515         case ECCHEnabled:
       
   516             {
       
   517             CCHUIDEBUG( "CCchUiApiImpl::StateIsAllowed: Allowed");
       
   518             allowed = ETrue;
       
   519             }
       
   520             break;
       
   521         default:
       
   522             CCHUIDEBUG( "CCchUiApiImpl::StateIsAllowed: DEFAULT case");
       
   523             break;
       
   524         }
       
   525     
       
   526     return allowed;
       
   527     }
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // Handles re-enabling of service.
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 void CCchUiApiImpl::HandleServiceReEnablingL( TUint aServiceId )
       
   534     {
       
   535     if ( iRemovableConnection )
       
   536         {
       
   537         CCHUIDEBUG( 
       
   538             "DoHandleServiceEventL - removing old connection" );
       
   539         
       
   540         RBuf serviceName;
       
   541         CleanupClosePushL( serviceName );
       
   542         serviceName.CreateL( KServiceNameMaxLength );
       
   543         
       
   544         iSpsHandler->ServiceNameL( 
       
   545                 aServiceId,
       
   546                 serviceName );
       
   547         
       
   548         // Remove old connection
       
   549         iConnectionHandler->RemoveConnectionL( 
       
   550             serviceName, iRemovableConnection );
       
   551         
       
   552         CleanupStack::PopAndDestroy( &serviceName );
       
   553         }
       
   554     
       
   555     CCHUIDEBUG( "HandleServiceReEnablingL - Re-Enabling service" );
       
   556     
       
   557     iReEnableService = EFalse;
       
   558     iCCHHandler->EnableL( aServiceId );    
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // Handle authentication failed completed situation.
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 void CCchUiApiImpl::DoHandleAuthenticationFailedCompleteL( 
       
   566     TInt aCompleteCode, 
       
   567     TCCHUiNotifierParams aResultParams )
       
   568     {
       
   569     CCHUIDEBUG( "CCchUiApiImpl::DoHandleAuthenticationFailedCompleteL - IN");            
       
   570         
       
   571     switch ( aCompleteCode )
       
   572         {
       
   573         case KErrNone:
       
   574             {
       
   575             TInt err( KErrNone );
       
   576                     
       
   577             // Set username
       
   578             iCCHHandler->SetUsernameL( aResultParams, err );   
       
   579                     
       
   580             // If no error set also password
       
   581             if ( !err )
       
   582                 {       
       
   583                 iCCHHandler->SetPasswordL( aResultParams, err );
       
   584                 }
       
   585             else
       
   586                 {
       
   587                 iLastOperationResult = 
       
   588                     MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   589                 }
       
   590                     
       
   591             // Both username and password set succesfully.
       
   592             if ( !err )
       
   593                 {   
       
   594                 iLastOperationResult = 
       
   595                 MCchUiObserver::ECchUiClientOperationResultCredentialsChanged;
       
   596                 }
       
   597             else
       
   598                 {
       
   599                 iLastOperationResult = 
       
   600                     MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   601                 }
       
   602             
       
   603             aCompleteCode = err;
       
   604             break;
       
   605             }
       
   606         case KErrAlreadyExists:
       
   607             {
       
   608             // dialog active, do nothing
       
   609             break;
       
   610             }
       
   611         case KErrCancel:
       
   612             {        
       
   613             iLastOperationResult = 
       
   614                 MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   615             break;
       
   616             }
       
   617         default:
       
   618             {
       
   619             CCHUIDEBUG( 
       
   620                "DoHandleAuthenticationFailedCompleteL - switch default case");
       
   621             iLastOperationResult = 
       
   622                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   623             break;
       
   624             }
       
   625         }
       
   626     
       
   627     switch ( iLastOperationResult )
       
   628         {
       
   629         case MCchUiObserver::ECchUiClientOperationResultCredentialsChanged:
       
   630             {
       
   631             iCCHHandler->EnableL( aResultParams.iServiceId );
       
   632             break;
       
   633             }
       
   634         default:
       
   635             {
       
   636             iCCHHandler->DisableL( aResultParams.iServiceId );
       
   637             break;
       
   638             }
       
   639         }
       
   640     
       
   641     CCHUIDEBUG( "CCchUiApiImpl::DoHandleAuthenticationFailedCompleteL - OUT");       
       
   642     }
       
   643     
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // Handle no connections complete situation.
       
   647 // ---------------------------------------------------------------------------
       
   648 //
       
   649 void CCchUiApiImpl::DoHandleNoConnectionsCompleteL( 
       
   650     TInt aCompleteCode, 
       
   651     TCCHUiNotifierParams aResultParams )
       
   652     {
       
   653     CCHUIDEBUG( "CCchUiApiImpl::DoHandleNoConnectionsCompleteL - IN"); 
       
   654 
       
   655     if ( KErrNone == aCompleteCode )
       
   656         {
       
   657         switch( aResultParams.iOperationCommand )
       
   658             {
       
   659             case ECchUiCommandSearchWlan:
       
   660                 {
       
   661                 HandleSearchWlanCompleteL( 
       
   662                         aCompleteCode, aResultParams );
       
   663                 break;
       
   664                 }
       
   665             case ECchUiCommandCopyGprs:
       
   666                 {
       
   667                 HandleCopyGprsCompleteL( 
       
   668                         aCompleteCode, aResultParams );                
       
   669                 break;
       
   670                 }
       
   671             case ECchUiCommandGprsNotFound:
       
   672                 {
       
   673                 CCHUIDEBUG( " -> GPRS was not found"); 
       
   674                 iLastOperationResult = 
       
   675                     MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   676                 break;
       
   677                 }    
       
   678             case ECchUiCommandEnableCancelled:
       
   679                 {
       
   680                 iLastOperationResult = 
       
   681                     MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   682                 break;
       
   683                 }
       
   684             case ECchUiCommandConnectWhenAvailable:
       
   685                 {
       
   686                 iLastOperationResult = 
       
   687                     MCchUiObserver::ECchUiClientOperationResultNotSet;
       
   688                 break;
       
   689                 }
       
   690             default:
       
   691                 {
       
   692                 CCHUIDEBUG( " -> !DEFAULT!"); 
       
   693                 iLastOperationResult = 
       
   694                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   695                 }
       
   696                 break;
       
   697             }
       
   698         }
       
   699     else if ( KErrAlreadyExists == aCompleteCode )
       
   700         {
       
   701         // dialog active, do nothing
       
   702         }
       
   703     else if ( KErrCancel == aCompleteCode )
       
   704         {
       
   705         iLastOperationResult = 
       
   706             MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   707         }
       
   708     else
       
   709         {
       
   710         iLastOperationResult = 
       
   711             MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   712         }
       
   713     
       
   714     if ( iLastOperationResult != 
       
   715         MCchUiObserver::ECchUiClientOperationResultNotSet )
       
   716         {
       
   717         InformObserversL( aResultParams.iServiceId );
       
   718         }
       
   719        
       
   720     switch ( iLastOperationResult )
       
   721         {
       
   722         case MCchUiObserver::ECchUiClientOperationResultAccessPointAdded:
       
   723             {
       
   724             // New access point was added --> enable service
       
   725             iCCHHandler->EnableL( aResultParams.iServiceId );
       
   726             break;
       
   727             }
       
   728         case MCchUiObserver::ECchUiClientOperationResultNotSet:
       
   729             {
       
   730             // If no operation result set, do nothing
       
   731             break;
       
   732             }
       
   733         // By default disable service
       
   734         default:
       
   735             {
       
   736             CCHUIDEBUG( " -> !DEFAULT!");
       
   737             CCHUIDEBUG( " -> Disabling service");
       
   738             iCCHHandler->DisableL( aResultParams.iServiceId );
       
   739             break;
       
   740             }
       
   741         }       
       
   742     
       
   743     CCHUIDEBUG( "CCchUiApiImpl::DoHandleNoConnectionsCompleteL - OUT"); 
       
   744     }
       
   745   
       
   746 // ---------------------------------------------------------------------------
       
   747 // Handle change connection confirmation note complete situation.
       
   748 // ---------------------------------------------------------------------------
       
   749 //
       
   750 void CCchUiApiImpl::DoHandleConfirmChangeConnectionCompleteL( 
       
   751     TInt aCompleteCode, 
       
   752     TCCHUiNotifierParams aResultParams )
       
   753     {    
       
   754     CCHUIDEBUG( 
       
   755         "CCchUiApiImpl::DoHandleConfirmChangeConnectionCompleteL - IN"); 
       
   756     
       
   757     switch( aCompleteCode )
       
   758         {
       
   759         case KErrNone:
       
   760             {            
       
   761             // show change connection query
       
   762             __ASSERT_ALWAYS( DialogIsAllowed( 
       
   763                 MCchUiObserver::ECchUiDialogTypeChangeConnection ), 
       
   764                 User::Leave( KErrNotSupported ) );
       
   765             
       
   766             // Set removable connection which is removed when connection
       
   767             // is changed successfully
       
   768             if ( aResultParams.iRemoveOldConnection )
       
   769                 {
       
   770                 iRemovableConnection = aResultParams.iCurrentConnectionIapId;
       
   771                 }
       
   772             
       
   773             CancelNotes();
       
   774             ShowDialogL( 
       
   775                 aResultParams.iServiceId, 
       
   776                 MCchUiObserver::ECchUiDialogTypeChangeConnection );
       
   777             break;
       
   778             }
       
   779         case KErrCancel:
       
   780             {      
       
   781             iLastOperationResult = 
       
   782                 MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   783             break;
       
   784             }
       
   785         default:
       
   786             {
       
   787             CCHUIDEBUG( 
       
   788             "DoHandleConfirmChangeConnectionCompleteL - default switch case");
       
   789             
       
   790             iLastOperationResult = 
       
   791                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   792             break;
       
   793             }
       
   794         }
       
   795     
       
   796     CCHUIDEBUG( 
       
   797             "CCchUiApiImpl::DoHandleConfirmChangeConnectionCompleteL - OUT"); 
       
   798     }
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // Handle change connection query complete situation.
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 void CCchUiApiImpl::DoHandleChangeConnectionCompleteL( 
       
   805     TInt aCompleteCode, 
       
   806     TCCHUiNotifierParams aResultParams )
       
   807     {  
       
   808     CCHUIDEBUG( "CCchUiApiImpl::DoHandleChangeConnectionCompleteL - IN"); 
       
   809         
       
   810     switch( aCompleteCode )
       
   811         {
       
   812         case KErrNone:
       
   813             {
       
   814             HandleChangeConnectionL( 
       
   815                 aCompleteCode, aResultParams );
       
   816             break;
       
   817             }
       
   818         case KErrCancel:
       
   819             {
       
   820             iLastOperationResult = 
       
   821                 MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   822             break;
       
   823             }
       
   824         default:
       
   825             {
       
   826             CCHUIDEBUG( 
       
   827                 "DoHandleChangeConnectionCompleteL - default switch case"); 
       
   828             
       
   829             iLastOperationResult = 
       
   830                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   831             
       
   832             break;
       
   833             }
       
   834         }
       
   835     
       
   836     CCHUIDEBUG( "CCchUiApiImpl::DoHandleChangeConnectionCompleteL - OUT"); 
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // Handles search wlan dialog result.
       
   841 // ---------------------------------------------------------------------------
       
   842 //    
       
   843 void CCchUiApiImpl::HandleSearchWlanCompleteL( 
       
   844     TInt& aCompleteCode, 
       
   845     TCCHUiNotifierParams& aResultParams )
       
   846     {
       
   847     CCHUIDEBUG( "CCchUiApiImpl::HandleSearchWlanCompleteL - IN"); 
       
   848     
       
   849     CCHUIDEBUG( "HandleSearchWlanCompleteL - begin wlan search"); 
       
   850     
       
   851     TInt err( KErrNone );
       
   852     TInt snapId( KErrNone );
       
   853     
       
   854     iCCHHandler->GetConnectionSnapIdL( 
       
   855         aResultParams.iServiceId, snapId, err );
       
   856                     
       
   857     if ( !err )
       
   858         {
       
   859         CCHUIDEBUG2( 
       
   860             "HandleSearchWlanCompleteL - service snap is: %d", snapId ); 
       
   861                         
       
   862         HBufC* serviceName = HBufC::NewLC( KServiceNameMaxLength );
       
   863         TPtr serviceNamePtr( serviceName->Des() );
       
   864         
       
   865         CCHUIDEBUG( "HandleSearchWlanCompleteL - get service name");    
       
   866                         
       
   867         iSpsHandler->ServiceNameL( 
       
   868             aResultParams.iServiceId, serviceNamePtr );
       
   869                         
       
   870         CCHUIDEBUG( "HandleSearchWlanCompleteL - proceed to wlan search");                 
       
   871                         
       
   872         TRAP( err, iConnectionHandler->SearchAccessPointsL(
       
   873                 aResultParams.iServiceId,
       
   874                 snapId,
       
   875                 serviceNamePtr ) ); 
       
   876                         
       
   877         CCHUIDEBUG2( "HandleSearchWlanCompleteL - wlan search err: %d", err );          
       
   878                         
       
   879         CleanupStack::PopAndDestroy( serviceName );
       
   880         
       
   881         HandleSearchAccessPointsErrorL( 
       
   882                 err, aCompleteCode, aResultParams );
       
   883         }
       
   884     
       
   885     CCHUIDEBUG( "CCchUiApiImpl::HandleSearchWlanCompleteL - OUT"); 
       
   886     }
       
   887     
       
   888 // ---------------------------------------------------------------------------
       
   889 // Handles search access points error code.
       
   890 // ---------------------------------------------------------------------------
       
   891 //
       
   892 void CCchUiApiImpl::HandleSearchAccessPointsErrorL( 
       
   893     TInt aErr,
       
   894     TInt& aCompleteCode, 
       
   895     TCCHUiNotifierParams& /*aResultParams*/ )
       
   896     {
       
   897     CCHUIDEBUG( "CCchUiApiImpl::HandleSearchAccessPointsErrorL - IN" );
       
   898     
       
   899     switch ( aErr )
       
   900         {
       
   901         case KErrNone:
       
   902             {
       
   903             CCHUIDEBUG( 
       
   904                 "HandleSearchAccessPointsErrorL - access point added" );             
       
   905             iLastOperationResult = 
       
   906                 MCchUiObserver::ECchUiClientOperationResultAccessPointAdded;
       
   907             break;
       
   908             }
       
   909         case KErrCancel: // user cancel
       
   910             {
       
   911             CCHUIDEBUG( "HandleSearchAccessPointsErrorL - error, cancelled");           
       
   912             iLastOperationResult = 
       
   913                 MCchUiObserver::ECchUiClientOperationResultUserCancelled;
       
   914             break;
       
   915             }
       
   916         default: // other errors
       
   917             {
       
   918             CCHUIDEBUG( 
       
   919               "HandleSearchAccessPointsErrorL - error, set general failure");
       
   920                
       
   921             aCompleteCode = aErr;
       
   922             iLastOperationResult = 
       
   923                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   924             }
       
   925         }
       
   926     
       
   927     CCHUIDEBUG( "CCchUiApiImpl::HandleSearchAccessPointsErrorL - OUT" );
       
   928     }
       
   929 
       
   930 // ---------------------------------------------------------------------------
       
   931 // Handles search wlan dialog result when use gprs selected.
       
   932 // ---------------------------------------------------------------------------
       
   933 //    
       
   934 void CCchUiApiImpl::HandleCopyGprsCompleteL( 
       
   935     TInt& /*aCompleteCode*/, 
       
   936     TCCHUiNotifierParams& aResultParams )
       
   937     {
       
   938     CCHUIDEBUG( "CCchUiApiImpl::HandleCopyGprsCompleteL - IN" );
       
   939     
       
   940     // User selected gprs access point which will now be stored in
       
   941     // service snap
       
   942     TInt snapId( KErrNone );
       
   943                     
       
   944     HBufC* serviceName = HBufC::NewLC( KServiceNameMaxLength );
       
   945     TPtr serviceNamePtr( serviceName->Des() );
       
   946     
       
   947     iSpsHandler->ServiceNameL( 
       
   948             aResultParams.iServiceId,
       
   949             serviceNamePtr );
       
   950                 
       
   951     TInt err( KErrNone );
       
   952     iCCHHandler->GetConnectionSnapIdL( 
       
   953             aResultParams.iServiceId, 
       
   954             snapId,
       
   955             err );
       
   956                     
       
   957     if ( !err )
       
   958         {
       
   959         CCHUIDEBUG2( 
       
   960             "HandleCopyGprsCompleteL - proceed, target snap is: %d", snapId );        
       
   961         CCHUIDEBUG2( 
       
   962             "HandleCopyGprsCompleteL - proceed, service id is: %d",
       
   963             aResultParams.iServiceId ); 
       
   964         CCHUIDEBUG2( "HandleCopyGprsCompleteL - gprs iap id is: %d", 
       
   965             aResultParams.iGprsIapId );                 
       
   966                         
       
   967         iConnectionHandler->CopyIapToServiceSnapL( 
       
   968                 aResultParams.iServiceId, serviceNamePtr, 
       
   969                 aResultParams.iGprsIapId, snapId );
       
   970                         
       
   971         CCHUIDEBUG( "HandleCopyGprsCompleteL - copy gprs iap done ok");                 
       
   972                         
       
   973         CleanupStack::PopAndDestroy( serviceName );
       
   974                         
       
   975         iLastOperationResult = 
       
   976             MCchUiObserver::ECchUiClientOperationResultAccessPointAdded;
       
   977                        
       
   978         CCHUIDEBUG( "  -> copy gprs iap done ok, enable");                 
       
   979         iCCHHandler->EnableL( aResultParams.iServiceId );
       
   980         }
       
   981     else
       
   982         {
       
   983         iLastOperationResult = 
       
   984             MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
   985         User::Leave( err );
       
   986         }
       
   987     
       
   988     CCHUIDEBUG( "CCchUiApiImpl::HandleCopyGprsCompleteL - OUT" );
       
   989     }
       
   990 
       
   991 // ---------------------------------------------------------------------------
       
   992 // Handles changing to new connection.
       
   993 // ---------------------------------------------------------------------------
       
   994 //    
       
   995 void CCchUiApiImpl::HandleChangeConnectionL( 
       
   996     TInt& aCompleteCode, 
       
   997     TCCHUiNotifierParams& aResultParams )
       
   998     {
       
   999     CCHUIDEBUG( "CCchUiApiImpl::HandleChangeConnectionL - IN" );        
       
  1000     
       
  1001     switch ( aResultParams.iOperationCommand )
       
  1002         {
       
  1003         case ECchUiCommandSearchWlan:
       
  1004             {
       
  1005             CCHUIDEBUG( "HandleChangeConnectionL - search wlan");                 
       
  1006             HandleSearchWlanCompleteL( 
       
  1007                 aCompleteCode, aResultParams );
       
  1008             break;
       
  1009             }
       
  1010         case ECchUiCommandCopyGprs:
       
  1011             {
       
  1012             CCHUIDEBUG( "HandleChangeConnectionL - copy gprs");       
       
  1013             HandleCopyGprsCompleteL( 
       
  1014                 aCompleteCode, aResultParams );
       
  1015             break;
       
  1016             }
       
  1017         default:
       
  1018             {
       
  1019             CCHUIDEBUG( "HandleChangeConnectionL - default switch case");
       
  1020             iLastOperationResult = 
       
  1021                 MCchUiObserver::ECchUiClientOperationResultGeneralFailure;
       
  1022             break;
       
  1023             }
       
  1024         }
       
  1025     
       
  1026     switch ( iLastOperationResult )
       
  1027         {
       
  1028         case MCchUiObserver::ECchUiClientOperationResultAccessPointAdded:
       
  1029             {
       
  1030             iLastOperationResult = 
       
  1031                 MCchUiObserver::ECchUiClientOperationResultConnectionChanged;
       
  1032                             
       
  1033             CCHUIDEBUG( "HandleChangeConnectionL - re-enable service");
       
  1034                             
       
  1035             // Disable service and set iReEnable flag so that after service
       
  1036             // has disconnected we can connect with new access point.
       
  1037             iCCHHandler->StartObservingL( aResultParams.iServiceId, *this );
       
  1038             
       
  1039             iReEnableService = ETrue;
       
  1040                 
       
  1041             iObservedService = aResultParams.iServiceId;
       
  1042             
       
  1043             InformObserversL( aResultParams.iServiceId );
       
  1044             iCCHHandler->DisableL( aResultParams.iServiceId );
       
  1045                             
       
  1046             // Check if id already exists in observed services
       
  1047             TInt error = iObservervedServices.Find( 
       
  1048                 aResultParams.iServiceId );
       
  1049                             
       
  1050             // Append id only if it is not found.
       
  1051             if ( KErrNotFound == error )
       
  1052                 {
       
  1053                 CCHUIDEBUG( 
       
  1054                    "HandleChangeConnectionL add to observerd services" );
       
  1055                 iObservervedServices.AppendL( aResultParams.iServiceId );
       
  1056                 }           
       
  1057             break;
       
  1058             }
       
  1059         default:
       
  1060             break;
       
  1061         }
       
  1062     
       
  1063     CCHUIDEBUG( "CCchUiApiImpl::HandleChangeConnectionL - OUT" );
       
  1064     }
       
  1065 
       
  1066 // ---------------------------------------------------------------------------
       
  1067 // Observer implementation for service events.
       
  1068 // ---------------------------------------------------------------------------
       
  1069 //    
       
  1070 void CCchUiApiImpl::ServiceStatusChanged( 
       
  1071     TInt aServiceId, 
       
  1072     TCCHSubserviceType aType, 
       
  1073     const TCchServiceStatus& aServiceStatus )
       
  1074     {
       
  1075     CCHUIDEBUG( "CCchUiApiImpl::ServiceStatusChanged - IN");
       
  1076     
       
  1077     CCHUIDEBUG2( "ServiceStatusChanged - aServiceId: %d", 
       
  1078         aServiceId ); 
       
  1079     CCHUIDEBUG2( "ServiceStatusChanged - aError: %d", 
       
  1080         aServiceStatus.Error() ); 
       
  1081     CCHUIDEBUG2( "ServiceStatusChanged - aState: %d",
       
  1082         aServiceStatus.State() ); 
       
  1083     CCHUIDEBUG2( "ServiceStatusChanged - aType: %d", 
       
  1084         aType ); 
       
  1085     
       
  1086     TInt observedPos = iObservervedServices.Find( aServiceId );
       
  1087     
       
  1088     CCHUIDEBUG2( "  ->  observed position: %d", observedPos ); 
       
  1089     
       
  1090     if ( KErrNotFound != observedPos )
       
  1091         {
       
  1092         switch ( aServiceStatus.Error() )
       
  1093             {
       
  1094             case KErrNone:
       
  1095                 {
       
  1096                 TRAP_IGNORE( DoHandleServiceEventL( 
       
  1097                         aServiceId, aType, aServiceStatus ) );
       
  1098                 break;
       
  1099                 }
       
  1100             default: // all error codes but KErrNone
       
  1101                 {
       
  1102                 TRAP_IGNORE( DoHandleServiceErrorL( 
       
  1103                         aServiceId, aType, aServiceStatus ) );
       
  1104                 break;
       
  1105                 }
       
  1106             }
       
  1107         }
       
  1108     
       
  1109     CCHUIDEBUG( "CCchUiApiImpl::ServiceStatusChanged - OUT");
       
  1110     }    
       
  1111     
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // Observer implementation for service events.
       
  1114 // ---------------------------------------------------------------------------
       
  1115 //    
       
  1116 void CCchUiApiImpl::DoHandleServiceErrorL( 
       
  1117     TInt aServiceId, 
       
  1118     TCCHSubserviceType aType, 
       
  1119     const TCchServiceStatus& aServiceStatus )
       
  1120     {
       
  1121     CCHUIDEBUG( "CCchUiApiImpl::DoHandleServiceErrorL - IN"); 
       
  1122     
       
  1123     CCHUIDEBUG2( "DoHandleServiceErrorL - aServiceId: %d", 
       
  1124         aServiceId ); 
       
  1125     CCHUIDEBUG2( "DoHandleServiceErrorL - aError: %d", 
       
  1126         aServiceStatus.Error() );
       
  1127     CCHUIDEBUG2( "DoHandleServiceErrorL - aState: %d", 
       
  1128         aServiceStatus.State() ); 
       
  1129 
       
  1130     // Check that sub service is allowed
       
  1131     __ASSERT_ALWAYS( SubServiceIsAllowed( aType ), 
       
  1132         User::Leave( KErrNotSupported ) );
       
  1133     
       
  1134     // Double-check subservice state
       
  1135     TInt err( KErrNone );
       
  1136     TCCHSubserviceState state = iCCHHandler->GetServiceStateL( 
       
  1137         aServiceId, aType, err );
       
  1138     
       
  1139     if ( err )
       
  1140         {
       
  1141         User::Leave( err );
       
  1142         }
       
  1143     
       
  1144     // Check that dialog showing is allowed.
       
  1145     __ASSERT_ALWAYS( ( StateIsAllowed( state ) || 
       
  1146        KCCHErrorInvalidSettings == aServiceStatus.Error() ) &&
       
  1147        !iConnectionHandler->SearchWlanOngoing(),
       
  1148        User::Leave( KErrNotSupported ) );
       
  1149     
       
  1150     switch ( aServiceStatus.Error() )
       
  1151         {
       
  1152         case KCCHErrorAuthenticationFailed:
       
  1153             {
       
  1154             __ASSERT_ALWAYS( DialogIsAllowed( 
       
  1155                 MCchUiObserver::ECchUiDialogTypeUsernamePasswordFailed ),
       
  1156                 User::Leave( KErrNotSupported ) );
       
  1157                          
       
  1158             ShowDialogL( 
       
  1159                 aServiceId, 
       
  1160                 MCchUiObserver::ECchUiDialogTypeUsernamePasswordFailed );
       
  1161             }
       
  1162             break;
       
  1163         
       
  1164         case KCCHErrorInvalidSettings:
       
  1165             {
       
  1166             __ASSERT_ALWAYS( DialogIsAllowed( 
       
  1167                 MCchUiObserver::ECchUiDialogTypeDefectiveSettings ), 
       
  1168                 User::Leave( KErrNotSupported ) );
       
  1169 
       
  1170             ShowDialogL( 
       
  1171                 aServiceId, 
       
  1172                 MCchUiObserver::ECchUiDialogTypeDefectiveSettings );
       
  1173             }
       
  1174             break;
       
  1175         
       
  1176         case KCCHErrorInvalidIap:
       
  1177         case KCCHErrorNetworkLost:
       
  1178         case KCCHErrorServiceNotResponding:
       
  1179             {
       
  1180             __ASSERT_ALWAYS( DialogIsAllowed( 
       
  1181                 MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable ), 
       
  1182                 User::Leave( KErrNotSupported ) );
       
  1183             
       
  1184             ShowDialogL( 
       
  1185                 aServiceId, 
       
  1186                 MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable );
       
  1187             }
       
  1188             break;
       
  1189         
       
  1190         case KCCHErrorAccessPointNotDefined:
       
  1191             {
       
  1192             __ASSERT_ALWAYS( DialogIsAllowed( 
       
  1193                 MCchUiObserver::ECchUiDialogTypeNoConnectionDefined ), 
       
  1194                 User::Leave( KErrNotSupported ) );
       
  1195             
       
  1196             ShowDialogL(
       
  1197                 aServiceId, 
       
  1198                 MCchUiObserver::ECchUiDialogTypeNoConnectionDefined );
       
  1199             }
       
  1200             break;
       
  1201         case KCCHErrorBandwidthInsufficient:
       
  1202             {
       
  1203             __ASSERT_ALWAYS( DialogIsAllowed( 
       
  1204                 MCchUiObserver::ECchUiDialogTypeErrorInConnection ), 
       
  1205                 User::Leave( KErrNotSupported ) );
       
  1206                   
       
  1207             ShowDialogL( 
       
  1208                 aServiceId, 
       
  1209                 MCchUiObserver::ECchUiDialogTypeErrorInConnection );
       
  1210             }
       
  1211             break;
       
  1212             
       
  1213         case KErrCancel:
       
  1214             {
       
  1215             CCHUIDEBUG( "CCchUiApiImpl::DoHandleServiceErrorL - cancelled"); 
       
  1216             CancelNotes();
       
  1217             }
       
  1218             break;            
       
  1219             
       
  1220         default:
       
  1221             break;
       
  1222         }
       
  1223     
       
  1224     CCHUIDEBUG( "CCchUiApiImpl::DoHandleServiceErrorL - OUT"); 
       
  1225     }
       
  1226     
       
  1227 // ---------------------------------------------------------------------------
       
  1228 // Observer implementation for service events.
       
  1229 // ---------------------------------------------------------------------------
       
  1230 //    
       
  1231 void CCchUiApiImpl::DoHandleServiceEventL( 
       
  1232     TInt aServiceId, 
       
  1233     TCCHSubserviceType aType, 
       
  1234     const TCchServiceStatus& aServiceStatus )
       
  1235     {
       
  1236     CCHUIDEBUG( "CCchUiApiImpl::DoHandleServiceEventL - IN" );
       
  1237     
       
  1238     CCHUIDEBUG2( "DoHandleServiceEventL - aServiceId:   %d", 
       
  1239         aServiceId ); 
       
  1240     CCHUIDEBUG2( "DoHandleServiceEventL - aError:       %d", 
       
  1241         aServiceStatus.Error() ); 
       
  1242     CCHUIDEBUG2( "DoHandleServiceEventL - aState:       %d", 
       
  1243         aServiceStatus.State() );
       
  1244     CCHUIDEBUG2( "DoHandleServiceEventL - aType:        %d", 
       
  1245         aType );
       
  1246     
       
  1247     // Check that sub service is allowed
       
  1248     __ASSERT_ALWAYS( SubServiceIsAllowed( aType ), 
       
  1249         User::Leave( KErrNotSupported ) );
       
  1250     
       
  1251     switch ( aServiceStatus.State() )
       
  1252         {
       
  1253         case ECCHDisabled:
       
  1254             {
       
  1255             CCHUIDEBUG( "DoHandleServiceEventL - disabled event" );
       
  1256             
       
  1257             // Check if all subservices are disabled
       
  1258             TBool allSubserviceDisabled = 
       
  1259                 iCCHHandler->AllSubservicesInStateL( aServiceId, ECCHDisabled );
       
  1260             
       
  1261             CCHUIDEBUG2( "DoHandleServiceEventL - all disabled=%d", 
       
  1262                 allSubserviceDisabled );
       
  1263             
       
  1264             // If all subservices are disabled stop observing service events.
       
  1265             if ( allSubserviceDisabled )
       
  1266                 {
       
  1267                 TInt observedPos = iObservervedServices.Find( aServiceId );
       
  1268                                  
       
  1269                 if ( KErrNotFound != observedPos )
       
  1270                     {
       
  1271                     CCHUIDEBUG( 
       
  1272                         "DoHandleServiceEventL - removed observed service" );
       
  1273                     iObservervedServices.Remove( observedPos );    
       
  1274                     }
       
  1275                                                                                         
       
  1276                 CCHUIDEBUG( "DoHandleServiceEventL - stop observing" );                              
       
  1277                 iCCHHandler->StopObservingL( aServiceId, *this );
       
  1278                 iObservedService = 0;
       
  1279                 }
       
  1280              
       
  1281             if ( iReEnableService )
       
  1282                 {
       
  1283                 if ( allSubserviceDisabled )
       
  1284                     {
       
  1285                     CCHUIDEBUG( "DoHandleServiceEventL - Re-Enable service" );
       
  1286                     HandleServiceReEnablingL( aServiceId );
       
  1287                     }
       
  1288                 else
       
  1289                     {
       
  1290                     // do nothing and wait next disabled event
       
  1291                     // to see if then all subservices are disabled
       
  1292                     }
       
  1293                 }
       
  1294             else if ( allSubserviceDisabled && !iReEnableService )
       
  1295                 {
       
  1296                 CCHUIDEBUG( "DoHandleServiceEventL - all subservices disabled" );
       
  1297                                 
       
  1298                 // Service is in disabled state. Inform cchui observers.
       
  1299                 InformObserversL( aServiceId );
       
  1300                 
       
  1301                 iLastOperationResult = 
       
  1302                     MCchUiObserver::ECchUiClientOperationResultNotSet;
       
  1303                 }
       
  1304             else
       
  1305                 {
       
  1306                 CCHUIDEBUG( "DoHandleServiceEventL - all subservices not disabled" );
       
  1307                 // not all subservices are disable, do nothing
       
  1308                 }
       
  1309             }
       
  1310             break;
       
  1311             
       
  1312         case ECCHEnabled:
       
  1313             {      
       
  1314             if ( iReEnableService && iCCHHandler->AllSubservicesInStateL( aServiceId, ECCHEnabled ) )
       
  1315                 {
       
  1316                 CCHUIDEBUG( "DoHandleServiceEventL - reset re-enabling" );
       
  1317                 // Just in case set re-enable flag to EFalse
       
  1318                 iReEnableService = EFalse;
       
  1319                 }
       
  1320             
       
  1321             CCHUIDEBUG( "DoHandleServiceEventL - service is enabled" );
       
  1322             
       
  1323             // Cancel notes and stop observing only if no active dialog exists
       
  1324             // which needs user action
       
  1325             if ( !iNoteController->ActiveDialogExists() && !iReEnableService )
       
  1326                 {              
       
  1327                 CancelNotes(); 
       
  1328                 
       
  1329                 TInt observedPos = iObservervedServices.Find( aServiceId );
       
  1330                 if ( KErrNotFound != observedPos )
       
  1331                     {
       
  1332                     CCHUIDEBUG( 
       
  1333                         "DoHandleServiceEventL - removed observed service" );
       
  1334                     iObservervedServices.Remove( observedPos );    
       
  1335                     }
       
  1336                          
       
  1337                 CCHUIDEBUG( "DoHandleServiceEventL - stop observing" );              
       
  1338                 iCCHHandler->StopObservingL( aServiceId, *this );
       
  1339                 iObservedService = 0;
       
  1340                 
       
  1341                 // Service is in enabled state. Inform cchui observers.
       
  1342                 InformObserversL( aServiceId );
       
  1343                 
       
  1344                 iLastOperationResult = 
       
  1345                     MCchUiObserver::ECchUiClientOperationResultNotSet;
       
  1346                 } 
       
  1347             
       
  1348             if ( iNoteController && 
       
  1349                 MCchUiObserver::ECchUiDialogTypeNoConnectionAvailable ==
       
  1350                 iNoteController->CurrentNote() )
       
  1351                 {
       
  1352                 CCHUIDEBUG( "DoHandleServiceEventL - cancel notifier" );
       
  1353                 // Connection enabled again so this notify can be canceled.
       
  1354                 CancelNotes();
       
  1355                 }
       
  1356             }
       
  1357             break;     
       
  1358         default:
       
  1359             CCHUIDEBUG( "DoHandleServiceEventL - default switch case" );
       
  1360             break;
       
  1361         }
       
  1362     
       
  1363     CCHUIDEBUG( "CCchUiApiImpl::DoHandleServiceEventL - OUT" );
       
  1364     }
       
  1365     
       
  1366 // ---------------------------------------------------------------------------
       
  1367 // Informs observers about cch ui results.
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 void CCchUiApiImpl::InformObserversL( TInt aServiceId )
       
  1371     {
       
  1372     CCHUIDEBUG( "CCchUiApiImpl::InformObserversL - IN"); 
       
  1373 
       
  1374     for ( TInt index = 0 ; index < iObservers.Count() ; index++ )
       
  1375         {    
       
  1376         CCHUIDEBUG2( "InformObserversL - aServiceId: %d", aServiceId ); 
       
  1377         CCHUIDEBUG2( "InformObserversL - iLastOperationResult: %d", 
       
  1378             iLastOperationResult ); 
       
  1379         
       
  1380         iObservers[index]->Observer().ConnectivityDialogsCompletedL( 
       
  1381             aServiceId,
       
  1382             iLastOperationResult );
       
  1383         }
       
  1384     
       
  1385     CCHUIDEBUG( "CCchUiApiImpl::InformObserversL - OUT"); 
       
  1386     }
       
  1387