1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
   | #include "sirifserver.h"
 
SirifServer::SirifServer(int port, const QHostAddress& address, const QString& name, QObject* pParent):QThread(pParent)
{
   m_IpAddress = address;
   m_QStrName = name;
   m_Port = port;
}
 
 
/** main loop of the thread */
void SirifServer::run()
{
   connect( &m_TcpSocket,
            SIGNAL(error(QAbstractSocket::SocketError)),
            this,
            SLOT(error(QAbstractSocket::SocketError)),
            Qt::QueuedConnection );
 
   connect( &m_TcpSocket,
            SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this,
            SLOT(stateChanged(QAbstractSocket::SocketState)),
            Qt::QueuedConnection );
 
   // Launch the connection
   m_Mutex.lock();
   if ( m_QStrName.length() )
      m_TcpSocket.connectToHost( m_QStrName, m_Port );
   else
      m_TcpSocket.connectToHost( m_IpAddress, m_Port );
   m_Mutex.unlock();
   exec();
}
 
void SirifServer::connectToRemote()
{
   // Check if the thread is already launch, if not launched, launch it now
  if ( !isRunning() )
      start();
}
 
/** This Qt signal is emitted by the QTcpSocket. */
void SirifServer::error(QAbstractSocket::SocketError ErrorValue)
{
   emit error( m_QStrName, ErrorValue );
}
 
/** This Qt signal is emitted by the QTcpSocket. */
void SirifServer::stateChanged( QAbstractSocket::SocketState State)
{
   emit stateChanged( m_QStrName, State );
} | 
Partager