Browse Source

plugin: Dispatch notifications to subscribed plugins

Signed-off-by: Christian Decker <decker.christian@gmail.com>
plugin-7
Christian Decker 6 years ago
parent
commit
cd8439b1c9
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 25
      lightningd/plugin.c
  2. 3
      lightningd/plugin.h

25
lightningd/plugin.c

@ -1054,3 +1054,28 @@ void json_add_opt_plugins(struct json_stream *response,
json_add_string(response, "plugin", p->cmd);
}
}
/**
* Determine whether a plugin is subscribed to a given topic/method.
*/
static bool plugin_subscriptions_contains(struct plugin *plugin,
const char *method)
{
for (size_t i = 0; i < tal_count(plugin->subscriptions); i++)
if (streq(method, plugin->subscriptions[i]))
return true;
return false;
}
void plugins_notify(struct plugins *plugins,
const struct jsonrpc_notification *n TAKES)
{
struct plugin *p;
list_for_each(&plugins->plugins, p, list) {
if (plugin_subscriptions_contains(p, n->method))
plugin_send(p, json_stream_dup(p, n->stream));
}
if (taken(n))
tal_free(n);
}

3
lightningd/plugin.h

@ -79,4 +79,7 @@ char *add_plugin_dir(struct plugins *plugins, const char *dir,
*/
void clear_plugins(struct plugins *plugins);
void plugins_notify(struct plugins *plugins,
const struct jsonrpc_notification *n TAKES);
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

Loading…
Cancel
Save