BluezQt 5.109.0
tpendingcall.h
1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#ifndef BLUEZQT_TPENDINGCALL_H
10#define BLUEZQT_TPENDINGCALL_H
11
12#include <QDBusPendingReply>
13
14#include "pendingcall.h"
15
16namespace BluezQt
17{
18using namespace std::placeholders;
19
31// KF6 TODO: convert all PendingCalls to TPendingCall (or convert existing PendingCall class to templated version).
32template<class... T>
34{
35private:
36 template<int Index, typename Ty, typename... Ts>
37 struct Select {
38 using Type = typename Select<Index - 1, Ts...>::Type;
39 };
40 template<typename Ty, typename... Ts>
41 struct Select<0, Ty, Ts...> {
42 using Type = Ty;
43 };
44
45public:
55 template<int Index>
56 inline const typename Select<Index, T...>::Type valueAt() const
57 {
58 using ResultType = typename Select<Index, T...>::Type;
59 return qdbus_cast<ResultType>(m_reply.argumentAt(Index), nullptr);
60 }
61
62private:
63 TPendingCall(const QDBusPendingCall &call, QObject *parent = nullptr)
64 : PendingCall(call, std::bind(&TPendingCall::process, this, _1, _2, _3), parent)
65 {
66 }
67
68 void process(QDBusPendingCallWatcher *watcher, ErrorProcessor errorProcessor, QVariantList *values)
69 {
70 m_reply = *watcher;
71 errorProcessor(m_reply.error());
72 if (m_reply.isError()) {
73 return;
74 }
75
76 for (int i = 0; i < m_reply.count(); ++i) {
77 values->append(m_reply.argumentAt(i));
78 }
79 }
80
81 QDBusPendingReply<T...> m_reply;
82
83 friend class MediaTransport;
84};
85
86} // namespace BluezQt
87
88#endif
Pending method call.
Definition pendingcall.h:33
Pending method call (template version).
Definition tpendingcall.h:34
const Select< Index, T... >::Type valueAt() const
Returns a return value at given index of the call.
Definition tpendingcall.h:56