[Telepathy-commits] [telepathy-qt4/master] Port PendingChannel to be a PendingOperation
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Dec 1 08:59:38 PST 2008
---
TelepathyQt4/cli-connection.cpp | 39 ++++-------------------------
TelepathyQt4/cli-connection.h | 51 +--------------------------------------
tests/pinocchio/chan-basics.cpp | 43 ++++++++++++++++----------------
3 files changed, 29 insertions(+), 104 deletions(-)
diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index eb3be90..79688c8 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -478,18 +478,15 @@ PendingOperation* Connection::requestDisconnect()
struct PendingChannel::Private
{
- Connection* connection;
QString channelType;
uint handleType;
uint handle;
QDBusObjectPath objectPath;
- QDBusError error;
};
PendingChannel::PendingChannel(Connection* connection, const QString& channelType, uint handleType, uint handle)
- : QObject(connection), mPriv(new Private)
+ : PendingOperation(connection), mPriv(new Private)
{
- mPriv->connection = connection;
mPriv->channelType = channelType;
mPriv->handleType = handleType;
mPriv->handle = handle;
@@ -502,7 +499,7 @@ PendingChannel::~PendingChannel()
Connection* PendingChannel::connection() const
{
- return mPriv->connection;
+ return qobject_cast<Connection*>(proxy());
}
const QString& PendingChannel::channelType() const
@@ -520,31 +517,6 @@ uint PendingChannel::handle() const
return mPriv->handle;
}
-bool PendingChannel::isFinished() const
-{
- return !mPriv->objectPath.path().isEmpty() || !mPriv->error.message().isEmpty();
-}
-
-bool PendingChannel::isError() const
-{
- return !mPriv->error.message().isEmpty();
-}
-
-const QDBusError& PendingChannel::error() const
-{
- if (isValid())
- warning() << "PendingChannel::error() called when valid";
- else if (!isFinished())
- warning() << "PendingChannel::error() called before finished";
-
- return mPriv->error;
-}
-
-bool PendingChannel::isValid() const
-{
- return isFinished() && !isError();
-}
-
Channel* PendingChannel::channel(QObject* parent) const
{
if (!isFinished()) {
@@ -556,7 +528,7 @@ Channel* PendingChannel::channel(QObject* parent) const
}
Channel* channel =
- new Channel(mPriv->connection,
+ new Channel(connection(),
mPriv->objectPath.path(),
parent);
return channel;
@@ -567,17 +539,18 @@ void PendingChannel::onCallFinished(QDBusPendingCallWatcher* watcher)
QDBusPendingReply<QDBusObjectPath> reply = *watcher;
debug() << "Received reply to RequestChannel";
+ setFinished();
if (!reply.isError()) {
debug() << " Success: object path" << reply.value().path();
mPriv->objectPath = reply.value();
} else {
debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
- mPriv->error = reply.error();
+ setError(reply.error());
}
debug() << " Emitting finished()";
- emit finished(this);
+ emit finished(this, isValid());
watcher->deleteLater();
}
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index dffffd2..aaac8c7 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -460,7 +460,7 @@ private:
* request. Instances of this class cannot be constructed directly; the only way
* to get one is to use Connection::requestChannel().
*/
-class PendingChannel : public QObject
+class PendingChannel : public PendingOperation
{
Q_OBJECT
@@ -500,44 +500,6 @@ public:
uint handle() const;
/**
- * Returns whether or not the request has finished processing.
- *
- * \sa finished()
- *
- * \return If the request is finished.
- */
- bool isFinished() const;
-
- /**
- * Returns whether or not the request resulted in an error. If the request
- * has not yet finished processing (isFinished() returns <code>false</code>),
- * this cannot yet be known, and <code>false</code> will be returned.
- *
- * \return <code>true</code> iff the request has finished processing AND has
- * resulted in an error.
- */
- bool isError() const;
-
- /**
- * Returns the error which the request resulted in, if any. If isError()
- * returns <code>false</code>, the request has not (at least yet) resulted
- * in an error, and an undefined value will be returned.
- *
- * \return The error as a QDBusError.
- */
- const QDBusError& error() const;
-
- /**
- * Returns whether or not the request completed successfully. If the request
- * has not yet finished processing (isFinished() returns <code>false</code>),
- * this cannot yet be known, and <code>false</code> will be returned.
- *
- * \return <code>true</code> iff the request has finished processing AND has
- * completed successfully.
- */
- bool isValid() const;
-
- /**
* Returns a newly constructed Channel high-level proxy object associated
* with the remote channel resulting from the channel request. If isValid()
* returns <code>false</code>, the request has not (at least yet) completed
@@ -548,17 +510,6 @@ public:
*/
Channel* channel(QObject* parent = 0) const;
-Q_SIGNALS:
- /**
- * Emitted when the request finishes processing. isFinished() will then
- * start returning <code>true</code> and isError(), error(), isValid() and
- * channel() will become meaningful to use.
- *
- * \param pendingChannel The PendingChannel object for which the request has
- * corresponding to the finished request.
- */
- void finished(Telepathy::Client::PendingChannel* pendingChannel);
-
private Q_SLOTS:
void onCallFinished(QDBusPendingCallWatcher* watcher);
diff --git a/tests/pinocchio/chan-basics.cpp b/tests/pinocchio/chan-basics.cpp
index 29f5606..40b395e 100644
--- a/tests/pinocchio/chan-basics.cpp
+++ b/tests/pinocchio/chan-basics.cpp
@@ -34,8 +34,8 @@ protected Q_SLOTS:
void expectConnReady(uint);
void expectChanReady(uint);
void expectSuccessfulCall(QDBusPendingCallWatcher*);
- void expectPendingChannelFinished(Telepathy::Client::PendingChannel*);
- void expectPendingChannelError(Telepathy::Client::PendingChannel*);
+ void expectPendingChannelFinished(Telepathy::Client::PendingOperation*);
+ void expectPendingChannelError(Telepathy::Client::PendingOperation*);
private Q_SLOTS:
void initTestCase();
@@ -219,21 +219,23 @@ void TestChanBasics::testBasics()
}
-void TestChanBasics::expectPendingChannelFinished(PendingChannel* pc)
+void TestChanBasics::expectPendingChannelFinished(PendingOperation* op)
{
- if (!pc->isFinished()) {
+ if (!op->isFinished()) {
qWarning() << "unfinished";
mLoop->exit(1);
return;
}
- if (pc->isError()) {
- qWarning().nospace() << pc->error().name()
- << ": " << pc->error().message();
+ if (op->isError()) {
+ qWarning().nospace() << op->errorName()
+ << ": " << op->errorMessage();
mLoop->exit(2);
return;
}
+ PendingChannel *pc = qobject_cast<PendingChannel*>(op);
+ mChan = pc->channel();
mLoop->exit(0);
}
@@ -245,13 +247,12 @@ void TestChanBasics::testPendingChannel()
Telepathy::HandleTypeList,
mSubscribeHandle);
- QVERIFY(connect(pc, SIGNAL(finished(Telepathy::Client::PendingChannel*)),
- this, SLOT(expectPendingChannelFinished(Telepathy::Client::PendingChannel*))));
+ QVERIFY(connect(pc, SIGNAL(finished(Telepathy::Client::PendingOperation*, bool)),
+ this, SLOT(expectPendingChannelFinished(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(pc, SIGNAL(finished(Telepathy::Client::PendingChannel*)),
- this, SLOT(expectPendingChannelFinished(Telepathy::Client::PendingChannel*))));
+ QVERIFY(disconnect(pc, SIGNAL(finished(Telepathy::Client::PendingOperation*, bool)),
+ this, SLOT(expectPendingChannelFinished(Telepathy::Client::PendingOperation*))));
- mChan = pc->channel();
QVERIFY(mChan);
QCOMPARE(mChan->readiness(), Channel::ReadinessJustCreated);
@@ -279,22 +280,22 @@ void TestChanBasics::testPendingChannel()
delete mChan;
}
-void TestChanBasics::expectPendingChannelError(PendingChannel* pc)
+void TestChanBasics::expectPendingChannelError(PendingOperation* op)
{
- if (!pc->isFinished()) {
+ if (!op->isFinished()) {
qWarning() << "unfinished";
mLoop->exit(1);
return;
}
- if (!pc->isError()) {
+ if (!op->isError()) {
qWarning() << "no error";
mLoop->exit(2);
return;
}
- qDebug().nospace() << pc->error().name()
- << ": " << pc->error().message();
+ qDebug().nospace() << op->errorName()
+ << ": " << op->errorMessage();
mLoop->exit(0);
}
@@ -306,11 +307,11 @@ void TestChanBasics::testPendingChannelError()
Telepathy::HandleTypeList,
31337);
- QVERIFY(connect(pc, SIGNAL(finished(Telepathy::Client::PendingChannel*)),
- this, SLOT(expectPendingChannelError(Telepathy::Client::PendingChannel*))));
+ QVERIFY(connect(pc, SIGNAL(finished(Telepathy::Client::PendingOperation*, bool)),
+ this, SLOT(expectPendingChannelError(Telepathy::Client::PendingOperation*))));
QCOMPARE(mLoop->exec(), 0);
- QVERIFY(disconnect(pc, SIGNAL(finished(Telepathy::Client::PendingChannel*)),
- this, SLOT(expectPendingChannelError(Telepathy::Client::PendingChannel*))));
+ QVERIFY(disconnect(pc, SIGNAL(finished(Telepathy::Client::PendingOperation*, bool)),
+ this, SLOT(expectPendingChannelError(Telepathy::Client::PendingOperation*))));
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list