wlanutilities/wlansniffer/wlansnifferapplication/src/wlansniffer.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 * WLAN Sniffer application main class implementation.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <QProcess>
       
    21 #include <QLocale>
       
    22 #include <HbStyleLoader>
       
    23 #include <HbTranslator>
       
    24 
       
    25 // User includes
       
    26 
       
    27 #include "wlansnifferengine.h"
       
    28 #include "wlansniffermainwindow.h"
       
    29 #include "wlansniffer.h"
       
    30 
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "wlansnifferTraces.h"
       
    34 #endif
       
    35 
       
    36 /*!
       
    37     \class WlanSniffer
       
    38     \brief WLAN Sniffer main class implementation.
       
    39 */
       
    40 
       
    41 // External function prototypes
       
    42 
       
    43 // Local constants
       
    44 
       
    45 //! Location of WLAN Sniffer custom layout definitions
       
    46 static const QString WlanSnifferLayoutPath(":/wlansnifferlayout/");
       
    47 
       
    48 // ======== LOCAL FUNCTIONS ========
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 /*!
       
    53     Constructor.
       
    54     
       
    55     @param [in] argc Parameter count.
       
    56     @param [in] argv Parameters. 
       
    57  */
       
    58 
       
    59 WlanSniffer::WlanSniffer(int argc, char* argv[]) :
       
    60     HbApplication(argc, argv),
       
    61     mEngine(new WlanSnifferEngine(this)),
       
    62     mTranslator(),
       
    63     mMainWindow(0)
       
    64 {
       
    65     OstTraceFunctionEntry0(WLANSNIFFER_WLANSNIFFER_ENTRY);
       
    66 
       
    67     // Start scanning immediately to get the first scan results as soon as
       
    68     // possible, since the scanning takes time.
       
    69     if (mEngine->masterWlan() && !mEngine->forceDisableWlan()) {
       
    70         mEngine->startWlanScanning();
       
    71     }
       
    72     
       
    73     // Register custom layout location
       
    74     HbStyleLoader::registerFilePath(WlanSnifferLayoutPath);
       
    75 
       
    76     // Install localization
       
    77     mTranslator = QSharedPointer<HbTranslator>(new HbTranslator());
       
    78     mTranslator->loadCommon();
       
    79     
       
    80     mMainWindow = QSharedPointer<WlanSnifferMainWindow>(
       
    81         new WlanSnifferMainWindow(mEngine));
       
    82     
       
    83     // Connect exit handling
       
    84     bool connectStatus = connect(
       
    85         mEngine,
       
    86         SIGNAL(exitTriggered()),
       
    87         this,
       
    88         SLOT(exitApplication()));
       
    89     Q_ASSERT(connectStatus);
       
    90 
       
    91     // Start the Wlan Sniffer Keepalive process, if not started yet
       
    92     // The purpose of the process is to manage Wlan links opened
       
    93     // by this application, and the process should be running always
       
    94     // after the first launch of this application.
       
    95     if (findKeepaliveProcess() == false) {
       
    96         QProcess::startDetached("wlansnifferkeepalive");
       
    97     }
       
    98     
       
    99     OstTraceFunctionExit0(WLANSNIFFER_WLANSNIFFER_EXIT);
       
   100 }
       
   101 
       
   102 /*!
       
   103     Destructor.
       
   104  */
       
   105 
       
   106 WlanSniffer::~WlanSniffer()
       
   107 {
       
   108     OstTraceFunctionEntry0(WLANSNIFFER_WLANSNIFFERDESTR_ENTRY);
       
   109 
       
   110     HbStyleLoader::unregisterFilePath(WlanSnifferLayoutPath);
       
   111     
       
   112     OstTraceFunctionExit0(WLANSNIFFER_WLANSNIFFERDESTR_EXIT);
       
   113 }
       
   114 
       
   115 /*!
       
   116     Function for finding possible running keepalive process.
       
   117     
       
   118     @return TRUE if a keepalive process was found running.
       
   119  */
       
   120 
       
   121 bool WlanSniffer::findKeepaliveProcess()
       
   122 {
       
   123     OstTraceFunctionEntry0(WLANSNIFFER_FINDKEEPALIVEPROCESS_ENTRY);
       
   124     
       
   125     // Try to search the keepalive process
       
   126     bool found = false;
       
   127     TFileName executableName;
       
   128     executableName.Copy(_L("wlansnifferkeepalive*"));
       
   129     TFindProcess processSearch;
       
   130     TFullName processFullName;
       
   131     while (processSearch.Next(processFullName) == KErrNone) {
       
   132         if (processFullName.Match(executableName) != KErrNotFound) { 
       
   133             found = true;
       
   134             break;
       
   135         }
       
   136     }
       
   137     
       
   138     OstTraceExt1(
       
   139         TRACE_NORMAL,
       
   140         WLANSNIFFER_FINDKEEPALIVEPROCESS_RESULT,
       
   141         "WlanSniffer::findKeepaliveProcess;found=%hhu",
       
   142         found);
       
   143     
       
   144     OstTraceFunctionExit0(WLANSNIFFER_FINDKEEPALIVEPROCESS_EXIT);
       
   145     return found;
       
   146 }
       
   147 
       
   148 /*!
       
   149     Slot for handling application exit.
       
   150  */
       
   151 
       
   152 void WlanSniffer::exitApplication()
       
   153 {
       
   154     OstTraceFunctionEntry0(WLANSNIFFER_EXITAPPLICATION_ENTRY);
       
   155     
       
   156     exit();
       
   157 
       
   158     OstTraceFunctionExit0(WLANSNIFFER_EXITAPPLICATION_EXIT);
       
   159 }