diff options
author | Alexandr Akulich <akulichalexander@gmail.com> | 2016-03-02 10:09:55 +0500 |
---|---|---|
committer | Alexandr Akulich <akulichalexander@gmail.com> | 2016-05-05 17:03:08 +0500 |
commit | 5d879e3c16838380ace1c3a665dffa2e3d7fc556 (patch) | |
tree | d36ea048a550a8602003095e6dca9eac48e055b1 | |
parent | db217f2e3bda97a6acf4c803efd0b887a85d382c (diff) |
Added service-side Debug Interface implementation.
-rw-r--r-- | TelepathyQt/BaseDebug | 12 | ||||
-rw-r--r-- | TelepathyQt/CMakeLists.txt | 10 | ||||
-rw-r--r-- | TelepathyQt/base-debug-internal.h | 58 | ||||
-rw-r--r-- | TelepathyQt/base-debug.cpp | 148 | ||||
-rw-r--r-- | TelepathyQt/base-debug.h | 71 | ||||
-rw-r--r-- | TelepathyQt/svc-debug.xml | 9 |
6 files changed, 307 insertions, 1 deletions
diff --git a/TelepathyQt/BaseDebug b/TelepathyQt/BaseDebug new file mode 100644 index 00000000..3cb79f19 --- /dev/null +++ b/TelepathyQt/BaseDebug @@ -0,0 +1,12 @@ +#ifndef _TelepathyQt_BaseDebug_HEADER_GUARD_ +#define _TelepathyQt_BaseDebug_HEADER_GUARD_ + +#ifndef IN_TP_QT_HEADER +#define IN_TP_QT_HEADER +#endif + +#include <TelepathyQt/base-debug.h> + +#undef IN_TP_QT_HEADER + +#endif // _TelepathyQt_BaseDebug_HEADER_GUARD_ diff --git a/TelepathyQt/CMakeLists.txt b/TelepathyQt/CMakeLists.txt index 096cc64f..f79c6b95 100644 --- a/TelepathyQt/CMakeLists.txt +++ b/TelepathyQt/CMakeLists.txt @@ -861,6 +861,7 @@ if(ENABLE_SERVICE_SUPPORT) base-connection-manager.cpp base-connection.cpp base-channel.cpp + base-debug.cpp base-protocol.cpp dbus-error.cpp dbus-object.cpp @@ -881,6 +882,8 @@ if(ENABLE_SERVICE_SUPPORT) base-connection.h BaseChannel base-channel.h + BaseDebug + base-debug.h BaseProtocol BaseProtocolAddressingInterface BaseProtocolAvatarsInterface @@ -915,6 +918,8 @@ if(ENABLE_SERVICE_SUPPORT) base-channel-internal.h base-connection.h base-connection-internal.h + base-debug.h + base-debug-internal.h base-protocol.h base-protocol-internal.h dbus-object.h @@ -927,7 +932,9 @@ if(ENABLE_SERVICE_SUPPORT) svc-channel svc-call svc-connection - svc-connection-manager) + svc-connection-manager + svc-debug + ) foreach(spec ${SPECS}) tpqt_xincludator(${spec}-spec-xincludator ${CMAKE_CURRENT_SOURCE_DIR}/${spec}.xml ${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml DEPENDS stable-typesgen) @@ -944,6 +951,7 @@ if(ENABLE_SERVICE_SUPPORT) tpqt_service_generator(svc-call servicecall Channel Tp::Service DEPENDS svc-call-spec-xincludator) tpqt_service_generator(svc-connection serviceconn Connection Tp::Service DEPENDS svc-connection-spec-xincludator) tpqt_service_generator(svc-connection-manager servicecm ConnectionManager Tp::Service DEPENDS svc-connection-manager-spec-xincludator) + tpqt_service_generator(svc-debug servicecm Debug Tp::Service DEPENDS svc-debug-spec-xincludator) if (TARGET doxygen-doc) add_dependencies(doxygen-doc all-generated-service-sources) diff --git a/TelepathyQt/base-debug-internal.h b/TelepathyQt/base-debug-internal.h new file mode 100644 index 00000000..514629c7 --- /dev/null +++ b/TelepathyQt/base-debug-internal.h @@ -0,0 +1,58 @@ +/** + * This file is part of TelepathyQt + * + * @copyright Copyright (C) 2016 Alexandr Akulich <akulichalexander@gmail.com> + * @license LGPL 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "TelepathyQt/_gen/svc-debug.h" + +#include <TelepathyQt/MethodInvocationContext> + +#include <QObject> +#include <QString> +#include <QStringList> +#include <QVariantMap> + +namespace Tp +{ + +class TP_QT_NO_EXPORT BaseDebug::Adaptee : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) + +public: + Adaptee(const QDBusConnection &dbusConnection, BaseDebug *interface); + + bool isEnabled(); + +Q_SIGNALS: + void newDebugMessage(double time, const QString& domain, uint level, const QString& message); + +public Q_SLOTS: + void setEnabled(bool enabled); + +private Q_SLOTS: + void getMessages( + const Tp::Service::DebugAdaptor::GetMessagesContextPtr &context); + +public: + BaseDebug *mInterface; +}; + +} diff --git a/TelepathyQt/base-debug.cpp b/TelepathyQt/base-debug.cpp new file mode 100644 index 00000000..929759da --- /dev/null +++ b/TelepathyQt/base-debug.cpp @@ -0,0 +1,148 @@ +/** + * This file is part of TelepathyQt + * + * @copyright Copyright (C) 2016 Alexandr Akulich <akulichalexander@gmail.com> + * @license LGPL 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <TelepathyQt/BaseDebug> +#include "TelepathyQt/base-debug-internal.h" + +#include <TelepathyQt/DBusObject> + +#include "TelepathyQt/_gen/base-debug.moc.hpp" +#include "TelepathyQt/_gen/base-debug-internal.moc.hpp" + +namespace Tp +{ + +struct TP_QT_NO_EXPORT BaseDebug::Private +{ + Private(BaseDebug *parent, const QDBusConnection &dbusConnection) + : parent(parent), + enabled(false), + adaptee(new BaseDebug::Adaptee(dbusConnection, parent)) + { + } + + BaseDebug *parent; + bool enabled; + GetMessagesCallback getMessageCB; + BaseDebug::Adaptee *adaptee; +}; + +BaseDebug::Adaptee::Adaptee(const QDBusConnection &dbusConnection, BaseDebug *interface) + : QObject(interface), + mInterface(interface) +{ + (void) new Service::DebugAdaptor(dbusConnection, this, interface->dbusObject()); +} + +bool BaseDebug::Adaptee::isEnabled() +{ + return mInterface->isEnabled(); +} + +void BaseDebug::Adaptee::setEnabled(bool enabled) +{ + mInterface->mPriv->enabled = enabled; +} + +void BaseDebug::Adaptee::getMessages(const Service::DebugAdaptor::GetMessagesContextPtr &context) +{ + DBusError error; + DebugMessageList messages = mInterface->getMessages(&error); + + if (error.isValid()) { + context->setFinishedWithError(error.name(), error.message()); + return; + } + context->setFinished(messages); +} + +BaseDebug::BaseDebug(const QDBusConnection &dbusConnection) : + DBusService(dbusConnection), + mPriv(new Private(this, dbusConnection)) +{ +} + +bool BaseDebug::isEnabled() const +{ + return mPriv->enabled; +} + +void BaseDebug::setGetMessagesCallback(const BaseDebug::GetMessagesCallback &cb) +{ + mPriv->getMessageCB = cb; +} + +DebugMessageList BaseDebug::getMessages(Tp::DBusError *error) const +{ + if (!mPriv->getMessageCB.isValid()) { + error->set(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); + return DebugMessageList(); + } + + return mPriv->getMessageCB(error); +} + +void BaseDebug::setEnabled(bool enabled) +{ + mPriv->enabled = enabled; +} + +void BaseDebug::newDebugMessage(const QString &domain, DebugLevel level, const QString &message) +{ + qint64 msec = QDateTime::currentMSecsSinceEpoch(); + double time = msec / 1000 + (msec % 1000 / 1000.0); + + newDebugMessage(time, domain, level, message); +} + +void BaseDebug::newDebugMessage(double time, const QString &domain, DebugLevel level, const QString &message) +{ + if (!isEnabled()) { + return; + } + + QMetaObject::invokeMethod(mPriv->adaptee, "newDebugMessage", + Q_ARG(double, time), Q_ARG(QString, domain), + Q_ARG(uint, level), Q_ARG(QString, message)); //Can simply use emit in Qt5 +} + +QVariantMap BaseDebug::immutableProperties() const +{ + // There is no immutable properties. + return QVariantMap(); +} + +bool BaseDebug::registerObject(Tp::DBusError *error) +{ + if (isRegistered()) { + return true; + } + + DBusError _error; + bool ret = DBusService::registerObject(TP_QT_IFACE_DEBUG, TP_QT_DEBUG_OBJECT_PATH, &_error); + + if (!ret && error) { + error->set(_error.name(), _error.message()); + } + return ret; +} + +} diff --git a/TelepathyQt/base-debug.h b/TelepathyQt/base-debug.h new file mode 100644 index 00000000..14f137a9 --- /dev/null +++ b/TelepathyQt/base-debug.h @@ -0,0 +1,71 @@ +/** + * This file is part of TelepathyQt + * + * @copyright Copyright (C) 2016 Alexandr Akulich <akulichalexander@gmail.com> + * @license LGPL 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _TelepathyQt_base_debug_h_HEADER_GUARD_ +#define _TelepathyQt_base_debug_h_HEADER_GUARD_ + +#ifndef IN_TP_QT_HEADER +#error IN_TP_QT_HEADER +#endif + +#include <TelepathyQt/Callbacks> +#include <TelepathyQt/Constants> +#include <TelepathyQt/DBusService> +#include <TelepathyQt/Global> +#include <TelepathyQt/Types> + +namespace Tp +{ + +class TP_QT_EXPORT BaseDebug : public DBusService +{ + Q_OBJECT +public: + explicit BaseDebug(const QDBusConnection &dbusConnection = QDBusConnection::sessionBus()); + + bool isEnabled() const; + + typedef Callback1<DebugMessageList, DBusError*> GetMessagesCallback; + void setGetMessagesCallback(const GetMessagesCallback &cb); + + DebugMessageList getMessages(DBusError *error) const; + +public Q_SLOTS: + void setEnabled(bool enabled); + + void newDebugMessage(const QString &domain, DebugLevel level, const QString &message); + void newDebugMessage(double time, const QString &domain, DebugLevel level, const QString &message); + + QVariantMap immutableProperties() const; + + bool registerObject(DBusError *error = NULL); + +protected: + class Adaptee; + friend class Adaptee; + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // namespace Tp + +#endif // _TelepathyQt_base_debug_h_HEADER_GUARD_ diff --git a/TelepathyQt/svc-debug.xml b/TelepathyQt/svc-debug.xml new file mode 100644 index 00000000..c4312f9b --- /dev/null +++ b/TelepathyQt/svc-debug.xml @@ -0,0 +1,9 @@ +<tp:spec + xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" + xmlns:xi="http://www.w3.org/2001/XInclude"> + +<tp:title>Debug interfaces</tp:title> + +<xi:include href="../spec/Debug.xml"/> + +</tp:spec> |