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