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// Qt-Security score:significant reason:default
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the public API. This header file may
11// change from version to version without notice, or even be
12// removed.
13//
14// We mean it.
15//
16//
17
18#ifndef QDBUSPENDINGCALL_P_H
19#define QDBUSPENDINGCALL_P_H
20
21#include <QtDBus/private/qtdbusglobal_p.h>
22#include <qlist.h>
23#include <qmutex.h>
24#include <qpointer.h>
25#include <qshareddata.h>
26#include <qwaitcondition.h>
27
28#include "qdbusmessage.h"
29#include "qdbus_symbols_p.h"
30
31#ifndef QT_NO_DBUS
32
33QT_BEGIN_NAMESPACE
34
35class QDBusPendingCall;
36class QDBusPendingCallWatcher;
37class QDBusPendingCallWatcherHelper;
38class QDBusConnectionPrivate;
39
40class QDBusPendingCallPrivate: public QSharedData
41{
42public:
43 // {
44 // set only during construction:
45 const QDBusMessage sentMessage;
46 QDBusConnectionPrivate * const connection;
47
48 // for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync)
49 QPointer<QObject> receiver;
50 QList<QMetaType> metaTypes;
51 int methodIdx;
52
53 // }
54
55 mutable QMutex mutex;
56 QWaitCondition waitForFinishedCondition;
57
58 // {
59 // protected by the mutex above:
60 QDBusPendingCallWatcherHelper *watcherHelper;
61 QDBusMessage replyMessage;
62 DBusPendingCall *pending;
63 QString expectedReplySignature;
64 // }
65
66 QDBusPendingCallPrivate(const QDBusMessage &sent, QDBusConnectionPrivate *connection)
67 : sentMessage(sent), connection(connection), watcherHelper(nullptr), pending(nullptr)
68 { }
69 ~QDBusPendingCallPrivate();
70 bool setReplyCallback(QObject *target, const char *member);
71 void waitForFinished();
72 void waitForFinishedWithGui();
73 void setMetaTypes(int count, const QMetaType *types);
74 void checkReceivedSignature();
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