diff options
Diffstat (limited to 'src/buildtool/serve_api')
-rw-r--r-- | src/buildtool/serve_api/serve_service/serve_server_implementation.cpp | 49 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/serve_server_implementation.hpp | 35 |
2 files changed, 41 insertions, 43 deletions
diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp index b588fc45..302e2da7 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp @@ -60,6 +60,34 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool { } } // namespace +auto ServeServerImpl::Create(std::optional<std::string> interface, + std::optional<int> port, + std::optional<std::string> info_file, + std::optional<std::string> pid_file) noexcept + -> std::optional<ServeServerImpl> { + ServeServerImpl server; + if (interface) { + server.interface_ = std::move(*interface); + } + if (port) { + auto parsed_port = ParsePort(*port); + if (parsed_port) { + server.port_ = static_cast<int>(*parsed_port); + } + else { + Logger::Log(LogLevel::Error, "Invalid port '{}'", *port); + return std::nullopt; + } + } + if (info_file) { + server.info_file_ = std::move(*info_file); + } + if (pid_file) { + server.pid_file_ = std::move(*pid_file); + } + return std::move(server); +} + auto ServeServerImpl::Run(RemoteServeConfig const& serve_config, std::optional<ServeApi> const& serve, bool with_execute) -> bool { @@ -159,25 +187,4 @@ auto ServeServerImpl::Run(RemoteServeConfig const& serve_config, return true; } -[[nodiscard]] auto ServeServerImpl::SetInfoFile(std::string const& x) noexcept - -> bool { - Instance().info_file_ = x; - return true; -} - -[[nodiscard]] auto ServeServerImpl::SetPidFile(std::string const& x) noexcept - -> bool { - Instance().pid_file_ = x; - return true; -} - -[[nodiscard]] auto ServeServerImpl::SetPort(int const x) noexcept -> bool { - auto port_num = ParsePort(x); - if (!port_num) { - return false; - } - Instance().port_ = static_cast<int>(*port_num); - return true; -} - #endif // BOOTSTRAP_BUILD_TOOL diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp index b3c0ee51..e0718284 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp @@ -15,6 +15,7 @@ #ifndef SERVE_SERVER_IMPLEMENTATION_HPP #define SERVE_SERVER_IMPLEMENTATION_HPP +#include <optional> #include <string> #include "src/buildtool/logging/logger.hpp" @@ -23,31 +24,20 @@ class ServeServerImpl { public: - ServeServerImpl() noexcept = default; - [[nodiscard]] static auto Instance() noexcept -> ServeServerImpl& { - static ServeServerImpl x; - return x; - } - - [[nodiscard]] static auto SetInterface(std::string const& x) noexcept - -> bool { - Instance().interface_ = x; - return true; - } - - [[nodiscard]] static auto SetPidFile(std::string const& x) noexcept -> bool; + [[nodiscard]] static auto Create( + std::optional<std::string> interface, + std::optional<int> port, + std::optional<std::string> info_file, + std::optional<std::string> pid_file) noexcept + -> std::optional<ServeServerImpl>; - [[nodiscard]] static auto SetPort(int x) noexcept -> bool; - - [[nodiscard]] static auto SetInfoFile(std::string const& x) noexcept - -> bool; + ~ServeServerImpl() noexcept = default; ServeServerImpl(ServeServerImpl const&) = delete; - auto operator=(ServeServerImpl const&) noexcept - -> ServeServerImpl& = delete; + auto operator=(ServeServerImpl const&) -> ServeServerImpl& = delete; - ServeServerImpl(ServeServerImpl&&) noexcept = delete; - auto operator=(ServeServerImpl&&) noexcept -> ServeServerImpl& = delete; + ServeServerImpl(ServeServerImpl&&) noexcept = default; + auto operator=(ServeServerImpl&&) noexcept -> ServeServerImpl& = default; /// \brief Start the serve service. /// \param serve_config RemoteServeConfig to be used. @@ -57,9 +47,10 @@ class ServeServerImpl { auto Run(RemoteServeConfig const& serve_config, std::optional<ServeApi> const& serve, bool with_execute) -> bool; - ~ServeServerImpl() = default; private: + ServeServerImpl() noexcept = default; + std::string interface_{"127.0.0.1"}; int port_{0}; std::string info_file_{}; |