diff --git a/CQtDeployer/main.cpp b/CQtDeployer/main.cpp index 3a9731b..534c923 100644 --- a/CQtDeployer/main.cpp +++ b/CQtDeployer/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); Deploy deploy; - if (deploy.run()) { + if (deploy.run(true)) { app.exit(1); } diff --git a/Deploy/deploy.cpp b/Deploy/deploy.cpp index d530521..35d9d79 100644 --- a/Deploy/deploy.cpp +++ b/Deploy/deploy.cpp @@ -18,22 +18,16 @@ Deploy::Deploy() { _packing = new Packing(); _paramsParser = new ConfigParser(_fileManager, _scaner, _packing); + connect(this, &Deploy::sigStart, this, &Deploy::handleStart, Qt::QueuedConnection); } -int Deploy::run() { - - if (!prepare()) { - return 1; +int Deploy::run(bool async) { + if (async) { + emit sigStart(); + return 0; } - if (!deploy()) { - return 2; - } - - if (!packing()) - return 3; - - return 0; + return runPrivate(); } Deploy::~Deploy() { @@ -86,7 +80,31 @@ bool Deploy::deploy() { return true; } -bool Deploy::packing() { +bool Deploy::packing(bool async) { + if (async) { + connect(_packing, &Packing::sigFinished, this, &Deploy::sigFinish, Qt::QueuedConnection); + } - return _packing->create(); + return _packing->create(async); +} + +int Deploy::runPrivate(bool async) { + if (!prepare()) { + return 1; + } + + if (!deploy()) { + return 2; + } + + if (!packing(async)) + return 3; + + return 0; +} + +void Deploy::handleStart() { + if (int exit = runPrivate(true)) { + emit sigFinish(exit); + } } diff --git a/Deploy/deploy.h b/Deploy/deploy.h index 0ac51a8..f2a4425 100644 --- a/Deploy/deploy.h +++ b/Deploy/deploy.h @@ -10,14 +10,17 @@ #include "deploy_global.h" +#include + class ConfigParser; class Extracter; class FileManager; class DependenciesScanner; class Packing; -class DEPLOYSHARED_EXPORT Deploy +class DEPLOYSHARED_EXPORT Deploy : public QObject { + Q_OBJECT private: ConfigParser * _paramsParser = nullptr; @@ -28,11 +31,19 @@ private: bool prepare(); bool deploy(); - bool packing(); + bool packing(bool async); + int runPrivate(bool async = false); + +private slots: + void handleStart(); + +signals: + void sigFinish(int code); + void sigStart(); public: Deploy(); - int run(); + int run(bool async = false); ~Deploy(); diff --git a/Deploy/packing.cpp b/Deploy/packing.cpp index 9f1852a..0d9a394 100644 --- a/Deploy/packing.cpp +++ b/Deploy/packing.cpp @@ -15,6 +15,9 @@ Packing::Packing() { connect(_proc, &QProcess::readyReadStandardOutput, this, &Packing::handleOutputUpdate, Qt::QueuedConnection); + connect(_proc, qOverload(&QProcess::finished), + this, &Packing::handleFinished, Qt::QueuedConnection); + moveToThread( new QThread(this)); } @@ -26,7 +29,7 @@ void Packing::setDistribution(iDistribution *pakage) { _pakage = pakage; } -bool Packing::create() { +bool Packing::create(bool async) { if (!_pakage) return false; @@ -50,7 +53,7 @@ bool Packing::create() { return false; } - if (!_proc->waitForFinished(-1)) { + if (async && !_proc->waitForFinished(-1)) { return false; } @@ -80,3 +83,7 @@ void Packing::handleOutputUpdate() { qInfo() << erroutLog; } +void Packing::handleFinished(int exitCode, QProcess::ExitStatus ) { + emit sigFinished(exitCode); +} + diff --git a/Deploy/packing.h b/Deploy/packing.h index 2c0b605..20ee27f 100644 --- a/Deploy/packing.h +++ b/Deploy/packing.h @@ -21,13 +21,17 @@ public: Packing(); ~Packing(); void setDistribution(iDistribution *pakage); - bool create(); + bool create(bool async); private: iDistribution *_pakage = nullptr; QProcess *_proc = nullptr; private slots: void handleOutputUpdate(); + void handleFinished(int exitCode, QProcess::ExitStatus); + +signals: + void sigFinished(int code); }; #endif // PACKING_H