56 lines
1.3 KiB
C
Raw Normal View History

#ifndef COMMAND_H_INCLUDED
#define COMMAND_H_INCLUDED
#include <QObject>
#include <QCoreApplication>
#include <QString>
#include <QStringList>
#include <QProcess>
#include <QMutex>
2024-12-20 13:01:34 +01:00
class Worker;
class Command : public QObject {
Q_OBJECT
2025-02-05 16:25:01 +01:00
protected:
QString m_command;
mutable QString m_commandResult;
2025-02-05 16:25:01 +01:00
private:
int m_waitForStartTimeout;
int m_waitForFinishTimeout;
int m_exitCode;
2025-02-05 16:25:01 +01:00
protected:
mutable QMutex m_mtx;
2025-02-05 16:25:01 +01:00
private:
2024-12-20 13:01:34 +01:00
QProcess *m_p;
2025-02-05 16:25:01 +01:00
protected:
2024-12-20 13:01:34 +01:00
Worker *m_worker;
2025-02-05 16:25:01 +01:00
public:
explicit Command(QString const &command,
int start_timeout = 100000,
int finish_timeout = 100000);
QString getCommandResult(bool reset = false) const;
QString command() const { return m_command; }
bool execute(QString workingDirectory, QStringList args = QStringList());
2024-12-20 13:01:34 +01:00
bool start(QString workingDirectory, QStringList args = QStringList());
int exitCode() const { return m_exitCode; }
2024-12-20 13:01:34 +01:00
void setWorker(Worker *worker) {m_worker = worker; }
Worker const *worker() const { return m_worker; }
Worker *worker() { return m_worker; }
2024-12-20 13:01:34 +01:00
2025-02-05 16:25:01 +01:00
protected slots:
virtual void readyReadStandardOutput();
virtual void readyReadStandardError();
2025-02-05 16:25:01 +01:00
virtual void finished(int exitCode, QProcess::ExitStatus exitStatus);
};
2025-02-05 16:25:01 +01:00
#endif // COMMAND_H_INCLUDED