For the moment it doesn't compile with enable final (need to
[kdenetwork.git] / kopete / protocols / oscar / liboscar / bytestream.h
blobe5a2b9999e682d62f3b6b9baba5713694bbb7dd7
1 /*
2 * bytestream.h - base class for bytestreams
3 * Copyright (C) 2003 Justin Karneges
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef CS_BYTESTREAM_H
22 #define CS_BYTESTREAM_H
24 #include <QtCore/QObject>
25 #include <QtNetwork/QAbstractSocket>
27 // CS_NAMESPACE_BEGIN
29 // CS_EXPORT_BEGIN
30 class ByteStream : public QObject
32 Q_OBJECT
33 public:
34 enum Error { ErrRead, ErrWrite, ErrCustom = 10 };
35 ByteStream(QObject *parent=0);
36 virtual ~ByteStream()=0;
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;
45 static void appendArray(QByteArray *a, const QByteArray &b);
46 static QByteArray takeArray(QByteArray *from, int size=0, bool del=true);
48 Q_SIGNALS:
49 void connectionClosed();
50 void delayedCloseFinished();
51 void readyRead();
52 void bytesWritten(int);
53 void error(QAbstractSocket::SocketError);
55 protected:
56 void clearReadBuffer();
57 void clearWriteBuffer();
58 void appendRead(const QByteArray &);
59 void appendWrite(const QByteArray &);
60 QByteArray takeRead(int size=0, bool del=true);
61 QByteArray takeWrite(int size=0, bool del=true);
62 QByteArray & readBuf();
63 QByteArray & writeBuf();
64 virtual int tryWrite();
66 private:
67 //! \if _hide_doc_
68 class Private;
69 Private *d;
70 //! \endif
72 // CS_EXPORT_END
74 // CS_NAMESPACE_END
76 #endif