blob: 5164b15f1df5f7c4bf2ec5bd1f04cfdf4d89b9da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QIFREMOTEOBJECTSREPLICAHELPER_P_H
#define QIFREMOTEOBJECTSREPLICAHELPER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtInterfaceFramework/QIfPendingReply>
#include <QtInterfaceFramework/QIfAbstractFeature>
#include <QtRemoteObjects/QRemoteObjectNode>
#include <QtRemoteObjects/QRemoteObjectReplica>
#include <QtRemoteObjects/QRemoteObjectPendingCall>
#include "qtifremoteobjectshelper_global.h"
#include "qifremoteobjectspendingresult_p.h"
QT_BEGIN_NAMESPACE
class Q_IFREMOTEOBJECTSHELPER_EXPORT QIfRemoteObjectsReplicaHelper : public QObject
{
Q_OBJECT
public:
QIfRemoteObjectsReplicaHelper(const QLoggingCategory &category = qtif_private::qLcQtIfRoHelper(), QObject *parent = nullptr);
QVariant fromRemoteObjectVariant(const QVariant &variant) const;
template <class T> QIfPendingReply<T> toQIfPendingReply(const QRemoteObjectPendingCall &reply)
{
qCDebug(m_category) << "Analyzing QRemoteObjectPendingCall";
QIfPendingReply<T> ifReply;
auto watcher = new QRemoteObjectPendingCallWatcher(reply);
connect(watcher, &QRemoteObjectPendingCallWatcher::finished, watcher, [this, ifReply] (QRemoteObjectPendingCallWatcher *self) mutable {
if (self->error() == QRemoteObjectPendingCallWatcher::NoError) {
QVariant value = self->returnValue();
if (value.canConvert<QIfRemoteObjectsPendingResult>()) {
auto result = value.value<QIfRemoteObjectsPendingResult>();
if (result.failed()) {
qCDebug(m_category) << "Pending Result with id:" << result.id() << "failed";
ifReply.setFailed();
} else {
qCDebug(m_category) << "Result not available yet. Waiting for id:" << result.id();
m_pendingReplies.insert(result.id(), ifReply);
}
} else {
qCDebug(m_category) << "Got the value right away:" << value;
ifReply.setSuccess(value);
}
} else {
ifReply.setFailed();
}
self->deleteLater();
});
return ifReply;
}
public Q_SLOTS:
void onPendingResultAvailable(quint64 id, bool isSuccess, const QVariant &value);
void onReplicaStateChanged(QRemoteObjectReplica::State newState, QRemoteObjectReplica::State oldState);
void onNodeError(QRemoteObjectNode::ErrorCode code);
Q_SIGNALS:
void errorChanged(QIfAbstractFeature::Error error, const QString &message = QString());
private:
QHash<quint64, QIfPendingReplyBase> m_pendingReplies;
const QLoggingCategory &m_category;
};
QT_END_NAMESPACE
#endif //QIFREMOTEOBJECTSREPLICAHELPER_P_H
|