telepathy-qt: BaseConnection::ensureChannel(): Refactored.

David Edmundson davidedmundson at kemper.freedesktop.org
Fri Apr 24 06:40:14 PDT 2015


Module: telepathy-qt
Branch: master
Commit: 127bb3ec5f08921ab9d3081f5a7747c2ce35b741
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=127bb3ec5f08921ab9d3081f5a7747c2ce35b741

Author: Alexandr Akulich <akulichalexander at gmail.com>
Date:   Mon Mar 30 07:49:06 2015 +0500

BaseConnection::ensureChannel(): Refactored.

Channel matching extracted to a protected virtual method.
Previous ensureChannel() implementation doesn't allow to
override the default "ChannelType/TargetHandleType/TargetHandle
matching" behavior, which might be incorrect for some reasons.

This way, we can not perform the request values extraction outside of
the cycle, but it is a necessary sacrifice with low performance hit,
because ensureChannel() is rarely used method, extraction operation
is low-cost and usualy there is just a few channels to iterate.

---

 TelepathyQt/base-connection.cpp |   27 ++++++++++++++++++++-------
 TelepathyQt/base-connection.h   |    2 ++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/TelepathyQt/base-connection.cpp b/TelepathyQt/base-connection.cpp
index 8c4ffac..0af7aaa 100644
--- a/TelepathyQt/base-connection.cpp
+++ b/TelepathyQt/base-connection.cpp
@@ -402,14 +402,14 @@ Tp::ChannelDetailsList BaseConnection::channelsDetails()
 
 Tp::BaseChannelPtr BaseConnection::ensureChannel(const QVariantMap &request, bool &yours, bool suppressHandler, DBusError *error)
 {
-    const QString channelType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")).toString();
-    uint targetHandleType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")).toUInt();
-    uint targetHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")).toUInt();
+    foreach(const BaseChannelPtr &channel, mPriv->channels) {
+        bool match = matchChannel(channel, request, error);
+
+        if (error->isValid()) {
+            return BaseChannelPtr();
+        }
 
-    foreach(BaseChannelPtr channel, mPriv->channels) {
-        if (channel->channelType() == channelType
-                && channel->targetHandleType() == targetHandleType
-                && channel->targetHandle() == targetHandle) {
+        if (match) {
             yours = false;
             return channel;
         }
@@ -597,6 +597,19 @@ bool BaseConnection::registerObject(const QString &busName,
     return DBusService::registerObject(busName, objectPath, error);
 }
 
+bool BaseConnection::matchChannel(const BaseChannelPtr &channel, const QVariantMap &request, DBusError *error)
+{
+    Q_UNUSED(error);
+
+    const QString channelType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")).toString();
+    uint targetHandleType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")).toUInt();
+    uint targetHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")).toUInt();
+
+    return channel->channelType() == channelType
+            && channel->targetHandleType() == targetHandleType
+            && channel->targetHandle() == targetHandle;
+}
+
 void BaseConnection::setSelfHandle(uint selfHandle)
 {
     bool changed = (selfHandle != mPriv->selfHandle);
diff --git a/TelepathyQt/base-connection.h b/TelepathyQt/base-connection.h
index 347ab0f..c557605 100644
--- a/TelepathyQt/base-connection.h
+++ b/TelepathyQt/base-connection.h
@@ -130,6 +130,8 @@ protected:
     virtual bool registerObject(const QString &busName, const QString &objectPath,
                                 DBusError *error);
 
+    virtual bool matchChannel(const Tp::BaseChannelPtr &channel, const QVariantMap &request, Tp::DBusError *error);
+
 private:
     class Adaptee;
     friend class Adaptee;



More information about the telepathy-commits mailing list