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/src/node.c

128 lines
3 KiB
C
Raw Normal View History

/** Main routine.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2015-06-02 21:53:04 +02:00
*********************************************************************************/
#include <stdlib.h>
#include <unistd.h>
2015-08-22 17:42:38 +02:00
2016-06-14 01:19:17 +02:00
#include <villas/utils.h>
#include <villas/super_node.h>
#include <villas/memory.h>
2016-06-14 01:19:17 +02:00
#include <villas/node.h>
2017-03-17 01:08:48 -03:00
#include <villas/path.h>
2017-02-18 10:58:17 -05:00
#include <villas/api.h>
#include <villas/web.h>
#include <villas/timing.h>
2017-03-03 20:21:33 -04:00
#include <villas/plugin.h>
2016-06-14 01:19:17 +02:00
#include <villas/kernel/kernel.h>
#include <villas/kernel/rt.h>
2016-11-20 13:11:37 -05:00
#include <villas/hook.h>
#include <villas/stats.h>
2017-02-18 10:58:17 -05:00
#ifdef ENABLE_OPAL_ASYNC
2016-11-20 02:45:39 -05:00
#include <villas/nodes/opal.h>
#endif
struct super_node sn;
2017-03-06 19:09:44 -04:00
static void quit(int signal, siginfo_t *sinfo, void *ctx)
{
super_node_stop(&sn);
super_node_destroy(&sn);
2015-08-07 01:11:43 +02:00
info(GRN("Goodbye!"));
2015-03-21 18:03:55 +01:00
_exit(EXIT_SUCCESS);
}
2016-10-22 20:37:02 -04:00
static void usage()
{
printf("Usage: villas-node [CONFIG]\n");
2017-02-18 10:58:17 -05:00
printf(" CONFIG is the path to an optional configuration file\n");
printf(" if omitted, VILLASnode will start without a configuration\n");
printf(" and wait for provisioning over the web interface.\n\n");
#ifdef ENABLE_OPAL_ASYNC
printf("Usage: villas-node OPAL_ASYNC_SHMEM_NAME OPAL_ASYNC_SHMEM_SIZE OPAL_PRINT_SHMEM_NAME\n");
printf(" This type of invocation is used by OPAL-RT Asynchronous processes.\n");
printf(" See in the RT-LAB User Guide for more information.\n\n");
#endif
printf("Supported node types:\n");
2017-03-03 20:21:33 -04:00
plugin_dump(PLUGIN_TYPE_NODE);
2015-08-22 17:42:38 +02:00
printf("\n");
2016-06-08 22:38:21 +02:00
printf("Supported hooks:\n");
2017-03-03 20:21:33 -04:00
plugin_dump(PLUGIN_TYPE_HOOK);
2016-06-08 22:38:21 +02:00
printf("\n");
2017-02-18 10:58:17 -05:00
printf("Supported API commands:\n");
2017-03-03 20:21:33 -04:00
plugin_dump(PLUGIN_TYPE_API);
2017-02-18 10:58:17 -05:00
printf("\n");
print_copyright();
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
/* Check arguments */
#ifdef ENABLE_OPAL_ASYNC
2017-02-18 10:58:17 -05:00
if (argc != 4)
usage(argv[0]);
char *uri = "opal-shmem.conf";
#else
if (argc == 2) {
if (!strcmp(argv[1], "-h") ||
!strcmp(argv[1], "--help"))
usage();
}
else if (argc > 2)
usage();
2017-02-18 10:58:17 -05:00
#endif
2015-08-07 01:11:43 +02:00
super_node_init(&sn);
2016-06-08 23:21:42 +02:00
info("This is VILLASnode %s (built on %s, %s)", BLD(YEL(VERSION)),
2015-09-17 00:58:04 +02:00
BLD(MAG(__DATE__)), BLD(MAG(__TIME__)));
2015-09-17 00:55:20 +02:00
/* Checks system requirements*/
if (kernel_has_version(KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN))
2015-09-17 00:55:20 +02:00
error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN);
2017-03-06 19:08:45 -04:00
signals_init(quit);
super_node_parse_cli(&sn, argc, argv);
super_node_check(&sn);
super_node_start(&sn);
if (sn.stats > 0)
stats_print_header();
2015-08-07 01:11:43 +02:00
2017-02-18 10:58:17 -05:00
struct timespec now, last = time_now();
/* Run! Until signal handler is invoked */
while (1) {
now = time_now();
if (sn.stats > 0 && time_delta(&last, &now) > sn.stats) {
for (size_t i = 0; i < list_length(&sn.paths); i++) {
struct path *p = list_at(&sn.paths, i);
for (size_t j = 0; j < list_length(&p->hooks); j++) {
struct hook *h = list_at(&p->hooks, j);
hook_run(h, HOOK_PERIODIC, NULL, 0);
}
2017-02-18 10:58:17 -05:00
}
last = time_now();
2015-10-14 14:52:29 +02:00
}
2017-02-18 10:58:17 -05:00
web_service(&sn.web); /** @todo Maybe we should move this to another thread */
}
return 0;
}