summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Freddi <dario.freddi@collabora.co.uk>2011-06-03 23:29:04 +0200
committerDario Freddi <dario.freddi@collabora.com>2012-07-03 11:11:16 +0200
commitb69bb13a893b7eae109cff2c0c5e66caaf77c6de (patch)
tree25a841cee373e5e0b5c5caf8d7a3f77ff12ab1bc
parent858c2e9d4d75a40fbfb6fb96ac65b1261be3c2a5 (diff)
dbus-tubes: Use a single implementation for pending DBus Tubes
-rw-r--r--TelepathyQt/CMakeLists.txt12
-rw-r--r--TelepathyQt/PendingDBusTube13
-rw-r--r--TelepathyQt/PendingDBusTubeAccept13
-rw-r--r--TelepathyQt/PendingDBusTubeOffer13
-rw-r--r--TelepathyQt/dbus-tube-channel.h3
-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-accept.h62
-rw-r--r--TelepathyQt/pending-dbus-tube-offer.cpp151
-rw-r--r--TelepathyQt/pending-dbus-tube.cpp (renamed from TelepathyQt/pending-dbus-tube-accept.cpp)95
-rw-r--r--TelepathyQt/pending-dbus-tube.h (renamed from TelepathyQt/pending-dbus-tube-offer.h)23
13 files changed, 122 insertions, 307 deletions
diff --git a/TelepathyQt/CMakeLists.txt b/TelepathyQt/CMakeLists.txt
index 43ebf04f..0e3549cb 100644
--- a/TelepathyQt/CMakeLists.txt
+++ b/TelepathyQt/CMakeLists.txt
@@ -94,8 +94,7 @@ set(telepathy_qt_SRCS
pending-contact-attributes.cpp
pending-contact-info.cpp
pending-contacts.cpp
- pending-dbus-tube-accept.cpp
- pending-dbus-tube-offer.cpp
+ pending-dbus-tube.cpp
pending-debug-message-list.cpp
pending-handles.cpp
pending-operation.cpp
@@ -402,10 +401,8 @@ set(telepathy_qt_HEADERS
pending-contact-info.h
PendingContacts
pending-contacts.h
- PendingDBusTubeAccept
- pending-dbus-tube-accept.h
- PendingDBusTubeOffer
- pending-dbus-tube-offer.h
+ PendingDBusTube
+ pending-dbus-tube.h
PendingDebugMessageList
pending-debug-message-list.h
PendingFailure
@@ -583,8 +580,7 @@ set(telepathy_qt_MOC_SRCS
pending-contact-info.h
pending-contacts.h
pending-contacts-internal.h
- pending-dbus-tube-accept.h
- pending-dbus-tube-offer.h
+ pending-dbus-tube.h
pending-debug-message-list.h
pending-handles.h
pending-operation.h
diff --git a/TelepathyQt/PendingDBusTube b/TelepathyQt/PendingDBusTube
new file mode 100644
index 00000000..dabe1aa0
--- /dev/null
+++ b/TelepathyQt/PendingDBusTube
@@ -0,0 +1,13 @@
+#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/PendingDBusTubeAccept b/TelepathyQt/PendingDBusTubeAccept
deleted file mode 100644
index 658c0a6a..00000000
--- a/TelepathyQt/PendingDBusTubeAccept
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _TelepathyQt_PendingDBusTubeAccept_HEADER_GUARD_
-#define _TelepathyQt_PendingDBusTubeAccept_HEADER_GUARD_
-
-#ifndef IN_TP_QT_HEADER
-#define IN_TP_QT_HEADER
-#endif
-
-#include <TelepathyQt/pending-dbus-tube-accept.h>
-
-#undef IN_TP_QT_HEADER
-
-#endif
-// vim:set ft=cpp:
diff --git a/TelepathyQt/PendingDBusTubeOffer b/TelepathyQt/PendingDBusTubeOffer
deleted file mode 100644
index 21083a86..00000000
--- a/TelepathyQt/PendingDBusTubeOffer
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _TelepathyQt_PendingDBusTubeOffer_HEADER_GUARD_
-#define _TelepathyQt_PendingDBusTubeOffer_HEADER_GUARD_
-
-#ifndef IN_TP_QT_HEADER
-#define IN_TP_QT_HEADER
-#endif
-
-#include <TelepathyQt/pending-dbus-tube-offer.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 699670ab..4863a0fe 100644
--- a/TelepathyQt/dbus-tube-channel.h
+++ b/TelepathyQt/dbus-tube-channel.h
@@ -67,8 +67,7 @@ private Q_SLOTS:
private:
struct Private;
- friend struct PendingDBusTubeAccept;
- friend struct PendingDBusTubeOffer;
+ friend struct PendingDBusTube;
friend struct Private;
Private *mPriv;
diff --git a/TelepathyQt/incoming-dbus-tube-channel.cpp b/TelepathyQt/incoming-dbus-tube-channel.cpp
index 69310575..9a016ec5 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/PendingDBusTubeAccept>
+#include <TelepathyQt/PendingDBusTube>
#include <TelepathyQt/PendingString>
#include <TelepathyQt/Types>
@@ -122,12 +122,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 PendingDBusTubeAccept serves both for monitoring the state of the tube and for
+ * The returned PendingDBusTube 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(PendingDBusTubeAccept *op)
+ * void MyTubeReceiver::onDBusTubeAccepted(PendingDBusTube *op)
* {
* if (op->isError()) {
* return;
@@ -190,7 +190,7 @@ 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 PendingDBusTubeAccept or from %address().
+ * retrieve the address either from \c PendingDBusTube or from %address().
*
* This method requires DBusTubeChannel::FeatureDBusTube to be enabled.
*
@@ -199,10 +199,10 @@ IncomingDBusTubeChannel::~IncomingDBusTubeChannel()
* \param requireCredentials Whether the server should require an SCM_CREDENTIALS message
* upon connection.
*
- * \return A %PendingDBusTubeAccept which will finish as soon as the tube is ready to be used
+ * \return A %PendingDBusTube which will finish as soon as the tube is ready to be used
* (hence in the Open state)
*/
-PendingDBusTubeAccept *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
+PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
{
SocketAccessControl accessControl = requireCredentials ?
SocketAccessControlCredentials :
@@ -211,14 +211,14 @@ PendingDBusTubeAccept *IncomingDBusTubeChannel::acceptTube(bool requireCredentia
if (!isReady(DBusTubeChannel::FeatureDBusTube)) {
warning() << "DBusTubeChannel::FeatureDBusTube must be ready before "
"calling offerTube";
- return new PendingDBusTubeAccept(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTube(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 PendingDBusTubeAccept(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel busy"), IncomingDBusTubeChannelPtr(this));
}
@@ -226,7 +226,7 @@ PendingDBusTubeAccept *IncomingDBusTubeChannel::acceptTube(bool requireCredentia
if (requireCredentials && !supportsCredentials()) {
warning() << "You requested an access control "
"not supported by this channel";
- return new PendingDBusTubeAccept(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
+ return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
QLatin1String("The requested access control is not supported"),
IncomingDBusTubeChannelPtr(this));
}
@@ -236,7 +236,7 @@ PendingDBusTubeAccept *IncomingDBusTubeChannel::acceptTube(bool requireCredentia
accessControl),
IncomingDBusTubeChannelPtr(this));
- PendingDBusTubeAccept *op = new PendingDBusTubeAccept(ps, IncomingDBusTubeChannelPtr(this));
+ PendingDBusTube *op = new PendingDBusTube(ps, IncomingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/incoming-dbus-tube-channel.h b/TelepathyQt/incoming-dbus-tube-channel.h
index bd1a1a4d..d297faa4 100644
--- a/TelepathyQt/incoming-dbus-tube-channel.h
+++ b/TelepathyQt/incoming-dbus-tube-channel.h
@@ -29,7 +29,7 @@
namespace Tp {
-class PendingDBusTubeAccept;
+class PendingDBusTube;
class TP_QT_EXPORT IncomingDBusTubeChannel : public DBusTubeChannel
{
@@ -42,7 +42,7 @@ public:
virtual ~IncomingDBusTubeChannel();
- PendingDBusTubeAccept *acceptTube(bool requireCredentials = false);
+ PendingDBusTube *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 1911fa87..09a2b6a9 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/PendingDBusTubeOffer>
+#include <TelepathyQt/PendingDBusTube>
#include <TelepathyQt/PendingString>
#include <TelepathyQt/Types>
@@ -159,7 +159,7 @@ OutgoingDBusTubeChannel::~OutgoingDBusTubeChannel()
*
* This method creates a brand new private DBus connection, and offers it through the tube.
*
- * The %PendingDBusTubeOffer returned by this method will be completed as soon as the tube is
+ * The %PendingDBusTube 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.
@@ -167,10 +167,10 @@ OutgoingDBusTubeChannel::~OutgoingDBusTubeChannel()
* \param requireCredentials Whether the server should require an SCM_CREDENTIALS message
* upon connection.
*
- * \returns A %PendingDBusTubeOffer which will finish as soon as the tube is ready to be used
+ * \returns A %PendingDBusTube which will finish as soon as the tube is ready to be used
* (hence in the Open state)
*/
-PendingDBusTubeOffer *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameters,
+PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap &parameters,
bool requireCredentials)
{
SocketAccessControl accessControl = requireCredentials ?
@@ -180,14 +180,14 @@ PendingDBusTubeOffer *OutgoingDBusTubeChannel::offerTube(const QVariantMap &para
if (!isReady(DBusTubeChannel::FeatureDBusTube)) {
warning() << "DBusTubeChannel::FeatureDBusTube must be ready before "
"calling offerTube";
- return new PendingDBusTubeOffer(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTube(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 PendingDBusTubeOffer(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
+ return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_AVAILABLE),
QLatin1String("Channel busy"), OutgoingDBusTubeChannelPtr(this));
}
@@ -195,7 +195,7 @@ PendingDBusTubeOffer *OutgoingDBusTubeChannel::offerTube(const QVariantMap &para
if (requireCredentials && !supportsCredentials()) {
warning() << "You requested an access control "
"not supported by this channel";
- return new PendingDBusTubeOffer(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
+ return new PendingDBusTube(QLatin1String(TP_QT_ERROR_NOT_IMPLEMENTED),
QLatin1String("The requested access control is not supported"),
OutgoingDBusTubeChannelPtr(this));
}
@@ -206,7 +206,7 @@ PendingDBusTubeOffer *OutgoingDBusTubeChannel::offerTube(const QVariantMap &para
accessControl),
OutgoingDBusTubeChannelPtr(this));
- PendingDBusTubeOffer *op = new PendingDBusTubeOffer(ps, OutgoingDBusTubeChannelPtr(this));
+ PendingDBusTube *op = new PendingDBusTube(ps, OutgoingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/outgoing-dbus-tube-channel.h b/TelepathyQt/outgoing-dbus-tube-channel.h
index 51af2d08..9f6addac 100644
--- a/TelepathyQt/outgoing-dbus-tube-channel.h
+++ b/TelepathyQt/outgoing-dbus-tube-channel.h
@@ -29,7 +29,7 @@
namespace Tp {
-class PendingDBusTubeOffer;
+class PendingDBusTube;
class TP_QT_EXPORT OutgoingDBusTubeChannel : public DBusTubeChannel
{
@@ -42,7 +42,7 @@ public:
virtual ~OutgoingDBusTubeChannel();
- PendingDBusTubeOffer *offerTube(const QVariantMap &parameters, bool requireCredentials = false);
+ PendingDBusTube *offerTube(const QVariantMap &parameters, bool requireCredentials = false);
protected:
OutgoingDBusTubeChannel(const ConnectionPtr &connection, const QString &objectPath,
diff --git a/TelepathyQt/pending-dbus-tube-accept.h b/TelepathyQt/pending-dbus-tube-accept.h
deleted file mode 100644
index e06cee97..00000000
--- a/TelepathyQt/pending-dbus-tube-accept.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * This file is part of TelepathyQt4
- *
- * Copyright (C) 2010 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_accept_h_HEADER_GUARD_
-#define _TelepathyQt_pending_dbus_tube_accept_h_HEADER_GUARD_
-
-#ifndef IN_TP_QT_HEADER
-#error IN_TP_QT_HEADER
-#endif
-
-#include <TelepathyQt/IncomingDBusTubeChannel>
-#include <TelepathyQt/PendingOperation>
-
-namespace Tp {
-
-class PendingString;
-
-class TP_QT_EXPORT PendingDBusTubeAccept : public PendingOperation
-{
- Q_OBJECT
- Q_DISABLE_COPY(PendingDBusTubeAccept)
-
-public:
- virtual ~PendingDBusTubeAccept();
-
- QString address() const;
-
-private Q_SLOTS:
- TP_QT_NO_EXPORT void onAcceptFinished(Tp::PendingOperation *op);
- TP_QT_NO_EXPORT void onTubeStateChanged(Tp::TubeChannelState state);
-
-private:
- PendingDBusTubeAccept(PendingString *string, const IncomingDBusTubeChannelPtr &object);
- PendingDBusTubeAccept(const QString &errorName, const QString &errorMessage,
- const IncomingDBusTubeChannelPtr &object);
-
- struct Private;
- friend class IncomingDBusTubeChannel;
- friend class Private;
- Private *mPriv;
-};
-
-}
-
-#endif
diff --git a/TelepathyQt/pending-dbus-tube-offer.cpp b/TelepathyQt/pending-dbus-tube-offer.cpp
deleted file mode 100644
index ed2e96b2..00000000
--- a/TelepathyQt/pending-dbus-tube-offer.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * This file is part of TelepathyQt4
- *
- * Copyright (C) 2010 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/PendingDBusTubeOffer>
-
-#include "TelepathyQt/_gen/pending-dbus-tube-offer.moc.hpp"
-
-
-#include "TelepathyQt/dbus-tube-channel-internal.h"
-#include "TelepathyQt/debug-internal.h"
-
-#include <TelepathyQt/PendingString>
-#include <TelepathyQt/Types>
-
-namespace Tp
-{
-
-struct TP_QT_NO_EXPORT PendingDBusTubeOffer::Private
-{
- Private(PendingDBusTubeOffer *parent);
- ~Private();
-
- // Public object
- PendingDBusTubeOffer *parent;
-
- OutgoingDBusTubeChannelPtr tube;
-};
-
-PendingDBusTubeOffer::Private::Private(PendingDBusTubeOffer *parent)
- : parent(parent)
-{
-}
-
-PendingDBusTubeOffer::Private::~Private()
-{
-}
-
-/**
- * \class PendingDBusTubeOffer
- * \headerfile TelepathyQt4/pending-dbus-tube-offer.h <TelepathyQt4/PendingDBusTubeOffer>
- *
- * A pending operation for offering a DBus tube
- *
- * This class represents an asynchronous operation for offering a DBus tube.
- * Upon completion, the address of the opened tube is returned as a QString.
- */
-
-PendingDBusTubeOffer::PendingDBusTubeOffer(
- PendingString *string,
- const OutgoingDBusTubeChannelPtr &object)
- : PendingOperation(object)
- , mPriv(new Private(this))
-{
- mPriv->tube = object;
-
- if (string->isFinished()) {
- onOfferFinished(string);
- } else {
- // Connect the pending void
- connect(string, SIGNAL(finished(Tp::PendingOperation*)),
- this, SLOT(onOfferFinished(Tp::PendingOperation*)));
- }
-}
-
-PendingDBusTubeOffer::PendingDBusTubeOffer(
- const QString &errorName,
- const QString &errorMessage,
- const OutgoingDBusTubeChannelPtr &object)
- : PendingOperation(object)
- , mPriv(new PendingDBusTubeOffer::Private(this))
-{
- setFinishedWithError(errorName, errorMessage);
-}
-
-/**
- * Class destructor
- */
-PendingDBusTubeOffer::~PendingDBusTubeOffer()
-{
- 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 PendingDBusTubeOffer::address() const
-{
- return mPriv->tube->address();
-}
-
-void PendingDBusTubeOffer::onOfferFinished(PendingOperation *op)
-{
- if (op->isError()) {
- // Fail
- setFinishedWithError(op->errorName(), op->errorMessage());
- return;
- }
-
- debug() << "Offer tube finished successfully";
-
- // Now get the address and set it
- PendingString *ps = qobject_cast<PendingString*>(op);
- DBusTubeChannelPtr::qObjectCast<DBusTubeChannel>(mPriv->tube)->mPriv->address = ps->result();
-
- // It might have been already opened - check
- if (mPriv->tube->state() == TubeChannelStateOpen) {
- onTubeStateChanged(mPriv->tube->state());
- } else {
- // Wait until the tube gets opened on the other side
- connect(mPriv->tube.data(), SIGNAL(tubeStateChanged(Tp::TubeChannelState)),
- this, SLOT(onTubeStateChanged(Tp::TubeChannelState)));
- }
-}
-
-void PendingDBusTubeOffer::onTubeStateChanged(TubeChannelState state)
-{
- debug() << "Tube state changed to " << state;
- if (state == TubeChannelStateOpen) {
- // The tube is ready: let's finish the operation
- setFinished();
- } else if (state != TubeChannelStateRemotePending) {
- // Something happened
- setFinishedWithError(QLatin1String("Connection refused"),
- QLatin1String("The connection to this tube was refused"));
- }
-}
-
-}
diff --git a/TelepathyQt/pending-dbus-tube-accept.cpp b/TelepathyQt/pending-dbus-tube.cpp
index fdb50a8c..61462bf8 100644
--- a/TelepathyQt/pending-dbus-tube-accept.cpp
+++ b/TelepathyQt/pending-dbus-tube.cpp
@@ -1,7 +1,7 @@
/*
* This file is part of TelepathyQt4
*
- * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ * 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
@@ -18,54 +18,56 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <TelepathyQt/PendingDBusTubeAccept>
+#include <TelepathyQt/PendingDBusTube>
-#include "TelepathyQt/_gen/pending-dbus-tube-accept.moc.hpp"
+#include "TelepathyQt/_gen/pending-dbus-tube.moc.hpp"
#include "TelepathyQt/dbus-tube-channel-internal.h"
#include "TelepathyQt/debug-internal.h"
+#include <TelepathyQt/IncomingDBusTubeChannel>
+#include <TelepathyQt/OutgoingDBusTubeChannel>
#include <TelepathyQt/PendingString>
#include <TelepathyQt/Types>
namespace Tp
{
-struct TP_QT_NO_EXPORT PendingDBusTubeAccept::Private
+struct TP_QT_NO_EXPORT PendingDBusTube::Private
{
- Private(PendingDBusTubeAccept *parent);
+ Private(PendingDBusTube *parent);
~Private();
// Public object
- PendingDBusTubeAccept *parent;
+ PendingDBusTube *parent;
- IncomingDBusTubeChannelPtr tube;
+ DBusTubeChannelPtr tube;
};
-PendingDBusTubeAccept::Private::Private(PendingDBusTubeAccept *parent)
+PendingDBusTube::Private::Private(PendingDBusTube *parent)
: parent(parent)
{
}
-PendingDBusTubeAccept::Private::~Private()
+PendingDBusTube::Private::~Private()
{
}
/**
- * \class PendingDBusTubeAccept
- * \headerfile TelepathyQt4/pending-dbus-tube-accept.h <TelepathyQt4/PendingDBusTubeAccept>
+ * \class PendingDBusTube
+ * \headerfile TelepathyQt/pending-dbus-tube.h <TelepathyQt/PendingDBusTube>
*
- * A pending operation for accepting a DBus tube
+ * A pending operation for accepting or offering a DBus tube
*
- * This class represents an asynchronous operation for accepting 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.
*/
-PendingDBusTubeAccept::PendingDBusTubeAccept(
+PendingDBusTube::PendingDBusTube(
PendingString *string,
const IncomingDBusTubeChannelPtr &object)
: PendingOperation(object)
- , mPriv(new PendingDBusTubeAccept::Private(this))
+ , mPriv(new Private(this))
{
mPriv->tube = object;
@@ -78,12 +80,29 @@ PendingDBusTubeAccept::PendingDBusTubeAccept(
}
}
-PendingDBusTubeAccept::PendingDBusTubeAccept(
+PendingDBusTube::PendingDBusTube(
+ PendingString *string,
+ const OutgoingDBusTubeChannelPtr &object)
+ : PendingOperation(object)
+ , mPriv(new Private(this))
+{
+ mPriv->tube = object;
+
+ if (string->isFinished()) {
+ onOfferFinished(string);
+ } else {
+ // Connect the pending void
+ connect(string, SIGNAL(finished(Tp::PendingOperation*)),
+ this, SLOT(onOfferFinished(Tp::PendingOperation*)));
+ }
+}
+
+PendingDBusTube::PendingDBusTube(
const QString &errorName,
const QString &errorMessage,
- const IncomingDBusTubeChannelPtr &object)
+ const DBusTubeChannelPtr &object)
: PendingOperation(object)
- , mPriv(new PendingDBusTubeAccept::Private(this))
+ , mPriv(new PendingDBusTube::Private(this))
{
setFinishedWithError(errorName, errorMessage);
}
@@ -91,7 +110,7 @@ PendingDBusTubeAccept::PendingDBusTubeAccept(
/**
* Class destructor
*/
-PendingDBusTubeAccept::~PendingDBusTubeAccept()
+PendingDBusTube::~PendingDBusTube()
{
delete mPriv;
}
@@ -105,12 +124,12 @@ PendingDBusTubeAccept::~PendingDBusTubeAccept()
*
* \returns The address of the opened DBus connection.
*/
-QString PendingDBusTubeAccept::address() const
+QString PendingDBusTube::address() const
{
return mPriv->tube->address();
}
-void PendingDBusTubeAccept::onAcceptFinished(PendingOperation *op)
+void PendingDBusTube::onAcceptFinished(PendingOperation *op)
{
if (op->isError()) {
// Fail
@@ -122,19 +141,43 @@ void PendingDBusTubeAccept::onAcceptFinished(PendingOperation *op)
// Now get the address and set it
PendingString *ps = qobject_cast<PendingString*>(op);
- DBusTubeChannelPtr::qObjectCast<DBusTubeChannel>(mPriv->tube)->mPriv->address = ps->result();
+ mPriv->tube->mPriv->address = 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 PendingDBusTube::onOfferFinished(PendingOperation *op)
+{
+ if (op->isError()) {
+ // Fail
+ setFinishedWithError(op->errorName(), op->errorMessage());
+ return;
+ }
+
+ debug() << "Offer tube finished successfully";
+
+ // Now get the address and set it
+ PendingString *ps = qobject_cast<PendingString*>(op);
+ mPriv->tube->mPriv->address = ps->result();
// It might have been already opened - check
if (mPriv->tube->state() == TubeChannelStateOpen) {
- onTubeStateChanged(mPriv->tube->state());
+ onStateChanged(mPriv->tube->state());
} else {
// Wait until the tube gets opened on the other side
- connect(mPriv->tube.data(), SIGNAL(tubeStateChanged(Tp::TubeChannelState)),
- this, SLOT(onTubeStateChanged(Tp::TubeChannelState)));
+ connect(mPriv->tube.data(), SIGNAL(stateChanged(Tp::TubeChannelState)),
+ this, SLOT(onStateChanged(Tp::TubeChannelState)));
}
}
-void PendingDBusTubeAccept::onTubeStateChanged(TubeChannelState state)
+void PendingDBusTube::onStateChanged(TubeChannelState state)
{
debug() << "Tube state changed to " << state;
if (state == TubeChannelStateOpen) {
diff --git a/TelepathyQt/pending-dbus-tube-offer.h b/TelepathyQt/pending-dbus-tube.h
index 8196ccf9..9da37453 100644
--- a/TelepathyQt/pending-dbus-tube-offer.h
+++ b/TelepathyQt/pending-dbus-tube.h
@@ -1,7 +1,7 @@
/*
* This file is part of TelepathyQt4
*
- * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ * 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
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef _TelepathyQt_pending_dbus_tube_offer_h_HEADER_GUARD_
-#define _TelepathyQt_pending_dbus_tube_offer_h_HEADER_GUARD_
+#ifndef _TelepathyQt_pending_dbus_tube_h_HEADER_GUARD_
+#define _TelepathyQt_pending_dbus_tube_h_HEADER_GUARD_
#ifndef IN_TP_QT_HEADER
#error IN_TP_QT_HEADER
@@ -32,27 +32,30 @@ namespace Tp {
class PendingString;
-class TP_QT_EXPORT PendingDBusTubeOffer : public PendingOperation
+class TP_QT_EXPORT PendingDBusTube : public PendingOperation
{
Q_OBJECT
- Q_DISABLE_COPY(PendingDBusTubeOffer)
+ Q_DISABLE_COPY(PendingDBusTube)
public:
- virtual ~PendingDBusTubeOffer();
+ virtual ~PendingDBusTube();
QString address() const;
private Q_SLOTS:
+ TP_QT_NO_EXPORT void onAcceptFinished(Tp::PendingOperation *op);
TP_QT_NO_EXPORT void onOfferFinished(Tp::PendingOperation *op);
- TP_QT_NO_EXPORT void onTubeStateChanged(Tp::TubeChannelState state);
+ TP_QT_NO_EXPORT void onStateChanged(Tp::TubeChannelState state);
private:
- PendingDBusTubeOffer(PendingString *string, const OutgoingDBusTubeChannelPtr &object);
- PendingDBusTubeOffer(const QString &errorName, const QString &errorMessage,
- const OutgoingDBusTubeChannelPtr &object);
+ PendingDBusTube(PendingString *string, const OutgoingDBusTubeChannelPtr &object);
+ PendingDBusTube(PendingString *string, const IncomingDBusTubeChannelPtr &object);
+ PendingDBusTube(const QString &errorName, const QString &errorMessage,
+ const DBusTubeChannelPtr &object);
struct Private;
friend class OutgoingDBusTubeChannel;
+ friend class IncomingDBusTubeChannel;
friend struct Private;
Private *mPriv;
};