--- a/QTfrontend/net/tcpBase.cpp Mon Jan 30 23:20:28 2012 +0100
+++ b/QTfrontend/net/tcpBase.cpp Mon Jan 30 17:32:18 2012 -0500
@@ -34,96 +34,102 @@
}
TCPBase::TCPBase(bool demoMode) :
- m_isDemoMode(demoMode),
- IPCSocket(0)
+ m_isDemoMode(demoMode),
+ IPCSocket(0)
{
- if(!IPCServer) {
- IPCServer = new QTcpServer(0);
- IPCServer->setMaxPendingConnections(1);
- if (!IPCServer->listen(QHostAddress::LocalHost)) {
- QMessageBox::critical(0, tr("Error"),
- tr("Unable to start the server: %1.")
- .arg(IPCServer->errorString()));
- exit(0); // FIXME - should be graceful exit here
+ if(!IPCServer)
+ {
+ IPCServer = new QTcpServer(0);
+ IPCServer->setMaxPendingConnections(1);
+ if (!IPCServer->listen(QHostAddress::LocalHost))
+ {
+ QMessageBox::critical(0, tr("Error"),
+ tr("Unable to start the server: %1.")
+ .arg(IPCServer->errorString()));
+ exit(0); // FIXME - should be graceful exit here
+ }
}
- }
- ipc_port=IPCServer->serverPort();
+ ipc_port=IPCServer->serverPort();
}
void TCPBase::NewConnection()
{
- if(IPCSocket) {
- // connection should be already finished
- return;
- }
- disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
- IPCSocket = IPCServer->nextPendingConnection();
- if(!IPCSocket) return;
- connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
- connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
- SendToClientFirst();
+ if(IPCSocket)
+ {
+ // connection should be already finished
+ return;
+ }
+ disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
+ IPCSocket = IPCServer->nextPendingConnection();
+ if(!IPCSocket) return;
+ connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
+ connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
+ SendToClientFirst();
}
void TCPBase::RealStart()
{
- connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
- IPCSocket = 0;
+ connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
+ IPCSocket = 0;
- QProcess * process;
- process = new QProcess;
- connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
- QStringList arguments=getArguments();
+ QProcess * process;
+ 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);
+ // redirect everything written on stdout/stderr
+ if(isDevBuild)
+ process->setProcessChannelMode(QProcess::ForwardedChannels);
+ process->start(bindir->absolutePath() + "/hwengine", arguments);
}
void TCPBase::ClientDisconnect()
{
- disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
- onClientDisconnect();
+ disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
+ onClientDisconnect();
- if(srvsList.size()==1) srvsList.pop_front();
- emit isReadyNow();
- IPCSocket->deleteLater();
- deleteLater();
+ if(srvsList.size()==1) srvsList.pop_front();
+ emit isReadyNow();
+ IPCSocket->deleteLater();
+ deleteLater();
}
void TCPBase::ClientRead()
{
- QByteArray readed=IPCSocket->readAll();
- if(readed.isEmpty()) return;
- readbuffer.append(readed);
- onClientRead();
+ QByteArray readed=IPCSocket->readAll();
+ if(readed.isEmpty()) return;
+ readbuffer.append(readed);
+ onClientRead();
}
void TCPBase::StartProcessError(QProcess::ProcessError error)
{
- QMessageBox::critical(0, tr("Error"),
- tr("Unable to run engine: %1 (")
- .arg(error) + bindir->absolutePath() + "/hwengine)");
+ QMessageBox::critical(0, tr("Error"),
+ tr("Unable to run engine: %1 (")
+ .arg(error) + bindir->absolutePath() + "/hwengine)");
}
void TCPBase::tcpServerReady()
{
- disconnect(srvsList.takeFirst(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+ disconnect(srvsList.takeFirst(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
- RealStart();
+ RealStart();
}
void TCPBase::Start()
{
- if(srvsList.isEmpty()) {
- srvsList.push_back(this);
- } else {
- connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
- srvsList.push_back(this);
- return;
- }
+ if(srvsList.isEmpty())
+ {
+ srvsList.push_back(this);
+ }
+ else
+ {
+ connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
+ srvsList.push_back(this);
+ return;
+ }
- RealStart();
+ RealStart();
}
void TCPBase::onClientRead()
@@ -150,7 +156,8 @@
if (!IPCSocket)
{
toSendBuf += buf;
- } else
+ }
+ else
{
if (toSendBuf.size() > 0)
{
@@ -158,9 +165,10 @@
if(m_isDemoMode) demo.append(toSendBuf);
toSendBuf.clear();
}
- if(!buf.isEmpty()) {
- IPCSocket->write(buf);
- if(m_isDemoMode) demo.append(buf);
+ if(!buf.isEmpty())
+ {
+ IPCSocket->write(buf);
+ if(m_isDemoMode) demo.append(buf);
}
}
}