From efb33d6494d88c27c8766553b6a963ddf2654458 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Fri, 11 Jul 2014 21:06:39 +0200 Subject: Included Log4Qt in project --- daemon/daemon.pro | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'daemon') diff --git a/daemon/daemon.pro b/daemon/daemon.pro index deadea0..aca65f1 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -9,6 +9,10 @@ QT += bluetooth dbus contacts PKGCONFIG += commhistory-qt5 mlite5 QMAKE_CXXFLAGS += -std=c++0x +LIBS += -L$$OUT_PWD/../ext/Log4Qt/ -llog4qt +QMAKE_RPATHDIR += /usr/share/$$TARGET/lib +INCLUDEPATH += ../ext/Log4Qt/src ../ext/Log4Qt/deploy/include + SOURCES += \ daemon.cpp \ manager.cpp \ @@ -26,11 +30,30 @@ HEADERS += \ dbusconnector.h \ dbusadaptor.h -INSTALLS += target pebbled +OTHER_FILES += \ + org.pebbled.xml \ + ../log4qt-debug.conf \ + ../log4qt-release.conf + +INSTALLS += target pebbled config target.path = /usr/bin pebbled.files = $${TARGET}.service pebbled.path = /usr/lib/systemd/user -OTHER_FILES += org.pebbled.xml +CONFIG(debug, debug|release) { + message(Debug build) + log4qt_demo_config.extra = cp $$PWD/../../log4qt-debug.conf $$OUT_PWD/../../log4qt.conf +} +else { + message(Release build) + log4qt_demo_config.extra = cp $$PWD/../../log4qt-release.conf $$OUT_PWD/../../log4qt.conf +} + +config.files = $$OUT_PWD/../../log4qt.conf +config.path = /usr/share/$$TARGET + +# so QtCreator could find commhistory headers... :-( +INCLUDEPATH += $$[QT_HOST_PREFIX]/include/commhistory-qt5 +INCLUDEPATH += $$[QT_HOST_PREFIX]/include/mlite5 -- cgit v1.2.3 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/daemon.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++ daemon/daemon.pro | 16 +++++----- daemon/dbusconnector.cpp | 12 ++++---- daemon/dbusconnector.h | 2 ++ daemon/manager.cpp | 36 +++++++++++----------- daemon/manager.h | 2 ++ daemon/voicecallhandler.cpp | 11 ++++--- daemon/voicecallhandler.h | 3 +- daemon/voicecallmanager.cpp | 6 ++-- daemon/voicecallmanager.h | 3 +- daemon/watchconnector.cpp | 26 ++++++++-------- daemon/watchconnector.h | 5 +++ ext/ext.pro | 5 --- log4qt-debug.conf | 29 +----------------- log4qt-release.conf | 28 +---------------- 15 files changed, 145 insertions(+), 114 deletions(-) (limited to 'daemon') diff --git a/daemon/daemon.cpp b/daemon/daemon.cpp index ab61171..eba9afa 100644 --- a/daemon/daemon.cpp +++ b/daemon/daemon.cpp @@ -30,6 +30,17 @@ #include #include +#include +#include +#include +#include + +#include "LogManager" +#include "SystemlogAppender" +#include "FileAppender" +#include "helpers/factory.h" +#include "Appender" +#include "PropertyConfigurator" void signalhandler(int sig) { @@ -43,10 +54,74 @@ void signalhandler(int sig) } } +// For some reason exactly SystemLogAppender doesn't have a factory registered in log4qt, +// so in order for it to be instantiatable from .conf file (or even in general?) we declare factory +// right here and will register it in initLoggin() +Log4Qt::Appender *create_system_log_appender() { + return new Log4Qt::SystemLogAppender; +} + +void initLogging() +{ + // Should really be done in log4qt, but somehow it's missing these + Log4Qt::Factory::registerAppender("org.apache.log4j.SystemLogAppender", create_system_log_appender); + + // Sailfish OS-specific locations for the app settings files and app's own files + const QString logConfigFilePath(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).at(0) + + "pebble/log4qt.conf"); + const QString fallbackLogConfigPath("/usr/share/pebble/log4qt.conf"); + + const QString& usedConfigFile = QFile::exists(logConfigFilePath) ? logConfigFilePath : fallbackLogConfigPath; + Log4Qt::PropertyConfigurator::configure(usedConfigFile); + + // Uglyish hack for replacing $XDG_CACHE_HOME with the proper cache directory + // TODO: Implement replacing of $XDG_CACHE_HOME (and other vars?) with the proper values before configuring log4qt + + // Iterate all appenders attached to root logger and whenever a FileAppender (or its descender found), replace + // $XDG_CACHE_HOME with the proper folder name + QList appenders = Log4Qt::LogManager::rootLogger()->appenders(); + QList::iterator i; + QDir pathCreator; + for (i = appenders.begin(); i != appenders.end(); ++i) { + Log4Qt::FileAppender* fa = qobject_cast(*i); + if(fa) { + QString filename = fa->file(); + + // As per March 2014 on emulator QStandardPaths::CacheLocation is /home/nemo/.cache + // while on device it is /home/nemo/.cache/app-name + // both things are fine, logging path will just be a little deeper on device + filename.replace("$XDG_CACHE_HOME", + QStandardPaths::standardLocations(QStandardPaths::CacheLocation).at(0) + ); + // make sure loggin dir exists + QFileInfo fi(filename); + if(!pathCreator.mkpath(fi.path())) { + Log4Qt::LogManager::rootLogger()->error("Failed to create dir for logging: %1", fi.path()); + } + + fa->setFile(filename); + fa->activateOptions(); + } + } + + // For capturing qDebug() and console.log() messages + // Note that console.log() might fail in Sailfish OS device builds. Not sure why, but it seems like + // console.log() exactly in Sailfish OS device release builds doesn't go through the same qDebug() channel + Log4Qt::LogManager::setHandleQtMessages(true); + + qDebug() << "Using following log config file: " << usedConfigFile; + + Log4Qt::Logger::logger(QLatin1String("Main Logger"))->info("Logging started"); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); + // Init logging should be called after app object creation as initLogging() will examine + // QCoreApplication for determining the .conf files locations + initLogging(); + watch::WatchConnector watch; DBusConnector dbus; VoiceCallManager voice; diff --git a/daemon/daemon.pro b/daemon/daemon.pro index aca65f1..9d1a441 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -1,7 +1,6 @@ TARGET = pebbled CONFIG += console -CONFIG -= app_bundle CONFIG += link_pkgconfig QT -= gui @@ -10,7 +9,7 @@ PKGCONFIG += commhistory-qt5 mlite5 QMAKE_CXXFLAGS += -std=c++0x LIBS += -L$$OUT_PWD/../ext/Log4Qt/ -llog4qt -QMAKE_RPATHDIR += /usr/share/$$TARGET/lib +QMAKE_RPATHDIR += /usr/share/pebble/lib INCLUDEPATH += ../ext/Log4Qt/src ../ext/Log4Qt/deploy/include SOURCES += \ @@ -35,7 +34,7 @@ OTHER_FILES += \ ../log4qt-debug.conf \ ../log4qt-release.conf -INSTALLS += target pebbled config +INSTALLS += target pebbled confile lib target.path = /usr/bin @@ -44,15 +43,18 @@ pebbled.path = /usr/lib/systemd/user CONFIG(debug, debug|release) { message(Debug build) - log4qt_demo_config.extra = cp $$PWD/../../log4qt-debug.conf $$OUT_PWD/../../log4qt.conf + confile.extra = cp $$PWD/../log4qt-debug.conf $$OUT_PWD/../log4qt.conf } else { message(Release build) - log4qt_demo_config.extra = cp $$PWD/../../log4qt-release.conf $$OUT_PWD/../../log4qt.conf + confile.extra = cp $$PWD/../log4qt-release.conf $$OUT_PWD/../log4qt.conf } -config.files = $$OUT_PWD/../../log4qt.conf -config.path = /usr/share/$$TARGET +confile.files = $$OUT_PWD/../log4qt.conf +confile.path = /usr/share/pebble + +lib.files += $$OUT_PWD/../ext/Log4Qt/*.s* +lib.path = /usr/share/pebble/lib # so QtCreator could find commhistory headers... :-( INCLUDEPATH += $$[QT_HOST_PREFIX]/include/commhistory-qt5 diff --git a/daemon/dbusconnector.cpp b/daemon/dbusconnector.cpp index e5bed8f..2ad753d 100644 --- a/daemon/dbusconnector.cpp +++ b/daemon/dbusconnector.cpp @@ -25,14 +25,14 @@ bool DBusConnector::findPebble() "org.bluez.Manager", "ListAdapters")); if (not ListAdaptersReply.isValid()) { - qWarning() << ListAdaptersReply.error().message(); + logger()->error() << ListAdaptersReply.error().message(); return false; } QList adapters = ListAdaptersReply.value(); if (adapters.isEmpty()) { - qWarning() << "No BT adapters found"; + logger()->debug() << "No BT adapters found"; return false; } @@ -41,7 +41,7 @@ bool DBusConnector::findPebble() "org.bluez.Adapter", "GetProperties")); if (not AdapterPropertiesReply.isValid()) { - qWarning() << AdapterPropertiesReply.error().message(); + logger()->error() << AdapterPropertiesReply.error().message(); return false; } @@ -57,16 +57,16 @@ bool DBusConnector::findPebble() "org.bluez.Device", "GetProperties")); if (not DevicePropertiesReply.isValid()) { - qWarning() << DevicePropertiesReply.error().message(); + logger()->error() << DevicePropertiesReply.error().message(); continue; } const QVariantMap &dict = DevicePropertiesReply.value(); QString tmp = dict["Name"].toString(); - qDebug() << "Found BT device:" << tmp; + logger()->debug() << "Found BT device:" << tmp; if (tmp.startsWith("Pebble")) { - qDebug() << "Found Pebble:" << tmp; + logger()->debug() << "Found Pebble:" << tmp; pebbleProps = dict; emit pebbleChanged(); return true; diff --git a/daemon/dbusconnector.h b/daemon/dbusconnector.h index e166238..98f6e58 100644 --- a/daemon/dbusconnector.h +++ b/daemon/dbusconnector.h @@ -3,10 +3,12 @@ #include #include +#include "Logger" class DBusConnector : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER Q_PROPERTY(QVariantMap pebble READ pebble NOTIFY pebbleChanged) 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"; } } diff --git a/daemon/manager.h b/daemon/manager.h index 8d3c8de..db0d0d3 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -11,6 +11,7 @@ #include #include #include +#include "Logger" using namespace QtContacts; using namespace CommHistory; @@ -18,6 +19,7 @@ using namespace CommHistory; class Manager : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER friend class PebbledProxy; diff --git a/daemon/voicecallhandler.cpp b/daemon/voicecallhandler.cpp index 1a006f1..c8ffe89 100644 --- a/daemon/voicecallhandler.cpp +++ b/daemon/voicecallhandler.cpp @@ -48,7 +48,7 @@ VoiceCallHandler::VoiceCallHandler(const QString &handlerId, QObject *parent) : QObject(parent), d_ptr(new VoiceCallHandlerPrivate(this, handlerId)) { Q_D(VoiceCallHandler); - qDebug() << QString("Creating D-Bus interface to: ") + handlerId; + logger()->debug() << QString("Creating D-Bus interface to: ") + handlerId; d->interface = new QDBusInterface("org.nemomobile.voicecall", "/calls/" + handlerId, "org.nemomobile.voicecall.VoiceCall", @@ -178,7 +178,8 @@ method return sender=:1.13 -> dest=:1.150 reply_serial=2 QDBusReply reply = props.call("GetAll", d->interface->interface()); if (reply.isValid()) { QVariantMap props = reply.value(); - qDebug() << props; + QString str; QDebug(&str) << props; + logger()->debug() << str; d->providerId = props["providerId"].toString(); d->duration = props["duration"].toInt(); d->status = props["status"].toInt(); @@ -196,7 +197,7 @@ method return sender=:1.13 -> dest=:1.150 reply_serial=2 emit emergencyChanged(); emit forwardedChanged(); } else if (notifyError) { - qWarning() << "Failed to get VoiceCall properties from VCM D-Bus service."; + logger()->error() << "Failed to get VoiceCall properties from VCM D-Bus service."; emit this->error("Failed to get VoiceCall properties from VCM D-Bus service."); } } @@ -413,10 +414,10 @@ void VoiceCallHandler::onPendingCallFinished(QDBusPendingCallWatcher *watcher) QDBusPendingReply reply = *watcher; if (reply.isError()) { - qWarning() << QString::fromLatin1("Received error reply for member: %1 (%2)").arg(reply.reply().member()).arg(reply.error().message()); + logger()->error() << QString::fromLatin1("Received error reply for member: %1 (%2)").arg(reply.reply().member()).arg(reply.error().message()); emit this->error(reply.error().message()); watcher->deleteLater(); } else { - qDebug() << QString::fromLatin1("Received successful reply for member: %1").arg(reply.reply().member()); + logger()->debug() << QString::fromLatin1("Received successful reply for member: %1").arg(reply.reply().member()); } } diff --git a/daemon/voicecallhandler.h b/daemon/voicecallhandler.h index 678d8f8..f96a97a 100644 --- a/daemon/voicecallhandler.h +++ b/daemon/voicecallhandler.h @@ -3,12 +3,13 @@ #include #include - #include +#include "Logger" class VoiceCallHandler : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER Q_ENUMS(VoiceCallStatus) diff --git a/daemon/voicecallmanager.cpp b/daemon/voicecallmanager.cpp index 90a3812..21d3d49 100644 --- a/daemon/voicecallmanager.cpp +++ b/daemon/voicecallmanager.cpp @@ -98,7 +98,7 @@ QString VoiceCallManager::defaultProviderId() const { Q_D(const VoiceCallManager); if(d->providers.count() == 0) { - qWarning() << Q_FUNC_INFO << "No provider added"; + logger()->debug() << Q_FUNC_INFO << "No provider added"; return QString::null; } @@ -288,7 +288,7 @@ void VoiceCallManager::onPendingCallFinished(QDBusPendingCallWatcher *watcher) if (reply.isError()) { emit this->error(reply.error().message()); } else { - qDebug() << QString("Received successful reply for member: ") + reply.reply().member(); + logger()->debug() << QString("Received successful reply for member: ") + reply.reply().member(); } watcher->deleteLater(); @@ -301,7 +301,7 @@ void VoiceCallManager::onPendingSilenceFinished(QDBusPendingCallWatcher *watcher if (reply.isError()) { emit this->error(reply.error().message()); } else { - qDebug() << QString("Received successful reply for member: ") + reply.reply().member(); + logger()->debug() << QString("Received successful reply for member: ") + reply.reply().member(); } watcher->deleteLater(); diff --git a/daemon/voicecallmanager.h b/daemon/voicecallmanager.h index de18781..afb9a11 100644 --- a/daemon/voicecallmanager.h +++ b/daemon/voicecallmanager.h @@ -4,9 +4,9 @@ #include "voicecallhandler.h" #include - #include #include +#include "Logger" class VoiceCallProviderData { @@ -27,6 +27,7 @@ typedef QList VoiceCallHandlerList; class VoiceCallManager : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER Q_PROPERTY(QDBusInterface* interface READ interface) diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index dbcd831..d999229 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -18,10 +18,10 @@ void WatchConnector::deviceDiscovered(const QBluetoothDeviceInfo &device) { //FIXME TODO: Configurable if (device.name().startsWith("Pebble")) { - qDebug() << "Found Pebble:" << device.name() << '(' << device.address().toString() << ')'; + logger()->debug() << "Found Pebble: " << device.name() << " (" << device.address().toString() << ')'; handleWatch(device.name(), device.address().toString()); } else { - qDebug() << "Found other device:" << device.name() << '(' << device.address().toString() << ')'; + logger()->debug() << "Found other device: " << device.name() << " (" << device.address().toString() << ')'; } } @@ -32,7 +32,7 @@ void WatchConnector::deviceConnect(const QString &name, const QString &address) void WatchConnector::reconnect() { - qDebug() << "reconnect" << _last_name; + logger()->debug() << "reconnect " << _last_name; if (!_last_name.isEmpty() && !_last_address.isEmpty()) { deviceConnect(_last_name, _last_address); } @@ -40,14 +40,14 @@ void WatchConnector::reconnect() void WatchConnector::disconnect() { - qDebug() << __FUNCTION__; + logger()->debug() << __FUNCTION__; socket->close(); socket->deleteLater(); } void WatchConnector::handleWatch(const QString &name, const QString &address) { - qDebug() << "handleWatch" << name << address; + logger()->debug() << "handleWatch " << name << " " << address; if (socket != nullptr && socket->isOpen()) { socket->close(); socket->deleteLater(); @@ -58,7 +58,7 @@ void WatchConnector::handleWatch(const QString &name, const QString &address) _last_address = address; if (emit_name) emit nameChanged(); - qDebug() << "Creating socket"; + logger()->debug() << "Creating socket"; socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); connect(socket, SIGNAL(readyRead()), SLOT(onReadSocket())); @@ -128,8 +128,8 @@ void WatchConnector::decodeMsg(QByteArray data) endpoint = (data.at(index) << 8) + data.at(index+1); index += 2; - qDebug() << "Length:" << datalen << " Endpoint:" << decodeEndpoint(endpoint); - qDebug() << "Data:" << data.mid(index).toHex(); + logger()->debug() << "Length:" << datalen << " Endpoint:" << decodeEndpoint(endpoint); + logger()->debug() << "Data:" << data.mid(index).toHex(); if (endpoint == watchPHONE_CONTROL) { if (data.length() >= 5) { if (data.at(4) == callHANGUP) { @@ -141,7 +141,7 @@ void WatchConnector::decodeMsg(QByteArray data) void WatchConnector::onReadSocket() { - qDebug() << "read"; + logger()->debug() << "read"; QBluetoothSocket *socket = qobject_cast(sender()); if (!socket) return; @@ -155,7 +155,7 @@ void WatchConnector::onReadSocket() void WatchConnector::onConnected() { - qDebug() << "Connected!"; + logger()->debug() << "Connected!"; bool was_connected = is_connected; is_connected = true; if (not was_connected) emit connectedChanged(); @@ -163,7 +163,7 @@ void WatchConnector::onConnected() void WatchConnector::onDisconnected() { - qDebug() << "Disconnected!"; + logger()->debug() << "Disconnected!"; bool was_connected = is_connected; is_connected = false; @@ -180,7 +180,7 @@ void WatchConnector::onDisconnected() } void WatchConnector::onError(QBluetoothSocket::SocketError error) { - qWarning() << "Error connecting Pebble" << error << socket->errorString(); + logger()->error() << "Error connecting Pebble: " << error << socket->errorString(); } void WatchConnector::sendData(const QByteArray &data) @@ -192,7 +192,7 @@ void WatchConnector::sendData(const QByteArray &data) void WatchConnector::sendMessage(unsigned int endpoint, QByteArray data) { - qDebug() << "Sending message"; + logger()->debug() << "Sending message"; QByteArray msg; // First send the length diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index eaeccdc..4015870 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -33,9 +33,11 @@ #include #include #include +#include #include #include #include +#include "Logger" using namespace QtBluetooth; @@ -45,8 +47,11 @@ namespace watch class WatchConnector : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER + Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString connected READ isConnected NOTIFY connectedChanged) + public: enum { watchTIME = 11, diff --git a/ext/ext.pro b/ext/ext.pro index 4ab8424..b1879b1 100644 --- a/ext/ext.pro +++ b/ext/ext.pro @@ -2,8 +2,3 @@ # Log4Qt folder is pulled right from the remote repository TEMPLATE = subdirs SUBDIRS = Log4Qt - -lib.files += $$OUT_PWD/../../ext/Log4Qt/*.s* -lib.path = /usr/share/$$TARGET/lib - -INSTALLS += lib diff --git a/log4qt-debug.conf b/log4qt-debug.conf index 52af6e1..974e593 100644 --- a/log4qt-debug.conf +++ b/log4qt-debug.conf @@ -1,42 +1,15 @@ -# Set root logger level. Nothing less important will ever be printed. E.g. TRACE messages will be skipped -# rootLogger will send messages coming to it further to three printing mechanisms: to console, -# syslog and file logger (all three defined below) log4j.rootLogger=DEBUG, consolelog, syslog, filelog -# Define a ConsoleAppender. Colors you are supposed to see on Windows only. Didn't check it myself though -# Console will print everything that gets to rootLogger, i.e. all DEBUG+ messages log4j.appender.consolelog=org.apache.log4j.ColorConsoleAppender -# Use SimpleTimeLayout. log4j.appender.consolelog.layout=org.apache.log4j.SimpleTimeLayout -# Let's not overload syslog and dump only ERROR+ messages to it -# Also no need for SimpleTimeLayout here. journalctl will record timestamp anyway log4j.appender.syslog=org.apache.log4j.SystemLogAppender log4j.appender.syslog.layout=org.apache.log4j.SimpleLayout log4j.appender.syslog.serviceName=journalctl log4j.appender.syslog.threshold=ERROR -# DailyRollingFileAppender will create a new log file every day -# .cache directory can be cleaned by anyone, but as a good developer in the production code you should -# delete too old log files yourself. For example on every app start you could delete logs that are older -# than a couple of months log4j.appender.filelog=org.apache.log4j.DailyRollingFileAppender log4j.appender.filelog.layout=org.apache.log4j.SimpleTimeLayout +log4j.appender.filelog.file=$XDG_CACHE_HOME/pebble.log -# @see in main.cpp how $XDG_CACHE_HOME is replaced with full path -log4j.appender.filelog.file=$XDG_CACHE_HOME/harbour-log4qtdemo.log - -################ -# Class/logger specific thresholds now. -# Ones for which threshold is not specified will use root logger's DEBUG level -# Use stricter levels for loggers that you want to shut up -################ - -# For example Company class is so stable, you only want ERROR+ messages from it -log4j.logger.Company=ERROR -#log4j.logger.bill=WARN - -# console.log() just as qDebug() goes to logger called "Qt" and uses level DEBUG. -# So setting it to INFO would suppress -# console.log() messages # log4j.logger.Qt=INFO diff --git a/log4qt-release.conf b/log4qt-release.conf index 0545429..393f493 100644 --- a/log4qt-release.conf +++ b/log4qt-release.conf @@ -1,19 +1,8 @@ -# In release mode let's log only ERRORs and FATALs to syslog, -# to console and our own log file let's add WARNs as welll, but everything less important we will ignore completely -# -# If more logs will be wanted, user will install increasedLogging package - -# So rootLogger will pass everything WARN+ to all appenders, syslog appender will cut it to ERROR+ later log4j.rootLogger=WARN, consolelog, syslog, filelog -# be a ConsoleAppender. log4j.appender.consolelog=org.apache.log4j.ColorConsoleAppender -# use SimpleTimeLayout. log4j.appender.consolelog.layout=org.apache.log4j.SimpleTimeLayout - -# No need for SimpleTimeLayout here. journalctl will record timestamp anyway -# Let's not overload syslog and dump only ERROR+ messages to it, m log4j.appender.syslog=org.apache.log4j.SystemLogAppender log4j.appender.syslog.layout=org.apache.log4j.SimpleLayout log4j.appender.syslog.serviceName=journalctl @@ -21,21 +10,6 @@ log4j.appender.syslog.threshold=ERROR log4j.appender.filelog=org.apache.log4j.DailyRollingFileAppender log4j.appender.filelog.layout=org.apache.log4j.SimpleTimeLayout +log4j.appender.filelog.file=$XDG_CACHE_HOME/pebble.log -# @see in main.cpp how $XDG_CACHE_HOME is replaced with full path -log4j.appender.filelog.file=$XDG_CACHE_HOME/harbour-log4qtdemo.log - - -################ -# Class/logger specific thresholds now. -# Ones for which threshold is not specified will use root logger's WARN level -# Use stricter levels for loggers that you want to silence even more -################ - -# For example Company class is so stable, you only want ERROR+ messages from it -log4j.logger.Company=ERROR -# log4j.logger.bill=WARN - -# console.log() as qDebug() goes to logger called "Qt" and level DEBUG. So setting it to INFO would suppress -# console.log() messages # log4j.logger.Qt=INFO -- cgit v1.2.3 From c84773de3af76832d15806647d8529c2e5b75257 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Fri, 11 Jul 2014 23:41:27 +0200 Subject: Fixed reconnect on disconnection Reconnection timeut will now raise gradually, to be 1000ms * reconnect attempt. This should help preserve power in the phone, when no Pebble is around. You can speed-up this process by reconnecting manually from manager app or its cover. Also force channel 1 for RFCOMM, as discovery does not work anymore after disconnection. --- app/qml/cover/CoverPage.qml | 1 + app/qml/pages/ManagerPage.qml | 2 +- daemon/watchconnector.cpp | 19 ++++++++++++++----- daemon/watchconnector.h | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) (limited to 'daemon') diff --git a/app/qml/cover/CoverPage.qml b/app/qml/cover/CoverPage.qml index 767799e..186de30 100644 --- a/app/qml/cover/CoverPage.qml +++ b/app/qml/cover/CoverPage.qml @@ -58,6 +58,7 @@ CoverBackground { CoverActionList { id: coverAction + enabled: pebbled.active CoverAction { iconSource: pebbled.connected ? "image://theme/icon-cover-transfers" : "image://theme/icon-cover-sync" diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml index adb1cf4..92d79b1 100644 --- a/app/qml/pages/ManagerPage.qml +++ b/app/qml/pages/ManagerPage.qml @@ -107,7 +107,7 @@ Page { if (pebbled.connected) { pebbled.disconnect(); } else { - pebbled.connect(); + pebbled.reconnect(); } } } diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index d999229..d0fcdad 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -4,11 +4,14 @@ using namespace watch; -static int __reconnect_timeout = 5000; //ms +static int __reconnect_timeout = 1000; //ms WatchConnector::WatchConnector(QObject *parent) : QObject(parent), socket(nullptr), is_connected(false) -{} +{ + reconnectTimer.setSingleShot(true); + connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect())); +} WatchConnector::~WatchConnector() { @@ -43,11 +46,14 @@ void WatchConnector::disconnect() logger()->debug() << __FUNCTION__; socket->close(); socket->deleteLater(); + reconnectTimer.stop(); + logger()->debug() << "Stopped reconnect timer"; } void WatchConnector::handleWatch(const QString &name, const QString &address) { logger()->debug() << "handleWatch " << name << " " << address; + reconnectTimer.stop(); if (socket != nullptr && socket->isOpen()) { socket->close(); socket->deleteLater(); @@ -67,7 +73,7 @@ void WatchConnector::handleWatch(const QString &name, const QString &address) connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onError(QBluetoothSocket::SocketError))); // FIXME: Assuming port 1 (with Pebble) - socket->connectToService(QBluetoothAddress(address), QBluetoothUuid(QBluetoothUuid::SerialPort)); + socket->connectToService(QBluetoothAddress(address), 1); } QString WatchConnector::decodeEndpoint(unsigned int val) @@ -158,6 +164,8 @@ void WatchConnector::onConnected() logger()->debug() << "Connected!"; bool was_connected = is_connected; is_connected = true; + reconnectTimer.stop(); + reconnectTimer.setInterval(0); if (not was_connected) emit connectedChanged(); } @@ -175,8 +183,9 @@ void WatchConnector::onDisconnected() socket->deleteLater(); - // Try to connect again after a timeout - QTimer::singleShot(__reconnect_timeout, this, SLOT(reconnect())); + reconnectTimer.setInterval(reconnectTimer.interval() + __reconnect_timeout); + reconnectTimer.start(); + logger()->debug() << "Will reconnect in " << reconnectTimer.interval() << " ms"; } void WatchConnector::onError(QBluetoothSocket::SocketError error) { diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index 4015870..36d0936 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -130,6 +130,7 @@ private: QPointer socket; bool is_connected; + QTimer reconnectTimer; QString _last_name; QString _last_address; }; -- 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') 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 From 9d03d21ad9affb57d3bad486e92eecd6b2a1df08 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Sat, 12 Jul 2014 02:10:03 +0200 Subject: (Possibly) Fix 'Unknown' call notifications --- daemon/voicecallhandler.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'daemon') diff --git a/daemon/voicecallhandler.cpp b/daemon/voicecallhandler.cpp index c8ffe89..428785f 100644 --- a/daemon/voicecallhandler.cpp +++ b/daemon/voicecallhandler.cpp @@ -66,7 +66,6 @@ VoiceCallHandler::~VoiceCallHandler() void VoiceCallHandler::initialize(bool notifyError) { Q_D(VoiceCallHandler); - bool success = false; /* method return sender=:1.13 -> dest=:1.150 reply_serial=2 @@ -154,24 +153,12 @@ method return sender=:1.13 -> dest=:1.150 reply_serial=2 " */ - if(d->interface->isValid()) - { - success = true; - success &= (bool)QObject::connect(d->interface, SIGNAL(error(QString)), SIGNAL(error(QString))); - success &= (bool)QObject::connect(d->interface, SIGNAL(statusChanged()), SLOT(onStatusChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(lineIdChanged()), SLOT(onLineIdChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(durationChanged()), SLOT(onDurationChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(startedAtChanged()), SLOT(onStartedAtChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(emergencyChanged()), SLOT(onEmergencyChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(multipartyChanged()), SLOT(onMultipartyChanged())); - success &= (bool)QObject::connect(d->interface, SIGNAL(forwardedChanged()), SLOT(onForwardedChanged())); - } - - if(!(d->connected = success)) + if (not d->connected) { QTimer::singleShot(2000, this, SLOT(initialize())); if(notifyError) emit this->error("Failed to connect to VCM D-Bus service."); - } else { + } + else if (d->interface->isValid()) { QDBusInterface props(d->interface->service(), d->interface->path(), "org.freedesktop.DBus.Properties", d->interface->connection()); @@ -196,10 +183,20 @@ method return sender=:1.13 -> dest=:1.150 reply_serial=2 emit multipartyChanged(); emit emergencyChanged(); emit forwardedChanged(); - } else if (notifyError) { + } + else { logger()->error() << "Failed to get VoiceCall properties from VCM D-Bus service."; - emit this->error("Failed to get VoiceCall properties from VCM D-Bus service."); + if (notifyError) emit this->error("Failed to get VoiceCall properties from VCM D-Bus service."); } + + connect(d->interface, SIGNAL(error(QString)), SIGNAL(error(QString))); + connect(d->interface, SIGNAL(statusChanged()), SLOT(onStatusChanged())); + connect(d->interface, SIGNAL(lineIdChanged()), SLOT(onLineIdChanged())); + connect(d->interface, SIGNAL(durationChanged()), SLOT(onDurationChanged())); + connect(d->interface, SIGNAL(startedAtChanged()), SLOT(onStartedAtChanged())); + connect(d->interface, SIGNAL(emergencyChanged()), SLOT(onEmergencyChanged())); + connect(d->interface, SIGNAL(multipartyChanged()), SLOT(onMultipartyChanged())); + connect(d->interface, SIGNAL(forwardedChanged()), SLOT(onForwardedChanged())); } } -- cgit v1.2.3