wlanutilities/wlansniffer/aiplugin/src/wsfwlanlistactivewrapper.cpp
branchRCL_3
changeset 10 dff6ebfd236f
child 11 8b0eae1b1d71
equal deleted inserted replaced
8:c2bc3f8c7777 10:dff6ebfd236f
       
     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 CWsfWLANListActiveWrapper.
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "wsflogger.h"
       
    21 #include "wsfmodel.h"
       
    22 #include "wsfwlaninfoarray.h"
       
    23 #include "wsfaicontroller.h"
       
    24 #include "wsfwlanlistactivewrapper.h"
       
    25 
       
    26 
       
    27 /**
       
    28 * Number of retries to fetch wlan data
       
    29 */
       
    30 static const TInt KRetries = 5;
       
    31 
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // CWsfWLANListActiveWrapper::CWsfWLANListActiveWrapper
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 CWsfWLANListActiveWrapper::CWsfWLANListActiveWrapper() :
       
    38     CActive( EPriorityStandard ), // Standard priority
       
    39     iPtr( NULL, 0 )
       
    40     {
       
    41     }
       
    42 
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // CWsfWLANListActiveWrapper::NewLC
       
    46 // ----------------------------------------------------------------------------
       
    47 //
       
    48 CWsfWLANListActiveWrapper* CWsfWLANListActiveWrapper::NewLC( CWsfModel* aModel, 
       
    49                                                 TWsfAiController &aController )
       
    50     {
       
    51     LOG_ENTERFN( "CWsfWLANListActiveWrapper::NewLC" );
       
    52     CWsfWLANListActiveWrapper* self =
       
    53             new (ELeave) CWsfWLANListActiveWrapper();
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL( aModel, aController );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CWsfWLANListActiveWrapper::NewL
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 CWsfWLANListActiveWrapper* CWsfWLANListActiveWrapper::NewL( CWsfModel* aModel, 
       
    65                                                 TWsfAiController &aController )
       
    66     {
       
    67     LOG_ENTERFN( "CWsfWLANListActiveWrapper::NewL" );
       
    68     CWsfWLANListActiveWrapper* self = CWsfWLANListActiveWrapper::NewLC(
       
    69              aModel, aController );
       
    70     CleanupStack::Pop(); // self;
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // CWsfWLANListActiveWrapper::ConstructL
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 void CWsfWLANListActiveWrapper::ConstructL( CWsfModel* aModel,
       
    80                                             TWsfAiController &aController )
       
    81     {
       
    82     LOG_ENTERFN( "CWsfWLANListActiveWrapper::ConstructL" );
       
    83     CActiveScheduler::Add(this); // Add to scheduler
       
    84     iModel = aModel;
       
    85     iController = &aController;
       
    86     iArray = CWsfWlanInfoArray::NewL();
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper()
       
    94     {
       
    95     LOG_ENTERFN( "CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper" );
       
    96     Cancel(); // Cancel any request, if outstanding
       
    97     // Delete instance variables if any
       
    98     if ( iBuffer )
       
    99         {
       
   100         delete iBuffer;
       
   101         }
       
   102     delete iArray;
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CWsfWLANListActiveWrapper::DoCancel
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void CWsfWLANListActiveWrapper::DoCancel()
       
   110     {
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CWsfWLANListActiveWrapper::Start
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 void CWsfWLANListActiveWrapper::Start( TBool aStarUp )
       
   118     {
       
   119     LOG_ENTERFN( "CWsfWLANListActiveWrapper::Start" );
       
   120     Cancel(); // Cancel any request, just to be sure
       
   121     iStartUp = aStarUp;
       
   122     iState = EUninitialized;
       
   123     iRetriesLeft = KRetries;
       
   124     iPckgAllocatedSize() = 0;
       
   125     iPckgNeededSize() = 0;
       
   126     SetActive();
       
   127     TRequestStatus* status = &iStatus;
       
   128     User::RequestComplete(status, KErrNone);
       
   129     }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CWsfWLANListActiveWrapper::GetWlanList
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 CWsfWlanInfoArray* CWsfWLANListActiveWrapper::GetWlanList()
       
   136     {
       
   137     LOG_ENTERFN( "CWsfWLANListActiveWrapper::GetWlanList" );
       
   138     return iArray;
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CWsfWLANListActiveWrapper::GetConnectedWLANNetwork
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 TWsfWlanInfo CWsfWLANListActiveWrapper::GetConnectedWLANNetwork()
       
   146     {
       
   147     LOG_ENTERFN( "CWsfWLANListActiveWrapper::GetConnectedWLANNetwork" );
       
   148     return iConnectedWlan;
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CWsfWLANListActiveWrapper::RunL
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 void CWsfWLANListActiveWrapper::RunL()
       
   156     {
       
   157     LOG_ENTERFN( "CWsfWLANListActiveWrapper::RunL" );
       
   158     if ( iState == EUninitialized )
       
   159         {
       
   160         LOG_WRITE( "Get WLAN list size" );
       
   161         iModel->GetWlanListSize( iPckgNeededSize, iStatus );
       
   162         iState = EInitialized;
       
   163         SetActive(); // Tell scheduler a request is active
       
   164         }
       
   165     else if ( iState == EInitialized )
       
   166         {
       
   167         LOG_WRITEF( "WLAN data buffer size = %d", iPckgNeededSize() );
       
   168 
       
   169         if ( !iPckgNeededSize() )
       
   170             {
       
   171             LOG_WRITE( "no data.." );
       
   172             iState = EProcessWLANListData;
       
   173             SetActive();
       
   174             TRequestStatus* status = &iStatus;
       
   175             User::RequestComplete(status, KErrNone);
       
   176             }
       
   177         else
       
   178             {
       
   179 			// alloc the required size buffer...
       
   180             delete iBuffer;
       
   181             iBuffer = NULL;
       
   182             iBuffer = HBufC8::NewL( iPckgNeededSize() );
       
   183             iPtr.Set( iBuffer->Des() );
       
   184         
       
   185             LOG_WRITE( "Get WLAN list" );
       
   186             iModel->GetWlanList( iPckgAllocatedSize, iPtr, iStatus );
       
   187             iState = EProcessWLANListData;
       
   188             SetActive(); // Tell scheduler a request is active
       
   189             }
       
   190         }
       
   191     else if ( iState == EProcessWLANListData )
       
   192         {
       
   193         LOG_WRITEF( "actual bytes occupied = %d", iPckgAllocatedSize() );
       
   194 
       
   195         if ( iPckgNeededSize() != iPckgAllocatedSize() )
       
   196             {
       
   197             // the buffer is not long enough... stop 
       
   198             if ( iRetriesLeft > 0 )
       
   199                 {
       
   200                 LOG_WRITEF( "iRetriesLeft = %d", iRetriesLeft );
       
   201                 iRetriesLeft--;
       
   202                 iState = EUninitialized;
       
   203                 SetActive();
       
   204                 TRequestStatus* status = &iStatus;
       
   205                 User::RequestComplete( status, KErrNone );
       
   206                 return;
       
   207                 }
       
   208             else
       
   209                 {
       
   210                 // no more retries
       
   211                 User::Leave( KErrOverflow );
       
   212                 }
       
   213             }
       
   214         
       
   215         iArray->Reset();
       
   216         
       
   217         if ( iPckgAllocatedSize() )
       
   218             {
       
   219             iArray->AppendFromStreamBufferL( iPtr );
       
   220             }
       
   221         
       
   222         LOG_WRITEF( "Array count=%d startup=%d", iArray->Count(), iStartUp );
       
   223         
       
   224         iModel->GetConnectedWlanDetails( iPckg, iConnectedWlan, iStatus );
       
   225         iState = EGetConnectedNetwork;
       
   226         SetActive(); // Tell scheduler a request is active
       
   227         }
       
   228     else if ( iState == EGetConnectedNetwork )
       
   229         {
       
   230         LOG_WRITEF( "request result = %d", iPckg() );
       
   231         
       
   232         if ( !iPckg() )
       
   233             {
       
   234             LOG_WRITE( "result is false, so wlaninfo is marked not connected" );
       
   235             iConnectedWlan.iConnectionState = ENotConnected;
       
   236             }
       
   237         
       
   238         LOG_WRITEF( "Connected = %d", iConnectedWlan.Connected() );
       
   239         
       
   240         LOG_WRITEF( "iConnectedWlan state = %d", 
       
   241                                             iConnectedWlan.iConnectionState );
       
   242         
       
   243         if ( iStartUp )
       
   244             {
       
   245             iController->StartupRefreshDataReadyL();
       
   246             }
       
   247         else
       
   248             {
       
   249             iController->WlanListDataReadyL();
       
   250             }
       
   251         }
       
   252     else
       
   253         {
       
   254         LOG_WRITEF( "iState = %d", iState );
       
   255         }
       
   256     }
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 // CWsfWLANListActiveWrapper::RunError
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 #ifdef _DEBUG
       
   263 TInt CWsfWLANListActiveWrapper::RunError( TInt aError )
       
   264     {
       
   265     LOG_ENTERFN( "CWsfWLANListActiveWrapper::RunError" );
       
   266     LOG_WRITEF( "aError = %d", aError );
       
   267     return aError;
       
   268     }
       
   269 #else
       
   270 TInt CWsfWLANListActiveWrapper::RunError( TInt /*aError*/ )
       
   271     {
       
   272     return KErrNone;
       
   273     }
       
   274 #endif