[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:19 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=44174b3

The following commit has been merged in the master branch:
commit 44174b3f753aa5035aa568f041990439b067b726
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Sat Jul 19 18:40:46 2014 +0200

    Add acknowledging messages.
    
    Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
 otr-proxy/CMakeLists.txt                         |  2 +
 otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp | 85 ++++++++++++++++++------
 otr-proxy/KTpProxy/otr-proxy-channel-adaptee.h   |  1 +
 otr-proxy/KTpProxy/otr-proxy-channel.h           | 10 +--
 otr-proxy/test/CMakeLists.txt                    | 31 +++++++++
 otr-proxy/test/example-test.cpp                  | 16 +++++
 6 files changed, 121 insertions(+), 24 deletions(-)

diff --git a/otr-proxy/CMakeLists.txt b/otr-proxy/CMakeLists.txt
index 0ea2e92..8da7a10 100644
--- a/otr-proxy/CMakeLists.txt
+++ b/otr-proxy/CMakeLists.txt
@@ -13,9 +13,11 @@ include_directories (${KDE4_INCLUDES}
 include (KDE4Defaults)
 
 add_definitions (${KDE4_DEFINITIONS})
+add_definitions (-std=c++11)
 
 configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 add_subdirectory(KTpProxy)
 add_subdirectory(data)
+add_subdirectory(test)
diff --git a/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp b/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp
index 4811edd..b3d43a0 100644
--- a/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp
+++ b/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.cpp
@@ -33,19 +33,31 @@
 class PendingSendMessageResult : public PendingCurryOperation
 {
     public:
-        PendingSendMessageResult(Tp::PendingOperation *op, const Tp::TextChannelPtr &chan)
+        PendingSendMessageResult(Tp::PendingOperation *op,
+                const Tp::TextChannelPtr &chan,
+                const Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr &context,
+                const Tp::MessagePartList &message,
+                uint flags)
             : PendingCurryOperation(op, Tp::SharedPtr<Tp::RefCounted>::dynamicCast(chan)),
-            token(QString::fromLatin1(""))
+            token(QString::fromLatin1("")),
+            context(context),
+            message(message),
+            flags(flags)
         { }
 
-        void setContext(const Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr &context)
+        Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr getContext()
         {
-            this->context = context;
+            return context;
         }
 
-        Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr& getContext()
+        uint getFlags()
         {
-            return context;
+            return flags;
+        }
+
+        Tp::MessagePartList getMessage()
+        {
+            return message;
         }
 
         const QString& getToken() const
@@ -61,6 +73,8 @@ class PendingSendMessageResult : public PendingCurryOperation
     private:
         QString token;
         Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr context;
+        Tp::MessagePartList message;
+        uint flags;
 };
 
 
@@ -85,12 +99,12 @@ bool OtrProxyChannel::Adaptee::connected() const
 
 Tp::MessagePartListList OtrProxyChannel::Adaptee::pendingMessages() const
 {
-    Tp::MessagePartListList messages;
-    Q_FOREACH(const Tp::ReceivedMessage &mes, chan->messageQueue()) {
-        messages << mes.parts();
+    Tp::MessagePartListList pending;
+    for(const auto& mp: messages) {
+        pending << mp.parts();
     }
 
-    return messages;
+    return pending;
 }
 
 uint OtrProxyChannel::Adaptee::trustLevel() const
@@ -117,6 +131,7 @@ void OtrProxyChannel::Adaptee::connectProxy(
         const Tp::Service::ChannelProxyInterfaceOTRAdaptor::ConnectProxyContextPtr &context)
 {
     kDebug() << "Connecting proxy: " << pc->objectPath();
+
     connect(chan.data(),
             SIGNAL(messageReceived(const Tp::ReceivedMessage&)),
             SLOT(onMessageReceived(const Tp::ReceivedMessage&)));
@@ -125,6 +140,10 @@ void OtrProxyChannel::Adaptee::connectProxy(
             SIGNAL(pendingMessageRemoved(const Tp::ReceivedMessage&)),
             SLOT(onPendingMessageRemoved(const Tp::ReceivedMessage&)));
 
+    for(const Tp::ReceivedMessage &m: chan->messageQueue()) {
+        onMessageReceived(m);
+    }
+
     isConnected = true;
     context->setFinished();
 }
@@ -139,6 +158,7 @@ void OtrProxyChannel::Adaptee::disconnectProxy(
             this, SLOT(onPendingMessageRemoved(const Tp::ReceivedMessage&)));
 
     isConnected = false;
+    messages.clear();
     context->setFinished();
 }
 
@@ -150,10 +170,13 @@ void OtrProxyChannel::Adaptee::sendMessage(const Tp::MessagePartList &message, u
         return;
     }
 
+    kDebug();
     PendingSendMessageResult *pending = new PendingSendMessageResult(
             chan->send(message, (Tp::MessageSendingFlags) flags),
-            chan);
-    pending->setContext(context);
+            chan,
+            context,
+            message,
+            flags);
 
     connect(pending,
             SIGNAL(finished(Tp::PendingOperation*)),
@@ -167,6 +190,23 @@ void OtrProxyChannel::Adaptee::acknowledgePendingMessages(const Tp::UIntList &id
         context->setFinishedWithError(KTP_PROXY_ERROR_NOT_CONNECTED, QString::fromLatin1("Proxy is not connected"));
         return;
     }
+
+    kDebug() << "Message queue size: " << messages.size();
+    QList<Tp::ReceivedMessage> toAcknowledge;
+    for(uint id: ids) {
+        auto found = messages.find(id);
+        if(found == messages.end()) {
+            kDebug() << "Client trying to acknowledge non existing message with id" << id;
+            context->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT,
+                    QLatin1String("Message with given ID is not present in the message queue"));
+            return;
+        } else {
+            toAcknowledge << *found;
+        }
+    }
+
+    kDebug() << "Acknowledging " << toAcknowledge.count() << " messages";
+    chan->acknowledge(toAcknowledge);
     context->setFinished();
 }
 
