Remove QtWebSockets from include directives
[contrib/qtwebsockets.git] / src / websockets / qwebsocket.h
1 /*
2 QWebSockets implements the WebSocket protocol as defined in RFC 6455.
3 Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com)
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 #ifndef QWEBSOCKET_H
21 #define QWEBSOCKET_H
22
23 #include <QUrl>
24 #ifndef QT_NO_NETWORKPROXY
25 #include <QNetworkProxy>
26 #endif
27
28 #include "qwebsockets_global.h"
29 #include "qwebsocketprotocol.h"
30
31 QT_BEGIN_NAMESPACE
32
33 class QTcpSocket;
34 class QWebSocketPrivate;
35
36 class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject
37 {
38     Q_OBJECT
39     Q_DISABLE_COPY(QWebSocket)
40     Q_DECLARE_PRIVATE(QWebSocket)
41
42 public:
43     explicit QWebSocket(const QString &origin = QString(), QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST, QObject *parent = Q_NULLPTR);
44     virtual ~QWebSocket();
45
46     void abort();
47     QAbstractSocket::SocketError error() const;
48     QString errorString() const;
49     bool flush();
50     bool isValid() const;
51     QHostAddress localAddress() const;
52     quint16 localPort() const;
53     QAbstractSocket::PauseModes pauseMode() const;
54     QHostAddress peerAddress() const;
55     QString peerName() const;
56     quint16 peerPort() const;
57 #ifndef QT_NO_NETWORKPROXY
58     QNetworkProxy proxy() const;
59     void setProxy(const QNetworkProxy &networkProxy);
60 #endif
61     qint64 readBufferSize() const;
62     void setReadBufferSize(qint64 size);
63
64     void resume();
65     void setPauseMode(QAbstractSocket::PauseModes pauseMode);
66
67     void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
68     QVariant socketOption(QAbstractSocket::SocketOption option);
69     QAbstractSocket::SocketState state() const;
70
71     bool waitForConnected(int msecs = 30000);
72     bool waitForDisconnected(int msecs = 30000);
73
74     QWebSocketProtocol::Version version() const;
75     QString resourceName() const;
76     QUrl requestUrl() const;
77     QString origin() const;
78     QString protocol() const;
79     QString extension() const;
80
81     qint64 write(const char *message);          //send data as text
82     qint64 write(const char *message, qint64 maxSize);          //send data as text
83     qint64 write(const QString &message);       //send data as text
84     qint64 write(const QByteArray &data);       //send data as binary
85
86 public Q_SLOTS:
87     void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL, const QString &reason = QString());
88     void open(const QUrl &url, bool mask = true);
89     void ping(const QByteArray &payload = QByteArray());
90
91 Q_SIGNALS:
92     void aboutToClose();
93     void connected();
94     void disconnected();
95     void stateChanged(QAbstractSocket::SocketState state);
96 #ifndef QT_NO_NETWORKPROXY
97     void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
98 #endif
99     void readChannelFinished();
100     void textFrameReceived(QString frame, bool isLastFrame);
101     void binaryFrameReceived(QByteArray frame, bool isLastFrame);
102     void textMessageReceived(QString message);
103     void binaryMessageReceived(QByteArray message);
104     void error(QAbstractSocket::SocketError error);
105     void pong(quint64 elapsedTime, QByteArray payload);
106
107 private:
108     QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *parent = Q_NULLPTR);
109     QWebSocketPrivate * const d_ptr;
110 };
111
112 QT_END_NAMESPACE
113
114 #endif // QWEBSOCKET_H