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 | #ifndef QDBUSCONNECTION_H |
42 | #define QDBUSCONNECTION_H |
43 | |
44 | #include <QtDBus/qtdbusglobal.h> |
45 | #include <QtCore/qobjectdefs.h> |
46 | #include <QtCore/qstring.h> |
47 | |
48 | #ifndef QT_NO_DBUS |
49 | |
50 | #ifdef interface |
51 | # undef interface |
52 | #endif |
53 | |
54 | QT_BEGIN_NAMESPACE |
55 | |
56 | |
57 | namespace QDBus |
58 | { |
59 | enum CallMode { |
60 | NoBlock, |
61 | Block, |
62 | BlockWithGui, |
63 | AutoDetect |
64 | }; |
65 | } |
66 | |
67 | class QDBusAbstractInterfacePrivate; |
68 | class QDBusInterface; |
69 | class QDBusError; |
70 | class QDBusMessage; |
71 | class QDBusPendingCall; |
72 | class QDBusConnectionInterface; |
73 | class QDBusVirtualObject; |
74 | class QObject; |
75 | |
76 | class QDBusConnectionPrivate; |
77 | class Q_DBUS_EXPORT QDBusConnection |
78 | { |
79 | Q_GADGET |
80 | public: |
81 | enum BusType { SessionBus, SystemBus, ActivationBus }; |
82 | Q_ENUM(BusType) |
83 | enum RegisterOption { |
84 | ExportAdaptors = 0x01, |
85 | |
86 | ExportScriptableSlots = 0x10, |
87 | ExportScriptableSignals = 0x20, |
88 | ExportScriptableProperties = 0x40, |
89 | ExportScriptableInvokables = 0x80, |
90 | ExportScriptableContents = 0xf0, |
91 | |
92 | ExportNonScriptableSlots = 0x100, |
93 | ExportNonScriptableSignals = 0x200, |
94 | ExportNonScriptableProperties = 0x400, |
95 | ExportNonScriptableInvokables = 0x800, |
96 | ExportNonScriptableContents = 0xf00, |
97 | |
98 | ExportAllSlots = ExportScriptableSlots|ExportNonScriptableSlots, |
99 | ExportAllSignals = ExportScriptableSignals|ExportNonScriptableSignals, |
100 | ExportAllProperties = ExportScriptableProperties|ExportNonScriptableProperties, |
101 | ExportAllInvokables = ExportScriptableInvokables|ExportNonScriptableInvokables, |
102 | ExportAllContents = ExportScriptableContents|ExportNonScriptableContents, |
103 | |
104 | #ifndef Q_QDOC |
105 | // Qt 4.2 had a misspelling here |
106 | ExportAllSignal = ExportAllSignals, |
107 | #endif |
108 | ExportChildObjects = 0x1000 |
109 | // Reserved = 0xff000000 |
110 | }; |
111 | Q_DECLARE_FLAGS(RegisterOptions, RegisterOption) |
112 | Q_FLAG(RegisterOptions) |
113 | |
114 | enum UnregisterMode { |
115 | UnregisterNode, |
116 | UnregisterTree |
117 | }; |
118 | Q_ENUM(UnregisterMode) |
119 | |
120 | enum VirtualObjectRegisterOption { |
121 | SingleNode = 0x0, |
122 | SubPath = 0x1 |
123 | // Reserved = 0xff000000 |
124 | }; |
125 | Q_DECLARE_FLAGS(VirtualObjectRegisterOptions, VirtualObjectRegisterOption) |
126 | |
127 | enum ConnectionCapability { |
128 | UnixFileDescriptorPassing = 0x0001 |
129 | }; |
130 | Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability) |
131 | |
132 | explicit QDBusConnection(const QString &name); |
133 | QDBusConnection(const QDBusConnection &other); |
134 | QDBusConnection(QDBusConnection &&other) noexcept : d(other.d) { other.d = nullptr; } |
135 | QDBusConnection &operator=(QDBusConnection &&other) noexcept { swap(other); return *this; } |
136 | QDBusConnection &operator=(const QDBusConnection &other); |
137 | ~QDBusConnection(); |
138 | |
139 | void swap(QDBusConnection &other) noexcept { qSwap(d, other.d); } |
140 | |
141 | bool isConnected() const; |
142 | QString baseService() const; |
143 | QDBusError lastError() const; |
144 | QString name() const; |
145 | ConnectionCapabilities connectionCapabilities() const; |
146 | |
147 | bool send(const QDBusMessage &message) const; |
148 | bool callWithCallback(const QDBusMessage &message, QObject *receiver, |
149 | const char *returnMethod, const char *errorMethod, |
150 | int timeout = -1) const; |
151 | bool callWithCallback(const QDBusMessage &message, QObject *receiver, |
152 | const char *slot, int timeout = -1) const; |
153 | QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode = QDBus::Block, |
154 | int timeout = -1) const; |
155 | QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout = -1) const; |
156 | |
157 | bool connect(const QString &service, const QString &path, const QString &interface, |
158 | const QString &name, QObject *receiver, const char *slot); |
159 | bool connect(const QString &service, const QString &path, const QString &interface, |
160 | const QString &name, const QString& signature, |
161 | QObject *receiver, const char *slot); |
162 | bool connect(const QString &service, const QString &path, const QString &interface, |
163 | const QString &name, const QStringList &argumentMatch, const QString& signature, |
164 | QObject *receiver, const char *slot); |
165 | |
166 | bool disconnect(const QString &service, const QString &path, const QString &interface, |
167 | const QString &name, QObject *receiver, const char *slot); |
168 | bool disconnect(const QString &service, const QString &path, const QString &interface, |
169 | const QString &name, const QString& signature, |
170 | QObject *receiver, const char *slot); |
171 | bool disconnect(const QString &service, const QString &path, const QString &interface, |
172 | const QString &name, const QStringList &argumentMatch, const QString& signature, |
173 | QObject *receiver, const char *slot); |
174 | |
175 | bool registerObject(const QString &path, QObject *object, |
176 | RegisterOptions options = ExportAdaptors); |
177 | bool registerObject(const QString &path, const QString &interface, QObject *object, |
178 | RegisterOptions options = ExportAdaptors); |
179 | void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode); |
180 | QObject *objectRegisteredAt(const QString &path) const; |
181 | |
182 | bool registerVirtualObject(const QString &path, QDBusVirtualObject *object, |
183 | VirtualObjectRegisterOption options = SingleNode); |
184 | |
185 | bool registerService(const QString &serviceName); |
186 | bool unregisterService(const QString &serviceName); |
187 | |
188 | QDBusConnectionInterface *interface() const; |
189 | |
190 | void *internalPointer() const; |
191 | |
192 | static QDBusConnection connectToBus(BusType type, const QString &name); |
193 | static QDBusConnection connectToBus(const QString &address, const QString &name); |
194 | static QDBusConnection connectToPeer(const QString &address, const QString &name); |
195 | static void disconnectFromBus(const QString &name); |
196 | static void disconnectFromPeer(const QString &name); |
197 | |
198 | static QByteArray localMachineId(); |
199 | |
200 | static QDBusConnection sessionBus(); |
201 | static QDBusConnection systemBus(); |
202 | |
203 | #if QT_DEPRECATED_SINCE(5,5) |
204 | static QT_DEPRECATED_X("This function no longer works, use QDBusContext instead" ) |
205 | QDBusConnection sender(); |
206 | #endif |
207 | |
208 | protected: |
209 | explicit QDBusConnection(QDBusConnectionPrivate *dd); |
210 | |
211 | private: |
212 | friend class QDBusConnectionPrivate; |
213 | QDBusConnectionPrivate *d; |
214 | }; |
215 | Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusConnection) |
216 | |
217 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions) |
218 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::VirtualObjectRegisterOptions) |
219 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::ConnectionCapabilities) |
220 | |
221 | QT_END_NAMESPACE |
222 | |
223 | #endif // QT_NO_DBUS |
224 | #endif |
225 | |