• 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
35class TQSocket;
36class TDEProcess;
37//class TQFile;
38
39
56class KMessageIO : public TQObject
57{
58 TQ_OBJECT
59
60
61public:
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
129signals:
135 void received (const TQByteArray &msg);
136
145 void connectionBroken ();
146
147public slots:
148
158 virtual void send (const TQByteArray &msg) = 0;
159
160protected:
161 TQ_UINT32 m_id;
162};
163
164
170class KMessageSocket : public KMessageIO
171{
172 TQ_OBJECT
173
174
175public:
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
266protected slots:
267 virtual void processNewData ();
268
269protected:
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
297class KMessageDirect : public KMessageIO
298{
299 TQ_OBJECT
300
301
302public:
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
347protected:
348 KMessageDirect *mPartner;
349};
350
351class 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
390class 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
KMessageDirect
This class implements the message communication using function calls directly.
Definition: kmessageio.h:298
KMessageDirect::~KMessageDirect
~KMessageDirect()
Destructor, closes the connection.
Definition: kmessageio.cpp:202
KMessageDirect::isNetwork
bool isNetwork() const
Definition: kmessageio.h:327
KMessageDirect::send
void send(const TQByteArray &msg)
Overwritten slot method from KMessageIO.
Definition: kmessageio.cpp:216
KMessageDirect::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:321
KMessageDirect::isConnected
bool isConnected() const
Returns true, if the object is connected to another instance.
Definition: kmessageio.cpp:211
KMessageDirect::KMessageDirect
KMessageDirect(KMessageDirect *partner=0, TQObject *parent=0, const char *name=0)
Creates an object and connects it to the object given in the first parameter.
Definition: kmessageio.cpp:180
KMessageIO
This abstract base class represents one end of a message connections between two clients.
Definition: kmessageio.h:57
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().
KMessageIO::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:75
KMessageIO::KMessageIO
KMessageIO(TQObject *parent=0, const char *name=0)
The usual TQObject constructor, does nothing else.
Definition: kmessageio.cpp:32
KMessageIO::peerName
virtual TQString peerName() const
Definition: kmessageio.h:126
KMessageIO::peerPort
virtual TQ_UINT16 peerPort() const
Definition: kmessageio.h:120
KMessageIO::connectionBroken
void connectionBroken()
This signal is emitted when the connection is closed.
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::id
TQ_UINT32 id()
Queries the ID of this object.
Definition: kmessageio.cpp:44
KMessageIO::setId
void setId(TQ_UINT32 id)
Sets the ID number of this object.
Definition: kmessageio.cpp:39
KMessageIO::~KMessageIO
~KMessageIO()
The usual destructor, does nothing special.
Definition: kmessageio.cpp:36
KMessageIO::isNetwork
virtual bool isNetwork() const
Definition: kmessageio.h:81
KMessageSocket
This class implements the message communication using a TCP/IP socket.
Definition: kmessageio.h:171
KMessageSocket::isNetwork
bool isNetwork() const
Definition: kmessageio.h:251
KMessageSocket::isConnected
bool isConnected() const
Returns true if the socket is in state /e connected.
Definition: kmessageio.cpp:91
KMessageSocket::KMessageSocket
KMessageSocket(TQString host, TQ_UINT16 port, TQObject *parent=0, const char *name=0)
Connects to a server socket on /e host with /e port.
Definition: kmessageio.cpp:51
KMessageSocket::rtti
virtual int rtti() const
The runtime idendifcation.
Definition: kmessageio.h:234
KMessageSocket::peerName
virtual TQString peerName() const
Definition: kmessageio.cpp:173
KMessageSocket::send
void send(const TQByteArray &msg)
Overwritten slot method from KMessageIO.
Definition: kmessageio.cpp:96
KMessageSocket::peerPort
virtual TQ_UINT16 peerPort() const
Definition: kmessageio.cpp:168
KMessageSocket::~KMessageSocket
~KMessageSocket()
Destructor, closes the socket.
Definition: kmessageio.cpp:86

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.9.4
This website is maintained by Timothy Pearson.