* dbus/dbus-sysdeps.c: Make tcp socket connection error somewhat more
[platform/upstream/dbus.git] / qt / qdbusconnection.h
1 /* qdbusconnection.h QDBusConnection object
2  *
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>
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
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.
13  *
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.
18  *
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.
22  *
23  */
24
25 #ifndef QDBUSCONNECTION_H
26 #define QDBUSCONNECTION_H
27
28 #include "qdbusmacros.h"
29 #include <QtCore/qstring.h>
30
31 class QDBusAbstractInterfacePrivate;
32 class QDBusInterface;
33 class QDBusError;
34 class QDBusMessage;
35 class QDBusBusService;
36 class QObject;
37
38 class QDBusConnectionPrivate;
39 class QDBUS_EXPORT QDBusConnection
40 {
41 public:
42     enum BusType { SessionBus, SystemBus, ActivationBus };
43     enum WaitMode { UseEventLoop, NoUseEventLoop };
44     enum RegisterOption {
45         ExportAdaptors = 0x01,
46
47         ExportSlots = 0x10,
48         ExportSignals = 0x20,
49         ExportProperties = 0x40,
50         ExportContents = 0xf0,
51
52         ExportAllSlots = 0x110,
53         ExportAllSignals = 0x220,
54         ExportAllProperties = 0x440,
55         ExportAllContents = 0xff0,
56
57         ExportChildObjects = 0x1000
58     };
59     enum UnregisterMode {
60         UnregisterNode,
61         UnregisterTree
62     };
63
64     Q_DECLARE_FLAGS(RegisterOptions, RegisterOption);
65
66     QDBusConnection(const QString &name);
67     QDBusConnection(const QDBusConnection &other);
68     ~QDBusConnection();
69
70     QDBusConnection &operator=(const QDBusConnection &other);
71
72     bool isConnected() const;
73     QString baseService() const;
74     QDBusError lastError() const;
75
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;
80
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);
86
87     bool registerObject(const QString &path, QObject *object,
88                         RegisterOptions options = ExportAdaptors);
89     void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode);
90
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());
95
96     QDBusBusService *busService() const;
97
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);
101
102 private:
103     QDBusAbstractInterfacePrivate *findInterface_helper(const QString &, const QString &,
104                                                         const QString&);
105     QDBusConnectionPrivate *d;
106 };
107
108 template<class Interface>
109 inline Interface *QDBusConnection::findInterface(const QString &service, const QString &path)
110 {
111     register QDBusAbstractInterfacePrivate *d;
112     d = findInterface_helper(service, path, Interface::staticInterfaceName());
113     if (d)
114         return new Interface(d);
115     return 0;
116 }
117
118 namespace QDBus {
119     QDBUS_EXPORT QDBusConnection &sessionBus();
120     QDBUS_EXPORT QDBusConnection &systemBus();
121 }
122
123 Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions)
124 #endif