[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/backgammon
From:       Dmitry Vladimirovich Chernov <diman4ik.chernov () gmail ! com>
Date:       2012-05-13 8:19:02
Message-ID: 20120513081902.9FE45AC85D () svn ! kde ! org
[Download RAW message or body]

SVN commit 1294593 by dmitryvchernov:

starting adding support for fibs registration

 M  +3 -0      CMakeLists.txt  
 M  +19 -7     games/backgammon/fibs/backgammon_fibs.cpp  
 M  +2 -2      games/backgammon/fibs/backgammon_fibs.h  
 M  +50 -12    games/backgammon/fibs/backgammon_fibs_connect.cpp  
 M  +25 -12    games/backgammon/fibs/backgammon_fibs_connect.h  
 A             test (directory)  
 A             test/CMakeLists.txt  
 A             test/test_registrator.cpp   [License: UNKNOWN]
 A             test/test_registrator.h   [License: GPL (v2+)]


--- trunk/playground/games/backgammon/CMakeLists.txt #1294592:1294593
@@ -35,6 +35,7 @@
     games/backgammon/backgammon_local.cpp
     games/backgammon/fibs/clip.cpp
     games/backgammon/fibs/message_dialog.cpp
+	games/backgammon/fibs/fibs_registrator.cpp
  )
 
 #kde4_automoc(${backgammon_SRCS})
@@ -60,3 +61,5 @@
 install( FILES backgammonui.rc  DESTINATION  ${DATA_INSTALL_DIR}/backgammon )
 install( FILES default_theme.svgz DESTINATION  ${DATA_INSTALL_DIR}/backgammon )
 
+add_subdirectory(test)
+
--- trunk/playground/games/backgammon/games/backgammon/fibs/backgammon_fibs.cpp \
#1294592:1294593 @@ -37,15 +37,26 @@
 {
     Clip::initPatterns();
     
-    m_connection = new BackgammonFibsConnect( this );
+    //m_connection = new BackgammonFibsConnect( this );
 
     /* 
      * connect the various slots
      */
-    connect( m_connection, SIGNAL(connectionDown()), this, \
                SLOT(serverDisconnected()) );
-    connect( m_connection, SIGNAL( newData( QString& ) ), this,  SLOT( \
                handleServerData( QString& ) ) );
-    connect( this, SIGNAL(serverString(const QString&)), m_connection,  \
SLOT(sendData(const QString&)) ); +    /*connect( m_connection, \
SIGNAL(connectionDown()), this, SLOT(serverDisconnected()) ); +    connect( \
m_connection, SIGNAL( newData( QString& ) ), this,  SLOT( handleServerData( QString& \
) ) );*/  
+	connect( &BackgammonFibsConnect::instance(), SIGNAL(connectionDown()), 
+			 this, SLOT(serverDisconnected()) );
+    connect( &BackgammonFibsConnect::instance(), SIGNAL( newData( QString& ) ), 
+			 this,  SLOT( handleServerData( QString& ) ) );
+	
+	//BackgammonFibsConnect::instance().addEventListener(this);
+	
+	// TODO: remove serverString instances from here
+    //connect( this, SIGNAL(serverString(const QString&)), m_connection,  \
SLOT(sendData(const QString&)) ); +	connect( this, SIGNAL(serverString(const \
QString&)),  +			 &BackgammonFibsConnect::instance(),  SLOT(sendData(const QString&)) \
); +    
     // Player plays white
     m_players[0] = new HumanPlayer(Checker::Black, "Player1");
     // Opponent plays red
@@ -59,8 +70,8 @@
     
 BackgammonFibs::~BackgammonFibs()
 {
-    if ( m_connection ) 
-        delete m_connection;
+    /*if ( m_connection ) 
+        delete m_connection;*/
 }
 
 void BackgammonFibs::handleServerData( QString& data )
@@ -423,7 +434,8 @@
 
 void BackgammonFibs::connectFIBS( const QString& serv, qint16 port )
 {
-    m_connection->makeConnect( serv, port );
+    //m_connection->makeConnect( serv, port );
+    BackgammonFibsConnect::instance().makeConnect( serv, port );
 }
 
 void BackgammonFibs::serverDisconnected()
--- trunk/playground/games/backgammon/games/backgammon/fibs/backgammon_fibs.h \
#1294592:1294593 @@ -36,7 +36,7 @@
 #include "move.h"
 #include "backgammongame.h"
 
-class BackgammonFibsConnect;
+//class BackgammonFibsConnect;
 
 
 class BackgammonFibs : public BackgammonGame
@@ -186,7 +186,7 @@
     QString getFirstWord( const QString& line );
     QString getLastWord( const QString& line );
     
-    BackgammonFibsConnect* m_connection;
+    //BackgammonFibsConnect* m_connection;
     
     QMap< int, bool > m_toggles;
     
