• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate/kgame

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • libkdegamesprivate
  • kgame
kmessageio.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Burkhard Lehner (Burkhard.Lehner@gmx.de)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 /*
21  KMessageIO class and subclasses KMessageSocket and KMessageDirect
22 */
23 
24 #ifndef _KMESSAGEIO_H_
25 #define _KMESSAGEIO_H_
26 
27 #include <QtCore/QObject>
28 #include <QtCore/QProcess>
29 #include <QtCore/QString>
30 #include <QtNetwork/QHostAddress>
31 #include <kdebug.h>
32 #include "../libkdegamesprivate_export.h"
33 
34 class QTcpSocket;
35 class KProcess;
36 class QFile;
37 
38 
57 class KDEGAMESPRIVATE_EXPORT KMessageIO : public QObject
58 {
59  Q_OBJECT
60 
61 public:
65  KMessageIO (QObject *parent = 0);
66 
70  ~KMessageIO ();
71 
75  virtual int rtti() const {return 0;}
76 
80  //virtual bool isNetwork () const = 0;
81  virtual bool isNetwork () const
82  {
83  kError(11001) << "Calling PURE virtual isNetwork...BAD";
84  return false;
85  }
86 
94  //virtual bool isConnected () const = 0;
95  virtual bool isConnected () const
96  {
97  kError(11001) << "Calling PURE virtual isConencted...BAD";
98  return false;
99  }
100 
109  void setId (quint32 id);
110 
114  quint32 id ();
115 
119  virtual quint16 peerPort () const { return 0; }
120 
124  virtual QString peerName () const { return QString::fromLatin1("localhost"); }
125 
126 
127 Q_SIGNALS:
133  void received (const QByteArray &msg);
134 
143  void connectionBroken ();
144 
145 public Q_SLOTS:
146 
156  virtual void send (const QByteArray &msg) = 0;
157 
158 protected:
159  quint32 m_id;
160 };
161 
162 
170 class KMessageSocket : public KMessageIO
171 {
172  Q_OBJECT
173 
174 public:
185  KMessageSocket (const QString& host, quint16 port, QObject *parent = 0 );
186 
195  KMessageSocket (QHostAddress host, quint16 port, QObject *parent = 0);
196 
208  explicit KMessageSocket (QTcpSocket *socket, QObject *parent = 0);
209 
221  explicit KMessageSocket (int socketFD, QObject *parent = 0);
222 
226  ~KMessageSocket ();
227 
231  virtual int rtti() const {return 1;}
232 
236  virtual quint16 peerPort () const;
237 
241  virtual QString peerName () const;
242 
246  bool isNetwork() const { return true; }
247 
251  bool isConnected () const;
252 
259  void send (const QByteArray &msg);
260 
261 protected Q_SLOTS:
262  virtual void processNewData ();
263 
264 protected:
265  void initSocket ();
266  QTcpSocket *mSocket;
267  bool mAwaitingHeader;
268  quint32 mNextBlockLength;
269 
270  bool isRecursive; // workaround for "bug" in QSocket, Qt 2.2.3 or older
271 };
272 
273 
294 class KMessageDirect : public KMessageIO
295 {
296  Q_OBJECT
297 
298 public:
306  explicit KMessageDirect (KMessageDirect *partner = 0, QObject *parent = 0);
307 
311  ~KMessageDirect ();
312 
316  virtual int rtti() const {return 2;}
317 
318 
322  bool isNetwork() const { return false; }
323 
332  bool isConnected () const;
333 
340  void send (const QByteArray &msg);
341 
342 protected:
343  KMessageDirect *mPartner;
344 };
345 
349 class KMessageProcess : public KMessageIO
350 {
351  Q_OBJECT
352 
353  public:
354  KMessageProcess(QObject *parent, const QString& file);
355  ~KMessageProcess();
356  bool isConnected() const;
357  void send (const QByteArray &msg);
358 
362  bool isNetwork() const { return false; }
363 
367  virtual int rtti() const {return 3;}
368 
369 
370 
371  public Q_SLOTS:
372  void slotReceivedStdout();
373  void slotReceivedStderr();
374  void slotProcessExited(int, QProcess::ExitStatus);
375 
376  Q_SIGNALS:
377  void signalReceivedStderr(QString msg);
378 
379  private:
380  QString mProcessName;
381  KProcess *mProcess;
382  QByteArray* mSendBuffer;
383  QByteArray mReceiveBuffer;
384  int mReceiveCount;
385 };
386 
387 #endif
388 
KMessageProcess::send
void send(const QByteArray &msg)
This slot sends the data block in /e msg to the connected object, that will emit /e received()...
Definition: kmessageio.cpp:263
KMessageProcess::signalReceivedStderr
void signalReceivedStderr(QString msg)
KMessageSocket::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:231
QHostAddress
KMessageSocket
This class implements the message communication using a TCP/IP socket.
Definition: kmessageio.h:170
QByteArray
KMessageProcess::~KMessageProcess
~KMessageProcess()
Definition: kmessageio.cpp:222
KMessageProcess::slotReceivedStdout
void slotReceivedStdout()
Definition: kmessageio.cpp:306
KMessageDirect::mPartner
KMessageDirect * mPartner
Definition: kmessageio.h:343
KMessageIO::isConnected
virtual bool isConnected() const
This method returns the status of the object, whether it is already (or still) connected to another K...
Definition: kmessageio.h:95
KMessageIO::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:75
KMessageSocket::send
void send(const QByteArray &msg)
Overwritten slot method from KMessageIO.
Definition: kmessageio.cpp:92
QFile
KMessageProcess::slotProcessExited
void slotProcessExited(int, QProcess::ExitStatus)
Definition: kmessageio.cpp:357
KMessageSocket::mAwaitingHeader
bool mAwaitingHeader
Definition: kmessageio.h:267
KMessageIO::m_id
quint32 m_id
Definition: kmessageio.h:159
KMessageDirect
This class implements the message communication using function calls directly.
Definition: kmessageio.h:294
KMessageDirect::send
void send(const QByteArray &msg)
Overwritten slot method from KMessageIO.
Definition: kmessageio.cpp:211
QObject
KMessageProcess::isConnected
bool isConnected() const
This method returns the status of the object, whether it is already (or still) connected to another K...
Definition: kmessageio.cpp:254
KMessageDirect::isConnected
bool isConnected() const
Returns true, if the object is connected to another instance.
Definition: kmessageio.cpp:206
KMessageIO
This abstract base class represents one end of a message connections between two clients.
Definition: kmessageio.h:57
KMessageSocket::isConnected
bool isConnected() const
Returns true if the socket is in state /e connected.
Definition: kmessageio.cpp:87
QString
KMessageSocket::mNextBlockLength
quint32 mNextBlockLength
Definition: kmessageio.h:268
KMessageSocket::isRecursive
bool isRecursive
Definition: kmessageio.h:270
KMessageDirect::KMessageDirect
KMessageDirect(KMessageDirect *partner=0, QObject *parent=0)
Creates an object and connects it to the object given in the first parameter.
Definition: kmessageio.cpp:176
KMessageDirect::isNetwork
bool isNetwork() const
Definition: kmessageio.h:322
KMessageSocket::peerPort
virtual quint16 peerPort() const
Definition: kmessageio.cpp:164
KMessageProcess::isNetwork
bool isNetwork() const
Definition: kmessageio.h:362
KMessageProcess::KMessageProcess
KMessageProcess(QObject *parent, const QString &file)
Definition: kmessageio.cpp:233
KMessageSocket::~KMessageSocket
~KMessageSocket()
Destructor, closes the socket.
Definition: kmessageio.cpp:82
KMessageSocket::processNewData
virtual void processNewData()
Definition: kmessageio.cpp:99
KMessageIO::peerPort
virtual quint16 peerPort() const
Definition: kmessageio.h:119
KMessageSocket::isNetwork
bool isNetwork() const
Definition: kmessageio.h:246
KMessageIO::isNetwork
virtual bool isNetwork() const
Definition: kmessageio.h:81
KMessageSocket::peerName
virtual QString peerName() const
Definition: kmessageio.cpp:169
KMessageSocket::initSocket
void initSocket()
Definition: kmessageio.cpp:154
KMessageIO::peerName
virtual QString peerName() const
Definition: kmessageio.h:124
KMessageSocket::KMessageSocket
KMessageSocket(const QString &host, quint16 port, QObject *parent=0)
Connects to a server socket on /e host with /e port.
Definition: kmessageio.cpp:51
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QTcpSocket
KMessageDirect::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:316
QObject::parent
QObject * parent() const
KMessageDirect::~KMessageDirect
~KMessageDirect()
Destructor, closes the connection.
Definition: kmessageio.cpp:197
KMessageProcess::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:367
KMessageProcess::slotReceivedStderr
void slotReceivedStderr()
Definition: kmessageio.cpp:286
KMessageSocket::mSocket
QTcpSocket * mSocket
Definition: kmessageio.h:266
KMessageProcess
Definition: kmessageio.h:349
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:54 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate/kgame

Skip menu "libkdegames/libkdegamesprivate/kgame"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal