mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 02:39:28 +01:00
libplugin: generalize the plugin_timer callback type
We don't take the callback result into account, so it can better be void. Having a general callback parameter is handy, because for bcli we want to pass it the struct bcli.
This commit is contained in:
parent
b0b55d36ef
commit
3eb0f56f87
3 changed files with 16 additions and 10 deletions
|
@ -9,7 +9,7 @@
|
|||
static u64 cycle_seconds = 0, expired_by = 86400;
|
||||
static struct plugin_timer *cleantimer;
|
||||
|
||||
static struct command_result *do_clean(struct plugin *p);
|
||||
static void do_clean(void *cb_arg);
|
||||
|
||||
static struct command_result *ignore(struct command *timer,
|
||||
const char *buf,
|
||||
|
@ -17,19 +17,20 @@ static struct command_result *ignore(struct command *timer,
|
|||
void *arg)
|
||||
{
|
||||
struct plugin *p = arg;
|
||||
cleantimer = plugin_timer(p, time_from_sec(cycle_seconds), do_clean);
|
||||
cleantimer = plugin_timer(p, time_from_sec(cycle_seconds), do_clean, p);
|
||||
return timer_complete(p);
|
||||
}
|
||||
|
||||
static struct command_result *do_clean(struct plugin *p)
|
||||
static void do_clean(void *cb_arg)
|
||||
{
|
||||
struct plugin *p = cb_arg;
|
||||
/* FIXME: delexpiredinvoice should be in our plugin too! */
|
||||
struct out_req *req = jsonrpc_request_start(p, NULL, "delexpiredinvoice",
|
||||
ignore, ignore, p);
|
||||
json_add_u64(req->js, "maxexpirytime",
|
||||
time_now().ts.tv_sec - expired_by);
|
||||
|
||||
return send_outreq(p, req);
|
||||
send_outreq(p, req);
|
||||
}
|
||||
|
||||
static struct command_result *json_autocleaninvoice(struct command *cmd,
|
||||
|
@ -53,7 +54,8 @@ static struct command_result *json_autocleaninvoice(struct command *cmd,
|
|||
return command_success_str(cmd, "Autoclean timer disabled");
|
||||
}
|
||||
tal_free(cleantimer);
|
||||
cleantimer = plugin_timer(cmd->plugin, time_from_sec(cycle_seconds), do_clean);
|
||||
cleantimer = plugin_timer(cmd->plugin, time_from_sec(cycle_seconds),
|
||||
do_clean, cmd->plugin);
|
||||
|
||||
return command_success_str(cmd,
|
||||
tal_fmt(cmd, "Autocleaning %"PRIu64
|
||||
|
@ -68,7 +70,7 @@ static void init(struct plugin *p,
|
|||
if (cycle_seconds) {
|
||||
plugin_log(p, LOG_INFORM, "autocleaning every %"PRIu64" seconds", cycle_seconds);
|
||||
cleantimer = plugin_timer(p, time_from_sec(cycle_seconds),
|
||||
do_clean);
|
||||
do_clean, p);
|
||||
} else
|
||||
plugin_log(p, LOG_DBG, "autocleaning not active");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ bool deprecated_apis;
|
|||
|
||||
struct plugin_timer {
|
||||
struct timer timer;
|
||||
struct command_result *(*cb)(struct plugin *p);
|
||||
void (*cb)(void *cb_arg);
|
||||
void *cb_arg;
|
||||
};
|
||||
|
||||
struct rpc_conn {
|
||||
|
@ -820,7 +821,7 @@ static void call_plugin_timer(struct plugin *p, struct timer *timer)
|
|||
p->in_timer++;
|
||||
/* Free this if they don't. */
|
||||
tal_steal(tmpctx, t);
|
||||
t->cb(p);
|
||||
t->cb(t->cb_arg);
|
||||
}
|
||||
|
||||
static void destroy_plugin_timer(struct plugin_timer *timer, struct plugin *p)
|
||||
|
@ -829,10 +830,12 @@ static void destroy_plugin_timer(struct plugin_timer *timer, struct plugin *p)
|
|||
}
|
||||
|
||||
struct plugin_timer *plugin_timer(struct plugin *p, struct timerel t,
|
||||
struct command_result *(*cb)(struct plugin *p))
|
||||
void (*cb)(void *cb_arg),
|
||||
void *cb_arg)
|
||||
{
|
||||
struct plugin_timer *timer = tal(NULL, struct plugin_timer);
|
||||
timer->cb = cb;
|
||||
timer->cb_arg = cb_arg;
|
||||
timer_init(&timer->timer);
|
||||
timer_addrel(&p->timers, &timer->timer, t);
|
||||
tal_add_destructor2(timer, destroy_plugin_timer, p);
|
||||
|
|
|
@ -212,7 +212,8 @@ struct command_result *timer_complete(struct plugin *p);
|
|||
*/
|
||||
struct plugin_timer *plugin_timer(struct plugin *p,
|
||||
struct timerel t,
|
||||
struct command_result *(*cb)(struct plugin *p));
|
||||
void (*cb)(void *cb_arg),
|
||||
void *cb_arg);
|
||||
|
||||
/* Log something */
|
||||
void plugin_log(struct plugin *p, enum log_level l, const char *fmt, ...) PRINTF_FMT(3, 4);
|
||||
|
|
Loading…
Add table
Reference in a new issue