telepathy-qt: debug-receiver: Implement DebugReceiver
Dario Freddi
drf at kemper.freedesktop.org
Mon Jul 2 07:53:54 PDT 2012
Module: telepathy-qt
Branch: master
Commit: 312a7e4779eae969b48d335256e32451a81bc222
URL: http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=312a7e4779eae969b48d335256e32451a81bc222
Author: George Kiagiadakis <george.kiagiadakis at collabora.com>
Date: Sun Dec 11 19:44:42 2011 +0200
debug-receiver: Implement DebugReceiver
---
TelepathyQt/debug-receiver.cpp | 125 +++++++++++++++++++++++++++++++++++++++-
TelepathyQt/debug-receiver.h | 14 +++++
2 files changed, 138 insertions(+), 1 deletions(-)
diff --git a/TelepathyQt/debug-receiver.cpp b/TelepathyQt/debug-receiver.cpp
index 62237ab..a4fbf4b 100644
--- a/TelepathyQt/debug-receiver.cpp
+++ b/TelepathyQt/debug-receiver.cpp
@@ -24,13 +24,122 @@
#include "TelepathyQt/_gen/cli-debug-receiver-body.hpp"
#include "TelepathyQt/_gen/cli-debug-receiver.moc.hpp"
+#include <TelepathyQt/debug-internal.h>
+#include <TelepathyQt/ReadinessHelper>
+#include <TelepathyQt/PendingVariantMap>
+#include <TelepathyQt/PendingDebugMessageList>
+
namespace Tp
{
struct TP_QT_NO_EXPORT DebugReceiver::Private
{
+ Private(DebugReceiver *parent);
+
+ static void introspectCore(Private *self);
+ static void introspectMonitor(Private *self);
+
+ DebugReceiver *parent;
+ Client::DebugInterface *baseInterface;
+ ReadinessHelper *readinessHelper;
+
+ bool newDebugMessageEnabled;
+ bool enabledByUs;
};
+DebugReceiver::Private::Private(DebugReceiver *parent)
+ : parent(parent),
+ baseInterface(new Client::DebugInterface(parent)),
+ readinessHelper(parent->readinessHelper()),
+ newDebugMessageEnabled(false),
+ enabledByUs(false)
+{
+ ReadinessHelper::Introspectables introspectables;
+
+ ReadinessHelper::Introspectable introspectableCore(
+ QSet<uint>() << 0, // makesSenseForStatuses
+ Features(), // dependsOnFeatures (core)
+ QStringList(), // dependsOnInterfaces
+ (ReadinessHelper::IntrospectFunc) &DebugReceiver::Private::introspectCore,
+ this);
+ introspectables[DebugReceiver::FeatureCore] = introspectableCore;
+
+ ReadinessHelper::Introspectable introspectableMonitor(
+ QSet<uint>() << 0, // makesSenseForStatuses
+ Features() << DebugReceiver::FeatureCore, // dependsOnFeatures (core)
+ QStringList(), // dependsOnInterfaces
+ (ReadinessHelper::IntrospectFunc) &DebugReceiver::Private::introspectMonitor,
+ this);
+ introspectables[DebugReceiver::FeatureMonitor] = introspectableMonitor;
+
+ readinessHelper->addIntrospectables(introspectables);
+}
+
+
+void DebugReceiver::Private::introspectCore(DebugReceiver::Private *self)
+{
+ //this is done mostly to verify that the object exists...
+ PendingVariantMap *op = self->baseInterface->requestAllProperties();
+ self->parent->connect(op,
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onRequestAllPropertiesFinished(Tp::PendingOperation*)));
+}
+
+void DebugReceiver::onRequestAllPropertiesFinished(Tp::PendingOperation *op)
+{
+ if (op->isError()) {
+ mPriv->readinessHelper->setIntrospectCompleted(
+ FeatureCore, false, op->errorName(), op->errorMessage());
+ } else {
+ PendingVariantMap *pvm = qobject_cast<PendingVariantMap*>(op);
+ mPriv->newDebugMessageEnabled = pvm->result()[QLatin1String("Enabled")].toBool();
+ mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, true);
+ }
+}
+
+
+void DebugReceiver::Private::introspectMonitor(DebugReceiver::Private *self)
+{
+ if (!self->newDebugMessageEnabled) {
+ PendingOperation *op = self->baseInterface->setPropertyEnabled(true);
+ self->parent->connect(op,
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onSetPropertyEnabledFinished(Tp::PendingOperation*)));
+ } else {
+ self->parent->connect(self->baseInterface,
+ SIGNAL(NewDebugMessage(double,QString,uint,QString)),
+ SLOT(onNewDebugMessage(double,QString,uint,QString)));
+
+ self->readinessHelper->setIntrospectCompleted(FeatureMonitor, true);
+ }
+}
+
+void DebugReceiver::onSetPropertyEnabledFinished(Tp::PendingOperation *op)
+{
+ if (op->isError()) {
+ mPriv->readinessHelper->setIntrospectCompleted(
+ FeatureMonitor, false, op->errorName(), op->errorMessage());
+ } else {
+ debug() << "DebugReceiver: Enabled emission of NewDebugMessage";
+ mPriv->newDebugMessageEnabled = true;
+ mPriv->enabledByUs = true;
+ Private::introspectMonitor(mPriv);
+ }
+}
+
+void DebugReceiver::onNewDebugMessage(double time, const QString &domain,
+ uint level, const QString &message)
+{
+ DebugMessage msg;
+ msg.timestamp = time;
+ msg.domain = domain;
+ msg.level = level;
+ msg.message = message;
+
+ Q_EMIT newDebugMessage(msg);
+}
+
+
/**
* Feature representing the core that needs to become ready to make the DebugReceiver
* object usable.
@@ -43,6 +152,9 @@ struct TP_QT_NO_EXPORT DebugReceiver::Private
*/
const Feature DebugReceiver::FeatureCore = Feature(QLatin1String(DebugReceiver::staticMetaObject.className()), 0, true);
+const Feature DebugReceiver::FeatureMonitor = Feature(QLatin1String(DebugReceiver::staticMetaObject.className()), 1);
+
+
DebugReceiverPtr DebugReceiver::create(const QString &busName, const QDBusConnection &bus)
{
return DebugReceiverPtr(new DebugReceiver(bus, busName,
@@ -55,14 +167,25 @@ DebugReceiver::DebugReceiver(const QDBusConnection &bus,
const QString &objectPath,
const Feature &featureCore)
: StatefulDBusProxy(bus, busName, objectPath, featureCore),
- mPriv(new Private)
+ mPriv(new Private(this))
{
}
DebugReceiver::~DebugReceiver()
{
+//TODO somehow we have to deal with this shitty spec....
+// if (isValid() && mPriv->enabledByUs) {
+// debug() << "DebugReceiver: Disabling emission of NewDebugMessage";
+// (void) mPriv->baseInterface->setPropertyEnabled(false);
+// }
delete mPriv;
}
+PendingDebugMessageList *DebugReceiver::fetchMessages() const
+{
+ return new PendingDebugMessageList(
+ mPriv->baseInterface->GetMessages(),
+ DebugReceiverPtr(const_cast<DebugReceiver*>(this)));
+}
}
diff --git a/TelepathyQt/debug-receiver.h b/TelepathyQt/debug-receiver.h
index eef771a..c597176 100644
--- a/TelepathyQt/debug-receiver.h
+++ b/TelepathyQt/debug-receiver.h
@@ -34,23 +34,37 @@
namespace Tp
{
+class PendingDebugMessageList;
+
class TP_QT_EXPORT DebugReceiver : public StatefulDBusProxy
{
Q_OBJECT
Q_DISABLE_COPY(DebugReceiver)
public:
static const Feature FeatureCore;
+ static const Feature FeatureMonitor;
static DebugReceiverPtr create(const QString &busName,
const QDBusConnection &bus = QDBusConnection::sessionBus());
virtual ~DebugReceiver();
+ PendingDebugMessageList *fetchMessages() const;
+
+Q_SIGNALS:
+ void newDebugMessage(const Tp::DebugMessage & message);
+
protected:
DebugReceiver(const QDBusConnection &bus,
const QString &busName,
const QString &objectPath,
const Feature &featureCore);
+private Q_SLOTS:
+ TP_QT_NO_EXPORT void onRequestAllPropertiesFinished(Tp::PendingOperation *op);
+ TP_QT_NO_EXPORT void onSetPropertyEnabledFinished(Tp::PendingOperation *op);
+ TP_QT_NO_EXPORT void onNewDebugMessage(double time, const QString &domain,
+ uint level, const QString &message);
+
private:
struct Private;
friend struct Private;
More information about the telepathy-commits
mailing list