-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWebServer.h
44 lines (37 loc) · 911 Bytes
/
WebServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <thread>
#include <string>
#include <mutex>
class WebServer
{
public:
bool start(const int32_t port);
void stop();
int32_t getPort() { return m_port; }
void setRedirectUrl(const std::string &url) { m_redirectUrl = url; }
void setExpectedReferer(const std::string &uri) { m_expectedReferer = uri; }
const std::string getErr() const { return m_err; }
std::string getToken();
void clearToken();
bool isAlreadyStarted() { return m_launching || m_running; }
public:
static WebServer& instance()
{
static WebServer a;
return a;
}
private:
WebServer();
~WebServer();
void workerThread();
int32_t m_port = 0;
bool m_launching = false;
bool m_running = false;
std::thread m_workerThread;
std::string m_err;
std::string m_token;
std::string m_redirectUrl;
std::mutex m_tokenMtx;
// Example, http://localhost:25341/?secret_token=
std::string m_expectedReferer;
};