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

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