Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdbusconnection_p.h
Go to the documentation of this file.
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 QDBUSCONNECTION_P_H
18#define QDBUSCONNECTION_P_H
19
20#include <QtDBus/private/qtdbusglobal_p.h>
21#include <qdbuserror.h>
22#include <qdbusconnection.h>
23
24#include <QtCore/qatomic.h>
25#include <QtCore/qhash.h>
26#include <QtCore/qlist.h>
27#include <QtCore/qobject.h>
28#include <QtCore/qpointer.h>
29#include <QtCore/qreadwritelock.h>
30#include <QtCore/qstringlist.h>
31#include <QtCore/qvarlengtharray.h>
32
33#include "qdbus_symbols_p.h"
34
35#include <qdbusmessage.h>
36#include <qdbusservicewatcher.h> // for the WatchMode enum
37Q_MOC_INCLUDE(<QtDBus/private/qdbuspendingcall_p.h>)
38
39#ifndef QT_NO_DBUS
40
42
43class QDBusMessage;
44class QSocketNotifier;
45class QTimerEvent;
46class QDBusObjectPrivate;
49class QMetaMethod;
51struct QDBusMetaObject;
55class QDBusServer;
56
57#ifndef QT_BOOTSTRAPPED
58
60{
61 mutable DBusError error;
62 Q_DISABLE_COPY_MOVE(QDBusErrorInternal)
63public:
64 inline QDBusErrorInternal() { q_dbus_error_init(&error); }
65 inline ~QDBusErrorInternal() { q_dbus_error_free(&error); }
66 inline bool operator !() const { return !q_dbus_error_is_set(&error); }
67 inline operator DBusError *() { q_dbus_error_free(&error); return &error; }
68 inline operator QDBusError() const { QDBusError err(&error); q_dbus_error_free(&error); return err; }
69};
70
71// QDBusConnectionPrivate holds the DBusConnection and
72// can have many QDBusConnection objects referring to it
73
75{
77public:
78 // structs and enums
79 enum ConnectionMode { InvalidMode, ServerMode, ClientMode, PeerMode }; // LocalMode
80
88
92 bool operator==(const ArgMatchRules &other) const {
93 return args == other.args &&
94 arg0namespace == other.arg0namespace;
95 }
96 };
97
99 {
100 inline SignalHook() : obj(nullptr), midx(-1) { }
101 QString service, path, signature;
103 int midx;
104 QList<QMetaType> params;
107 };
108
110 Object = 0x0,
111 VirtualObject = 0x01000000
112 };
113
115 {
116 typedef QList<ObjectTreeNode> DataList;
117
118 inline ObjectTreeNode() : obj(nullptr) { }
119 inline ObjectTreeNode(const QString &n) // intentionally implicit
120 : name(n), obj(nullptr)
121 {
122 }
123 inline bool operator<(const QString &other) const
124 { return name < other; }
125 inline bool operator<(QStringView other) const
126 { return name < other; }
127 inline bool isActive() const
128 { return obj || !children.isEmpty(); }
129
132 union {
135 };
136 QDBusConnection::RegisterOptions flags;
137
139 };
140
141 // typedefs
142 typedef QMultiHash<qintptr, Watcher> WatcherHash;
143 typedef QHash<int, DBusTimeout *> TimeoutHash;
144 typedef QList<QDBusMessage> PendingMessageList;
145
146 typedef QMultiHash<QString, SignalHook> SignalHookHash;
147 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
148 typedef QHash<QByteArray, int> MatchRefCountHash;
149 typedef QList<QDBusPendingCallPrivate *> PendingCallList;
150
152 WatchedServiceData() : refcount(0) {}
153 WatchedServiceData(const QString &owner, int refcount = 0)
154 : owner(owner), refcount(refcount)
155 {}
158 };
159 typedef QHash<QString, WatchedServiceData> WatchedServicesHash;
160
161 // public methods are entry points from other objects
164
165 void createBusService();
167 void setConnection(DBusConnection *connection, const QDBusErrorInternal &error);
168 void setServer(QDBusServer *object, DBusServer *server, const QDBusErrorInternal &error);
169 void closeConnection();
170
171 QString getNameOwner(const QString &service);
172
173 bool shouldWatchService(const QString &service);
174 void watchService(const QString &service, QDBusServiceWatcher::WatchMode mode,
175 QObject *obj, const char *member);
176 void unwatchService(const QString &service, QDBusServiceWatcher::WatchMode mode,
177 QObject *obj, const char *member);
178
179 bool send(const QDBusMessage &message);
180 QDBusMessage sendWithReply(const QDBusMessage &message, QDBus::CallMode mode, int timeout = -1);
181 QDBusMessage sendWithReplyLocal(const QDBusMessage &message);
182 QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
183 const char *returnMethod, const char *errorMethod,int timeout = -1);
184
185 bool connectSignal(const QString &service, const QString &path, const QString& interface,
186 const QString &name, const QStringList &argumentMatch, const QString &signature,
187 QObject *receiver, const char *slot);
188 bool disconnectSignal(const QString &service, const QString &path, const QString& interface,
189 const QString &name, const QStringList &argumentMatch, const QString &signature,
190 QObject *receiver, const char *slot);
191 bool connectSignal(const QString &service, const QString &path, const QString& interface,
192 const QString &name, const ArgMatchRules &argumentMatch, const QString &signature,
193 QObject *receiver, const char *slot);
194 bool disconnectSignal(const QString &service, const QString &path, const QString& interface,
195 const QString &name, const ArgMatchRules &argumentMatch, const QString &signature,
196 QObject *receiver, const char *slot);
197 void registerObject(const ObjectTreeNode *node);
198 void unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode);
199 void connectRelay(const QString &service,
200 const QString &path, const QString &interface,
201 QDBusAbstractInterface *receiver, const QMetaMethod &signal);
202 void disconnectRelay(const QString &service,
203 const QString &path, const QString &interface,
204 QDBusAbstractInterface *receiver, const QMetaMethod &signal);
205 void registerService(const QString &serviceName);
206 void unregisterService(const QString &serviceName);
207
208 bool handleMessage(const QDBusMessage &msg);
209
210 QDBusMetaObject *findMetaObject(const QString &service, const QString &path,
212
213 void postEventToThread(int action, QObject *target, QEvent *event);
214
215 void enableDispatchDelayed(QObject *context);
216
217private:
218 void checkThread();
219 bool handleError(const QDBusErrorInternal &error);
220
221 void handleSignal(const QString &key, const QDBusMessage &msg);
222 void handleSignal(const QDBusMessage &msg);
223 void handleObjectCall(const QDBusMessage &message);
224
225 void activateSignal(const SignalHook& hook, const QDBusMessage &msg);
226 void activateObject(ObjectTreeNode &node, const QDBusMessage &msg, int pathStartPos);
227 bool activateInternalFilters(const ObjectTreeNode &node, const QDBusMessage &msg);
228 bool activateCall(QObject *object, QDBusConnection::RegisterOptions flags,
229 const QDBusMessage &msg);
230
231 void sendInternal(QDBusPendingCallPrivate *pcall, void *msg, int timeout);
232 void sendError(const QDBusMessage &msg, QDBusError::ErrorType code);
233 void deliverCall(QObject *object, const QDBusMessage &msg, const QList<QMetaType> &metaTypes,
234 int slotIdx);
235
236 SignalHookHash::Iterator removeSignalHookNoLock(SignalHookHash::Iterator it);
237 void collectAllObjects(ObjectTreeNode &node, QSet<QObject *> &set);
238
239 bool isServiceRegisteredByThread(const QString &serviceName);
240
241 QString getNameOwnerNoCache(const QString &service);
242
243 void watchForDBusDisconnection();
244
245 void handleAuthentication();
246
247 bool addSignalHook(const QString &key, const SignalHook &hook);
248 bool removeSignalHook(const QString &key, const SignalHook &hook);
249
250 bool addSignalHookImpl(const QString &key, const SignalHook &hook);
251 bool removeSignalHookImpl(const QString &key, const SignalHook &hook);
252
253protected:
254 void timerEvent(QTimerEvent *e) override;
255
256public slots:
257 // public slots
258 void setDispatchEnabled(bool enable);
259 void doDispatch();
260 void socketRead(qintptr);
261 void socketWrite(qintptr);
262 void objectDestroyed(QObject *o);
263 void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args);
264
265private slots:
266 void serviceOwnerChangedNoLock(const QString &name, const QString &oldOwner, const QString &newOwner);
267 void registerServiceNoLock(const QString &serviceName);
268 void unregisterServiceNoLock(const QString &serviceName);
269 void handleDBusDisconnection();
270
271signals:
274 void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout = -1);
275 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
277
278public:
281 QDBusConnection::ConnectionCapabilities connectionCapabilities() const
282 {
283 return (QDBusConnection::ConnectionCapabilities)capabilities.loadRelaxed();
284 }
285 QString name; // this connection's name
286 QString baseService; // this connection's base service
288
290 union {
293 };
294
295 union {
297 DBusServer *server;
298 };
302
303 // the master lock protects our own internal state
306
314
316 bool dispatchEnabled; // protected by the dispatch lock, not the main lock
318
319 // static methods
320 static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> &params,
321 QString &errorMsg);
322 static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
323 const QString &service, const QString &path, const QString &interface,
324 const QString &name, const ArgMatchRules &argMatch, QObject *receiver,
325 const char *signal, int minMIdx, bool buildSignature,
326 QString &errorMsg);
327 static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object,
328 int idx, const QList<QMetaType> &metaTypes,
329 const QDBusMessage &msg);
330 static void processFinishedCall(QDBusPendingCallPrivate *call);
331
332 static QDBusConnectionPrivate *d(const QDBusConnection& q) { return q.d; }
334
337 friend class QDBusServer;
338};
339
340// in qdbusmisc.cpp
341extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<QMetaType> &metaTypes, QString &errorMsg);
342# endif // QT_BOOTSTRAPPED
343extern Q_DBUS_EXPORT int qDBusParametersForMethod(const QList<QByteArray> &parameters,
344 QList<QMetaType> &metaTypes, QString &errorMsg);
345extern Q_DBUS_EXPORT bool qDBusCheckAsyncTag(const char *tag);
346#ifndef QT_BOOTSTRAPPED
347extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
349
350// in qdbusinternalfilters.cpp
353 const QDBusMessage &msg);
355 const QDBusMessage &msg);
357 const QDBusMessage &msg);
358
359#endif // QT_BOOTSTRAPPED
360
362
363#endif // QT_NO_DBUS
364#endif
Connects to the accessibility dbus.
Definition main.cpp:8
\inmodule QtCore
Definition qatomic.h:112
T loadRelaxed() const noexcept
\inmodule QtCore
Definition qbytearray.h:57
static QDBusConnectionPrivate * d(const QDBusConnection &q)
PendingMessageList pendingMessages
WatchedServicesHash watchedServices
QMultiHash< qintptr, Watcher > WatcherHash
MatchRefCountHash matchRefCounts
QHash< QByteArray, int > MatchRefCountHash
static QDBusConnection q(QDBusConnectionPrivate *connection)
QList< QDBusPendingCallPrivate * > PendingCallList
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
QHash< int, DBusTimeout * > TimeoutHash
QDBusConnection::ConnectionCapabilities connectionCapabilities() const
void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout=-1)
QDBusConnectionInterface * busService
void spyHooksFinished(const QDBusMessage &msg)
QMultiHash< QString, SignalHook > SignalHookHash
QHash< QString, WatchedServiceData > WatchedServicesHash
MetaObjectHash cachedMetaObjects
QHash< QString, QDBusMetaObject * > MetaObjectHash
QList< QDBusMessage > PendingMessageList
DBusConnection * connection
void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message)
\inmodule QtDBus
UnregisterMode
The mode for unregistering an object path:
\inmodule QtDBus
Definition qdbuserror.h:21
ErrorType
In order to facilitate verification of the most common D-Bus errors generated by the D-Bus implementa...
Definition qdbuserror.h:24
\inmodule QtDBus
\inmodule QtDBus
Definition qdbusserver.h:21
\inmodule QtCore
Definition qcoreevent.h:45
\inmodule QtCore
Definition qmetaobject.h:19
\inmodule QtCore
Definition qobject.h:103
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Definition qobject.cpp:1470
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
QSet< QString >::iterator it
auto signal
auto mo
[7]
CallMode
This enum describes the various ways of placing a function call.
Combined button and popup list for selecting options.
static void * context
AudioChannelLayoutTag tag
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch * watch
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
DBusConnection const char DBusError * error
DBusConnection * connection
bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node, const QString &path)
QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
Definition qdbusmisc.cpp:42
QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
int qDBusParametersForMethod(const QMetaMethod &mm, QList< QMetaType > &metaTypes, QString &errorMsg)
Q_DBUS_EXPORT bool qDBusCheckAsyncTag(const char *tag)
Definition qdbusmisc.cpp:25
QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, const QString &signature_, QList< QMetaType > &metaTypes)
static QByteArray normalizedName(QAnyStringView name)
GLenum mode
GLuint64 key
GLbitfield GLuint64 timeout
[4]
GLenum target
GLbitfield flags
GLboolean enable
GLuint GLsizei const GLchar * message
GLuint name
GLfloat n
void ** params
struct _cl_event * event
GLhandleARB obj
[2]
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
#define Q_AUTOTEST_EXPORT
#define Q_OBJECT
#define Q_MOC_INCLUDE(...)
#define slots
#define signals
ptrdiff_t qintptr
Definition qtypes.h:166
ReturnedValue read(const char *data)
QFuture< QSet< QChar > > set
[10]
gzip write("uncompressed data")
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
clientDtls setPeer(address, port, peerName)
QJSValueList args
bool operator==(const ArgMatchRules &other) const
bool operator<(const QString &other) const
bool operator<(QStringView other) const
QDBusConnection::RegisterOptions flags
WatchedServiceData(const QString &owner, int refcount=0)
\inmodule QtCore