1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDBUSABSTRACTINTERFACE_H
5#define QDBUSABSTRACTINTERFACE_H
6
7#include <QtDBus/qtdbusglobal.h>
8#include <QtCore/qstring.h>
9#include <QtCore/qvariant.h>
10#include <QtCore/qlist.h>
11#include <QtCore/qobject.h>
12
13#include <QtDBus/qdbusmessage.h>
14#include <QtDBus/qdbusextratypes.h>
15#include <QtDBus/qdbusconnection.h>
16#include <QtDBus/qdbuspendingcall.h>
17
18#ifdef interface
19#undef interface
20#endif
21
22#ifndef QT_NO_DBUS
23
24QT_BEGIN_NAMESPACE
25
26
27class QDBusError;
28class QDBusPendingCall;
29
30class QDBusAbstractInterfacePrivate;
31
32class Q_DBUS_EXPORT QDBusAbstractInterfaceBase: public QObject
33{
34public:
35 int qt_metacall(QMetaObject::Call, int, void**) override;
36protected:
37 QDBusAbstractInterfaceBase(QDBusAbstractInterfacePrivate &dd, QObject *parent);
38private:
39 Q_DECLARE_PRIVATE(QDBusAbstractInterface)
40};
41
42class Q_DBUS_EXPORT QDBusAbstractInterface:
43#ifdef Q_QDOC
44 public QObject
45#else
46 public QDBusAbstractInterfaceBase
47#endif
48{
49 Q_OBJECT
50
51public:
52 virtual ~QDBusAbstractInterface();
53 bool isValid() const;
54
55 QDBusConnection connection() const;
56
57 QString service() const;
58 QString path() const;
59 QString interface() const;
60
61 QDBusError lastError() const;
62
63 void setTimeout(int timeout);
64 int timeout() const;
65
66 QDBusMessage call(const QString &method)
67 {
68 return doCall(mode: QDBus::AutoDetect, method, args: nullptr, numArgs: 0);
69 }
70
71 template <typename...Args>
72 QDBusMessage call(const QString &method, Args &&...args)
73 {
74 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
75 return doCall(mode: QDBus::AutoDetect, method, args: variants, numArgs: sizeof...(args));
76 }
77
78 QDBusMessage call(QDBus::CallMode mode, const QString &method)
79 {
80 return doCall(mode, method, args: nullptr, numArgs: 0);
81 }
82
83 template <typename...Args>
84 QDBusMessage call(QDBus::CallMode mode, const QString &method, Args &&...args)
85 {
86 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
87 return doCall(mode, method, args: variants, numArgs: sizeof...(args));
88 }
89
90 QDBusMessage callWithArgumentList(QDBus::CallMode mode,
91 const QString &method,
92 const QList<QVariant> &args);
93
94 bool callWithCallback(const QString &method,
95 const QList<QVariant> &args,
96 QObject *receiver, const char *member, const char *errorSlot);
97 bool callWithCallback(const QString &method,
98 const QList<QVariant> &args,
99 QObject *receiver, const char *member);
100
101 QDBusPendingCall asyncCall(const QString &method)
102 {
103 return doAsyncCall(method, args: nullptr, numArgs: 0);
104 }
105
106 template <typename...Args>
107 QDBusPendingCall asyncCall(const QString &method, Args&&...args)
108 {
109 const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
110 return doAsyncCall(method, args: variants, numArgs: sizeof...(args));
111 }
112
113 QDBusPendingCall asyncCallWithArgumentList(const QString &method,
114 const QList<QVariant> &args);
115
116protected:
117 QDBusAbstractInterface(const QString &service, const QString &path, const char *interface,
118 const QDBusConnection &connection, QObject *parent);
119 QDBusAbstractInterface(QDBusAbstractInterfacePrivate &, QObject *parent);
120
121 void connectNotify(const QMetaMethod &signal) override;
122 void disconnectNotify(const QMetaMethod &signal) override;
123 QVariant internalPropGet(const char *propname) const;
124 void internalPropSet(const char *propname, const QVariant &value);
125 QDBusMessage internalConstCall(QDBus::CallMode mode,
126 const QString &method,
127 const QList<QVariant> &args = QList<QVariant>()) const;
128
129private:
130 QDBusMessage doCall(QDBus::CallMode mode, const QString &method, const QVariant *args, size_t numArgs);
131 QDBusPendingCall doAsyncCall(const QString &method, const QVariant *args, size_t numArgs);
132
133private:
134 Q_DECLARE_PRIVATE(QDBusAbstractInterface)
135 Q_PRIVATE_SLOT(d_func(), void _q_serviceOwnerChanged(QString,QString,QString))
136};
137
138QT_END_NAMESPACE
139
140#endif // QT_NO_DBUS
141#endif
142

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