summaryrefslogtreecommitdiff
path: root/src/buildtool/serve_api/remote/serve_api.hpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-06-13 10:16:29 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-06-18 12:05:10 +0200
commitdc9a7b8499da9ce7a90546afecd048d0bfb31f38 (patch)
treeefc036d485bb8418ffbf77957be2d5f2252a9306 /src/buildtool/serve_api/remote/serve_api.hpp
parentd08e6f1af5a96818c9e7c2c9e0a6288470489822 (diff)
downloadjustbuild-dc9a7b8499da9ce7a90546afecd048d0bfb31f38.tar.gz
Make ServeApi a general class, not a singleton
...and adjust interfaces.
Diffstat (limited to 'src/buildtool/serve_api/remote/serve_api.hpp')
-rw-r--r--src/buildtool/serve_api/remote/serve_api.hpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp
index 98966e6a..510881cb 100644
--- a/src/buildtool/serve_api/remote/serve_api.hpp
+++ b/src/buildtool/serve_api/remote/serve_api.hpp
@@ -37,10 +37,8 @@ class ServeApi final {};
class ServeApi final {
public:
- [[nodiscard]] static auto Instance() noexcept -> ServeApi const& {
- static ServeApi instance = ServeApi::init();
- return instance;
- }
+ explicit ServeApi(ServerAddress const& address) noexcept
+ : stc_{address}, tc_{address}, cc_{address} {}
~ServeApi() noexcept = default;
ServeApi(ServeApi const&) = delete;
@@ -48,6 +46,15 @@ class ServeApi final {
auto operator=(ServeApi const&) -> ServeApi& = delete;
auto operator=(ServeApi&&) -> ServeApi& = delete;
+ [[nodiscard]] static auto Create(
+ RemoteServeConfig const& serve_config) noexcept
+ -> std::optional<ServeApi> {
+ if (auto address = serve_config.RemoteAddress()) {
+ return std::make_optional<ServeApi>(*address);
+ }
+ return std::nullopt;
+ }
+
[[nodiscard]] auto RetrieveTreeFromCommit(std::string const& commit,
std::string const& subdir = ".",
bool sync_tree = false)
@@ -130,14 +137,6 @@ class ServeApi final {
}
private:
- explicit ServeApi(ServerAddress const& address) noexcept
- : stc_{address}, tc_{address}, cc_{address} {}
-
- [[nodiscard]] static auto init() noexcept -> ServeApi {
- auto sadd = RemoteServeConfig::Instance().RemoteAddress();
- return ServeApi{*sadd};
- }
-
// source tree service client
SourceTreeClient const stc_;
// target service client