File indexing completed on 2024-06-02 04:06:59
0001 /* 0002 * bytestream.h - base class for bytestreams 0003 * Copyright (C) 2003 Justin Karneges 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * either version 2 0009 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0019 * 0020 */ 0021 0022 #ifndef CS_BYTESTREAM_H 0023 #define CS_BYTESTREAM_H 0024 0025 #include <QObject> 0026 #include <QByteArray> 0027 0028 #include "iris_export.h" 0029 // CS_NAMESPACE_BEGIN 0030 0031 // CS_EXPORT_BEGIN 0032 class IRIS_EXPORT ByteStream : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 enum Error { ErrRead, ErrWrite, ErrCustom = 10 }; 0037 ByteStream(QObject *parent=0); 0038 ~ByteStream() override =0; 0039 0040 virtual bool isOpen() const; 0041 virtual void close(); 0042 virtual void write(const QByteArray &); 0043 virtual QByteArray read(int bytes=0); 0044 virtual int bytesAvailable() const; 0045 virtual int bytesToWrite() const; 0046 0047 static void appendArray(QByteArray *a, const QByteArray &b); 0048 static QByteArray takeArray(QByteArray *from, int size=0, bool del=true); 0049 0050 signals: 0051 void connectionClosed(); 0052 void delayedCloseFinished(); 0053 void readyRead(); 0054 void bytesWritten(int); 0055 void error(int); 0056 0057 protected: 0058 void clearReadBuffer(); 0059 void clearWriteBuffer(); 0060 void appendRead(const QByteArray &); 0061 void appendWrite(const QByteArray &); 0062 QByteArray takeRead(int size=0, bool del=true); 0063 QByteArray takeWrite(int size=0, bool del=true); 0064 QByteArray & readBuf(); 0065 QByteArray & writeBuf(); 0066 virtual int tryWrite(); 0067 0068 private: 0069 //! \if _hide_doc_ 0070 class Private; 0071 Private *d; 0072 //! \endif 0073 }; 0074 // CS_EXPORT_END 0075 0076 // CS_NAMESPACE_END 0077 0078 #endif