[telepathy-qt4/master] PendingChannelRequest: Make PendingChannelRequest only fininsh when ChannelRequest succeed or fail.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Thu Jun 11 09:45:02 PDT 2009
---
TelepathyQt4/pending-channel-request-internal.h | 20 +++--
TelepathyQt4/pending-channel-request.cpp | 87 ++++++++++++-----------
TelepathyQt4/pending-channel-request.h | 10 ++-
3 files changed, 64 insertions(+), 53 deletions(-)
diff --git a/TelepathyQt4/pending-channel-request-internal.h b/TelepathyQt4/pending-channel-request-internal.h
index b69beb3..6bd9e3c 100644
--- a/TelepathyQt4/pending-channel-request-internal.h
+++ b/TelepathyQt4/pending-channel-request-internal.h
@@ -35,20 +35,24 @@ class PendingChannelRequestCancelOperation : public PendingOperation
Q_DISABLE_COPY(PendingChannelRequestCancelOperation)
public:
- PendingChannelRequestCancelOperation(
- const ChannelRequestPtr &channelRequest)
- : PendingOperation(channelRequest.data())
+ PendingChannelRequestCancelOperation(QObject *parent)
+ : PendingOperation(parent)
{
- mPendingOperation = channelRequest->cancel();
- connect(mPendingOperation,
- SIGNAL(finished(Tp::PendingOperation*)),
- SLOT(onCancelOperationFinished(Tp::PendingOperation*)));
}
~PendingChannelRequestCancelOperation()
{
}
+ void proceed(const ChannelRequestPtr &channelRequest)
+ {
+ Q_ASSERT(mChannelRequest);
+ mChannelRequest = channelRequest;
+ connect(mChannelRequest->cancel(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onCancelOperationFinished(Tp::PendingOperation*)));
+ }
+
private Q_SLOTS:
void onCancelOperationFinished(Tp::PendingOperation *op)
{
@@ -60,7 +64,7 @@ private Q_SLOTS:
}
private:
- PendingOperation *mPendingOperation;
+ ChannelRequestPtr mChannelRequest;
};
} // Tp
diff --git a/TelepathyQt4/pending-channel-request.cpp b/TelepathyQt4/pending-channel-request.cpp
index 6e26c7e..d60ca63 100644
--- a/TelepathyQt4/pending-channel-request.cpp
+++ b/TelepathyQt4/pending-channel-request.cpp
@@ -29,6 +29,7 @@
#include <TelepathyQt4/ChannelDispatcher>
#include <TelepathyQt4/ChannelRequest>
+#include <TelepathyQt4/PendingFailure>
#include <TelepathyQt4/PendingReady>
/**
@@ -49,13 +50,13 @@ struct PendingChannelRequest::Private
{
Private(const QDBusConnection &dbusConnection)
: dbusConnection(dbusConnection),
- channelRequestFinished(false)
+ cancelOperation(0)
{
}
QDBusConnection dbusConnection;
ChannelRequestPtr channelRequest;
- bool channelRequestFinished;
+ PendingChannelRequestCancelOperation *cancelOperation;
};
/**
@@ -129,46 +130,33 @@ PendingChannelRequest::PendingChannelRequest(const QDBusConnection &dbusConnecti
*/
PendingChannelRequest::~PendingChannelRequest()
{
- // let's call proceed now, as the channel request was not canceled neither
- // succeeded yet.
- if (!mPriv->channelRequestFinished && isFinished() && isValid()) {
- mPriv->channelRequest->proceed();
- }
-
delete mPriv;
}
ChannelRequestPtr PendingChannelRequest::channelRequest() const
{
- if (!isFinished()) {
- warning() << "PendingChannelRequest::channelRequest called before "
- "finished, returning 0";
- return ChannelRequestPtr();
- } else if (!isValid()) {
- warning() << "PendingChannelRequest::channelRequest called when "
- "not valid, returning 0";
- return ChannelRequestPtr();
- }
-
return mPriv->channelRequest;
}
PendingOperation *PendingChannelRequest::cancel()
{
- if (!isFinished()) {
- warning() << "PendingChannelRequest::cancel called before "
- "finished, returning 0";
- return 0;
- } else if (!isValid()) {
- warning() << "PendingChannelRequest::cancel called when "
- "not valid, returning 0";
- return 0;
+ if (isFinished()) {
+ return new PendingFailure(this, "org.freedesktop.DBus.UnknownMethod",
+ "ChannnelRequest already finished");
}
- // PendingChannelRequestCancelOperation will hold a reference to
- // ChannelRequest so it does not get deleted even if this PendingOperation
- // gets deleted.
- return new PendingChannelRequestCancelOperation(mPriv->channelRequest);
+ if (!mPriv->cancelOperation) {
+ mPriv->cancelOperation = new PendingChannelRequestCancelOperation(this);
+ connect(mPriv->cancelOperation,
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onCancelOperationFinished(Tp::PendingOperation*)));
+
+ if (mPriv->channelRequest) {
+ mPriv->cancelOperation->proceed(mPriv->channelRequest);
+ }
+ }
+
+ return mPriv->cancelOperation;
}
void PendingChannelRequest::onWatcherFinished(QDBusPendingCallWatcher *watcher)
@@ -182,16 +170,23 @@ void PendingChannelRequest::onWatcherFinished(QDBusPendingCallWatcher *watcher)
mPriv->channelRequest = ChannelRequest::create(mPriv->dbusConnection,
objectPath.path(), QVariantMap());
- connect(mPriv->channelRequest->becomeReady(),
- SIGNAL(finished(Tp::PendingOperation*)),
- SLOT(onChannelRequestReady(Tp::PendingOperation*)));
connect(mPriv->channelRequest.data(),
SIGNAL(failed(const QString &, const QString &)),
- SLOT(onChannelRequestFinished()));
+ SLOT(onChannelRequestFailed(const QString &, const QString &)));
connect(mPriv->channelRequest.data(),
SIGNAL(succeeded()),
- SLOT(onChannelRequestFinished()));
+ SLOT(onChannelRequestSucceeded()));
+
+ connect(mPriv->channelRequest->proceed(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onProceedOperationFinished(Tp::PendingOperation*)));
+
+ if (mPriv->cancelOperation) {
+ mPriv->cancelOperation->proceed(mPriv->channelRequest);
+ }
+
+ emit channelRequestCreated(mPriv->channelRequest);
} else {
debug().nospace() << "Ensure/CreateChannel failed:" <<
reply.error().name() << ": " << reply.error().message();
@@ -201,21 +196,27 @@ void PendingChannelRequest::onWatcherFinished(QDBusPendingCallWatcher *watcher)
watcher->deleteLater();
}
-void PendingChannelRequest::onChannelRequestReady(PendingOperation *op)
+void PendingChannelRequest::onChannelRequestFailed(
+ const QString &errorName, const QString &errorMessage)
+{
+ setFinishedWithError(errorName, errorMessage);
+}
+
+void PendingChannelRequest::onChannelRequestSucceeded()
+{
+ setFinished();
+}
+
+void PendingChannelRequest::onProceedOperationFinished(PendingOperation *op)
{
if (op->isError()) {
- debug().nospace() << "Unable to make ChannelRequest object ready:" <<
- op->errorName() << ": " << op->errorMessage();
setFinishedWithError(op->errorName(), op->errorMessage());
- return;
}
-
- setFinished();
}
-void PendingChannelRequest::onChannelRequestFinished()
+void PendingChannelRequest::onCancelOperationFinished(PendingOperation *op)
{
- mPriv->channelRequestFinished = true;
+ mPriv->cancelOperation = 0;
}
} // Tp
diff --git a/TelepathyQt4/pending-channel-request.h b/TelepathyQt4/pending-channel-request.h
index 097648f..e748eaf 100644
--- a/TelepathyQt4/pending-channel-request.h
+++ b/TelepathyQt4/pending-channel-request.h
@@ -52,10 +52,16 @@ public:
PendingOperation *cancel();
+Q_SIGNALS:
+ void channelRequestCreated(const ChannelRequestPtr &channelRequest);
+
private Q_SLOTS:
void onWatcherFinished(QDBusPendingCallWatcher *watcher);
- void onChannelRequestReady(Tp::PendingOperation *op);
- void onChannelRequestFinished();
+ void onChannelRequestFailed(const QString &errorName,
+ const QString &errorMessage);
+ void onChannelRequestSucceeded();
+ void onProceedOperationFinished(Tp::PendingOperation *op);
+ void onCancelOperationFinished(Tp::PendingOperation *op);
private:
friend class Account;
--
1.5.6.5
More information about the telepathy-commits
mailing list