LCOV - code coverage report
Current view: top level - src - executor.h (source / functions) Hit Total Coverage
Test: .lcov.total Lines: 1 2 50.0 %
Date: 2018-06-12 11:27:04 Functions: 2 9 22.2 %

          Line data    Source code
       1             : #ifndef EXECUTOR_H
       2             : #define EXECUTOR_H
       3             : 
       4             : #include <QObject>
       5             : #include <QProcess>
       6             : #include <QQueue>
       7             : 
       8             : /*!
       9             :     \class Executor
      10             :     \brief Executes external commands for handleing password, git and other data
      11             : */
      12          16 : class Executor : public QObject {
      13             :   Q_OBJECT
      14             : 
      15             :   /*!
      16             :       \struct execQueueItem
      17             :       \brief Execution queue items for non-interactive ordered execution.
      18             :    */
      19           0 :   struct execQueueItem {
      20             :     /**
      21             :      * @brief id    identifier of process given by the caller
      22             :      */
      23             :     int id;
      24             :     /**
      25             :      * @brief app   executable path.
      26             :      */
      27             :     QString app;
      28             :     /**
      29             :      * @brief args  arguments for executable.
      30             :      */
      31             :     QStringList args;
      32             :     /**
      33             :      * @brief input     data to write to stdin of process
      34             :      */
      35             :     QString input;
      36             :     /**
      37             :      * @brief readStdout    whether to read stdout
      38             :      */
      39             :     bool readStdout;
      40             :     /**
      41             :      * @brief readStderr    whether to read stderr
      42             :      *                      it's read regardless of this setting in case of
      43             :      *                      non-0 return value of process
      44             :      */
      45             :     bool readStderr;
      46             :     /**
      47             :      * @brief workingDir    working directory in which the process will be
      48             :      *                      started
      49             :      */
      50             :     QString workingDir;
      51             :   };
      52             : 
      53             :   QQueue<execQueueItem> m_execQueue;
      54             :   QProcess m_process;
      55             :   bool running;
      56             :   void executeNext();
      57             : 
      58             : public:
      59             :   explicit Executor(QObject *parent = 0);
      60             : 
      61             :   void execute(int id, const QString &app, const QStringList &args,
      62             :                bool readStdout, bool readStderr = true);
      63             : 
      64             :   void execute(int id, const QString &workDir, const QString &app,
      65             :                const QStringList &args, bool readStdout,
      66             :                bool readStderr = true);
      67             : 
      68             :   void execute(int id, const QString &app, const QStringList &args,
      69             :                QString input = QString(), bool readStdout = false,
      70             :                bool readStderr = true);
      71             : 
      72             :   void execute(int id, const QString &workDir, const QString &app,
      73             :                const QStringList &args, QString input = QString(),
      74             :                bool readStdout = false, bool readStderr = true);
      75             : 
      76             :   int executeBlocking(QString app, const QStringList &args,
      77             :                       QString input = QString(),
      78             :                       QString *process_out = Q_NULLPTR,
      79             :                       QString *process_err = Q_NULLPTR);
      80             : 
      81             :   int executeBlocking(QString app, const QStringList &args,
      82             :                       QString *process_out, QString *process_err = Q_NULLPTR);
      83             : 
      84             :   void setEnvironment(const QStringList &env);
      85             : 
      86             :   int cancelNext();
      87             : private slots:
      88             :   void finished(int exitCode, QProcess::ExitStatus exitStatus);
      89             : signals:
      90             :   /**
      91             :    * @brief finished    signal that is emited when process finishes
      92             :    *
      93             :    * @param id          id of the process
      94             :    * @param exitCode    return code of the process
      95             :    * @param output      stdout produced by the process
      96             :    * @param errout      stderr produced by the process
      97             :    */
      98             :   void finished(int id, int exitCode, const QString &output,
      99             :                 const QString &errout);
     100             :   /**
     101             :    * @brief starting    signal that is emited when process starts
     102             :    */
     103             :   void starting();
     104             :   /**
     105             :    * @brief error       signal that is emited when process finishes with an
     106             :    * error
     107             :    *
     108             :    * @param id          id of the process
     109             :    * @param exitCode    return code of the process
     110             :    * @param output      stdout produced by the process
     111             :    * @param errout      stderr produced by the process
     112             :    */
     113             :   void error(int id, int exitCode, const QString &output,
     114             :              const QString &errout);
     115             : };
     116             : 
     117             : #endif // EXECUTOR_H

Generated by: LCOV version 1.13