17 constexpr
static std::array<std::string_view, 7> keys = {
"power_mgt",
"name",
"memory",
"max_memory",
"autostart",
"send_signal",
"send_keys"};
18 constexpr
static std::array<Hdl, 7> fcns = {
21 auto pm_message = [&](gsl::czstring<> name, gsl::czstring<> value) {
22 rapidjson::Value msg_val{};
24 msg_val.AddMember(rapidjson::StringRef(name), rapidjson::StringRef(value), json_res.GetAllocator());
25 json_res.message(msg_val);
29 constexpr
auto getShutdownFlag = getFlag<virt::enums::domain::ShutdownFlag>;
31 const rapidjson::Value* json_flag =
nullptr;
32 gsl::czstring<> pm_req{};
35 pm_req = val.GetString();
36 }
else if (val.IsObject()) {
37 auto it_req = val.FindMember(
"request");
38 auto it_flags = val.FindMember(
"type");
39 if (it_req == val.MemberEnd())
41 if (it_flags != val.MemberEnd())
42 json_flag = &it_flags->value;
43 pm_req = it_req->value.GetString();
50 const auto pm_hdl = [&](gsl::czstring<> req_tag,
auto flag_ti,
auto mem_fcn,
int errc, gsl::czstring<> pm_msg,
auto prereqs) {
51 using Flag =
typename decltype(flag_ti)::type;
52 return [=, &json_flag, &json_res]() {
53 const auto mem_fcn_passthru = [=](
auto... args) constexpr {
return mem_fcn(args...); };
54 const auto local_error = [&] {
59 if (pm_req == std::string_view{req_tag}) {
63 if constexpr (
test_sfinae([](
auto f) -> std::enable_if_t<!std::is_same_v<decltype(f),
Empty>> {},
Flag{})) {
64 constexpr
const auto getFlags = getCombinedFlags<Flag>;
65 const auto o_flagset = getFlags(*json_flag, json_res);
68 if (
const auto flagset = *o_flagset; !mem_fcn(flagset))
73 if constexpr (
test_sfinae([](
auto f) { f(); }, mem_fcn_passthru)) {
79 return pm_message(req_tag, pm_msg);
84 constexpr
auto no_flags = ti<Empty>;
86 pm_hdl(
"shutdown", ti<virt::enums::domain::ShutdownFlag>,
PM_LIFT(dom.shutdown), 200,
"Domain is being shutdown",
88 pm_hdl(
"destroy", ti<virt::enums::domain::DestroyFlag>,
PM_LIFT(dom.destroy), 209,
"Domain destroyed",
89 PM_PREREQ(
if (!dom.isActive())
return error(210);)),
90 pm_hdl(
"start", ti<virt::enums::domain::CreateFlag>,
PM_LIFT(dom.create), 202,
"Domain started",
91 PM_PREREQ(
if (dom.isActive())
return error(203);)),
92 pm_hdl(
"reboot", ti<virt::enums::domain::ShutdownFlag>,
PM_LIFT(dom.reboot), 213,
"Domain is being rebooted",
94 pm_hdl(
"reset", no_flags,
PM_LIFT(dom.reset), 214,
"Domain was reset",
PM_PREREQ(
if (!dom.isActive())
return error(210);)),
95 pm_hdl(
"suspend", no_flags,
PM_LIFT(dom.suspend), 215,
"Domain suspended",
97 pm_hdl(
"resume", no_flags,
PM_LIFT(dom.resume), 212,
"Domain resumed",
99 [&]() {
return error(300); });
105 if (!dom.rename(val.GetString()))
113 if (!dom.setMemory(val.GetInt()))
121 if (!dom.setMaxMemory(val.GetInt()))
129 if (!dom.setAutoStart(val.GetBool()))
135 val, json_res, [&](
auto... args) {
return dom.sendProcessSignal(args...); },
WArg<JTag::Int64>{
"pid"},
144 const auto keycodeset_opt = extract_param<JTag::Enum, JTag::None, virt::enums::domain::KeycodeSet>(val,
"keycode_set", json_res);
147 const auto keycodeset = *keycodeset_opt;
149 const auto holdtime_opt = extract_param<JTag::Uint32>(val,
"hold_time", json_res);
152 const auto holdtime = *holdtime_opt;
154 const auto keys_opt = extract_param<JTag::Array, JTag::Uint32>(val,
"keys", json_res);
157 const auto keys = *keys_opt;
161 static_assert(keys.size() == fcns.size());
DependsOutcome
Definition: depends.hpp:11
#define PM_PREREQ(...)
Definition: actions_table.hpp:14
Definition: domain_actions_table.hpp:11
auto wrap_fcn(const rapidjson::Value &val, JsonRes &json_res, Fcn fcn, Args...args) noexcept
Definition: json2virt.hpp:186
Definition: utility.hpp:55
static constexpr auto RUNNING
Definition: State.hpp:31
Definition: json2virt.hpp:134
Logger logger
Definition: logger.hpp:58
void error(Ts...msg)
Definition: logger.hpp:25
#define PM_LIFT(mem_fn)
Definition: actions_table.hpp:13
class ErrorMessages error_messages
Definition: json_utils.hpp:21
constexpr auto action_scope
Definition: actions_table.hpp:51
constexpr auto test_sfinae(Lambda lambda, Ts &&...) -> decltype(lambda(std::declval< Ts >()...), bool
Definition: utility.hpp:37
static constexpr auto PAUSED
Definition: State.hpp:33
Flag
Definition: Decls.hpp:68
Definition: Domain.hpp:96
Definition: utility.hpp:27
Definition: actions_table.hpp:60
DomainActionsTable domain_actions_table
DependsOutcome(*)(const rapidjson::Value &val, JsonRes &json_res, virt::Domain &dom) DomainActionsHdl
Definition: domain_actions_table.hpp:10