aboutsummaryrefslogtreecommitdiff
path: root/src/zen/zenserviceclient.h
blob: 4e0f1398248a7a2c400645e6627ba1752444c84d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/logging/sink.h>
#include <zenhttp/httpclient.h>
#include <zenutil/sessionsclient.h>

#include <memory>
#include <string>

namespace zen {

/// RAII wrapper that combines host resolution, HTTP client creation, and session lifecycle.
/// On construction, resolves the host, creates an HttpClient, and announces a session.
/// On destruction, removes the session (best-effort).
class ZenServiceClient
{
public:
	struct Options
	{
		std::string		   HostSpec;	  // Raw host spec (empty = auto-resolve)
		std::string		   CommandName;	  // e.g. "info", "gc" — used as session Mode
		HttpClientSettings HttpSettings;  // Forwarded to HttpClient
	};

	explicit ZenServiceClient(Options Opts);
	~ZenServiceClient();

	ZenServiceClient(const ZenServiceClient&) = delete;
	ZenServiceClient& operator=(const ZenServiceClient&) = delete;

	HttpClient&		   Http() { return m_Http; }
	const std::string& HostSpec() const { return m_HostSpec; }

	/// True if the resolved host spec targets a Unix domain socket
	/// (i.e. `unix:///...`). Useful for command paths that don't make
	/// sense over a unix transport (browser launches, WebSocket dialing
	/// without UnixSocketPath plumbing, etc.).
	bool IsUnixSocket() const;

private:
	std::string							   m_HostSpec;
	HttpClient							   m_Http;
	std::unique_ptr<SessionsServiceClient> m_Sessions;
	logging::SinkPtr					   m_LogSink;
};

}  // namespace zen