wlanutilities/wlanqtutilities/wrapper/src/wlanqtutilsesockwrapper_symbian.cpp
branchRCL_3
changeset 24 63be7eb3fc78
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
       
     1 /*
       
     2 * Copyright (c) 2009-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 * Private implementation of wrapper for Symbian Esock library.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <es_sock.h>
       
    22 #include <in_sock.h>
       
    23 #include <extendedconnpref.h>
       
    24 
       
    25 // User includes
       
    26 
       
    27 #include "wlanqtutilsesockwrapper.h"
       
    28 #include "wlanqtutilsesockwrapper_symbian.h"
       
    29 
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "wlanqtutilsesockwrapper_symbianTraces.h"
       
    33 #endif
       
    34 
       
    35 /*!
       
    36     \class WlanQtUtilsWlanQtUtilsEsockWrapperPrivate
       
    37     \brief Private implementation of wrapper for Symbian Esock library.
       
    38 
       
    39     Provides functionality to connect and disconnect IAPs.
       
    40 */
       
    41 
       
    42 // External function prototypes
       
    43 
       
    44 // Local constants
       
    45 
       
    46 // ======== LOCAL FUNCTIONS ========
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 /*!
       
    51     Constructor.
       
    52     
       
    53     @param [in] wrapper Wrapper to report progress to.
       
    54  */
       
    55 
       
    56 WlanQtUtilsEsockWrapperPrivate::WlanQtUtilsEsockWrapperPrivate(
       
    57     WlanQtUtilsEsockWrapper *wrapper) :
       
    58     CActive(EPriorityStandard),
       
    59     iConnectionActive(EFalse),
       
    60     q_ptr(wrapper)
       
    61 {
       
    62     OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_ENTRY, this);
       
    63 
       
    64     CActiveScheduler::Add(this);
       
    65     
       
    66     // Establish a session to Socket Server. Errors in Socket Server
       
    67     // connection are fatal so just throw them as exceptions
       
    68     qt_symbian_throwIfError(iSocketServer.Connect());
       
    69 
       
    70     OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_EXIT, this);
       
    71 }
       
    72 
       
    73 /*!
       
    74     Destructor.
       
    75  */
       
    76 
       
    77 WlanQtUtilsEsockWrapperPrivate::~WlanQtUtilsEsockWrapperPrivate()
       
    78 {
       
    79     OstTraceFunctionEntry1(DUP1_WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_ENTRY, this);
       
    80 
       
    81     // Close any possibly ongoing connection
       
    82     Cancel();
       
    83     // Close Socket Server session
       
    84     iSocketServer.Close();
       
    85     
       
    86     OstTraceFunctionExit1(DUP1_WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_EXIT, this);
       
    87 }
       
    88 
       
    89 /*!
       
    90    Starts connection creation to given IAP.
       
    91 
       
    92    @param [in] iapId IAP ID to connect.
       
    93  */
       
    94 
       
    95 void WlanQtUtilsEsockWrapperPrivate::ConnectIap(int iapId)
       
    96 {
       
    97     OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP_ENTRY, this);
       
    98     
       
    99     // Cancel a (possibly) ongoing previous request
       
   100     Cancel();
       
   101     
       
   102     OstTrace1(
       
   103         TRACE_NORMAL,
       
   104         WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP,
       
   105         "WlanQtUtilsEsockWrapperPrivate::connectIap;iapId=%d",
       
   106         iapId );
       
   107     
       
   108     // Open an RConnection object. Errors in RConnection opening are
       
   109     // fatal so just throw them as exceptions
       
   110     qt_symbian_throwIfError(iConnection.Open(iSocketServer));
       
   111     
       
   112     // Create overrides for connection preferences to force opening of the
       
   113     // given IAP without any user prompts.
       
   114     TConnPrefList prefList;
       
   115     TExtendedConnPref prefs;
       
   116     prefs.SetIapId(iapId);
       
   117     prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent);
       
   118     QT_TRAP_THROWING(prefList.AppendL(&prefs));
       
   119      
       
   120     // Start a connection with connection preferences
       
   121     iConnection.Start(prefList, iStatus);
       
   122 
       
   123     iConnectionActive = ETrue;
       
   124     
       
   125     SetActive();
       
   126     
       
   127     OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP_EXIT, this);
       
   128 }
       
   129 
       
   130 /*!
       
   131    Disconnects connection, if one is active.
       
   132  */
       
   133 
       
   134 void WlanQtUtilsEsockWrapperPrivate::DisconnectIap()
       
   135 {      
       
   136     OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_ENTRY, this);
       
   137     
       
   138     if (iConnectionActive) {
       
   139         OstTrace0(
       
   140             TRACE_NORMAL,
       
   141             WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_DISCONNECT,
       
   142             "WlanQtUtilsEsockWrapperPrivate::disconnectIap Disconnecting connection");
       
   143         
       
   144         iConnectionActive = EFalse;
       
   145         iConnection.Close();            
       
   146     } else {
       
   147         OstTrace0(
       
   148             TRACE_NORMAL,
       
   149             WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_IGNORED,
       
   150             "WlanQtUtilsEsockWrapperPrivate::disconnectIap Ignored since no active connection");
       
   151     }
       
   152     
       
   153     OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_EXIT, this);
       
   154 }
       
   155 
       
   156 /*!
       
   157    From CActive: called when async request (RConnection::Start())
       
   158    has been completed.
       
   159  */
       
   160 
       
   161 void WlanQtUtilsEsockWrapperPrivate::RunL()
       
   162 {
       
   163     OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL_ENTRY, this);
       
   164 
       
   165     OstTrace1(
       
   166         TRACE_NORMAL,
       
   167         WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL,
       
   168         "WlanQtUtilsEsockWrapperPrivate::RunL;iStatus=%d", iStatus.Int());
       
   169     
       
   170     bool success;
       
   171     if (iStatus == KErrNone) {
       
   172         success = true;
       
   173     } else {
       
   174         success = false;
       
   175         iConnectionActive = EFalse;
       
   176     }
       
   177     
       
   178     // Report to public wrapper
       
   179     q_ptr->updateConnection(success, iStatus.Int());
       
   180     
       
   181     OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL_EXIT, this);
       
   182 }
       
   183 
       
   184 /*!
       
   185    From CActive: called when active object is cancelled.
       
   186  */
       
   187 
       
   188 void WlanQtUtilsEsockWrapperPrivate::DoCancel()
       
   189 {
       
   190     OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_DOCANCEL_ENTRY, this);
       
   191     
       
   192     // Disconnect, if needed.
       
   193     DisconnectIap();
       
   194     
       
   195     OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_DOCANCEL_EXIT, this);
       
   196 }