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

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