[Kde-games-devel] [libkdegames] /: Remove KGameProcess + KMessageFilePipe

Albert Astals Cid aacid at kde.org
Mon Dec 24 15:41:42 UTC 2012


Git commit c6ecc98e8f5bf1f256ab6d60d367a500bfb75055 by Albert Astals Cid.
Committed on 24/12/2012 at 16:39.
Pushed by aacid into branch 'master'.

Remove KGameProcess + KMessageFilePipe

They are only used in kfourinline so i moved them there
We are deprecating the kgame
library (you need to define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API to use it)
So the less classes in here the better :-)

CCMAIL: kde-games-devel at kde.org

M  +0    -1    CMakeLists.txt
M  +0    -1    libkdegamesprivate/CMakeLists.txt
D  +0    -170  libkdegamesprivate/kgame/kgameprocess.cpp
D  +0    -244  libkdegamesprivate/kgame/kgameprocess.h
M  +0    -91   libkdegamesprivate/kgame/kmessageio.cpp
M  +0    -30   libkdegamesprivate/kgame/kmessageio.h

http://commits.kde.org/libkdegames/c6ecc98e8f5bf1f256ab6d60d367a500bfb75055

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 237c688..88de30c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -140,7 +140,6 @@ set(kdegamesprivate_LIB_SRCS
     libkdegamesprivate/kgame/kgameio.cpp
     libkdegamesprivate/kgame/kgamemessage.cpp
     libkdegamesprivate/kgame/kgamenetwork.cpp
-    libkdegamesprivate/kgame/kgameprocess.cpp
     libkdegamesprivate/kgame/kgameproperty.cpp
     libkdegamesprivate/kgame/kgamepropertyhandler.cpp
     libkdegamesprivate/kgame/kgamesequence.cpp
diff --git a/libkdegamesprivate/CMakeLists.txt b/libkdegamesprivate/CMakeLists.txt
index fa34a22..83d4aac 100644
--- a/libkdegamesprivate/CMakeLists.txt
+++ b/libkdegamesprivate/CMakeLists.txt
@@ -30,7 +30,6 @@ install(FILES
     kgame/kgameio.h
     kgame/kgamemessage.h
     kgame/kgamenetwork.h
-    kgame/kgameprocess.h
     kgame/kgamepropertyarray.h
     kgame/kgameproperty.h
     kgame/kgamepropertyhandler.h
diff --git a/libkdegamesprivate/kgame/kgameprocess.cpp b/libkdegamesprivate/kgame/kgameprocess.cpp
deleted file mode 100644
index df8d460..0000000
--- a/libkdegamesprivate/kgame/kgameprocess.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
-    This file is part of the KDE games library
-    Copyright (C) 2001 Martin Heni (kde at heni-online.de)
-    Copyright (C) 2001 Andreas Beckermann (b_mann at gmx.de)
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License version 2 as published by the Free Software Foundation.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public License
-    along with this library; see the file COPYING.LIB.  If not, write to
-    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-    Boston, MA 02110-1301, USA.
-*/
-
-#include "kgameprocess.h"
-#include "kplayer.h"
-#include "kgame.h"
-#include "kgamemessage.h"
-#include "kmessageio.h"
-
-#include <krandomsequence.h>
-
-#include <qbuffer.h>
-#include <QDataStream>
-#include <QtCore/QFile>
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#define READ_BUFFER_SIZE  1024
-
-class KGameProcessPrivate
-{
-public:
-    QFile rFile;
-    QFile wFile;
-    KRandomSequence* mRandom;
-};
-
-// ----------------------- Process Child ---------------------------
-
-KGameProcess::KGameProcess()
-    : QObject(), d(new KGameProcessPrivate)
-{
-  mTerminate=false;
-  // Check whether a player is set. If not create one!
-  d->rFile.open(stdin, QIODevice::ReadOnly|QIODevice::Unbuffered);
-  d->wFile.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered);
-  mMessageIO = new KMessageFilePipe(this, &d->rFile, &d->wFile);
-//  mMessageClient=new KMessageClient(this);
-//  mMessageClient->setServer(mMessageIO);
-//  connect (mMessageClient, SIGNAL(broadcastReceived(QByteArray,quint32)),
-//          this, SLOT(receivedMessage(QByteArray,quint32)));
-  connect (mMessageIO, SIGNAL(received(QByteArray)),
-          this, SLOT(receivedMessage(QByteArray)));
- 
-  d->mRandom = new KRandomSequence;
-  d->mRandom->setSeed(0);
-}
-KGameProcess::~KGameProcess() 
-{
-  delete d->mRandom;
-  //delete mMessageClient;
-  //delete mMessageServer;
-  fprintf(stderr,"KGameProcess::destructor\n");
-  fflush(stderr);
-  delete mMessageIO;
-  d->rFile.close();
-  d->wFile.close();
-  delete d;
-}
-
-
-bool KGameProcess::exec(int argc, char *argv[])
-{
-  // Get id and cookie, ... from command line
-  processArgs(argc,argv);
-  do
-  {
-    mMessageIO->exec();
-  }  while(!mTerminate);
-  return true;
-}
-
-//    You have to do this to create a message 
-//    QByteArray buffer;
-//    QDataStream wstream(buffer,QIODevice::WriteOnly);
-//    then stream data into the stream and call this function
-void KGameProcess::sendSystemMessage(QDataStream &stream,int msgid,quint32 receiver)
-{
-  fprintf(stderr,"KGameProcess::sendSystemMessage to parent id=%d recv=%ld\n",msgid,(unsigned long)receiver);
-  QByteArray a;
-  QDataStream outstream(&a,QIODevice::WriteOnly);
-
-  QBuffer *device=(QBuffer *)stream.device();
-  QByteArray data=device->buffer();
-
-  KGameMessage::createHeader(outstream,0,receiver,msgid);
-  outstream.writeRawData(data.data(),data.size());
-
-  //  if (mMessageClient) mMessageClient->sendForward(a,2);
-  if (mMessageIO) mMessageIO->send(a);
-  else fprintf(stderr,"KGameProcess::sendSystemMessage:: NO IO DEVICE ... WILL FAIL\n");
-}
-
-void KGameProcess::sendMessage(QDataStream &stream,int msgid,quint32 receiver)
-{
-  sendSystemMessage(stream,msgid+KGameMessage::IdUser,receiver);
-}
-
-void KGameProcess::processArgs(int argc, char *argv[])
-{
-  int v=0;
-  if (argc>2)
-  {
-    v=atoi(argv[2]);
-    //kDebug(11001) << "cookie (unused) " << v;
-  }
-  if (argc>1)
-  {
-    v=atoi(argv[1]);
-    //kDebug(11001) << "id (unused) " << v;
-  }
-  fprintf(stderr,"KGameProcess::processArgs \n");
-  fflush(stderr);
-}
-
-void KGameProcess::receivedMessage(const QByteArray& receiveBuffer)
-{
- QDataStream stream(receiveBuffer);
- int msgid;
- quint32 sender; 
- quint32 receiver; 
- KGameMessage::extractHeader(stream, sender, receiver, msgid);
- fprintf(stderr,"--- KGameProcess::receivedMessage(): id=%d sender=%ld,recv=%ld\n",
-         msgid,(unsigned long)sender,(unsigned long)receiver);
- switch(msgid)
- {
-   case KGameMessage::IdTurn:
-     qint8 b;
-     stream >> b;
-     emit signalTurn(stream,(bool)b);
-   break;
-   case KGameMessage::IdIOAdded:
-     qint16 id;
-     stream >> id;
-     emit signalInit(stream,(int)id);
-   break;
-   default:
-      emit signalCommand(stream,msgid-KGameMessage::IdUser,receiver,sender);
-   break;
- }
-}
-
-KRandomSequence* KGameProcess::random()
-{
-  return d->mRandom;
-}
-
-
-#include "kgameprocess.moc"
diff --git a/libkdegamesprivate/kgame/kgameprocess.h b/libkdegamesprivate/kgame/kgameprocess.h
deleted file mode 100644
index b2a43c4..0000000
--- a/libkdegamesprivate/kgame/kgameprocess.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
-    This file is part of the KDE games library
-    Copyright (C) 2001 Martin Heni (kde at heni-online.de)
-    Copyright (C) 2001 Andreas Beckermann (b_mann at gmx.de)
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License version 2 as published by the Free Software Foundation.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public License
-    along with this library; see the file COPYING.LIB.  If not, write to
-    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-    Boston, MA 02110-1301, USA.
-*/
-
-#ifndef __KGAMEPROCESS_H_
-#define __KGAMEPROCESS_H_
-
-#include <QtCore/QObject>
-
-#include "kgameproperty.h"
-#include "../libkdegamesprivate_export.h"
-
-class KRandomSequence;
-
-class KPlayer;
-class KMessageFilePipe;
-class KGameProcessPrivate;
-
-/**
- * \class KGameProcess kgameprocess.h <KGame/KGameProcess>
- * 
- * This is the process class used on the computer player
- * side to communicate with its counterpart KProcessIO class.
- * Using these two classes will give fully transparent communication
- * via QDataStreams.
- */
-class KDEGAMESPRIVATE_EXPORT KGameProcess:  public QObject
-{
-  Q_OBJECT
-
-  public:
-    /**
-     * Creates a KGameProcess class. Done only in the computer
-     * player. To activate the communication you have to call
-     * the exec function of this class which will listen
-     * to the communication and emit signals to notify you of
-     * any incoming messages.
-     * Note: This function will only return after you set
-     * setTerminate(true) in one of the received signals.
-     * So you can not do any computer calculation after the exec function.
-     * Instead you react on the signals which are emitted after a
-     * message is received and perform the calculations there!
-     * Example:
-     * \code
-     *  int main(int argc ,char * argv[])
-     *  {
-     *    KGameProcess proc;
-     *    connect(&proc,SIGNAL(signalCommand(QDataStream &,int ,int ,int )),
-     *                    this,SLOT(slotCommand(QDataStream & ,int ,int ,int )));
-     *    connect(&proc,SIGNAL(signalInit(QDataStream &,int)),
-     *                    this,SLOT(slotInit(QDataStream & ,int )));
-     *    connect(&proc,SIGNAL(signalTurn(QDataStream &,bool )),
-     *                    this,SLOT(slotTurn(QDataStream & ,bool )));
-     *    return proc.exec(argc,argv);
-     *  }
-     *  \endcode
-     */
-    KGameProcess();
-    /**
-     * Destruct the process
-     */
-    ~KGameProcess();
-
-    /**
-     * Enters the event loop of the computer process. Does only
-     * return on setTerminate(true)!
-     */
-    bool exec(int argc, char *argv[]);
-
-    /**
-     * Should the computer process leave its exec function?
-     * Activated if you setTerminate(true);
-     *
-     * @return true/false
-     */
-    bool terminate() const {return mTerminate;}
-
-    /**
-     * Set this to true if the computer process should end, ie
-     * leave its exec function.
-     *
-     * @param b true for exit the exec function
-     */
-    void setTerminate(bool b) {mTerminate=b;}
-
-    /**
-     * Sends a message to the corresponding KGameIO
-     * device. Works like the sendSystemMessage but
-     * for user id's
-     *
-     * @param stream the QDataStream containing the message
-     * @param msgid the message id for the message
-     * @param receiver unused
-     */
-    void sendMessage(QDataStream &stream,int msgid,quint32 receiver=0);
-
-    /**
-     * Sends a system message to the corresonding KGameIO device.
-     * This will normally be either a performed move or a query
-     * (IdProcessQuery). The query option is a way to communicate
-     * with the KGameIO at the other side and e.g. retrieve some
-     * game relevant data from here.
-     * Example for a query:
-     * \code
-     *  QByteArray buffer;
-     *  QDataStream out(buffer,QIODevice::WriteOnly);
-     *  int msgid=KGameMessage::IdProcessQuery;
-     *  out << (int)1;
-     *  proc.sendSystemMessage(out,msgid,0);
-     * \endcode
-     *
-     * @param stream the QDataStream containing the message
-     * @param msgid the message id for the message
-     * @param receiver unused
-     */
-    void sendSystemMessage(QDataStream &stream,int msgid,quint32 receiver=0);
-
-    /**
-     * Returns a pointer to a KRandomSequence. You can generate
-     * random numbers via e.g.
-     * \code
-     *   random()->getLong(100);
-     * \endcode
-     * 
-     * @return KRandomSequence pointer
-     */
-    KRandomSequence *random();
-
-  protected:
-    /**
-     * processes the command line argumens to set up the computer player
-     * Pass the argumens exactely as given by main()
-     */
-    void processArgs(int argc, char *argv[]);
-
-  protected Q_SLOTS:
-    /**
-     * A message is received via the interprocess connection. The
-     * appropriate signals are called.
-     */
-      void receivedMessage(const QByteArray& receiveBuffer);
-
-  Q_SIGNALS:
-    /**
-     * The generic communication signal. You have to connect to this
-     * signal to generate a valid computer response onto arbitrary messages.
-     * All signals but IdIOAdded and IdTurn end up here!
-     * Example:
-     * \code
-     * void Computer::slotCommand(int &msgid,QDataStream &in,QDataStream &out)
-     * {
-     *   qint32 data,move;
-     *   in >> data;
-     *   // compute move ...
-     *   move=data*2;
-     *   out << move;
-     * }
-     * \endcode
-     *
-     * @param inputStream the incoming data stream
-     * @param msgid the message id of the message which got transmitted to the computer
-     * @param receiver the id of the receiver
-     * @param sender the id of the sender
-     */
-     void signalCommand(QDataStream &inputStream,int msgid,int receiver,int sender);
-
-     /**
-      * This signal is emmited if the computer player should perform a turn.
-      * Calculations can be made here and the move can then be send back with
-      * sendSystemMessage with the message id KGameMessage::IdPlayerInput.
-      * These must provide a move which complies to your other move syntax as
-      * e.g. produces by keyboard or mouse input.
-      * Additional data which have been written into the stream from the
-      * ProcessIO's signal signalPrepareTurn can be retrieved from the
-      * stream here.
-      * Example:
-      * \code
-      * void slotTurn(QDataStream &in,bool turn)
-      * {
-      *   int id;
-      *   int recv;
-      *   QByteArray buffer;
-      *   QDataStream out(buffer,QIODevice::WriteOnly);
-      *   if (turn)
-      *   {
-      *     // Create a move - the format is yours to decide
-      *     // It arrives exactly as this in the kgame inputMove function!!
-      *     qint8 x1,y1,pl;
-      *     pl=-1;
-      *     x1=proc.random()->getLong(8);
-      *     y1=proc.random()->getLong(8);
-      *     // Stream it
-      *     out << pl << x1 << y1;
-      *     id=KGameMessage::IdPlayerInput;
-      *     proc.sendSystemMessage(out,id,0);
-      *   }
-      * }
-      * \endcode
-      *
-      * @param stream The datastream which contains user data
-      * @param turn True or false whether the turn is activated or deactivated
-      *
-      */
-     void signalTurn(QDataStream &stream,bool turn);
-
-     /**
-      * This signal is emmited when the process is initialized, i.e. added
-      * to a KPlayer. Initial initialisation can be performed here be reacting
-      * to the KProcessIO signal signalIOAdded and retrieving the data here
-      * from the stream. 
-      * It works just as the signalTurn() but is only send when the player is
-      * added to the game, i.e. it needs some initialization data
-      *
-      * @param stream The datastream which contains user data 
-      * @param userid The userId of the player. (Careful to rely on it yet)
-      */
-     void signalInit(QDataStream &stream,int userid);
-
-  protected:
-    bool mTerminate;
-    KMessageFilePipe *mMessageIO;
-  private:
-    friend class KGameProcessPrivate;
-    KGameProcessPrivate *const d;
-
-    Q_DISABLE_COPY(KGameProcess)
-};
-#endif
diff --git a/libkdegamesprivate/kgame/kmessageio.cpp b/libkdegamesprivate/kgame/kmessageio.cpp
index 64e312d..d7ee246 100644
--- a/libkdegamesprivate/kgame/kmessageio.cpp
+++ b/libkdegamesprivate/kgame/kmessageio.cpp
@@ -362,96 +362,5 @@ void KMessageProcess::slotProcessExited(int exitCode, QProcess::ExitStatus)
   mProcess=0;
 }
 
