| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt WebGL module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #ifndef QWEBGLWEBSOCKETSERVER_H |
| 31 | #define QWEBGLWEBSOCKETSERVER_H |
| 32 | |
| 33 | #include <QtCore/qobject.h> |
| 34 | #include <QtCore/qscopedpointer.h> |
| 35 | |
| 36 | QT_BEGIN_NAMESPACE |
| 37 | |
| 38 | class QMutex; |
| 39 | class QWebSocket; |
| 40 | class QWaitCondition; |
| 41 | class QWebGLWebSocketServerPrivate; |
| 42 | |
| 43 | class QWebGLWebSocketServer : public QObject |
| 44 | { |
| 45 | Q_OBJECT |
| 46 | |
| 47 | public: |
| 48 | enum class MessageType |
| 49 | { |
| 50 | Connect, |
| 51 | GlCommand, |
| 52 | CreateCanvas, |
| 53 | DestroyCanvas, |
| 54 | OpenUrl, |
| 55 | ChangeTitle |
| 56 | }; |
| 57 | |
| 58 | QWebGLWebSocketServer(quint16 port, QObject *parent = nullptr); |
| 59 | ~QWebGLWebSocketServer() override; |
| 60 | |
| 61 | quint16 port() const; |
| 62 | |
| 63 | QMutex *mutex(); |
| 64 | QWaitCondition *waitCondition(); |
| 65 | |
| 66 | QVariant queryValue(int id); |
| 67 | |
| 68 | public slots: |
| 69 | void create(); |
| 70 | void sendMessage(QWebSocket *socket, |
| 71 | QWebGLWebSocketServer::MessageType type, |
| 72 | const QVariantMap &values); |
| 73 | |
| 74 | protected: |
| 75 | bool event(QEvent *event) override; |
| 76 | |
| 77 | private slots: |
| 78 | void onNewConnection(); |
| 79 | void onDisconnect(); |
| 80 | void onTextMessageReceived(const QString &message); |
| 81 | |
| 82 | private: |
| 83 | Q_DISABLE_COPY(QWebGLWebSocketServer) |
| 84 | Q_DECLARE_PRIVATE(QWebGLWebSocketServer) |
| 85 | QScopedPointer<QWebGLWebSocketServerPrivate> d_ptr; |
| 86 | }; |
| 87 | |
| 88 | QT_END_NAMESPACE |
| 89 | |
| 90 | #endif // QWEBGLWEBSOCKETSERVER_H |
| 91 | |