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