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 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class QRemoteObjectPendingCallWatcherPrivate; |
14 | class QRemoteObjectPendingCallData; |
15 | |
16 | class Q_REMOTEOBJECTS_EXPORT QRemoteObjectPendingCall |
17 | { |
18 | public: |
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 | |
39 | protected: |
40 | QRemoteObjectPendingCall(QRemoteObjectPendingCallData *dd); |
41 | |
42 | /// Shared data, note: might be null |
43 | QExplicitlySharedDataPointer<QRemoteObjectPendingCallData> d; |
44 | |
45 | private: |
46 | friend class QConnectedReplicaImplementation; |
47 | }; |
48 | |
49 | QT_END_NAMESPACE |
50 | QT_DECL_METATYPE_EXTERN(QRemoteObjectPendingCall, Q_REMOTEOBJECTS_EXPORT) |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | class Q_REMOTEOBJECTS_EXPORT QRemoteObjectPendingCallWatcher: public QObject, public QRemoteObjectPendingCall |
54 | { |
55 | Q_OBJECT |
56 | |
57 | public: |
58 | QRemoteObjectPendingCallWatcher(const QRemoteObjectPendingCall &call, QObject *parent = nullptr); |
59 | ~QRemoteObjectPendingCallWatcher() override; |
60 | |
61 | bool isFinished() const; |
62 | |
63 | void waitForFinished(); |
64 | |
65 | Q_SIGNALS: |
66 | void finished(QRemoteObjectPendingCallWatcher *self); |
67 | |
68 | private: |
69 | Q_DECLARE_PRIVATE(QRemoteObjectPendingCallWatcher) |
70 | }; |
71 | |
72 | template<typename T> |
73 | class QRemoteObjectPendingReply : public QRemoteObjectPendingCall |
74 | { |
75 | public: |
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 | |
97 | QT_END_NAMESPACE |
98 | |
99 | #endif |
100 |