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 QDBUSINTEGRATOR_P_H
54#define QDBUSINTEGRATOR_P_H
55
56#include <QtDBus/private/qtdbusglobal_p.h>
57#include "qdbus_symbols_p.h"
58
59#include "qcoreevent.h"
60#include "qeventloop.h"
61#include "qobject.h"
62#include "private/qobject_p.h"
63#include "qlist.h"
64#include "qpointer.h"
65#include "qsemaphore.h"
66
67#include "qdbusconnection.h"
68#include "qdbusmessage.h"
69#include "qdbusconnection_p.h"
70
71#ifndef QT_NO_DBUS
72
73QT_BEGIN_NAMESPACE
74
75class QDBusConnectionPrivate;
76class QDBusMessage;
77
78// Really private structs used by qdbusintegrator.cpp
79// Things that aren't used by any other file
80
81struct QDBusSlotCache
82{
83 struct Data
84 {
85 int flags;
86 int slotIdx;
87 QList<QMetaType> metaTypes;
88
89 void swap(Data &other) noexcept
90 {
91 qSwap(flags, other.flags);
92 qSwap(slotIdx, other.slotIdx);
93 qSwap(metaTypes, other.metaTypes);
94 }
95 };
96 typedef QMultiHash<QString, Data> Hash;
97 Hash hash;
98
99 void swap(QDBusSlotCache &other) noexcept { qSwap(hash, other.hash); }
100};
101Q_DECLARE_SHARED(QDBusSlotCache::Data)
102Q_DECLARE_SHARED(QDBusSlotCache)
103
104class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent
105{
106public:
107 QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
108 const QDBusMessage &msg, const QList<QMetaType> &types, int f = 0)
109 : QAbstractMetaCallEvent(sender, -1),
110 connection(c),
111 message(msg),
112 metaTypes(types),
113 id(id),
114 flags(f)
115 {
116 }
117
118 void placeMetaCall(QObject *object) override
119 {
120 QDBusConnectionPrivate::d(connection)->deliverCall(object, flags, message, metaTypes, id);
121 }
122
123private:
124 QDBusConnection connection; // just for refcounting
125 QDBusMessage message;
126 QList<QMetaType> metaTypes;
127 int id;
128 int flags;
129};
130
131class QDBusActivateObjectEvent: public QAbstractMetaCallEvent
132{
133public:
134 QDBusActivateObjectEvent(const QDBusConnection &c, QObject *sender,
135 const QDBusConnectionPrivate::ObjectTreeNode &n,
136 int p, const QDBusMessage &m, QSemaphore *s = nullptr)
137 : QAbstractMetaCallEvent(sender, -1, s), connection(c), node(n),
138 pathStartPos(p), message(m), handled(false)
139 { }
140 ~QDBusActivateObjectEvent() override;
141
142 void placeMetaCall(QObject *) override;
143
144private:
145 QDBusConnection connection; // just for refcounting
146 QDBusConnectionPrivate::ObjectTreeNode node;
147 int pathStartPos;
148 QDBusMessage message;
149 bool handled;
150};
151
152class QDBusSpyCallEvent : public QAbstractMetaCallEvent
153{
154public:
155 typedef void (*Hook)(const QDBusMessage&);
156 QDBusSpyCallEvent(QDBusConnectionPrivate *cp, const QDBusConnection &c, const QDBusMessage &msg,
157 const Hook *hooks, int count)
158 : QAbstractMetaCallEvent(cp, 0), conn(c), msg(msg), hooks(hooks), hookCount(count)
159 {}
160 ~QDBusSpyCallEvent() override;
161 void placeMetaCall(QObject *) override;
162 static inline void invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount);
163
164 QDBusConnection conn; // keeps the refcount in QDBusConnectionPrivate up
165 QDBusMessage msg;
166 const Hook *hooks;
167 int hookCount;
168};
169
170QT_END_NAMESPACE
171
172Q_DECLARE_METATYPE(QDBusSlotCache)
173
174#endif // QT_NO_DBUS
175#endif
176