3 static struct blob_attr
*
4 find_attr(struct blob_attr
*attr
, const char *name
, enum blobmsg_type type
)
6 struct blobmsg_policy policy
= { name
, type
};
12 blobmsg_parse_attr(&policy
, 1, &ret
, attr
);
17 udebug_ubus_msg_cb(struct udebug_ubus
*ctx
, struct blob_attr
*data
)
19 struct blob_attr
*en_attr
;
22 data
= find_attr(data
, "service", BLOBMSG_TYPE_TABLE
);
23 data
= find_attr(data
, ctx
->service
, BLOBMSG_TYPE_TABLE
);
27 en_attr
= find_attr(data
, "enabled", BLOBMSG_TYPE_STRING
);
28 enabled
= en_attr
&& !!atoi(blobmsg_get_string(en_attr
));
29 ctx
->cb(ctx
, data
, enabled
);
33 udebug_ubus_notify_cb(struct ubus_context
*ubus
, struct ubus_object
*obj
,
34 struct ubus_request_data
*req
, const char *method
,
35 struct blob_attr
*msg
)
37 struct udebug_ubus
*ctx
= container_of(obj
, struct udebug_ubus
, sub
.obj
);
39 if (!strcmp(method
, "config"))
40 udebug_ubus_msg_cb(ctx
, msg
);
46 udebug_ubus_req_cb(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
48 udebug_ubus_msg_cb(req
->priv
, msg
);
52 udebug_ubus_new_obj_cb(struct ubus_context
*ubus
, struct ubus_subscriber
*sub
,
55 return !strcmp(path
, "udebug");
58 void udebug_ubus_init(struct udebug_ubus
*ctx
, struct ubus_context
*ubus
,
59 const char *service
, udebug_config_cb cb
)
64 ctx
->service
= service
;
66 ctx
->sub
.new_obj_cb
= udebug_ubus_new_obj_cb
;
67 ctx
->sub
.cb
= udebug_ubus_notify_cb
;
68 ubus_register_subscriber(ubus
, &ctx
->sub
);
70 if (ubus_lookup_id(ubus
, "udebug", &id
))
73 ubus_subscribe(ubus
, &ctx
->sub
, id
);
74 ubus_invoke(ubus
, id
, "get_config", NULL
, udebug_ubus_req_cb
, ctx
, 1000);
77 void udebug_ubus_free(struct udebug_ubus
*ctx
)
82 ubus_unregister_subscriber(ctx
->ubus
, &ctx
->sub
);