]> git.sesse.net Git - ultimatescore/blob - client/ws_server.h
17d13094433a3169ad8b2b40a71878354fb5101c
[ultimatescore] / client / ws_server.h
1 #ifndef _WS_SERVER_H
2 #define _WS_SERVER_H 1
3
4 #include <functional>
5 #include <mutex>
6 #include <string>
7 #include <thread>
8 #include <unordered_set>
9 #include <vector>
10
11 #include <QObject>
12
13 class QWebSocket;
14 class QWebSocketServer;
15
16 class WSServer : public QObject {
17         Q_OBJECT
18
19 public:
20         WSServer(const std::string &host, int port);
21
22         void add_init_command(const std::string &cmd);
23         void set_connection_callback(const std::function<void(bool)> &callback);
24         void send_command(const std::string &cmd);
25         void change_port(int port);
26
27 private slots:
28         void on_new_connection();
29         void disconnected();
30
31 private:
32         void thread_func();
33
34         std::vector<std::string> init_commands;
35         std::function<void(bool)> connection_callback;
36
37         QWebSocketServer *ws_server;
38         std::unordered_set<QWebSocket *> clients;
39 };
40
41 #endif  // !defined(_WS_SERVER_H)