summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-05-03 11:48:49 +0200
committerSimon Rettberg2024-05-03 11:48:49 +0200
commit972fced03e9660c97a4dc107b6d9b415e893dae0 (patch)
treea0407c62a70b0f8e515b25ce374a3fad7dfd7aca
parentStay on top, ignore close events (diff)
downloadcowgui-972fced03e9660c97a4dc107b6d9b415e893dae0.tar.gz
cowgui-972fced03e9660c97a4dc107b6d9b415e893dae0.tar.xz
cowgui-972fced03e9660c97a4dc107b6d9b415e893dae0.zip
Handle command line, add sending SIGQUIT to dnbd3-fuse
-rw-r--r--src/gui.cpp21
-rw-r--r--src/gui.h3
-rw-r--r--src/main.cpp26
3 files changed, 41 insertions, 9 deletions
diff --git a/src/gui.cpp b/src/gui.cpp
index 02925ad..67f961c 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -13,6 +13,8 @@
#include <QJsonArray>
#include <QCloseEvent>
+#include <signal.h>
+
static QString STATE_COPYING("COPYING"); // Still busy copying original file, new chunks are only accepted in already copied range
static QString STATE_WAITING_FOR_UPLOAD_DONE("WAITING_FOR_UPLOAD_DONE"); // Copying done, just waiting for new chunks until client signals that it's done
static QString STATE_WAITING_FOR_COPYING_DONE("WAITING_FOR_COPYING_DONE"); // Copying not done, but dnbd3-fuse already told us it's done, wait for copying
@@ -21,16 +23,17 @@ static QString STATE_PROCESSING("PROCESSING"); // Hashing, renaming, creating DB
static QString STATE_ERROR("ERROR");
static QString STATE_COMPLETELY_DONE("COMPLETELY_DONE");
-Gui::Gui(const char *urlbase, const char *uuid, QWidget *parent)
+Gui::Gui(const QString &urlbase, const QString &uuid, int dnbd3pid, QWidget *parent)
: QDialog(parent)
, _nam(new QNetworkAccessManager(this))
- , _urlStatus(QString(urlbase).append("status/").append(uuid))
- , _urlAbort(QString(urlbase).append("abort/").append(uuid))
- , _urlFinish(QString(urlbase).append("finish/").append(uuid))
+ , _urlStatus(urlbase + QLatin1String("status/") + uuid)
+ , _urlAbort(urlbase + QLatin1String("abort/") + uuid)
+ , _urlFinish(urlbase + QLatin1String("finish/") + uuid)
, _denyInteraction(false)
, _allowClose(false)
, _tmrStatus(new QTimer(this))
, _status(nullptr)
+ , _dnbd3pid(dnbd3pid)
{
_nam->setAutoDeleteReplies(true);
_nam->setTransferTimeout(5000);
@@ -162,14 +165,18 @@ void Gui::pushedCancel(bool)
}
if (_denyInteraction)
return;
+ if (_remoteState == STATE_COMPLETELY_DONE) {
+ _btnAbort->setEnabled(false);
+ return;
+ }
if (_remoteState != STATE_ERROR) {
int ret = QMessageBox::question(this, tr("Bestätigung"), tr("Wollen Sie diesen Bearbeitungsvorgang wirklich abbrechen?"));
if (ret == QMessageBox::No)
return;
}
- if (_remoteState == STATE_COMPLETELY_DONE) {
- _btnAbort->setEnabled(false);
- return;
+ if (_dnbd3pid != 0 && _dnbd3pid != -1) {
+ // SIGQUIT tells dnbd3-fuse to stop uploading
+ ::kill(_dnbd3pid, SIGQUIT);
}
_denyInteraction = true;
QNetworkReply *reply = _nam->post(QNetworkRequest(_urlAbort), QByteArray());
diff --git a/src/gui.h b/src/gui.h
index c4a4b39..24b4478 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -16,7 +16,7 @@ class Gui : public QDialog
{
Q_OBJECT
public:
- explicit Gui(const char *urlbase, const char *uuid, QWidget *parent = nullptr);
+ explicit Gui(const QString &urlbase, const QString &uuid, int dnbd3pid, QWidget *parent = nullptr);
~Gui();
protected:
@@ -40,6 +40,7 @@ private:
QTimer *_tmrStatus;
QHash<QString, Progress*> _items;
QLabel *_status;
+ int _dnbd3pid;
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 310d2a3..51c9899 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,11 +1,35 @@
#include "gui.h"
#include <QApplication>
+#include <QCommandLineOption>
+#include <QCommandLineParser>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- Gui window("http://10.4.9.57/cow/", "uuuuuuid");
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QObject::tr("CoW-GUI for dnbd3-fuse sessions"));
+ parser.addHelpOption();
+ QCommandLineOption sessionOption(QStringList() << QLatin1String("session") << QLatin1String("s"),
+ QObject::tr("Session ID to use when talking to server"),
+ QLatin1String("sessionid"));
+ QCommandLineOption urlOption(QStringList() << QLatin1String("url") << QLatin1String("u"),
+ QObject::tr("URL base of server to talk to"),
+ QLatin1String("url"));
+ QCommandLineOption pidOption(QStringList() << QLatin1String("pid") << QLatin1String("p"),
+ QObject::tr("PID of dnbd3-fuse, so we can cancel the upload via SIGQUIT on abort"),
+ QLatin1String("pid"));
+ parser.addOption(sessionOption);
+ parser.addOption(urlOption);
+ parser.addOption(pidOption);
+ parser.process(app);
+
+ if (!parser.isSet(sessionOption) || !parser.isSet(urlOption) || !parser.isSet(pidOption)) {
+ parser.showHelp();
+ return 1;
+ }
+
+ Gui window(parser.value(urlOption), parser.value(sessionOption), parser.value(pidOption).toInt());
window.show();
return QGuiApplication::exec();