/* SPDX-License-Identifier: GPL-3.0-or-later Copyright © 2022 Amebis */ #pragma once #include "controller.hpp" #include #include #include #include #include #include class AppComponent { protected: const oatpp::base::CommandLineArguments& m_cmdArgs; public: AppComponent(const oatpp::base::CommandLineArguments& cmdArgs) : m_cmdArgs(cmdArgs) {} OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([this] { oatpp::String host = m_cmdArgs.getNamedArgumentValue("--host", "localhost"); v_uint16 port = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--port", "8000")); oatpp::network::Address::Family family = oatpp::network::Address::UNSPEC; if (m_cmdArgs.hasArgument("-4")) family = oatpp::network::Address::IP_4; else if (m_cmdArgs.hasArgument("-6")) family = oatpp::network::Address::IP_6; return oatpp::network::tcp::server::ConnectionProvider::createShared({host, port, family}); }()); 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); return oatpp::web::server::HttpConnectionHandler::createShared(router); }()); OATPP_CREATE_COMPONENT(std::shared_ptr, apiObjectMapper)([] { return oatpp::parser::json::mapping::ObjectMapper::createShared(); }()); OATPP_CREATE_COMPONENT(std::shared_ptr, controller)([] { OATPP_COMPONENT(std::shared_ptr, objectMapper); return std::make_shared(objectMapper); }()); OATPP_CREATE_COMPONENT(std::shared_ptr, server)([] { OATPP_COMPONENT(std::shared_ptr, connectionProvider); OATPP_COMPONENT(std::shared_ptr, connectionHandler); return oatpp::network::Server::createShared(connectionProvider, connectionHandler); }()); };