Add "tee" node type
This commit is contained in:
parent
deea29898a
commit
9f876162e5
2
Makefile
2
Makefile
|
@ -12,7 +12,7 @@ CPPFLAGS += $(shell pkg-config --cflags $(DEPS))
|
|||
LDLIBS += $(shell pkg-config --libs $(DEPS))
|
||||
INTERP ?=
|
||||
MAIN = main
|
||||
OBJS = main.o events.o processing.o graph.o config.o hash_table.o module_registry.o nodes/getchar.o nodes/print.o nodes/evdev.o
|
||||
OBJS = main.o events.o processing.o graph.o config.o hash_table.o module_registry.o nodes/getchar.o nodes/print.o nodes/evdev.o nodes/tee.o
|
||||
|
||||
all: $(MAIN)
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#include "../graph.h"
|
||||
#include "../module_registry.h"
|
||||
|
||||
static bool
|
||||
handle_event(EventPositionBase * self, EventNode * event)
|
||||
{
|
||||
GraphNode *node = DOWNCAST(GraphNode, EventPositionBase, self);
|
||||
size_t count = node->outputs.length;
|
||||
if (!count) {
|
||||
event_destroy(event);
|
||||
return true;
|
||||
}
|
||||
if (count > 1) {
|
||||
count = event_replicate(event, count - 1) + 1;
|
||||
}
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
event->position = &node->outputs.elements[i]->as_EventPositionBase;
|
||||
event = event->next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static GraphNode *
|
||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config)
|
||||
{
|
||||
(void) config;
|
||||
GraphNode * node = T_ALLOC(1, GraphNode);
|
||||
if (!node) {
|
||||
return node;
|
||||
}
|
||||
*node = (GraphNode) {
|
||||
.as_EventPositionBase = {
|
||||
.handle_event = &handle_event,
|
||||
.waiting_new_event = false,
|
||||
},
|
||||
.specification = spec,
|
||||
.inputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||
.outputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
static void destroy
|
||||
(GraphNodeSpecification * self, GraphNode * target)
|
||||
{
|
||||
(void) self;
|
||||
free(target);
|
||||
}
|
||||
|
||||
GraphNodeSpecification nodespec_tee = (GraphNodeSpecification) {
|
||||
.create = &create,
|
||||
.destroy = &destroy,
|
||||
.register_io = NULL,
|
||||
.name = "tee",
|
||||
};
|
||||
|
||||
MODULE_CONSTRUCTOR(init)
|
||||
{
|
||||
register_graph_node_specification(&nodespec_tee);
|
||||
}
|
Loading…
Reference in New Issue