diff options
Diffstat (limited to 'c++-qt/gats-qt/gatsstream.h')
-rw-r--r--[l---------] | c++-qt/gats-qt/gatsstream.h | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/c++-qt/gats-qt/gatsstream.h b/c++-qt/gats-qt/gatsstream.h index 38d4d0e..979ca60 120000..100644 --- a/c++-qt/gats-qt/gatsstream.h +++ b/c++-qt/gats-qt/gatsstream.h | |||
@@ -1 +1,79 @@ | |||
1 | ../src/gatsstream.h \ No newline at end of file | 1 | /* |
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #ifndef GATS_STREAM_H | ||
9 | #define GATS_STREAM_H | ||
10 | |||
11 | #include <QIODevice> | ||
12 | #include <QByteArray> | ||
13 | |||
14 | namespace Gats | ||
15 | { | ||
16 | class Object; | ||
17 | |||
18 | class GatsStream : public QObject | ||
19 | { | ||
20 | Q_OBJECT; | ||
21 | public: | ||
22 | GatsStream( QIODevice &rStream ); | ||
23 | virtual ~GatsStream(); | ||
24 | |||
25 | public slots: | ||
26 | /** | ||
27 | * Read an object packet from the assosiated stream. This will make | ||
28 | * every effort to only read exactly enough data to describe one packet, | ||
29 | * in case you want to do other things with your stream. It will | ||
30 | * automatically skip NULL byte spacing between packets, which makes | ||
31 | * a convinient padding method for encrypted data streams. Since | ||
32 | * sizing information is available in the packet header exact amounts | ||
33 | * of data can be read, however this function doesn't assume that it | ||
34 | * can read the entire object in one operation. If it fails to read | ||
35 | * a complete packet in one call, it will keep the data it's read so | ||
36 | * far buffered and return NULL, ready for another attempt. You can | ||
37 | * use the function hasReadBuffer() to deterimne if readObject() | ||
38 | * has read part of an object packet or not. If readObject returns | ||
39 | * non-null then hasReadBuffer should return false on it's next call. | ||
40 | */ | ||
41 | Gats::Object *readObject(); | ||
42 | |||
43 | /** | ||
44 | * Works exactly like readObject, except it reads all pending objects | ||
45 | * and emits a objectRead signal for each one read. It doesn't return | ||
46 | * anything. This is perfect for connecting to a QIODevice's readRead | ||
47 | * signal. | ||
48 | */ | ||
49 | void readAllObjects(); | ||
50 | |||
51 | public: | ||
52 | /** | ||
53 | * Write an object | ||
54 | */ | ||
55 | void writeObject( Gats::Object *pObject ); | ||
56 | |||
57 | /** | ||
58 | * Tells you if there is data still in the read buffer, i.e. that a | ||
59 | * packet is part way through being read. If readObject has returned | ||
60 | * non-null in the most recent call, this should always be false. | ||
61 | */ | ||
62 | bool hasReadBuffer() { return qbRead.size() > 0; } | ||
63 | int getReadBufferSize() { return qbRead.size(); } | ||
64 | |||
65 | QIODevice &getIODevice() { return rStream; } | ||
66 | |||
67 | signals: | ||
68 | void objectRead( Gats::Object *pObj ); | ||
69 | |||
70 | private: | ||
71 | bool skipReadNulls(); | ||
72 | |||
73 | private: | ||
74 | QIODevice &rStream; | ||
75 | QByteArray qbRead; | ||
76 | }; | ||
77 | }; | ||
78 | |||
79 | #endif | ||