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 QDBUSINTEGRATOR_P_H
19#define QDBUSINTEGRATOR_P_H
20
21#include <QtDBus/private/qtdbusglobal_p.h>
22#include "qdbus_symbols_p.h"
23
24#include "qcoreevent.h"
25#include "qeventloop.h"
26#include "qobject.h"
27#include "private/qobject_p.h"
28#include "qlist.h"
29#include "qpointer.h"
30#include "qsemaphore.h"
31
32#include "qdbusconnection.h"
33#include "qdbusmessage.h"
34#include "qdbusconnection_p.h"
35
36#ifndef QT_NO_DBUS
37
38QT_BEGIN_NAMESPACE
39
40class QDBusConnectionPrivate;
41class QDBusMessage;
42
43// Really private structs used by qdbusintegrator.cpp
44// Things that aren't used by any other file
45
46struct QDBusSlotCache
47{
48 struct Data
49 {
50 int slotIdx;
51 QList<QMetaType> metaTypes;
52
53 void swap(Data &other) noexcept
54 {
55 std::swap(a&: slotIdx, b&: other.slotIdx);
56 metaTypes.swap(other&: other.metaTypes);
57 }
58 };
59
60 struct Key
61 {
62 QString memberWithSignature;
63 QDBusConnection::RegisterOptions flags;
64
65 friend bool operator==(const Key &lhs, const Key &rhs) noexcept
66 {
67 return lhs.memberWithSignature == rhs.memberWithSignature && lhs.flags == rhs.flags;
68 }
69
70 friend size_t qHash(const QDBusSlotCache::Key &key, size_t seed = 0) noexcept
71 {
72 return qHashMulti(seed, args: key.memberWithSignature, args: key.flags);
73 }
74 };
75
76 using Hash = QHash<Key, Data>;
77
78 Hash hash;
79
80 void swap(QDBusSlotCache &other) noexcept { hash.swap(other&: other.hash); }
81};
82Q_DECLARE_SHARED(QDBusSlotCache::Data)
83Q_DECLARE_SHARED(QDBusSlotCache)
84
85class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent
86{
87public:
88 QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
89 const QDBusMessage &msg, const QList<QMetaType> &types)
90 : QAbstractMetaCallEvent(sender, -1), connection(c), message(msg), metaTypes(types), id(id)
91 {
92 }
93
94 void placeMetaCall(QObject *object) override
95 {
96 QDBusConnectionPrivate::d(q: connection)->deliverCall(object, msg: message, metaTypes, slotIdx: id);
97 }
98
99private:
100 QDBusConnection connection; // just for refcounting
101 QDBusMessage message;
102 QList<QMetaType> metaTypes;
103 int id;
104};
105
106class QDBusActivateObjectEvent: public QAbstractMetaCallEvent
107{
108public:
109 QDBusActivateObjectEvent(const QDBusConnection &c, QObject *sender,
110 const QDBusConnectionPrivate::ObjectTreeNode &n,
111 int p, const QDBusMessage &m, QSemaphore *s = nullptr)
112 : QAbstractMetaCallEvent(sender, -1, s), connection(c), node(n),
113 pathStartPos(p), message(m), handled(false)
114 { }
115 ~QDBusActivateObjectEvent() override;
116
117 void placeMetaCall(QObject *) override;
118
119private:
120 QDBusConnection connection; // just for refcounting
121 QDBusConnectionPrivate::ObjectTreeNode node;
122 int pathStartPos;
123 QDBusMessage message;
124 bool handled;
125};
126
127class QDBusSpyCallEvent : public QAbstractMetaCallEvent
128{
129public:
130 typedef void (*Hook)(const QDBusMessage&);
131 QDBusSpyCallEvent(QDBusConnectionPrivate *cp, const QDBusConnection &c, const QDBusMessage &msg)
132 : QAbstractMetaCallEvent(cp, 0), conn(c), msg(msg)
133 {}
134 ~QDBusSpyCallEvent() override;
135 void placeMetaCall(QObject *) override;
136 static inline void invokeSpyHooks(const QDBusMessage &msg);
137
138 QDBusConnection conn; // keeps the refcount in QDBusConnectionPrivate up
139 QDBusMessage msg;
140};
141
142QT_END_NAMESPACE
143
144QT_DECL_METATYPE_EXTERN(QDBusSlotCache, Q_DBUS_EXPORT)
145
146#endif // QT_NO_DBUS
147#endif
148

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