2019-12-22 07:49:55 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2019-12-22 07:49:55 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-12-22 07:49:55 +00:00
|
|
|
*/
|
2014-01-28 22:22:59 +00:00
|
|
|
|
|
|
|
#ifndef RESPONSE_WAITER_H
|
|
|
|
#define RESPONSE_WAITER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2014-02-06 15:25:22 +00:00
|
|
|
#include <QTimer>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QVariant>
|
2014-01-28 22:22:59 +00:00
|
|
|
|
|
|
|
class QDBusPendingCall;
|
|
|
|
class QDBusPendingCallWatcher;
|
|
|
|
|
2014-01-31 10:06:21 +00:00
|
|
|
class DBusResponseWaiter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-01-31 10:06:21 +00:00
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
static DBusResponseWaiter *instance();
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
/// extract QDbusPendingCall from \p variant and blocks until completed
|
2021-10-27 22:11:36 +01:00
|
|
|
Q_INVOKABLE QVariant waitForReply(QVariant variant) const;
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
const QDBusPendingCall *extractPendingCall(QVariant &variant) const;
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-01-31 10:06:21 +00:00
|
|
|
private:
|
|
|
|
DBusResponseWaiter();
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
static DBusResponseWaiter *m_instance;
|
2014-01-31 10:06:21 +00:00
|
|
|
QList<int> m_registered;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DBusAsyncResponse : public QObject
|
2014-01-28 22:22:59 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2014-02-06 14:05:05 +00:00
|
|
|
Q_PROPERTY(bool autoDelete READ autodelete WRITE setAutodelete)
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-01-28 22:22:59 +00:00
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit DBusAsyncResponse(QObject *parent = nullptr);
|
2016-06-20 08:05:02 +01:00
|
|
|
~DBusAsyncResponse() override = default;
|
2014-01-28 22:22:59 +00:00
|
|
|
|
2021-10-27 22:11:36 +01:00
|
|
|
Q_INVOKABLE void setPendingCall(QVariant e);
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void setAutodelete(bool b)
|
|
|
|
{
|
|
|
|
m_autodelete = b;
|
|
|
|
};
|
|
|
|
bool autodelete() const
|
|
|
|
{
|
|
|
|
return m_autodelete;
|
|
|
|
}
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-01-28 22:22:59 +00:00
|
|
|
Q_SIGNALS:
|
2022-09-10 22:23:52 +01:00
|
|
|
void success(const QVariant &result);
|
|
|
|
void error(const QString &message);
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-01-28 22:22:59 +00:00
|
|
|
private Q_SLOTS:
|
2022-09-10 22:23:52 +01:00
|
|
|
void onCallFinished(QDBusPendingCallWatcher *watcher);
|
2014-02-06 15:25:22 +00:00
|
|
|
void onTimeout();
|
2019-12-22 07:49:55 +00:00
|
|
|
|
2014-02-06 15:25:22 +00:00
|
|
|
private:
|
|
|
|
QTimer m_timeout;
|
2014-02-05 20:36:51 +00:00
|
|
|
bool m_autodelete;
|
2014-01-28 22:22:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|