From 040b7d9a8c7625f93e93690e47dbabb71ff87fd7 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 3 Sep 2021 18:17:40 +0200 Subject: Refactor packet sending: Add SendSuccess/SendError --- src/client/QXmppClient.cpp | 28 ++++------------------------ src/client/QXmppClient.h | 3 ++- src/client/QXmppRosterManager.cpp | 4 ++-- src/client/QXmppRosterManager.h | 5 +++-- 4 files changed, 11 insertions(+), 29 deletions(-) (limited to 'src/client') diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 4d1efe7d..e6655bd0 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -326,32 +326,12 @@ bool QXmppClient::sendPacket(const QXmppNonza &packet) /// /// Sends a packet and reports the result via QFuture. /// -/// The QFuture might have multiple results. The first result of the future is -/// reported immediately (it's safe to access resultAt(0)). If writing the data -/// to the socket succeeds (that does not mean the server received it), -/// QXmpp::Sent is reported. Otherwise QXmpp::NotSent is reported. -/// /// If stream management is enabled the future continues to be active until the -/// server acknowledges the packet. On success QXmpp::Acknowledged is reported -/// and the future finishes. +/// server acknowledges the packet. On success QXmpp::SendSuccess with +/// acknowledged == true is reported and the future finishes. /// /// If connection errors occur the packet is resent if possible. If reconnecting -/// is not possible, QXmpp::NotSent is reported. -/// -/// For you the most important result is the last one. QXmpp::Sent means the -/// packet has been sent without stream management (no acknowledgment). -/// QXmpp::Acknowledged means the packet has been sent and has been received by -/// the server, QXmpp::NotSent means no success. -/// -/// \note TL;DR: The future might have multiple results, so don't do: -/// \code -/// send().result(); -/// \endcode -/// Instead do the following to handle the final result: -/// \code -/// send().results().last(); -/// \endcode -/// QXmpp::Sent or QXmpp::Acknowledged mean success. +/// is not possible, an error is reported. /// /// \warning THIS API IS NOT FINALIZED YET! /// @@ -359,7 +339,7 @@ bool QXmppClient::sendPacket(const QXmppNonza &packet) /// You can use QFutureWatcher in Qt 5 and QFuture::then() in Qt 6 to handle the /// results. /// -QFuture QXmppClient::send(const QXmppStanza &stanza) +QFuture QXmppClient::send(const QXmppStanza &stanza) { return d->stream->send(stanza); } diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h index 9a977074..3daf629c 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -27,6 +27,7 @@ #include "QXmppConfiguration.h" #include "QXmppLogger.h" #include "QXmppPresence.h" +#include "QXmppSendResult.h" #include @@ -230,7 +231,7 @@ public: State state() const; QXmppStanza::Error::Condition xmppStreamError(); - QFuture send(const QXmppStanza &); + QFuture send(const QXmppStanza &); QFuture sendIq(const QXmppIq &); QFuture sendGenericIq(const QXmppIq &iq); diff --git a/src/client/QXmppRosterManager.cpp b/src/client/QXmppRosterManager.cpp index 0f1f0df1..0405056e 100644 --- a/src/client/QXmppRosterManager.cpp +++ b/src/client/QXmppRosterManager.cpp @@ -351,7 +351,7 @@ QFuture QXmppRosterManager::renameRosterItem(const Q /// /// \since QXmpp 1.5 /// -QFuture QXmppRosterManager::subscribeTo(const QString &bareJid, const QString &reason) +QFuture QXmppRosterManager::subscribeTo(const QString &bareJid, const QString &reason) { QXmppPresence packet; packet.setTo(QXmppUtils::jidToBareJid(bareJid)); @@ -368,7 +368,7 @@ QFuture QXmppRosterManager::subscribeTo(const QString &bareJ /// /// \since QXmpp 1.5 /// -QFuture QXmppRosterManager::unsubscribeFrom(const QString &bareJid, const QString &reason) +QFuture QXmppRosterManager::unsubscribeFrom(const QString &bareJid, const QString &reason) { QXmppPresence packet; packet.setTo(QXmppUtils::jidToBareJid(bareJid)); diff --git a/src/client/QXmppRosterManager.h b/src/client/QXmppRosterManager.h index 09c32ea0..6d872343 100644 --- a/src/client/QXmppRosterManager.h +++ b/src/client/QXmppRosterManager.h @@ -29,6 +29,7 @@ #include "QXmppClientExtension.h" #include "QXmppPresence.h" #include "QXmppRosterIq.h" +#include "QXmppSendResult.h" #include @@ -94,8 +95,8 @@ public: QFuture addRosterItem(const QString &bareJid, const QString &name = {}, const QSet &groups = {}); QFuture removeRosterItem(const QString &bareJid); QFuture renameRosterItem(const QString &bareJid, const QString &name); - QFuture subscribeTo(const QString &bareJid, const QString &reason = {}); - QFuture unsubscribeFrom(const QString &bareJid, const QString &reason = {}); + QFuture subscribeTo(const QString &bareJid, const QString &reason = {}); + QFuture unsubscribeFrom(const QString &bareJid, const QString &reason = {}); /// \cond bool handleStanza(const QDomElement &element) override; -- cgit v1.2.3