UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
launch_manager.cpp
Go to the documentation of this file.
1#include "launch_manager.hpp"
2#include "debug.hpp"
3
6 auto& p = currentLaunch->process;
7 p.blockSignals(true);
8 p.terminate();
9 p.waitForFinished(500);
10 if(p.state() != QProcess::NotRunning){
11 p.kill();
12 p.waitForFinished(1000);
13 }
14 }
15 queuedLaunch.reset();
16}
17
18void LaunchManager::launch(std::unique_ptr<LaunchContext>&& ctx){
20 doLaunch(std::move(ctx));
21 } else {
23 return;
24 }
25 queuedLaunch = std::move(ctx);
26 currentLaunch->terminate();
27 }
28}
29
30void LaunchManager::doLaunch(std::unique_ptr<LaunchContext>&& ctx){
31 currentLaunch = std::move(ctx);
32
33 connect(&currentLaunch->process,
34 QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
35 this, &LaunchManager::processFinished, Qt::UniqueConnection);
36
37 currentLaunch->process.start(currentLaunch->executablePath, currentLaunch->args);
38
39 if(!currentLaunch->process.waitForStarted()){
40 //Shouldn't happen as we probe ug executability at startup
41 abort_msgBox("Failed to launch process. Did the ug executable disappear?");
42 }
43}
44
46 if(!currentLaunch)
47 return;
48
49 currentLaunch->terminate();
50}
51
53 currentLaunch.reset();
54
55 if(queuedLaunch)
56 doLaunch(std::move(queuedLaunch));
57}
58
59std::unique_ptr<LaunchContext> LaunchManager::extractCurrentCtx(){
60 auto ret = std::move(currentLaunch);
61 return ret;
62}
63
64
65void LaunchManager::reLaunch(std::unique_ptr<LaunchContext>&& ctx){
66 queuedLaunch = std::move(ctx);
67}
68
75
77 connect(&killTimer, &QTimer::timeout, [=](){ process.kill(); });
78 killTimer.setSingleShot(true);
79 connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
81
82 process.setProcessChannelMode(QProcess::MergedChannels);
83 connect(&process, &QProcess::readyReadStandardOutput, this, &LaunchContext::processOutput);
84 connect(&process, &QProcess::readyReadStandardError, this, &LaunchContext::processOutput);
85}
86
87void LaunchContext::processTerminationHandler(int code, QProcess::ExitStatus es){
89}
90
92 QString str = process.isReadable() ? process.readAll() : QByteArray();
93
94 emit processOutputRead(str);
95
96 lineBuf.write(str.toStdString());
97
98 while(lineBuf.hasLine()){
100 lineBuf.pop();
101 }
102}
103
106 process.terminate();
108}
void processOutputLine(std::string_view sv)
void processTerminated(int code, QProcess::ExitStatus es, bool wasRequested)
LineBuffer lineBuf
void processOutputRead(QString str)
void processTerminationHandler(int code, QProcess::ExitStatus es)
static constexpr int terminateTimeoutMs
std::unique_ptr< LaunchContext > currentLaunch
std::unique_ptr< LaunchContext > queuedLaunch
void doLaunch(std::unique_ptr< LaunchContext > &&ctx)
LaunchContext::Type getCurrentStatus() const
void launch(std::unique_ptr< LaunchContext > &&ctx)
void reLaunch(std::unique_ptr< LaunchContext > &&ctx)
std::unique_ptr< LaunchContext > extractCurrentCtx()
bool hasLine() const
void write(std::string_view str)
std::string_view peek() const
static void abort_msgBox(const char *msg)
Definition debug.hpp:20