Browse Source

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>
nifty/pset-pre
Rusty Russell 5 years ago
parent
commit
f8cdb523dd
  1. 4
      lightningd/plugin_hook.c
  2. 9
      lightningd/plugin_hook.h
  3. 2
      lightningd/test/run-invoice-select-inchan.c
  4. 2
      lightningd/test/run-jsonrpc.c
  5. 2
      wallet/test/run-wallet.c

4
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); 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) tal_t *cb_arg STEALS)
{ {
struct plugin_hook_request *ph_req; 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); list_add_tail(&ph_req->call_chain, &link->list);
} }
plugin_hook_call_next(ph_req); plugin_hook_call_next(ph_req);
return false;
} else { } else {
/* If no plugin has registered for this hook, just /* If no plugin has registered for this hook, just
* call the callback with a NULL result. Saves us the * 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); hook->final_cb(cb_arg);
else else
hook->single_response_cb(cb_arg, NULL, NULL); hook->single_response_cb(cb_arg, NULL, NULL);
return true;
} }
} }

9
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` /* Do not call this directly, rather use the `plugin_hook_call_name`
* wrappers generated by the `PLUGIN_HOOK_REGISTER` macro. * 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); tal_t *cb_arg STEALS);
/* Generic deserialize_cb: returns true iff 'result': 'continue' */ /* 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 */ /* FIXME: Find a way to avoid back-to-back declaration and definition */
#define PLUGIN_HOOK_CALL_DEF(name, cb_arg_type) \ #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) \ 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 /* Typechecked registration of a plugin hook. We check that the

2
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) int peer_fd UNNEEDED, int gossip_fd UNNEEDED, int gossip_store_fd UNNEEDED)
{ fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); } { fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* 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) tal_t *cb_arg STEALS UNNEEDED)
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
/* Generated stub for subd_release_channel */ /* Generated stub for subd_release_channel */

2
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) const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "param_tok called!\n"); abort(); } { fprintf(stderr, "param_tok called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* 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) tal_t *cb_arg STEALS UNNEEDED)
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */

2
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) int peer_fd UNNEEDED, int gossip_fd UNNEEDED, int gossip_store_fd UNNEEDED)
{ fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); } { fprintf(stderr, "per_peer_state_set_fds called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* 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) tal_t *cb_arg STEALS UNNEEDED)
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
/* Generated stub for process_onionpacket */ /* Generated stub for process_onionpacket */

Loading…
Cancel
Save