LeechCraft
0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
dbus.h
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#pragma once
10
11
#include <coroutine>
12
#include <memory>
13
#include <tuple>
14
#include <QDBusPendingCallWatcher>
15
#include <QDBusPendingReply>
16
#include <
util/sll/either.h
>
17
#include <
util/sll/void.h
>
18
#include "
taskfwd.h
"
19
20
namespace
LC::Util::detail
21
{
22
template
<
typename
... Rets>
23
struct
DBusAwaiter
24
{
25
QDBusPendingReply<Rets...>
Reply_
;
26
std::unique_ptr<QDBusPendingCallWatcher>
Watcher_
;
27
28
DBusAwaiter
(
const
QDBusPendingReply<Rets...>& reply)
29
:
Reply_
{ reply }
30
{
31
}
32
33
bool
await_ready
() const noexcept
34
{
35
return
Reply_
.isFinished ();
36
}
37
38
void
await_suspend
(std::coroutine_handle<> handle)
noexcept
39
{
40
Watcher_
= std::make_unique<QDBusPendingCallWatcher> (
Reply_
);
41
QObject::connect (
Watcher_
.get (),
42
&QDBusPendingCallWatcher::finished,
43
Watcher_
.get (),
44
handle);
45
}
46
47
template
<
typename
=
void
>
48
struct
SuccessType
;
49
50
template
<
typename
T>
requires
(
sizeof
... (Rets) == 0)
51
struct
SuccessType<T>
{
using
Type
=
Void
; };
52
53
template
<
typename
T>
requires
(
sizeof
... (Rets) == 1)
54
struct
SuccessType<T>
{
using
Type
= Rets... [0]; };
55
56
template
<
typename
T>
requires
(
sizeof
... (Rets) > 1)
57
struct
SuccessType<T>
{
using
Type
= std::tuple<Rets...>; };
58
59
using
SuccessType_t
=
SuccessType<>::Type
;
60
61
Either<QDBusError, SuccessType_t>
await_resume
() const noexcept
62
{
63
if
(
Reply_
.isError ())
64
return
{
AsLeft
,
Reply_
.error () };
65
66
if
constexpr
(
sizeof
... (Rets) == 0)
67
return
{
Void
{} };
68
else
if
constexpr
(
sizeof
... (Rets) == 1)
69
return
{
Reply_
.value () };
70
else
71
return
[&]<
size_t
... Idxs> (std::index_sequence<Idxs...>) -> std::tuple<Rets...>
72
{
73
return
{
Reply_
.template argumentAt<Idxs> ()... };
74
} (std::make_index_sequence<
sizeof
... (Rets)> {});
75
}
76
};
77
}
78
79
namespace
LC::Util
80
{
81
template
<
typename
... Rets>
82
detail::DBusAwaiter
<Rets...>
Reply
(
const
QDBusPendingReply<Rets...>& reply)
83
{
84
return
{ reply };
85
}
86
87
template
<
typename
... Rets>
88
detail::DBusAwaiter
<Rets...>
Typed
(
const
QDBusPendingCall& asyncCall)
89
{
90
return
{ asyncCall };
91
}
92
93
template
<
typename
... Rets,
typename
... Actual>
94
detail::DBusAwaiter<Rets...>
Typed
(
const
QDBusPendingReply<Actual...>&) =
delete
(
"do not use Util::Typed to await typed QDBusPendingReply<...>"
);
95
96
template
<
typename
... Rets>
97
detail::DBusAwaiter<Rets...>
GetAwaiter
(
const
QDBusPendingReply<Rets...>& reply, AwaiterCPO)
98
{
99
return
{ reply };
100
}
101
}
102
103
namespace
LC
104
{
105
template
<
typename
... Rets>
106
auto
operator
co_await
(
const
QDBusPendingReply<Rets...>& reply)
107
{
108
return
Util::GetAwaiter
(reply, {});
109
}
110
}
111
112
namespace
LC::Util::DBus
113
{
114
template
<
typename
... Args>
115
struct
AsyncReply
116
{
117
QDBusPendingReply<Args...>
Raw_
;
118
119
detail::DBusAwaiter
<Args...>
operator
co_await
()
const
120
{
121
return
{
Raw_
};
122
}
123
};
124
}
LC::Util::Either
Definition
either.h:34
LC::Util::DBus
Definition
async.cpp:15
LC::Util::detail
Definition
fancytrayiconfreedesktop.cpp:24
LC::Util
Definition
icoreproxy.h:34
LC::Util::AsLeft
constexpr auto AsLeft
Definition
either.h:28
LC::Util::Typed
detail::DBusAwaiter< Rets... > Typed(const QDBusPendingCall &asyncCall)
Definition
dbus.h:88
LC::Util::GetAwaiter
detail::EitherAwaiter< L, R, std::identity > GetAwaiter(const Either< L, R > &either, AwaiterCPO)
Definition
either.h:119
LC::Util::Reply
detail::DBusAwaiter< Rets... > Reply(const QDBusPendingReply< Rets... > &reply)
Definition
dbus.h:82
LC
Definition
constants.h:15
either.h
LC::Util::DBus::AsyncReply
Definition
dbus.h:116
LC::Util::DBus::AsyncReply::Raw_
QDBusPendingReply< Args... > Raw_
Definition
dbus.h:117
LC::Util::Void
A proper void type, akin to unit (or ()) type in functional languages.
Definition
void.h:21
LC::Util::detail::DBusAwaiter::SuccessType< T >::Type
Void Type
Definition
dbus.h:51
LC::Util::detail::DBusAwaiter::SuccessType
Definition
dbus.h:48
LC::Util::detail::DBusAwaiter
Definition
dbus.h:24
LC::Util::detail::DBusAwaiter::await_ready
bool await_ready() const noexcept
Definition
dbus.h:33
LC::Util::detail::DBusAwaiter::Watcher_
std::unique_ptr< QDBusPendingCallWatcher > Watcher_
Definition
dbus.h:26
LC::Util::detail::DBusAwaiter::Reply_
QDBusPendingReply< Rets... > Reply_
Definition
dbus.h:25
LC::Util::detail::DBusAwaiter::DBusAwaiter
DBusAwaiter(const QDBusPendingReply< Rets... > &reply)
Definition
dbus.h:28
LC::Util::detail::DBusAwaiter::await_suspend
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition
dbus.h:38
LC::Util::detail::DBusAwaiter::await_resume
Either< QDBusError, SuccessType_t > await_resume() const noexcept
Definition
dbus.h:61
LC::Util::detail::DBusAwaiter::SuccessType_t
SuccessType<>::Type SuccessType_t
Definition
dbus.h:59
taskfwd.h
void.h
src
util
threads
coro
dbus.h
Generated by
1.18.0