[telepathy-qt4/master] ClientRegistrar: Added PendingClientOperation that will be used in async methods to allow async replies.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue May 19 06:48:58 PDT 2009


---
 TelepathyQt4/Makefile.am                  |    4 ++
 TelepathyQt4/PendingClientOperation       |   13 +++++
 TelepathyQt4/pending-client-operation.cpp |   72 +++++++++++++++++++++++++++++
 TelepathyQt4/pending-client-operation.h   |   63 +++++++++++++++++++++++++
 TelepathyQt4/pending-operation.h          |    6 +-
 5 files changed, 155 insertions(+), 3 deletions(-)
 create mode 100644 TelepathyQt4/PendingClientOperation
 create mode 100644 TelepathyQt4/pending-client-operation.cpp
 create mode 100644 TelepathyQt4/pending-client-operation.h

diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 2262a7c..fc29170 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -71,6 +71,7 @@ libtelepathy_qt4_la_SOURCES = \
     optional-interface-factory.cpp \
     pending-account.cpp \
     pending-channel.cpp \
+    pending-client-operation.cpp \
     pending-connection.cpp \
     pending-contact-attributes.cpp \
     pending-contacts.cpp \
@@ -123,6 +124,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/file-transfer.moc.hpp \
     _gen/pending-account.moc.hpp \
     _gen/pending-channel.moc.hpp \
+    _gen/pending-client-operation.moc.hpp \
     _gen/pending-connection.moc.hpp \
     _gen/pending-contact-attributes.moc.hpp \
     _gen/pending-contacts.moc.hpp \
@@ -162,6 +164,7 @@ tpqt4include_HEADERS = \
     OptionalInterfaceFactory \
     PendingAccount \
     PendingChannel \
+    PendingClientOperation \
     PendingConnection \
     PendingContacts \
     PendingContactAttributes \
@@ -242,6 +245,7 @@ tpqt4include_HEADERS = \
     optional-interface-factory.h \
     pending-account.h \
     pending-channel.h \
+    pending-client-operation.h \
     pending-connection.h \
     pending-contact-attributes.h \
     pending-contacts.h \
diff --git a/TelepathyQt4/PendingClientOperation b/TelepathyQt4/PendingClientOperation
new file mode 100644
index 0000000..2128ce5
--- /dev/null
+++ b/TelepathyQt4/PendingClientOperation
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_PendingClientOperation_HEADER_GUARD_
+#define _TelepathyQt4_Client_PendingClientOperation_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/pending-client-operation.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/pending-client-operation.cpp b/TelepathyQt4/pending-client-operation.cpp
new file mode 100644
index 0000000..d436bf1
--- /dev/null
+++ b/TelepathyQt4/pending-client-operation.cpp
@@ -0,0 +1,72 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * 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 <TelepathyQt4/PendingClientOperation>
+
+#include "TelepathyQt4/_gen/pending-client-operation.moc.hpp"
+
+namespace Tp
+{
+
+struct PendingClientOperation::Private
+{
+    Private(const QDBusConnection &bus, const QDBusMessage &message)
+        : bus(bus), message(message)
+    {
+    }
+
+    QDBusConnection bus;
+    QDBusMessage message;
+};
+
+PendingClientOperation::PendingClientOperation(const QDBusConnection &bus,
+        const QDBusMessage &message, QObject *parent)
+    : PendingOperation(parent),
+      mPriv(new Private(bus, message))
+{
+    message.setDelayedReply(true);
+}
+
+PendingClientOperation::~PendingClientOperation()
+{
+    delete mPriv;
+}
+
+void PendingClientOperation::setFinished()
+{
+    mPriv->bus.send(mPriv->message.createReply());
+    PendingOperation::setFinished();
+}
+
+void PendingClientOperation::setFinishedWithError(const QString &name,
+        const QString &message)
+{
+    mPriv->bus.send(mPriv->message.createErrorReply(name, message));
+    PendingOperation::setFinishedWithError(name, message);
+}
+
+void PendingClientOperation::setFinishedWithError(const QDBusError &error)
+{
+    mPriv->bus.send(mPriv->message.createErrorReply(error));
+    PendingOperation::setFinishedWithError(error);
+}
+
+} // Tp
diff --git a/TelepathyQt4/pending-client-operation.h b/TelepathyQt4/pending-client-operation.h
new file mode 100644
index 0000000..c1b7282
--- /dev/null
+++ b/TelepathyQt4/pending-client-operation.h
@@ -0,0 +1,63 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * 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 _TelepathyQt4_cli_pending_client_operation_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_pending_client_operation_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/PendingOperation>
+
+#include <QDBusConnection>
+#include <QDBusMessage>
+
+namespace Tp
+{
+
+class PendingClientOperation : public PendingOperation
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(PendingClientOperation)
+
+public:
+    PendingClientOperation(const QDBusConnection &bus,
+            const QDBusMessage &message,
+            QObject *parent);
+    ~PendingClientOperation();
+
+    // overload as public methods so clients (Handler, Approver, Observer) can
+    // call this method when finished processing a async method to send
+    // a reply.
+    void setFinished();
+    void setFinishedWithError(const QString &name, const QString &message);
+    void setFinishedWithError(const QDBusError &error);
+
+private:
+    struct Private;
+    friend struct Private;
+    Private *mPriv;
+};
+
+} // Tp
+
+#endif
diff --git a/TelepathyQt4/pending-operation.h b/TelepathyQt4/pending-operation.h
index f2fba1d..fecf305 100644
--- a/TelepathyQt4/pending-operation.h
+++ b/TelepathyQt4/pending-operation.h
@@ -145,7 +145,7 @@ protected:
      * Record that this pending operation has finished successfully, and
      * emit the #finished() signal next time the event loop runs.
      */
-    void setFinished();
+    virtual void setFinished();
 
     /**
      * Record that this pending operation has finished with an error, and
@@ -154,7 +154,7 @@ protected:
      * \param name A D-Bus error name, which must be non-empty
      * \param message A debugging message
      */
-    void setFinishedWithError(const QString& name, const QString& message);
+    virtual void setFinishedWithError(const QString& name, const QString& message);
 
     /**
      * Record that this pending operation has finished with an error, and
@@ -162,7 +162,7 @@ protected:
      *
      * \param error A QtDBus error
      */
-    void setFinishedWithError(const QDBusError& error);
+    virtual void setFinishedWithError(const QDBusError& error);
 
 private Q_SLOTS:
     void emitFinished();
-- 
1.5.6.5




More information about the telepathy-commits mailing list