virthttp  0.0
libvirt http interface
depends.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 #include <rapidjson/document.h>
4 #include "json_utils.hpp"
5 #include "utils.hpp"
6 
12 
22 bool check_depends(const rapidjson::Value& depends_json, std::vector<DependsOutcome>& outcomes, JsonRes& json_res) noexcept;
23 
33 template <typename Hdl> void handle_depends(const rapidjson::Value& json_req, JsonRes& json_res, Hdl&& hdl) {
34  auto error = [&](auto... args) { return json_res.error(args...); };
35 
36  if (!json_req.IsArray())
37  return error(298);
38 
39  std::vector<DependsOutcome> outcomes{};
40  outcomes.reserve(json_req.Size());
41 
42  for (const auto& action : json_req.GetArray()) {
43  if (check_depends(action, outcomes, json_res))
44  outcomes.push_back(hdl(action));
45  }
46 }
DependsOutcome
Definition: depends.hpp:11
void error(int code)
Definition: json_utils.hpp:57
bool check_depends(const rapidjson::Value &depends_json, std::vector< DependsOutcome > &outcomes, JsonRes &json_res) noexcept
Definition: depends.cpp:4
Definition: json_utils.hpp:21
void handle_depends(const rapidjson::Value &json_req, JsonRes &json_res, Hdl &&hdl)
Definition: depends.hpp:33