1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDBUSABSTRACTINTERFACE_H
41#define QDBUSABSTRACTINTERFACE_H
42
43#include <QtDBus/qtdbusglobal.h>
44#include <QtCore/qstring.h>
45#include <QtCore/qvariant.h>
46#include <QtCore/qlist.h>
47#include <QtCore/qobject.h>
48
49#include <QtDBus/qdbusmessage.h>
50#include <QtDBus/qdbusextratypes.h>
51#include <QtDBus/qdbusconnection.h>
52#include <QtDBus/qdbuspendingcall.h>
53
54#ifdef interface
55#undef interface
56#endif
57
58#ifndef QT_NO_DBUS
59
60QT_BEGIN_NAMESPACE
61
62
63class QDBusError;
64class QDBusPendingCall;
65
66class QDBusAbstractInterfacePrivate;
67
68class Q_DBUS_EXPORT QDBusAbstractInterfaceBase: public QObject
69{
70public:
71 int qt_metacall(QMetaObject::Call, int, void**) override;
72protected:
73 QDBusAbstractInterfaceBase(QDBusAbstractInterfacePrivate &dd, QObject *parent);
74private:
75 Q_DECLARE_PRIVATE(QDBusAbstractInterface)
76};
77
78class Q_DBUS_EXPORT QDBusAbstractInterface:
79#ifdef Q_QDOC
80 public QObject
81#else
82 public QDBusAbstractInterfaceBase
83#endif
84{
85 Q_OBJECT
86
87public:
88 virtual ~QDBusAbstractInterface();
89 bool isValid() const;
90
91 QDBusConnection connection() const;
92
93 QString service() const;
94 QString path() const;
95 QString interface() const;
96
97 QDBusError lastError() const;
98
99 void setTimeout(int timeout);
100 int timeout() const;
101
102 QDBusMessage call(const QString &method)
103 {
104 return doCall(QDBus::AutoDetect, method, nullptr, 0);
105 }
106
107 template <typename...Args>
108 QDBusMessage call(const QString &method, Args &&...args)
109 {
110 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
111 return doCall(QDBus::AutoDetect, method, variants, sizeof...(args));
112 }
113
114 QDBusMessage call(QDBus::CallMode mode, const QString &method)
115 {
116 return doCall(mode, method, nullptr, 0);
117 }
118
119 template <typename...Args>
120 QDBusMessage call(QDBus::CallMode mode, const QString &method, Args &&...args)
121 {
122 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
123 return doCall(mode, method, variants, sizeof...(args));
124 }
125
126 QDBusMessage callWithArgumentList(QDBus::CallMode mode,
127 const QString &method,
128 const QList<QVariant> &args);
129
130 bool callWithCallback(const QString &method,
131 const QList<QVariant> &args,
132 QObject *receiver, const char *member, const char *errorSlot);
133 bool callWithCallback(const QString &method,
134 const QList<QVariant> &args,
135 QObject *receiver, const char *member);
136
137 QDBusPendingCall asyncCall(const QString &method)
138 {
139 return doAsyncCall(method, nullptr, 0);
140 }
141
142 template <typename...Args>
143 QDBusPendingCall asyncCall(const QString &method, Args&&...args)
144 {
145 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
146 return doAsyncCall(method, variants, sizeof...(args));
147 }
148
149 QDBusPendingCall asyncCallWithArgumentList(const QString &method,
150 const QList<QVariant> &args);
151
152protected:
153 QDBusAbstractInterface(const QString &service, const QString &path, const char *interface,
154 const QDBusConnection &connection, QObject *parent);
155 QDBusAbstractInterface(QDBusAbstractInterfacePrivate &, QObject *parent);
156
157 void connectNotify(const QMetaMethod &signal) override;
158 void disconnectNotify(const QMetaMethod &signal) override;
159 QVariant internalPropGet(const char *propname) const;
160 void internalPropSet(const char *propname, const QVariant &value);
161 QDBusMessage internalConstCall(QDBus::CallMode mode,
162 const QString &method,
163 const QList<QVariant> &args = QList<QVariant>()) const;
164
165private:
166 QDBusMessage doCall(QDBus::CallMode mode, const QString &method, const QVariant *args, size_t numArgs);
167 QDBusPendingCall doAsyncCall(const QString &method, const QVariant *args, size_t numArgs);
168
169private:
170 Q_DECLARE_PRIVATE(QDBusAbstractInterface)
171 Q_PRIVATE_SLOT(d_func(), void _q_serviceOwnerChanged(QString,QString,QString))
172};
173
174QT_END_NAMESPACE
175
176#endif // QT_NO_DBUS
177#endif
178

source code of qtbase/src/dbus/qdbusabstractinterface.h