1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDBus module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDBUSCONNECTION_H
43 #define QDBUSCONNECTION_H
45 #include <QtDBus/qdbusmacros.h>
46 #include <QtCore/qstring.h>
65 class QDBusAbstractInterfacePrivate;
69 class QDBusPendingCall;
70 class QDBusConnectionInterface;
71 class QDBusVirtualObject;
74 class QDBusConnectionPrivate;
75 class Q_DBUS_EXPORT QDBusConnection
78 Q_ENUMS(BusType UnregisterMode)
79 Q_FLAGS(RegisterOptions)
81 enum BusType { SessionBus, SystemBus, ActivationBus };
83 ExportAdaptors = 0x01,
85 ExportScriptableSlots = 0x10,
86 ExportScriptableSignals = 0x20,
87 ExportScriptableProperties = 0x40,
88 ExportScriptableInvokables = 0x80,
89 ExportScriptableContents = 0xf0,
91 ExportNonScriptableSlots = 0x100,
92 ExportNonScriptableSignals = 0x200,
93 ExportNonScriptableProperties = 0x400,
94 ExportNonScriptableInvokables = 0x800,
95 ExportNonScriptableContents = 0xf00,
97 ExportAllSlots = ExportScriptableSlots|ExportNonScriptableSlots,
98 ExportAllSignals = ExportScriptableSignals|ExportNonScriptableSignals,
99 ExportAllProperties = ExportScriptableProperties|ExportNonScriptableProperties,
100 ExportAllInvokables = ExportScriptableInvokables|ExportNonScriptableInvokables,
101 ExportAllContents = ExportScriptableContents|ExportNonScriptableContents,
104 // Qt 4.2 had a misspelling here
105 ExportAllSignal = ExportAllSignals,
107 ExportChildObjects = 0x1000
108 // Reserved = 0xff000000
110 enum UnregisterMode {
114 Q_DECLARE_FLAGS(RegisterOptions, RegisterOption)
116 enum VirtualObjectRegisterOption {
119 // Reserved = 0xff000000
122 Q_DECLARE_FLAGS(VirtualObjectRegisterOptions, VirtualObjectRegisterOption)
125 enum ConnectionCapability {
126 UnixFileDescriptorPassing = 0x0001
128 Q_DECLARE_FLAGS(ConnectionCapabilities, ConnectionCapability)
130 explicit QDBusConnection(const QString &name);
131 QDBusConnection(const QDBusConnection &other);
134 QDBusConnection &operator=(const QDBusConnection &other);
136 bool isConnected() const;
137 QString baseService() const;
138 QDBusError lastError() const;
139 QString name() const;
140 ConnectionCapabilities connectionCapabilities() const;
142 bool send(const QDBusMessage &message) const;
143 bool callWithCallback(const QDBusMessage &message, QObject *receiver,
144 const char *returnMethod, const char *errorMethod,
145 int timeout = -1) const;
146 bool callWithCallback(const QDBusMessage &message, QObject *receiver,
147 const char *slot, int timeout = -1) const;
148 QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode = QDBus::Block,
149 int timeout = -1) const;
150 QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout = -1) const;
152 bool connect(const QString &service, const QString &path, const QString &interface,
153 const QString &name, QObject *receiver, const char *slot);
154 bool connect(const QString &service, const QString &path, const QString &interface,
155 const QString &name, const QString& signature,
156 QObject *receiver, const char *slot);
157 bool connect(const QString &service, const QString &path, const QString &interface,
158 const QString &name, const QStringList &argumentMatch, const QString& signature,
159 QObject *receiver, const char *slot);
161 bool disconnect(const QString &service, const QString &path, const QString &interface,
162 const QString &name, QObject *receiver, const char *slot);
163 bool disconnect(const QString &service, const QString &path, const QString &interface,
164 const QString &name, const QString& signature,
165 QObject *receiver, const char *slot);
166 bool disconnect(const QString &service, const QString &path, const QString &interface,
167 const QString &name, const QStringList &argumentMatch, const QString& signature,
168 QObject *receiver, const char *slot);
170 bool registerObject(const QString &path, QObject *object,
171 RegisterOptions options = ExportAdaptors);
172 void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode);
173 QObject *objectRegisteredAt(const QString &path) const;
175 bool registerVirtualObject(const QString &path, QDBusVirtualObject *object,
176 VirtualObjectRegisterOption options = SingleNode);
178 bool registerService(const QString &serviceName);
179 bool unregisterService(const QString &serviceName);
181 QDBusConnectionInterface *interface() const;
183 void *internalPointer() const;
185 static QDBusConnection connectToBus(BusType type, const QString &name);
186 static QDBusConnection connectToBus(const QString &address, const QString &name);
187 static QDBusConnection connectToPeer(const QString &address, const QString &name);
188 static void disconnectFromBus(const QString &name);
189 static void disconnectFromPeer(const QString &name);
191 static QByteArray localMachineId();
193 static QDBusConnection sessionBus();
194 static QDBusConnection systemBus();
196 static QDBusConnection sender();
199 explicit QDBusConnection(QDBusConnectionPrivate *dd);
202 friend class QDBusConnectionPrivate;
203 QDBusConnectionPrivate *d;
206 Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions)
207 Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::VirtualObjectRegisterOptions)