diff -r 77415202bfc8 -r fcbbe021d614 connectionmonitoring/indicatorobserver/src/indicatorobserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectionmonitoring/indicatorobserver/src/indicatorobserver.cpp Fri Apr 16 15:21:37 2010 +0300 @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "indicatorobserver.h" + +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "indicatorobserverTraces.h" +#endif + +QTM_USE_NAMESPACE + +/*! + IndicatorObserver::IndicatorObserver +*/ +IndicatorObserver::IndicatorObserver(int argc, char* argv[]) : + QCoreApplication(argc, argv), + mNetConfigurationManager(new QNetworkConfigurationManager(this)), + mSettingsManager(new XQSettingsManager(this)), + mActiveCellularConfigurations(new QList), + mActiveWlanConfigurations(new QList), + mWlanEnabled(0), + mWlanIndicatorIsActivated(false), + mCellularIndicatorIsActivated(false) + +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_CONSTRUCTOR_ENTRY, "-->"); + + bool connectStatus = false; + + connectStatus = connect( + mNetConfigurationManager, + SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, + SLOT(handleConfigurationChanged(const QNetworkConfiguration&))); + + if (!connectStatus){ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_CONNECT_FAILED, "Connecting handleConfigurationChanged SLOT failed"); + } + + connectStatus = connect( + mSettingsManager, + SIGNAL(valueChanged(const XQSettingsKey, const QVariant)), + this, + SLOT(updateWlanRadioStatus(const XQSettingsKey, const QVariant))); + + if (!connectStatus){ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_CONNECT_FAILED_DUP1, "Connecting updateWlanRadioStatus SLOT failed"); + } + + // Subscribe for WLAN ON/OFF change indications + XQSettingsKey wlanKey( + XQSettingsKey::TargetCentralRepository, + KCRUidWlanDeviceSettingsRegistryId.iUid, + KWlanOnOff); + + //Read current status of WLAN radio + //mWlanEnabled = mSettingsManager->readItemValue(wlanKey).toInt() ? true : false; + mWlanEnabled = true; + //TODO: Replace above code with commented code when WlanOnOff implementation is in release. + //TODO: Remeber to add check for read failure(call error() method from settings manager). + + mSettingsManager->startMonitoring(wlanKey); + + initializeIndicators(); + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_CONSTRUCTOR_EXIT, "<--"); +} + +/*! + IndicatorObserver::~IndicatorObserver +*/ +IndicatorObserver::~IndicatorObserver() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DESTRUCTOR_ENTRY, "-->"); + + if(mCellularIndicatorIsActivated) { + deactivateCellularIndicatorPlugin(); + } + + if (mActiveCellularConfigurations) { + mActiveCellularConfigurations->clear(); + delete mActiveCellularConfigurations; + } + + + if (mWlanIndicatorIsActivated) { + deactivateWlanIndicatorPlugin(); + } + + if (mActiveWlanConfigurations) { + mActiveWlanConfigurations->clear(); + delete mActiveWlanConfigurations; + } + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DESTRUCTOR_EXIT, "<--"); +} + +/*! + IndicatorObserver::initializeIndicators +*/ +void IndicatorObserver::initializeIndicators() +{ + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_INITIALIZEINDICATORS_ENTRY, "-->"); + + findActiveConfigurations(); + updateWlanIndicator(); + updateCellularIndicator(); + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_INITIALIZEINDICATORS_EXIT, "<--"); +} + +/*! + IndicatorObserver::updateWlanRadioStatus +*/ +void IndicatorObserver::updateWlanRadioStatus(const XQSettingsKey &key, const QVariant &value) +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATEWLANRADIOSTATUS_ENTRY, "-->"); + + // The key parameter is not used, since only WLAN ON/OFF setting is connected to this slot + Q_UNUSED(key); + + // Inform about WLAN ON/OFF status change + Q_UNUSED(value); //TODO: to be removed with final implementation. To keep compiler satisfied. + // mWlanEnabled = value.toInt() ? true : false; + + mWlanEnabled = true; //TODO: Replace with above code when WlanOnOff implementation is in release + + if (mWlanEnabled == false) { + deactivateWlanIndicatorPlugin(); + } else { + updateWlanIndicator(); + } + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATEWLANRADIOSTATUS_EXIT, "<--"); +} + +/*! + IndicatorObserver::findActiveConfigurations +*/ +void IndicatorObserver::findActiveConfigurations() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_FINDACTIVECONFIGURATIONS_ENTRY, "-->"); + + mActiveWlanConfigurations->clear(); + mActiveCellularConfigurations->clear(); + + //Let's find active connections if any + QList allConfigurations = mNetConfigurationManager->allConfigurations(QNetworkConfiguration::Active); + + for (int i=0; iappend(allConfigurations[i]); + } else if (bearerName == bearer2G || + bearerName == bearerWCDMA || + bearerName == bearerHSPA || + bearerName == bearerCDMA2000) { + mActiveCellularConfigurations->append(allConfigurations[i]); + } + } + } + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_FINDACTIVECONFIGURATIONS_EXIT, "<--"); +} + +/*! + IndicatorObserver::updateWlanIndicator +*/ +void IndicatorObserver::updateWlanIndicator() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATEWLANINDICATOR_ENTRY, "-->"); + QList list; + + int count = mActiveWlanConfigurations->count(); + + //We do not deactivate WlanIndicator plugin here as it is done in updateWlanRadioStatus method + //as WLAN radio status determines whether to show indicator or not + if ( mWlanEnabled ) { + if(count == 0) { + list.insert(0, wlanNotConnected); + activateWlanIndicatorPlugin(list); + } else { + list.insert(0, wlanConnected); + list.insert(1, mActiveWlanConfigurations->at(0).name()); + activateWlanIndicatorPlugin(list); + } + } + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATEWLANINDICATOR_EXIT, "<--"); +} + +/*! + IndicatorObserver::updateCellularIndicator +*/ +void IndicatorObserver::updateCellularIndicator() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATECELLULARINDICATOR_ENTRY, "-->"); + + QList list; + + int count = mActiveCellularConfigurations->count(); + + if ( count == 0 ) { + if ( mCellularIndicatorIsActivated ){ + deactivateCellularIndicatorPlugin(); + } + } else { + if (count == 1) { + list.insert(0, count); + list.insert(1, mActiveCellularConfigurations->at(0).name()); + list.insert(2, mActiveCellularConfigurations->at(0).identifier().toInt()); + } else { + list.insert(0, count); + + } + activateCellularIndicatorPlugin(list); + } + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_UPDATECELLULARINDICATOR_EXIT, "<--"); +} + +/*! + IndicatorObserver::handleConfigurationChanged +*/ +void IndicatorObserver::handleConfigurationChanged(const QNetworkConfiguration& config) +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_HANDLECONFIGURATIONCHANGED_ENTRY, "-->"); + + switch (config.state()) + { + case QNetworkConfiguration::Defined: //To handle situation where we have active connection and it is lost due to bad radio conditions + case QNetworkConfiguration::Discovered: + case QNetworkConfiguration::Active: + { + findActiveConfigurations(); + + QString bearerName = config.bearerName(); + + if (bearerName == bearerWLAN) { + updateWlanIndicator(); + } else if (bearerName == bearer2G || + bearerName == bearerWCDMA || + bearerName == bearerHSPA || + bearerName == bearerCDMA2000) { + updateCellularIndicator(); + } + } + break; + + default: + break; + } + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_HANDLECONFIGURATIONCHANGED_EXIT, "<--"); +} + +/*! + IndicatorObserver::activateCellularIndicatorPlugin +*/ +void IndicatorObserver::activateCellularIndicatorPlugin(QList list) +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_ACTIVATECELLULARINDICATORPLUGIN_ENTRY, "-->"); + + HbIndicator indicator; + bool success = indicator.activate("com.nokia.hb.indicator.connectivity.cellularindicatorplugin/1.0", list); + + if (!success) { + mCellularIndicatorIsActivated = false; + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_CELLULAR_INDICATOR_ACTIVATION_FAILED, "Cellular indicator activation failed"); + } else { + mCellularIndicatorIsActivated = true; + } + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_ACTIVATECELLULARINDICATORPLUGIN_EXIT, "<--"); +} + +/*! + IndicatorObserver::deactivateCellularIndicatorPlugin +*/ +void IndicatorObserver::deactivateCellularIndicatorPlugin() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DEACTIVATECELLULARINDICATORPLUGIN_ENTRY, "-->"); + + HbIndicator indicator; + indicator.deactivate("com.nokia.hb.indicator.connectivity.cellularindicatorplugin/1.0"); + mCellularIndicatorIsActivated = false; + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DEACTIVATECELLULARINDICATORPLUGIN_EXIT, "<--"); +} + +/*! + IndicatorObserver::activateWlanIndicatorPlugin +*/ +void IndicatorObserver::activateWlanIndicatorPlugin(QList list) +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_ACTIVATEWLANINDICATORPLUGIN_ENTRY, "-->"); + + HbIndicator indicator; + bool success = indicator.activate("com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0", list); + + if (!success) { + mWlanIndicatorIsActivated = false; + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_WLAN_INDICATOR_ACTIVATION_FAILED, "WLAN indicator activation failed"); + } else { + mWlanIndicatorIsActivated = true; + } + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_ACTIVATEWLANINDICATORPLUGIN_EXIT, "<--"); +} + +/*! + IndicatorObserver::deactivateWlanIndicatorPlugin +*/ +void IndicatorObserver::deactivateWlanIndicatorPlugin() +{ + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DEACTIVATEWLANINDICATORPLUGIN_ENTRY, "-->"); + + HbIndicator indicator; + indicator.deactivate("com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0"); + mWlanIndicatorIsActivated = false; + + OstTrace0(TRACE_FLOW, INDICATOROBSERVER_DEACTIVATEWLANINDICATORPLUGIN_EXIT, "<--"); +}