From 6a8cdaf2f718fef8a826fd98241050a7d3cbfb3d Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Fri, 11 Jul 2014 23:31:28 +0200 Subject: Use Log4Qt in daemon --- daemon/manager.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'daemon/manager.cpp') diff --git a/daemon/manager.cpp b/daemon/manager.cpp index f25e724..c045c1b 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -32,7 +32,7 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan notification.setImage("icon-system-bluetooth-device"); if (btDevice.isValid()) { - qDebug() << "BT local name:" << btDevice.name(); + logger()->debug() << "BT local name:" << btDevice.name(); connect(dbus, SIGNAL(pebbleChanged()), SLOT(onPebbleChanged())); dbus->findPebble(); } @@ -51,7 +51,7 @@ void Manager::onPebbleChanged() const QVariantMap & pebble = dbus->pebble(); QString name = pebble["Name"].toString(); if (name.isEmpty()) { - qDebug() << "Pebble gone"; + logger()->debug() << "Pebble gone"; } else { watch->deviceConnect(name, pebble["Address"].toString()); } @@ -62,19 +62,19 @@ void Manager::onConnectedChanged() QString message = QString("%1 %2") .arg(watch->name().isEmpty() ? "Pebble" : watch->name()) .arg(watch->isConnected() ? "connected" : "disconnected"); - qDebug() << message; + logger()->debug() << message; if (notification.isPublished()) notification.remove(); notification.setBody(message); if (!notification.publish()) { - qDebug() << "Failed publishing notification"; + logger()->debug() << "Failed publishing notification"; } } void Manager::onActiveVoiceCallChanged() { - qDebug() << "Manager::onActiveVoiceCallChanged()"; + logger()->debug() << "Manager::onActiveVoiceCallChanged()"; VoiceCallHandler* handler = voice->activeVoiceCall(); if (handler) { @@ -87,11 +87,11 @@ void Manager::onActiveVoiceCallStatusChanged() { VoiceCallHandler* handler = voice->activeVoiceCall(); if (!handler) { - qWarning() << "ActiveVoiceCallStatusChanged but no activeVoiceCall??"; + logger()->debug() << "ActiveVoiceCallStatusChanged but no activeVoiceCall??"; return; } - qDebug() << "handlerId:" << handler->handlerId() + logger()->debug() << "handlerId:" << handler->handlerId() << "providerId:" << handler->providerId() << "status:" << handler->status() << "statusText:" << handler->statusText() @@ -99,28 +99,28 @@ void Manager::onActiveVoiceCallStatusChanged() << "incoming:" << handler->isIncoming(); if (!watch->isConnected()) { - qDebug() << "Watch is not connected"; + logger()->debug() << "Watch is not connected"; return; } switch ((VoiceCallHandler::VoiceCallStatus)handler->status()) { case VoiceCallHandler::STATUS_ALERTING: case VoiceCallHandler::STATUS_DIALING: - qDebug() << "Tell outgoing:" << handler->lineId(); + logger()->debug() << "Tell outgoing:" << handler->lineId(); watch->ring(handler->lineId(), findPersonByNumber(handler->lineId()), false); break; case VoiceCallHandler::STATUS_INCOMING: case VoiceCallHandler::STATUS_WAITING: - qDebug() << "Tell incoming:" << handler->lineId(); + logger()->debug() << "Tell incoming:" << handler->lineId(); watch->ring(handler->lineId(), findPersonByNumber(handler->lineId())); break; case VoiceCallHandler::STATUS_NULL: case VoiceCallHandler::STATUS_DISCONNECTED: - qDebug() << "Endphone"; + logger()->debug() << "Endphone"; watch->endPhoneCall(); break; case VoiceCallHandler::STATUS_ACTIVE: - qDebug() << "Startphone"; + logger()->debug() << "Startphone"; watch->startPhoneCall(); break; case VoiceCallHandler::STATUS_HELD: @@ -142,7 +142,7 @@ QString Manager::findPersonByNumber(QString number) void Manager::onVoiceError(const QString &message) { - qWarning() << "Error: " << message; + logger()->error() << "Error: " << message; } void Manager::hangupAll() @@ -155,7 +155,7 @@ void Manager::hangupAll() void Manager::onConversationGroupAdded(GroupObject *group) { if (!group) { - qWarning() << "Got null conversation group"; + logger()->debug() << "Got null conversation group"; return; } @@ -168,7 +168,7 @@ void Manager::onUnreadMessagesChanged() { GroupObject *group = qobject_cast(sender()); if (!group) { - qWarning() << "Got unreadMessagesChanged for null group"; + logger()->debug() << "Got unreadMessagesChanged for null group"; return; } processUnreadMessages(group); @@ -179,10 +179,10 @@ void Manager::processUnreadMessages(GroupObject *group) if (group->unreadMessages()) { QString name = group->contactName(); QString message = group->lastMessageText(); - qDebug() << "Msg:" << message; - qDebug() << "From:" << name; + logger()->debug() << "Msg:" << message; + logger()->debug() << "From:" << name; watch->sendSMSNotification(name.isEmpty()?"Unknown":name, message); } else { - qWarning() << "Got processUnreadMessages for group with no new messages"; + logger()->debug() << "Got processUnreadMessages for group with no new messages"; } } -- cgit v1.2.3 From 4d55e3d01c1c75a979ad6f53ac18648fc90c6934 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Sat, 12 Jul 2014 01:13:04 +0200 Subject: Reworked PebbledInterface DBus handling --- app/pebbledinterface.cpp | 62 +++++++++++++++++++++++++---------------------- app/pebbledinterface.h | 6 +++-- daemon/manager.cpp | 1 - daemon/watchconnector.cpp | 4 +-- 4 files changed, 39 insertions(+), 34 deletions(-) (limited to 'daemon/manager.cpp') diff --git a/app/pebbledinterface.cpp b/app/pebbledinterface.cpp index 390964a..1bd9b50 100644 --- a/app/pebbledinterface.cpp +++ b/app/pebbledinterface.cpp @@ -1,25 +1,28 @@ #include "pebbledinterface.h" QString PebbledInterface::PEBBLED_SYSTEMD_UNIT("pebbled.service"); -QString PebbledInterface::SYSTEMD_UNIT_IFACE("org.freedesktop.systemd1.Unit"); +QString PebbledInterface::PEBBLED_DBUS_SERVICE("org.pebbled"); +QString PebbledInterface::PEBBLED_DBUS_PATH("/"); +QString PebbledInterface::PEBBLED_DBUS_IFACE("org.pebbled"); PebbledInterface::PebbledInterface(QObject *parent) : - QObject(parent), pebbled(0), systemd(0), unitprops(0) + QObject(parent), pebbled(0), systemd(0) { - pebbled = new QDBusInterface("org.pebbled", - "/", - "org.pebbled", - QDBusConnection::sessionBus(), this); - pebbled->connection() - .connect(pebbled->service(), pebbled->path(), pebbled->interface(), - "connectedChanged", this, SIGNAL(connectedChanged())); - pebbled->connection() - .connect(pebbled->service(), pebbled->path(), pebbled->interface(), - "pebbleChanged", this, SLOT(onPebbleChanged())); + QDBusConnection::sessionBus().connect( + PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, + "connectedChanged", this, SIGNAL(connectedChanged())); + + QDBusConnection::sessionBus().connect( + PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, + "pebbleChanged", this, SLOT(onPebbleChanged())); // simulate connected change on active changed - connect(this, SIGNAL(activeChanged()), this, SIGNAL(connectedChanged())); + // as the daemon might not had a chance to send connectedChanged() + connect(this, SIGNAL(activeChanged()), SIGNAL(connectedChanged())); + + pebbled = new QDBusInterface(PEBBLED_DBUS_SERVICE, PEBBLED_DBUS_PATH, PEBBLED_DBUS_IFACE, + QDBusConnection::sessionBus(), this); systemd = new QDBusInterface("org.freedesktop.systemd1", "/org/freedesktop/systemd1", @@ -29,29 +32,30 @@ PebbledInterface::PebbledInterface(QObject *parent) : systemd->call("Subscribe"); QDBusReply unit = systemd->call("LoadUnit", PEBBLED_SYSTEMD_UNIT); - if (not unit.isValid()) { - qWarning() << unit.error().message(); - } else { - unitprops = new QDBusInterface("org.freedesktop.systemd1", - unit.value().path(), - "org.freedesktop.DBus.Properties", - QDBusConnection::sessionBus(), this); + if (unit.isValid()) { + unitPath = unit.value(); + getUnitProperties(); - unitprops->connection() - .connect("org.freedesktop.systemd1", - unitprops->path(), - "org.freedesktop.DBus.Properties", - "PropertiesChanged", - this, - SLOT(onPropertiesChanged(QString,QMap,QStringList)) - ); + QDBusConnection::sessionBus().connect( + "org.freedesktop.systemd1", + unitPath.path(), + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + this, + SLOT(onPropertiesChanged(QString,QMap,QStringList))); + } else { + qWarning() << unit.error().message(); } } void PebbledInterface::getUnitProperties() { - QDBusReply reply = unitprops->call("GetAll", SYSTEMD_UNIT_IFACE); + QDBusMessage request = QDBusMessage::createMethodCall( + "org.freedesktop.systemd1", unitPath.path(), + "org.freedesktop.DBus.Properties", "GetAll"); + request << "org.freedesktop.systemd1.Unit"; + QDBusReply reply = QDBusConnection::sessionBus().call(request); if (reply.isValid()) { QVariantMap newProperties = reply.value(); bool emitEnabledChanged = (properties["UnitFileState"] != newProperties["UnitFileState"]); diff --git a/app/pebbledinterface.h b/app/pebbledinterface.h index eccc766..df9cd3d 100644 --- a/app/pebbledinterface.h +++ b/app/pebbledinterface.h @@ -10,7 +10,9 @@ class PebbledInterface : public QObject Q_OBJECT static QString PEBBLED_SYSTEMD_UNIT; - static QString SYSTEMD_UNIT_IFACE; + static QString PEBBLED_DBUS_SERVICE; + static QString PEBBLED_DBUS_PATH; + static QString PEBBLED_DBUS_IFACE; Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) bool enabled() const; @@ -58,7 +60,7 @@ private slots: private: QDBusInterface *pebbled; QDBusInterface *systemd; - QDBusInterface *unitprops; + QDBusObjectPath unitPath; QVariantMap properties; }; diff --git a/daemon/manager.cpp b/daemon/manager.cpp index c045c1b..8ff6785 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -24,7 +24,6 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan connect(voice, SIGNAL(activeVoiceCallChanged()), SLOT(onActiveVoiceCallChanged())); connect(voice, SIGNAL(error(const QString &)), SLOT(onVoiceError(const QString &))); - // Watch instantiated hangup, follow the orders connect(watch, SIGNAL(hangup()), SLOT(hangupAll())); connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged())); diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index d0fcdad..088384d 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -176,11 +176,11 @@ void WatchConnector::onDisconnected() bool was_connected = is_connected; is_connected = false; + if (was_connected) emit connectedChanged(); + QBluetoothSocket *socket = qobject_cast(sender()); if (!socket) return; - if (was_connected) emit connectedChanged(); - socket->deleteLater(); reconnectTimer.setInterval(reconnectTimer.interval() + __reconnect_timeout); -- cgit v1.2.3