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