wlanutilities/wlansniffer/engine/client/src/wsfeventhandler.cpp
changeset 19 10810c91db26
parent 3 ff3b37722600
child 22 498f36116140
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
     1 /*
       
     2 * Copyright (c) 2007-2008 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 CWsfEventHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "wsfeventhandler.h"
       
    23 
       
    24 //  INTERNAL INCLUDES
       
    25 #include "wsfstatechangeobserver.h"
       
    26 #include "wsflogger.h"
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CWsfEventHandler::NewL
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CWsfEventHandler* CWsfEventHandler::NewL( RWsfSession& aSession, 
       
    34                                           MWsfStateChangeObserver& aObserver )
       
    35     {
       
    36     CWsfEventHandler* thisPtr = new (ELeave) CWsfEventHandler( aSession, 
       
    37                                                                aObserver );
       
    38     CleanupStack::PushL( thisPtr );
       
    39     thisPtr->ConstructL();
       
    40     CleanupStack::Pop( thisPtr );
       
    41     return thisPtr;
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CWsfEventHandler::~CWsfEventHandler
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CWsfEventHandler::~CWsfEventHandler()
       
    50     {
       
    51     Cancel();
       
    52     iSession = NULL;
       
    53     iObserver = NULL;
       
    54     }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CWsfEventHandler::CWsfEventHandler
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CWsfEventHandler::CWsfEventHandler( RWsfSession& aSession, 
       
    62                                     MWsfStateChangeObserver& aObserver ): 
       
    63     CActive( CActive::EPriorityStandard )
       
    64     {
       
    65     iSession = &aSession;
       
    66     iObserver = &aObserver;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CWsfEventHandler::ConstructL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CWsfEventHandler::ConstructL()
       
    75     {
       
    76     CActiveScheduler::Add( this );
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CWsfEventHandler::DoRunL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CWsfEventHandler::DoRunL()
       
    85     {
       
    86     LOG_ENTERFN( "CWsfEventHandler::DoRunL" );    
       
    87     LOG_WRITEF( "CWsfEventHandler::DoRunL event = %d", iEvent().iEvent );    
       
    88 
       
    89     switch ( iEvent().iEvent )
       
    90         {
       
    91         case EEngineWlanDataChanged:
       
    92             {
       
    93             iObserver->WlanListChangedL();
       
    94             break;
       
    95             }
       
    96 
       
    97         case EEngineScanDisabled:
       
    98             {
       
    99             iObserver->ScanDisabledL();
       
   100             break;
       
   101             }
       
   102 
       
   103         case EEngineScanEnabled:
       
   104             {
       
   105             iObserver->ScanEnabledL();
       
   106             break;
       
   107             }
       
   108 
       
   109         case EEngineConnected:
       
   110             {
       
   111             if ( !iBlockConnectedEvent )
       
   112                 {
       
   113                 // if the event wasn't blocked, notify the observer
       
   114                 // get the connection name
       
   115                 HBufC* accessPointName = iSession->ConnectedAccountNameL();
       
   116                 CleanupStack::PushL( accessPointName );
       
   117                 iObserver->WlanConnectionActivatedL( *accessPointName );
       
   118                 CleanupStack::PopAndDestroy( accessPointName );
       
   119                 }
       
   120             else
       
   121                 {
       
   122                 // if it was blocked, just clear the flag
       
   123                 iBlockConnectedEvent = EFalse;
       
   124                 }
       
   125                 
       
   126             // anyhow, connecting process is finished
       
   127             if ( iConnecting )
       
   128                 {
       
   129                 iConnecting = EFalse;
       
   130                 iSession->StopConnectingWait();
       
   131                 iObserver->ConnectionCreationProcessFinishedL( 
       
   132                                         KErrNone );
       
   133                 }
       
   134             break;
       
   135             }
       
   136 
       
   137         case EEngineDisconnected:
       
   138             {
       
   139             iObserver->WlanConnectionClosedL();
       
   140             break;
       
   141             }
       
   142 
       
   143         case EEngineError:
       
   144             {
       
   145             iObserver->NotifyEngineError( iEvent().iError );
       
   146             break;
       
   147             }
       
   148             
       
   149         case EEngineConnectingFailed:
       
   150             {
       
   151             if ( iConnecting )
       
   152                 {
       
   153                 // connecting is over
       
   154                 iConnecting = EFalse;
       
   155 
       
   156                 // make client return with KErrCancel
       
   157                 iSession->iConnectingResult = iEvent().iError;
       
   158                 iSession->StopConnectingWait();
       
   159                 iObserver->ConnectionCreationProcessFinishedL( 
       
   160                         iSession->iConnectingResult );
       
   161                 }
       
   162             break;
       
   163             }
       
   164 
       
   165         default:
       
   166             __ASSERT_DEBUG(0, _L("CWsfEventHandler - Invalid EngineEvent"));
       
   167             break;        
       
   168         }
       
   169 
       
   170     }
       
   171 
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CWsfEventHandler::RunL
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void CWsfEventHandler::RunL()
       
   178     {
       
   179     LOG_ENTERFN( "CWsfEventHandler::RunL" );
       
   180     TInt notifyError( KErrNone );
       
   181     TBool reissue( ETrue );
       
   182     
       
   183     if ( iStatus.Int() >= KErrNone && iObserver )
       
   184         {
       
   185         TRAP( notifyError, DoRunL() );
       
   186         }
       
   187         
       
   188     if ( notifyError )
       
   189         {
       
   190         // notified class leaved
       
   191         LOG_WRITEF( "CWsfEventHandler::RunL notify error %d", notifyError );
       
   192         }
       
   193     else if ( iStatus.Int() != KErrNone )
       
   194         {
       
   195         if ( iStatus.Int() == KErrCancel )
       
   196             {
       
   197             // KErrCancel is the signal that we are going down
       
   198             LOG_WRITE( "going down..." );
       
   199             reissue = EFalse;
       
   200             }
       
   201         else
       
   202             {
       
   203             // error on the server side
       
   204             LOG_WRITEF( "CWsfEventHandler::RunL engine error %d", 
       
   205                         iStatus.Int() );
       
   206 
       
   207             TBool notify( ETrue );
       
   208                       
       
   209             if ( iStatus.Int() == KErrServerTerminated )
       
   210                 {
       
   211                 reissue = EFalse;
       
   212                 
       
   213                 if ( iObserver
       
   214                         && iSession->RecoverFromServerTermination( *iObserver ) )
       
   215                     {
       
   216                     // no need to reissue if recovered since it is already
       
   217                     // done in the recovery process
       
   218                     notify = EFalse;
       
   219                     }
       
   220                 }
       
   221 
       
   222             if ( notify && iObserver )
       
   223                 {
       
   224                 // let the client decide what to do
       
   225                 iObserver->NotifyEngineError( iStatus.Int() );
       
   226                 }
       
   227             }
       
   228         }
       
   229         
       
   230 
       
   231     if ( reissue && iObserver )
       
   232         {
       
   233         // reissue callback request
       
   234         iSession->NotifyEventL( *iObserver );
       
   235         }
       
   236     }
       
   237   
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CWsfEventHandler::DoCancel
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CWsfEventHandler::DoCancel()
       
   244     {
       
   245     LOG_ENTERFN( "CWsfEventHandler::DoCancel" );
       
   246     iSession->DoCancelNotifyEvent();
       
   247     }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CWsfEventHandler::RunError
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 TInt CWsfEventHandler::RunError( TInt aError )
       
   255     {
       
   256     LOG_ENTERFN( "CWsfEventHandler::RunError" );
       
   257     LOG_WRITEF( "CWsfEventHandler::RunError error = %d", aError );
       
   258     if ( iObserver )
       
   259         {
       
   260         iObserver->NotifyEngineError( aError ) ;
       
   261         }
       
   262     return KErrNone; // we don't wan't to panic euser-47 - do we?
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CWsfEventHandler::Start
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CWsfEventHandler::Start()
       
   271     {
       
   272     SetActive();
       
   273     }
       
   274 
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CWsfEventHandler::EventContainer
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 TPckgBuf<TWsfNotifyEventContainer>& CWsfEventHandler::EventContainer()
       
   281     {
       
   282     return iEvent;
       
   283     }
       
   284 
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CWsfEventHandler::ResetObserver
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CWsfEventHandler::ResetObserver( MWsfStateChangeObserver& aObserver )
       
   291     {
       
   292     LOG_ENTERFN( "CWsfEventHandler::ResetObserver" );
       
   293     iObserver = &aObserver;
       
   294     }
       
   295 
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CWsfEventHandler::BlockNextConnectedEvent
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CWsfEventHandler::BlockNextConnectedEvent()
       
   302     {
       
   303     if ( iConnecting )
       
   304         {
       
   305         // set the flag only if we are the ones who are connecting
       
   306         iBlockConnectedEvent = ETrue;
       
   307         }
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CWsfEventHandler::SetConnecting
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CWsfEventHandler::SetConnecting( TBool aConnecting )
       
   316     {
       
   317     iConnecting = aConnecting;
       
   318     }
       
   319     
       
   320     
       
   321 // ---------------------------------------------------------------------------
       
   322 // CWsfEventHandler::Connecting
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 TBool CWsfEventHandler::Connecting() const
       
   326     {
       
   327     return iConnecting;
       
   328     }
       
   329