--- a/QTfrontend/net/tcpBase.cpp Mon Nov 19 13:21:20 2012 +0100
+++ b/QTfrontend/net/tcpBase.cpp Mon Nov 19 23:43:45 2012 +0400
@@ -31,11 +31,15 @@
TCPBase::~TCPBase()
{
+ // make sure this object is not in the server list anymore
+ srvsList.removeOne(this);
+
if (IPCSocket)
IPCSocket->deleteLater();
}
TCPBase::TCPBase(bool demoMode) :
+ m_hasStarted(false),
m_isDemoMode(demoMode),
IPCSocket(0)
{
@@ -71,9 +75,6 @@
connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
SendToClientFirst();
-
- if(srvsList.size()==1) srvsList.pop_front();
- emit isReadyNow();
}
void TCPBase::RealStart()
@@ -82,14 +83,17 @@
IPCSocket = 0;
QProcess * process;
- process = new QProcess;
+ process = new QProcess();
connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
QStringList arguments=getArguments();
// redirect everything written on stdout/stderr
if(isDevBuild)
process->setProcessChannelMode(QProcess::ForwardedChannels);
+
process->start(bindir->absolutePath() + "/hwengine", arguments);
+
+ m_hasStarted = true;
}
void TCPBase::ClientDisconnect()
@@ -97,13 +101,9 @@
disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
onClientDisconnect();
- /* if(srvsList.size()==1) srvsList.pop_front();
- emit isReadyNow();*/
+ emit isReadyNow();
IPCSocket->deleteLater();
- // make sure this object is not in the server list anymore
- srvsList.removeOne(this);
-
deleteLater();
}
@@ -130,25 +130,31 @@
void TCPBase::tcpServerReady()
{
- disconnect(srvsList.takeFirst(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+ disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
RealStart();
}
-void TCPBase::Start()
+void TCPBase::Start(bool couldCancelPreviousRequest)
{
if(srvsList.isEmpty())
{
srvsList.push_back(this);
+ RealStart();
}
else
{
- connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
- srvsList.push_back(this);
- return;
+ if(couldCancelPreviousRequest && srvsList.last()->couldBeRemoved())
+ {
+ TCPBase * last = srvsList.takeLast();
+ last->deleteLater();
+ Start(couldCancelPreviousRequest);
+ } else
+ {
+ connect(srvsList.last(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+ srvsList.push_back(this);
+ }
}
-
- RealStart();
}
void TCPBase::onClientRead()
@@ -191,3 +197,8 @@
}
}
}
+
+bool TCPBase::couldBeRemoved()
+{
+ return false;
+}