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 QDBUSCONNECTIONMANAGER_P_H |
18 | #define QDBUSCONNECTIONMANAGER_P_H |
19 | |
20 | #include <QtDBus/private/qtdbusglobal_p.h> |
21 | #include "qdbusconnection_p.h" |
22 | #include "private/qthread_p.h" |
23 | |
24 | #ifndef QT_NO_DBUS |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QDBusConnectionManager : public QDaemonThread |
29 | { |
30 | Q_OBJECT |
31 | struct ConnectionRequestData; |
32 | public: |
33 | QDBusConnectionManager(); |
34 | ~QDBusConnectionManager(); |
35 | static QDBusConnectionManager* instance(); |
36 | |
37 | QDBusConnectionPrivate *busConnection(QDBusConnection::BusType type); |
38 | QDBusConnectionPrivate *connection(const QString &name) const; |
39 | void removeConnection(const QString &name); |
40 | void setConnection(const QString &name, QDBusConnectionPrivate *c); |
41 | QDBusConnectionPrivate *connectToBus(QDBusConnection::BusType type, const QString &name, bool suspendedDelivery); |
42 | QDBusConnectionPrivate *connectToBus(const QString &address, const QString &name); |
43 | QDBusConnectionPrivate *connectToPeer(const QString &address, const QString &name); |
44 | |
45 | mutable QMutex mutex; |
46 | |
47 | signals: |
48 | void connectionRequested(ConnectionRequestData *); |
49 | void serverRequested(const QString &address, void *server); |
50 | |
51 | protected: |
52 | void run() override; |
53 | |
54 | private: |
55 | void executeConnectionRequest(ConnectionRequestData *data); |
56 | void createServer(const QString &address, void *server); |
57 | |
58 | QHash<QString, QDBusConnectionPrivate *> connectionHash; |
59 | |
60 | QMutex defaultBusMutex; |
61 | QDBusConnectionPrivate *defaultBuses[2]; |
62 | |
63 | mutable QMutex senderMutex; |
64 | QString senderName; // internal; will probably change |
65 | }; |
66 | |
67 | // TODO: move into own header and use Q_MOC_INCLUDE |
68 | struct QDBusConnectionManager::ConnectionRequestData |
69 | { |
70 | enum RequestType { |
71 | ConnectToStandardBus, |
72 | ConnectToBusByAddress, |
73 | ConnectToPeerByAddress |
74 | } type; |
75 | |
76 | union { |
77 | QDBusConnection::BusType busType; |
78 | const QString *busAddress; |
79 | }; |
80 | const QString *name; |
81 | |
82 | QDBusConnectionPrivate *result; |
83 | |
84 | bool suspendedDelivery; |
85 | }; |
86 | |
87 | QT_END_NAMESPACE |
88 | |
89 | #endif // QT_NO_DBUS |
90 | #endif |
91 | |