@@ -190,26 +230,33 @@ void OtrProxyChannel::Adaptee::stop(const Tp::Service::ChannelProxyInterfaceOTRA
 
 void OtrProxyChannel::Adaptee::onMessageReceived(const Tp::ReceivedMessage &receivedMessage)
 {
-    kDebug() << "Received message: " << receivedMessage.text();
-    emit messageReceived(receivedMessage.parts());
+    const uint id = receivedMessage.header()[QLatin1String("pending-message-id")].variant().toUInt(NULL);
+    kDebug() << "Received message: " << receivedMessage.text() << " with id: " << id;
+    messages.insert(id, receivedMessage);
+    Q_EMIT messageReceived(receivedMessage.parts());
 }
 
 void OtrProxyChannel::Adaptee::onPendingMessageRemoved(const Tp::ReceivedMessage &receivedMessage)
 {
-    QDBusVariant variant = receivedMessage.header().value(QLatin1String("pending-message-id"));
-    emit pendingMessagesRemoved(Tp::UIntList() << variant.variant().toUInt(NULL));
+    const uint id = receivedMessage.header().value(QLatin1String("pending-message-id")).variant().toUInt(NULL);
+    if(messages.remove(id)) {
+        Q_EMIT pendingMessagesRemoved(Tp::UIntList() << id);
+    } else {
+        kDebug() << "Text channel removed missing pending message with id: " << id;
+    }
 }
 
-
 void OtrProxyChannel::Adaptee::onPendingSendFinished(Tp::PendingOperation *op)
 {
     PendingSendMessageResult *sendResult = dynamic_cast<PendingSendMessageResult*>(op);
 
     Tp::Service::ChannelProxyInterfaceOTRAdaptor::SendMessageContextPtr ctx = sendResult->getContext();
 
-    if(op->isError()) {
-        ctx->setFinishedWithError(op->errorName(), op->errorMessage());
+    if(sendResult->isError()) {
+        ctx->setFinishedWithError(sendResult->errorName(), sendResult->errorMessage());
     } else {
         ctx->setFinished(sendResult->getToken());
+        Q_EMIT messageSent(sendResult->getMessage(), sendResult->getFlags(), sendResult->getToken());
     }
 }
+
diff --git a/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.h b/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.h
index a7b3369..35d5e82 100644
--- a/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.h
+++ b/otr-proxy/KTpProxy/otr-proxy-channel-adaptee.h
@@ -79,6 +79,7 @@ class OtrProxyChannel::Adaptee : public QObject
         Tp::TextChannelPtr chan;
         bool isConnected;
 
+        QMap<uint, Tp::ReceivedMessage> messages; // queue
 };
 
 #endif
diff --git a/otr-proxy/KTpProxy/otr-proxy-channel.h b/otr-proxy/KTpProxy/otr-proxy-channel.h
index 1497f97..e2dd1e6 100644
--- a/otr-proxy/KTpProxy/otr-proxy-channel.h
+++ b/otr-proxy/KTpProxy/otr-proxy-channel.h
@@ -57,11 +57,11 @@ class OtrProxyChannel : public Tp::DBusService
         void onClosed();
 
     private:
-            class Adaptee;
-            friend class Adaptee;
-            class Private;
-            friend class Private;
-            Private *d;
+        class Adaptee;
+        friend class Adaptee;
+        class Private;
+        friend class Private;
+        Private *d;
 };
 
 #endif /* KTP_PROXY_OTR_PROXY_CHANNEL_HEADER */
