5#ifndef QXMPPDISCOVERYMANAGER_P_H
6#define QXMPPDISCOVERYMANAGER_P_H
8#include "QXmppDiscoveryManager.h"
9#include "QXmppPromise.h"
15using namespace QXmpp::Private;
17namespace QXmpp::Private {
19template<
typename Params,
typename Response>
20struct AttachableRequests {
23 std::vector<QXmppPromise<Response>> promises;
26 std::vector<Request> requests;
29 std::optional<QXmppTask<Response>> attach(
const Params &key)
31 auto itr = std::ranges::find(requests, key, &Request::params);
32 if (itr != requests.end()) {
33 QXmppPromise<Response> p;
35 itr->promises.push_back(std::move(p));
42 QXmppTask<Response> makeNew(Params key)
44 Q_ASSERT(!contains(requests, key, &Request::params));
46 QXmppPromise<Response> p;
48 requests.push_back(Request { key, { std::move(p) } });
52 void finish(
const Params &key, Response &&response)
54 auto itr = std::ranges::find(requests, key, &Request::params);
55 Q_ASSERT(itr != requests.end());
56 if (itr == requests.end()) {
60 auto promises = std::move(itr->promises);
63 for (
auto it = promises.begin(); it != promises.end(); ++it) {
65 it->finish(std::next(it) == promises.end() ? std::move(response) : response);
69 QXmppTask<Response> produce(Params key, std::function<QXmppTask<Response>(Params)> requestFunction, QObject *context)
71 if (
auto task = attach(key)) {
74 auto task = makeNew(key);
75 requestFunction(key).then(context, [
this, key](
auto &&response) {
76 finish(key, std::move(response));
84class QXmppDiscoveryManagerPrivate
87 using StanzaError = QXmppStanza::Error;
89 QXmppDiscoveryManager *q =
nullptr;
90 QString clientCapabilitiesNode;
91 QList<QXmppDiscoIdentity> identities;
92 QList<QXmppDataForm> dataForms;
95 QCache<std::tuple<QString, QString>, QXmppDiscoInfo> infoCache;
96 QCache<std::tuple<QString, QString>, QList<QXmppDiscoItem>> itemsCache;
102 explicit QXmppDiscoveryManagerPrivate(QXmppDiscoveryManager *q) : q(q) { }
104 static QString defaultApplicationName();
105 static QXmppDiscoIdentity defaultIdentity();
107 std::variant<CompatIq<QXmppDiscoInfo>, StanzaError> handleIq(GetIq<QXmppDiscoInfo> &&iq);
108 std::variant<CompatIq<QXmppDiscoItems>, StanzaError> handleIq(GetIq<QXmppDiscoItems> &&iq);
QXmppTask< T > task()
Definition QXmppPromise.h:86
std::variant< T, QXmppError > Result
Definition QXmppGlobal.h:209