From f8cdb523dd05925b3b59df26d5cb4f43fa37ceb6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 5 May 2020 10:41:59 +0930 Subject: [PATCH] plugin_hook_call: return indication whether we called the callback or not. This will allow us to simplify the caller's command handling. Signed-off-by: Rusty Russell --- lightningd/plugin_hook.c | 4 +++- lightningd/plugin_hook.h | 9 ++++++--- lightningd/test/run-invoice-select-inchan.c | 2 +- lightningd/test/run-jsonrpc.c | 2 +- wallet/test/run-wallet.c | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 97b8fc248..2d32d9f6f 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -238,7 +238,7 @@ static void plugin_hook_call_next(struct plugin_hook_request *ph_req) plugin_request_send(ph_req->plugin, req); } -void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, +bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, tal_t *cb_arg STEALS) { struct plugin_hook_request *ph_req; @@ -265,6 +265,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, list_add_tail(&ph_req->call_chain, &link->list); } plugin_hook_call_next(ph_req); + return false; } else { /* If no plugin has registered for this hook, just * call the callback with a NULL result. Saves us the @@ -275,6 +276,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, hook->final_cb(cb_arg); else hook->single_response_cb(cb_arg, NULL, NULL); + return true; } } diff --git a/lightningd/plugin_hook.h b/lightningd/plugin_hook.h index e2be6277c..272659336 100644 --- a/lightningd/plugin_hook.h +++ b/lightningd/plugin_hook.h @@ -83,8 +83,11 @@ AUTODATA_TYPE(hooks, struct plugin_hook); /* Do not call this directly, rather use the `plugin_hook_call_name` * wrappers generated by the `PLUGIN_HOOK_REGISTER` macro. + * + * Returns true if callback called immediately, otherwise false if it's + * still waiting on a plugin response. */ -void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, +bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, tal_t *cb_arg STEALS); /* Generic deserialize_cb: returns true iff 'result': 'continue' */ @@ -97,10 +100,10 @@ bool plugin_hook_continue(void *arg, const char *buffer, const jsmntok_t *toks); */ /* FIXME: Find a way to avoid back-to-back declaration and definition */ #define PLUGIN_HOOK_CALL_DEF(name, cb_arg_type) \ - UNNEEDED static inline void plugin_hook_call_##name( \ + UNNEEDED static inline bool plugin_hook_call_##name( \ struct lightningd *ld, cb_arg_type cb_arg STEALS) \ { \ - plugin_hook_call_(ld, &name##_hook_gen, cb_arg); \ + return plugin_hook_call_(ld, &name##_hook_gen, cb_arg); \ } /* Typechecked registration of a plugin hook. We check that the diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 839df1603..49d0d0043 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -378,7 +378,7 @@ void per_peer_state_set_fds(struct per_peer_state *pps UNNEEDED, int peer_fd UNNEEDED, int gossip_fd UNNEEDED, int gossip_store_fd UNNEEDED) { fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); } /* Generated stub for plugin_hook_call_ */ -void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, +bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, tal_t *cb_arg STEALS UNNEEDED) { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } /* Generated stub for subd_release_channel */ diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 5bb185784..111c2f7bf 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -95,7 +95,7 @@ struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name const jsmntok_t **out UNNEEDED) { fprintf(stderr, "param_tok called!\n"); abort(); } /* Generated stub for plugin_hook_call_ */ -void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, +bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, tal_t *cb_arg STEALS UNNEEDED) { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index a1fbcbf49..e10132750 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -546,7 +546,7 @@ void per_peer_state_set_fds(struct per_peer_state *pps UNNEEDED, int peer_fd UNNEEDED, int gossip_fd UNNEEDED, int gossip_store_fd UNNEEDED) { fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); } /* Generated stub for plugin_hook_call_ */ -void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, +bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, tal_t *cb_arg STEALS UNNEEDED) { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } /* Generated stub for process_onionpacket */