| 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 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | |
| 63 | class QDBusError; |
| 64 | class QDBusPendingCall; |
| 65 | |
| 66 | class QDBusAbstractInterfacePrivate; |
| 67 | |
| 68 | class Q_DBUS_EXPORT QDBusAbstractInterfaceBase: public QObject |
| 69 | { |
| 70 | public: |
| 71 | int qt_metacall(QMetaObject::Call, int, void**) override; |
| 72 | protected: |
| 73 | QDBusAbstractInterfaceBase(QDBusAbstractInterfacePrivate &dd, QObject *parent); |
| 74 | private: |
| 75 | Q_DECLARE_PRIVATE(QDBusAbstractInterface) |
| 76 | }; |
| 77 | |
| 78 | class Q_DBUS_EXPORT QDBusAbstractInterface: |
| 79 | #ifdef Q_QDOC |
| 80 | public QObject |
| 81 | #else |
| 82 | public QDBusAbstractInterfaceBase |
| 83 | #endif |
| 84 | { |
| 85 | Q_OBJECT |
| 86 | |
| 87 | public: |
| 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(mode: QDBus::AutoDetect, method, args: nullptr, numArgs: 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(mode: QDBus::AutoDetect, method, args: variants, numArgs: sizeof...(args)); |
| 112 | } |
| 113 | |
| 114 | QDBusMessage call(QDBus::CallMode mode, const QString &method) |
| 115 | { |
| 116 | return doCall(mode, method, args: nullptr, numArgs: 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, args: variants, numArgs: sizeof...(args)); |
| 124 | } |
| 125 | |
| 126 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 127 | QDBusMessage call(const QString &method, |
| 128 | const QVariant &arg1, |
| 129 | const QVariant &arg2, |
| 130 | const QVariant &arg3, |
| 131 | const QVariant &arg4, |
| 132 | const QVariant &arg5, |
| 133 | const QVariant &arg6, |
| 134 | const QVariant &arg7, |
| 135 | const QVariant &arg8); |
| 136 | |
| 137 | QDBusMessage call(QDBus::CallMode mode, |
| 138 | const QString &method, |
| 139 | const QVariant &arg1, |
| 140 | const QVariant &arg2, |
| 141 | const QVariant &arg3, |
| 142 | const QVariant &arg4, |
| 143 | const QVariant &arg5, |
| 144 | const QVariant &arg6, |
| 145 | const QVariant &arg7, |
| 146 | const QVariant &arg8); |
| 147 | #endif // Qt 5 |
| 148 | |
| 149 | QDBusMessage callWithArgumentList(QDBus::CallMode mode, |
| 150 | const QString &method, |
| 151 | const QList<QVariant> &args); |
| 152 | |
| 153 | bool callWithCallback(const QString &method, |
| 154 | const QList<QVariant> &args, |
| 155 | QObject *receiver, const char *member, const char *errorSlot); |
| 156 | bool callWithCallback(const QString &method, |
| 157 | const QList<QVariant> &args, |
| 158 | QObject *receiver, const char *member); |
| 159 | |
| 160 | QDBusPendingCall asyncCall(const QString &method) |
| 161 | { |
| 162 | return doAsyncCall(method, args: nullptr, numArgs: 0); |
| 163 | } |
| 164 | |
| 165 | template <typename...Args> |
| 166 | QDBusPendingCall asyncCall(const QString &method, Args&&...args) |
| 167 | { |
| 168 | const QVariant variants[] = { QVariant(std::forward<Args>(args))... }; |
| 169 | return doAsyncCall(method, args: variants, numArgs: sizeof...(args)); |
| 170 | } |
| 171 | |
| 172 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 173 | QDBusPendingCall asyncCall(const QString &method, |
| 174 | const QVariant &arg1, |
| 175 | const QVariant &arg2, |
| 176 | const QVariant &arg3, |
| 177 | const QVariant &arg4, |
| 178 | const QVariant &arg5, |
| 179 | const QVariant &arg6, |
| 180 | const QVariant &arg7, |
| 181 | const QVariant &arg8); |
| 182 | #endif // Qt 5 |
| 183 | |
| 184 | QDBusPendingCall asyncCallWithArgumentList(const QString &method, |
| 185 | const QList<QVariant> &args); |
| 186 | |
| 187 | protected: |
| 188 | QDBusAbstractInterface(const QString &service, const QString &path, const char *interface, |
| 189 | const QDBusConnection &connection, QObject *parent); |
| 190 | QDBusAbstractInterface(QDBusAbstractInterfacePrivate &, QObject *parent); |
| 191 | |
| 192 | void connectNotify(const QMetaMethod &signal) override; |
| 193 | void disconnectNotify(const QMetaMethod &signal) override; |
| 194 | QVariant internalPropGet(const char *propname) const; |
| 195 | void internalPropSet(const char *propname, const QVariant &value); |
| 196 | QDBusMessage internalConstCall(QDBus::CallMode mode, |
| 197 | const QString &method, |
| 198 | const QList<QVariant> &args = QList<QVariant>()) const; |
| 199 | |
| 200 | private: |
| 201 | QDBusMessage doCall(QDBus::CallMode mode, const QString &method, const QVariant *args, size_t numArgs); |
| 202 | QDBusPendingCall doAsyncCall(const QString &method, const QVariant *args, size_t numArgs); |
| 203 | |
| 204 | private: |
| 205 | Q_DECLARE_PRIVATE(QDBusAbstractInterface) |
| 206 | Q_PRIVATE_SLOT(d_func(), void _q_serviceOwnerChanged(QString,QString,QString)) |
| 207 | }; |
| 208 | |
| 209 | QT_END_NAMESPACE |
| 210 | |
| 211 | #endif // QT_NO_DBUS |
| 212 | #endif |
| 213 | |