--- trunk/playground/games/backgammon/games/backgammon/fibs/backgammon_fibs_connect.cpp \
#1294592:1294593 @@ -24,6 +24,12 @@
 #include <KDebug>
 
 
+BackgammonFibsConnect& BackgammonFibsConnect::instance()
+{
+	static BackgammonFibsConnect theInstance(0);
+	return theInstance;
+}
+
 BackgammonFibsConnect::BackgammonFibsConnect( QObject *parent ) : QObject(parent)
 {
     /* 
@@ -31,10 +37,10 @@
      */
     m_socket = new QTcpSocket( this );
     
-    connect( m_socket, SIGNAL( hostFound() ), SLOT( hostFound() ) );
+    //connect( m_socket, SIGNAL( hostFound() ), SLOT( hostFound() ) );
     connect( m_socket, SIGNAL( connected() ), SLOT( connected() ) );
     connect( m_socket, SIGNAL( readyRead() ), SLOT( receiveData() ) );
-    connect( m_socket, SIGNAL( disconnected() ), SLOT( connectionLost() ) );
+    //connect( m_socket, SIGNAL( disconnected() ), SLOT( connectionLost() ) );
     connect( m_socket, SIGNAL( error( QAbstractSocket::SocketError ) ), SLOT( error( \
QAbstractSocket::SocketError ) ) );  }
 
@@ -68,17 +74,7 @@
     }
     else
         kDebug() << "empty message??";
-}
 
-void BackgammonFibsConnect::hostFound()
-{
-    kDebug() << "host found";
-}
-
-void BackgammonFibsConnect::connectionLost()
-{
-    kDebug() << "disconnected";
-	
 	rxBuffer.clear();
 	txBuffer.clear();
 }
@@ -98,6 +94,48 @@
 
 void BackgammonFibsConnect::makeConnect( const QString& host, qint16 port )
 {
+	if( m_socket->state() != QAbstractSocket::ConnectedState ) 
+	{
     kDebug() << "connecting " << host << " : " << port;
     m_socket->connectToHost( host, port );
 }
+	else
+		kDebug() << "already connected";
+}
+
+bool BackgammonFibsConnect::isConnected()
+{
+	return m_socket->state() == QAbstractSocket::ConnectedState;
+}
+
+void BackgammonFibsConnect::disconnectFIBS()
+{
+	m_socket->disconnectFromHost();
+}
+
+void BackgammonFibsConnect::connectFIBS()
+{
+	if( m_socket->state() != QAbstractSocket::ConnectedState ) 
+	{
+		//kDebug() << "connecting " << host << " : " << port;
+		m_socket->connectToHost( "www.fibs.com", 4321 );
+	}
+	else
+		kDebug() << "already connected";
+}
+
+/*void BackgammonFibsConnect::addEventListener( QObect* listener )
+{
+	connect( this, SIGNAL(connectionDown()), listener, SLOT(serverDisconnected()) );
+    connect( this, SIGNAL( newData( QString& ) ), listener,  SLOT( handleServerData( \
QString& ) ) ); +}
+
+void BackgammonFibsConnect::addSender( QObect* listener )
+{
+	connect( sender, SIGNAL(serverString(const QString&)), m_connection,  \
SLOT(sendData(const QString&)) ); +}
+
+void BackgammonFibsConnect::addReceiver( QObect* listener )
+{
+	
+}*/
--- trunk/playground/games/backgammon/games/backgammon/fibs/backgammon_fibs_connect.h \
#1294592:1294593 @@ -25,29 +25,33 @@
 #include <QTcpSocket>
 
 
+// TODO: make singleton
 class BackgammonFibsConnect : public QObject
 {
     Q_OBJECT
 public:
+    static BackgammonFibsConnect& instance();
     
     /**
-    * Constructor
-    */
-    BackgammonFibsConnect( QObject *parent );
-
-    /**
-    * Destructor
-    */
-    virtual ~BackgammonFibsConnect();
-
-    /**
     * Returns the file descriptor of the socket, or negative values
     * if the socket is closed.
     */
     int status();
     
+	bool isConnected();
+    
     void makeConnect( const QString& host, qint16 port );
         
+	void disconnectFIBS();
+	
+	void connectFIBS();
+	
+	/*void addEventListener( QObject* listener );
+	
+	void addSender( QObject* sender );
+	
+	void addReceiver( QObject* receiver );*/
+        
 public slots:
         
     /**
@@ -77,11 +81,20 @@
     void receiveData( );
     void error( QAbstractSocket::SocketError );
     
-    void hostFound();
+    //void hostFound();
     void connected();
-    void connectionLost();
+    //void connectionLost();
 
 private:
+	/**
+     * Constructor
+     */
+    BackgammonFibsConnect( QObject *parent );
+
+    /**
+     * Destructor
+     */
+    virtual ~BackgammonFibsConnect();
     QTcpSocket* m_socket;
     QString rxBuffer;
     QString txBuffer;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic