File indexing completed on 2023-05-30 09:17:24

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@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 DBUSHELPERS_H
0008 #define DBUSHELPERS_H
0009 
0010 #include <KLocalizedString>
0011 #include <QDBusPendingReply>
0012 #include <QTextStream>
0013 
0014 template<typename T>
0015 Q_REQUIRED_RESULT T blockOnReply(QDBusPendingReply<T> reply)
0016 {
0017     reply.waitForFinished();
0018     if (reply.isError()) {
0019         QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl;
0020         exit(1);
0021     }
0022     return reply.value();
0023 }
0024 
0025 void blockOnReply(QDBusPendingReply<void> reply)
0026 {
0027     reply.waitForFinished();
0028     if (reply.isError()) {
0029         QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl;
0030         exit(1);
0031     }
0032 }
0033 
0034 #endif