mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
notification: Add registeration interface
This commit is contained in:
parent
d0fe0d658f
commit
25d79c5c3f
@ -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; i<num_notis; i++)
|
||||
if (streq(notilist[i]->topic, 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; i<ARRAY_SIZE(notification_topics); i++)
|
||||
if (streq(topic, notification_topics[i]))
|
||||
return true;
|
||||
@ -131,3 +149,7 @@ void notify_forward_event(struct lightningd *ld,
|
||||
jsonrpc_notification_end(n);
|
||||
plugins_notify(ld->plugins, 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 *);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/short_channel_id.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/autodata/autodata.h>
|
||||
#include <ccan/json_escape/json_escape.h>
|
||||
#include <ccan/time/time.h>
|
||||
#include <common/amount.h>
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user