From 25d79c5c3fdfc5f9c6ede46401082a96c3d85766 Mon Sep 17 00:00:00 2001 From: trueptolemy Date: Sun, 11 Aug 2019 05:32:13 +0800 Subject: [PATCH] notification: Add registeration interface --- lightningd/notification.c | 22 ++++++++++++++++++++++ lightningd/notification.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lightningd/notification.c b/lightningd/notification.c index 75b342c50..b006fb3ef 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -13,8 +13,26 @@ const char *notification_topics[] = { "forward_event" }; +static struct notification *find_notification_by_topic(const char* topic) +{ + static struct notification **notilist = NULL; + static size_t num_notis; + if (!notilist) + notilist = autodata_get(notifications, &num_notis); + + for (size_t i=0; itopic, topic)) + return notilist[i]; + return NULL; +} + bool notifications_have_topic(const char *topic) { + struct notification *noti = find_notification_by_topic(topic); + if (noti) + return true; + + /* TODO: Remove this block after making all notifications registered. */ for (size_t i=0; iplugins, take(n)); } + +/* TODO: It's a dummy notification. Will be removed when we have a 'real' one + * in this file. */ +REGISTER_JSON_INTERNAL_COMMAND(hello_notification, NULL, void *); diff --git a/lightningd/notification.h b/lightningd/notification.h index 9741c939c..cf97d81bf 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -17,6 +18,22 @@ bool notifications_have_topic(const char *topic); +struct notification { + const char *topic; + /* the serialization interface */ + void *serialize; +}; + +AUTODATA_TYPE(notifications, struct notification); + +/* FIXME: Find a way to avoid back-to-back declaration and definition */ +#define REGISTER_NOTIFICATION(topic, serialize) \ + struct notification topic##_notification_gen = { \ + stringify(topic), \ + serialize, \ + }; \ + AUTODATA(notifications, &topic##_notification_gen); + void notify_connect(struct lightningd *ld, struct node_id *nodeid, struct wireaddr_internal *addr); void notify_disconnect(struct lightningd *ld, struct node_id *nodeid);