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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-05-05 10:41:59 +09:30
parent b592d6fd8f
commit f8cdb523dd
5 changed files with 12 additions and 7 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */