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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright Epic Games, Inc. All Rights Reserved.
#include "compute_cmd.h"
#if ZEN_WITH_COMPUTE_SERVICES
# include "zenserviceclient.h"
# include <zencore/compactbinary.h>
# include <zencore/logging.h>
# include <zenhttp/httpclient.h>
using namespace std::literals;
namespace zen {
//////////////////////////////////////////////////////////////////////////
// ComputeRecordStartSubCmd
ComputeRecordStartSubCmd::ComputeRecordStartSubCmd() : ZenSubCmdBase("record-start", "Start recording compute actions")
{
SubOptions().add_option("", "u", "hosturl", ZenCmdBase::kHostUrlHelp, cxxopts::value(m_HostName)->default_value(""), "<hosturl>");
}
void
ComputeRecordStartSubCmd::Run(const ZenCliOptions& GlobalOptions)
{
ZEN_UNUSED(GlobalOptions);
ZenServiceClient Service({.HostSpec = m_HostName, .CommandName = "record-start"});
HttpClient& Http = Service.Http();
if (HttpClient::Response Response = Http.Post("/compute/record/start"sv, HttpClient::KeyValueMap{}, HttpClient::KeyValueMap{}))
{
CbObject Obj = Response.AsObject();
std::string_view Path = Obj["path"sv].AsString();
ZEN_CONSOLE("recording started: " ZEN_BRIGHT_GREEN("{}"), Path);
}
else
{
Response.ThrowError("Failed to start recording");
}
}
//////////////////////////////////////////////////////////////////////////
// ComputeRecordStopSubCmd
ComputeRecordStopSubCmd::ComputeRecordStopSubCmd() : ZenSubCmdBase("record-stop", "Stop recording compute actions")
{
SubOptions().add_option("", "u", "hosturl", ZenCmdBase::kHostUrlHelp, cxxopts::value(m_HostName)->default_value(""), "<hosturl>");
}
void
ComputeRecordStopSubCmd::Run(const ZenCliOptions& GlobalOptions)
{
ZEN_UNUSED(GlobalOptions);
ZenServiceClient Service({.HostSpec = m_HostName, .CommandName = "record-stop"});
HttpClient& Http = Service.Http();
if (HttpClient::Response Response = Http.Post("/compute/record/stop"sv, HttpClient::KeyValueMap{}, HttpClient::KeyValueMap{}))
{
CbObject Obj = Response.AsObject();
std::string_view Path = Obj["path"sv].AsString();
ZEN_CONSOLE("recording stopped: " ZEN_BRIGHT_GREEN("{}"), Path);
}
else
{
Response.ThrowError("Failed to stop recording");
}
}
//////////////////////////////////////////////////////////////////////////
// ComputeCommand
ComputeCommand::ComputeCommand()
{
m_Options.add_options()("h,help", "Print help");
m_Options.add_option("__hidden__", "", "subcommand", "", cxxopts::value<std::string>(m_SubCommand)->default_value(""), "");
m_Options.parse_positional({"subcommand"});
AddSubCommand(m_RecordStartSubCmd);
AddSubCommand(m_RecordStopSubCmd);
}
ComputeCommand::~ComputeCommand() = default;
} // namespace zen
#endif // ZEN_WITH_COMPUTE_SERVICES
|