Skip to content

Commit f81ccb2

Browse files
gudnufdaywalker90
authored andcommitted
new notifications: plugin_stopped and plugin_started
1 parent 5e6eda0 commit f81ccb2

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

doc/developers-guide/plugin-development/event-notifications.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,51 @@ In the shutdown case, plugins should not interact with lightnind except via (id-
483483
}
484484
}
485485
```
486+
487+
### `plugin_started` and
488+
489+
Emitted when a plugin has completed startup.
490+
491+
```json
492+
{
493+
"plugin_started": {
494+
"plugin_name": "example_plugin",
495+
"plugin_path": "/path/to/example_plugin.py",
496+
"methods": [
497+
"example_method1",
498+
"example_method2",
499+
"example_method3"
500+
]
501+
}
502+
}
503+
```
504+
505+
Where:
506+
507+
- `plugin_name`: The short name of the plugin.
508+
- `plugin_path`: The full file path to the plugin executable.
509+
- `methods`: An array of RPC method names that the plugin registered.
510+
511+
### `plugin_stopped`
512+
513+
Emitted when a plugin has been stopped or has exited.
514+
515+
```json
516+
{
517+
"plugin_stopped": {
518+
"plugin_name": "example_plugin",
519+
"plugin_path": "/path/to/example_plugin.py",
520+
"methods": [
521+
"example_method1",
522+
"example_method2",
523+
"example_method3"
524+
]
525+
}
526+
}
527+
```
528+
529+
Where:
530+
531+
- `plugin_name`: The short name of the plugin.
532+
- `plugin_path`: The full file path to the plugin executable.
533+
- `methods`: An array of RPC method names that the plugin registered.

lightningd/notification.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,45 @@ void notify_log(struct lightningd *ld, const struct log_entry *l)
638638
log_notification_serialize(n->stream, l);
639639
notify_send(ld, n);
640640
}
641+
642+
static void plugin_started_notification_serialize(struct json_stream *stream,
643+
struct plugin *plugin)
644+
{
645+
json_add_string(stream, "plugin_name", plugin->shortname);
646+
json_add_string(stream, "plugin_path", plugin->cmd);
647+
json_array_start(stream, "methods");
648+
for (size_t i = 0; i < tal_count(plugin->methods); i++) {
649+
json_add_string(stream, NULL, plugin->methods[i]);
650+
}
651+
json_array_end(stream);
652+
}
653+
654+
REGISTER_NOTIFICATION(plugin_started);
655+
656+
void notify_plugin_started(struct lightningd *ld, struct plugin *plugin)
657+
{
658+
struct jsonrpc_notification *n = notify_start("plugin_started");
659+
plugin_started_notification_serialize(n->stream, plugin);
660+
notify_send(ld, n);
661+
}
662+
663+
static void plugin_stopped_notification_serialize(struct json_stream *stream,
664+
struct plugin *plugin)
665+
{
666+
json_add_string(stream, "plugin_name", plugin->shortname);
667+
json_add_string(stream, "plugin_path", plugin->cmd);
668+
json_array_start(stream, "methods");
669+
for (size_t i = 0; i < tal_count(plugin->methods); i++) {
670+
json_add_string(stream, NULL, plugin->methods[i]);
671+
}
672+
json_array_end(stream);
673+
}
674+
675+
REGISTER_NOTIFICATION(plugin_stopped);
676+
677+
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin)
678+
{
679+
struct jsonrpc_notification *n = notify_start("plugin_stopped");
680+
plugin_stopped_notification_serialize(n->stream, plugin);
681+
notify_send(ld, n);
682+
}

lightningd/notification.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,7 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
109109
bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p);
110110
/* Inform the plugin when a log line is emitted */
111111
void notify_log(struct lightningd *ld, const struct log_entry *l);
112+
113+
void notify_plugin_started(struct lightningd *ld, struct plugin *plugin);
114+
void notify_plugin_stopped(struct lightningd *ld, struct plugin *plugin);
112115
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */

lightningd/plugin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ static void destroy_plugin(struct plugin *p)
305305

306306
if (tal_count(p->custom_msgs))
307307
tell_connectd_custommsgs(p->plugins);
308+
309+
notify_plugin_stopped(p->plugins->ld, p);
308310
}
309311

310312
static u32 file_checksum(struct lightningd *ld, const char *path)
@@ -2200,6 +2202,7 @@ static void plugin_config_cb(const char *buffer,
22002202
}
22012203
if (tal_count(plugin->custom_msgs))
22022204
tell_connectd_custommsgs(plugin->plugins);
2205+
notify_plugin_started(plugin->plugins->ld, plugin);
22032206
check_plugins_initted(plugin->plugins);
22042207
}
22052208

0 commit comments

Comments
 (0)