ClientThread is now created in Session.

This commit is contained in:
lotodore
2007-02-18 13:45:56 +00:00
parent 9ec3e020dd
commit a4eefbe18b
9 changed files with 60 additions and 26 deletions
+31 -10
View File
@@ -21,26 +21,24 @@
#include "game.h"
#include "guiinterface.h"
#include "configfile.h"
#include <net/clientthread.h>
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 1000
using namespace std;
Session::Session(GuiInterface* g) : actualGame(0), myGui(g)
{
actualGameID = 0;
// Session an mainwindowimpl bergeben
myGui->setSession(this);
Session::Session(GuiInterface *g)
: actualGameID(0), myNetClient(0), actualGame(0), myGui(g)
{
myConfig = new ConfigFile;
}
Session::~Session()
{
terminateNetworkClient();
deleteGame();
delete myConfig;
}
@@ -57,3 +55,26 @@ void Session::deleteGame() {
actualGame = 0;
}
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd)
{
if (myNetClient || !myGui)
return; // TODO: throw exception
myNetClient = new ClientThread(*myGui);
myNetClient->Init(serverAddress, serverPort, ipv6, pwd);
myNetClient->Run();
}
void Session::terminateNetworkClient()
{
if (!myNetClient)
return; // already terminated
myNetClient->SignalTermination();
// Give the thread some time to terminate.
if (myNetClient->Join(NET_CLIENT_TERMINATE_TIMEOUT_MSEC))
{
delete myNetClient;
}
// If termination fails, leave a memory leak to prevent a crash.
myNetClient = 0;
}