[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src/client ClientEngine.h ClientEngine.cpp
From: |
Pascal Audoux |
Subject: |
[Camino-devel] camino/src/client ClientEngine.h ClientEngine.cpp |
Date: |
Thu, 30 Jan 2003 16:42:58 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Pascal Audoux <address@hidden> 03/01/30 16:42:58
Modified files:
src/client : ClientEngine.h ClientEngine.cpp
Log message:
begin of the state machine
add signal when connection etablished or broken
Patches:
Index: camino/src/client/ClientEngine.cpp
diff -u camino/src/client/ClientEngine.cpp:1.6
camino/src/client/ClientEngine.cpp:1.7
--- camino/src/client/ClientEngine.cpp:1.6 Wed Jan 29 17:21:49 2003
+++ camino/src/client/ClientEngine.cpp Thu Jan 30 16:42:58 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ClientEngine.cpp,v 1.6 2003/01/29 22:21:49 Audoux Exp $
+** Version : $Id: ClientEngine.cpp,v 1.7 2003/01/30 21:42:58 Audoux Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -34,7 +34,7 @@
ClientEngine::ClientEngine()
{
_socket = new QSocket( this );
- _connected = false;
+ _state = StateNotConnected;
setDevice( _socket );
connect( _socket, SIGNAL( connected() ), SLOT( slotServerConnected() )
);
connect( _socket, SIGNAL( connectionClosed() ), SLOT(
slotConnectionClosed() ) );
@@ -43,6 +43,11 @@
_send = new MsgCoder( _socket );
}
+bool ClientEngine::isConnected()
+{
+ return( _state != StateNotConnected );
+}
+
void ClientEngine::connectToServer( const QString & serverName, int port,
const QString & playerName )
{
qDebug("connecting to server...");
@@ -53,20 +58,24 @@
_playerName = playerName;
_socket->connectToHost( serverName, port );
- _connected = true;
}
void ClientEngine::slotServerConnected()
{
+ _state = StateWaitStart;
+ emit sig_connected( true );
qDebug("ClientEngine - Connection with server established!");
qDebug("ClientEngine - send player name " );
_send->connectServer( _playerName );
qDebug("ClientEngine - send player name - done" );
+ _state = StateWaitStart;
}
void ClientEngine::slotConnectionClosed()
{
qDebug("ClientEngine - Connection with server closed!");
+ _state = StateNotConnected;
+ emit sig_connected( false );
}
void ClientEngine::recvMsg( QString source, QString msg )
@@ -99,7 +108,10 @@
void ClientEngine::sendUndo()
{
- _send->sendUndo();
+ if( _state == StatePlay ) {
+ _send->sendUndo();
+ _state = StateUndoProcessing;
+ }
}
Index: camino/src/client/ClientEngine.h
diff -u camino/src/client/ClientEngine.h:1.5
camino/src/client/ClientEngine.h:1.6
--- camino/src/client/ClientEngine.h:1.5 Wed Jan 29 17:21:49 2003
+++ camino/src/client/ClientEngine.h Thu Jan 30 16:42:58 2003
@@ -5,7 +5,7 @@
** ClientEngine.h
** The intelligence of the client is here
**
-** Version : $Id: ClientEngine.h,v 1.5 2003/01/29 22:21:49 Audoux Exp $
+** Version : $Id: ClientEngine.h,v 1.6 2003/01/30 21:42:58 Audoux Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -54,7 +54,7 @@
void connectToServer( const QString & serverName, int port, const
QString & playerName );
- bool isConnected() { return _connected; }
+ bool isConnected();
void recvMsg( QString source, QString msg );
@@ -65,15 +65,25 @@
signals:
void sig_message( const QString & msg );
+ void sig_connected( bool );
+
protected slots:
void slotServerConnected();
void slotConnectionClosed();
protected:
+ enum StateClient {
+ StateNotConnected,
+ StateWaitStart,
+ StateWaitTurn,
+ StateUndoRequested,
+ StateUndoProcessing,
+ StatePlay
+ } _state;
QSocket * _socket;
MsgCoder * _send;
QString _playerName;
- bool _connected;
+
};
#endif // CLIENT_ENGINE_H