plugin: simplify hooks calling methods, and make lifetime requirements explicit.

They callback must take ownership of the payload (almost all do, but
now it's explicit).

And since the payload and cb_arg arguments to plugin_hook_call_() are
always identical, make them a single parameter.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-04-15 19:50:41 +09:30
parent 1e34d8989d
commit 9aedb0c61f
11 changed files with 44 additions and 49 deletions

View File

@@ -14,7 +14,6 @@ struct plugin_hook_request {
struct plugin *plugin;
const struct plugin_hook *hook;
void *cb_arg;
void *payload;
struct db *db;
struct lightningd *ld;
};
@@ -221,13 +220,13 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
plugin_get_log(ph_req->plugin),
plugin_hook_callback, ph_req);
hook->serialize_payload(ph_req->payload, req->stream);
hook->serialize_payload(ph_req->cb_arg, req->stream);
jsonrpc_request_end(req);
plugin_request_send(ph_req->plugin, req);
}
void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
void *payload, void *cb_arg)
tal_t *cb_arg STEALS)
{
struct plugin_hook_request *ph_req;
struct plugin_hook_call_link *link;
@@ -239,9 +238,8 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
* to eventually to inspect in-flight requests. */
ph_req = notleak(tal(hook->plugins, struct plugin_hook_request));
ph_req->hook = hook;
ph_req->cb_arg = cb_arg;
ph_req->cb_arg = tal_steal(ph_req, cb_arg);
ph_req->db = ld->wallet->db;
ph_req->payload = tal_steal(ph_req, payload);
ph_req->ld = ld;
list_head_init(&ph_req->call_chain);