• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • kgame
kmessageio.h
1 /*
2  This file is part of the TDE 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 <tqcstring.h>
28 #include <tqhostaddress.h>
29 #include <tqobject.h>
30 #include <tqstring.h>
31 #include <tqptrqueue.h>
32 #include <tqfile.h>
33 #include <kdebug.h>
34 
35 class TQSocket;
36 class TDEProcess;
37 //class TQFile;
38 
39 
56 class KMessageIO : public TQObject
57 {
58  TQ_OBJECT
59 
60 
61 public:
65  KMessageIO (TQObject *parent = 0, const char *name = 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  kdError(11001) << "Calling PURE virtual isNetwork...BAD" << endl;
84  return false;
85  }
86 
94  //virtual bool isConnected () const = 0;
95  virtual bool isConnected () const
96  {
97  kdError(11001) << "Calling PURE virtual isConencted...BAD" << endl;
98  return false;
99  }
100 
109  void setId (TQ_UINT32 id);
110 
114  TQ_UINT32 id ();
115 
120  virtual TQ_UINT16 peerPort () const { return 0; }
121 
126  virtual TQString peerName () const { return TQString::fromLatin1("localhost"); }
127 
128 
129 signals:
135  void received (const TQByteArray &msg);
136 
145  void connectionBroken ();
146 
147 public slots:
148 
158  virtual void send (const TQByteArray &msg) = 0;
159 
160 protected:
161  TQ_UINT32 m_id;
162 };
163 
164 
170 class KMessageSocket : public KMessageIO
171 {
172  TQ_OBJECT
173 
174 
175 public:
186  KMessageSocket (TQString host, TQ_UINT16 port, TQObject *parent = 0,
187  const char *name = 0);
188 
197  KMessageSocket (TQHostAddress host, TQ_UINT16 port, TQObject *parent = 0,
198  const char *name = 0);
199 
211  KMessageSocket (TQSocket *socket, TQObject *parent = 0, const char *name = 0);
212 
224  KMessageSocket (int socketFD, TQObject *parent = 0, const char *name = 0);
225 
229  ~KMessageSocket ();
230 
234  virtual int rtti() const {return 1;}
235 
240  virtual TQ_UINT16 peerPort () const;
241 
246  virtual TQString peerName () const;
247 
251  bool isNetwork() const { return true; }
252 
256  bool isConnected () const;
257 
264  void send (const TQByteArray &msg);
265 
266 protected slots:
267  virtual void processNewData ();
268 
269 protected:
270  void initSocket ();
271  TQSocket *mSocket;
272  bool mAwaitingHeader;
273  TQ_UINT32 mNextBlockLength;
274 
275  bool isRecursive; // workaround for "bug" in TQSocket, TQt 2.2.3 or older
276 };
277 
278 
297 class KMessageDirect : public KMessageIO
298 {
299  TQ_OBJECT
300 
301 
302 public:
310  KMessageDirect (KMessageDirect *partner = 0, TQObject *parent = 0, const char
311 *name = 0);
312 
316  ~KMessageDirect ();
317 
321  virtual int rtti() const {return 2;}
322 
323 
327  bool isNetwork() const { return false; }
328 
337  bool isConnected () const;
338 
345  void send (const TQByteArray &msg);
346 
347 protected:
348  KMessageDirect *mPartner;
349 };
350 
351 class KMessageProcess : public KMessageIO
352 {
353  TQ_OBJECT
354 
355 
356  public:
357  KMessageProcess(TQObject *parent, TQString file);
358  ~KMessageProcess();
359  bool isConnected() const;
360  void send (const TQByteArray &msg);
361  void writeToProcess();
362 
366  bool isNetwork() const { return false; }
367 
371  virtual int rtti() const {return 3;}
372 
373 
374 
375  public slots:
376  void slotReceivedStdout(TDEProcess *proc, char *buffer, int buflen);
377  void slotReceivedStderr(TDEProcess *proc, char *buffer, int buflen);
378  void slotProcessExited(TDEProcess *p);
379  void slotWroteStdin(TDEProcess *p);
380 
381  private:
382  TQString mProcessName;
383  TDEProcess *mProcess;
384  TQPtrQueue <TQByteArray> mQueue;
385  TQByteArray *mSendBuffer;
386  TQByteArray mReceiveBuffer;
387  unsigned int mReceiveCount;
388 };
389 
390 class KMessageFilePipe : public KMessageIO
391 {
392  TQ_OBJECT
393 
394 
395  public:
396  KMessageFilePipe(TQObject *parent,TQFile *readFile,TQFile *writeFile);
397  ~KMessageFilePipe();
398  bool isConnected() const;
399  void send (const TQByteArray &msg);
400  void exec();
401 
405  bool isNetwork() const { return false; }
406 
410  virtual int rtti() const {return 4;}
411 
412 
413 
414  private:
415  TQFile *mReadFile;
416  TQFile *mWriteFile;
417  TQByteArray mReceiveBuffer;
418  unsigned int mReceiveCount;
419 };
420 
421 #endif
KMessageIO::~KMessageIO
~KMessageIO()
The usual destructor, does nothing special.
Definition: kmessageio.cpp:36
KMessageIO::send
virtual void send(const TQByteArray &msg)=0
This slot sends the data block in /e msg to the connected object, that will emit /e received()...
KMessageSocket
This class implements the message communication using a TCP/IP socket.
Definition: kmessageio.h:170
KMessageSocket::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:234
KMessageIO::received
void received(const TQByteArray &msg)
This signal is emitted when /e send() on the connected KMessageIO object is called.
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::peerName
virtual TQString peerName() const
Definition: kmessageio.h:126
KMessageDirect
This class implements the message communication using function calls directly.
Definition: kmessageio.h:297
KMessageDirect::isNetwork
bool isNetwork() const
Definition: kmessageio.h:327
KMessageIO::peerPort
virtual TQ_UINT16 peerPort() const
Definition: kmessageio.h:120
KMessageSocket::isNetwork
bool isNetwork() const
Definition: kmessageio.h:251
KMessageIO
This abstract base class represents one end of a message connections between two clients.
Definition: kmessageio.h:56
KMessageIO::setId
void setId(TQ_UINT32 id)
Sets the ID number of this object.
Definition: kmessageio.cpp:39
KMessageIO::KMessageIO
KMessageIO(TQObject *parent=0, const char *name=0)
The usual TQObject constructor, does nothing else.
Definition: kmessageio.cpp:32
KMessageIO::connectionBroken
void connectionBroken()
This signal is emitted when the connection is closed.
KMessageIO::isNetwork
virtual bool isNetwork() const
Definition: kmessageio.h:81
KMessageDirect::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:321
KMessageIO::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:75
KMessageIO::id
TQ_UINT32 id()
Queries the ID of this object.
Definition: kmessageio.cpp:44

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.