From abb47b420739f25bd48f5a7ce2cb4b2d4b063d45 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 22 Feb 2023 22:41:11 -0800 Subject: Begin sketching out browser source * Fix oatpp fetch and build --- GUI/GUI/GUI/BrowserSource.cpp | 12 +++++++ GUI/GUI/GUI/BrowserSource.h | 73 +++++++++++++++++++++++++++++++++++++++++++ GUI/GUI/GUI/GUI.vcxproj | 8 +++-- GUI/Libraries/fetch.ps1 | 8 ++++- 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 GUI/GUI/GUI/BrowserSource.cpp create mode 100644 GUI/GUI/GUI/BrowserSource.h (limited to 'GUI') diff --git a/GUI/GUI/GUI/BrowserSource.cpp b/GUI/GUI/GUI/BrowserSource.cpp new file mode 100644 index 0000000..9df4f81 --- /dev/null +++ b/GUI/GUI/GUI/BrowserSource.cpp @@ -0,0 +1,12 @@ +#include "BrowserSource.h" + +#include "oatpp/network/Server.hpp" + +BrowserSource::BrowserSource(uint16_t port) + : port_(port) +{ + AppComponent components; + OATPP_COMPONENT(std::shared_ptr, router); + router->addController(std::make_shared()); + +} diff --git a/GUI/GUI/GUI/BrowserSource.h b/GUI/GUI/GUI/BrowserSource.h new file mode 100644 index 0000000..efc6142 --- /dev/null +++ b/GUI/GUI/GUI/BrowserSource.h @@ -0,0 +1,73 @@ +#pragma once + +#include "oatpp/core/macro/codegen.hpp" +#include "oatpp/core/macro/component.hpp" +#include "oatpp/core/Types.hpp" +#include "oatpp/network/tcp/server/ConnectionProvider.hpp" +#include "oatpp/parser/json/mapping/ObjectMapper.hpp" +#include "oatpp/web/server/api/ApiController.hpp" +#include "oatpp/web/server/HttpConnectionHandler.hpp" +#include "oatpp/web/protocol/http/incoming/Request.hpp" + +#include + +#include OATPP_CODEGEN_BEGIN(DTO) + +class AppDto : public oatpp::DTO { + + DTO_INIT(AppDto, DTO) + + DTO_FIELD(Int32, statusCode); + DTO_FIELD(String, message); + +}; + +#include OATPP_CODEGEN_END(DTO) + +#include OATPP_CODEGEN_BEGIN(ApiController) + +class AppController : public oatpp::web::server::api::ApiController { +public: + AppController(OATPP_COMPONENT(std::shared_ptr, objectMapper)) + : oatpp::web::server::api::ApiController(objectMapper) + {} +public: + + ENDPOINT("GET", "/", root) { + auto dto = AppDto::createShared(); + dto->statusCode = 200; + dto->message = "Hello World!"; + return createDtoResponse(Status::CODE_200, dto); + } +}; + +#include OATPP_CODEGEN_END(ApiController) + +class AppComponent { +public: + // TODO(yum) parameterize port + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([] { + return oatpp::network::tcp::server::ConnectionProvider::createShared({ "0.0.0.0", 8000, oatpp::network::Address::IP_4 }); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { + return oatpp::web::server::HttpRouter::createShared(); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_COMPONENT(std::shared_ptr, router); // get Router component + return oatpp::web::server::HttpConnectionHandler::createShared(router); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, apiObjectMapper)([] { + return oatpp::parser::json::mapping::ObjectMapper::createShared(); + }()); +}; + +class BrowserSource { +public: + BrowserSource(uint16_t port); + +private: + const uint16_t port_; +}; diff --git a/GUI/GUI/GUI/GUI.vcxproj b/GUI/GUI/GUI/GUI.vcxproj index 0243d73..8db7fbf 100644 --- a/GUI/GUI/GUI/GUI.vcxproj +++ b/GUI/GUI/GUI/GUI.vcxproj @@ -75,8 +75,8 @@ - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)/whisper/ - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(ProjectDir)/whisper + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)/whisper;$(ProjectDir)/oatpp + $(VC_IncludePath);$(WindowsSDK_IncludePath);$(ProjectDir) @@ -141,11 +141,12 @@ true true true - kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;shell32.lib;shlwapi.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;version.lib;comctl32.lib;rpcrt4.lib;ws2_32.lib;wininet.lib;winmm.lib;Whisper.lib;%(AdditionalDependencies) + kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;shell32.lib;shlwapi.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;version.lib;comctl32.lib;rpcrt4.lib;ws2_32.lib;wininet.lib;winmm.lib;Whisper.lib;oatpp.lib;%(AdditionalDependencies) + @@ -155,6 +156,7 @@ + diff --git a/GUI/Libraries/fetch.ps1 b/GUI/Libraries/fetch.ps1 index 218d48b..550dfa5 100644 --- a/GUI/Libraries/fetch.ps1 +++ b/GUI/Libraries/fetch.ps1 @@ -86,8 +86,14 @@ if (-Not (Test-Path oatpp)) { pushd $OATPP_DIR > $null mkdir build pushd build > $null - cmake.exe .. -DCMAKE_BUILD_TYPE=Release -DOATPP_BUILD_TESTS=OFF + cmake.exe .. ` + -DCMAKE_BUILD_TYPE=Release ` + -DBUILD_SHARED_LIBS=OFF ` + -DOATPP_MSVC_LINK_STATIC_RUNTIME=ON ` + -DOATPP_BUILD_TESTS=OFF cmake.exe --build . -j $NPROC --config Release + cp src/Release/oatpp.lib ../../../../GUI/GUI/oatpp/ + cp -Recurse ../src/oatpp/* ../../../../GUI/GUI/oatpp/ popd > $null popd > $null } -- cgit v1.2.3