diff options
author | Wim Vriend <facetracknoir@gmail.com> | 2010-12-25 13:57:40 +0000 |
---|---|---|
committer | Wim Vriend <facetracknoir@gmail.com> | 2010-12-25 13:57:40 +0000 |
commit | 016d79347d429c291ea65eb95663e200e1e601f2 (patch) | |
tree | b4121701f105f608c711a6b18e178bbb8e577b90 /FaceTrackNoIR/FGServer.cpp | |
parent | e007864f430012ac03455142b3910760df03987d (diff) |
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
Diffstat (limited to 'FaceTrackNoIR/FGServer.cpp')
-rw-r--r-- | FaceTrackNoIR/FGServer.cpp | 94 |
1 files changed, 51 insertions, 43 deletions
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 <QtGui>
#include <QtNetwork>
#include "FGServer.h"
@@ -36,44 +41,27 @@ 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.
//
TestData.x = virtPosX;
@@ -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;
}
//
|