QTfrontend/net/tcpBase.cpp
changeset 9800 169fbb968bb3
parent 9212 1d4e1469940b
child 9998 736015b847e3
equal deleted inserted replaced
9797:1fdc1507e42d 9800:169fbb968bb3
    78 
    78 
    79 TCPBase::TCPBase(bool demoMode, QObject *parent) :
    79 TCPBase::TCPBase(bool demoMode, QObject *parent) :
    80     QObject(parent),
    80     QObject(parent),
    81     m_hasStarted(false),
    81     m_hasStarted(false),
    82     m_isDemoMode(demoMode),
    82     m_isDemoMode(demoMode),
       
    83     m_connected(false),
    83     IPCSocket(0)
    84     IPCSocket(0)
    84 {
    85 {
    85     if(!IPCServer)
    86     if(!IPCServer)
    86     {
    87     {
    87         IPCServer = new QTcpServer(0);
    88         IPCServer = new QTcpServer(0);
   101     if(IPCSocket)
   102     if(IPCSocket)
   102     {
   103     {
   103         // connection should be already finished
   104         // connection should be already finished
   104         return;
   105         return;
   105     }
   106     }
       
   107 
   106     disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   108     disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   107     IPCSocket = IPCServer->nextPendingConnection();
   109     IPCSocket = IPCServer->nextPendingConnection();
       
   110 
   108     if(!IPCSocket) return;
   111     if(!IPCSocket) return;
       
   112 
       
   113     m_connected = true;
       
   114 
   109     connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
   115     connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
   110     connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
   116     connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
   111     SendToClientFirst();
   117     SendToClientFirst();
       
   118 
       
   119     if(simultaneousRun())
       
   120     {
       
   121         srvsList.removeOne(this);
       
   122         emit isReadyNow();
       
   123     }
   112 }
   124 }
   113 
   125 
   114 void TCPBase::RealStart()
   126 void TCPBase::RealStart()
   115 {
   127 {
   116     connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   128     connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   147 void TCPBase::ClientDisconnect()
   159 void TCPBase::ClientDisconnect()
   148 {
   160 {
   149     disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
   161     disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
   150     onClientDisconnect();
   162     onClientDisconnect();
   151 
   163 
   152     emit isReadyNow();
   164     if(!simultaneousRun())
       
   165         emit isReadyNow();
   153     IPCSocket->deleteLater();
   166     IPCSocket->deleteLater();
   154 
   167 
   155     deleteLater();
   168     deleteLater();
   156 }
   169 }
   157 
   170 
   186     else
   199     else
   187     {
   200     {
   188         TCPBase * last = srvsList.last();
   201         TCPBase * last = srvsList.last();
   189         if(couldCancelPreviousRequest
   202         if(couldCancelPreviousRequest
   190             && last->couldBeRemoved()
   203             && last->couldBeRemoved()
       
   204             && (last->isConnected() || !last->hasStarted())
   191             && (last->parent() == parent()))
   205             && (last->parent() == parent()))
   192         {
   206         {
   193             srvsList.removeLast();
   207             srvsList.removeLast();
   194             last->deleteLater();
   208             last->deleteLater();
   195             Start(couldCancelPreviousRequest);
   209             Start(couldCancelPreviousRequest);
   196         } else
   210         } else
   197         {
   211         {
   198             connect(srvsList.last(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   212             connect(last, SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   199             srvsList.push_back(this);
   213             srvsList.push_back(this);
   200         }
   214         }
   201     }
   215     }
   202 }
   216 }
   203 
   217 
   244 
   258 
   245 bool TCPBase::couldBeRemoved()
   259 bool TCPBase::couldBeRemoved()
   246 {
   260 {
   247     return false;
   261     return false;
   248 }
   262 }
       
   263 
       
   264 bool TCPBase::isConnected()
       
   265 {
       
   266     return m_connected;
       
   267 }
       
   268 
       
   269 bool TCPBase::simultaneousRun()
       
   270 {
       
   271     return false;
       
   272 }
       
   273 
       
   274 bool TCPBase::hasStarted()
       
   275 {
       
   276     return m_hasStarted;
       
   277 }