1 /* qdbusconnection.h QDBusConnection object
3 * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
4 * Copyright (C) 2006 Trolltech AS. All rights reserved.
5 * Author: Thiago Macieira <thiago.macieira@trolltech.com>
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #ifndef QDBUSCONNECTION_H
26 #define QDBUSCONNECTION_H
28 #include "qdbusmacros.h"
29 #include <QtCore/qstring.h>
31 class QDBusAbstractInterfacePrivate;
35 class QDBusBusService;
38 class QDBusConnectionPrivate;
39 class QDBUS_EXPORT QDBusConnection
42 enum BusType { SessionBus, SystemBus, ActivationBus };
43 enum WaitMode { UseEventLoop, NoUseEventLoop };
45 ExportAdaptors = 0x01,
49 ExportProperties = 0x40,
50 ExportContents = 0xf0,
52 ExportAllSlots = 0x110,
53 ExportAllSignals = 0x220,
54 ExportAllProperties = 0x440,
55 ExportAllContents = 0xff0,
57 ExportChildObjects = 0x1000
64 Q_DECLARE_FLAGS(RegisterOptions, RegisterOption);
66 QDBusConnection(const QString &name);
67 QDBusConnection(const QDBusConnection &other);
70 QDBusConnection &operator=(const QDBusConnection &other);
72 bool isConnected() const;
73 QString baseService() const;
74 QDBusError lastError() const;
76 bool send(const QDBusMessage &message) const;
77 QDBusMessage sendWithReply(const QDBusMessage &message, WaitMode mode = NoUseEventLoop) const;
78 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
79 const char *slot) const;
81 bool connect(const QString &service, const QString &path, const QString &interface,
82 const QString &name, QObject *receiver, const char *slot);
83 bool connect(const QString &service, const QString &path, const QString &interface,
84 const QString &name, const QString& signature,
85 QObject *receiver, const char *slot);
87 bool registerObject(const QString &path, QObject *object,
88 RegisterOptions options = ExportAdaptors);
89 void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode);
91 template<class Interface>
92 inline Interface *findInterface(const QString &service, const QString &path);
93 QDBusInterface *findInterface(const QString& service, const QString& path,
94 const QString& interface = QString());
96 QDBusBusService *busService() const;
98 static QDBusConnection addConnection(BusType type, const QString &name);
99 static QDBusConnection addConnection(const QString &address, const QString &name);
100 static void closeConnection(const QString &name);
103 QDBusAbstractInterfacePrivate *findInterface_helper(const QString &, const QString &,
105 QDBusConnectionPrivate *d;
108 template<class Interface>
109 inline Interface *QDBusConnection::findInterface(const QString &service, const QString &path)
111 register QDBusAbstractInterfacePrivate *d;
112 d = findInterface_helper(service, path, Interface::staticInterfaceName());
114 return new Interface(d);
119 QDBUS_EXPORT QDBusConnection &sessionBus();
120 QDBUS_EXPORT QDBusConnection &systemBus();
123 Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions)