From 016d79347d429c291ea65eb95663e200e1e601f2 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sat, 25 Dec 2010 13:57:40 +0000 Subject: Finished removing QThread from Protocol-server code. Seems to work fine... git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@33 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR/FGServer.cpp | 94 +++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 43 deletions(-) (limited to 'FaceTrackNoIR/FGServer.cpp') diff --git a/FaceTrackNoIR/FGServer.cpp b/FaceTrackNoIR/FGServer.cpp index 47ca31ba..9f362e52 100644 --- a/FaceTrackNoIR/FGServer.cpp +++ b/FaceTrackNoIR/FGServer.cpp @@ -25,6 +25,11 @@ * to FlightGear, using UDP. * * It is based on the (Linux) example made by Melchior FRANZ. * ********************************************************************************/ +/* + Modifications (last one on top): + 20101224 - WVR: Base class is no longer inheriting QThread. sendHeadposeToGame + is called from run() of Tracker.cpp +*/ #include #include #include "FGServer.h" @@ -36,43 +41,26 @@ FGServer::FGServer( Tracker *parent ) { // Save the parent headTracker = parent; + loadSettings(); +} - // Create events - //m_StopThread = CreateEvent(0, TRUE, FALSE, 0); - //m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); +/** destructor **/ +FGServer::~FGServer() { + inSocket->disconnectFromHost(); + inSocket->waitForDisconnected(); + outSocket->disconnectFromHost(); + outSocket->waitForDisconnected(); - loadSettings(); + delete inSocket; + delete outSocket; } // -// Callback function registered in the run() method. -// Retrieve all pending Datagrams (typically 1) and send a reply, containing the headpose-data. +// Update Headpose in Game. // -void FGServer::readPendingDatagrams() -{ -QHostAddress sender; -quint16 senderPort; -qint32 cmd; +void FGServer::sendHeadposeToGame() { int no_bytes; - // - // Read data from FlightGear - // - while (inSocket->hasPendingDatagrams()) { - QByteArray datagram; - datagram.resize(inSocket->pendingDatagramSize()); - -// qDebug() << "FGServer::readPendingDatagrams says: size =" << inSocket->pendingDatagramSize(); - - inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort); -// qDebug() << "FGServer::readPendingDatagrams says: data =" << cmd; - - fg_cmd = cmd; // Let's just accept that command for now... - if ( cmd > 0 ) { - headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle - } - } - // // Copy the Raw measurements directly to the client. // @@ -100,9 +88,40 @@ int no_bytes; } -/** QThread run @override **/ -void FGServer::run() { +// +// Callback function registered in the run() method. +// Retrieve all pending Datagrams (typically 1) and send a reply, containing the headpose-data. +// +void FGServer::readPendingDatagrams() +{ +QHostAddress sender; +quint16 senderPort; + + // + // Read data from FlightGear + // + while (inSocket->hasPendingDatagrams()) { + QByteArray datagram; + datagram.resize(inSocket->pendingDatagramSize()); + +// qDebug() << "FGServer::readPendingDatagrams says: size =" << inSocket->pendingDatagramSize(); + inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort); +// qDebug() << "FGServer::readPendingDatagrams says: data =" << cmd; + + fg_cmd = cmd; // Let's just accept that command for now... + if ( cmd > 0 ) { + headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle + } + } +} + +// +// Check if the Client DLL exists and load it (to test it), if so. +// Returns 'true' if all seems OK. +// +bool FGServer::checkServerInstallationOK( HANDLE handle ) +{ // Init. the data TestData.x = 0.0f; TestData.y = 0.0f; @@ -123,19 +142,8 @@ void FGServer::run() { // Connect the inSocket to the member-function, to read FlightGear commands connect(inSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection); -// exec(); // Exec only returns, when the thread terminates... -} -/** QThread terminate @override **/ -void FGServer::terminate() { - - inSocket->disconnectFromHost(); - inSocket->waitForDisconnected(); - outSocket->disconnectFromHost(); - outSocket->waitForDisconnected(); - - delete inSocket; - delete outSocket; + return true; } // -- cgit v1.2.3