Skip to content

Commit

Permalink
Merge pull request #57 from lpotter/master
Browse files Browse the repository at this point in the history
[timed] Fixes JB#29843 Make call to connman async.
  • Loading branch information
lpotter committed Jun 16, 2015
2 parents d338426 + b20d2b3 commit aa591b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/server/ntpcontroller.cpp
Expand Up @@ -25,6 +25,7 @@
#include <QDBusReply>
#include <QDBusVariant>
#include <QDBusServiceWatcher>
#include <QtDBus/QDBusPendingCallWatcher>

#include "../common/log.h"

Expand All @@ -41,8 +42,9 @@ NtpController::NtpController(bool enable, QObject *parent) :
this);
connect(m_connmanWatcher, SIGNAL(serviceRegistered(QString)),
this, SLOT(serviceRegistered()));

enableNtpTimeAdjustment(m_enable);
QDBusInterface connmanInterface(CONNMAN_SERVICE, "/", CONNMAN_INTERFACE, QDBusConnection::systemBus());
if (connmanInterface.isValid())
enableNtpTimeAdjustment(m_enable);
}

void NtpController::enableNtpTimeAdjustment(bool enable)
Expand All @@ -68,7 +70,24 @@ void NtpController::setConnmanProperty(QString key, QString value)
QList<QVariant> arguments;
arguments << key << QVariant::fromValue(QDBusVariant(value));
request.setArguments(arguments);
QDBusReply<void> reply = QDBusConnection::systemBus().call(request);

QDBusPendingReply<void> reply = QDBusConnection::systemBus().asyncCall(request);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);

QObject::connect(watcher,SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(propertiesReply(QDBusPendingCallWatcher*)));
}

void NtpController::serviceRegistered()
{
enableNtpTimeAdjustment(m_enable);
}

void NtpController::propertiesReply(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<void> reply = *call;
call->deleteLater();

if (reply.error().isValid()) {
log_warning("Failed to call %s.%s: %s",
QString(CONNMAN_INTERFACE).toStdString().c_str(),
Expand All @@ -77,12 +96,7 @@ void NtpController::setConnmanProperty(QString key, QString value)
} else {
log_debug("Set %s property %s to value %s",
QString(CONNMAN_INTERFACE).toStdString().c_str(),
key.toStdString().c_str(),
value.toStdString().c_str());
reply.argumentAt(0).toString().toStdString().c_str(),
reply.argumentAt(1).toString().toStdString().c_str());
}
}

void NtpController::serviceRegistered()
{
enableNtpTimeAdjustment(m_enable);
}
2 changes: 2 additions & 0 deletions src/server/ntpcontroller.h
Expand Up @@ -25,6 +25,7 @@
#include <QObject>

class QDBusServiceWatcher;
class QDBusPendingCallWatcher;

class NtpController : public QObject
{
Expand All @@ -36,6 +37,7 @@ class NtpController : public QObject

public slots:
void serviceRegistered();
void propertiesReply(QDBusPendingCallWatcher *call);

private:
void setConnmanProperty(QString key, QString value);
Expand Down

0 comments on commit aa591b5

Please sign in to comment.