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