LeechCraft
0.6.70-18450-gabe19ee3b0
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
19
namespace
LC::Util::detail
20
{
21
template
<
typename
... Rets>
22
struct
DBusAwaiter
23
{
24
QDBusPendingReply<Rets...>
Reply_
;
25
std::unique_ptr<QDBusPendingCallWatcher>
Watcher_
;
26
27
DBusAwaiter
(
const
QDBusPendingReply<Rets...>& reply)
28
:
Reply_
{ reply }
29
{
30
}
31
32
bool
await_ready
() const noexcept
33
{
34
return
Reply_
.isFinished ();
35
}
36
37
void
await_suspend
(std::coroutine_handle<> handle)
noexcept
38
{
39
Watcher_
= std::make_unique<QDBusPendingCallWatcher> (
Reply_
);
40
QObject::connect (
Watcher_
.get (),
41
&QDBusPendingCallWatcher::finished,
42
handle);
43
}
44
45
template
<
typename
=
void
>
46
struct
SuccessType
;
47
48
template
<
typename
T>
requires
(
sizeof
... (Rets) == 0)
49
struct
SuccessType<T>
{
using
Type
=
Void
; };
50
51
template
<
typename
T>
requires
(
sizeof
... (Rets) == 1)
52
struct
SuccessType<T>
{
using
Type
= Rets... [0]; };
53
54
template
<
typename
T>
requires
(
sizeof
... (Rets) > 1)
55
struct
SuccessType<T>
{
using
Type
= std::tuple<Rets...>; };
56
57
using
SuccessType_t
=
SuccessType<>::Type
;
58
59
Either<QDBusError, SuccessType_t>
await_resume
() const noexcept
60
{
61
if
(
Reply_
.isError ())
62
return
{
AsLeft
,
Reply_
.error () };
63
64
if
constexpr
(
sizeof
... (Rets) == 0)
65
return
{
Void
{} };
66
else
if
constexpr
(
sizeof
... (Rets) == 1)
67
return
{
Reply_
.value () };
68
else
69
return
[&]<
size_t
... Idxs> (std::index_sequence<Idxs...>) -> std::tuple<Rets...>
70
{
71
return
{
Reply_
.template argumentAt<Idxs> ()... };
72
} (std::make_index_sequence<
sizeof
... (Rets)> {});
73
}
74
};
75
}
76
77
namespace
LC
78
{
79
template
<
typename
... Rets>
80
Util::detail::DBusAwaiter
<Rets...>
operator
co_await
(
const
QDBusPendingReply<Rets...>& reply)
81
{
82
return
{ reply };
83
}
84
}
85
86
namespace
LC::Util
87
{
88
template
<
typename
... Rets>
89
detail::DBusAwaiter
<Rets...>
Typed
(
const
QDBusPendingCall& asyncCall)
90
{
91
return
{ asyncCall };
92
}
93
}
LC::Util::Either
Definition
either.h:33
LC::Util::detail
Definition
fancytrayiconfreedesktop.cpp:24
LC::Util
Definition
icoreproxy.h:34
LC::Util::AsLeft
constexpr auto AsLeft
Definition
either.h:27
LC::Util::Typed
detail::DBusAwaiter< Rets... > Typed(const QDBusPendingCall &asyncCall)
Definition
dbus.h:89
LC
Definition
constants.h:15
either.h
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:49
LC::Util::detail::DBusAwaiter::SuccessType
Definition
dbus.h:46
LC::Util::detail::DBusAwaiter
Definition
dbus.h:23
LC::Util::detail::DBusAwaiter::await_ready
bool await_ready() const noexcept
Definition
dbus.h:32
LC::Util::detail::DBusAwaiter::Watcher_
std::unique_ptr< QDBusPendingCallWatcher > Watcher_
Definition
dbus.h:25
LC::Util::detail::DBusAwaiter::Reply_
QDBusPendingReply< Rets... > Reply_
Definition
dbus.h:24
LC::Util::detail::DBusAwaiter::DBusAwaiter
DBusAwaiter(const QDBusPendingReply< Rets... > &reply)
Definition
dbus.h:27
LC::Util::detail::DBusAwaiter::await_suspend
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition
dbus.h:37
LC::Util::detail::DBusAwaiter::await_resume
Either< QDBusError, SuccessType_t > await_resume() const noexcept
Definition
dbus.h:59
LC::Util::detail::DBusAwaiter::SuccessType_t
SuccessType<>::Type SuccessType_t
Definition
dbus.h:57
void.h
src
util
threads
coro
dbus.h
Generated by
1.17.0