diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-02-08 00:45:09 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-02-08 07:49:05 (GMT) |
commit | 5096692696b18df82914fc1f63597e00c24fa5d2 (patch) | |
tree | 69ee5d57422e17f83a2aeb573c5b24ff62eca0f8 | |
parent | 10628947d5ab1cfcd571ada10c0eab4b7f1f02ac (diff) | |
download | Qt-5096692696b18df82914fc1f63597e00c24fa5d2.zip Qt-5096692696b18df82914fc1f63597e00c24fa5d2.tar.gz Qt-5096692696b18df82914fc1f63597e00c24fa5d2.tar.bz2 |
Remove remaining Network Manager ifdef'ed code from common code.
-rw-r--r-- | src/network/bearer/bearer.pri | 2 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/networkmanager.pro | 2 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 61 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 4 | ||||
-rw-r--r-- | src/plugins/bearer/qbearerengine_impl.h | 4 | ||||
-rw-r--r-- | src/plugins/bearer/qnetworksession_impl.cpp | 100 | ||||
-rw-r--r-- | src/plugins/bearer/qnetworksession_impl.h | 13 |
7 files changed, 86 insertions, 100 deletions
diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 14e7c0c..7dc9195 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -46,7 +46,5 @@ maemo { SOURCES += bearer/qnetworkconfigmanager_p.cpp \ bearer/qbearerengine.cpp \ bearer/qbearerplugin.cpp - - contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM } diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 5bac121..bf0d29a 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network dbus -DEFINES += BACKEND_NM - HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 2c550f0..9a9bdad 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -680,6 +680,67 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i return QNetworkSession::Invalid; } +quint64 QNetworkManagerEngine::bytesWritten(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + const QString networkInterface = getInterfaceFromId(id); + if (!networkInterface.isEmpty()) { + const QString devFile = QLatin1String("/sys/class/net/") + + networkInterface + + QLatin1String("/statistics/tx_bytes"); + + quint64 result = Q_UINT64_C(0); + + QFile tx(devFile); + if (tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + + return result; + } + } + + return Q_UINT64_C(0); +} + +quint64 QNetworkManagerEngine::bytesReceived(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + const QString networkInterface = getInterfaceFromId(id); + if (!networkInterface.isEmpty()) { + const QString devFile = QLatin1String("/sys/class/net/") + + networkInterface + + QLatin1String("/statistics/rx_bytes"); + + quint64 result = Q_UINT64_C(0); + + QFile tx(devFile); + if (tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + + return result; + } + } + + return Q_UINT64_C(0); +} + +quint64 QNetworkManagerEngine::startTime(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + if (connection) + return connection->getTimestamp(); + else + return Q_UINT64_C(0); +} + QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() const { return QNetworkConfigurationManager::ForcedRoaming | diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 848f166..70efc05 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -82,6 +82,10 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + quint64 bytesWritten(const QString &id); + quint64 bytesReceived(const QString &id); + quint64 startTime(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; QNetworkSessionPrivate *createSessionBackend(); diff --git a/src/plugins/bearer/qbearerengine_impl.h b/src/plugins/bearer/qbearerengine_impl.h index 6fffe27..3772639 100644 --- a/src/plugins/bearer/qbearerengine_impl.h +++ b/src/plugins/bearer/qbearerengine_impl.h @@ -68,6 +68,10 @@ public: virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + virtual quint64 bytesWritten(const QString &) { return Q_UINT64_C(0); } + virtual quint64 bytesReceived(const QString &) { return Q_UINT64_C(0); } + virtual quint64 startTime(const QString &) { return Q_UINT64_C(0); } + Q_SIGNALS: void connectionError(const QString &id, ConnectionError error); }; diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index c823d89..8f95e77 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -266,50 +266,26 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const quint64 QNetworkSessionPrivateImpl::bytesWritten() const { -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast<QNmWifiEngine*>(getEngineFromId(config.d->id))->sentDataForId(config.d->id); - } - } - } else { - return static_cast<QNmWifiEngine*>(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); - } - } -#endif - return tx_data; + if (engine && state == QNetworkSession::Connected) + return engine->bytesWritten(activeConfig.identifier()); + else + return Q_UINT64_C(0); } quint64 QNetworkSessionPrivateImpl::bytesReceived() const { -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast<QNmWifiEngine*>(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); - } - } - } else { - return static_cast<QNmWifiEngine*>(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); - } - } -#endif - return rx_data; + if (engine && state == QNetworkSession::Connected) + return engine->bytesReceived(activeConfig.identifier()); + else + return Q_UINT64_C(0); } quint64 QNetworkSessionPrivateImpl::activeTime() const { -#if defined(BACKEND_NM) - if (startTime.isNull()) { - return 0; - } - if(state == QNetworkSession::Connected ) - return startTime.secsTo(QDateTime::currentDateTime()); -#endif - return m_activeTime; + if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0)) + return QDateTime::currentDateTime().toTime_t() - startTime; + else + return Q_UINT64_C(0); } void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() @@ -381,9 +357,8 @@ void QNetworkSessionPrivateImpl::networkConfigurationsChanged() updateStateFromServiceNetwork(); else updateStateFromActiveConfig(); -#if defined(BACKEND_NM) && 0 - setActiveTimeStamp(); -#endif + + startTime = engine->startTime(activeConfig.identifier()); } void QNetworkSessionPrivateImpl::configurationChanged(const QNetworkConfiguration &config) @@ -429,51 +404,4 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id, } } -#if defined(BACKEND_NM) && 0 -void QNetworkSessionPrivateImpl::setActiveTimeStamp() -{ - if(NetworkManagerAvailable()) { - startTime = QDateTime(); - return; - } - QString connectionIdent = q->configuration().identifier(); - QString interface = currentInterface().hardwareAddress().toLower(); - QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); - - QString path; - QString serviceName; - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - - QList<QDBusObjectPath> connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath conpath, connections) { - QNetworkManagerConnectionActive *conDetails; - conDetails = new QNetworkManagerConnectionActive(conpath.path()); - QDBusObjectPath connection = conDetails->connection(); - serviceName = conDetails->serviceName(); - QList<QDBusObjectPath> so = conDetails->devices(); - foreach(QDBusObjectPath device, so) { - - if(device.path() == devicePath) { - path = connection.path(); - } - break; - } - } -if(serviceName.isEmpty()) - return; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(serviceName); - QList<QDBusObjectPath> list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); - startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); - // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - } - if(startTime.isNull()) - startTime = QDateTime::currentDateTime(); -} -#endif - QT_END_NAMESPACE diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h index 0126a99..7349e77 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/plugins/bearer/qnetworksession_impl.h @@ -68,8 +68,8 @@ class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { Q_OBJECT public: - QNetworkSessionPrivateImpl() : - tx_data(0), rx_data(0), m_activeTime(0) + QNetworkSessionPrivateImpl() + : startTime(0) { } @@ -115,20 +115,13 @@ private Q_SLOTS: private: QNetworkConfigurationManager manager; - quint64 tx_data; - quint64 rx_data; - quint64 m_activeTime; - bool opened; QBearerEngineImpl *engine; QNetworkSession::SessionError lastError; -#if defined(BACKEND_NM) - QDateTime startTime; - void setActiveTimeStamp(); -#endif + quint64 startTime; }; QT_END_NAMESPACE |