Skip to content
Snippets Groups Projects
Commit aa5a1857 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

cntlr: fix ieee1905 resubscribe

parent 253cc9dd
No related branches found
No related tags found
No related merge requests found
Pipeline #39650 failed
......@@ -58,7 +58,7 @@ void stop_cntlr(struct controller *c)
exit(0);
}
ubus_unregister_event_handler(c->ubus_ctx, &c->ieee1905_evh);
ubus_unregister_event_handler(c->ubus_ctx, &c->evh);
cntlr_remove_object(c);
cmdu_ackq_free(&c->cmdu_ack_q);
uloop_done();
......@@ -2371,6 +2371,63 @@ static void cntlr_ackq_delete_cb(struct cmdu_ackq *q, struct cmdu_ackq_entry *e)
cmdu_free(cmdu);
}
static void uobj_add_event_handler(void *cntlr, struct blob_attr *msg)
{
char path[32] = {0};
uint32_t id = 0;
struct controller *c = (struct controller *) cntlr;
struct blob_attr *tb[2];
static const struct blobmsg_policy ev_attr[2] = {
[0] = { .name = "id", .type = BLOBMSG_TYPE_INT32 },
[1] = { .name = "path", .type = BLOBMSG_TYPE_STRING }
};
blobmsg_parse(ev_attr, 2, tb, blob_data(msg), blob_len(msg));
if (!tb[0] || !tb[1])
return;
strncpy(path, blobmsg_data(tb[1]), sizeof(path) - 1);
id = (uint32_t) blobmsg_get_u32(tb[0]);
dbg("|%s:%d| path = [%s] id = [%d] [%u]\n", __func__, __LINE__, path,
id, id);
if (!strncmp(path, map_plugin, strlen(map_plugin))) {
/* TODO: how to handle failure? */
controller_subscribe_for_cmdus(c);
}
}
static void cntlr_event_handler(struct ubus_context *ctx,
struct ubus_event_handler *ev,
const char *type, struct blob_attr *msg)
{
int i;
char *str;
struct controller *c = container_of(ev, struct controller, evh);
struct wifi_ev_handler {
const char *ev_type;
void (*handler)(void *ctx, struct blob_attr *ev_data);
} evs[] = {
{ "ubus.object.add", uobj_add_event_handler }
};
str = blobmsg_format_json(msg, true);
if (!str)
return;
info("[ &controller = %p ] Received [event = %s] [val = %s]\n",
c, type, str);
for (i = 0; i < ARRAY_SIZE(evs); i++) {
if (!strcmp(type, evs[i].ev_type))
evs[i].handler(c, msg);
}
free(str);
}
int start_controller(void)
{
struct controller *c;
......@@ -2448,6 +2505,9 @@ int start_controller(void)
uloop_timeout_set(&c->signal_handler, 5 * 1000);
uloop_timeout_set(&c->query_nodes, 60 * 1000);
c->evh.cb = cntlr_event_handler;
ubus_register_event_handler(ctx, &c->evh, "ubus.object.*");
controller_subscribe_for_cmdus(c);
......
......@@ -359,8 +359,7 @@ struct controller {
void *comm;
struct ubus_object obj;
struct ubus_context *ubus_ctx;
/* struct ubus_event_handler ubus_ev; */ /** for local events */
struct ubus_event_handler ieee1905_evh;
struct ubus_event_handler evh;
struct uloop_timeout heartbeat;
int num_nodes;
int num_tx_links;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment