From 7cda24509b58edaeb80c85d4942e9752f08d55b6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 5 May 2020 10:42:46 +0930 Subject: [PATCH] lightningd: plugins_any_in_state and plugins_all_in_state helpers. Signed-off-by: Rusty Russell --- lightningd/plugin.c | 22 ++++++++++++++++++++++ lightningd/plugin.h | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 789a0632e..d3c9aaf13 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -973,6 +973,28 @@ bool plugin_parse_getmanifest_response(const char *buffer, return true; } +bool plugins_any_in_state(const struct plugins *plugins, enum plugin_state state) +{ + const struct plugin *p; + + list_for_each(&plugins->plugins, p, list) { + if (p->plugin_state == state) + return true; + } + return false; +} + +bool plugins_all_in_state(const struct plugins *plugins, enum plugin_state state) +{ + const struct plugin *p; + + list_for_each(&plugins->plugins, p, list) { + if (p->plugin_state != state) + return false; + } + return true; +} + /** * Callback for the plugin_manifest request. */ diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 4120f91ee..7bd687a5f 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -208,6 +208,16 @@ struct plugin *find_plugin_for_command(struct lightningd *ld, */ void plugins_config(struct plugins *plugins); +/** + * Are any plugins at this state still? + */ +bool plugins_any_in_state(const struct plugins *plugins, enum plugin_state state); + +/** + * Are all plugins at this state? + */ +bool plugins_all_in_state(const struct plugins *plugins, enum plugin_state state); + /** * Read and treat (populate options, methods, ...) the `getmanifest` response. */