From e8537f4b5246ac61bdbc11602fc802a288198555 Mon Sep 17 00:00:00 2001 From: Tau Date: Thu, 8 Nov 2018 14:17:59 -0500 Subject: [PATCH] jvs/jvs-bus.c: Add JVS bus definitions --- jvs/jvs-bus.c | 30 ++++++++++++++++++++++++++++++ jvs/jvs-bus.h | 24 ++++++++++++++++++++++++ jvs/meson.build | 2 ++ 3 files changed, 56 insertions(+) create mode 100644 jvs/jvs-bus.c create mode 100644 jvs/jvs-bus.h diff --git a/jvs/jvs-bus.c b/jvs/jvs-bus.c new file mode 100644 index 0000000..8961b84 --- /dev/null +++ b/jvs/jvs-bus.c @@ -0,0 +1,30 @@ +#include +#include +#include + +#include "jvs/jvs-bus.h" + +void jvs_bus_transact( + struct jvs_node *head, + const void *bytes, + size_t nbytes, + struct iobuf *resp) +{ + struct jvs_node *node; + + assert(bytes != NULL); + assert(resp != NULL); + + for (node = head ; node != NULL ; node = node->next) { + node->transact(node, bytes, nbytes, resp); + } +} + +bool jvs_node_sense(struct jvs_node *node) +{ + if (node != NULL) { + return node->sense(node); + } else { + return false; + } +} diff --git a/jvs/jvs-bus.h b/jvs/jvs-bus.h new file mode 100644 index 0000000..820ba20 --- /dev/null +++ b/jvs/jvs-bus.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "hook/iobuf.h" + +struct jvs_node { + struct jvs_node *next; + void (*transact)( + struct jvs_node *node, + const void *bytes, + size_t nbytes, + struct iobuf *resp); + bool (*sense)(struct jvs_node *node); +}; + +void jvs_bus_transact( + struct jvs_node *head, + const void *bytes, + size_t nbytes, + struct iobuf *resp); + +bool jvs_node_sense(struct jvs_node *node); diff --git a/jvs/meson.build b/jvs/meson.build index a8854fe..f39045a 100644 --- a/jvs/meson.build +++ b/jvs/meson.build @@ -7,5 +7,7 @@ jvs_lib = static_library( capnhook.get_variable('hook_dep'), ], sources : [ + 'jvs-bus.c', + 'jvs-bus.h', ], )