1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtDBus module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDBUSCONNECTION_H
43#define QDBUSCONNECTION_H
44
45#include <QtDBus/qdbusmacros.h>
46#include <QtCore/qstring.h>
47
48#ifndef QT_NO_DBUS
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(DBus)
55
56namespace QDBus
57{
58 enum CallMode {
59 NoBlock,
60 Block,
61 BlockWithGui,
62 AutoDetect
63 };
64}
65
66class QDBusAbstractInterfacePrivate;
67class QDBusInterface;
68class QDBusError;
69class QDBusMessage;
70class QDBusPendingCall;
71class QDBusConnectionInterface;
72class QDBusVirtualObject;
73class QObject;
74
75class QDBusConnectionPrivate;
76class Q_DBUS_EXPORT QDBusConnection
77{
78 Q_GADGET
79 Q_ENUMS(BusType UnregisterMode)
80 Q_FLAGS(RegisterOptions)
81public:
82 enum BusType { SessionBus, SystemBus, ActivationBus };
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 enum UnregisterMode {
112 UnregisterNode,
113 UnregisterTree
114 };
115 Q_DECLARE_FLAGS(RegisterOptions, RegisterOption)
116
117 enum VirtualObjectRegisterOption {
118 SingleNode = 0x0,
119 SubPath = 0x1
120 // Reserved = 0xff000000
121 };
122#ifndef Q_QDOC
123 Q_DECLARE_FLAGS(VirtualObjectRegisterOptions, VirtualObjectRegisterOption)
124#endif
125
126 enum ConnectionCapability {
127 UnixFileDescriptorPassing = 0x0001
128 };
129 Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability)
130
131 QDBusConnection(const QString &name);
132 QDBusConnection(const QDBusConnection &other);
133 ~QDBusConnection();
134
135 QDBusConnection &operator=(const QDBusConnection &other);
136
137 bool isConnected() const;
138 QString baseService() const;
139 QDBusError lastError() const;
140 QString name() const;
141 ConnectionCapabilities connectionCapabilities() const;
142
143 bool send(const QDBusMessage &message) const;
144 bool callWithCallback(const QDBusMessage &message, QObject *receiver,
145 const char *returnMethod, const char *errorMethod,
146 int timeout = -1) const;
147 bool callWithCallback(const QDBusMessage &message, QObject *receiver,
148 const char *slot, int timeout = -1) const;
149 QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode = QDBus::Block,
150 int timeout = -1) const;
151 QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout = -1) const;
152
153 bool connect(const QString &service, const QString &path, const QString &interface,
154 const QString &name, QObject *receiver, const char *slot);
155 bool connect(const QString &service, const QString &path, const QString &interface,
156 const QString &name, const QString& signature,
157 QObject *receiver, const char *slot);
158 bool connect(const QString &service, const QString &path, const QString &interface,
159 const QString &name, const QStringList &argumentMatch, const QString& signature,
160 QObject *receiver, const char *slot);
161
162 bool disconnect(const QString &service, const QString &path, const QString &interface,
163 const QString &name, QObject *receiver, const char *slot);
164 bool disconnect(const QString &service, const QString &path, const QString &interface,
165 const QString &name, const QString& signature,
166 QObject *receiver, const char *slot);
167 bool disconnect(const QString &service, const QString &path, const QString &interface,
168 const QString &name, const QStringList &argumentMatch, const QString& signature,
169 QObject *receiver, const char *slot);
170
171 bool registerObject(const QString &path, QObject *object,
172 RegisterOptions options = ExportAdaptors);
173 void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode);
174 QObject *objectRegisteredAt(const QString &path) const;
175
176 bool registerVirtualObject(const QString &path, QDBusVirtualObject *object,
177 VirtualObjectRegisterOption options = SingleNode);
178
179 bool registerService(const QString &serviceName);
180 bool unregisterService(const QString &serviceName);
181
182 QDBusConnectionInterface *interface() const;
183
184 void *internalPointer() const;
185
186 static QDBusConnection connectToBus(BusType type, const QString &name);
187 static QDBusConnection connectToBus(const QString &address, const QString &name);
188 static QDBusConnection connectToPeer(const QString &address, const QString &name);
189 static void disconnectFromBus(const QString &name);
190 static void disconnectFromPeer(const QString &name);
191
192 static QByteArray localMachineId();
193
194 static QDBusConnection sessionBus();
195 static QDBusConnection systemBus();
196
197 static QDBusConnection sender();
198
199protected:
200 explicit QDBusConnection(QDBusConnectionPrivate *dd);
201
202private:
203 friend class QDBusConnectionPrivate;
204 QDBusConnectionPrivate *d;
205};
206
207Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions)
208Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::VirtualObjectRegisterOptions)
209
210QT_END_NAMESPACE
211
212QT_END_HEADER
213
214#endif // QT_NO_DBUS
215#endif
216