plugins: return plugin in plugin_register, make conn initializers publics

This commit is contained in:
darosior 2019-09-15 23:45:33 +02:00 committed by Rusty Russell
parent 6dca80a375
commit fcc358c9bc
2 changed files with 16 additions and 7 deletions

View File

@ -61,7 +61,7 @@ static void destroy_plugin(struct plugin *p)
list_del(&p->list);
}
void plugin_register(struct plugins *plugins, const char* path TAKES)
struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES)
{
struct plugin *p, *p_temp;
@ -70,7 +70,7 @@ void plugin_register(struct plugins *plugins, const char* path TAKES)
if (streq(path, p_temp->cmd)) {
if (taken(path))
tal_free(path);
return;
return NULL;
}
}
@ -107,6 +107,7 @@ void plugin_register(struct plugins *plugins, const char* path TAKES)
list_add_tail(&plugins->plugins, &p->list);
tal_add_destructor(p, destroy_plugin);
return p;
}
bool plugin_paths_match(const char *cmd, const char *name)
@ -435,8 +436,8 @@ static void plugin_conn_finish(struct io_conn *conn, struct plugin *plugin)
tal_free(plugin);
}
static struct io_plan *plugin_stdin_conn_init(struct io_conn *conn,
struct plugin *plugin)
struct io_plan *plugin_stdin_conn_init(struct io_conn *conn,
struct plugin *plugin)
{
/* We write to their stdin */
/* We don't have anything queued yet, wait for notification */
@ -445,8 +446,8 @@ static struct io_plan *plugin_stdin_conn_init(struct io_conn *conn,
return io_wait(plugin->stdin_conn, plugin, plugin_write_json, plugin);
}
static struct io_plan *plugin_stdout_conn_init(struct io_conn *conn,
struct plugin *plugin)
struct io_plan *plugin_stdout_conn_init(struct io_conn *conn,
struct plugin *plugin)
{
/* We read from their stdout */
plugin->stdout_conn = conn;

View File

@ -130,7 +130,7 @@ void plugins_init(struct plugins *plugins, const char *dev_plugin_debug);
* @param plugins: Plugin context
* @param path: The path of the executable for this plugin
*/
void plugin_register(struct plugins *plugins, const char* path TAKES);
struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES);
/**
* Returns true if the provided name matches a plugin command
@ -203,6 +203,14 @@ void plugin_request_send(struct plugin *plugin,
*/
char *plugin_opt_set(const char *arg, struct plugin_opt *popt);
/**
* Helpers to initialize a connection to a plugin; we read from their
* stdout, and write to their stdin.
*/
struct io_plan *plugin_stdin_conn_init(struct io_conn *conn,
struct plugin *plugin);
struct io_plan *plugin_stdout_conn_init(struct io_conn *conn,
struct plugin *plugin);
/**
* Needed for I/O logging for plugin messages.