diff options
author | Leon Handreke <leonh@ndreke.de> | 2014-03-13 10:22:48 +0100 |
---|---|---|
committer | David Edmundson <kde@davidedmundson.co.uk> | 2014-04-11 23:56:35 +0200 |
commit | f5eab1974e4d698e79506ca4c3c704c54c89edc7 (patch) | |
tree | 437f1343d4711d5b36e5d2f0c27f184b4747497c | |
parent | b38e443c312157e86a5c6f4d0c07df7ecfc3a1cc (diff) |
Client.Handler.HandleChannels -> HandleChannel
Made for auth-handler handling channels. This is the benchmark
-rw-r--r-- | TelepathyQt/abstract-client.cpp | 18 | ||||
-rw-r--r-- | TelepathyQt/abstract-client.h | 13 | ||||
-rw-r--r-- | TelepathyQt/client-registrar-internal.h | 21 | ||||
-rw-r--r-- | TelepathyQt/client-registrar.cpp | 72 | ||||
-rw-r--r-- | TelepathyQt/request-temporary-handler-internal.cpp | 15 | ||||
-rw-r--r-- | TelepathyQt/request-temporary-handler-internal.h | 5 | ||||
-rw-r--r-- | TelepathyQt/simple-stream-tube-handler.cpp | 73 | ||||
-rw-r--r-- | TelepathyQt/simple-stream-tube-handler.h | 7 |
8 files changed, 111 insertions, 113 deletions
diff --git a/TelepathyQt/abstract-client.cpp b/TelepathyQt/abstract-client.cpp index 82801757..b9da55e0 100644 --- a/TelepathyQt/abstract-client.cpp +++ b/TelepathyQt/abstract-client.cpp @@ -616,12 +616,12 @@ struct TP_QT_NO_EXPORT AbstractClientHandler::Private * an appropriate channel handler automatically. * * To become an handler one should inherit AbstractClientHandler and - * implement the pure virtual bypassApproval() and handleChannels() methods. + * implement the pure virtual bypassApproval() and handleChannel() methods. * After that the object representing the handler must be registered using * ClientRegistrar::registerClient(). * * When new channels in which the approver has registered an interest are - * ready to be handled, the method handleChannels() is invoked. + * ready to be handled, the method handleChannel() is invoked. * * \section handler_usage_sec Usage * @@ -637,7 +637,7 @@ struct TP_QT_NO_EXPORT AbstractClientHandler::Private * * void bypassApproval() const; * - * void handleChannels(const MethodInvocationContextPtr<> &context, + * void handleChannel(const MethodInvocationContextPtr<> &context, * const AccountPtr &account, * const ConnectionPtr &connection, * const QList<ChannelPtr> &channels, @@ -656,7 +656,7 @@ struct TP_QT_NO_EXPORT AbstractClientHandler::Private * return false; * } * - * void MyHandler::handleChannels(const MethodInvocationContextPtr<> &context, + * void MyHandler::handleChannel(const MethodInvocationContextPtr<> &context, * const AccountPtr &account, * const ConnectionPtr &connection, * const QList<ChannelPtr> &channels, @@ -703,7 +703,7 @@ struct TP_QT_NO_EXPORT AbstractClientHandler::Private * \headerfile TelepathyQt/abstract-client.h <TelepathyQt/AbstractClientHandler> * * \brief The AbstractClientHandler::HandlerInfo class provides a wrapper - * around the additional info about the channels passed to handleChannels(). + * around the additional info about the channels passed to handleChannel(). * * \sa AbstractClientHandler */ @@ -868,7 +868,7 @@ AbstractClientHandler::Capabilities AbstractClientHandler::handlerCapabilities() */ /** - * \fn void AbstractClientHandler::handleChannels( + * \fn void AbstractClientHandler::handleChannel( * const MethodInvocationContextPtr<> &context, * const AccountPtr &account, * const ConnectionPtr &connection, @@ -884,7 +884,7 @@ AbstractClientHandler::Capabilities AbstractClientHandler::handlerCapabilities() * Clients are expected to know what channels they're already handling, and * which channel object corresponds to which window or tab. * - * After handleChannels() replies successfully by calling + * After handleChannel() replies successfully by calling * MethodInvocationContext::setFinished(), the client process is considered * to be responsible for the channel until it its unique name disappears from * the bus. @@ -943,7 +943,7 @@ bool AbstractClientHandler::wantsRequestNotification() const * responsiveness. * * If the request succeeds and is given to the expected handler, the - * requestsSatisfied parameter to handleChannels() can be used to match the + * requestsSatisfied parameter to handleChannel() can be used to match the * channel to a previous addRequest() call. * * This lets the UI direct the channels to the window that it already opened. @@ -953,7 +953,7 @@ bool AbstractClientHandler::wantsRequestNotification() const * * This lets the UI close the window or display the error. * - * The channel dispatcher will attempt to ensure that handleChannels() is called + * The channel dispatcher will attempt to ensure that handleChannel() is called * on the same handler that received addRequest(). If that isn't possible, * removeRequest() will be called on the handler that previously received * addRequest(), with the special error #TP_QT_ERROR_NOT_YOURS, which diff --git a/TelepathyQt/abstract-client.h b/TelepathyQt/abstract-client.h index 8e8ce47e..eb78777c 100644 --- a/TelepathyQt/abstract-client.h +++ b/TelepathyQt/abstract-client.h @@ -186,13 +186,14 @@ public: virtual bool bypassApproval() const = 0; - virtual void handleChannels(const MethodInvocationContextPtr<> &context, - const AccountPtr &account, - const ConnectionPtr &connection, - const QList<ChannelPtr> &channels, - const QList<ChannelRequestPtr> &requestsSatisfied, + virtual void handleChannel(const Tp::MethodInvocationContextPtr<> &context, + const Tp::AccountPtr &account, + const Tp::ConnectionPtr &connection, + const Tp::ChannelPtr &channel, + const QVariantMap &channelProperties, + const QList<Tp::ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime, - const HandlerInfo &handlerInfo) = 0; + const Tp::AbstractClientHandler::HandlerInfo &handlerInfo) = 0; bool wantsRequestNotification() const; virtual void addRequest(const ChannelRequestPtr &request); diff --git a/TelepathyQt/client-registrar-internal.h b/TelepathyQt/client-registrar-internal.h index 7de99c1c..b0b81eee 100644 --- a/TelepathyQt/client-registrar-internal.h +++ b/TelepathyQt/client-registrar-internal.h @@ -222,12 +222,13 @@ class TP_QT_NO_EXPORT ClientHandlerAdaptor : public QDBusAbstractAdaptor " <property name=\"BypassApproval\" type=\"b\" access=\"read\" />\n" " <property name=\"Capabilities\" type=\"as\" access=\"read\" />\n" " <property name=\"HandledChannels\" type=\"ao\" access=\"read\" />\n" -" <method name=\"HandleChannels\" >\n" +" <method name=\"HandleChannel\" >\n" " <arg name=\"Account\" type=\"o\" direction=\"in\" />\n" " <arg name=\"Connection\" type=\"o\" direction=\"in\" />\n" -" <arg name=\"Channels\" type=\"a(oa{sv})\" direction=\"in\" />\n" -" <arg name=\"Requests_Satisfied\" type=\"ao\" direction=\"in\" />\n" -" <arg name=\"User_Action_Time\" type=\"t\" direction=\"in\" />\n" +" <arg name=\"Channel\" direction=\"in\" type=\"o\">\n" +" <arg name=\"Channel_Properties\" direction=\"in\" type=\"a{sv}\">\n" +" <arg name=\"Requests_Satisfied\" type=\"a{oa{sv}}\" direction=\"in\" />\n" +" <arg name=\"User_Action_Time\" type=\"x\" direction=\"in\" />\n" " <arg name=\"Handler_Info\" type=\"a{sv}\" direction=\"in\" />\n" " </method>\n" " </interface>\n" @@ -271,11 +272,12 @@ public: // Properties } public Q_SLOTS: // Methods - void HandleChannels(const QDBusObjectPath &account, + void HandleChannel(const QDBusObjectPath &account, const QDBusObjectPath &connection, - const TpDBus::ChannelDetailsList &channels, - const TpDBus::ObjectPathList &requestsSatisfied, - qulonglong userActionTime, + const QDBusObjectPath &channel, + const QVariantMap &channelProperties, + const TpDBus::ObjectImmutablePropertiesMap &requestsSatisfied, + const qlonglong &userActionTime, const QVariantMap &handlerInfo, const QDBusMessage &message); @@ -293,7 +295,8 @@ private: MethodInvocationContextPtr<> ctx; AccountPtr acc; ConnectionPtr conn; - QList<ChannelPtr> chans; + ChannelPtr chan; + QVariantMap chanProperties; QList<ChannelRequestPtr> chanReqs; QDateTime time; AbstractClientHandler::HandlerInfo handlerInfo; diff --git a/TelepathyQt/client-registrar.cpp b/TelepathyQt/client-registrar.cpp index 6880d326..2363c9a7 100644 --- a/TelepathyQt/client-registrar.cpp +++ b/TelepathyQt/client-registrar.cpp @@ -43,9 +43,9 @@ namespace Tp { -class HandleChannelsInvocationContext : public MethodInvocationContext<> +class HandleChannelInvocationContext : public MethodInvocationContext<> { - Q_DISABLE_COPY(HandleChannelsInvocationContext) + Q_DISABLE_COPY(HandleChannelInvocationContext) public: typedef void (*FinishedCb)(const MethodInvocationContextPtr<> &context, @@ -53,20 +53,20 @@ public: void *data); static MethodInvocationContextPtr<> create(const QDBusConnection &bus, - const QDBusMessage &message, const QList<ChannelPtr> &channels, + const QDBusMessage &message, const ChannelPtr &channel, FinishedCb finishedCb, void *finishedCbData) { return SharedPtr<MethodInvocationContext<> >( - new HandleChannelsInvocationContext(bus, message, channels, + new HandleChannelInvocationContext(bus, message, channel, finishedCb, finishedCbData)); } private: - HandleChannelsInvocationContext(const QDBusConnection &connection, - const QDBusMessage &message, const QList<ChannelPtr> &channels, + HandleChannelInvocationContext(const QDBusConnection &connection, + const QDBusMessage &message, const ChannelPtr &channel, FinishedCb finishedCb, void *finishedCbData) : MethodInvocationContext<>(connection, message), - mChannels(channels), + mChannel(channel), mFinishedCb(finishedCb), mFinishedCbData(finishedCbData) { @@ -75,11 +75,13 @@ private: void onFinished() { if (mFinishedCb) { - mFinishedCb(MethodInvocationContextPtr<>(this), mChannels, mFinishedCbData); + QList<ChannelPtr> myChannels; + myChannels << mChannel; + mFinishedCb(MethodInvocationContextPtr<>(this), myChannels, mFinishedCbData); } } - QList<ChannelPtr> mChannels; + ChannelPtr mChannel; FinishedCb mFinishedCb; void *mFinishedCbData; }; @@ -381,15 +383,16 @@ ClientHandlerAdaptor::~ClientHandlerAdaptor() } } -void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath, +void ClientHandlerAdaptor::HandleChannel(const QDBusObjectPath &accountPath, const QDBusObjectPath &connectionPath, - const TpDBus::ChannelDetailsList &channelDetailsList, - const TpDBus::ObjectPathList &requestsSatisfied, - qulonglong userActionTime_t, + const QDBusObjectPath &channelPath, + const QVariantMap &channelProperties, + const TpDBus::ObjectImmutablePropertiesMap &requestsSatisfied, + const qlonglong &userActionTime_t, const QVariantMap &handlerInfo, const QDBusMessage &message) { - debug() << "HandleChannels: account:" << accountPath.path() << + debug() << "HandleChannel: account:" << accountPath.path() << ", connection:" << connectionPath.path(); AccountFactoryConstPtr accFactory = mRegistrar->accountFactory(); @@ -422,21 +425,19 @@ void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath, invocation->conn = ConnectionPtr::qObjectCast(connReady->proxy()); readyOps.append(connReady); - foreach (const TpDBus::ChannelDetails &channelDetails, channelDetailsList) { - PendingReady *chanReady = chanFactory->proxy(invocation->conn, - channelDetails.channel.path(), channelDetails.properties); - ChannelPtr channel = ChannelPtr::qObjectCast(chanReady->proxy()); - invocation->chans.append(channel); - readyOps.append(chanReady); - } + PendingReady *chanReady = chanFactory->proxy(invocation->conn, + channelPath.path(), channelProperties); + ChannelPtr channel = ChannelPtr::qObjectCast(chanReady->proxy()); + invocation->chan = channel; + invocation->chanProperties = channelProperties; + readyOps.append(chanReady); invocation->handlerInfo = AbstractClientHandler::HandlerInfo(handlerInfo); - TpDBus::ObjectImmutablePropertiesMap reqPropsMap = qdbus_cast<TpDBus::ObjectImmutablePropertiesMap>( - handlerInfo.value(QLatin1String("request-properties"))); - foreach (const QDBusObjectPath &reqPath, requestsSatisfied) { + TpDBus::ObjectImmutablePropertiesMap::const_iterator iter = requestsSatisfied.constBegin(); + while(iter != requestsSatisfied.constEnd()) { ChannelRequestPtr channelRequest = ChannelRequest::create(invocation->acc, - reqPath.path(), reqPropsMap.value(reqPath)); + iter.key().path(), iter.value()); invocation->chanReqs.append(channelRequest); readyOps.append(channelRequest->becomeReady()); } @@ -446,9 +447,9 @@ void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath, invocation->time = QDateTime::fromTime_t((uint) userActionTime_t); } - invocation->ctx = HandleChannelsInvocationContext::create(mBus, message, - invocation->chans, - reinterpret_cast<HandleChannelsInvocationContext::FinishedCb>( + invocation->ctx = HandleChannelInvocationContext::create(mBus, message, + invocation->chan, + reinterpret_cast<HandleChannelInvocationContext::FinishedCb>( &ClientHandlerAdaptor::onContextFinished), this); @@ -459,8 +460,7 @@ void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath, mInvocations.append(invocation); - debug() << "Preparing proxies for HandleChannels of" << channelDetailsList.size() << "channels" - << "for client" << mClient; + debug() << "Preparing proxy for HandleChannel for client" << mClient; } void ClientHandlerAdaptor::onReadyOpFinished(Tp::PendingOperation *op) @@ -477,7 +477,7 @@ void ClientHandlerAdaptor::onReadyOpFinished(Tp::PendingOperation *op) (*i)->readyOp = 0; if (op->isError()) { - warning() << "Preparing proxies for HandleChannels failed with" << op->errorName() + warning() << "Preparing proxies for HandleChannel failed with" << op->errorName() << op->errorMessage(); (*i)->error = op->errorName(); (*i)->message = op->errorMessage(); @@ -502,11 +502,11 @@ void ClientHandlerAdaptor::onReadyOpFinished(Tp::PendingOperation *op) continue; } - debug() << "Invoking application handleChannels with" << invocation->chans.size() - << "channels on" << mClient; + debug() << "Invoking application handleChannel on" << mClient; - mClient->handleChannels(invocation->ctx, invocation->acc, invocation->conn, - invocation->chans, invocation->chanReqs, invocation->time, invocation->handlerInfo); + mClient->handleChannel(invocation->ctx, invocation->acc, invocation->conn, + invocation->chan, invocation->chanProperties, invocation->chanReqs, + invocation->time, invocation->handlerInfo); } } @@ -515,7 +515,7 @@ void ClientHandlerAdaptor::onContextFinished( const QList<ChannelPtr> &channels, ClientHandlerAdaptor *self) { if (!context->isError()) { - debug() << "HandleChannels context finished successfully, " + debug() << "HandleChannel context finished successfully, " "updating handled channels"; // register the channels in FakeHandlerManager so we report HandledChannels correctly diff --git a/TelepathyQt/request-temporary-handler-internal.cpp b/TelepathyQt/request-temporary-handler-internal.cpp index 2b6df496..2486a46a 100644 --- a/TelepathyQt/request-temporary-handler-internal.cpp +++ b/TelepathyQt/request-temporary-handler-internal.cpp @@ -50,27 +50,26 @@ RequestTemporaryHandler::~RequestTemporaryHandler() { } -void RequestTemporaryHandler::handleChannels( +void RequestTemporaryHandler::handleChannel( const MethodInvocationContextPtr<> &context, const AccountPtr &account, const ConnectionPtr &connection, - const QList<ChannelPtr> &channels, + const ChannelPtr &newChannel, + const QVariantMap &channelProperties, const QList<ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime, const HandlerInfo &handlerInfo) { + Q_UNUSED(channelProperties); Q_ASSERT(dbusHandlerInvoked); QString errorMessage; ChannelPtr oldChannel = channel(); - if (channels.size() != 1 || requestsSatisfied.size() != 1) { - errorMessage = QLatin1String("Only one channel and one channel request should be given " - "to HandleChannels"); - } else if (account != mAccount) { + if (account != mAccount) { errorMessage = QLatin1String("Account received is not the same as the account which made " "the request"); - } else if (oldChannel && oldChannel != channels.first()) { + } else if (oldChannel && oldChannel != newChannel) { errorMessage = QLatin1String("Received a channel that is not the same as the first " "one received"); } @@ -90,7 +89,7 @@ void RequestTemporaryHandler::handleChannels( ChannelRequestPtr channelRequest = requestsSatisfied.first(); if (!oldChannel) { - mChannel = WeakPtr<Channel>(channels.first()); + mChannel = WeakPtr<Channel>(newChannel); emit channelReceived(channel(), userActionTime, channelRequest->hints()); } else { if (mQueueChannelReceived) { diff --git a/TelepathyQt/request-temporary-handler-internal.h b/TelepathyQt/request-temporary-handler-internal.h index 42f3f36d..b734d57f 100644 --- a/TelepathyQt/request-temporary-handler-internal.h +++ b/TelepathyQt/request-temporary-handler-internal.h @@ -52,10 +52,11 @@ public: */ bool bypassApproval() const { return false; } - void handleChannels(const MethodInvocationContextPtr<> &context, + void handleChannel(const MethodInvocationContextPtr<> &context, const AccountPtr &account, const ConnectionPtr &connection, - const QList<ChannelPtr> &channels, + const ChannelPtr &channel, + const QVariantMap &channelProperties, const QList<ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime, const HandlerInfo &handlerInfo); diff --git a/TelepathyQt/simple-stream-tube-handler.cpp b/TelepathyQt/simple-stream-tube-handler.cpp index 09fbd827..401274c3 100644 --- a/TelepathyQt/simple-stream-tube-handler.cpp +++ b/TelepathyQt/simple-stream-tube-handler.cpp @@ -102,48 +102,46 @@ SimpleStreamTubeHandler::~SimpleStreamTubeHandler() } } -void SimpleStreamTubeHandler::handleChannels( +void SimpleStreamTubeHandler::handleChannel( const MethodInvocationContextPtr<> &context, const AccountPtr &account, const ConnectionPtr &connection, - const QList<ChannelPtr> &channels, + const ChannelPtr &channel, + const QVariantMap &channelProperties, const QList<ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime, const HandlerInfo &handlerInfo) { - debug() << "SimpleStreamTubeHandler::handleChannels() invoked for " << - channels.size() << "channels on account" << account->objectPath(); + debug() << "SimpleStreamTubeHandler::handleChannel() invoked on account" << account->objectPath(); SharedPtr<InvocationData> invocation(new InvocationData()); QList<PendingOperation *> readyOps; - foreach (const ChannelPtr &chan, channels) { - StreamTubeChannelPtr tube = StreamTubeChannelPtr::qObjectCast(chan); - - if (!tube) { - // TODO: if Channel ever starts utilizing its immutable props for the immutable - // accessors, use Channel::channelType() here - const QString channelType = - chan->immutableProperties()[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString(); - - if (channelType != TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE1) { - debug() << "We got a non-StreamTube channel" << chan->objectPath() << - "of type" << channelType << ", ignoring"; - } else { - warning() << "The channel factory used for a simple StreamTube handler must" << - "construct StreamTubeChannel subclasses for stream tubes"; - } - continue; - } + StreamTubeChannelPtr tube = StreamTubeChannelPtr::qObjectCast(channel); - Features features = StreamTubeChannel::FeatureCore; - if (mMonitorConnections) { - features.insert(StreamTubeChannel::FeatureConnectionMonitoring); + if (!tube) { + // TODO: if Channel ever starts utilizing its immutable props for the immutable + // accessors, use Channel::channelType() here + const QString channelType = + channel->immutableProperties()[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")].toString(); + + if (channelType != TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE1) { + debug() << "We got a non-StreamTube channel" << channel->objectPath() << + "of type" << channelType << ", ignoring"; + } else { + warning() << "The channel factory used for a simple StreamTube handler must" << + "construct StreamTubeChannel subclasses for stream tubes"; } - readyOps.append(tube->becomeReady(features)); + return; + } - invocation->tubes.append(tube); + Features features = StreamTubeChannel::FeatureCore; + if (mMonitorConnections) { + features.insert(StreamTubeChannel::FeatureConnectionMonitoring); } + readyOps.append(tube->becomeReady(features)); + + invocation->tube = tube; invocation->ctx = context; invocation->acc = account; @@ -155,11 +153,11 @@ void SimpleStreamTubeHandler::handleChannels( mInvocations.append(invocation); - if (invocation->tubes.isEmpty()) { - warning() << "SSTH::HandleChannels got no suitable channels, admitting we're Confused"; + if (!invocation->tube) { + warning() << "SSTH::HandleChannel got no suitable channel, admitting we're Confused"; invocation->readyOp = 0; invocation->error = TP_QT_ERROR_CONFUSED; - invocation->message = QLatin1String("Got no suitable channels"); + invocation->message = QLatin1String("Got no suitable channel"); onReadyOpFinished(0); } else { invocation->readyOp = new PendingComposite(readyOps, SharedPtr<SimpleStreamTubeHandler>(this)); @@ -202,15 +200,9 @@ void SimpleStreamTubeHandler::onReadyOpFinished(Tp::PendingOperation *op) continue; } - debug() << "Emitting SSTubeHandler::invokedForTube for" << invocation->tubes.size() - << "tubes"; - - foreach (const StreamTubeChannelPtr &tube, invocation->tubes) { - if (!tube->isValid()) { - debug() << "Skipping already invalidated tube" << tube->objectPath(); - continue; - } - + debug() << "Emitting SSTubeHandler::invokedForTube"; + const StreamTubeChannelPtr &tube = invocation->tube; + if (tube->isValid()) { if (!mTubes.contains(tube)) { connect(tube.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), @@ -224,8 +216,9 @@ void SimpleStreamTubeHandler::onReadyOpFinished(Tp::PendingOperation *op) tube, invocation->time, invocation->hints); + } else { + debug() << "Skipping already invalidated tube" << tube->objectPath(); } - invocation->ctx->setFinished(); } } diff --git a/TelepathyQt/simple-stream-tube-handler.h b/TelepathyQt/simple-stream-tube-handler.h index d5b78dcb..6ae3d43d 100644 --- a/TelepathyQt/simple-stream-tube-handler.h +++ b/TelepathyQt/simple-stream-tube-handler.h @@ -64,10 +64,11 @@ public: return mBypassApproval; } - void handleChannels(const MethodInvocationContextPtr<> &context, + void handleChannel(const MethodInvocationContextPtr<> &context, const AccountPtr &account, const ConnectionPtr &connection, - const QList<ChannelPtr> &channels, + const ChannelPtr &channel, + const QVariantMap &channelProperties, const QList<ChannelRequestPtr> &requestsSatisfied, const QDateTime &userActionTime, const HandlerInfo &handlerInfo); @@ -106,7 +107,7 @@ private: MethodInvocationContextPtr<> ctx; AccountPtr acc; - QList<StreamTubeChannelPtr> tubes; + StreamTubeChannelPtr tube; QDateTime time; ChannelRequestHints hints; }; |