mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added missing web and api source files
This commit is contained in:
parent
71bb3fb4d8
commit
056cbbfe89
6 changed files with 151 additions and 1 deletions
|
@ -18,8 +18,9 @@ LIB_LDFLAGS = -shared
|
|||
LIB_LDLIBS = $(LDLIBS) -ldl -lrt -Wl,-soname,$(LIB_NAME).so.$(LIB_ABI_VERSION)
|
||||
|
||||
-include lib/hooks/Makefile.inc
|
||||
-include lib/apis/Makefile.inc
|
||||
-include lib/api/Makefile.inc
|
||||
-include lib/fpga/Makefile.inc
|
||||
-include lib/web/Makefile.inc
|
||||
|
||||
LIB_PKGS = openssl
|
||||
|
||||
|
|
1
lib/api/actions/Makefile.inc
Normal file
1
lib/api/actions/Makefile.inc
Normal file
|
@ -0,0 +1 @@
|
|||
LIB_SRCS += $(wildcard lib/api/actions/*.c)
|
45
lib/api/actions/capabiltities.c
Normal file
45
lib/api/actions/capabiltities.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/** The "capabiltities" API ressource.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
*********************************************************************************/
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
static int api_capabilities(struct api_action *h, json_t *args, json_t **resp, struct api_session *s)
|
||||
{
|
||||
json_t *json_hooks = json_array();
|
||||
json_t *json_apis = json_array();
|
||||
json_t *json_nodes = json_array();
|
||||
json_t *json_name;
|
||||
|
||||
for (size_t i = 0; i < list_length(&plugins); i++) {
|
||||
struct plugin *p = list_at(&plugins, i);
|
||||
|
||||
json_name = json_string(p->name);
|
||||
|
||||
switch (p->type) {
|
||||
case PLUGIN_TYPE_NODE: json_array_append_new(json_nodes, json_name); break;
|
||||
case PLUGIN_TYPE_HOOK: json_array_append_new(json_hooks, json_name); break;
|
||||
case PLUGIN_TYPE_API: json_array_append_new(json_apis, json_name); break;
|
||||
default: { }
|
||||
}
|
||||
}
|
||||
|
||||
*resp = json_pack("{ s: s, s: o, s: o, s: o }",
|
||||
"build", BUILDID,
|
||||
"hooks", json_hooks,
|
||||
"node-types", json_nodes,
|
||||
"apis", json_apis);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "capabilities",
|
||||
.description = "get capabiltities and details about this VILLASnode instance",
|
||||
.type = PLUGIN_TYPE_API,
|
||||
.api.cb = api_capabilities
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
29
lib/api/actions/config.c
Normal file
29
lib/api/actions/config.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/** The "config" API ressource.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
*********************************************************************************/
|
||||
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "api.h"
|
||||
#include "utils.h"
|
||||
#include "plugin.h"
|
||||
|
||||
static int api_config(struct api_action *h, json_t *args, json_t **resp, struct api_session *s)
|
||||
{
|
||||
config_setting_t *cfg_root = config_root_setting(&s->api->super_node->cfg);
|
||||
|
||||
*resp = cfg_root ? config_to_json(cfg_root) : json_object();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "config",
|
||||
.description = "retrieve current VILLASnode configuration",
|
||||
.type = PLUGIN_TYPE_API,
|
||||
.api.cb = api_config
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
51
lib/api/actions/nodes.c
Normal file
51
lib/api/actions/nodes.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/** The "nodes" API ressource.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
*********************************************************************************/
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "node.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "api.h"
|
||||
|
||||
extern struct list nodes;
|
||||
|
||||
static int api_nodes(struct api_action *r, json_t *args, json_t **resp, struct api_session *s)
|
||||
{
|
||||
json_t *json_nodes = json_array();
|
||||
|
||||
for (size_t i = 0; i < list_length(&s->api->super_node->nodes); i++) {
|
||||
struct node *n = list_at(&s->api->super_node->nodes, i);
|
||||
|
||||
json_t *json_node = json_pack("{ s: s, s: i, s: i, s: i, s: i }",
|
||||
"name", node_name_short(n),
|
||||
"state", n->state,
|
||||
"vectorize", n->vectorize,
|
||||
"affinity", n->affinity,
|
||||
"id", i
|
||||
);
|
||||
|
||||
/* Add all additional fields of node here.
|
||||
* This can be used for metadata */
|
||||
json_object_update(json_node, config_to_json(n->cfg));
|
||||
|
||||
json_array_append_new(json_nodes, json_node);
|
||||
}
|
||||
|
||||
*resp = json_nodes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "nodes",
|
||||
.description = "retrieve list of all known nodes",
|
||||
.type = PLUGIN_TYPE_API,
|
||||
.api.cb = api_nodes
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
23
lib/api/actions/reload.c
Normal file
23
lib/api/actions/reload.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/** The "restart" API ressource.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
*********************************************************************************/
|
||||
|
||||
#include "plugin.h"
|
||||
#include "api.h"
|
||||
|
||||
/** @todo not implemented yet */
|
||||
static int api_restart(struct api_action *h, json_t *args, json_t **resp, struct api_session *s)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct plugin p = {
|
||||
.name = "restart",
|
||||
.description = "restart VILLASnode with new configuration",
|
||||
.type = PLUGIN_TYPE_API,
|
||||
.api.cb = api_restart
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
Loading…
Add table
Reference in a new issue