LeechCraft
0.6.70-19214-g121e5318a7
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
handle);
44
}
45
46
template
<
typename
=
void
>
47
struct
SuccessType
;
48
49
template
<
typename
T>
requires
(
sizeof
... (Rets) == 0)
50
struct
SuccessType<T>
{
using
Type
=
Void
; };
51
52
template
<
typename
T>
requires
(
sizeof
... (Rets) == 1)
53
struct
SuccessType<T>
{
using
Type
= Rets... [0]; };
54
55
template
<
typename
T>
requires
(
sizeof
... (Rets) > 1)
56
struct
SuccessType<T>
{
using
Type
= std::tuple<Rets...>; };
57
58
using
SuccessType_t
=
SuccessType<>::Type
;
59
60
Either<QDBusError, SuccessType_t>
await_resume
() const noexcept
61
{
62
if
(
Reply_
.isError ())
63
return
{
AsLeft
,
Reply_
.error () };
64
65
if
constexpr
(
sizeof
... (Rets) == 0)
66
return
{
Void
{} };
67
else
if
constexpr
(
sizeof
... (Rets) == 1)
68
return
{
Reply_
.value () };
69
else
70
return
[&]<
size_t
... Idxs> (std::index_sequence<Idxs...>) -> std::tuple<Rets...>
71
{
72
return
{
Reply_
.template argumentAt<Idxs> ()... };
73
} (std::make_index_sequence<
sizeof
... (Rets)> {});
74
}
75
};
76
}
77
78
namespace
LC::Util
79
{
80
template
<
typename
... Rets>
81
detail::DBusAwaiter
<Rets...>
Reply
(
const
QDBusPendingReply<Rets...>& reply)
82
{
83
return
{ reply };
84
}
85
86
template
<
typename
... Rets>
87
detail::DBusAwaiter
<Rets...>
Typed
(
const
QDBusPendingCall& asyncCall)
88
{
89
return
{ asyncCall };
90
}
91
92
template
<
typename
... Rets,
typename
... Actual>
93
detail::DBusAwaiter<Rets...>
Typed
(
const
QDBusPendingReply<Actual...>&) =
delete
(
"do not use Util::Typed to await typed QDBusPendingReply<...>"
);
94
95
template
<
typename
... Rets>
96
detail::DBusAwaiter<Rets...>
GetAwaiter
(
const
QDBusPendingReply<Rets...>& reply, AwaiterCPO)
97
{
98
return
{ reply };
99
}
100
}
101
102
namespace
LC
103
{
104
template
<
typename
... Rets>
105
auto
operator
co_await
(
const
QDBusPendingReply<Rets...>& reply)
106
{
107
return
Util::GetAwaiter
(reply, {});
108
}
109
}
110
111
namespace
LC::Util::DBus
112
{
113
template
<
typename
... Args>
114
struct
AsyncReply
115
{
116
QDBusPendingReply<Args...>
Raw_
;
117
118
detail::DBusAwaiter
<Args...>
operator
co_await
()
const
119
{
120
return
{
Raw_
};
121
}
122
};
123
}
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:87
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:81
LC
Definition
constants.h:15
either.h
LC::Util::DBus::AsyncReply
Definition
dbus.h:115
LC::Util::DBus::AsyncReply::Raw_
QDBusPendingReply< Args... > Raw_
Definition
dbus.h:116
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:50
LC::Util::detail::DBusAwaiter::SuccessType
Definition
dbus.h:47
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:60
LC::Util::detail::DBusAwaiter::SuccessType_t
SuccessType<>::Type SuccessType_t
Definition
dbus.h:58
taskfwd.h
void.h
src
util
threads
coro
dbus.h
Generated by
1.18.0