diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-18 10:12:15 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-22 18:44:29 +0200 |
commit | 69a5e84e420aa16022baeb146931cd6da43f6305 (patch) | |
tree | af74c8e23dc41bcbaaa97a697510fa1019f88cac /src/buildtool/execution_api/execution_service/server_implementation.cpp | |
parent | c046489012d3d30a46b94c8047256fd41e8076c9 (diff) | |
download | justbuild-69a5e84e420aa16022baeb146931cd6da43f6305.tar.gz |
Make ServerImpl a general class, not singleton
Diffstat (limited to 'src/buildtool/execution_api/execution_service/server_implementation.cpp')
-rw-r--r-- | src/buildtool/execution_api/execution_service/server_implementation.cpp | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/buildtool/execution_api/execution_service/server_implementation.cpp b/src/buildtool/execution_api/execution_service/server_implementation.cpp index 63322451..73734840 100644 --- a/src/buildtool/execution_api/execution_service/server_implementation.cpp +++ b/src/buildtool/execution_api/execution_service/server_implementation.cpp @@ -53,6 +53,34 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool { } } // namespace +auto ServerImpl::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<ServerImpl> { + ServerImpl 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 ServerImpl::Run(StorageConfig const& storage_config, Storage const& storage, ApiBundle const& apis, @@ -129,24 +157,3 @@ auto ServerImpl::Run(StorageConfig const& storage_config, server->Wait(); return true; } - -[[nodiscard]] auto ServerImpl::SetInfoFile(std::string const& x) noexcept - -> bool { - Instance().info_file_ = x; - return true; -} - -[[nodiscard]] auto ServerImpl::SetPidFile(std::string const& x) noexcept - -> bool { - Instance().pid_file_ = x; - return true; -} - -[[nodiscard]] auto ServerImpl::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; -} |