1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 19:12:30 +01:00

Add basic http server

this is for content like godot webasm
that is only able to be shown from a
webserver
This commit is contained in:
Elias Steurer 2021-10-23 18:34:25 +02:00
parent e155879e37
commit 8615d7371f
4 changed files with 63 additions and 2 deletions

View File

@ -10,13 +10,16 @@ find_package(
REQUIRED) REQUIRED)
set(SOURCES # cmake-format: sortable set(SOURCES # cmake-format: sortable
src/util.cpp src/contenttypes.cpp) src/util.cpp src/contenttypes.cpp inc/public/ScreenPlayUtil/httpfileserver.cpp)
set(HEADER # cmake-format: sortable set(HEADER # cmake-format: sortable
inc/public/ScreenPlayUtil/util.h inc/public/ScreenPlayUtil/contenttypes.h inc/public/ScreenPlayUtil/projectfile.h) inc/public/ScreenPlayUtil/util.h inc/public/ScreenPlayUtil/httpfileserver.h inc/public/ScreenPlayUtil/contenttypes.h inc/public/ScreenPlayUtil/projectfile.h)
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADER}) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADER})
find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h")
target_include_directories(${PROJECT_NAME} PUBLIC ${CPP_HTTPLIB_INCLUDE_DIRS})
target_include_directories( target_include_directories(
${PROJECT_NAME} ${PROJECT_NAME}
PUBLIC inc/public/ PUBLIC inc/public/

View File

@ -0,0 +1,28 @@
#include "httpfileserver.h"
#include "httplib.h"
namespace ScreenPlay {
HttpFileServer::HttpFileServer(QObject* parent)
: QObject { parent }
{
}
void HttpFileServer::startServer()
{
const auto deleter = [](auto* ptr) { delete ptr; };
m_server = std::unique_ptr<httplib::Server, Deleter>(new httplib::Server(), deleter);
m_thread = std::thread([&]() {
qInfo() << " set_mount_point" << m_server->set_mount_point("/", "C:/Users/Eli/Desktop/web");
qInfo() << "listen";
m_server->listen("0.0.0.0", 8081);
qInfo() << "end";
});
}
void HttpFileServer::stopServer()
{
if (m_thread.joinable())
m_thread.join();
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <QDebug>
#include <QObject>
#include <memory>
#include <thread>
namespace httplib {
class Server;
}
namespace ScreenPlay {
class HttpFileServer : public QObject {
Q_OBJECT
public:
explicit HttpFileServer(QObject* parent = nullptr);
void startServer();
void stopServer();
private:
using Deleter = std::function<void(httplib::Server*)>;
std::unique_ptr<httplib::Server, Deleter> m_server;
std::thread m_thread;
};
}

View File

@ -42,6 +42,7 @@ if __name__ == "__main__":
"sentry-native", "sentry-native",
"doctest", "doctest",
"benchmark", "benchmark",
"cpp-httplib"
] ]
vcpkg_triplet = "" vcpkg_triplet = ""