-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmrhat_integration.cpp
More file actions
27 lines (21 loc) · 901 Bytes
/
mrhat_integration.cpp
File metadata and controls
27 lines (21 loc) · 901 Bytes
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
#include <httplib.h>
#include <fmt/format.h>
#include "mrhat_integration.hpp"
#include <iostream>
bool MrHatIntegration::signal_reset_on_halt() { return api_impl(true); }
bool MrHatIntegration::clear_reset_on_halt() { return api_impl(false); }
bool MrHatIntegration::api_impl(bool set) {
httplib::Client cli("localhost", port);
const auto endpoint = fmt::format("/api/register/{}/{}/{}", rst_action_reg,
rst_action_bit, set ? 1 : 0);
if (auto res = cli.Post(endpoint);
res && (res->status >= 200 && res->status < 300)) {
return true;
} else {
std::cerr << fmt::format("error sending reset on halt action to "
"http://localhost:{}{} status:{} code:{}\n",
port, endpoint, res ? res->status : -1,
static_cast<int>(res.error()));
return false;
}
}