|
@@ -25,7 +25,11 @@
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
+thread readPipeLoopThread;
|
|
|
+thread notificationsLoopThread;
|
|
|
+
|
|
|
namespace CliManager {
|
|
|
+
|
|
|
QMLHandler *qmlHandler;
|
|
|
bool programActive = true;
|
|
|
int inpipefd[2];
|
|
@@ -41,7 +45,14 @@ void CliManager::writeToCli(QString command) {
|
|
|
write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
|
|
|
}
|
|
|
|
|
|
-void CliManager::onExit() { writeToCli("exit"); }
|
|
|
+void CliManager::onExit() {
|
|
|
+ // stop threads
|
|
|
+ CliManager::setProgramActive(false);
|
|
|
+ readPipeLoopThread.join();
|
|
|
+ notificationsLoopThread.join();
|
|
|
+
|
|
|
+ writeToCli("exit");
|
|
|
+}
|
|
|
|
|
|
void CliManager::setQmlHandler(QMLHandler *q) { qmlHandler = q; }
|
|
|
|
|
@@ -67,8 +78,9 @@ void CliManager::init() {
|
|
|
close(outpipefd[0]);
|
|
|
close(inpipefd[1]);
|
|
|
|
|
|
- std::thread(&CliManager::readPipeLoop).detach();
|
|
|
- std::thread(&CliManager::notificationsLoop).detach();
|
|
|
+ // start threads
|
|
|
+ readPipeLoopThread = thread(&CliManager::readPipeLoop);
|
|
|
+ notificationsLoopThread = thread(&CliManager::notificationsLoop);
|
|
|
}
|
|
|
|
|
|
std::vector<std::string> tokenizeByNewlines(std::string in) {
|