[telepathy-qt4/master] ClientRegistrar: Do not pass ready objects to AddRequest/HandleChannels to avoid wrong method call order.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Mon May 11 13:51:36 PDT 2009
---
TelepathyQt4/client-registrar-internal.h | 96 +----------
TelepathyQt4/client-registrar.cpp | 277 ++++++------------------------
2 files changed, 52 insertions(+), 321 deletions(-)
diff --git a/TelepathyQt4/client-registrar-internal.h b/TelepathyQt4/client-registrar-internal.h
index 92a7b53..7a6a3c9 100644
--- a/TelepathyQt4/client-registrar-internal.h
+++ b/TelepathyQt4/client-registrar-internal.h
@@ -132,74 +132,17 @@ public Q_SLOTS: // Methods
private Q_SLOTS:
void onOperationFinished(Tp::PendingOperation *op);
- void onHandleChannelsCallFinished();
void onChannelInvalidated(Tp::DBusProxy *proxy);
private:
- void processHandleChannelsQueue();
-
- class HandleChannelsCall;
-
QDBusConnection mBus;
AbstractClientHandler *mClient;
- QHash<PendingClientOperation *, HandleChannelsCall *> mOperations;
- QQueue<HandleChannelsCall*> mHandleChannelsQueue;
- bool mProcessingHandleChannels;
+ QHash<PendingClientOperation *, QList<ChannelPtr> > mOperations;
QSet<ChannelPtr> mHandledChannels;
static QHash<QPair<QString, QString>, QList<ClientHandlerAdaptor *> > mAdaptorsForConnection;
};
-class ClientHandlerAdaptor::HandleChannelsCall : public QObject
-{
- Q_OBJECT
-
-public:
- HandleChannelsCall(AbstractClientHandler *client,
- PendingClientOperation *op,
- const QDBusObjectPath &account,
- const QDBusObjectPath &connection,
- const ChannelDetailsList &channels,
- const ObjectPathList &requestsSatisfied,
- qulonglong userActionTime,
- const QVariantMap &handlerInfo,
- const QDBusConnection &bus,
- const QDBusMessage &message,
- QObject *parent);
- virtual ~HandleChannelsCall();
-
- QList<ChannelPtr> channels() const { return mChannels; };
-
- void process();
-
-Q_SIGNALS:
- void finished();
-
-private Q_SLOTS:
- void onObjectReady(Tp::PendingOperation *op);
- void onConnectionReady(Tp::PendingOperation *op);
-
-private:
- void checkFinished();
- void setFinishedWithError(const QString &errorName,
- const QString &errorMessage);
-
- AbstractClientHandler *mClient;
- PendingClientOperation *mOperation;
- QDBusObjectPath mAccountPath;
- QDBusObjectPath mConnectionPath;
- ChannelDetailsList mChannelDetailsList;
- ObjectPathList mRequestsSatisfied;
- qulonglong mUserActionTime;
- QVariantMap mHandlerInfo;
- QDBusConnection mBus;
- QDBusMessage mMessage;
- AccountPtr mAccount;
- ConnectionPtr mConnection;
- QList<ChannelPtr> mChannels;
- QList<ChannelRequestPtr> mChannelRequests;
-};
-
class ClientHandlerRequestsAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
@@ -232,46 +175,9 @@ public Q_SLOTS: // Methods
const QString &errorName, const QString &errorMessage,
const QDBusMessage &message);
-private Q_SLOTS:
- void onAddRequestCallFinished();
-
private:
- void processAddRequestQueue();
-
- class AddRequestCall;
-
QDBusConnection mBus;
AbstractClientHandler *mClient;
- QQueue<AddRequestCall*> mAddRequestQueue;
- bool mProcessingAddRequest;
-};
-
-class ClientHandlerRequestsAdaptor::AddRequestCall : public QObject
-{
- Q_OBJECT
-
-public:
- AddRequestCall(AbstractClientHandler *client,
- const QDBusObjectPath &request,
- const QVariantMap &requestProperties,
- const QDBusConnection &bus,
- QObject *parent);
- virtual ~AddRequestCall();
-
- void process();
-
-Q_SIGNALS:
- void finished();
-
-private Q_SLOTS:
- void onChannelRequestReady(Tp::PendingOperation *op);
-
-private:
- AbstractClientHandler *mClient;
- QDBusObjectPath mRequestPath;
- QVariantMap mRequestProperties;
- QDBusConnection mBus;
- ChannelRequestPtr mRequest;
};
} // Tp
diff --git a/TelepathyQt4/client-registrar.cpp b/TelepathyQt4/client-registrar.cpp
index dfa472e..44cd6d7 100644
--- a/TelepathyQt4/client-registrar.cpp
+++ b/TelepathyQt4/client-registrar.cpp
@@ -55,8 +55,7 @@ ClientHandlerAdaptor::ClientHandlerAdaptor(const QDBusConnection &bus,
QObject *parent)
: QDBusAbstractAdaptor(parent),
mBus(bus),
- mClient(client),
- mProcessingHandleChannels(false)
+ mClient(client)
{
QList<ClientHandlerAdaptor *> &handlerAdaptors =
mAdaptorsForConnection[qMakePair(mBus.name(), mBus.baseService())];
@@ -74,39 +73,69 @@ ClientHandlerAdaptor::~ClientHandlerAdaptor()
}
}
-void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &account,
- const QDBusObjectPath &connection,
- const Tp::ChannelDetailsList &channels,
+void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath,
+ const QDBusObjectPath &connectionPath,
+ const Tp::ChannelDetailsList &channelDetailsList,
const Tp::ObjectPathList &requestsSatisfied,
- qulonglong userActionTime,
+ qulonglong userActionTime_t,
const QVariantMap &handlerInfo,
const QDBusMessage &message)
{
- debug() << "HandleChannels: account:" << account.path() << ", connection:"
- << connection.path();
+ debug() << "HandleChannels: account:" << accountPath.path() <<
+ ", connection:" << connectionPath.path();
- PendingClientOperation *op = new PendingClientOperation(mBus,
+ AccountPtr account = Account::create(mBus,
+ TELEPATHY_ACCOUNT_MANAGER_BUS_NAME,
+ accountPath.path());
+
+ QString connectionBusName = connectionPath.path().mid(1).replace('/', '.');
+ ConnectionPtr connection = Connection::create(mBus, connectionBusName,
+ connectionPath.path());
+
+ QList<ChannelPtr> channels;
+ ChannelPtr channel;
+ foreach (const ChannelDetails &channelDetails, channelDetailsList) {
+ channel = Channel::create(connection, channelDetails.channel.path(),
+ channelDetails.properties);
+ channels.append(channel);
+ }
+
+ QList<ChannelRequestPtr> channelRequests;
+ ChannelRequestPtr channelRequest;
+ foreach (const QDBusObjectPath &path, requestsSatisfied) {
+ channelRequest = ChannelRequest::create(mBus,
+ path.path(), QVariantMap());
+ channelRequests.append(channelRequest);
+ }
+
+ // FIXME: Telepathy supports 64-bit time_t, but Qt only does so on
+ // ILP64 systems (e.g. sparc64, but not x86_64). If QDateTime
+ // gains a fromTimestamp64 method, we should use it instead.
+ QDateTime userActionTime;
+ if (userActionTime_t != 0) {
+ userActionTime = QDateTime::fromTime_t((uint) userActionTime_t);
+ }
+
+ PendingClientOperation *operation = new PendingClientOperation(mBus,
message, this);
- HandleChannelsCall *call = new HandleChannelsCall(mClient, op,
- account, connection, channels, requestsSatisfied,
- userActionTime, handlerInfo, mBus, message, this);
- connect(op,
+ connect(operation,
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onOperationFinished(Tp::PendingOperation*)));
- mOperations.insert(op, call);
- mHandleChannelsQueue.enqueue(call);
- processHandleChannelsQueue();
+ mClient->handleChannels(operation, account, connection, channels,
+ channelRequests, userActionTime, handlerInfo);
+
+ mOperations.insert(operation, channels);
}
void ClientHandlerAdaptor::onOperationFinished(PendingOperation *op)
{
- HandleChannelsCall *call =
- mOperations.value(dynamic_cast<PendingClientOperation*>(op));
if (!op->isError()) {
debug() << "HandleChannels operation finished successfully, "
"updating handled channels";
- foreach (const ChannelPtr &channel, call->channels()) {
+ QList<ChannelPtr> channels =
+ mOperations.value(dynamic_cast<PendingClientOperation*>(op));
+ foreach (const ChannelPtr &channel, channels) {
mHandledChannels.insert(channel);
connect(channel.data(),
SIGNAL(invalidated(Tp::DBusProxy *,
@@ -116,15 +145,6 @@ void ClientHandlerAdaptor::onOperationFinished(PendingOperation *op)
}
mOperations.remove(dynamic_cast<PendingClientOperation*>(op));
- // op will delete itself, so no need to delete it
- delete call;
-}
-
-void ClientHandlerAdaptor::onHandleChannelsCallFinished()
-{
- mHandleChannelsQueue.dequeue();
- mProcessingHandleChannels = false;
- processHandleChannelsQueue();
}
void ClientHandlerAdaptor::onChannelInvalidated(DBusProxy *proxy)
@@ -133,145 +153,13 @@ void ClientHandlerAdaptor::onChannelInvalidated(DBusProxy *proxy)
mHandledChannels.remove(channel);
}
-void ClientHandlerAdaptor::processHandleChannelsQueue()
-{
- if (mProcessingHandleChannels || mHandleChannelsQueue.isEmpty()) {
- return;
- }
-
- mProcessingHandleChannels = true;
- HandleChannelsCall *call = mHandleChannelsQueue.head();
- connect(call,
- SIGNAL(finished()),
- SLOT(onHandleChannelsCallFinished()));
- call->process();
-}
-
-ClientHandlerAdaptor::HandleChannelsCall::HandleChannelsCall(
- AbstractClientHandler *client,
- PendingClientOperation *op,
- const QDBusObjectPath &account,
- const QDBusObjectPath &connection,
- const ChannelDetailsList &channels,
- const ObjectPathList &requestsSatisfied,
- qulonglong userActionTime,
- const QVariantMap &handlerInfo,
- const QDBusConnection &bus,
- const QDBusMessage &message,
- QObject *parent)
- : QObject(parent),
- mClient(client),
- mOperation(op),
- mAccountPath(account),
- mConnectionPath(connection),
- mChannelDetailsList(channels),
- mRequestsSatisfied(requestsSatisfied),
- mUserActionTime(userActionTime),
- mHandlerInfo(handlerInfo),
- mBus(bus),
- mMessage(message)
-{
-}
-
-ClientHandlerAdaptor::HandleChannelsCall::~HandleChannelsCall()
-{
-}
-
-void ClientHandlerAdaptor::HandleChannelsCall::process()
-{
- mAccount = Account::create(mBus,
- TELEPATHY_ACCOUNT_MANAGER_BUS_NAME,
- mAccountPath.path());
- connect(mAccount->becomeReady(),
- SIGNAL(finished(Tp::PendingOperation *)),
- SLOT(onObjectReady(Tp::PendingOperation *)));
-
- QString connectionBusName = mConnectionPath.path().mid(1).replace('/', '.');
- mConnection = Connection::create(mBus, connectionBusName,
- mConnectionPath.path());
- connect(mConnection->becomeReady(),
- SIGNAL(finished(Tp::PendingOperation *)),
- SLOT(onConnectionReady(Tp::PendingOperation *)));
-
- ChannelRequestPtr channelRequest;
- foreach (const QDBusObjectPath &path, mRequestsSatisfied) {
- channelRequest = ChannelRequest::create(mBus,
- path.path(), QVariantMap());
- mChannelRequests.append(channelRequest);
- }
-}
-
-void ClientHandlerAdaptor::HandleChannelsCall::onObjectReady(
- PendingOperation *op)
-{
- if (op->isError()) {
- setFinishedWithError(op->errorName(), op->errorMessage());
- return;
- }
- checkFinished();
-}
-
-void ClientHandlerAdaptor::HandleChannelsCall::onConnectionReady(
- PendingOperation *op)
-{
- if (op->isError()) {
- setFinishedWithError(op->errorName(), op->errorMessage());
- return;
- }
-
- ChannelPtr channel;
- foreach (const ChannelDetails &channelDetails, mChannelDetailsList) {
- channel = Channel::create(mConnection, channelDetails.channel.path(),
- channelDetails.properties);
- connect(channel->becomeReady(),
- SIGNAL(finished(Tp::PendingOperation *)),
- SLOT(onObjectReady(Tp::PendingOperation *)));
- mChannels.append(channel);
- }
-
- // just to make sure
- checkFinished();
-}
-
-void ClientHandlerAdaptor::HandleChannelsCall::checkFinished()
-{
- if (!mAccount->isReady() || !mConnection->isReady()) {
- return;
- }
-
- foreach (const ChannelPtr &channel, mChannels) {
- if (!channel->isReady()) {
- return;
- }
- }
-
- // FIXME: Telepathy supports 64-bit time_t, but Qt only does so on
- // ILP64 systems (e.g. sparc64, but not x86_64). If QDateTime
- // gains a fromTimestamp64 method, we should use it instead.
- QDateTime userActionTime;
- if (mUserActionTime != 0) {
- userActionTime = QDateTime::fromTime_t((uint) mUserActionTime);
- }
- mClient->handleChannels(mOperation, mAccount, mConnection, mChannels,
- mChannelRequests, userActionTime, mHandlerInfo);
- emit finished();
-}
-
-void ClientHandlerAdaptor::HandleChannelsCall::setFinishedWithError(const QString &errorName,
- const QString &errorMessage)
-{
- mOperation->setFinishedWithError(errorName, errorMessage);
- emit finished();
-}
-
ClientHandlerRequestsAdaptor::ClientHandlerRequestsAdaptor(
const QDBusConnection &bus,
AbstractClientHandler *client,
QObject *parent)
: QDBusAbstractAdaptor(parent),
mBus(bus),
- mClient(client),
- mProcessingAddRequest(false)
+ mClient(client)
{
}
@@ -286,10 +174,8 @@ void ClientHandlerRequestsAdaptor::AddRequest(
{
debug() << "AddRequest:" << request.path();
mBus.send(message.createReply());
-
- mAddRequestQueue.enqueue(new AddRequestCall(mClient, request,
- requestProperties, mBus, this));
- processAddRequestQueue();
+ mClient->addRequest(ChannelRequest::create(mBus,
+ request.path(), requestProperties));
}
void ClientHandlerRequestsAdaptor::RemoveRequest(
@@ -304,67 +190,6 @@ void ClientHandlerRequestsAdaptor::RemoveRequest(
request.path(), QVariantMap()), errorName, errorMessage);
}
-void ClientHandlerRequestsAdaptor::processAddRequestQueue()
-{
- if (mProcessingAddRequest || mAddRequestQueue.isEmpty()) {
- return;
- }
-
- mProcessingAddRequest = true;
- AddRequestCall *call = mAddRequestQueue.head();
- connect(call,
- SIGNAL(finished()),
- SLOT(onAddRequestCallFinished()));
- call->process();
-}
-
-void ClientHandlerRequestsAdaptor::onAddRequestCallFinished()
-{
- mAddRequestQueue.dequeue();
- mProcessingAddRequest = false;
- processAddRequestQueue();
-}
-
-ClientHandlerRequestsAdaptor::AddRequestCall::AddRequestCall(
- AbstractClientHandler *client,
- const QDBusObjectPath &request,
- const QVariantMap &requestProperties,
- const QDBusConnection &bus,
- QObject *parent)
- : QObject(parent),
- mClient(client),
- mRequestPath(request),
- mRequestProperties(requestProperties),
- mBus(bus)
-{
-}
-
-ClientHandlerRequestsAdaptor::AddRequestCall::~AddRequestCall()
-{
-}
-
-void ClientHandlerRequestsAdaptor::AddRequestCall::process()
-{
- mRequest = ChannelRequest::create(mBus,
- mRequestPath.path(), mRequestProperties);
- connect(mRequest->becomeReady(),
- SIGNAL(finished(Tp::PendingOperation *)),
- SLOT(onChannelRequestReady(Tp::PendingOperation *)));
-}
-
-void ClientHandlerRequestsAdaptor::AddRequestCall::onChannelRequestReady(
- PendingOperation *op)
-{
- if (!op->isError()) {
- mClient->addRequest(mRequest);
- } else {
- warning() << "Unable to make ChannelRequest ready:" << op->errorName()
- << "-" << op->errorMessage() << ". Ignoring AddRequest call";
- }
- emit finished();
- deleteLater();
-}
-
struct ClientRegistrar::Private
{
Private(const QDBusConnection &bus)
--
1.5.6.5
More information about the telepathy-commits
mailing list