parent
9c40400d26
commit
427aab95ea
@ -0,0 +1,52 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdexcept": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
#ifndef JSON_UTILS_H
|
||||
#define JSON_UTILS_H
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
JsonObject getNode(String name, JsonArray nodes);
|
||||
JsonObject getContainer(int id, JsonArray containers);
|
||||
#include <json/retrieve.h>
|
||||
//JsonObject getNode(String name, JsonArray nodes);
|
||||
Node getNode(String name);
|
||||
Container getContainer(int id, String node);
|
||||
VM getVM(int id, String node);
|
||||
|
||||
#endif /* JSON_UTILS_H */
|
||||
|
||||
@ -1,27 +1,52 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <json/utils.h>
|
||||
#include <utils.h>
|
||||
#include <stdexcept>
|
||||
|
||||
/**
|
||||
Get a specific node from an array of nodes
|
||||
*/
|
||||
JsonObject getNode(String name, JsonArray nodes) {
|
||||
for (JsonObject node : nodes) {
|
||||
if (node["node"] == name) {
|
||||
return node;
|
||||
Node getNode(String name)
|
||||
{
|
||||
int numNodes;
|
||||
|
||||
Node *nodes = getNodeInfo(&numNodes);
|
||||
for (int i = 0; i < numNodes; i++)
|
||||
{
|
||||
if (nodes[i].name == name)
|
||||
{
|
||||
return nodes[i];
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error("Can't find the requested node in the array");
|
||||
}
|
||||
|
||||
Container getContainer(int id, String node)
|
||||
{
|
||||
|
||||
int numContainers;
|
||||
Container *containers = getContainerInfo(&numContainers, node);
|
||||
for (int i = 0; i < numContainers; i++)
|
||||
{
|
||||
if (containers[i].id == id)
|
||||
{
|
||||
return containers[i];
|
||||
}
|
||||
}
|
||||
displayError("Node not found!");
|
||||
|
||||
throw std::runtime_error("Can't find the requested container in the array");
|
||||
}
|
||||
|
||||
JsonObject getContainer(int id, JsonArray containers) {
|
||||
for (JsonObject container : containers) {
|
||||
Serial.println(id);
|
||||
Serial.println(container["vmid"].as<int>());
|
||||
if (container["vmid"].as<int>() == id) {
|
||||
return container;
|
||||
VM getVM(int id, String node)
|
||||
{
|
||||
int numVMs;
|
||||
|
||||
VM *vms = getVMInfo(&numVMs, node);
|
||||
for (int i = 0; i < numVMs; i++)
|
||||
{
|
||||
if (vms[i].id == id)
|
||||
{
|
||||
return vms[i];
|
||||
}
|
||||
}
|
||||
displayError("Machine not found!");
|
||||
|
||||
throw std::runtime_error("Can't find the requested vm in the array");
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue