2024-08-14 00:33:52 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "print.h"
|
2024-08-15 21:57:17 +03:00
|
|
|
#include "../module_registry.h"
|
2024-08-14 00:33:52 +03:00
|
|
|
|
|
|
|
static bool
|
|
|
|
handle_event(EventPositionBase * self, EventNode * event)
|
|
|
|
{
|
|
|
|
#define PRINT_FIELD(fmt, path) printf("%s = " fmt "\n", #path, data.path)
|
|
|
|
(void) self;
|
|
|
|
EventData data = event->data;
|
|
|
|
printf("Event from connector %ld:\n", event->input_index);
|
|
|
|
PRINT_FIELD("%d", code.ns);
|
2024-08-14 15:53:17 +03:00
|
|
|
PRINT_FIELD("%d", code.major);
|
|
|
|
PRINT_FIELD("%d", code.minor);
|
2024-08-14 00:33:52 +03:00
|
|
|
PRINT_FIELD("%d", ttl);
|
|
|
|
PRINT_FIELD("%d", priority);
|
|
|
|
PRINT_FIELD("%ld", payload);
|
|
|
|
printf("modifiers = ");
|
|
|
|
for (ssize_t i = data.modifiers.byte_length - 1; i >= 0; --i) {
|
|
|
|
printf("%02x", data.modifiers.bits[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
2024-08-14 14:47:55 +03:00
|
|
|
printf("time.absolute = %ld.%09ld\n", data.time.absolute.tv_sec, data.time.absolute.tv_nsec);
|
2024-08-14 00:33:52 +03:00
|
|
|
printf("---\n\n");
|
|
|
|
event_destroy(event);
|
|
|
|
return true;
|
|
|
|
#undef PRINT_FIELD
|
|
|
|
}
|
|
|
|
|
|
|
|
static GraphNode *
|
2024-08-17 12:02:26 +03:00
|
|
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
2024-08-14 00:33:52 +03:00
|
|
|
{
|
2024-08-14 23:23:21 +03:00
|
|
|
(void) config;
|
2024-08-17 12:02:26 +03:00
|
|
|
(void) env;
|
2024-08-15 17:53:02 +03:00
|
|
|
GraphNode * node = T_ALLOC(1, GraphNode);
|
2024-08-14 00:33:52 +03:00
|
|
|
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_print = (GraphNodeSpecification) {
|
|
|
|
.create = &create,
|
|
|
|
.destroy = &destroy,
|
|
|
|
.register_io = NULL,
|
|
|
|
.name = "print",
|
2024-08-18 16:26:54 +03:00
|
|
|
.documentation = "Prints received events\nAccepts events on any connector\nDoes not send events"
|
|
|
|
,
|
2024-08-14 00:33:52 +03:00
|
|
|
};
|
2024-08-15 21:57:17 +03:00
|
|
|
|
|
|
|
MODULE_CONSTRUCTOR(init)
|
|
|
|
{
|
|
|
|
register_graph_node_specification(&nodespec_print);
|
|
|
|
}
|