| 1 | /*
|
|---|
| 2 | * bytestream.h - base class for bytestreams
|
|---|
| 3 | * Copyright (C) 2003 Justin Karneges
|
|---|
| 4 | *
|
|---|
| 5 | * This library is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | * License as published by the Free Software Foundation; either
|
|---|
| 8 | * version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 10 | * This library is distributed in the hope that it will be useful,
|
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | * Lesser General Public License for more details.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | * License along with this library; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #ifndef CS_BYTESTREAM_H
|
|---|
| 22 | #define CS_BYTESTREAM_H
|
|---|
| 23 |
|
|---|
| 24 | #include<qobject.h>
|
|---|
| 25 | #include<qcstring.h>
|
|---|
| 26 |
|
|---|
| 27 | // CS_NAMESPACE_BEGIN
|
|---|
| 28 |
|
|---|
| 29 | // CS_EXPORT_BEGIN
|
|---|
| 30 | class ByteStream : public QObject
|
|---|
| 31 | {
|
|---|
| 32 | Q_OBJECT
|
|---|
| 33 | public:
|
|---|
| 34 | enum Error { ErrRead, ErrWrite, ErrCustom = 10 };
|
|---|
| 35 | ByteStream(QObject *parent=0);
|
|---|
| 36 | virtual ~ByteStream()=0;
|
|---|
| 37 |
|
|---|
| 38 | virtual bool isOpen() const;
|
|---|
| 39 | virtual void close();
|
|---|
| 40 | virtual void write(const QByteArray &);
|
|---|
| 41 | virtual QByteArray read(int bytes=0);
|
|---|
| 42 | virtual int bytesAvailable() const;
|
|---|
| 43 | virtual int bytesToWrite() const;
|
|---|
| 44 |
|
|---|
| 45 | void write(const QCString &);
|
|---|
| 46 |
|
|---|
| 47 | static void appendArray(QByteArray *a, const QByteArray &b);
|
|---|
| 48 | static QByteArray takeArray(QByteArray *from, int size=0, bool del=true);
|
|---|
| 49 |
|
|---|
| 50 | signals:
|
|---|
| 51 | void connectionClosed();
|
|---|
| 52 | void delayedCloseFinished();
|
|---|
| 53 | void readyRead();
|
|---|
| 54 | void bytesWritten(int);
|
|---|
| 55 | void error(int);
|
|---|
| 56 |
|
|---|
| 57 | protected:
|
|---|
| 58 | void clearReadBuffer();
|
|---|
| 59 | void clearWriteBuffer();
|
|---|
| 60 | void appendRead(const QByteArray &);
|
|---|
| 61 | void appendWrite(const QByteArray &);
|
|---|
| 62 | QByteArray takeRead(int size=0, bool del=true);
|
|---|
| 63 | QByteArray takeWrite(int size=0, bool del=true);
|
|---|
| 64 | QByteArray & readBuf();
|
|---|
| 65 | QByteArray & writeBuf();
|
|---|
| 66 | virtual int tryWrite();
|
|---|
| 67 |
|
|---|
| 68 | private:
|
|---|
| 69 | //! \if _hide_doc_
|
|---|
| 70 | class Private;
|
|---|
| 71 | Private *d;
|
|---|
| 72 | //! \endif
|
|---|
| 73 | };
|
|---|
| 74 | // CS_EXPORT_END
|
|---|
| 75 |
|
|---|
| 76 | // CS_NAMESPACE_END
|
|---|
| 77 |
|
|---|
| 78 | #endif
|
|---|