Plotly.cpp 0.1.0
A C++ plotting library for expressive, interactive, real-time & streaming data visualization
Loading...
Searching...
No Matches
http_server.hpp
Go to the documentation of this file.
1#ifndef PLOTLY_DETAILS_HTTP_SERVER_HPP
2#define PLOTLY_DETAILS_HTTP_SERVER_HPP
3
4#include "httplib.h"
5#include <filesystem>
6#include <string_view>
7#include <thread>
8
17
18namespace plotly::detail {
19
30private:
31 httplib::Server _server;
32 int _port = 0;
33 std::thread _serverThread;
34
35 void setupCommon();
36
37public:
42 explicit HttpServer(const std::filesystem::path &directory);
43
48
49 // Prevent copying
50 HttpServer(const HttpServer &) = delete;
51 auto operator=(const HttpServer &) -> HttpServer & = delete;
52
53 // Prevent moving (due to thread member)
54 HttpServer(HttpServer &&) = delete;
55 auto operator=(HttpServer &&) -> HttpServer & = delete;
56
63 void start();
64
69 [[nodiscard]] auto getPort() const noexcept -> int;
70
79 void setWebsocketPortRequestHandler(int wsPort);
80
86 void stop();
87};
88
89} // namespace plotly::detail
90
91#endif // PLOTLY_DETAILS_HTTP_SERVER_HPP
void setWebsocketPortRequestHandler(int wsPort)
Configure the server to respond with a specific WebSocket port.
Definition http_server.cpp:61
auto getPort() const noexcept -> int
Get the port number the server is running on.
Definition http_server.cpp:59
void start()
Start the HTTP server.
Definition http_server.cpp:31
HttpServer(const std::filesystem::path &directory)
Construct a server serving files from a directory.
Definition http_server.cpp:22
HttpServer(HttpServer &&)=delete
HttpServer(const HttpServer &)=delete
void stop()
Stop the HTTP server.
Definition http_server.cpp:49
~HttpServer()
Destructor.
Definition http_server.cpp:29
auto operator=(const HttpServer &) -> HttpServer &=delete
auto operator=(HttpServer &&) -> HttpServer &=delete
Definition browser.cpp:27