plugin: Multiple plugins can register a singl hook

Switch from having a single plugin to a list of plugins. If the hook is of
type single we will enforce that constraint on the number of registered
plugins when attempting to add.
This commit is contained in:
Christian Decker
2020-02-04 16:53:04 +01:00
committed by Rusty Russell
parent 9a2a09efd6
commit b25e195c2c
2 changed files with 54 additions and 27 deletions

View File

@@ -59,8 +59,9 @@ struct plugin_hook {
void (*response_cb)(void *arg, const char *buffer, const jsmntok_t *toks);
void (*serialize_payload)(void *src, struct json_stream *dest);
/* Which plugin has registered this hook? */
struct plugin *plugin;
/* Which plugins have registered this hook? This is a `tal_arr`
* initialized at creation. */
struct plugin **plugins;
};
AUTODATA_TYPE(hooks, struct plugin_hook);
@@ -107,7 +108,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
typesafe_cb_cast(void (*)(void *, struct json_stream *), \
void (*)(payload_type, struct json_stream *), \
serialize_payload), \
NULL, /* .plugin */ \
NULL, /* .plugins */ \
}; \
AUTODATA(hooks, &name##_hook_gen); \
PLUGIN_HOOK_CALL_DEF(name, payload_type, response_cb_arg_type);