|
@@ -7,6 +7,7 @@
|
|
|
#include <sys/wait.h>
|
|
|
#include <thread>
|
|
|
#include <unistd.h>
|
|
|
+#include <QGuiApplication>
|
|
|
|
|
|
#include "qmlhandler.h"
|
|
|
#include <boost/asio.hpp>
|
|
@@ -21,12 +22,20 @@ int inpipefd[2];
|
|
|
int outpipefd[2];
|
|
|
char buf[1024];
|
|
|
|
|
|
+bool programActive = true;
|
|
|
+
|
|
|
+void QMLHandler::onExit() {
|
|
|
+ write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
|
|
|
+}
|
|
|
+
|
|
|
void QMLHandler::handleJSON(string buffer) {
|
|
|
Json::Value root;
|
|
|
- Json::Reader reader;
|
|
|
+ Json::CharReaderBuilder builder;
|
|
|
+ Json::CharReader * reader = builder.newCharReader();
|
|
|
+ string jsonError;
|
|
|
+
|
|
|
+ bool parsingSuccessful = reader->parse(buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
|
|
|
|
|
|
- bool parsingSuccessful = reader.parse(buffer, root);
|
|
|
- qInfo() << parsingSuccessful;
|
|
|
if (!parsingSuccessful) {
|
|
|
return;
|
|
|
}
|
|
@@ -38,7 +47,7 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
}
|
|
|
|
|
|
else if (cmd == "close") {
|
|
|
- exit(0);
|
|
|
+ programActive = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -49,7 +58,7 @@ void QMLHandler::readPipeLoop() {
|
|
|
inPipeStatus.fd = inpipefd[0];
|
|
|
inPipeStatus.events = POLLIN;
|
|
|
|
|
|
- while (true) {
|
|
|
+ while (programActive) {
|
|
|
poll(&inPipeStatus, 1, 100);
|
|
|
|
|
|
if (inPipeStatus.revents & POLLIN) {
|
|
@@ -79,12 +88,6 @@ void QMLHandler::readPipeLoop() {
|
|
|
|
|
|
QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
|
|
|
|
|
|
-// Main
|
|
|
-void QMLHandler::onClosing() {
|
|
|
- qInfo() << "Closing";
|
|
|
- write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
|
|
|
-}
|
|
|
-
|
|
|
// Sending
|
|
|
void QMLHandler::onSendingSelectFileButton(QUrl url) {
|
|
|
emit log("File Selected: " + url.toString());
|
|
@@ -114,7 +117,7 @@ void QMLHandler::onIpPopupEnterIp(QString ip) {
|
|
|
// Child
|
|
|
dup2(outpipefd[0], STDIN_FILENO);
|
|
|
dup2(inpipefd[1], STDOUT_FILENO);
|
|
|
- dup2(inpipefd[1], STDERR_FILENO);
|
|
|
+ //dup2(inpipefd[1], STDERR_FILENO);
|
|
|
|
|
|
// ask kernel to deliver SIGTERM in case the parent dies
|
|
|
prctl(PR_SET_PDEATHSIG, SIGTERM);
|