| 1635 | } |
| 1636 | |
| 1637 | static struct plugin *new_plugin(const tal_t *ctx, |
| 1638 | const char *argv0, |
| 1639 | const char *(*init)(struct plugin *p, |
| 1640 | const char *buf, |
| 1641 | const jsmntok_t *), |
| 1642 | const enum plugin_restartability restartability, |
| 1643 | bool init_rpc, |
| 1644 | struct feature_set *features STEALS, |
| 1645 | const struct plugin_command *commands TAKES, |
| 1646 | size_t num_commands, |
| 1647 | const struct plugin_notification *notif_subs TAKES, |
| 1648 | size_t num_notif_subs, |
| 1649 | const struct plugin_hook *hook_subs TAKES, |
| 1650 | size_t num_hook_subs, |
| 1651 | const char **notif_topics TAKES, |
| 1652 | size_t num_notif_topics, |
| 1653 | va_list ap) |
| 1654 | { |
| 1655 | const char *optname; |
| 1656 | struct plugin *p = tal(ctx, struct plugin); |
| 1657 | char *name; |
| 1658 | |
| 1659 | /* id is our name, without extension (not that we expect any, in C!) */ |
| 1660 | name = path_basename(p, argv0); |
| 1661 | name[path_ext_off(name)] = '\0'; |
| 1662 | p->id = name; |
| 1663 | p->buffer = tal_arr(p, char, 64); |
| 1664 | list_head_init(&p->js_list); |
| 1665 | p->used = 0; |
| 1666 | p->len_read = 0; |
| 1667 | jsmn_init(&p->parser); |
| 1668 | p->toks = toks_alloc(p); |
| 1669 | /* Async RPC */ |
| 1670 | p->rpc_buffer = tal_arr(p, char, 64); |
| 1671 | list_head_init(&p->rpc_js_list); |
| 1672 | p->rpc_used = 0; |
| 1673 | p->rpc_read_offset = 0; |
| 1674 | p->rpc_len_read = 0; |
| 1675 | jsmn_init(&p->rpc_parser); |
| 1676 | p->rpc_toks = toks_alloc(p); |
| 1677 | p->next_outreq_id = 0; |
| 1678 | strmap_init(&p->out_reqs); |
| 1679 | |
| 1680 | p->desired_features = tal_steal(p, features); |
| 1681 | if (init_rpc) { |
| 1682 | /* Sync RPC FIXME: maybe go full async ? */ |
| 1683 | p->rpc_conn = tal(p, struct rpc_conn); |
| 1684 | } else { |
| 1685 | p->rpc_conn = NULL; |
| 1686 | } |
| 1687 | |
| 1688 | p->init = init; |
| 1689 | p->manifested = p->initialized = p->exiting = false; |
| 1690 | p->restartability = restartability; |
| 1691 | strmap_init(&p->usagemap); |
| 1692 | p->in_timer = 0; |
| 1693 | |
| 1694 | p->commands = commands; |
no test coverage detected