merge
authorunc0rr
Thu, 06 Mar 2014 00:19:50 +0400
changeset 10179 26c4256a9e4b
parent 10177 0f9042536c46 (diff)
parent 10178 949b51ca18c6 (current diff)
child 10180 8d4bb51bf5cb
merge
--- a/QTfrontend/net/tcpBase.cpp	Wed Mar 05 12:38:01 2014 +0100
+++ b/QTfrontend/net/tcpBase.cpp	Thu Mar 06 00:19:50 2014 +0400
@@ -43,6 +43,7 @@
 
 EngineInstance::~EngineInstance()
 {
+    qDebug() << "EngineInstance delete" << QThread::currentThreadId();
 }
 
 void EngineInstance::setArguments(const QStringList & arguments)
@@ -64,7 +65,11 @@
 
 void EngineInstance::start()
 {
+    qDebug() << "EngineInstance start" << QThread::currentThreadId();
+
     RunEngine(m_argv.size(), m_argv.data());
+
+    emit finished();
 }
 
 #endif
@@ -74,6 +79,23 @@
 
 TCPBase::~TCPBase()
 {
+    if(m_hasStarted)
+    {
+        if(IPCSocket)
+            IPCSocket->close();
+
+        if(m_connected)
+        {
+#ifdef HWLIBRARY
+            if(!thread)
+                qDebug("WTF");
+            thread->quit();
+            thread->wait();
+#else
+            process->waitForFinished(1000);
+#endif
+        }
+    }
     // make sure this object is not in the server list anymore
     srvsList.removeOne(this);
 
@@ -135,7 +157,7 @@
     IPCSocket = 0;
 
 #ifdef HWLIBRARY
-    QThread *thread = new QThread();
+    thread = new QThread(this);
     EngineInstance *instance = new EngineInstance();
     instance->setArguments(getArguments());
 
@@ -147,8 +169,7 @@
     connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater()));
     thread->start();
 #else
-    QProcess * process;
-    process = new QProcess();
+    process = new QProcess(this);
     connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
     QStringList arguments = getArguments();
 
@@ -168,7 +189,13 @@
     onClientDisconnect();
 
     if(!simultaneousRun())
+    {
+#ifdef HWLIBRARY
+        thread->quit();
+        thread->wait();
+#endif
         emit isReadyNow();
+    }
     IPCSocket->deleteLater();
 
     deleteLater();
@@ -176,9 +203,9 @@
 
 void TCPBase::ClientRead()
 {
-    QByteArray readed=IPCSocket->readAll();
-    if(readed.isEmpty()) return;
-    readbuffer.append(readed);
+    QByteArray read = IPCSocket->readAll();
+    if(read.isEmpty()) return;
+    readbuffer.append(read);
     onClientRead();
 }
 
@@ -211,7 +238,7 @@
             && (last->parent() == parent()))
         {
             srvsList.removeLast();
-            last->deleteLater();
+            delete last;
             Start(couldCancelPreviousRequest);
         } else
         {
--- a/QTfrontend/net/tcpBase.h	Wed Mar 05 12:38:01 2014 +0100
+++ b/QTfrontend/net/tcpBase.h	Thu Mar 06 00:19:50 2014 +0400
@@ -27,6 +27,7 @@
 #include <QString>
 #include <QDir>
 #include <QProcess>
+#include <QThread>
 #include <QPointer>
 #include <QVector>
 #include <QList>
@@ -72,7 +73,11 @@
 
     private:
         static QPointer<QTcpServer> IPCServer;
-
+#ifdef HWLIBRARY
+        QThread * thread;
+#else
+        QProcess * process;
+#endif
         bool m_isDemoMode;
         bool m_connected;
         void RealStart();
@@ -98,9 +103,11 @@
     void setArguments(const QStringList & arguments);
 
 public slots:
-    void start(void);
+    void start();
+
 signals:
-    void finished(void);
+    void finished();
+
 private:
     QList<QByteArray> m_arguments;
     QVector<char *> m_argv;