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
32QT_BEGIN_NAMESPACE
33
34class QDBusPendingCall;
35class QDBusPendingCallWatcher;
36class QDBusPendingCallWatcherHelper;
37class QDBusConnectionPrivate;
38
39class QDBusPendingCallPrivate: public QSharedData
40{
41public:
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 setMetaTypes(int count, const QMetaType *types);
72 void checkReceivedSignature();
73
74 static QDBusPendingCall fromMessage(const QDBusMessage &msg);
75};
76
77class QDBusPendingCallWatcherHelper: public QObject
78{
79 Q_OBJECT
80public:
81 void add(QDBusPendingCallWatcher *watcher);
82
83 void emitSignals(const QDBusMessage &replyMessage, const QDBusMessage &sentMessage)
84 {
85 if (replyMessage.type() == QDBusMessage::ReplyMessage)
86 emit reply(msg: replyMessage);
87 else
88 emit error(error: QDBusError(replyMessage), msg: sentMessage);
89 emit finished();
90 }
91
92Q_SIGNALS:
93 void finished();
94 void reply(const QDBusMessage &msg);
95 void error(const QDBusError &error, const QDBusMessage &msg);
96};
97
98QT_END_NAMESPACE
99
100#endif // QT_NO_DBUS
101#endif
102

source code of qtbase/src/dbus/qdbuspendingcall_p.h