Browse Source

lightningd/plugin_hook: make it possible to unregister a hook

This adds 'plugin_unregister_hook' and 'plugin_unregister_hook_all'
functions to unregister a given hook a plugin registered, or all hooks a
plugin registered for. Since hooks can only be registered once, it's
useful in the case a new plugin is added which would be prefered for
hook registration over an already loaded plugin.
pull/2938/head
darosior 6 years ago
committed by Rusty Russell
parent
commit
d299420fbe
  1. 26
      lightningd/plugin_hook.c
  2. 6
      lightningd/plugin_hook.h

26
lightningd/plugin_hook.c

@ -39,6 +39,32 @@ bool plugin_hook_register(struct plugin *plugin, const char *method)
return true;
}
bool plugin_hook_unregister(struct plugin *plugin, const char *method)
{
struct plugin_hook *hook = plugin_hook_by_name(method);
if (!hook) {
/* No such hook name registered */
return false;
} else if (hook->plugin == NULL) {
/* This name is not registered */
return false;
}
hook->plugin = NULL;
return true;
}
void plugin_hook_unregister_all(struct plugin *plugin)
{
static struct plugin_hook **hooks = NULL;
static size_t num_hooks;
if (!hooks)
hooks = autodata_get(hooks, &num_hooks);
for (size_t i = 0; i < num_hooks; i++)
if (hooks[i]->plugin == plugin)
hooks[i]->plugin = NULL;
}
/**
* Callback to be passed to the jsonrpc_request.
*

6
lightningd/plugin_hook.h

@ -102,6 +102,12 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
bool plugin_hook_register(struct plugin *plugin, const char *method);
/* Unregister a hook a plugin has registered for */
bool plugin_hook_unregister(struct plugin *plugin, const char *method);
/* Unregister all hooks a plugin has registered for */
void plugin_hook_unregister_all(struct plugin *plugin);
/* Special sync plugin hook for db: changes[] are SQL statements, with optional
* final command appended. */
void plugin_hook_db_sync(struct db *db, const char **changes, const char *final);

Loading…
Cancel
Save