mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Issue #15 Created CPromise, a way to set the result of QFuture objects
This enables several new features: * singleShot can return a QFuture. * a version of invokeMethod that returns a QFuture. * CGenericDBusInterface::callDBusFuture, which returns a QFuture.
This commit is contained in:
@@ -12,12 +12,14 @@
|
||||
#define BLACKMISC_GENERICDBUSINTERFACE_H
|
||||
|
||||
#include "logmessage.h"
|
||||
#include "blackmisc/promise.h"
|
||||
#include <QDBusAbstractInterface>
|
||||
#include <QDBusPendingCall>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QDBusError>
|
||||
#include <QObject>
|
||||
#include <QMetaMethod>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
/*!
|
||||
@@ -102,6 +104,15 @@ namespace BlackMisc
|
||||
return pcw;
|
||||
}
|
||||
|
||||
//! Call DBus with asynchronous return as a future
|
||||
template <typename Ret, typename... Args>
|
||||
QFuture<Ret> callDBusFuture(QLatin1String method, Args&&... args)
|
||||
{
|
||||
auto sharedPromise = QSharedPointer<CPromise<Ret>>::create();
|
||||
this->callDBusAsync(method, [ = ](auto pcw) { sharedPromise->setResult(QDBusPendingReply<Ret>(*pcw)); }, std::forward<Args>(args)...);
|
||||
return sharedPromise->future();
|
||||
}
|
||||
|
||||
//! Cancel all asynchronous DBus calls which are currently pending
|
||||
//! \warning Don't call this from inside an async callback!
|
||||
void cancelAllPendingAsyncCalls()
|
||||
|
||||
Reference in New Issue
Block a user