refs #276 added async methods to CGenericDBusInterface

This commit is contained in:
Mathew Sutcliffe
2014-06-18 19:14:40 +01:00
parent af1ededf9c
commit 580b7edc35

View File

@@ -40,6 +40,28 @@ namespace BlackMisc
QDBusPendingReply<Ret> pr = this->asyncCallWithArgumentList(method, argumentList);
return pr;
}
//! Call DBus with asynchronous return value
//! Callback can be any callable object taking a single argument of type QDBusPendingCallWatcher*.
template <typename Func, typename... Args>
void callDBusAsync(const QLatin1String &method, Func callback, Args&&... args)
{
QList<QVariant> argumentList { QVariant::fromValue(std::forward<Args>(args))... };
QDBusPendingCall pc = this->asyncCallWithArgumentList(method, argumentList);
auto pcw = new QDBusPendingCallWatcher(pc, this);
connect(pcw, &QDBusPendingCallWatcher::finished, callback);
}
//! Cancel all asynchronous DBus calls which are currently pending
//! \warning Don't call this from inside an async callback!
void cancelAllPendingAsyncCalls()
{
auto watchers = this->findChildren<QDBusPendingCallWatcher *>(QString(), Qt::FindDirectChildrenOnly);
for (auto w : watchers)
{
delete w;
}
}
};
}