1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtDBus module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41//
42// W A R N I N G
43// -------------
44//
45// This file is not part of the public API. This header file may
46// change from version to version without notice, or even be
47// removed.
48//
49// We mean it.
50//
51//
52
53#ifndef QDBUSPENDINGCALL_P_H
54#define QDBUSPENDINGCALL_P_H
55
56#include <QtDBus/private/qtdbusglobal_p.h>
57#include <qlist.h>
58#include <qmutex.h>
59#include <qpointer.h>
60#include <qshareddata.h>
61#include <qwaitcondition.h>
62
63#include "qdbusmessage.h"
64#include "qdbus_symbols_p.h"
65
66#ifndef QT_NO_DBUS
67
68QT_BEGIN_NAMESPACE
69
70class QDBusPendingCall;
71class QDBusPendingCallWatcher;
72class QDBusPendingCallWatcherHelper;
73class QDBusConnectionPrivate;
74
75class QDBusPendingCallPrivate: public QSharedData
76{
77public:
78 // {
79 // set only during construction:
80 const QDBusMessage sentMessage;
81 QDBusConnectionPrivate * const connection;
82
83 // for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync)
84 QPointer<QObject> receiver;
85 QList<QMetaType> metaTypes;
86 int methodIdx;
87
88 // }
89
90 mutable QMutex mutex;
91 QWaitCondition waitForFinishedCondition;
92
93 // {
94 // protected by the mutex above:
95 QDBusPendingCallWatcherHelper *watcherHelper;
96 QDBusMessage replyMessage;
97 DBusPendingCall *pending;
98 QString expectedReplySignature;
99 // }
100
101 QDBusPendingCallPrivate(const QDBusMessage &sent, QDBusConnectionPrivate *connection)
102 : sentMessage(sent), connection(connection), watcherHelper(nullptr), pending(nullptr)
103 { }
104 ~QDBusPendingCallPrivate();
105 bool setReplyCallback(QObject *target, const char *member);
106 void waitForFinished();
107 void setMetaTypes(int count, const QMetaType *types);
108 void checkReceivedSignature();
109
110 static QDBusPendingCall fromMessage(const QDBusMessage &msg);
111};
112
113class QDBusPendingCallWatcherHelper: public QObject
114{
115 Q_OBJECT
116public:
117 void add(QDBusPendingCallWatcher *watcher);
118
119 void emitSignals(const QDBusMessage &replyMessage, const QDBusMessage &sentMessage)
120 {
121 if (replyMessage.type() == QDBusMessage::ReplyMessage)
122 emit reply(replyMessage);
123 else
124 emit error(QDBusError(replyMessage), sentMessage);
125 emit finished();
126 }
127
128Q_SIGNALS:
129 void finished();
130 void reply(const QDBusMessage &msg);
131 void error(const QDBusError &error, const QDBusMessage &msg);
132};
133
134QT_END_NAMESPACE
135
136#endif // QT_NO_DBUS
137#endif
138