1// Copyright (C) 2017 Ford Motor Company
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QREMOTEOBJECTPENDINGCALL_H
6#define QREMOTEOBJECTPENDINGCALL_H
7
8#include <QtRemoteObjects/qtremoteobjectglobal.h>
9
10#include <QtCore/qvariant.h>
11
12QT_BEGIN_NAMESPACE
13
14class QRemoteObjectPendingCallWatcherPrivate;
15class QRemoteObjectPendingCallData;
16
17class Q_REMOTEOBJECTS_EXPORT QRemoteObjectPendingCall
18{
19public:
20 enum Error {
21 NoError,
22 InvalidMessage
23 };
24
25 QRemoteObjectPendingCall();
26 QRemoteObjectPendingCall(const QRemoteObjectPendingCall &other);
27 ~QRemoteObjectPendingCall();
28
29 QRemoteObjectPendingCall &operator=(const QRemoteObjectPendingCall &other);
30
31 QVariant returnValue() const;
32 QRemoteObjectPendingCall::Error error() const;
33
34 bool isFinished() const;
35
36 bool waitForFinished(int timeout = 30000);
37
38 static QRemoteObjectPendingCall fromCompletedCall(const QVariant &returnValue);
39
40protected:
41 QRemoteObjectPendingCall(QRemoteObjectPendingCallData *dd);
42
43 /// Shared data, note: might be null
44 QExplicitlySharedDataPointer<QRemoteObjectPendingCallData> d;
45
46private:
47 friend class QConnectedReplicaImplementation;
48};
49
50QT_END_NAMESPACE
51QT_DECL_METATYPE_EXTERN(QRemoteObjectPendingCall, Q_REMOTEOBJECTS_EXPORT)
52QT_BEGIN_NAMESPACE
53
54class Q_REMOTEOBJECTS_EXPORT QRemoteObjectPendingCallWatcher: public QObject, public QRemoteObjectPendingCall
55{
56 Q_OBJECT
57
58public:
59 QRemoteObjectPendingCallWatcher(const QRemoteObjectPendingCall &call, QObject *parent = nullptr);
60 ~QRemoteObjectPendingCallWatcher() override;
61
62 bool isFinished() const;
63
64 void waitForFinished();
65
66Q_SIGNALS:
67 void finished(QRemoteObjectPendingCallWatcher *self);
68
69private:
70 Q_DECLARE_PRIVATE(QRemoteObjectPendingCallWatcher)
71};
72
73template<typename T>
74class QRemoteObjectPendingReply : public QRemoteObjectPendingCall
75{
76public:
77 typedef T Type;
78
79 QRemoteObjectPendingReply() = default;
80 explicit QRemoteObjectPendingReply(const QRemoteObjectPendingCall &call)
81 : QRemoteObjectPendingCall(call)
82 {
83 }
84
85 QRemoteObjectPendingReply &operator=(const QRemoteObjectPendingCall &other)
86 {
87 QRemoteObjectPendingCall::operator=(other);
88 return *this;
89 }
90
91 Type returnValue() const
92 {
93 return qvariant_cast<Type>(QRemoteObjectPendingCall::returnValue());
94 }
95
96};
97
98QT_END_NAMESPACE
99
100#endif
101

source code of qtremoteobjects/src/remoteobjects/qremoteobjectpendingcall.h