wlanutilities/wpswizard/src/cwpsactiverunner.cpp
branchRCL_3
changeset 24 63be7eb3fc78
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
       
     1 /*
       
     2  * Copyright (c) 2010 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 middleware wrapper class
       
    15  *
       
    16  *
       
    17  */
       
    18 // System includes
       
    19 #include <wlanmgmtcommon.h>
       
    20 #include <e32math.h>
       
    21 
       
    22 // User includes
       
    23 #include "cwpsactiverunner.h"
       
    24 
       
    25 // External function prototypes
       
    26 
       
    27 //Constants
       
    28 static const TInt KArrayGranularity = 4;
       
    29 static const TInt KDefaultPinLength = 10;
       
    30 
       
    31 // Trace includes
       
    32 #include "OstTraceDefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "cwpsactiverunnerTraces.h"
       
    35 #endif
       
    36 
       
    37 /*!
       
    38  \class CWpsActiveRunner
       
    39  \brief CWpsActiveRunner is a wrapper class wlan Mgmt engine interface.
       
    40  The wrapper class for wlan management engine calls
       
    41  */
       
    42 
       
    43 // ======== LOCAL FUNCTIONS ========
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 /*!
       
    48  * Creates the instance of active runner which encapsulates the wlan mgmt
       
    49  * interface middleware calls
       
    50  *
       
    51  *
       
    52  * \param MWpsActiveRunnerCallback[in] call back interface to notify the
       
    53  *      completion of the middleware calls
       
    54  */
       
    55 CWpsActiveRunner* CWpsActiveRunner::NewL(MWpsActiveRunnerCallback& aObserver)
       
    56 {
       
    57     OstTraceFunctionEntry0( CWPSACTIVERUNNER_NEWL_ENTRY );
       
    58     CWpsActiveRunner* self = new (ELeave) CWpsActiveRunner(aObserver);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop(self);
       
    62     OstTraceFunctionExit0( CWPSACTIVERUNNER_NEWL_EXIT );
       
    63     return self;
       
    64 }
       
    65 
       
    66 /*!
       
    67  * Creates the instance of active runner which encapsulates the wlan mgmt
       
    68  * interface middleware calls
       
    69  *
       
    70  *
       
    71  * \param MWpsActiveRunnerCallback[in] call back interface to notify the
       
    72  *      completion of the middleware calls
       
    73  */
       
    74 CWpsActiveRunner::CWpsActiveRunner(MWpsActiveRunnerCallback& aObserver) :
       
    75     CActive(EPriorityStandard),
       
    76     iObserver(aObserver),
       
    77     isCancelTriggered(false),
       
    78     iWLANMgmtClient(NULL),
       
    79     iIapParametersArray(NULL)
       
    80 {
       
    81     OstTraceFunctionEntry1( CWPSACTIVERUNNER_CWPSACTIVERUNNER_ENTRY, this );
       
    82     OstTraceFunctionExit1( CWPSACTIVERUNNER_CWPSACTIVERUNNER_EXIT, this );
       
    83 }
       
    84 
       
    85 /*!
       
    86  * ConstructL, Two phased constructor.
       
    87  *
       
    88  */
       
    89 void CWpsActiveRunner::ConstructL()
       
    90 {
       
    91     OstTraceFunctionEntry1( CWPSACTIVERUNNER_CONSTRUCTL_ENTRY, this );
       
    92 
       
    93     CActiveScheduler::Add(this);
       
    94     InitializeL();
       
    95     OstTraceFunctionExit1( CWPSACTIVERUNNER_CONSTRUCTL_EXIT, this );
       
    96 }
       
    97 
       
    98 /*!
       
    99  * Initializes the member variables for making the middleware calls
       
   100  *
       
   101  */
       
   102 
       
   103 void CWpsActiveRunner::InitializeL()
       
   104 {
       
   105     OstTraceFunctionEntry1( CWPSACTIVERUNNER_INITIALIZEL_ENTRY, this );
       
   106     iWLANMgmtClient = CWlanMgmtClient::NewL();
       
   107     iIapParametersArray = new (ELeave) CArrayFixSeg<
       
   108         TWlanProtectedSetupCredentialAttribute> (KArrayGranularity);
       
   109     
       
   110     OstTraceFunctionExit1( CWPSACTIVERUNNER_INITIALIZEL_EXIT, this );
       
   111 }
       
   112 
       
   113 /*!
       
   114  * Destructor
       
   115  *
       
   116  */
       
   117 CWpsActiveRunner::~CWpsActiveRunner()
       
   118 {
       
   119     OstTraceFunctionEntry0( DUP1_CWPSACTIVERUNNER_CWPSACTIVERUNNER_ENTRY );
       
   120     Cancel();
       
   121     delete iWLANMgmtClient;
       
   122     delete iIapParametersArray;
       
   123     OstTraceFunctionExit0( DUP1_CWPSACTIVERUNNER_CWPSACTIVERUNNER_EXIT );
       
   124 }
       
   125 
       
   126 /*!
       
   127  * Initiates the call to the middleware
       
   128  *
       
   129  * \param aSsid[in] The network ssid to which we have to connect
       
   130  * \param aPin[in] The pin to be used for WPS negotiating
       
   131  */
       
   132 void CWpsActiveRunner::StartSetup(RBuf8& aSsid, int aPin)
       
   133 {
       
   134     OstTraceFunctionEntry1( CWPSACTIVERUNNER_STARTSETUP_ENTRY, this );
       
   135     TWlanSsid ssid;
       
   136     TWlanWpsPin pin;
       
   137 
       
   138     isCancelTriggered = false;
       
   139     ssid.Copy(aSsid);
       
   140     TBuf8<KDefaultPinLength> pinCode;
       
   141 
       
   142     if (aPin == 0) {
       
   143         pinCode.AppendFill('0', 8);
       
   144     }
       
   145     else {
       
   146         pinCode.AppendNum(aPin);
       
   147     }
       
   148 
       
   149     pin.Copy(pinCode);
       
   150 
       
   151     iWLANMgmtClient->RunProtectedSetup(iStatus, ssid, pin, *iIapParametersArray);
       
   152 
       
   153     SetActive();
       
   154 
       
   155     OstTraceFunctionExit1( CWPSACTIVERUNNER_STARTSETUP_EXIT, this );
       
   156 }
       
   157 
       
   158 /*!
       
   159  * RunL implementation
       
   160  */
       
   161 void CWpsActiveRunner::RunL()
       
   162 {
       
   163     OstTraceFunctionEntry1( CWPSACTIVERUNNER_RUNL_ENTRY, this );
       
   164 
       
   165     TInt completionCode = iStatus.Int();
       
   166     QList<TWlanProtectedSetupCredentialAttribute> credentials;
       
   167 
       
   168     if(!isCancelTriggered) {
       
   169 
       
   170         if (completionCode < KErrNone) {
       
   171             //Raise Error
       
   172         QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials, completionCode));
       
   173         }
       
   174         else {
       
   175             TInt len = iIapParametersArray->Length();
       
   176             TInt count;
       
   177             for(count=0;count<iIapParametersArray->Count();count++)
       
   178                 {
       
   179                 TWlanProtectedSetupCredentialAttribute attr =(*iIapParametersArray)[count];
       
   180                 credentials.append(attr);
       
   181                 }
       
   182             QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials,completionCode));
       
   183 
       
   184         }
       
   185     }
       
   186 
       
   187     OstTraceFunctionExit1( CWPSACTIVERUNNER_RUNL_EXIT, this );
       
   188 }
       
   189 
       
   190 /*!
       
   191  * Cancels the ongoing call
       
   192  */
       
   193 void CWpsActiveRunner::DoCancel()
       
   194 {
       
   195     OstTraceFunctionEntry1( CWPSACTIVERUNNER_DOCANCEL_ENTRY, this );
       
   196     isCancelTriggered = true;
       
   197     if(iWLANMgmtClient)
       
   198         {
       
   199         iWLANMgmtClient->CancelProtectedSetup();
       
   200         }
       
   201     OstTraceFunctionExit1( CWPSACTIVERUNNER_DOCANCEL_EXIT, this );
       
   202 }
       
   203 
       
   204 /*!
       
   205  * Handles the error usecase
       
   206  */
       
   207 TInt CWpsActiveRunner::RunError(TInt aError)
       
   208 {
       
   209     OstTraceFunctionEntry1( CWPSACTIVERUNNER_RUNERROR_ENTRY, this );
       
   210 
       
   211     OstTrace1( TRACE_ERROR, CWPSACTIVERUNNER_RUNERROR, "CWpsActiveRunner::RunError;aError=%d", aError );
       
   212 
       
   213     QList<TWlanProtectedSetupCredentialAttribute> credentials;
       
   214     if(iWLANMgmtClient)
       
   215         {
       
   216         iWLANMgmtClient->CancelProtectedSetup();
       
   217         }
       
   218 
       
   219     QT_TRYCATCH_LEAVING(iObserver.WpsActiveRunnerStopped(credentials, aError));
       
   220 
       
   221     return 0;
       
   222 }
       
   223