OpenMS
ExternalProcess.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- 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 
18 class QProcess; // forward declare to avoid header include
19 class QString;
20 class QStringList;
21 
22 namespace OpenMS
23 {
24 
36  class OPENMS_DLLAPI ExternalProcess
37  : public QObject
38  {
39  Q_OBJECT
40 
41  public:
43  enum class RETURNSTATE
44  {
45  SUCCESS,
46  NONZERO_EXIT,
47  CRASH,
48  FAILED_TO_START
49  };
50 
52  enum class IO_MODE
53  {
54  NO_IO,
55  READ_ONLY,
56  WRITE_ONLY,
57  READ_WRITE
58  };
59 
62 
64  ExternalProcess(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
65 
67  ~ExternalProcess() override ;
68 
70  void setCallbacks(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
71 
83  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);
84 
88  ExternalProcess::RETURNSTATE run(const QString& exe, const QStringList& args, const QString& working_dir, const bool verbose, IO_MODE io_mode = IO_MODE::READ_WRITE);
89 
90  private slots:
93 
94  private:
96  std::function<void(const String&)> callbackStdOut_;
97  std::function<void(const String&)> callbackStdErr_;
98  };
99 } // ns OpenMS
A wrapper around QProcess to conveniently start an external program and forward its outputs.
Definition: ExternalProcess.h:38
~ExternalProcess() override
D'tor.
std::function< void(const String &)> callbackStdErr_
Definition: ExternalProcess.h:97
ExternalProcess()
default Ctor; callbacks for stdout/stderr are empty
RETURNSTATE
result of calling an external executable
Definition: ExternalProcess.h:44
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)
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:53
QProcess * qp_
pointer to avoid including the QProcess header here (it's huge)
Definition: ExternalProcess.h:95
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
std::function< void(const String &)> callbackStdOut_
Definition: ExternalProcess.h:96
ExternalProcess::RETURNSTATE run(const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose, IO_MODE io_mode=IO_MODE::READ_WRITE)
Same as other overload, just without a returned error message.
A more convenient string class.
Definition: String.h:34
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19