2022-03-28 18:06:47 +02:00
|
|
|
/** The Universal Data-exchange API.
|
|
|
|
*
|
2022-12-14 17:41:58 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-28 18:06:47 +02:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-07-04 18:20:03 +02:00
|
|
|
* @license Apache 2.0
|
2022-03-28 18:06:47 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2022-12-14 17:39:50 +01:00
|
|
|
#include <villas/utils.hpp>
|
2022-03-28 18:06:47 +02:00
|
|
|
#include <villas/api/requests/universal.hpp>
|
|
|
|
#include <villas/api/response.hpp>
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
namespace api {
|
|
|
|
namespace universal {
|
|
|
|
|
|
|
|
class SignalsRequest : public UniversalRequest {
|
|
|
|
public:
|
|
|
|
using UniversalRequest::UniversalRequest;
|
|
|
|
|
|
|
|
virtual Response * execute()
|
|
|
|
{
|
|
|
|
if (method != Session::Method::GET)
|
|
|
|
throw InvalidMethod(this);
|
|
|
|
|
|
|
|
if (body != nullptr)
|
|
|
|
throw BadRequest("This endpoint does not accept any body data");
|
|
|
|
|
|
|
|
auto *json_sigs = json_array();
|
2022-12-14 17:39:50 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < MIN(api_node->getOutputSignals()->size(), api_node->write.channels.size()); i++) {
|
|
|
|
auto sig = api_node->getOutputSignals()->at(i);
|
|
|
|
auto ch = api_node->write.channels.at(i);
|
|
|
|
auto *json_sig = ch->toJson(sig);
|
2022-03-28 18:06:47 +02:00
|
|
|
|
|
|
|
json_array_append(json_sigs, json_sig);
|
|
|
|
}
|
|
|
|
|
2022-12-14 17:39:50 +01:00
|
|
|
for (size_t i = 0; i < MIN(api_node->getInputSignals()->size(), api_node->read.channels.size()); i++) {
|
|
|
|
auto sig = api_node->getInputSignals()->at(i);
|
|
|
|
auto ch = api_node->read.channels.at(i);
|
|
|
|
auto *json_sig = ch->toJson(sig);
|
2022-03-28 18:06:47 +02:00
|
|
|
|
|
|
|
json_array_append(json_sigs, json_sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new JsonResponse(session, HTTP_STATUS_OK, json_sigs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register API requests */
|
2022-12-14 17:39:50 +01:00
|
|
|
static char n[] = "universal/channels";
|
|
|
|
static char r[] = "/universal/(" RE_NODE_NAME ")/channels";
|
|
|
|
static char d[] = "get channels of universal data-exchange API node";
|
2022-03-28 18:06:47 +02:00
|
|
|
static RequestPlugin<SignalsRequest, n, r, d> p;
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace universal
|
|
|
|
} // namespace api
|
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|