diff options
| author | Linus Jahn <lnj@kaidan.im> | 2021-12-05 16:07:38 +0100 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-03-03 12:50:18 +0100 |
| commit | b7010fb164381e3852b4b43658910014ac374259 (patch) | |
| tree | 75ee9ca1a34bea6f2646c83162c898747d6e1c50 /src | |
| parent | 30fb4de15cfb4586bba0f7f379011e46298941f4 (diff) | |
| download | qxmpp-b7010fb164381e3852b4b43658910014ac374259.tar.gz | |
QXmppPacket: Use QFutureInterface directly without shared_ptr
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppPacket.cpp | 17 | ||||
| -rw-r--r-- | src/base/QXmppPacket_p.h | 7 | ||||
| -rw-r--r-- | src/client/QXmppClient.cpp | 45 |
3 files changed, 31 insertions, 38 deletions
diff --git a/src/base/QXmppPacket.cpp b/src/base/QXmppPacket.cpp index f058a569..d61af9da 100644 --- a/src/base/QXmppPacket.cpp +++ b/src/base/QXmppPacket.cpp @@ -17,22 +17,17 @@ inline QByteArray serialize(const QXmppNonza &nonza) } /// \cond -QXmppPacket::QXmppPacket(const QXmppNonza &nonza) - : QXmppPacket(nonza, std::make_shared<QFutureInterface<QXmpp::SendResult>>()) -{ -} - -QXmppPacket::QXmppPacket(const QXmppNonza &nonza, std::shared_ptr<QFutureInterface<QXmpp::SendResult>> interface) +QXmppPacket::QXmppPacket(const QXmppNonza &nonza, QFutureInterface<QXmpp::SendResult> interface) : QXmppPacket(serialize(nonza), nonza.isXmppStanza(), std::move(interface)) { } -QXmppPacket::QXmppPacket(const QByteArray &data, bool isXmppStanza, std::shared_ptr<QFutureInterface<QXmpp::SendResult>> interface) +QXmppPacket::QXmppPacket(const QByteArray &data, bool isXmppStanza, QFutureInterface<QXmpp::SendResult> interface) : m_interface(std::move(interface)), m_data(data), m_isXmppStanza(isXmppStanza) { - m_interface->reportStarted(); + m_interface.reportStarted(); } QByteArray QXmppPacket::data() const @@ -47,16 +42,16 @@ bool QXmppPacket::isXmppStanza() const QFuture<QXmpp::SendResult> QXmppPacket::future() { - return m_interface->future(); + return m_interface.future(); } void QXmppPacket::reportFinished() { - m_interface->reportFinished(); + m_interface.reportFinished(); } void QXmppPacket::reportResult(const QXmpp::SendResult &result) { - m_interface->reportResult(result); + m_interface.reportResult(result); } /// \endcond diff --git a/src/base/QXmppPacket_p.h b/src/base/QXmppPacket_p.h index 565b053a..a7170a17 100644 --- a/src/base/QXmppPacket_p.h +++ b/src/base/QXmppPacket_p.h @@ -17,9 +17,8 @@ class QXmppNonza; class QXmppPacket { public: - QXmppPacket(const QXmppNonza &nonza); - QXmppPacket(const QXmppNonza &nonza, std::shared_ptr<QFutureInterface<QXmpp::SendResult>>); - QXmppPacket(const QByteArray &data, bool isXmppStanza, std::shared_ptr<QFutureInterface<QXmpp::SendResult>>); + QXmppPacket(const QXmppNonza &nonza, QFutureInterface<QXmpp::SendResult> = {}); + QXmppPacket(const QByteArray &data, bool isXmppStanza, QFutureInterface<QXmpp::SendResult> = {}); QByteArray data() const; bool isXmppStanza() const; @@ -30,7 +29,7 @@ public: void reportResult(const QXmpp::SendResult &); private: - std::shared_ptr<QFutureInterface<QXmpp::SendResult>> m_interface; + QFutureInterface<QXmpp::SendResult> m_interface; QByteArray m_data; bool m_isXmppStanza; }; diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 00fc3201..9787f4b5 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -363,20 +363,20 @@ bool QXmppClient::sendPacket(const QXmppNonza &packet) QFuture<QXmpp::SendResult> QXmppClient::send(QXmppStanza &&stanza) { const auto sendEncrypted = [this](QFuture<EncryptMessageResult> &&future) { - auto interface = std::make_shared<QFutureInterface<QXmpp::SendResult>>(QFutureInterfaceBase::Started); + QFutureInterface<QXmpp::SendResult> interface(QFutureInterfaceBase::Started); - await(future, this, [this, interface](EncryptMessageResult &&result) { + await(future, this, [this, interface](EncryptMessageResult &&result) mutable { if (const auto *xml = std::get_if<QByteArray>(&result)) { auto future = d->stream->send(QXmppPacket(*xml, true, interface)); - await(future, this, [=](QXmpp::SendResult &&result) { - reportFinishedResult(*interface, result); + await(future, this, [interface](QXmpp::SendResult &&result) mutable { + reportFinishedResult(interface, result); }); } else { - reportFinishedResult(*interface, { std::get<QXmpp::SendError>(result) }); + reportFinishedResult(interface, { std::get<QXmpp::SendError>(result) }); } }); - return interface->future(); + return interface.future(); }; if (d->encryptionExtension) { @@ -444,49 +444,48 @@ QFuture<QXmppClient::IqResult> QXmppClient::sendIq(QXmppIq &&iq) QFuture<QXmppClient::IqResult> QXmppClient::sendSensitiveIq(QXmppIq &&iq) { const auto sendEncrypted = [this](QFuture<IqEncryptResult> &&future, const QString &id) { - auto interface = std::make_shared<QFutureInterface<IqResult>>(QFutureInterfaceBase::Started); - - await(future, this, [this, interface, id](IqEncryptResult result) { + QFutureInterface<IqResult> interface(QFutureInterfaceBase::Started); + await(future, this, [this, interface, id](IqEncryptResult result) mutable { if (const auto *xml = std::get_if<QByteArray>(&result)) { // encrypted successfully - auto future = d->stream->sendIq(QXmppPacket(*xml, true, std::make_shared<QFutureInterface<QXmpp::SendResult>>()), id); - await(future, this, [this, interface](QXmppStream::IqResult result) { + auto future = d->stream->sendIq(QXmppPacket(*xml, true), id); + await(future, this, [this, interface](QXmppStream::IqResult result) mutable { if (const auto encryptedDom = std::get_if<QDomElement>(&result)) { // received result (should be encrypted) if (d->encryptionExtension) { // decrypt auto future = d->encryptionExtension->decryptIq(*encryptedDom); - await(future, this, [interface, encryptedDom = *encryptedDom](IqDecryptResult result) { + await(future, this, [interface, encryptedDom = *encryptedDom](IqDecryptResult result) mutable { if (const auto dom = std::get_if<QDomElement>(&result)) { // decrypted result - interface->reportResult(*dom); + interface.reportResult(*dom); } else if (std::holds_alternative<QXmppE2eeExtension::NotEncrypted>(result)) { // the IQ response from the other entity was not encrypted // then report IQ response without modifications - interface->reportResult(encryptedDom); + interface.reportResult(encryptedDom); } else if (const auto error = std::get_if<QXmpp::SendError>(&result)) { - interface->reportResult(*error); + interface.reportResult(*error); } - interface->reportFinished(); + interface.reportFinished(); }); } else { - interface->reportResult(QXmpp::SendError { + interface.reportResult(QXmpp::SendError { QStringLiteral("No decryption extension found."), QXmpp::SendError::EncryptionError }); - interface->reportFinished(); + interface.reportFinished(); } } else { - interface->reportResult(std::get<QXmpp::SendError>(result)); - interface->reportFinished(); + interface.reportResult(std::get<QXmpp::SendError>(result)); + interface.reportFinished(); } }); } else { - interface->reportResult(std::get<QXmpp::SendError>(result)); - interface->reportFinished(); + interface.reportResult(std::get<QXmpp::SendError>(result)); + interface.reportFinished(); } }); - return interface->future(); + return interface.future(); }; if (iq.id().isEmpty() || d->stream->hasIqId(iq.id())) { |
