Add "documentation" field to node specification

Use it as node type help message
This commit is contained in:
Vftdan 2024-08-18 15:26:54 +02:00
parent 8b55223b9d
commit e2ea8fed1e
9 changed files with 28 additions and 2 deletions

View File

@ -33,6 +33,7 @@ struct graph_node_specification {
void (*destroy)(GraphNodeSpecification * self, GraphNode * target); void (*destroy)(GraphNodeSpecification * self, GraphNode * target);
void (*register_io)(GraphNodeSpecification * self, GraphNode * target, ProcessingState * state); void (*register_io)(GraphNodeSpecification * self, GraphNode * target, ProcessingState * state);
char *name; char *name;
char *documentation;
}; };
void graph_channel_init(GraphChannel * ch, GraphNode * start, size_t start_idx, GraphNode * end, size_t end_idx); void graph_channel_init(GraphChannel * ch, GraphNode * start, size_t start_idx, GraphNode * end, size_t end_idx);

4
main.c
View File

@ -65,9 +65,9 @@ main(int argc, char ** argv)
fprintf(stderr, "Unknown node type \"%s\"\n", optarg); fprintf(stderr, "Unknown node type \"%s\"\n", optarg);
return 1; return 1;
} }
const char* module_help = NULL; const char* module_help = spec->documentation;
if (module_help) { if (module_help) {
printf("Help for module \"%s\":\n", optarg); printf("Help for node type \"%s\":\n", optarg);
printf("%s\n", module_help); printf("%s\n", module_help);
} else { } else {
printf("No help provided for node type \"%s\"\n", optarg); printf("No help provided for node type \"%s\"\n", optarg);

View File

@ -139,6 +139,10 @@ GraphNodeSpecification nodespec_evdev = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = &register_io, .register_io = &register_io,
.name = "evdev", .name = "evdev",
.documentation = "Reads evdev events of the specified device\nDoes not accept events\nSends events on all connectors with major code, minor code, payload respectively set to evdev event type, code, value"
"\nOption 'namespace' (optional): set namespace for the generated events"
"\nOption 'file' (required): device file to read events from (like '/dev/input/eventN'), the process must have sufficient privileges to read the file"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -95,6 +95,9 @@ GraphNodeSpecification nodespec_getchar = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = &register_io, .register_io = &register_io,
.name = "getchar", .name = "getchar",
.documentation = "Converts stdin bytes to events\nDoes not accept events\nSends events on all connectors with major and minor codes (0, 1) and the read byte as payload"
"\nOption 'namespace' (optional): set namespace for the generated events"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -91,6 +91,10 @@ GraphNodeSpecification nodespec_modifiers = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = NULL, .register_io = NULL,
.name = "modifiers", .name = "modifiers",
.documentation = "Sets/unsets/toggles modifiers in an event\nAccepts events on any connector\nSends events on all connectors"
"\nOption 'operation' (required): the operation to apply to the event modifier set ('set'/'unset'/'toggle')"
"\nOption 'modifiers' (required): collection of integers --- the set of modifiers to operate on"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -94,6 +94,13 @@ GraphNodeSpecification nodespec_modify_predicate = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = NULL, .register_io = NULL,
.name = "modify_predicate", .name = "modify_predicate",
.documentation = "Changes 'enabled' and 'inverted' flags of a predicate\nAccepts events on any connector\nDoes not send events"
"\nOption 'target' (required): the predicate to modify"
"\nOption 'enable_on' (optional): the predicate, satisfying events of which set 'enabled' flag of the target predicate to 1"
"\nOption 'disable_on' (optional): the predicate, satisfying events of which set 'enabled' flag of the target predicate to 0"
"\nOption 'invert_on' (optional): the predicate, satisfying events of which set 'inverted' flag of the target predicate to 1"
"\nOption 'uninvert_on' (optional): the predicate, satisfying events of which set 'inverted' flag of the target predicate to 0"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -60,6 +60,8 @@ GraphNodeSpecification nodespec_print = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = NULL, .register_io = NULL,
.name = "print", .name = "print",
.documentation = "Prints received events\nAccepts events on any connector\nDoes not send events"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -88,6 +88,9 @@ GraphNodeSpecification nodespec_router = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = NULL, .register_io = NULL,
.name = "router", .name = "router",
.documentation = "Conditionally copies the received events\nAccepts events on any connector\nSends events on all connectors with configured predicates"
"\nOption 'predicates' (required): collection of predicates in the order of output connectors from zero, a received event is copied to the given connector iff it satisfies the predicate"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)

View File

@ -53,6 +53,8 @@ GraphNodeSpecification nodespec_tee = (GraphNodeSpecification) {
.destroy = &destroy, .destroy = &destroy,
.register_io = NULL, .register_io = NULL,
.name = "tee", .name = "tee",
.documentation = "Copies the received events\nAccepts events on any connector\nSends events on all connectors"
,
}; };
MODULE_CONSTRUCTOR(init) MODULE_CONSTRUCTOR(init)