-
-// ----------------------- KMessageFilePipe ---------------------------
-KMessageFilePipe::KMessageFilePipe(QObject *parent,QFile *readfile,QFile *writefile) : KMessageIO(parent)
-{
-  mReadFile=readfile;
-  mWriteFile=writefile;
-  mReceiveCount=0;
-  mReceiveBuffer.resize(1024);
-}
-
-KMessageFilePipe::~KMessageFilePipe()
-{
-}
-
-bool KMessageFilePipe::isConnected () const
-{
-  return (mReadFile!=0)&&(mWriteFile!=0);
-}
-
-// Send to parent
-void KMessageFilePipe::send(const QByteArray &msg)
-{
-  unsigned int size=msg.size()+2*sizeof(long);
-
-  char *tmpbuffer=new char[size];
-  long *p1=(long *)tmpbuffer;
-  long *p2=p1+1;
-  memcpy(tmpbuffer+2*sizeof(long),msg.data(),msg.size());
-  *p1=0x4242aeae;
-  *p2=size;
-
-  QByteArray buffer(tmpbuffer,size);
-  mWriteFile->write(buffer);
-  mWriteFile->flush();
-  delete [] tmpbuffer;
-
-  /* DEBUG:
-  fprintf(stderr,"+++ KMessageFilePipe:: SEND(%d to parent) realsize=%d\n",msg.size(),buffer.size());
-  for (int i=0;i<buffer.size();i++) fprintf(stderr,"%02x ",(unsigned char)buffer.at(i));fprintf(stderr,"\n");
-  fflush(stderr);
-  */
-
-
-}
-
-void KMessageFilePipe::exec()
-{
-
-  // According to BL: Blocking read is ok
-  // while(mReadFile->atEnd()) { usleep(100); }
-   char ch;
-   mReadFile->getChar(&ch);
-
-   while (mReceiveCount>=mReceiveBuffer.size()) mReceiveBuffer.resize(mReceiveBuffer.size()+1024);
-   mReceiveBuffer[mReceiveCount]=ch;
-   mReceiveCount++;
-
-   // Change for message
-   if (mReceiveCount>=int(2*sizeof(long)))
-   {
-     long *p1=(long *)mReceiveBuffer.data();
-     long *p2=p1+1;
-     int len;
-     if (*p1!=0x4242aeae)
-     {
-       fprintf(stderr,"KMessageFilePipe::exec:: Cookie error...transmission failure...serious problem...\n");
-       fflush(stderr);
-//       for (int i=0;i<16;i++) fprintf(stderr,"%02x ",mReceiveBuffer[i]);fprintf(stderr,"\n");
-     }
-     len=(int)(*p2);
-     if (len==mReceiveCount)
-     {
-       //fprintf(stderr,"KMessageFilePipe::exec:: Got Message with len %d\n",len);
-
-       QByteArray msg;
-       msg.resize(len);
-       //msg.setRawData(mReceiveBuffer.data()+2*sizeof(long),len-2*sizeof(long));
-       qCopy(mReceiveBuffer.begin()+2*sizeof(long),mReceiveBuffer.begin()+len, msg.begin());
-// 	msg.duplicate(mReceiveBuffer.data()+2*sizeof(long),len-2*sizeof(long));
-       emit received(msg);
-       //msg.resetRawData(mReceiveBuffer.data()+2*sizeof(long),len-2*sizeof(long));
-       mReceiveCount=0;
-     }
-   }
-
-
-   return ;
-
-
-}
-
 #include "kmessageio.moc"
 
diff --git a/libkdegamesprivate/kgame/kmessageio.h b/libkdegamesprivate/kgame/kmessageio.h
index 674bebf..29aa6ed 100644
--- a/libkdegamesprivate/kgame/kmessageio.h
+++ b/libkdegamesprivate/kgame/kmessageio.h
@@ -384,35 +384,5 @@ class KMessageProcess : public KMessageIO
     int mReceiveCount;
 };
 
-class KMessageFilePipe : public KMessageIO
-{
-  Q_OBJECT 
-
-  public:
-    KMessageFilePipe(QObject *parent,QFile *readFile,QFile *writeFile);
-    ~KMessageFilePipe();
-    bool isConnected() const;
-    void send (const QByteArray &msg);
-    void exec();
-
-    /**
-      @return FALSE as this is no network IO.
-    */
-    bool isNetwork() const { return false; }
-
-  /**
-  * The runtime idendifcation
-  */
-  virtual int rtti() const {return 4;}
-
-
-
-  private:
-    QFile *mReadFile;
-    QFile *mWriteFile;
-    QByteArray mReceiveBuffer;
-    int mReceiveCount;
-};
-
 #endif
 


More information about the kde-games-devel mailing list