forked from nemomobile/libconnman-qt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nemomobile#12 from lpotter/master
add counter & session API
- Loading branch information
Showing
13 changed files
with
669 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright © 2012, Jolla. | ||
* | ||
* This program is licensed under the terms and conditions of the | ||
* Apache License, version 2.0. The full text of the Apache License is at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
#include <QtDBus/QDBusConnection> | ||
|
||
#include "counter.h" | ||
|
||
static const char COUNTER_PATH[] = "/ConnectivityCounter"; | ||
|
||
Counter::Counter(QObject *parent) : | ||
QObject(parent), | ||
m_manager(NetworkManagerFactory::createInstance()) | ||
{ | ||
new CounterAdaptor(this); | ||
QDBusConnection::systemBus().registerObject(COUNTER_PATH, this); | ||
|
||
if (m_manager->isAvailable()) { | ||
m_manager->registerCounter(QString(COUNTER_PATH),1024,5); | ||
} | ||
} | ||
|
||
Counter::~Counter() | ||
{ | ||
} | ||
|
||
void Counter::serviceUsage(const QString &servicePath, const QVariantMap &counters, bool roaming) | ||
{ | ||
latestCounts.insert(servicePath, counters); | ||
Q_EMIT counterChanged(servicePath, counters, roaming); | ||
} | ||
|
||
QVariantMap Counter::latestStats(const QString &servicePath) | ||
{ | ||
return latestCounts[servicePath]; | ||
} | ||
|
||
|
||
CounterAdaptor::CounterAdaptor(Counter* parent) | ||
: QDBusAbstractAdaptor(parent), | ||
m_counter(parent) | ||
{ | ||
} | ||
|
||
CounterAdaptor::~CounterAdaptor() | ||
{ | ||
} | ||
|
||
void CounterAdaptor::Release() | ||
{ | ||
} | ||
|
||
void CounterAdaptor::Usage(const QDBusObjectPath &service_path, | ||
const QVariantMap &home, | ||
const QVariantMap &roaming) | ||
{ | ||
if (roaming.isEmpty()) { | ||
// home | ||
m_counter->serviceUsage(service_path.path(), home, false); | ||
} else if (home.isEmpty()) { | ||
//roaming | ||
m_counter->serviceUsage(service_path.path(), roaming, true); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright © 2012, Jolla. | ||
* | ||
* This program is licensed under the terms and conditions of the | ||
* Apache License, version 2.0. The full text of the Apache License is at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
#ifndef COUNTER_H | ||
#define COUNTER_H | ||
|
||
#include <QObject> | ||
#include <QVariantMap> | ||
#include <QtDBus/QDBusAbstractAdaptor> | ||
#include <QtDBus/QDBusObjectPath> | ||
|
||
#include <networkmanager.h> | ||
|
||
class Counter : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(Counter) | ||
public: | ||
explicit Counter(QObject *parent = 0); | ||
virtual ~Counter(); | ||
|
||
void serviceUsage(const QString &servicePath, const QVariantMap &counters, bool roaming); | ||
void secondsOnline(const QString &servicePath); | ||
QVariantMap latestStats(const QString &servicePath); | ||
QPair <quint32, quint32> latestBytes(const QString &servicePath); | ||
|
||
signals: | ||
// "RX.Bytes", "RX.Packets" | ||
// "TX.Bytes", "TX.Packets" | ||
// "Time" | ||
void counterChanged(const QString servicePath, const QVariantMap &counters, bool roaming); | ||
|
||
public slots: | ||
|
||
private: | ||
NetworkManager* m_manager; | ||
QMap <QString,QVariantMap> latestCounts; | ||
|
||
}; | ||
|
||
|
||
class CounterAdaptor : public QDBusAbstractAdaptor | ||
{ | ||
Q_OBJECT; | ||
Q_CLASSINFO("D-Bus Interface", "net.connman.Counter"); | ||
|
||
public: | ||
explicit CounterAdaptor(Counter* parent); | ||
virtual ~CounterAdaptor(); | ||
|
||
public slots: | ||
void Release(); | ||
void Usage(const QDBusObjectPath &service_path, | ||
const QVariantMap &home, | ||
const QVariantMap &roaming); | ||
|
||
private: | ||
Counter* m_counter; | ||
friend class CounterAdaptor; | ||
}; | ||
#endif // COUNTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright © 2012, Jolla Ltd | ||
* | ||
* This program is licensed under the terms and conditions of the | ||
* Apache License, version 2.0. The full text of the Apache License is at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
*/ | ||
|
||
#include "networksession.h" | ||
#include "sessionagent.h" | ||
|
||
NetworkSession::NetworkSession(QObject *parent) : | ||
QObject(parent), | ||
m_sessionAgent(0), | ||
m_path("/ConnmanQmlSessionAgent") | ||
{ | ||
} | ||
|
||
NetworkSession::~NetworkSession() | ||
{ | ||
} | ||
|
||
void NetworkSession::registerSession() | ||
{ | ||
if (m_path.isEmpty()) | ||
return; | ||
m_sessionAgent = new SessionAgent(m_path ,this); | ||
connect(m_sessionAgent,SIGNAL(settingsUpdated(QVariantMap)), | ||
this,SLOT(sessionSettingsUpdated(QVariantMap))); | ||
|
||
m_sessionAgent->registerSession(); | ||
} | ||
|
||
QString NetworkSession::state() const | ||
{ | ||
return settingsMap.value("State").toString(); | ||
} | ||
|
||
QString NetworkSession::name() const | ||
{ | ||
return settingsMap.value("Name").toString(); | ||
} | ||
|
||
QString NetworkSession::bearer() const | ||
{ | ||
return settingsMap.value("Bearer").toString(); | ||
} | ||
|
||
QString NetworkSession::sessionInterface() const | ||
{ | ||
return settingsMap.value("Interface").toString(); | ||
} | ||
|
||
QVariantMap NetworkSession::ipv4() const | ||
{ | ||
return settingsMap.value("IPv4").toMap(); | ||
} | ||
|
||
QVariantMap NetworkSession::ipv6() const | ||
{ | ||
return settingsMap.value("IPv6").toMap(); | ||
} | ||
|
||
QStringList NetworkSession::allowedBearers() const | ||
{ | ||
return settingsMap.value("AllowedBearers").toStringList(); | ||
} | ||
|
||
QString NetworkSession::connectionType() const | ||
{ | ||
return settingsMap.value("ConnectionType").toString(); | ||
} | ||
|
||
void NetworkSession::setAllowedBearers(const QStringList &bearers) | ||
{ | ||
settingsMap.insert("AllowedBearers", qVariantFromValue(bearers)); | ||
m_sessionAgent->setAllowedBearers(bearers); | ||
} | ||
|
||
void NetworkSession::setConnectionType(const QString &type) | ||
{ | ||
settingsMap.insert("ConnectionType", qVariantFromValue(type)); | ||
m_sessionAgent->setConnectionType(type); | ||
} | ||
|
||
void NetworkSession::requestDestroy() | ||
{ | ||
m_sessionAgent->requestDestroy(); | ||
} | ||
|
||
void NetworkSession::requestConnect() | ||
{ | ||
m_sessionAgent->requestConnect(); | ||
} | ||
|
||
void NetworkSession::requestDisconnect() | ||
{ | ||
m_sessionAgent->requestDisconnect(); | ||
} | ||
|
||
void NetworkSession::sessionSettingsUpdated(const QVariantMap &settings) | ||
{ | ||
Q_FOREACH(const QString &name, settings.keys()) { | ||
settingsMap.insert(name,settings[name]); | ||
} | ||
Q_EMIT settingsChanged(settings); | ||
} | ||
|
||
QString NetworkSession::path() const | ||
{ | ||
return m_path; | ||
} | ||
|
||
void NetworkSession::setPath(const QString &path) | ||
{ | ||
m_path = path; | ||
} |
Oops, something went wrong.