1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/api/node_request.hpp

71 lines
1.8 KiB
C++
Raw Normal View History

2020-08-25 20:27:26 +02:00
/** API Request for nodes.
2020-08-25 20:22:19 +02:00
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
2020-08-25 20:27:26 +02:00
#include <uuid/uuid.h>
2020-08-25 20:22:19 +02:00
#include <villas/api/request.hpp>
2020-08-25 20:27:26 +02:00
/* Forward declarations */
2020-08-25 21:00:52 +02:00
struct vnode;
2020-08-25 20:27:26 +02:00
namespace villas {
namespace node {
namespace api {
2020-08-25 20:22:19 +02:00
class NodeRequest : public Request {
public:
2020-08-25 20:27:26 +02:00
using Request::Request;
2020-08-25 21:00:52 +02:00
struct vnode *node;
2020-08-25 20:22:19 +02:00
2020-08-25 20:27:26 +02:00
virtual void
prepare()
{
int ret;
auto *nodes = session->getSuperNode()->getNodes();
uuid_t uuid;
ret = uuid_parse(matches[1].c_str(), uuid);
2020-08-25 20:27:26 +02:00
if (ret) {
node = vlist_lookup_name<struct vnode>(nodes, matches[1]);
2020-08-25 20:27:26 +02:00
if (!node)
2020-09-30 16:11:13 +02:00
throw BadRequest("Unknown node", "{ s: s }",
"node", matches[1].c_str()
2020-09-30 16:11:13 +02:00
);
2020-08-25 20:27:26 +02:00
}
else {
2020-08-25 21:00:52 +02:00
node = vlist_lookup_uuid<struct vnode>(nodes, uuid);
2020-08-25 20:27:26 +02:00
if (!node)
2020-09-30 16:11:13 +02:00
throw BadRequest("No node found with with matching UUID", "{ s: s }",
"uuid", matches[1].c_str()
2020-09-30 16:11:13 +02:00
);
2020-08-25 20:27:26 +02:00
}
}
2020-08-25 20:22:19 +02:00
};
2020-08-25 20:27:26 +02:00
} /* namespace api */
} /* namespace node */
2020-09-30 16:11:13 +02:00
} /* namespace villas */