summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Freddi <dario.freddi@collabora.com>2011-11-03 17:56:36 +0100
committerDario Freddi <dario.freddi@collabora.com>2012-07-03 11:11:21 +0200
commitcbe223d583136d68edea17a7e420dbd991fdb9cc (patch)
tree64a653977038b7ec13ae1fc61fdc7ebc916c17cd
parent3ad1c46263cd4a0e11dbfcaf33c78c96bfe9e883 (diff)
dbus-tubes: Rename to PendingDBusTubeConnection
-rw-r--r--TelepathyQt/CMakeLists.txt8
-rw-r--r--TelepathyQt/PendingDBusTube13
-rw-r--r--TelepathyQt/PendingDBusTubeConnection13
-rw-r--r--TelepathyQt/dbus-tube-channel.h2
-rw-r--r--TelepathyQt/incoming-dbus-tube-channel.cpp20
-rw-r--r--TelepathyQt/incoming-dbus-tube-channel.h4
-rw-r--r--TelepathyQt/outgoing-dbus-tube-channel.cpp16
-rw-r--r--TelepathyQt/outgoing-dbus-tube-channel.h4
-rw-r--r--TelepathyQt/pending-dbus-tube-connection.cpp205
-rw-r--r--TelepathyQt/pending-dbus-tube-connection.h71
10 files changed, 316 insertions, 40 deletions
diff --git a/TelepathyQt/CMakeLists.txt b/TelepathyQt/CMakeLists.txt
index 0e3549cb..7577be98 100644
--- a/TelepathyQt/CMakeLists.txt
+++ b/TelepathyQt/CMakeLists.txt
@@ -94,7 +94,7 @@ set(telepathy_qt_SRCS
pending-contact-attributes.cpp
pending-contact-info.cpp
pending-contacts.cpp
- pending-dbus-tube.cpp
+ pending-dbus-tube-connection.cpp
pending-debug-message-list.cpp
pending-handles.cpp
pending-operation.cpp
@@ -401,8 +401,8 @@ set(telepathy_qt_HEADERS
pending-contact-info.h
PendingContacts
pending-contacts.h
- PendingDBusTube
- pending-dbus-tube.h
+ PendingDBusTubeConnection
+ pending-dbus-tube-connection.h
PendingDebugMessageList
pending-debug-message-list.h
PendingFailure
@@ -580,7 +580,7 @@ set(telepathy_qt_MOC_SRCS
pending-contact-info.h
pending-contacts.h
pending-contacts-internal.h
- pending-dbus-tube.h
+ pending-dbus-tube-connection.h
pending-debug-message-list.h
pending-handles.h
pending-operation.h
diff --git a/TelepathyQt/PendingDBusTube b/TelepathyQt/PendingDBusTube
deleted file mode 100644
index dabe1aa0..00000000
--- a/TelepathyQt/PendingDBusTube
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _TelepathyQt_PendingDBusTube_HEADER_GUARD_
-#define _TelepathyQt_PendingDBusTube_HEADER_GUARD_
-
-#ifndef IN_TP_QT_HEADER
-#define IN_TP_QT_HEADER
-#endif
-
-#include <TelepathyQt/pending-dbus-tube.h>
-
-#undef IN_TP_QT_HEADER
-
-#endif
-// vim:set ft=cpp:
diff --git a/TelepathyQt/PendingDBusTubeConnection b/TelepathyQt/PendingDBusTubeConnection
new file mode 100644
index 00000000..301e5dc4
--- /dev/null
+++ b/TelepathyQt/PendingDBusTubeConnection
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt_PendingDBusTubeConnection_HEADER_GUARD_
+#define _TelepathyQt_PendingDBusTubeConnection_HEADER_GUARD_
+
+#ifndef IN_TP_QT_HEADER
+#define IN_TP_QT_HEADER
+#endif
+
+#include <TelepathyQt/pending-dbus-tube-connection.h>
+
+#undef IN_TP_QT_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt/dbus-tube-channel.h b/TelepathyQt/dbus-tube-channel.h
index d00f89a8..5f817f8f 100644
--- a/TelepathyQt/dbus-tube-channel.h
+++ b/TelepathyQt/dbus-tube-channel.h
@@ -72,7 +72,7 @@ private Q_SLOTS:
private:
struct Private;
- friend struct PendingDBusTube;
+ friend struct PendingDBusTubeConnection;
friend struct Private;
Private *mPriv;
diff --git a/TelepathyQt/incoming-dbus-tube-channel.cpp b/TelepathyQt/incoming-dbus-tube-channel.cpp
index cad3a5f2..7a8d1be3 100644
--- a/TelepathyQt/incoming-dbus-tube-channel.cpp
+++ b/TelepathyQt/incoming-dbus-tube-channel.cpp
@@ -26,7 +26,7 @@
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>
-#include <TelepathyQt/PendingDBusTube>
+#include <TelepathyQt/PendingDBusTubeConnection>
#include <TelepathyQt/PendingString>
#include <TelepathyQt/Types>
@@ -119,12 +119,12 @@ IncomingDBusTubeChannel::Private::~Private()
* Once your object is ready, you can use #acceptTube to accept the tube and create a brand
* new private DBus connection.
*
- * The returned PendingDBusTube serves both for monitoring the state of the tube and for
+ * The returned PendingDBusTubeConnection serves both for monitoring the state of the tube and for
* obtaining, upon success, the address of the new connection.
* When the operation finishes, you can do:
*
* \code
- * void MyTubeReceiver::onDBusTubeAccepted(PendingDBusTube *op)
+ * void MyTubeReceiver::onDBusTubeAccepted(PendingDBusTubeConnection *op)
* {
* if (op->isError()) {
* return;
@@ -187,17 +187,17 @@ IncomingDBusTubeChannel::~IncomingDBusTubeChannel()
*
* Once called, this method will try opening the tube, and will create a new private DBus connection
* which can be used to communicate with the other end. You can then
- * retrieve the address either from \c PendingDBusTube or from %address().
+ * retrieve the address either from \c PendingDBusTubeConnection or from %address().
*
* This method requires DBusTubeChannel::FeatureDBusTube to be enabled.
*
* \param requireCredentials Whether the server should require an SCM_CREDENTIALS message
* upon connection.
*
- * \return A %PendingDBusTube which will finish as soon as the tube is ready to be used
+ * \return A %PendingDBusTubeConnection which will finish as soon as the tube is ready to be used
* (hence in the Open state)
*/
-PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
+PendingDBusTubeConnection *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
{
SocketAccessControl accessControl = requireCredentials ?
SocketAccessControlCredentials :
@@ -206,14 +206,14 @@ PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
if (!isReady(DBusTubeChannel::FeatureDBusTube)) {
warning() << "DBusTubeChannel::FeatureDBusTube must be ready before "
"calling offerTube";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel not ready"), IncomingDBusTubeChannelPtr(this));
}
// The tube must be in local pending state
if (state() != TubeChannelStateLocalPending) {
warning() << "You can accept tubes only when they are in LocalPending state";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel busy"), IncomingDBusTubeChannelPtr(this));
}
@@ -221,7 +221,7 @@ PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
if (requireCredentials && !supportsCredentials()) {
warning() << "You requested an access control "
"not supported by this channel";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
QLatin1String("The requested access control is not supported"),
IncomingDBusTubeChannelPtr(this));
}
@@ -246,7 +246,7 @@ PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
accessControl),
IncomingDBusTubeChannelPtr(this));
- PendingDBusTube *op = new PendingDBusTube(ps, requireCredentials,
+ PendingDBusTubeConnection *op = new PendingDBusTubeConnection(ps, requireCredentials,
credentialByte, IncomingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/incoming-dbus-tube-channel.h b/TelepathyQt/incoming-dbus-tube-channel.h
index d297faa4..5bbd8456 100644
--- a/TelepathyQt/incoming-dbus-tube-channel.h
+++ b/TelepathyQt/incoming-dbus-tube-channel.h
@@ -29,7 +29,7 @@
namespace Tp {
-class PendingDBusTube;
+class PendingDBusTubeConnection;
class TP_QT_EXPORT IncomingDBusTubeChannel : public DBusTubeChannel
{
@@ -42,7 +42,7 @@ public:
virtual ~IncomingDBusTubeChannel();
- PendingDBusTube *acceptTube(bool requireCredentials = false);
+ PendingDBusTubeConnection *acceptTube(bool requireCredentials = false);
protected:
IncomingDBusTubeChannel(const ConnectionPtr &connection, const QString &objectPath,
diff --git a/TelepathyQt/outgoing-dbus-tube-channel.cpp b/TelepathyQt/outgoing-dbus-tube-channel.cpp
index a2e036b2..17862436 100644
--- a/TelepathyQt/outgoing-dbus-tube-channel.cpp
+++ b/TelepathyQt/outgoing-dbus-tube-channel.cpp
@@ -26,7 +26,7 @@
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>
-#include <TelepathyQt/PendingDBusTube>
+#include <TelepathyQt/PendingDBusTubeConnection>
#include <TelepathyQt/PendingString>
#include <TelepathyQt/Types>
@@ -151,7 +151,7 @@ OutgoingDBusTubeChannel::~OutgoingDBusTubeChannel()
*
* This method sets up a private DBus connection to the channel target(s), and offers it through the tube.
*
- * The %PendingDBusTube returned by this method will be completed as soon as the tube is
+ * The %PendingDBusTubeConnection returned by this method will be completed as soon as the tube is
* opened and ready to be used.
*
* \param parameters A dictionary of arbitrary Parameters to send with the tube offer.
@@ -160,10 +160,10 @@ OutgoingDBusTubeChannel::~OutgoingDBusTubeChannel()
* \param requireCredentials Whether the server should require an SCM_CREDENTIALS message
* upon connection.
*
- * \returns A %PendingDBusTube which will finish as soon as the tube is ready to be used
+ * \returns A %PendingDBusTubeConnection which will finish as soon as the tube is ready to be used
* (hence in the Open state)
*/
-PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameters,
+PendingDBusTubeConnection *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameters,
bool requireCredentials)
{
SocketAccessControl accessControl = requireCredentials ?
@@ -173,14 +173,14 @@ PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameter
if (!isReady(DBusTubeChannel::FeatureDBusTube)) {
warning() << "DBusTubeChannel::FeatureDBusTube must be ready before "
"calling offerTube";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel not ready"), OutgoingDBusTubeChannelPtr(this));
}
// The tube must be not offered
if (state() != TubeChannelStateNotOffered) {
warning() << "You can not expose more than a bus for each DBus Tube";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel busy"), OutgoingDBusTubeChannelPtr(this));
}
@@ -188,7 +188,7 @@ PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameter
if (requireCredentials && !supportsCredentials()) {
warning() << "You requested an access control "
"not supported by this channel";
- return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
+ return new PendingDBusTubeConnection(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
QLatin1String("The requested access control is not supported"),
OutgoingDBusTubeChannelPtr(this));
}
@@ -199,7 +199,7 @@ PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameter
accessControl),
OutgoingDBusTubeChannelPtr(this));
- PendingDBusTube *op = new PendingDBusTube(ps, requireCredentials,
+ PendingDBusTubeConnection *op = new PendingDBusTubeConnection(ps, requireCredentials,
0, OutgoingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/outgoing-dbus-tube-channel.h b/TelepathyQt/outgoing-dbus-tube-channel.h
index 9f6addac..11926112 100644
--- a/TelepathyQt/outgoing-dbus-tube-channel.h
+++ b/TelepathyQt/outgoing-dbus-tube-channel.h
@@ -29,7 +29,7 @@
namespace Tp {
-class PendingDBusTube;
+class PendingDBusTubeConnection;
class TP_QT_EXPORT OutgoingDBusTubeChannel : public DBusTubeChannel
{
@@ -42,7 +42,7 @@ public:
virtual ~OutgoingDBusTubeChannel();
- PendingDBusTube *offerTube(const QVariantMap &parameters, bool requireCredentials = false);
+ PendingDBusTubeConnection *offerTube(const QVariantMap &parameters, bool requireCredentials = false);
protected:
OutgoingDBusTubeChannel(const ConnectionPtr &connection, const QString &objectPath,
diff --git a/TelepathyQt/pending-dbus-tube-connection.cpp b/TelepathyQt/pending-dbus-tube-connection.cpp
new file mode 100644
index 00000000..d71fd57e
--- /dev/null
+++ b/TelepathyQt/pending-dbus-tube-connection.cpp
@@ -0,0 +1,205 @@
+/*
+ * This file is part of TelepathyQt
+ *
+ * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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/PendingDBusTubeConnection>
+
+#include "TelepathyQt/_gen/pending-dbus-tube-connection.moc.hpp"
+
+#include "TelepathyQt/debug-internal.h"
+
+#include <TelepathyQt/IncomingDBusTubeChannel>
+#include <TelepathyQt/OutgoingDBusTubeChannel>
+#include <TelepathyQt/PendingString>
+#include <TelepathyQt/Types>
+
+namespace Tp
+{
+
+struct TP_QT_NO_EXPORT PendingDBusTubeConnection::Private
+{
+ Private(PendingDBusTubeConnection *parent);
+ ~Private();
+
+ // Public object
+ PendingDBusTubeConnection *parent;
+
+ DBusTubeChannelPtr tube;
+
+ bool requiresCredentials;
+ uchar credentialByte;
+};
+
+PendingDBusTubeConnection::Private::Private(PendingDBusTubeConnection *parent)
+ : parent(parent),
+ requiresCredentials(false),
+ credentialByte(0)
+{
+}
+
+PendingDBusTubeConnection::Private::~Private()
+{
+}
+
+/**
+ * \class PendingDBusTubeConnection
+ * \headerfile TelepathyQt4/pending-dbus-tube-connection.h <TelepathyQt4/PendingDBusTubeConnection>
+ *
+ * A pending operation for accepting or offering a DBus tube
+ *
+ * This class represents an asynchronous operation for accepting or offering a DBus tube.
+ * Upon completion, the address of the opened tube is returned as a QString.
+ */
+
+PendingDBusTubeConnection::PendingDBusTubeConnection(
+ PendingString *string,
+ bool requiresCredentials,
+ uchar credentialByte,
+ const DBusTubeChannelPtr &object)
+ : PendingOperation(object)
+ , mPriv(new Private(this))
+{
+ mPriv->tube = object;
+
+ mPriv->requiresCredentials = requiresCredentials;
+ mPriv->credentialByte = credentialByte;
+
+ connect(mPriv->tube.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
+ this, SLOT(onChannelInvalidated(Tp::DBusProxy*,QString,QString)));
+
+ if (string->isFinished()) {
+ onConnectionFinished(string);
+ } else {
+ // Connect the pending void
+ connect(string, SIGNAL(finished(Tp::PendingOperation*)),
+ this, SLOT(onConnectionFinished(Tp::PendingOperation*)));
+ }
+}
+
+PendingDBusTubeConnection::PendingDBusTubeConnection(
+ const QString &errorName,
+ const QString &errorMessage,
+ const DBusTubeChannelPtr &object)
+ : PendingOperation(object)
+ , mPriv(new PendingDBusTubeConnection::Private(this))
+{
+ setFinishedWithError(errorName, errorMessage);
+}
+
+/**
+ * Class destructor
+ */
+PendingDBusTubeConnection::~PendingDBusTubeConnection()
+{
+ delete mPriv;
+}
+
+/**
+ * When the operation has been completed successfully, returns the address of the opened DBus connection.
+ *
+ * Please note this function will return a meaningful value only if the operation has already
+ * been completed successfully: in case of failure or non-completion, an empty QString will be
+ * returned.
+ *
+ * \returns The address of the opened DBus connection.
+ */
+QString PendingDBusTubeConnection::address() const
+{
+ return mPriv->tube->address();
+}
+
+/**
+ * Return whether sending a credential byte once connecting to the socket is required.
+ *
+ * Note that if this method returns \c true, one should send a SCM_CREDS or SCM_CREDENTIALS
+ * and the credentialByte() once connected. If SCM_CREDS or SCM_CREDENTIALS cannot be sent,
+ * the credentialByte() should still be sent.
+ *
+ * \return \c true if sending credentials is required, \c false otherwise.
+ * \sa credentialByte()
+ */
+bool PendingDBusTubeConnection::requiresCredentials() const
+{
+ return mPriv->requiresCredentials;
+}
+
+/**
+ * Return the credential byte to send once connecting to the socket if requiresCredentials() is \c
+ * true.
+ *
+ * \return The credential byte.
+ * \sa requiresCredentials()
+ */
+uchar PendingDBusTubeConnection::credentialByte() const
+{
+ return mPriv->credentialByte;
+}
+
+void PendingDBusTubeConnection::onConnectionFinished(PendingOperation *op)
+{
+ if (isFinished()) {
+ // The operation has already failed
+ return;
+ }
+
+ if (op->isError()) {
+ // Fail
+ setFinishedWithError(op->errorName(), op->errorMessage());
+ return;
+ }
+
+ debug() << "Accept/Offer tube finished successfully";
+
+ // Now get the address and set it
+ PendingString *ps = qobject_cast<PendingString*>(op);
+ mPriv->tube->setAddress(ps->result());
+
+ // It might have been already opened - check
+ if (mPriv->tube->state() == TubeChannelStateOpen) {
+ onStateChanged(mPriv->tube->state());
+ } else {
+ // Wait until the tube gets opened on the other side
+ connect(mPriv->tube.data(), SIGNAL(stateChanged(Tp::TubeChannelState)),
+ this, SLOT(onStateChanged(Tp::TubeChannelState)));
+ }
+}
+
+void PendingDBusTubeConnection::onStateChanged(TubeChannelState state)
+{
+ debug() << "Tube state changed to " << state;
+ if (state == TubeChannelStateOpen) {
+ // The tube is ready: mark the operation as finished
+ setFinished();
+ }
+}
+
+void PendingDBusTubeConnection::onChannelInvalidated(DBusProxy* proxy,
+ const QString& errorName, const QString& errorMessage)
+{
+ Q_UNUSED(proxy);
+
+ if (isFinished()) {
+ // The operation has already finished
+ return;
+ }
+
+ setFinishedWithError(errorName, errorMessage);
+}
+
+}
diff --git a/TelepathyQt/pending-dbus-tube-connection.h b/TelepathyQt/pending-dbus-tube-connection.h
new file mode 100644
index 00000000..c2811373
--- /dev/null
+++ b/TelepathyQt/pending-dbus-tube-connection.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of TelepathyQt
+ *
+ * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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_pending_dbus_tube_connection_h_HEADER_GUARD_
+#define _TelepathyQt_pending_dbus_tube_connection_h_HEADER_GUARD_
+
+#ifndef IN_TP_QT_HEADER
+#error IN_TP_QT_HEADER
+#endif
+
+#include <TelepathyQt/PendingOperation>
+#include <TelepathyQt/OutgoingDBusTubeChannel>
+
+namespace Tp {
+
+class PendingString;
+
+class TP_QT_EXPORT PendingDBusTubeConnection : public PendingOperation
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(PendingDBusTubeConnection)
+
+public:
+ virtual ~PendingDBusTubeConnection();
+
+ QString address() const;
+
+ bool requiresCredentials() const;
+ uchar credentialByte() const;
+
+private Q_SLOTS:
+ TP_QT_NO_EXPORT void onConnectionFinished(Tp::PendingOperation *op);
+ TP_QT_NO_EXPORT void onStateChanged(Tp::TubeChannelState state);
+ TP_QT_NO_EXPORT void onChannelInvalidated(Tp::DBusProxy *proxy,
+ const QString &errorName,
+ const QString &errorMessage);
+
+private:
+ TP_QT_NO_EXPORT PendingDBusTubeConnection(PendingString *string,
+ bool requiresCredentials, uchar credentialByte,
+ const DBusTubeChannelPtr &object);
+ TP_QT_NO_EXPORT PendingDBusTubeConnection(const QString &errorName, const QString &errorMessage,
+ const DBusTubeChannelPtr &object);
+
+ struct Private;
+ friend class OutgoingDBusTubeChannel;
+ friend class IncomingDBusTubeChannel;
+ friend struct Private;
+ Private *mPriv;
+};
+
+}
+
+#endif