OpenMS
Loading...
Searching...
No Matches
ExternalProcess.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11// OpenMS_GUI config
13
14#include <QtCore/QObject>
15
16#include <functional> // for std::function
17#include <map> // for std::map
18
19class QProcess; // forward declare to avoid header include
20class QString;
21#include <QtCore/qcontainerfwd.h> // for QStringList
22
23namespace OpenMS
24{
25
37 class OPENMS_DLLAPI ExternalProcess
38 : public QObject
39 {
40 Q_OBJECT
41
42 public:
44 enum class RETURNSTATE
45 {
46 SUCCESS,
47 NONZERO_EXIT,
48 CRASH,
49 FAILED_TO_START
50 };
51
53 enum class IO_MODE
54 {
55 NO_IO,
56 READ_ONLY,
57 WRITE_ONLY,
58 READ_WRITE
59 };
60
63
65 ExternalProcess(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
66
68 ~ExternalProcess() override ;
69
71 void setCallbacks(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
72
85 RETURNSTATE run(const QString& exe, const QStringList& args, const QString& working_dir, const bool verbose, String& error_msg, IO_MODE io_mode = IO_MODE::READ_WRITE, const std::map<QString, QString>& env = std::map<QString, QString>());
86
90 ExternalProcess::RETURNSTATE run(const QString& exe, const QStringList& args, const QString& working_dir, const bool verbose, IO_MODE io_mode = IO_MODE::READ_WRITE, const std::map<QString, QString>& env = std::map<QString, QString>());
91
92 private slots:
95
96 private:
98 std::function<void(const String&)> callbackStdOut_;
99 std::function<void(const String&)> callbackStdErr_;
100 };
101} // ns OpenMS
A wrapper around QProcess to conveniently start an external program and forward its outputs.
Definition ExternalProcess.h:39
~ExternalProcess() override
D'tor.
std::function< void(const String &)> callbackStdErr_
Definition ExternalProcess.h:99
ExternalProcess()
default Ctor; callbacks for stdout/stderr are empty
RETURNSTATE
result of calling an external executable
Definition ExternalProcess.h:45
RETURNSTATE run(const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose, String &error_msg, IO_MODE io_mode=IO_MODE::READ_WRITE, const std::map< QString, QString > &env=std::map< QString, QString >())
Runs a program and calls the callback functions from time to time if output from the external program...
void setCallbacks(std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
re-wire the callbacks used during run()
IO_MODE
Open mode for the process.
Definition ExternalProcess.h:54
QProcess * qp_
pointer to avoid including the QProcess header here (it's huge)
Definition ExternalProcess.h:97
ExternalProcess(std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
set the callback functions to process stdout and stderr output when the external process generates it
ExternalProcess::RETURNSTATE run(const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose, IO_MODE io_mode=IO_MODE::READ_WRITE, const std::map< QString, QString > &env=std::map< QString, QString >())
Same as other overload, just without a returned error message.
std::function< void(const String &)> callbackStdOut_
Definition ExternalProcess.h:98
A more convenient string class.
Definition String.h:34
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19