QTfrontend/tcpBase.cpp
changeset 389 9628e69b609f
parent 381 6096d74c37da
child 390 dca6bd77d71d
equal deleted inserted replaced
388:dcf5335940bd 389:9628e69b609f
    24 #include <QImage>
    24 #include <QImage>
    25 
    25 
    26 #include "hwconsts.h"
    26 #include "hwconsts.h"
    27 
    27 
    28 QList<TCPBase*> srvsList;
    28 QList<TCPBase*> srvsList;
    29 QTcpServer* TCPBase::IPCServer(0);
    29 QPointer<QTcpServer> TCPBase::IPCServer(0);
    30 
    30 
    31 TCPBase::TCPBase(bool demoMode) :
    31 TCPBase::TCPBase(bool demoMode) :
    32   m_isDemoMode(demoMode),
    32   m_isDemoMode(demoMode),
    33   IPCSocket(0)
    33   IPCSocket(0)
    34 {
    34 {
    49 {
    49 {
    50   if(IPCSocket) {
    50   if(IPCSocket) {
    51     // connection should be already finished
    51     // connection should be already finished
    52     return;
    52     return;
    53   }
    53   }
       
    54   disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    54   IPCSocket = IPCServer->nextPendingConnection();
    55   IPCSocket = IPCServer->nextPendingConnection();
    55   if(!IPCSocket) return;
    56   if(!IPCSocket) return;
    56   connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
    57   connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
       
    58   connect(IPCSocket, SIGNAL(disconnected()), IPCSocket, SLOT(deleteLater()));
    57   connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
    59   connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
    58   SendToClientFirst();
    60   SendToClientFirst();
    59 }
    61 }
    60 
    62 
    61 void TCPBase::RealStart()
    63 void TCPBase::RealStart()
    62 {
    64 {
    63   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    65   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
    64   IPCSocket = 0;
    66   IPCSocket = 0;
    65   
    67 
    66   QProcess * process;
    68   QProcess * process;
    67   process = new QProcess;
    69   process = new QProcess;
    68   connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
    70   connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
    69   QStringList arguments=setArguments();
    71   QStringList arguments=setArguments();
    70   process->start(bindir->absolutePath() + "/hwengine", arguments);
    72   process->start(bindir->absolutePath() + "/hwengine", arguments);
    71 }
    73 }
    72 
    74 
    73 void TCPBase::ClientDisconnect()
    75 void TCPBase::ClientDisconnect()
    74 {
    76 {
    75   IPCSocket->close();
       
    76   IPCSocket->deleteLater();
       
    77   // IPCSocket = 0; // FIXME: breaks image receiving
       
    78 
       
    79   onClientDisconnect();
    77   onClientDisconnect();
    80 
    78 
    81   readbuffer.clear();
    79   readbuffer.clear();
    82 
    80 
    83   if(srvsList.size()==1) srvsList.pop_front();
    81   if(srvsList.size()==1) srvsList.pop_front();
    97 			.arg(error) + bindir->absolutePath() + "/hwengine)");
    95 			.arg(error) + bindir->absolutePath() + "/hwengine)");
    98 }
    96 }
    99 
    97 
   100 void TCPBase::tcpServerReady()
    98 void TCPBase::tcpServerReady()
   101 {
    99 {
   102   disconnect(srvsList.front(), SIGNAL(isReadyNow()), *(++srvsList.begin()), SLOT(tcpServerReady()));
   100   disconnect(srvsList.front(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   103   srvsList.pop_front();
   101   srvsList.pop_front();
   104 
   102 
   105   RealStart();
   103   RealStart();
   106 }
   104 }
   107 
   105 
   112   } else {
   110   } else {
   113     connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   111     connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   114     srvsList.push_back(this);
   112     srvsList.push_back(this);
   115     return;
   113     return;
   116   }
   114   }
   117   
   115 
   118   RealStart();
   116   RealStart();
   119 }
   117 }
   120 
   118 
   121 void TCPBase::onClientRead()
   119 void TCPBase::onClientRead()
   122 {
   120 {