ClientThread is now created in Session.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#ifndef GUIINTERFACE_H
|
||||
#define GUIINTERFACE_H
|
||||
|
||||
// #include <iostream>
|
||||
#include <net/clientcallback.h>
|
||||
#include <string>
|
||||
|
||||
class Game;
|
||||
@@ -28,7 +28,7 @@ class Session;
|
||||
class HandInterface;
|
||||
|
||||
|
||||
class GuiInterface{
|
||||
class GuiInterface : public ClientCallback {
|
||||
public:
|
||||
virtual ~GuiInterface();
|
||||
|
||||
|
||||
@@ -90,5 +90,5 @@ void GuiWrapper::meInAction() const { myW->meInAction(); }
|
||||
void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); }
|
||||
void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); }
|
||||
|
||||
void GuiWrapper::showActionConnectToServerDialog(int actionID) { myConnectToServerDialog->refresh(actionID); }
|
||||
void GuiWrapper::showErrorConnectToServerDialog(int errorID, int osErrorID) { myConnectToServerDialog->error(errorID, osErrorID); }
|
||||
void GuiWrapper::SignalNetClientSuccess(int actionID) { myConnectToServerDialog->refresh(actionID); }
|
||||
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myConnectToServerDialog->error(errorID, osErrorID); }
|
||||
|
||||
@@ -87,8 +87,8 @@ public:
|
||||
void logPlayerActionMsg(std::string playerName, int action, int setValue) ;
|
||||
void logNewGameHandMsg(int gameID, int handID) ;
|
||||
|
||||
void showActionConnectToServerDialog(int actionID);
|
||||
void showErrorConnectToServerDialog(int errorID, int osErrorID);
|
||||
void SignalNetClientSuccess(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "joinnetworkgamedialogimpl.h"
|
||||
#include "session.h"
|
||||
// #include "configfile.h"
|
||||
|
||||
joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent)
|
||||
@@ -30,11 +31,14 @@ joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent)
|
||||
|
||||
}
|
||||
|
||||
void joinNetworkGameDialogImpl::setSession(Session* s)
|
||||
{
|
||||
mySession = s;
|
||||
}
|
||||
|
||||
void joinNetworkGameDialogImpl::startClient() {
|
||||
|
||||
ClientThread *myClientThread = new ClientThread();
|
||||
myClientThread->Init(lineEdit_ipAddress->text().toStdString(), spinBox_port->value(), checkBox_ipv6->isChecked(), lineEdit_password->text().toStdString());
|
||||
myClientThread->Run();
|
||||
|
||||
// TODO: Check input values!
|
||||
if (mySession)
|
||||
mySession->startNetworkClient(lineEdit_ipAddress->text().toUtf8().constData(), spinBox_port->value(), checkBox_ipv6->isChecked(), lineEdit_password->text().toUtf8().constData());
|
||||
}
|
||||
@@ -22,21 +22,26 @@
|
||||
|
||||
#include "ui_joinnetworkgamedialog.h"
|
||||
|
||||
#include "clientthread.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
|
||||
class Session;
|
||||
|
||||
class joinNetworkGameDialogImpl: public QDialog, public Ui::joinNetworkGameDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
joinNetworkGameDialogImpl(QWidget *parent = 0);
|
||||
|
||||
void joinNetworkGameDialogImpl::setSession(Session* s);
|
||||
|
||||
public slots:
|
||||
|
||||
void startClient();
|
||||
|
||||
private:
|
||||
|
||||
Session *mySession;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -545,6 +545,7 @@ void mainWindowImpl::callAboutPokerthDialog() {
|
||||
void mainWindowImpl::callJoinNetworkGameDialog() {
|
||||
|
||||
joinNetworkGameDialogImpl *v = new joinNetworkGameDialogImpl();
|
||||
v->setSession(mySession);
|
||||
v->exec();
|
||||
|
||||
if (v->result() == QDialog::Accepted ) {
|
||||
|
||||
+1
-1
@@ -47,8 +47,8 @@ int main( int argc, char **argv )
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
GuiInterface *myGuiInterface = new GuiWrapper();
|
||||
|
||||
Session theFirst(myGuiInterface);
|
||||
myGuiInterface->setSession(&theFirst);
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
+30
-9
@@ -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)
|
||||
Session::Session(GuiInterface *g)
|
||||
: actualGameID(0), myNetClient(0), actualGame(0), myGui(g)
|
||||
{
|
||||
|
||||
actualGameID = 0;
|
||||
// Session an mainwindowimpl bergeben
|
||||
myGui->setSession(this);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+6
-3
@@ -19,14 +19,12 @@
|
||||
***************************************************************************/
|
||||
#ifndef STDSESSION_H
|
||||
#define STDSESSION_H
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
class GuiInterface;
|
||||
class Game;
|
||||
class ConfigFile;
|
||||
|
||||
class ClientThread;
|
||||
|
||||
class Session{
|
||||
public:
|
||||
@@ -38,6 +36,9 @@ public:
|
||||
void startGame(int, int, int);
|
||||
void deleteGame();
|
||||
|
||||
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, const std::string &pwd);
|
||||
void terminateNetworkClient();
|
||||
|
||||
void setActualGameID(const int& theValue) { actualGameID = theValue; }
|
||||
int getActualGameID() const { return actualGameID; }
|
||||
|
||||
@@ -47,6 +48,8 @@ private:
|
||||
|
||||
int actualGameID;
|
||||
|
||||
ClientThread *myNetClient;
|
||||
|
||||
Game *actualGame;
|
||||
GuiInterface *myGui;
|
||||
ConfigFile *myConfig;
|
||||
|
||||
Reference in New Issue
Block a user