QVisu
Qt-based visualization for smart homes
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
C:/Users/max/ti/qt5/qvisu/qvwebsocket.h
1 /* QVisu websockets (c) 2015 Maximilian Gauger mgauger@kalassi.de
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation, either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12 
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef QVWEBSOCKET_H
18 #define QVWEBSOCKET_H
19 
20 //#define USE_THREADS
21 
22 #include <QObject>
23 #include <QTcpSocket>
24 #include <QUrl>
25 #include <QTimer>
26 #include <QFile>
32 class QVWebsocket : public QObject
33 {
34  Q_OBJECT
35 public:
36  explicit QVWebsocket(QObject *parent = 0);
37  ~QVWebsocket();
38 
39 signals:
41  void connected();
43  void disconnected();
45  void textMessageReceived(QString);
46 
47 public slots:
49  void open(QUrl);
51  void close();
53  void shutdown();
55  void sendTextMessage(QString);
56  void startLogging(QString);
57  void stopLogging();
58 #ifdef USE_THREADS
59  void setThread(QThread*);
60 #endif
61 
62 private slots:
64  void socketConnected();
66  void socketDisconnected();
68  void socketReadyRead();
69 
70 private:
71  QTcpSocket *socket;
72  QString host, path, key;
73  QByteArray inputBuffer;
74  QTimer close_timer;
75  QFile log_file;
76  QTextStream log_stream;
77 
78  enum {
79  socketClosed,
80  socketOpening,
81  awaitingUpgrade,
82  wsEstablished,
83  wsClosing
84  } status;
85 
86 
87 };
88 
89 #endif // QVWEBSOCKET_H
void close()
Definition: qvwebsocket.cpp:84
void open(QUrl)
Definition: qvwebsocket.cpp:42
void textMessageReceived(QString)
void sendTextMessage(QString)
Definition: qvwebsocket.cpp:92
void shutdown()
Definition: qvwebsocket.cpp:70
void connected()
void disconnected()
Definition: qvwebsocket.h:32