File indexing completed on 2024-05-12 17:08:31
0001 /* 0002 * SPDX-FileCopyrightText: 2018-2019 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef DBUSHELPER_H_ 0008 #define DBUSHELPER_H_ 0009 0010 #include <QDBusAbstractInterface> 0011 #include <QDBusConnection> 0012 0013 namespace KBolt 0014 { 0015 class Device; 0016 } 0017 0018 namespace DBusHelper 0019 { 0020 QDBusConnection connection(); 0021 QString serviceName(); 0022 0023 using CallErrorCallback = std::function<void(const QString &)>; 0024 using CallOkCallback = std::function<void()>; 0025 void handleCall(QDBusPendingCall call, CallOkCallback &&okCb, CallErrorCallback &&errCb, QObject *parent); 0026 0027 template<typename... V> 0028 void call(QDBusAbstractInterface *iface, const QString &method, const V &... args, CallOkCallback &&okCb, CallErrorCallback &&errCb, QObject *parent = nullptr) 0029 { 0030 handleCall(iface->asyncCall(method, args...), std::move(okCb), std::move(errCb), parent); 0031 } 0032 0033 } // namespace 0034 0035 #endif