From 366111c5c7b407fe0e944ee71de1c51137147805 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 10 Oct 2023 17:26:40 +0200 Subject: just-serve: Extend client and API for services Target and Configuration Co-authored-by: Alberto Sartori --- src/buildtool/serve_api/remote/serve_api.hpp | 64 ++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 12 deletions(-) (limited to 'src/buildtool/serve_api/remote/serve_api.hpp') diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp index a0d50ea9..48ba4098 100644 --- a/src/buildtool/serve_api/remote/serve_api.hpp +++ b/src/buildtool/serve_api/remote/serve_api.hpp @@ -21,37 +21,77 @@ #include "src/buildtool/common/remote/port.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" +#include "src/buildtool/serve_api/remote/config.hpp" +#include "src/buildtool/serve_api/remote/configuration_client.hpp" #include "src/buildtool/serve_api/remote/source_tree_client.hpp" +#include "src/buildtool/serve_api/remote/target_client.hpp" class ServeApi final { public: - using Ptr = std::unique_ptr; - - ServeApi(std::string const& host, Port port) noexcept; - ServeApi(ServeApi const&) = delete; - ServeApi(ServeApi&& other) noexcept; + ~ServeApi() = default; auto operator=(ServeApi const&) -> ServeApi& = delete; auto operator=(ServeApi&&) -> ServeApi& = delete; - ~ServeApi(); + [[nodiscard]] static auto Instance() noexcept -> ServeApi& { + static ServeApi instance = ServeApi::init(); + return instance; + } - [[nodiscard]] auto RetrieveTreeFromCommit(std::string const& commit, - std::string const& subdir = ".", - bool sync_tree = false) - -> std::optional; + [[nodiscard]] static auto RetrieveTreeFromCommit( + std::string const& commit, + std::string const& subdir = ".", + bool sync_tree = false) -> std::optional { + return Instance().stc_->ServeCommitTree(commit, subdir, sync_tree); + } - [[nodiscard]] auto RetrieveTreeFromArchive( + [[nodiscard]] static auto RetrieveTreeFromArchive( std::string const& content, std::string const& archive_type = "archive", std::string const& subdir = ".", std::optional const& resolve_symlinks = std::nullopt, - bool sync_tree = false) -> std::optional; + bool sync_tree = false) -> std::optional { + return Instance().stc_->ServeArchiveTree( + content, archive_type, subdir, resolve_symlinks, sync_tree); + } + + [[nodiscard]] static auto ServeTargetVariables( + std::string const& target_root_id, + std::string const& target_file, + std::string const& target) -> std::optional> { + return Instance().tc_->ServeTargetVariables( + target_root_id, target_file, target); + } + + [[nodiscard]] static auto ServeTarget(const TargetCacheKey& key) + -> std::optional> { + return Instance().tc_->ServeTarget(key); + } + + [[nodiscard]] static auto CheckServeRemoteExecution() -> bool { + return Instance().cc_->CheckServeRemoteExecution(); + } private: + ServeApi(std::string const& host, Port port) noexcept + : stc_{std::make_unique(host, port)}, + tc_{std::make_unique(host, port)}, + cc_{std::make_unique(host, port)} {} + + ServeApi(ServeApi&& other) noexcept = default; + + [[nodiscard]] static auto init() noexcept -> ServeApi { + auto sadd = RemoteServeConfig::RemoteAddress(); + return ServeApi{sadd->host, sadd->port}; + } + // source tree service client std::unique_ptr stc_; + // target service client + std::unique_ptr tc_; + // configuration service client + std::unique_ptr cc_; }; #endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_SERVE_API_HPP -- cgit v1.2.3