wlanutilities/wlanqtutilities/base/src/wlanqtutilsap.cpp
changeset 31 e8f4211554fb
child 39 7b3e49e4608a
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 * WLAN AP (Access Point, unknown network) class.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <QString>
       
    21 #include <QHash>
       
    22 #include <QVariant>
       
    23 #include <QDebug>
       
    24 
       
    25 // User includes
       
    26 
       
    27 #include "wlanqtutilsap.h"
       
    28 
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "wlanqtutilsapTraces.h"
       
    32 #endif
       
    33 
       
    34 /*!
       
    35     \class WlanQtUtilsApPrivate
       
    36     \brief Private implementation of WlanQtUtilsAp.
       
    37 */
       
    38 
       
    39 class WlanQtUtilsApPrivate
       
    40 {
       
    41 private:
       
    42     //! Access Point configuration data
       
    43     QHash<int, QVariant> mConfigurations;
       
    44 
       
    45     friend class WlanQtUtilsAp;
       
    46 };
       
    47 
       
    48 /*!
       
    49     \class WlanQtUtilsAp
       
    50     \brief WLAN Access Point class.
       
    51 
       
    52     Contains the information related to unknown WLAN access points.
       
    53 */
       
    54 
       
    55 // External function prototypes
       
    56 
       
    57 // Local constants
       
    58 
       
    59 // ======== LOCAL FUNCTIONS ========
       
    60 
       
    61 // ======== MEMBER FUNCTIONS ========
       
    62 
       
    63 /*!
       
    64     Constructor.
       
    65 */
       
    66 
       
    67 WlanQtUtilsAp::WlanQtUtilsAp() :
       
    68     d_ptr(new WlanQtUtilsApPrivate())
       
    69 {
       
    70 }
       
    71 
       
    72 /*!
       
    73     Copy constructor.
       
    74 
       
    75     @param [in] ref AP to create a copy of.
       
    76 */
       
    77 
       
    78 WlanQtUtilsAp::WlanQtUtilsAp(const WlanQtUtilsAp &ref) :
       
    79     d_ptr(new WlanQtUtilsApPrivate())
       
    80 {
       
    81     d_ptr->mConfigurations = ref.d_ptr->mConfigurations;
       
    82 }
       
    83 
       
    84 /*!
       
    85     Destructor.
       
    86 */
       
    87 
       
    88 WlanQtUtilsAp::~WlanQtUtilsAp()
       
    89 {
       
    90 }
       
    91 
       
    92 /*!
       
    93     Getter for AP data.
       
    94 
       
    95     @param [in] identifier Identifier of value to get.
       
    96     
       
    97     @return Value.
       
    98 */
       
    99 
       
   100 QVariant WlanQtUtilsAp::value(int identifier) const
       
   101 {
       
   102     Q_ASSERT(d_ptr->mConfigurations.contains(identifier));
       
   103     Q_ASSERT(d_ptr->mConfigurations[identifier].isValid());
       
   104     
       
   105 #ifdef OST_TRACE_COMPILER_IN_USE
       
   106     QString tmp;
       
   107     QDebug tmpStream(&tmp);
       
   108     tmpStream << d_ptr->mConfigurations[identifier];
       
   109     TPtrC16 string(tmp.utf16(), tmp.length());
       
   110     
       
   111     OstTraceExt2(
       
   112         TRACE_DUMP,
       
   113         WLANQTUTILSAP_VALUE,
       
   114         "WlanQtUtilsAp::value;identifier=%{ConfId};string=%S",
       
   115         (TUint)identifier,
       
   116         string);
       
   117 #endif
       
   118     
       
   119     return d_ptr->mConfigurations[identifier];
       
   120 }
       
   121 
       
   122 /*!
       
   123     Setter for AP data.
       
   124 
       
   125     @param [in] identifier Identifier of value to set.
       
   126     @param [in] value Value to set.
       
   127 */
       
   128 
       
   129 void WlanQtUtilsAp::setValue(int identifier, QVariant value)
       
   130 {
       
   131 #ifdef OST_TRACE_COMPILER_IN_USE
       
   132     QString tmp;
       
   133     QDebug tmpStream(&tmp);
       
   134     tmpStream << value;
       
   135     TPtrC16 string(tmp.utf16(), tmp.length());
       
   136     
       
   137     OstTraceExt2(
       
   138         TRACE_DUMP,
       
   139         WLANQTUTILSAP_SETVALUE,
       
   140         "WlanQtUtilsAp::setValue;identifier=%{ConfId};string=%S",
       
   141         (TUint)identifier,
       
   142         string);
       
   143 #endif
       
   144     
       
   145     d_ptr->mConfigurations[identifier] = value;
       
   146 }
       
   147 
       
   148 /*!
       
   149     AP comparison function.
       
   150 
       
   151     @param [in] ap1 First AP to compare.
       
   152     @param [in] ap2 Second AP to compare.
       
   153 
       
   154     @return TRUE, if APs are considered to be same.
       
   155 */
       
   156 
       
   157 bool WlanQtUtilsAp::compare(
       
   158     const WlanQtUtilsAp *ap1,
       
   159     const WlanQtUtilsAp *ap2)
       
   160 {
       
   161     bool equal = false;
       
   162     
       
   163     // SSID (case sensitive) and security mode (with or without PSK)
       
   164     // are the values, which identify a unique access point.
       
   165     if (ap1->value(WlanQtUtilsAp::ConfIdSsid) ==
       
   166         ap2->value(WlanQtUtilsAp::ConfIdSsid)
       
   167         && ap1->value(WlanQtUtilsAp::ConfIdSecurityMode) == 
       
   168            ap2->value(WlanQtUtilsAp::ConfIdSecurityMode)
       
   169            && ap1->value(WlanQtUtilsAp::ConfIdWpaPskUse) ==
       
   170               ap2->value(WlanQtUtilsAp::ConfIdWpaPskUse)) {
       
   171         equal = true;
       
   172     }
       
   173     
       
   174     return equal;
       
   175 }