wlanutilities/wlanlogin/ictswlanlogininterface/src/ictswlanlogininterface.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:
       
    15 * Entry library for launching Wlan Login application.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <xqservicerequest.h>
       
    21 #include <xqappmgr.h>
       
    22 
       
    23 // User includes
       
    24 
       
    25 #include "ictswlanlogininterface.h"
       
    26 #include "wlanloginservice.h"
       
    27 #include "ictsqtwrapper.h"
       
    28 
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "ictswlanlogininterfaceTraces.h"
       
    32 #endif
       
    33 
       
    34 /*!
       
    35     \class IctsWlanLoginInterface
       
    36     \brief This class provides a Qt API for running Internet connectivity test
       
    37            against WLAN accesspoint. If authentication is needed this component
       
    38            launches WLAN Login application through Qt Highway to render 
       
    39            authentication Web page.
       
    40 */
       
    41 
       
    42 // External function prototypes
       
    43 
       
    44 // Local constants
       
    45 
       
    46 // ======== LOCAL FUNCTIONS ========
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 /*!
       
    51     Constructor.
       
    52 */
       
    53 IctsWlanLoginInterface::IctsWlanLoginInterface(QObject *parent) :
       
    54     QObject(parent),
       
    55     mIctsWrapper(NULL),
       
    56     mAiwMgr(NULL),
       
    57     mAsyncRequest(NULL),
       
    58     mIapId(0),
       
    59     mNetId(0)
       
    60 {   
       
    61    OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_CONSTRUCTOR_ENTRY);
       
    62    
       
    63    mAiwMgr = new XQApplicationManager();
       
    64    
       
    65    OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_CONSTRUCTOR_EXIT);
       
    66 }
       
    67 
       
    68 /*!
       
    69     Destructor.
       
    70 */
       
    71 IctsWlanLoginInterface::~IctsWlanLoginInterface()
       
    72 { 
       
    73     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_DESTRUCTOR_ENTRY);
       
    74     
       
    75     if (mAsyncRequest){
       
    76         delete mAsyncRequest;
       
    77     }
       
    78     
       
    79     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_DESTRUCTOR_EXIT);
       
    80 }
       
    81 
       
    82 /*!
       
    83     Function for launching Wlan login application.
       
    84     
       
    85     @param [in] iapId Internet accesspoint id to be tested
       
    86     @param [in] netId network identifier of the connection to be used
       
    87 */
       
    88 void IctsWlanLoginInterface::start(int iapId, int netId)
       
    89 {    
       
    90     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_START_ENTRY);
       
    91     
       
    92     // Create ICTS instance as we know needed parameters now
       
    93     mIctsWrapper = new IctsWrapper(iapId, netId, this);
       
    94     
       
    95     // Store identifiers for later use
       
    96     mIapId = iapId;
       
    97     mNetId = netId;
       
    98         
       
    99     bool connectStatus = connect( 
       
   100         mIctsWrapper,
       
   101         SIGNAL(connectivityTestResult(IctsWrapper::ConnectivityTestResult, QUrl)), 
       
   102         this, 
       
   103         SLOT(handleConnectivityTestResult(IctsWrapper::ConnectivityTestResult, QUrl)));    
       
   104     Q_ASSERT(connectStatus);
       
   105     
       
   106     mIctsWrapper->startConnectivityTest();
       
   107     
       
   108     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_START_EXIT);
       
   109 }
       
   110 
       
   111 /*!
       
   112     Function for launching Wlan login application.
       
   113     
       
   114     @param [in] iapId Internet accesspoint id to be used
       
   115     @param [in] netId network id of the connection to be used
       
   116     @param [in] url Redirection URL to be loaded
       
   117     
       
   118 */
       
   119 void IctsWlanLoginInterface::wlanLoginAppStart(int iapId, int netId, QUrl url)
       
   120 {    
       
   121     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_WLANLOGINAPPSTART_ENTRY);
       
   122     
       
   123     // Execution of asynchronous and embedded Wlan Login start
       
   124     mAsyncRequest = mAiwMgr->create(
       
   125         "wlanlogin",
       
   126         "com.nokia.symbian.IWlanLogin",
       
   127         "start(int,int,QUrl)",
       
   128         false);
       
   129    
       
   130     // The Wlan Login service must always exist
       
   131     Q_ASSERT(mAsyncRequest);
       
   132 
       
   133     // Connect result handling signal
       
   134     bool connectStatus = connect(
       
   135         mAsyncRequest, 
       
   136         SIGNAL(requestOk(const QVariant&)),
       
   137         this,
       
   138         SLOT(handleOk(const QVariant&)));
       
   139     Q_ASSERT(connectStatus == true);
       
   140     
       
   141     // Connect error handling signal or apply lastError function instead.
       
   142     connectStatus = connect(
       
   143         mAsyncRequest,
       
   144         SIGNAL(requestError(int,const QString&)),
       
   145         this,
       
   146         SLOT(handleError(int)));        // Error string is ignored.
       
   147     Q_ASSERT(connectStatus == true);
       
   148 
       
   149     // Set function parameters
       
   150     QList<QVariant> args;
       
   151     args << iapId;
       
   152     args << netId;
       
   153     args << url;
       
   154      
       
   155     mAsyncRequest->setArguments(args);
       
   156    
       
   157     // The service is set asynchronous
       
   158     mAsyncRequest->setSynchronous(false);
       
   159    
       
   160     // Send the request
       
   161     bool status = mAsyncRequest->send(); 
       
   162     Q_ASSERT(status);
       
   163     
       
   164     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_WLANLOGINAPPSTART_EXIT);
       
   165 }
       
   166 
       
   167 /*!
       
   168     Function for handling request's response from QtHighway framework
       
   169     when transaction is OK. This is used only with asynchronous requests.
       
   170     
       
   171     @param [in] result Status received from WLAN Login application
       
   172 */
       
   173 void IctsWlanLoginInterface::handleOk(const QVariant& result)
       
   174 {
       
   175     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_HANDLEOK_ENTRY);
       
   176     
       
   177     ictsResultType ictsRes = IctsFailed;
       
   178     
       
   179     // Handling of result received from service.
       
   180     int i = result.toInt();
       
   181     WlanLoginService::WlanLoginStatus status = 
       
   182         static_cast<WlanLoginService::WlanLoginStatus>(i);
       
   183     
       
   184     switch (status) {
       
   185         case WlanLoginService::WlanLoginStatusConnectionDropped:
       
   186         case WlanLoginService::WlanLoginStatusCancel:
       
   187             OstTrace0(
       
   188                 TRACE_NORMAL, 
       
   189                 ICTSWLANLOGININTERFACE_HANDLEOK_CANCEL_TRACE,
       
   190                 "WlanLoginStatusCancel or WlanLoginStatusConnectionDropped received ");
       
   191             // User has canceled Wlan Login and it has to be stopped
       
   192             stop();
       
   193             ictsRes = IctsCanceled;
       
   194             break;
       
   195             
       
   196         case WlanLoginService::WlanLoginStatusNext:
       
   197             OstTrace0(
       
   198                 TRACE_NORMAL, 
       
   199                 ICTSWLANLOGININTERFACE_HANDLEOK_NEXT_TRACE,
       
   200                 "WlanLoginStatusNext received");
       
   201             ictsRes = IctsHotspotPassed;
       
   202             break;
       
   203             
       
   204         case WlanLoginService::WlanLoginStatusFailed:
       
   205             OstTrace0( TRACE_NORMAL, 
       
   206                 ICTSWLANLOGININTERFACE_HANDLEOK_FAILED_TRACE,
       
   207                 "WlanLoginStatusFailed received ");
       
   208             stop();
       
   209             ictsRes = IctsFailed;
       
   210             break;
       
   211                   
       
   212         default:
       
   213             OstTrace0(
       
   214 			    TRACE_NORMAL,
       
   215                 ICTSWLANLOGININTERFACE_HANDLEOK_UNEXPECTED_STATUS_TRACE,
       
   216                 "Unexpected WlanLoginStatus received");
       
   217             break;
       
   218             
       
   219     }
       
   220     emit ictsResult(ictsRes);
       
   221     
       
   222     delete mAsyncRequest;
       
   223     mAsyncRequest = NULL;
       
   224     
       
   225     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_HANDLEOK_EXIT);
       
   226 }
       
   227 
       
   228 /*!
       
   229     Function for handling request's response from QtHighway framework
       
   230     when errors occured. This is used only with asynchronous requests.
       
   231     
       
   232     @param [in] errorCode Error code that was received
       
   233 */
       
   234 void IctsWlanLoginInterface::handleError(int errorCode)
       
   235 {    
       
   236     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_HANDLEERROR_ENTRY);
       
   237     
       
   238     OstTrace1(
       
   239         TRACE_NORMAL,
       
   240         ICTSWLANLOGININTERFACE_ERRORCODE_TRACE,
       
   241         "errorCode=%d",
       
   242         errorCode);
       
   243     
       
   244     delete mAsyncRequest;
       
   245     mAsyncRequest = NULL;
       
   246     
       
   247     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_HANDLEERROR_EXIT);
       
   248 }
       
   249 
       
   250 /*!
       
   251     Function for stopping launched Wlan login application.
       
   252 */
       
   253 void IctsWlanLoginInterface::stop()
       
   254 { 
       
   255     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_STOP_ENTRY);
       
   256     
       
   257     // Execution of synchronous and embedded Wlan Login stop
       
   258     QScopedPointer<XQAiwRequest> syncRequest(mAiwMgr->create(
       
   259          "wlanlogin",
       
   260          "com.nokia.symbian.IWlanLogin",
       
   261          "stop()",
       
   262          false));
       
   263    
       
   264     // The Wlan Login service must always exist
       
   265     Q_ASSERT(syncRequest);
       
   266    
       
   267     // The service is set synchronous
       
   268     syncRequest->setSynchronous(true);
       
   269    
       
   270     // Send the request
       
   271     bool status = syncRequest->send(); 
       
   272     Q_ASSERT(status);
       
   273     
       
   274     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_STOP_EXIT);
       
   275 }
       
   276 
       
   277 /*!
       
   278     Function for handling connectivityTestResult signal
       
   279     
       
   280     @param [in] result Internet connectivity test result
       
   281     @param [in] redirectUrl Possible redirection URL. Valid only when HttpAuthenticationNeeded result received.
       
   282 */
       
   283 void IctsWlanLoginInterface::handleConnectivityTestResult(IctsWrapper::ConnectivityTestResult result, QUrl redirectUrl)
       
   284 {
       
   285     OstTraceFunctionEntry0(ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYTESTRESULT_ENTRY);
       
   286    
       
   287     OstTrace1(TRACE_NORMAL,
       
   288         ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYRESULT_RESULT_TRACE,
       
   289         "ConnectivityTestResult=%d",
       
   290         result);
       
   291         
       
   292     switch (result) 
       
   293         {
       
   294         case IctsWrapper::ConnectionOk:
       
   295             
       
   296             OstTrace1(
       
   297                 TRACE_BORDER,
       
   298                 ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYTESTRESULT_EMIT_ICTSRESULT_PASSED,
       
   299                 "IctsWlanLoginInterface::handleConnectivityTestResult emit ictsResult;result=%d",
       
   300                 IctsPassed);
       
   301             
       
   302             emit ictsResult(IctsPassed);
       
   303             break;
       
   304             
       
   305         case IctsWrapper::HttpAuthenticationNeeded:
       
   306             // Inform client that Hotspot authentication is needed. 
       
   307             OstTrace0(
       
   308                 TRACE_BORDER,
       
   309                 ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYTESTRESULT_EMIT_HOTSPOTCASE,
       
   310                 "IctsWlanLoginInterface::handleConnectivityTestResult emit hotspotCase");
       
   311             
       
   312             emit hotspotCase();
       
   313             wlanLoginAppStart(mIapId, mNetId, redirectUrl);
       
   314             break;
       
   315             
       
   316         default:
       
   317             OstTrace1(
       
   318                 TRACE_BORDER,
       
   319                 ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYTESTRESULT_EMIT_ICTS_RESULT_FAILED,
       
   320                 "IctsWlanLoginInterface::handleConnectivityTestResult emit ictsResult;result=%d",
       
   321                 IctsFailed);
       
   322             emit ictsResult(IctsFailed);
       
   323             break;
       
   324             
       
   325         }
       
   326     
       
   327     OstTraceFunctionExit0(ICTSWLANLOGININTERFACE_HANDLECONNECTIVITYTESTRESULT_EXIT);
       
   328 }