1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

node, hook: remove parse_cli() functions

This commit is contained in:
Steffen Vogel 2018-08-07 18:28:55 +02:00
parent f623a7ecfb
commit a8bda29430
8 changed files with 92 additions and 142 deletions

View file

@ -64,7 +64,6 @@ struct hook {
int hook_init(struct hook *h, struct hook_type *vt, struct path *p, struct node *n);
int hook_parse(struct hook *h, json_t *cfg);
int hook_parse_cli(struct hook *h, int argc, char *argv[]);
int hook_destroy(struct hook *h);

View file

@ -60,7 +60,6 @@ struct hook_type {
size_t size; /**< Size of allocation for struct hook::_vd */
int (*parse)(struct hook *h, json_t *cfg);
int (*parse_cli)(struct hook *h, int argc, char *argv[]);
int (*init)(struct hook *h); /**< Called before path is started to parseHOOK_DESTROYs. */
int (*destroy)(struct hook *h); /**< Called after path has been stopped to release memory allocated by HOOK_INIT */

View file

@ -91,9 +91,6 @@ int node_init(struct node *n, struct node_type *vt);
*/
int node_parse(struct node *n, json_t *cfg, const char *name);
/** Parse settings of a node from cmdline. */
int node_parse_cli(struct node *n, int argc, char *argv[]);
/** Parse an array or single node and checks if they exist in the "nodes" section.
*
* Examples:

View file

@ -107,9 +107,6 @@ struct node_type {
*/
int (*check)(struct node *n);
/** Parse node from command line arguments. */
int (*parse_cli)(struct node *n, int argc, char *argv[]);
/** Returns a string with a textual represenation of this node.
*
* @param n A pointer to the node object.

View file

@ -84,28 +84,6 @@ int hook_parse(struct hook *h, json_t *cfg)
return 0;
}
int hook_parse_cli(struct hook *h, int argc, char *argv[])
{
int ret;
if (h->_vt->parse_cli) {
ret = h->_vt->parse_cli(h, argc, argv);
if (ret)
return ret;
h->state = STATE_PARSED;
}
else {
h->cfg = json_load_cli(argc, argv);
if (!h->cfg)
return -1;
ret = hook_parse(h, h->cfg);
}
return ret;
}
int hook_destroy(struct hook *h)
{
int ret;

View file

@ -270,32 +270,6 @@ int node_parse(struct node *n, json_t *json, const char *name)
return ret;
}
int node_parse_cli(struct node *n, int argc, char *argv[])
{
int ret;
assert(node_type(n));
if (node_type(n)->parse_cli) {
n->name = strdup("cli");
ret = node_type(n)->parse_cli(n, argc, argv);
if (ret)
return ret;
n->state = STATE_PARSED;
}
else {
n->cfg = json_load_cli(argc, argv);
if (!n->cfg)
return -1;
ret = node_parse(n, n->cfg, "cli");
}
return ret;
}
int node_check(struct node *n)
{
int ret;

View file

@ -100,82 +100,6 @@ int signal_generator_parse(struct node *n, json_t *cfg)
return 0;
}
int signal_generator_parse_cli(struct node *n, int argc, char *argv[])
{
char *type;
struct signal_generator *s = (struct signal_generator *) n->_vd;
/* Default values */
s->rate = 10;
s->frequency = 1;
s->amplitude = 1;
s->stddev = 0.02;
s->type = SIGNAL_GENERATOR_TYPE_MIXED;
s->rt = 1;
s->values = 1;
s->limit = -1;
s->offset = 0;
s->monitor_missed = 1;
/* Parse optional command line arguments */
char c, *endptr;
while ((c = getopt(argc, argv, "v:r:f:l:a:D:no:m")) != -1) {
switch (c) {
case 'n':
s->rt = 0;
break;
case 'l':
s->limit = strtoul(optarg, &endptr, 10);
goto check;
case 'v':
s->values = strtoul(optarg, &endptr, 10);
goto check;
case 'r':
s->rate = strtof(optarg, &endptr);
goto check;
case 'o':
s->offset = strtof(optarg, &endptr);
goto check;
case 'f':
s->frequency = strtof(optarg, &endptr);
goto check;
case 'a':
s->amplitude = strtof(optarg, &endptr);
goto check;
case 'D':
s->stddev = strtof(optarg, &endptr);
goto check;
case 'm':
s->monitor_missed = 0;
goto check;
case '?':
break;
}
continue;
check: if (optarg == endptr)
warn("Failed to parse parse option argument '-%c %s'", c, optarg);
}
if (argc != optind + 1)
return -1;
type = argv[optind];
int t = signal_generator_lookup_type(type);
if (t == -1)
error("Invalid signal type: %s", type);
s->type = t;
/* We know the expected number of values. */
n->samplelen = s->values;
return 0;
}
int signal_generator_start(struct node *n)
{
int ret;
@ -319,15 +243,14 @@ static struct plugin p = {
.description = "Signal generator",
.type = PLUGIN_TYPE_NODE,
.node = {
.vectorize = 1,
.size = sizeof(struct signal_generator),
.parse = signal_generator_parse,
.parse_cli = signal_generator_parse_cli,
.print = signal_generator_print,
.start = signal_generator_start,
.stop = signal_generator_stop,
.read = signal_generator_read,
.fd = signal_generator_fd
.vectorize = 1,
.size = sizeof(struct signal_generator),
.parse = signal_generator_parse,
.print = signal_generator_print,
.start = signal_generator_start,
.stop = signal_generator_stop,
.read = signal_generator_read,
.fd = signal_generator_fd
}
};

View file

@ -45,6 +45,84 @@ struct io io;
struct pool q;
struct sample *t;
json_t * parse_cli(int argc, char *argv[])
{
/* Default values */
double rate = 10;
double frequency = 1;
double amplitude = 1;
double stddev = 0.02;
double offset = 0;
char *type;
int rt = 1;
int values = 1;
int limit = -1;
/* Parse optional command line arguments */
char c, *endptr;
while ((c = getopt(argc, argv, "v:r:f:l:a:D:no:")) != -1) {
switch (c) {
case 'n':
rt = 0;
break;
case 'l':
limit = strtoul(optarg, &endptr, 10);
goto check;
case 'v':
values = strtoul(optarg, &endptr, 10);
goto check;
case 'r':
rate = strtof(optarg, &endptr);
goto check;
case 'o':
offset = strtof(optarg, &endptr);
goto check;
case 'f':
frequency = strtof(optarg, &endptr);
goto check;
case 'a':
amplitude = strtof(optarg, &endptr);
goto check;
case 'D':
stddev = strtof(optarg, &endptr);
goto check;
case '?':
break;
}
continue;
check: if (optarg == endptr)
warn("Failed to parse parse option argument '-%c %s'", c, optarg);
}
if (argc != optind + 1)
return NULL;
type = argv[optind];
return json_pack("{ s: s, s: s, s: f, s: f, s: f, s: f, s: f, s: b, s: i, s: i }",
"type", "signal",
"signal", type,
"rate", rate,
"frequency", frequency,
"amplitude", amplitude,
"stddev", stddev,
"offset", offset,
"realtime", rt,
"values", values,
"limit", limit
);
}
void usage()
{
std::cout << "Usage: villas-signal [OPTIONS] SIGNAL" << std::endl;
@ -150,8 +228,13 @@ int main(int argc, char *argv[])
ret = io_open(&io, NULL);
if (ret)
error("Failed to open output");
cfg = parse_cli(argc, argv);
if (!cfg) {
usage();
exit(EXIT_FAILURE);
}
ret = node_parse_cli(&n, argc, argv);
ret = node_parse(&n, cfg, "cli");
if (ret) {
usage();
exit(EXIT_FAILURE);