* dbus/dbus-sysdeps.c: Make tcp socket connection error somewhat more
[platform/upstream/dbus.git] / qt / qdbusabstractinterface.h
1 /* -*- C++ -*-
2  *
3  * Copyright (C) 2005 Thiago Macieira <thiago@kde.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 QDBUSABSTRACTINTERFACE_H
26 #define QDBUSABSTRACTINTERFACE_H
27
28 #include <QtCore/qstring.h>
29 #include <QtCore/qvariant.h>
30 #include <QtCore/qlist.h>
31 #include <QtCore/qobject.h>
32
33 #include "qdbusmessage.h"
34 #include "qdbustypehelper_p.h"
35
36 class QDBusConnection;
37 class QDBusError;
38
39 class QDBusAbstractInterfacePrivate;
40 class QDBUS_EXPORT QDBusAbstractInterface: public QObject
41 {
42     Q_OBJECT
43
44 public:
45     enum CallMode {
46         NoWaitForReply,
47         UseEventLoop,
48         NoUseEventLoop,
49         AutoDetect
50     };
51
52 public:
53     virtual ~QDBusAbstractInterface();
54     bool isValid() const;
55
56     QDBusConnection connection() const;
57
58     QString service() const;
59     QString path() const;
60     QString interface() const;
61
62     QDBusError lastError() const;
63
64     QDBusMessage callWithArgs(const QString &method, const QList<QVariant> &args = QList<QVariant>(),
65                               CallMode mode = AutoDetect);
66     bool callWithArgs(const QString &method, QObject *receiver, const char *slot,
67                       const QList<QVariant> &args = QList<QVariant>());
68
69     inline QDBusMessage call(const QString &m)
70     {
71         return callWithArgs(m);
72     }
73
74     inline QDBusMessage call(CallMode mode, const QString &m)
75     {
76         return callWithArgs(m, QList<QVariant>(), mode);
77     }
78     
79 #ifndef Q_QDOC
80 private:
81     template<typename T> inline QVariant qvfv(const T &t)
82     { return QDBusTypeHelper<T>::toVariant(t); }
83     
84 public:
85     template<typename T1>
86     inline QDBusMessage call(const QString &m, const T1 &t1)
87     {
88         QList<QVariant> args;
89         args << qvfv(t1);
90         return callWithArgs(m, args);
91     }
92
93     template<typename T1, typename T2>
94     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2)
95     {
96         QList<QVariant> args;
97         args << qvfv(t1) << qvfv(t2);
98         return callWithArgs(m, args);
99     }
100
101     template<typename T1, typename T2, typename T3>
102     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3)
103     {
104         QList<QVariant> args;
105         args << qvfv(t1) << qvfv(t2) << qvfv(t3);
106         return callWithArgs(m, args);
107     }
108       
109     template<typename T1, typename T2, typename T3, typename T4>
110     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3,
111                              const T4 &t4)
112     {
113         QList<QVariant> args;
114         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
115              << qvfv(t4);
116         return callWithArgs(m, args);
117     }
118
119     template<typename T1, typename T2, typename T3, typename T4, typename T5>
120     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3,
121                              const T4 &t4, const T5 &t5)
122     {
123         QList<QVariant> args;
124         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
125              << qvfv(t4) << qvfv(t5);
126         return callWithArgs(m, args);
127     }
128   
129     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
130     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3,
131                              const T4 &t4, const T5 &t5, const T6 &t6)
132     {
133         QList<QVariant> args;
134         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
135              << qvfv(t4) << qvfv(t5) << qvfv(t6);
136         return callWithArgs(m, args);
137     }
138
139     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
140     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3,
141                              const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7)
142     {
143         QList<QVariant> args;
144         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
145              << qvfv(t4) << qvfv(t5) << qvfv(t6)
146              << qvfv(t7);
147         return callWithArgs(m, args);
148     }
149
150     template<typename T1, typename T2, typename T3, typename T4, typename T5,
151              typename T6, typename T7, typename T8>
152     inline QDBusMessage call(const QString &m, const T1 &t1, const T2 &t2, const T3 &t3,
153                              const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7, const T8 &t8)
154     {
155         QList<QVariant> args;
156         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
157              << qvfv(t4) << qvfv(t5) << qvfv(t6)
158              << qvfv(t7) << qvfv(t8);
159         return callWithArgs(m, args);
160     }
161
162     template<typename T1>
163     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1)
164     {
165         QList<QVariant> args;
166         args << qvfv(t1);
167         return callWithArgs(m, args, mode);
168     }
169
170     template<typename T1, typename T2>
171     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2)
172     {
173         QList<QVariant> args;
174         args << qvfv(t1) << qvfv(t2);
175         return callWithArgs(m, args, mode);
176     }
177
178     template<typename T1, typename T2, typename T3>
179     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
180                              const T3 &t3)
181     {
182         QList<QVariant> args;
183         args << qvfv(t1) << qvfv(t2) << qvfv(t3);
184         return callWithArgs(m, args, mode);
185     }
186       
187     template<typename T1, typename T2, typename T3, typename T4>
188     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
189                              const T3 &t3, const T4 &t4)
190     {
191         QList<QVariant> args;
192         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
193              << qvfv(t4);
194         return callWithArgs(m, args, mode);
195     }
196
197     template<typename T1, typename T2, typename T3, typename T4, typename T5>
198     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
199                              const T3 &t3, const T4 &t4, const T5 &t5)
200     {
201         QList<QVariant> args;
202         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
203              << qvfv(t4) << qvfv(t5);
204         return callWithArgs(m, args, mode);
205     }
206   
207     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
208     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
209                              const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6)
210     {
211         QList<QVariant> args;
212         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
213              << qvfv(t4) << qvfv(t5) << qvfv(t6);
214         return callWithArgs(m, args, mode);
215     }
216
217     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
218     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
219                              const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7)
220     {
221         QList<QVariant> args;
222         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
223              << qvfv(t4) << qvfv(t5) << qvfv(t6)
224              << qvfv(t7);
225         return callWithArgs(m, args, mode);
226     }
227
228     template<typename T1, typename T2, typename T3, typename T4, typename T5,
229              typename T6, typename T7, typename T8>
230     inline QDBusMessage call(CallMode mode, const QString &m, const T1 &t1, const T2 &t2,
231                              const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7,
232                              const T8 &t8)
233     {
234         QList<QVariant> args;
235         args << qvfv(t1) << qvfv(t2) << qvfv(t3)
236              << qvfv(t4) << qvfv(t5) << qvfv(t6)
237              << qvfv(t7) << qvfv(t8);
238         return callWithArgs(m, args, mode);
239     }
240 #endif
241
242 protected:
243     QDBusAbstractInterface(QDBusAbstractInterfacePrivate *);
244     void connectNotify(const char *signal);
245     void disconnectNotify(const char *signal);
246     QVariant internalPropGet(const char *propname) const;
247     void internalPropSet(const char *propname, const QVariant &value);
248
249 private:
250     friend class QDBusInterface;
251     QDBusAbstractInterfacePrivate *d_ptr; // remove for Qt 4.2.0
252
253     Q_DECLARE_PRIVATE(QDBusAbstractInterface)
254     Q_DISABLE_COPY(QDBusAbstractInterface)
255 };
256
257 #endif