From b6a1735929bf99f6619eea0d66fd57502ad0c2f9 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 19 Sep 2018 22:19:51 +0200 Subject: [PATCH] plugin: Basic scaffolding for the plugin subsystem --- lightningd/Makefile | 1 + lightningd/plugin.c | 35 +++++++++++++++++++++++++++++++++++ lightningd/plugin.h | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lightningd/plugin.c create mode 100644 lightningd/plugin.h diff --git a/lightningd/Makefile b/lightningd/Makefile index 8ff4cdd91..a3fdfa09d 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -78,6 +78,7 @@ LIGHTNINGD_SRC := \ lightningd/peer_control.c \ lightningd/peer_htlcs.c \ lightningd/ping.c \ + lightningd/plugin.c \ lightningd/subd.c \ lightningd/watch.c diff --git a/lightningd/plugin.c b/lightningd/plugin.c new file mode 100644 index 000000000..f7c8f95f2 --- /dev/null +++ b/lightningd/plugin.c @@ -0,0 +1,35 @@ +#include "lightningd/plugin.h" + +#include +#include + +struct plugin { + int stdin, stdout; + pid_t pid; + char *cmd; +}; + +struct plugins { + struct plugin **plugins; +}; + +struct plugins *plugins_new(const tal_t *ctx){ + struct plugins *p; + p = tal(ctx, struct plugins); + p->plugins = tal_arr(p, struct plugin *, 0); + return p; +} + +void plugin_register(struct plugins *plugins, const char* path TAKES) +{ + struct plugin *p; + size_t n = tal_count(plugins->plugins); + tal_resize(&plugins->plugins, n+1); + p = tal(plugins, struct plugin); + plugins->plugins[n] = p; + p->cmd = tal_strdup(p, path); +} + +void plugins_init(struct plugins *plugins) +{ +} diff --git a/lightningd/plugin.h b/lightningd/plugin.h new file mode 100644 index 000000000..60bf3da67 --- /dev/null +++ b/lightningd/plugin.h @@ -0,0 +1,38 @@ +#ifndef LIGHTNING_LIGHTNINGD_PLUGIN_H +#define LIGHTNING_LIGHTNINGD_PLUGIN_H +#include "config.h" +#include +#include + +/** + * A collection of plugins, and some associated information. + * + * Mainly used as root context for calls in the plugin subsystem. + */ +struct plugins; + +/** + * Create a new plugins context. + */ +struct plugins *plugins_new(const tal_t *ctx); + +/** + * Initialize the registered plugins. + * + * Initialization includes spinning up the plugins, reading their + * manifest, and registering the JSON-RPC passthrough and command line + * arguments. In order to read the getmanifest reply from the plugins + * we spin up our own io_loop that exits once all plugins have + * responded. + */ +void plugins_init(struct plugins *plugins); + +/** + * Register a plugin for initialization and execution. + * + * @param plugins: Plugin context + * @param path: The path of the executable for this plugin + */ +void plugin_register(struct plugins *plugins, const char* path TAKES); + +#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */