Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

src: switch from Qt to boost implementation of executeProcess #1145

Merged
merged 2 commits into from
Feb 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up includes
  • Loading branch information
mlangkabel committed Feb 22, 2021
commit 5689e21c515863c2aaac4ad2bbdf6f3e7fc9dc10
62 changes: 4 additions & 58 deletions src/lib_gui/utility/utilityApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,20 @@
#include <boost/process.hpp>
#include <boost/process/async_pipe.hpp>
#include <boost/process/child.hpp>
//#include <boost/process/env.hpp>
//#include <boost/process/environment.hpp>
#include <boost/process/io.hpp>
#include <boost/process/search_path.hpp>
//#include <boost/process/shell.hpp>
#include <boost/process/start_dir.hpp>
//#include <boost/process/system.hpp>

#include <boost/filesystem/path.hpp>
#include <iostream>

#include <QProcess>
#include <QRegularExpression>
#include <QSysInfo>
#include <QThread>
#include <qprocessordetection.h>

#include "AppPath.h"
#include "ApplicationSettings.h"
#include "ScopedFunctor.h"
#include "UserPaths.h"
#include "logging.h"
#include "utilityString.h"

namespace
{
void logProcessStreams(QProcess& process, std::wstring& outputBuffer, std::wstring& errorBuffer)
{
{
outputBuffer += QString(process.readAllStandardOutput()).toStdWString();
std::vector<std::wstring> outputLines = utility::split<std::vector<std::wstring>>(
outputBuffer, L"\n");
for (size_t i = 0; i < outputLines.size() - 1; i++)
{
if (outputLines[i].back() == L'\r')
{
outputLines[i].pop_back();
}
LOG_INFO_BARE(L"Process output: " + outputLines[i]);
}
outputBuffer = outputLines.back();
}
{
errorBuffer += QString(process.readAllStandardError()).toStdWString();
std::vector<std::wstring> errorLines = utility::split<std::vector<std::wstring>>(
errorBuffer, L"\n");
for (size_t i = 0; i < errorLines.size() - 1; i++)
{
if (errorLines[i].back() == L'\r')
{
errorLines[i].pop_back();
}
LOG_ERROR_BARE(L"Process error: " + errorLines[i]);
}
errorBuffer = errorLines.back();
}
}
} // namespace

namespace utility
{
std::mutex s_runningProcessesMutex;
std::set<QProcess*> s_runningProcesses;
std::set<std::shared_ptr<boost::process::child>> s_runningBoostProcesses;
std::set<std::shared_ptr<boost::process::child>> s_runningProcesses;
} // namespace utility

std::wstring utility::searchPath(const std::wstring& bin, bool& ok)
Expand Down Expand Up @@ -141,12 +91,12 @@ utility::ProcessOutput utility::executeProcess(

{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
s_runningBoostProcesses.insert(process);
s_runningProcesses.insert(process);
}

ScopedFunctor remover([process]() {
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
s_runningBoostProcesses.erase(process);
s_runningProcesses.erase(process);
});

bool outputReceived = false;
Expand Down Expand Up @@ -257,11 +207,7 @@ utility::ProcessOutput utility::executeProcess(
void utility::killRunningProcesses()
{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
for (QProcess* process: s_runningProcesses)
{
process->kill();
}
for (std::shared_ptr<boost::process::child> process: s_runningBoostProcesses)
for (std::shared_ptr<boost::process::child> process: s_runningProcesses)
{
process->terminate();
}
Expand Down