diff --git a/otr-proxy/test/CMakeLists.txt b/otr-proxy/test/CMakeLists.txt
new file mode 100644
index 0000000..e822795
--- /dev/null
+++ b/otr-proxy/test/CMakeLists.txt
@@ -0,0 +1,31 @@
+set(ktp-proxy-test_LIBS
+        ${KDE4_KDECORE_LIBS}
+        ${KDE4_KDEUI_LIBS}
+        ${KDE4_KIO_LIBS}
+        ${QT_QTTEST_LIBRARY}
+        ${TELEPATHY_QT4_LIBRARIES}
+        ${TELEPATHY_QT4_SERVICE_LIBRARIES}
+)
+
+message("-- Adding test files:")
+file(GLOB TEST_FILES "*.cpp")
+set(TEST_NAMES "")
+
+set(CMAKE_AUTOMOC ON)
+
+foreach(file ${TEST_FILES})
+    get_filename_component(base_name ${file} NAME_WE)
+    get_filename_component(full_name ${file} NAME)
+
+    kde4_add_unit_test(${base_name} TESTNAME ktp-proxy-${base_name} ${full_name})
+    target_link_libraries (${base_name} ${ktp-proxy-test_LIBS})
+
+    LIST(APPEND TEST_NAMES ${base_name})
+endforeach()
+
+message("--   Tests found:")
+foreach(test ${TEST_NAMES})
+    message("--    " ${test})
+endforeach()
+
+ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${TEST_NAMES})
diff --git a/otr-proxy/test/example-test.cpp b/otr-proxy/test/example-test.cpp
new file mode 100644
index 0000000..2e0473f
--- /dev/null
+++ b/otr-proxy/test/example-test.cpp
@@ -0,0 +1,16 @@
+#include <QtCore>
+#include <QtTest>
+
+class ExampleTest : public QObject
+{
+    Q_OBJECT
+
+private Q_SLOTS:
+    void testDummy()
+    {
+        QVERIFY(true);
+    }
+};
+
+QTEST_MAIN(ExampleTest)
+#include "example-test.moc"

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list