| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // Copyright (C) 2016 Intel Corporation. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | // |
| 6 | // W A R N I N G |
| 7 | // ------------- |
| 8 | // |
| 9 | // This file is not part of the public API. This header file may |
| 10 | // change from version to version without notice, or even be |
| 11 | // removed. |
| 12 | // |
| 13 | // We mean it. |
| 14 | // |
| 15 | // |
| 16 | |
| 17 | #ifndef QDBUSPENDINGCALL_P_H |
| 18 | #define QDBUSPENDINGCALL_P_H |
| 19 | |
| 20 | #include <QtDBus/private/qtdbusglobal_p.h> |
| 21 | #include <qlist.h> |
| 22 | #include <qmutex.h> |
| 23 | #include <qpointer.h> |
| 24 | #include <qshareddata.h> |
| 25 | #include <qwaitcondition.h> |
| 26 | |
| 27 | #include "qdbusmessage.h" |
| 28 | #include "qdbus_symbols_p.h" |
| 29 | |
| 30 | #ifndef QT_NO_DBUS |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | class QDBusPendingCall; |
| 35 | class QDBusPendingCallWatcher; |
| 36 | class QDBusPendingCallWatcherHelper; |
| 37 | class QDBusConnectionPrivate; |
| 38 | |
| 39 | class QDBusPendingCallPrivate: public QSharedData |
| 40 | { |
| 41 | public: |
| 42 | // { |
| 43 | // set only during construction: |
| 44 | const QDBusMessage sentMessage; |
| 45 | QDBusConnectionPrivate * const connection; |
| 46 | |
| 47 | // for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync) |
| 48 | QPointer<QObject> receiver; |
| 49 | QList<QMetaType> metaTypes; |
| 50 | int methodIdx; |
| 51 | |
| 52 | // } |
| 53 | |
| 54 | mutable QMutex mutex; |
| 55 | QWaitCondition waitForFinishedCondition; |
| 56 | |
| 57 | // { |
| 58 | // protected by the mutex above: |
| 59 | QDBusPendingCallWatcherHelper *watcherHelper; |
| 60 | QDBusMessage replyMessage; |
| 61 | DBusPendingCall *pending; |
| 62 | QString expectedReplySignature; |
| 63 | // } |
| 64 | |
| 65 | QDBusPendingCallPrivate(const QDBusMessage &sent, QDBusConnectionPrivate *connection) |
| 66 | : sentMessage(sent), connection(connection), watcherHelper(nullptr), pending(nullptr) |
| 67 | { } |
| 68 | ~QDBusPendingCallPrivate(); |
| 69 | bool setReplyCallback(QObject *target, const char *member); |
| 70 | void waitForFinished(); |
| 71 | void waitForFinishedWithGui(); |
| 72 | void setMetaTypes(int count, const QMetaType *types); |
| 73 | void checkReceivedSignature(); |
| 74 | }; |
| 75 | |
| 76 | class QDBusPendingCallWatcherHelper: public QObject |
| 77 | { |
| 78 | Q_OBJECT |
| 79 | public: |
| 80 | void add(QDBusPendingCallWatcher *watcher); |
| 81 | |
| 82 | void emitSignals(const QDBusMessage &replyMessage, const QDBusMessage &sentMessage) |
| 83 | { |
| 84 | if (replyMessage.type() == QDBusMessage::ReplyMessage) |
| 85 | emit reply(msg: replyMessage); |
| 86 | else |
| 87 | emit error(error: QDBusError(replyMessage), msg: sentMessage); |
| 88 | emit finished(); |
| 89 | } |
| 90 | |
| 91 | Q_SIGNALS: |
| 92 | void finished(); |
| 93 | void reply(const QDBusMessage &msg); |
| 94 | void error(const QDBusError &error, const QDBusMessage &msg); |
| 95 | }; |
| 96 | |
| 97 | QT_END_NAMESPACE |
| 98 | |
| 99 | #endif // QT_NO_DBUS |
| 100 | #endif |
| 101 | |