summaryrefslogtreecommitdiffstats
path: root/src/plugins/bearer/connman/qconnmanservice_linux.cpp
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@jollamobile.com>2014-01-23 18:47:31 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-07 05:34:30 +0100
commitcc14f85730813b9f0bb752627bab3c44803091a6 (patch)
tree4067c89125712461df5ee9ce06e78ae69c82667d /src/plugins/bearer/connman/qconnmanservice_linux.cpp
parent125bb81bef7729d182f533989ffdf53685abbe31 (diff)
Refactor and remove dead code, add property caching.
This helps with a flood of dbus messages due to properties. Change-Id: I7aa9d36a077d84a88dab561d007d597b0780e096 Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/plugins/bearer/connman/qconnmanservice_linux.cpp')
-rw-r--r--src/plugins/bearer/connman/qconnmanservice_linux.cpp866
1 files changed, 218 insertions, 648 deletions
diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp
index 6d9ee265c6..46b24f77dd 100644
--- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp
+++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp
@@ -75,708 +75,380 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &map)
}
QConnmanManagerInterface::QConnmanManagerInterface( QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
- QLatin1String(CONNMAN_MANAGER_PATH),
+ : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
CONNMAN_MANAGER_INTERFACE,
QDBusConnection::systemBus(), parent)
{
qDBusRegisterMetaType<ConnmanMap>();
qDBusRegisterMetaType<ConnmanMapList>();
-}
-QConnmanManagerInterface::~QConnmanManagerInterface()
-{
-}
+ QList<QVariant> argumentList;
+ QDBusPendingReply<QVariantMap> props_reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(props_reply, this);
-void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal)
-{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
- if(!connection().connect(QLatin1String(CONNMAN_SERVICE),
- QLatin1String(CONNMAN_MANAGER_PATH),
- QLatin1String(CONNMAN_MANAGER_INTERFACE),
- QLatin1String("PropertyChanged"),
- this,SIGNAL(propertyChanged(QString,QDBusVariant)))) {
- qWarning() << "PropertyChanged not connected";
- }
- }
+ QObject::connect(watcher,SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(propertiesReply(QDBusPendingCallWatcher*)));
- static const QMetaMethod stateChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::stateChanged);
- if (signal == stateChangedSignal) {
- if (!connection().connect(QLatin1String(CONNMAN_SERVICE),
- QLatin1String(CONNMAN_MANAGER_PATH),
- QLatin1String(CONNMAN_MANAGER_INTERFACE),
- QLatin1String("StateChanged"),
- this,SIGNAL(stateChanged(QString)))) {
- qWarning() << "StateChanged not connected";
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
+ QStringLiteral(CONNMAN_SERVICE_INTERFACE),
+ QStringLiteral("PropertyChanged"),
+ this,SLOT(changedProperty(QString,QDBusVariant)));
- }
- }
- static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChangedContext);
- if (signal == propertyChangedContextSignal) {
- QConnmanDBusHelper *helper;
- helper = new QConnmanDBusHelper(this);
-
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- QLatin1String(CONNMAN_MANAGER_PATH),
- QLatin1String(CONNMAN_MANAGER_INTERFACE),
- QLatin1String("PropertyChanged"),
- helper,SLOT(propertyChanged(QString,QDBusVariant)));
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
+ QStringLiteral(CONNMAN_SERVICE_INTERFACE),
+ QStringLiteral("TechnologyAdded"),
+ this,SLOT(technologyAdded(QDBusObjectPath,QVariantMap)));
- QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)),
- this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection);
- }
- static const QMetaMethod servicesChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::servicesChanged);
- if (signal == servicesChangedSignal) {
- if (!connection().connect(QLatin1String(CONNMAN_SERVICE),
- QLatin1String(CONNMAN_MANAGER_PATH),
- QLatin1String(CONNMAN_MANAGER_INTERFACE),
- QLatin1String("ServicesChanged"),
- this,SLOT(onServicesChanged(ConnmanMapList, QList<QDBusObjectPath>)))) {
- qWarning() << "servicesChanged not connected";
- }
- }
-}
-
-void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList<QDBusObjectPath> &removed)
-{
- emit servicesChanged(changed, removed);
-}
-
-
-void QConnmanManagerInterface::disconnectNotify(const QMetaMethod &signal)
-{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
-
- }
-}
-
-QVariant QConnmanManagerInterface::getProperty(const QString &property)
-{
- QVariant var;
- QVariantMap map = getProperties();
- if (map.contains(property)) {
- var = map.value(property);
- } else {
- qDebug() << "does not contain" << property;
- }
- return var;
-}
-
-QVariantMap QConnmanManagerInterface::getProperties()
-{
- if(this->isValid()) {
- QDBusReply<QVariantMap > reply = this->call(QLatin1String("GetProperties"));
- return reply.value();
- } else return QVariantMap();
-}
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
+ QStringLiteral(CONNMAN_SERVICE_INTERFACE),
+ QStringLiteral("TechnologyRemoved"),
+ this,SLOT(technologyRemoved(QDBusObjectPath)));
-QString QConnmanManagerInterface::getState()
-{
- QDBusReply<QString > reply = this->call("GetState");
- return reply.value();
-}
+ QList<QVariant> argumentList2;
+ QDBusPendingReply<ConnmanMapList> serv_reply = asyncCallWithArgumentList(QLatin1String("GetServices"), argumentList2);
+ QDBusPendingCallWatcher *watcher2 = new QDBusPendingCallWatcher(serv_reply, this);
-bool QConnmanManagerInterface::setProperty(const QString &name, const QDBusVariant &value)
-{
- Q_UNUSED(name);
- Q_UNUSED(value);
- return false;
-}
+ QObject::connect(watcher2,SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(servicesReply(QDBusPendingCallWatcher*)));
-QDBusObjectPath QConnmanManagerInterface::createProfile(const QString &/*name*/)
-{
- return QDBusObjectPath();
}
-bool QConnmanManagerInterface::removeProfile(QDBusObjectPath /*path*/)
+QConnmanManagerInterface::~QConnmanManagerInterface()
{
- return false;
}
-bool QConnmanManagerInterface::requestScan(const QString &type)
+void QConnmanManagerInterface::changedProperty(const QString &name, const QDBusVariant &value)
{
- QDBusReply<QString> reply = this->call(QLatin1String("RequestScan"), QVariant::fromValue(type));
-
- bool ok = true;
- if(reply.error().type() == QDBusError::InvalidArgs) {
- qWarning() << reply.error().message();
- ok = false;
- }
- return ok;
+ propertiesCacheMap[name] = value.variant();
}
-bool QConnmanManagerInterface::enableTechnology(const QString &type)
+void QConnmanManagerInterface::propertiesReply(QDBusPendingCallWatcher *call)
{
- QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("EnableTechnology"), QVariant::fromValue(type));
- bool ok = true;
- if(reply.error().type() == QDBusError::InvalidArgs) {
- qWarning() << reply.error().message();
- ok = false;
- }
- return ok;
-}
+ QDBusPendingReply<QVariantMap> props_reply = *call;
-bool QConnmanManagerInterface::disableTechnology(const QString &type)
-{
- QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("DisableTechnology"), QVariant::fromValue(type));
- bool ok = true;
- if(reply.error().type() == QDBusError::InvalidArgs) {
- qWarning() << reply.error().message();
- ok = false;
+ if (props_reply.isError()) {
+ qDebug() << props_reply.error().message();
+ } else {
+ propertiesCacheMap = props_reply.value();
}
- return ok;
+ call->deleteLater();
}
-QDBusObjectPath QConnmanManagerInterface::connectService(QVariantMap &map)
+void QConnmanManagerInterface::servicesReply(QDBusPendingCallWatcher *call)
{
- QDBusReply<QDBusObjectPath > reply = this->call(QLatin1String("ConnectService"), QVariant::fromValue(map));
- if(!reply.isValid()) {
- qDebug() << reply.error().message();
+ QDBusPendingReply<ConnmanMapList> serv_reply = *call;
+ if (serv_reply.isError()) {
+ qDebug() << serv_reply.error().message();
+ } else {
+ servicesList.clear(); //connman list changes order
+ ConnmanMap connmanobj;
+ Q_FOREACH (connmanobj, serv_reply.value()) {
+ servicesList << connmanobj.objectPath.path();
+ }
+ Q_EMIT servicesReady(servicesList);
}
- return reply;
+ call->deleteLater();
}
-void QConnmanManagerInterface::registerAgent(QDBusObjectPath &/*path*/)
-{
-}
-
-void QConnmanManagerInterface::unregisterAgent(QDBusObjectPath /*path*/)
+void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal)
{
-}
-
-void QConnmanManagerInterface::registerCounter(const QString &path, quint32 interval)
-{ QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("RegisterCounter"),
- QVariant::fromValue(path),
- QVariant::fromValue(interval));
- if(reply.error().type() == QDBusError::InvalidArgs) {
- qWarning() << reply.error().message();
+ static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged);
+ if (signal == propertyChangedSignal) {
+ if (!connection().connect(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
+ QStringLiteral(CONNMAN_MANAGER_INTERFACE),
+ QStringLiteral("PropertyChanged"),
+ this,SIGNAL(propertyChanged(QString,QDBusVariant)))) {
+ qWarning() << "PropertyChanged not connected";
+ }
}
-}
-void QConnmanManagerInterface::unregisterCounter(const QString &path)
-{ QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("UnregisterCounter"),
- QVariant::fromValue(path));
- if(reply.error().type() == QDBusError::InvalidArgs) {
- qWarning() << reply.error().message();
+ static const QMetaMethod servicesChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::servicesChanged);
+ if (signal == servicesChangedSignal) {
+ if (!connection().connect(QStringLiteral(CONNMAN_SERVICE),
+ QStringLiteral(CONNMAN_MANAGER_PATH),
+ QStringLiteral(CONNMAN_MANAGER_INTERFACE),
+ QStringLiteral("ServicesChanged"),
+ this,SLOT(onServicesChanged(ConnmanMapList, QList<QDBusObjectPath>)))) {
+ qWarning() << "servicesChanged not connected";
+ }
}
}
-QString QConnmanManagerInterface::requestSession(const QString &bearerName)
-{
- QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("RequestSession"),
- QVariant::fromValue(bearerName));
- return QString();
-}
-
-void QConnmanManagerInterface::releaseSession()
-{
- QDBusReply<QList<QDBusObjectPath> > reply = this->call(QLatin1String("ReleaseSession"));
-}
-
-
-QDBusObjectPath QConnmanManagerInterface::lookupService(const QString &service)
+void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList<QDBusObjectPath> &removed)
{
- QDBusReply<QDBusObjectPath > reply = this->call(QLatin1String("LookupService"), QVariant::fromValue(service));
- if(!reply.isValid()) {
- qDebug() << reply.error().message();
+ ConnmanMap connmanobj;
+ servicesList.clear(); //connman list changes order
+ Q_FOREACH (connmanobj, changed) {
+ const QString svcPath(connmanobj.objectPath.path());
+ servicesList << svcPath;
}
- return reply;
-}
-// properties
-
-QStringList QConnmanManagerInterface::getAvailableTechnologies()
-{
- QVariant var = getProperty("AvailableTechnologies");
- return qdbus_cast<QStringList>(var);
+ Q_EMIT servicesChanged(changed, removed);
}
-QStringList QConnmanManagerInterface::getEnabledTechnologies()
+QVariant QConnmanManagerInterface::getProperty(const QString &property)
{
- QVariant var = getProperty("EnabledTechnologies");
- return qdbus_cast<QStringList>(var);
+ QVariant var;
+ var = propertiesCacheMap.value(property);
+ return var;
}
-QStringList QConnmanManagerInterface::getConnectedTechnologies()
+QVariantMap QConnmanManagerInterface::getProperties()
{
- QVariant var = getProperty("ConnectedTechnologies");
- return qdbus_cast<QStringList>(var);
+ if (propertiesCacheMap.isEmpty()) {
+ QDBusPendingReply<QVariantMap> reply = call(QLatin1String("GetProperties"));
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ propertiesCacheMap = reply.value();
+ }
+ }
+ return propertiesCacheMap;
}
-QString QConnmanManagerInterface::getDefaultTechnology()
+QString QConnmanManagerInterface::getState()
{
- QVariant var = getProperty("DefaultTechnology");
- return qdbus_cast<QString>(var);
+ return getProperty(QStringLiteral("State")).toString();
}
bool QConnmanManagerInterface::getOfflineMode()
{
- QVariant var = getProperty("OfflineMode");
+ QVariant var = getProperty(QStringLiteral("OfflineMode"));
return qdbus_cast<bool>(var);
}
-QString QConnmanManagerInterface::getActiveProfile()
-{
- QVariant var = getProperty("ActiveProfile");
- return qdbus_cast<QString>(var);
-}
-
-QStringList QConnmanManagerInterface::getProfiles()
-{
- QVariant var = getProperty("Profiles");
- return qdbus_cast<QStringList>(var);
-}
-
QStringList QConnmanManagerInterface::getTechnologies()
{
- QStringList list;
- QDBusReply<ConnmanMapList> replyList = this->call(QLatin1String("GetTechnologies"));
- if (replyList.isValid()) {
- Q_FOREACH (ConnmanMap map, replyList.value()) {
- list << map.objectPath.path();
- }
- } else {
- // try for older version
- QVariant var = getProperty("Technologies");
- if (!var.isNull()) {
- list = qdbus_cast<QStringList>(var);
+ if (technologiesMap.isEmpty()) {
+ QDBusPendingReply<ConnmanMapList> reply = call(QLatin1String("GetTechnologies"));
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ Q_FOREACH (ConnmanMap map, reply.value()) {
+ if (!technologiesMap.contains(map.objectPath.path())) {
+ technologyAdded(map.objectPath, map.propertyMap);
+ }
+ }
}
}
- return list;
+ return technologiesMap.keys();
}
QStringList QConnmanManagerInterface::getServices()
{
- QStringList list;
- QDBusReply<ConnmanMapList> replyList = this->call(QLatin1String("GetServices"));
- if (replyList.isValid()) {
- Q_FOREACH (ConnmanMap map, replyList.value()) {
- list << map.objectPath.path();
- }
- } else {
- QVariant var = getProperty("Services");
- if (!var.isNull()) {
- list = qdbus_cast<QStringList>(var);
+ if (servicesList.isEmpty()) {
+ QDBusPendingReply<ConnmanMapList> reply = call(QLatin1String("GetServices"));
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ Q_FOREACH (ConnmanMap map, reply.value()) {
+ servicesList << map.objectPath.path();
+ }
}
}
- return list;
+ return servicesList;
}
-QString QConnmanManagerInterface::getPathForTechnology(const QString &name)
+void QConnmanManagerInterface::requestScan(const QString &type)
{
- foreach (const QString &path, getTechnologies()) {
- if(path.contains(name)) {
- return path;
+ Q_FOREACH (QConnmanTechnologyInterface *tech, technologiesMap) {
+ if (tech->type() == type) {
+ tech->scan();
}
}
- return "";
-}
-
-
-//////////////////////////
-QConnmanProfileInterface::QConnmanProfileInterface(const QString &dbusPathName,QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
- dbusPathName,
- CONNMAN_PROFILE_INTERFACE,
- QDBusConnection::systemBus(), parent)
-{
-}
-
-QConnmanProfileInterface::~QConnmanProfileInterface()
-{
}
-void QConnmanProfileInterface::connectNotify(const QMetaMethod &signal)
+void QConnmanManagerInterface::technologyAdded(const QDBusObjectPath &path, const QVariantMap &)
{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanProfileInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- this->path(),
- QLatin1String(CONNMAN_PROFILE_INTERFACE),
- QLatin1String("PropertyChanged"),
- this,SIGNAL(propertyChanged(QString,QDBusVariant)));
+ if (!technologiesList.contains(path.path())) {
+ technologiesList << path.path();
+ QConnmanTechnologyInterface *tech;
+ tech = new QConnmanTechnologyInterface(path.path(),this);
+ technologiesMap.insert(path.path(),tech);
+ connect(tech,SIGNAL(scanFinished()),this,SIGNAL(scanFinished()));
}
}
-void QConnmanProfileInterface::disconnectNotify(const QMetaMethod &signal)
+void QConnmanManagerInterface::technologyRemoved(const QDBusObjectPath &path)
{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanProfileInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
-
+ if (technologiesList.contains(path.path())) {
+ technologiesList.removeOne(path.path());
+ QConnmanTechnologyInterface * tech = technologiesMap.take(path.path());
+ delete tech;
}
}
-QVariantMap QConnmanProfileInterface::getProperties()
+QConnmanServiceInterface::QConnmanServiceInterface(const QString &dbusPathName,QObject *parent)
+ : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE),
+ dbusPathName,
+ CONNMAN_SERVICE_INTERFACE,
+ QDBusConnection::systemBus(), parent)
{
- QDBusReply<QVariantMap > reply = this->call(QLatin1String("GetProperties"));
- return reply.value();
-}
+ QList<QVariant> argumentList;
+ QDBusPendingReply<QVariantMap> props_reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
-QVariant QConnmanProfileInterface::getProperty(const QString &property)
-{
- QVariant var;
- QVariantMap map = getProperties();
- if (map.contains(property)) {
- var = map.value(property);
- }
- return var;
-}
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(props_reply, this);
-// properties
-QString QConnmanProfileInterface::getName()
-{
+ QObject::connect(watcher,SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(propertiesReply(QDBusPendingCallWatcher*)));
- QVariant var = getProperty("Name");
- return qdbus_cast<QString>(var);
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ path(),
+ QStringLiteral(CONNMAN_SERVICE_INTERFACE),
+ QStringLiteral("PropertyChanged"),
+ this,SLOT(changedProperty(QString,QDBusVariant)));
}
-bool QConnmanProfileInterface::isOfflineMode()
-{
- QVariant var = getProperty("OfflineMode");
- return qdbus_cast<bool>(var);
-}
-
-QStringList QConnmanProfileInterface::getServices()
+QConnmanServiceInterface::~QConnmanServiceInterface()
{
- QVariant var = getProperty("Services");
- return qdbus_cast<QStringList>(var);
}
-
-///////////////////////////
-QConnmanServiceInterface::QConnmanServiceInterface(const QString &dbusPathName,QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
- dbusPathName,
- CONNMAN_SERVICE_INTERFACE,
- QDBusConnection::systemBus(), parent)
+QVariantMap QConnmanServiceInterface::getProperties()
{
+ if (propertiesCacheMap.isEmpty()) {
+ QDBusPendingReply<QVariantMap> reply = call(QLatin1String("GetProperties"));
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ propertiesCacheMap = reply.value();
+ Q_EMIT propertiesReady();
+ }
+ }
+ return propertiesCacheMap;
}
-QConnmanServiceInterface::~QConnmanServiceInterface()
+void QConnmanServiceInterface::propertiesReply(QDBusPendingCallWatcher *call)
{
+ QDBusPendingReply<QVariantMap> props_reply = *call;
+ if (props_reply.isError()) {
+ qDebug() << props_reply.error().message();
+ return;
+ }
+ propertiesCacheMap = props_reply.value();
+ Q_EMIT propertiesReady();
}
void QConnmanServiceInterface::connectNotify(const QMetaMethod &signal)
{
static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChanged);
if (signal == propertyChangedSignal) {
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- this->path(),
- QLatin1String(CONNMAN_SERVICE_INTERFACE),
- QLatin1String("PropertyChanged"),
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ path(),
+ QStringLiteral(CONNMAN_SERVICE_INTERFACE),
+ QStringLiteral("PropertyChanged"),
this,SIGNAL(propertyChanged(QString,QDBusVariant)));
}
- static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChangedContext);
- if (signal == propertyChangedContextSignal) {
- QConnmanDBusHelper *helper;
- helper = new QConnmanDBusHelper(this);
-
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- this->path(),
- QLatin1String(CONNMAN_SERVICE_INTERFACE),
- QLatin1String("PropertyChanged"),
- helper,SLOT(propertyChanged(QString,QDBusVariant)));
-
- QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)),
- this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection);
- }
-}
-
-void QConnmanServiceInterface::disconnectNotify(const QMetaMethod &signal)
-{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
-
- }
}
-QVariantMap QConnmanServiceInterface::getProperties()
+void QConnmanServiceInterface::changedProperty(const QString &name, const QDBusVariant &value)
{
- if(this->isValid()) {
- QDBusReply<QVariantMap> reply = this->call(QLatin1String("GetProperties"));
- return reply.value();
- }
- else
- return QVariantMap();
+ propertiesCacheMap[name] = value.variant();
+ if (name == QStringLiteral("State"))
+ Q_EMIT stateChanged(value.variant().toString());
}
QVariant QConnmanServiceInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
- if (map.contains(property)) {
- var = map.value(property);
- }
+ var = map.value(property);
return var;
}
void QConnmanServiceInterface::connect()
{
- this->asyncCall(QLatin1String("Connect"));
+ asyncCall(QLatin1String("Connect"));
}
void QConnmanServiceInterface::disconnect()
{
- QDBusReply<QVariantMap> reply = this->call(QLatin1String("Disconnect"));
+ asyncCall(QLatin1String("Disconnect"));
}
void QConnmanServiceInterface::remove()
{
- QDBusReply<QVariantMap> reply = this->call(QLatin1String("Remove"));
+ asyncCall(QLatin1String("Remove"));
}
// properties
-QString QConnmanServiceInterface::getState()
+QString QConnmanServiceInterface::state()
{
- QVariant var = getProperty("State");
+ QVariant var = getProperty(QStringLiteral("State"));
return qdbus_cast<QString>(var);
}
-QString QConnmanServiceInterface::getError()
+QString QConnmanServiceInterface::lastError()
{
- QVariant var = getProperty("Error");
+ QVariant var = getProperty(QStringLiteral("Error"));
return qdbus_cast<QString>(var);
}
-QString QConnmanServiceInterface::getName()
+QString QConnmanServiceInterface::name()
{
- QVariant var = getProperty("Name");
+ QVariant var = getProperty(QStringLiteral("Name"));
return qdbus_cast<QString>(var);
}
-QString QConnmanServiceInterface::getType()
+QString QConnmanServiceInterface::type()
{
- QVariant var = getProperty("Type");
+ QVariant var = getProperty(QStringLiteral("Type"));
return qdbus_cast<QString>(var);
}
-QString QConnmanServiceInterface::getMode()
+QString QConnmanServiceInterface::security()
{
- QVariant var = getProperty("Mode");
+ QVariant var = getProperty(QStringLiteral("Security"));
return qdbus_cast<QString>(var);
}
-QString QConnmanServiceInterface::getSecurity()
+bool QConnmanServiceInterface::favorite()
{
- QVariant var = getProperty("Security");
- return qdbus_cast<QString>(var);
-}
-
-QString QConnmanServiceInterface::getPassphrase()
-{
- QVariant var = getProperty("Passphrase");
- return qdbus_cast<QString>(var);
-}
-
-bool QConnmanServiceInterface::isPassphraseRequired()
-{
- QVariant var = getProperty("PassphraseRequired");
- return qdbus_cast<bool>(var);
-}
-
-quint8 QConnmanServiceInterface::getSignalStrength()
-{
- QVariant var = getProperty("Strength");
- return qdbus_cast<quint8>(var);
-}
-
-bool QConnmanServiceInterface::isFavorite()
-{
- QVariant var = getProperty("Favorite");
+ QVariant var = getProperty(QStringLiteral("Favorite"));
return qdbus_cast<bool>(var);
}
-bool QConnmanServiceInterface::isImmutable()
+bool QConnmanServiceInterface::autoConnect()
{
- QVariant var = getProperty("Immutable");
+ QVariant var = getProperty(QStringLiteral("AutoConnect"));
return qdbus_cast<bool>(var);
}
-bool QConnmanServiceInterface::isAutoConnect()
+bool QConnmanServiceInterface::roaming()
{
- QVariant var = getProperty("AutoConnect");
+ QVariant var = getProperty(QStringLiteral("Roaming"));
return qdbus_cast<bool>(var);
}
-bool QConnmanServiceInterface::isSetupRequired()
-{
- QVariant var = getProperty("SetupRequired");
- return qdbus_cast<bool>(var);
-}
-
-QString QConnmanServiceInterface::getAPN()
-{
- QVariant var = getProperty("APN");
- return qdbus_cast<QString>(var);
-}
-
-QString QConnmanServiceInterface::getMCC()
-{
- QVariant var = getProperty("MCC");
- return qdbus_cast<QString>(var);
-}
-
-QString QConnmanServiceInterface::getMNC()
-{
- QVariant var = getProperty("MNC");
- return qdbus_cast<QString>(var);
-}
-
-bool QConnmanServiceInterface::isRoaming()
-{
- QVariant var = getProperty("Roaming");
- return qdbus_cast<bool>(var);
-}
-
-QStringList QConnmanServiceInterface::getNameservers()
-{
- QVariant var = getProperty("NameServers");
- return qdbus_cast<QStringList>(var);
-}
-
-QStringList QConnmanServiceInterface::getDomains()
-{
- QVariant var = getProperty("Domains");
- return qdbus_cast<QStringList>(var);
-}
-
-QVariantMap QConnmanServiceInterface::getIPv4()
+QVariantMap QConnmanServiceInterface::ethernet()
{
- QVariant var = getProperty("IPv4");
+ QVariant var = getProperty(QStringLiteral("Ethernet"));
return qdbus_cast<QVariantMap >(var);
}
-QVariantMap QConnmanServiceInterface::getIPv4Configuration()
-{
- QVariant var = getProperty("IPv4.Configuration");
- return qdbus_cast<QVariantMap >(var);
-}
-
-QVariantMap QConnmanServiceInterface::getProxy()
-{
- QVariant var = getProperty("Proxy");
- return qdbus_cast<QVariantMap >(var);
-}
-
-QVariantMap QConnmanServiceInterface::getEthernet()
-{
- QVariant var = getProperty("Ethernet");
- return qdbus_cast<QVariantMap >(var);
-}
-
-QString QConnmanServiceInterface::getMethod()
-{
- QVariant var;
- QVariantMap map = getEthernet();
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "Method") {
- return it.value().toString();
- }
- }
- return QString();
-}
-
-QString QConnmanServiceInterface::getInterface()
-{
- QVariant var;
- QVariantMap map = getEthernet();
-
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "Interface") {
- return it.value().toString();
- }
- }
-
- return QString();
-}
-
-QString QConnmanServiceInterface::getMacAddress()
-{
- QVariant var;
- QVariantMap map = getEthernet();
-
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "Address") {
- return it.value().toString();
- }
- }
- return QString();
-}
-
-quint16 QConnmanServiceInterface::getMtu()
-{
- quint16 mtu=0;
- QVariant var;
- QVariantMap map = getEthernet();
-
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "MTU") {
- return it.value().toUInt();
- }
- }
- return mtu;
-}
-
-quint16 QConnmanServiceInterface::getSpeed()
+QString QConnmanServiceInterface::serviceInterface()
{
- quint16 speed=0;
- QVariant var;
- QVariantMap map = getEthernet();
-
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "Speed") {
- return it.value().toUInt();
- }
- }
- return speed;
+ QVariantMap map = ethernet();
+ return map.value(QStringLiteral("Interface")).toString();
}
-QString QConnmanServiceInterface::getDuplex()
-{
- QVariant var;
- QVariantMap map = getEthernet();
-
- QMapIterator<QString,QVariant> it(map);
- while(it.hasNext()) {
- it.next();
- if(it.key() == "Duplex") {
- return it.value().toString();
- }
- }
- return QString();
-}
-
-
bool QConnmanServiceInterface::isOfflineMode()
{
- QVariant var = getProperty("OfflineMode");
+ QVariant var = getProperty(QStringLiteral("OfflineMode"));
return qdbus_cast<bool>(var);
}
-QStringList QConnmanServiceInterface::getServices()
+QStringList QConnmanServiceInterface::services()
{
- QVariant var = getProperty("Services");
+ QVariant var = getProperty(QStringLiteral("Services"));
return qdbus_cast<QStringList>(var);
}
-
//////////////////////////
QConnmanTechnologyInterface::QConnmanTechnologyInterface(const QString &dbusPathName,QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
+ : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE),
dbusPathName,
CONNMAN_TECHNOLOGY_INTERFACE,
QDBusConnection::systemBus(), parent)
@@ -791,154 +463,52 @@ void QConnmanTechnologyInterface::connectNotify(const QMetaMethod &signal)
{
static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChanged);
if (signal == propertyChangedSignal) {
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- this->path(),
- QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE),
- QLatin1String("PropertyChanged"),
+ QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE),
+ path(),
+ QStringLiteral(CONNMAN_TECHNOLOGY_INTERFACE),
+ QStringLiteral("PropertyChanged"),
this,SIGNAL(propertyChanged(QString,QDBusVariant)));
}
- static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChangedContext);
- if (signal == propertyChangedContextSignal) {
- QConnmanDBusHelper *helper;
- helper = new QConnmanDBusHelper(this);
-
- QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE),
- this->path(),
- QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE),
- QLatin1String("PropertyChanged"),
- helper,SLOT(propertyChanged(QString,QDBusVariant)));
-
- QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)),
- this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection);
- }
}
-void QConnmanTechnologyInterface::disconnectNotify(const QMetaMethod &signal)
+QVariantMap QConnmanTechnologyInterface::properties()
{
- static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChanged);
- if (signal == propertyChangedSignal) {
-
+ if (propertiesMap.isEmpty()) {
+ QDBusPendingReply<QVariantMap> reply = call(QLatin1String("GetProperties"));
+ reply.waitForFinished();
+ propertiesMap = reply.value();
}
-}
-
-QVariantMap QConnmanTechnologyInterface::getProperties()
-{
- QDBusReply<QVariantMap> reply = this->call(QLatin1String("GetProperties"));
- return reply.value();
+ return propertiesMap;
}
QVariant QConnmanTechnologyInterface::getProperty(const QString &property)
{
QVariant var;
- QVariantMap map = getProperties();
- if (map.contains(property)) {
- var = map.value(property);
- }
+ QVariantMap map = properties();
+ var = map.value(property);
return var;
}
-// properties
-QString QConnmanTechnologyInterface::getState()
-{
- QVariant var = getProperty("State");
- return qdbus_cast<QString>(var);
-}
-
-QString QConnmanTechnologyInterface::getName()
-{
- QVariant var = getProperty("Name");
- return qdbus_cast<QString>(var);
-}
-
-QString QConnmanTechnologyInterface::getType()
+QString QConnmanTechnologyInterface::type()
{
- QVariant var = getProperty("Type");
+ QVariant var = getProperty(QStringLiteral("Type"));
return qdbus_cast<QString>(var);
}
-
-//////////////////////////////////
-QConnmanAgentInterface::QConnmanAgentInterface(const QString &dbusPathName, QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
- dbusPathName,
- CONNMAN_AGENT_INTERFACE,
- QDBusConnection::systemBus(), parent)
-{
-}
-
-QConnmanAgentInterface::~QConnmanAgentInterface()
-{
-}
-
-void QConnmanAgentInterface::connectNotify(const QMetaMethod &signal)
-{
- Q_UNUSED(signal);
-}
-
-void QConnmanAgentInterface::disconnectNotify(const QMetaMethod &signal)
-{
- Q_UNUSED(signal);
-}
-
-
-void QConnmanAgentInterface::release()
-{
-}
-
-void QConnmanAgentInterface::reportError(QDBusObjectPath &/*path*/, const QString &/*error*/)
-{
-}
-
-void QConnmanAgentInterface::cancel()
-{
-}
-
-
-/////////////////////////////////////////
-QConnmanCounterInterface::QConnmanCounterInterface(const QString &dbusPathName,QObject *parent)
- : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE),
- dbusPathName,
- CONNMAN_COUNTER_INTERFACE,
- QDBusConnection::systemBus(), parent)
-{
-}
-
-QConnmanCounterInterface::~QConnmanCounterInterface()
-{
-}
-
-quint32 QConnmanCounterInterface::getReceivedByteCount()
-{
- return 0;
-}
-
-quint32 QConnmanCounterInterface::getTransmittedByteCount()
-{
- return 0;
-}
-
-quint64 QConnmanCounterInterface::getTimeOnline()
-{
- return 0;
-}
-
-/////////////////////////////////////////
-QConnmanDBusHelper::QConnmanDBusHelper(QObject * parent)
- : QObject(parent)
-{
-}
-
-QConnmanDBusHelper::~QConnmanDBusHelper()
+void QConnmanTechnologyInterface::scan()
{
+ QDBusPendingReply<> reply = asyncCall(QLatin1String("Scan"));
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
+ connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(scanReply(QDBusPendingCallWatcher*)));
}
-void QConnmanDBusHelper::propertyChanged(const QString &item, const QDBusVariant &var)
+void QConnmanTechnologyInterface::scanReply(QDBusPendingCallWatcher *call)
{
- QDBusMessage msg = this->message();
- Q_EMIT propertyChangedContext(msg.path() ,item, var);
+ Q_EMIT scanFinished();
+ call->deleteLater();
}
-/////////////////
QT_END_NAMESPACE
#endif // QT_NO_DBUS