wlanutilities/wlanqtutilities/wrapper/src/wlanqtutilsconmonwrapperinfo_s60.cpp
changeset 31 e8f4211554fb
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
       
     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 Connection Monitor
       
    16 * library's scan interface.
       
    17 */
       
    18 
       
    19 // System includes
       
    20 
       
    21 #include <rconnmon.h>
       
    22 #include <nifvar.h>
       
    23 
       
    24 // User includes
       
    25 
       
    26 #include "wlanqtutils.h"
       
    27 #include "wlanqtutilsconnection.h"
       
    28 #include "wlanqtutilsconmonwrapper.h"
       
    29 #include "wlanqtutilsconmonwrapperinfo_s60_p.h"
       
    30 
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "wlanqtutilsconmonwrapperinfo_s60Traces.h"
       
    34 #endif
       
    35 
       
    36 /*!
       
    37     \class WlanQtUtilsConMonWrapperInfo
       
    38     \brief Private wrapper for Symbian Connection Monitor library.
       
    39 
       
    40     Provides functionality to request information about connections.
       
    41 */
       
    42 
       
    43 // External function prototypes
       
    44 
       
    45 // Local constants
       
    46 
       
    47 // ======== LOCAL FUNCTIONS ========
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 /*!
       
    52     Constructor.
       
    53     
       
    54     @param [in] wrapper Wrapper to report progress to.
       
    55 */
       
    56 
       
    57 WlanQtUtilsConMonWrapperInfo::WlanQtUtilsConMonWrapperInfo(
       
    58     WlanQtUtilsConMonWrapper *wrapper) :
       
    59     iMonitoringConnection(0),
       
    60     q_ptr(wrapper)
       
    61 {
       
    62     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_WLANQTUTILSCONMONWRAPPERINFO_ENTRY, this);
       
    63 
       
    64     // Errors in Connection Monitor Server connection are fatal so just
       
    65     // throw them as exceptions
       
    66     QT_TRAP_THROWING(
       
    67         iMonitor.ConnectL();
       
    68         iMonitor.NotifyEventL(*this);
       
    69         );
       
    70 
       
    71     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_WLANQTUTILSCONMONWRAPPERINFO_EXIT, this);
       
    72 }
       
    73 
       
    74 /*!
       
    75     Destructor.
       
    76 */
       
    77 
       
    78 WlanQtUtilsConMonWrapperInfo::~WlanQtUtilsConMonWrapperInfo()
       
    79 {
       
    80     OstTraceFunctionEntry1(DUP1_WLANQTUTILSCONMONWRAPPERINFO_WLANQTUTILSCONMONWRAPPERINFO_ENTRY, this);
       
    81 
       
    82     iMonitor.CancelNotifications();
       
    83     iMonitor.Close();
       
    84 
       
    85     OstTraceFunctionExit1(DUP1_WLANQTUTILSCONMONWRAPPERINFO_WLANQTUTILSCONMONWRAPPERINFO_EXIT, this);
       
    86 }
       
    87 
       
    88 /*!
       
    89    Getter for active connection information.
       
    90 
       
    91    @return Information of active connection, if one exists.
       
    92 */ 
       
    93 
       
    94 WlanQtUtilsConnection *WlanQtUtilsConMonWrapperInfo::ActiveConnection()
       
    95 {
       
    96     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_ACTIVECONNECTION_ENTRY, this);
       
    97 
       
    98     // Get number of active connections
       
    99     TRequestStatus status;
       
   100 
       
   101     WlanQtUtilsConnection *activeConn = NULL;
       
   102     TUint numConnections = 0;
       
   103     iMonitor.GetConnectionCount(numConnections, status);
       
   104     User::WaitForRequest(status);
       
   105     if (status.Int() == KErrNone) {
       
   106         // Get connection info of this connection
       
   107         for (TUint i = 1; i <= numConnections; i++) {
       
   108             TUint numSubConnections = 0;
       
   109             TUint connectionId = 0;
       
   110             TInt ret = iMonitor.GetConnectionInfo(
       
   111                 i,
       
   112                 connectionId,
       
   113                 numSubConnections);
       
   114             if (ret == KErrNone) {
       
   115                 activeConn = ConnectionInfo(connectionId);
       
   116                 if (activeConn != NULL) {
       
   117                     // ConnectionInfo() only returns WLAN connections,
       
   118                     // and there may be only one active WLAN connection,
       
   119                     // so this is the one we want to return and also
       
   120                     // remember later.
       
   121                     Q_ASSERT(iMonitoringConnection == 0 
       
   122                         || iMonitoringConnection == connectionId);
       
   123                     iMonitoringConnection = connectionId;
       
   124                     break;
       
   125                 }
       
   126             }
       
   127         }
       
   128     }
       
   129 
       
   130     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_ACTIVECONNECTION_EXIT, this);
       
   131     return activeConn;
       
   132 }
       
   133 
       
   134 /*!
       
   135    Returns information of a connection with the given connection ID.
       
   136 
       
   137    @param[in] connectionId Connection ID.
       
   138    @return Information of the given connection, if one exists.
       
   139 */
       
   140 
       
   141 WlanQtUtilsConnection *WlanQtUtilsConMonWrapperInfo::ConnectionInfo(
       
   142     uint connectionId)
       
   143 {
       
   144     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_CONNECTIONINFO_ENTRY, this);
       
   145     
       
   146     WlanQtUtilsConnection *activeConn = NULL;
       
   147 
       
   148     if (IsWlanConnection(connectionId)) {
       
   149         activeConn = new WlanQtUtilsConnection();
       
   150         activeConn->setConnectionId(connectionId);
       
   151         if (!ConnectionInfoDetails(activeConn)) {
       
   152             delete activeConn;
       
   153             activeConn = NULL;
       
   154         }
       
   155     }
       
   156 
       
   157     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_CONNECTIONINFO_EXIT, this);
       
   158     return activeConn;
       
   159 }
       
   160 
       
   161 /*!
       
   162    Gets detailed information of a given connection.
       
   163 
       
   164    @param[out] connection Where to store info. Connection ID must already
       
   165                           be valid.
       
   166                           
       
   167    @return Returns ETrue if detail fetching succeeded.
       
   168 */
       
   169 
       
   170 TBool WlanQtUtilsConMonWrapperInfo::ConnectionInfoDetails(
       
   171     WlanQtUtilsConnection *connection)
       
   172 {
       
   173     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_CONNECTIONINFODETAILS_ENTRY, this);
       
   174     Q_ASSERT(connection != NULL);
       
   175 
       
   176     TBool success = EFalse;
       
   177     TUint connectionId = connection->connectionId();
       
   178     TRequestStatus status;
       
   179 
       
   180     // Get connection IAP ID.
       
   181     TUint iapId = 0;
       
   182     iMonitor.GetUintAttribute(
       
   183         connectionId,
       
   184         0,
       
   185         KIAPId,
       
   186         iapId,
       
   187         status);
       
   188     User::WaitForRequest(status);
       
   189     if (status.Int() == KErrNone) {
       
   190         connection->setIapId(iapId);
       
   191 
       
   192         // Get connection status.
       
   193         TInt connectionStatus = 0;
       
   194         iMonitor.GetIntAttribute(
       
   195             connectionId,
       
   196             0,
       
   197             KConnectionStatus,
       
   198             connectionStatus,
       
   199             status);
       
   200         User::WaitForRequest(status);
       
   201         if (status.Int() == KErrNone) {
       
   202             connection->setConnectionStatus(
       
   203                 ConnMonConnStatusMap(connectionStatus));
       
   204             success = ETrue;
       
   205         }
       
   206     }
       
   207 
       
   208     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_CONNECTIONINFODETAILS_EXIT, this);
       
   209     return success;
       
   210 }
       
   211 
       
   212 /*!
       
   213    Handler of Connection Monitor Server events.
       
   214    
       
   215    @param [in] connMonEvent Connection monitor event.
       
   216 */
       
   217 
       
   218 void WlanQtUtilsConMonWrapperInfo::EventL(const CConnMonEventBase& connMonEvent)
       
   219 {
       
   220     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_EVENTL_ENTRY, this);
       
   221 
       
   222     TUint connectionId = connMonEvent.ConnectionId();
       
   223     
       
   224     OstTraceExt2(
       
   225         TRACE_NORMAL,
       
   226         WLANQTUTILSCONMONWRAPPERINFO_EVENTL_EVENTTYPE,
       
   227         "WlanQtUtilsConMonWrapperInfo::EventL;connectionId=%u;aConnMonEvent.EventType()=%{ConnMonEvent}",
       
   228         connectionId,
       
   229         connMonEvent.EventType());
       
   230 
       
   231     switch (connMonEvent.EventType()) {
       
   232     case EConnMonCreateConnection:
       
   233         // Filter out other than WLAN connections
       
   234         if (IsWlanConnection(connectionId)) {
       
   235             iMonitoringConnection = connectionId;
       
   236             emit q_ptr->connCreatedEventFromWrapper(connectionId);
       
   237         }
       
   238         break;
       
   239         
       
   240     case EConnMonDeleteConnection:
       
   241         if (iMonitoringConnection == connectionId) {
       
   242             iMonitoringConnection = 0;
       
   243             emit q_ptr->connDeletedEventFromWrapper(connectionId);
       
   244         }
       
   245         break;
       
   246         
       
   247     case EConnMonConnectionStatusChange:
       
   248         if (iMonitoringConnection == connectionId) {
       
   249             // Find out the new status for the connection
       
   250             const CConnMonConnectionStatusChange *connMonStatusEvent;
       
   251             connMonStatusEvent =
       
   252                 static_cast< const CConnMonConnectionStatusChange* >(&connMonEvent);
       
   253             WlanQtUtils::ConnStatus connectionStatus;
       
   254             connectionStatus =
       
   255                 ConnMonConnStatusMap(connMonStatusEvent->ConnectionStatus());
       
   256             
       
   257             OstTraceExt2(
       
   258                 TRACE_NORMAL,
       
   259                 WLANQTUTILSCONMONWRAPPERINFO_EVENTL_CONNSTATUS,
       
   260                 "WlanQtUtilsConMonWrapperInfo::EventL;connectionId=%u;eventConnectionStatusChange->ConnectionStatus()=%{ConnMonConnStatus}",
       
   261                 connectionId,
       
   262                 connMonStatusEvent->ConnectionStatus());
       
   263     
       
   264             if (connectionStatus != WlanQtUtils::ConnStatusNone) {
       
   265                 emit q_ptr->connStatusEventFromWrapper(
       
   266                     connectionId,
       
   267                     connectionStatus);
       
   268             }
       
   269         }
       
   270         break;
       
   271         
       
   272     default:
       
   273         // Not interesting
       
   274         break;
       
   275     }
       
   276 
       
   277     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_EVENTL_EXIT, this);
       
   278 }
       
   279 
       
   280 /*!
       
   281    Maps Connection Monitor's connection status value into
       
   282    WlanQtUtilsConnectionStatus.
       
   283    
       
   284    Note: Mapping is only valid for WLAN connections.
       
   285 
       
   286    @param connStatus Connection status as used by Connection
       
   287                      Monitor server. Defined in nifvar.h.
       
   288    @return Connection status in Wlan Qt Utilities style.
       
   289 */
       
   290 
       
   291 WlanQtUtils::ConnStatus WlanQtUtilsConMonWrapperInfo::ConnMonConnStatusMap(
       
   292     TInt connStatus)
       
   293     {    
       
   294     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_CONNMONCONNSTATUSMAP_ENTRY, this);
       
   295 
       
   296     WlanQtUtils::ConnStatus utilsConnStatus;
       
   297     switch (connStatus) {
       
   298     // KConnectionOpen is not final status for WLAN, because DHCP is
       
   299     // run after that
       
   300     case KConnectionOpen:
       
   301     case KStartingConnection:
       
   302         utilsConnStatus = WlanQtUtils::ConnStatusConnecting;
       
   303         break;
       
   304         
       
   305     case KLinkLayerOpen:
       
   306         utilsConnStatus = WlanQtUtils::ConnStatusConnected;
       
   307         break;
       
   308         
       
   309     case KLinkLayerClosed:
       
   310         utilsConnStatus = WlanQtUtils::ConnStatusDisconnected;
       
   311         break;
       
   312         
       
   313     default:
       
   314         // Ignore all other values
       
   315         utilsConnStatus = WlanQtUtils::ConnStatusNone;
       
   316         break;
       
   317     }
       
   318     
       
   319     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_CONNMONCONNSTATUSMAP_EXIT, this);
       
   320     return utilsConnStatus;
       
   321 }
       
   322 
       
   323 /*!
       
   324     Checks the bearer of given connection.
       
   325     Meant for filtering handling only for WLAN IAP's.
       
   326     
       
   327     @param [in] connectionId Connection ID.
       
   328     
       
   329     @return Returns ETrue if connection a WLAN connection, otherwise false. 
       
   330 */
       
   331 
       
   332 TBool WlanQtUtilsConMonWrapperInfo::IsWlanConnection(TUint connectionId)
       
   333 {
       
   334     OstTraceFunctionEntry1(WLANQTUTILSCONMONWRAPPERINFO_ISWLANCONNECTION_ENTRY, this);
       
   335     
       
   336     TBool result = EFalse;
       
   337     TRequestStatus status;
       
   338 
       
   339     TInt bearer = 0;
       
   340     iMonitor.GetIntAttribute(
       
   341         connectionId,
       
   342         0,
       
   343         KBearer,
       
   344         bearer,
       
   345         status);
       
   346     User::WaitForRequest(status);
       
   347 
       
   348     if (status.Int() == KErrNone && bearer == EBearerWLAN) {
       
   349         result = ETrue;
       
   350     }
       
   351     
       
   352     OstTraceFunctionExit1(WLANQTUTILSCONMONWRAPPERINFO_ISWLANCONNECTION_EXIT, this);
       
   353     return result;
       
   354 }