LeechCraft
0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
process.cpp
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
#include "
process.h
"
10
#include <QProcess>
11
#include <QtDebug>
12
#include <
util/sll/visitor.h
>
13
14
namespace
LC::Util
15
{
16
QDebug
operator<<
(QDebug dbg,
const
ProcessFailedToStart
& failed)
17
{
18
QDebugStateSaver saver { dbg };
19
dbg.nospace () <<
"ProcessFailedToStart { "
<< failed.
Error_
<<
" }"
;
20
return
dbg;
21
}
22
23
QDebug
operator<<
(QDebug dbg,
const
ProcessCrashed
& crashed)
24
{
25
QDebugStateSaver saver { dbg };
26
dbg.nospace () <<
"ProcessCrashed { code: "
<< crashed.
Code_
<<
" }"
;
27
return
dbg;
28
}
29
30
QDebug
operator<<
(QDebug dbg,
const
ProcessExited
& exited)
31
{
32
QDebugStateSaver saver { dbg };
33
dbg.nospace () <<
"ProcessExited { code: "
<< exited.
Code_
<<
" }"
;
34
return
dbg;
35
}
36
37
QDebug
operator<<
(QDebug dbg,
const
ProcessOutcome
& outcome)
38
{
39
Visit
(outcome, [&dbg] (
const
auto
& alternative) { dbg << alternative; });
40
return
dbg;
41
}
42
}
43
44
namespace
LC::Util::detail
45
{
46
bool
ProcessAwaiter::await_ready
() const noexcept
47
{
48
return
Process_
.state () == QProcess::NotRunning;
49
}
50
51
void
ProcessAwaiter::await_suspend
(std::coroutine_handle<> handle)
52
{
53
const
auto
resumeLater = [
this
, handle]
54
{
55
if
(!
await_ready
())
56
return
;
57
58
QObject::disconnect (std::move (
FinishedConn_
).Release ());
59
QObject::disconnect (std::move (
ErrorConn_
).Release ());
60
QMetaObject::invokeMethod (&
CoroResumeGuard_
, handle, Qt::QueuedConnection);
61
};
62
FinishedConn_
= QObject::connect (&
Process_
, &QProcess::finished, resumeLater);
63
ErrorConn_
= QObject::connect (&
Process_
, &QProcess::errorOccurred, resumeLater);
64
}
65
66
ProcessOutcome
ProcessAwaiter::await_resume
()
const
67
{
68
if
(
Process_
.error () == QProcess::FailedToStart)
69
return
ProcessFailedToStart
{
Process_
.errorString () };
70
71
if
(
Process_
.exitStatus () == QProcess::CrashExit)
72
return
ProcessCrashed
{
Process_
.exitCode () };
73
74
return
ProcessExited
{
Process_
.exitCode () };
75
}
76
}
LC::Util::detail
Definition
fancytrayiconfreedesktop.cpp:24
LC::Util
Definition
icoreproxy.h:34
LC::Util::ProcessOutcome
std::variant< ProcessFailedToStart, ProcessCrashed, ProcessExited > ProcessOutcome
Definition
process.h:45
LC::Util::Visit
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition
either.h:189
LC::Util::operator<<
QDebug operator<<(QDebug dbg, const CtString< N, Char > &str)
Definition
ctstringutils.h:113
process.h
LC::Util::ProcessCrashed
Definition
process.h:32
LC::Util::ProcessCrashed::Code_
int Code_
Definition
process.h:33
LC::Util::ProcessExited
Definition
process.h:39
LC::Util::ProcessExited::Code_
int Code_
Definition
process.h:40
LC::Util::ProcessFailedToStart
Definition
process.h:25
LC::Util::ProcessFailedToStart::Error_
QString Error_
Definition
process.h:26
LC::Util::detail::ProcessAwaiter::CoroResumeGuard_
QObject CoroResumeGuard_
Definition
process.h:58
LC::Util::detail::ProcessAwaiter::FinishedConn_
RaiiSignalConnection FinishedConn_
Definition
process.h:60
LC::Util::detail::ProcessAwaiter::await_suspend
void await_suspend(std::coroutine_handle<> handle)
Definition
process.cpp:51
LC::Util::detail::ProcessAwaiter::Process_
QProcess & Process_
Definition
process.h:56
LC::Util::detail::ProcessAwaiter::ErrorConn_
RaiiSignalConnection ErrorConn_
Definition
process.h:61
LC::Util::detail::ProcessAwaiter::await_resume
ProcessOutcome await_resume() const
Definition
process.cpp:66
LC::Util::detail::ProcessAwaiter::await_ready
bool await_ready() const noexcept
Definition
process.cpp:46
visitor.h
src
util
threads
coro
process.cpp
Generated by
1.18.0