ubus_invoke(ctx->ubus, id, "get_config", NULL, udebug_ubus_req_cb, ctx, 1000);
}
+void udebug_ubus_ring_init(struct udebug *ud, struct udebug_ubus_ring *ring)
+{
+ if (!ring->size)
+ ring->size = ring->default_size;
+ if (!ring->entries)
+ ring->entries = ring->default_entries;
+ udebug_buf_init(ring->buf, ring->entries, ring->size);
+ udebug_buf_add(ud, ring->buf, ring->meta);
+}
+
+void udebug_ubus_apply_config(struct udebug *ud, struct udebug_ubus_ring *rings, int n,
+ struct blob_attr *data, bool enabled)
+{
+ enum {
+ CFG_ATTR_ENABLE,
+ CFG_ATTR_SIZE,
+ CFG_ATTR_ENTRIES,
+ __CFG_ATTR_MAX,
+ };
+ static struct blobmsg_policy policy[] = {
+ [CFG_ATTR_ENABLE] = { NULL, BLOBMSG_TYPE_STRING },
+ [CFG_ATTR_SIZE] = { NULL, BLOBMSG_TYPE_STRING },
+ [CFG_ATTR_ENTRIES] = { NULL, BLOBMSG_TYPE_STRING },
+ };
+
+ for (size_t i = 0; i < n; i++) {
+ struct blob_attr *tb[__CFG_ATTR_MAX], *cur;
+ struct udebug_buf *buf = rings[i].buf;
+ const char *name = rings[i].meta->name;
+ int name_len = strlen(name);
+ unsigned int size, entries;
+ bool cur_enabled = enabled;
+ char *str;
+
+ policy[CFG_ATTR_ENABLE].name = name;
+
+#define SIZE_FMT "%s_size"
+ str = alloca(sizeof(SIZE_FMT) + name_len);
+ sprintf(str, SIZE_FMT, name);
+ policy[CFG_ATTR_SIZE].name = str;
+
+#define ENTRIES_FMT "%s_entries"
+ str = alloca(sizeof(ENTRIES_FMT) + name_len);
+ sprintf(str, ENTRIES_FMT, name);
+ policy[CFG_ATTR_ENTRIES].name = str;
+
+ blobmsg_parse_attr(policy, __CFG_ATTR_MAX, tb, data);
+
+ if ((cur = tb[CFG_ATTR_ENABLE]) != NULL)
+ cur_enabled = !!atoi(blobmsg_get_string(cur));
+
+ if ((cur = tb[CFG_ATTR_SIZE]) != NULL)
+ size = atoi(blobmsg_get_string(cur));
+ else
+ size = rings[i].default_size;
+
+ if ((cur = tb[CFG_ATTR_ENTRIES]) != NULL)
+ entries = atoi(blobmsg_get_string(cur));
+ else
+ entries = rings[i].default_entries;
+
+ if (udebug_buf_valid(buf) == cur_enabled &&
+ size == rings[i].size &&
+ entries == rings[i].entries)
+ continue;
+
+ if (udebug_buf_valid(buf))
+ udebug_buf_free(buf);
+
+ rings[i].size = size;
+ rings[i].entries = entries;
+ if (!cur_enabled)
+ continue;
+
+ udebug_ubus_ring_init(ud, &rings[i]);
+ }
+}
+
void udebug_ubus_init(struct udebug_ubus *ctx, struct ubus_context *ubus,
const char *service, udebug_config_cb cb)
{
struct udebug_ubus;
typedef void (*udebug_config_cb)(struct udebug_ubus *ctx, struct blob_attr *data, bool enabled);
+struct udebug_ubus_ring {
+ struct udebug_buf *buf;
+ const struct udebug_buf_meta *meta;
+ unsigned int size, default_size;
+ unsigned int entries, default_entries;
+};
+
struct udebug_ubus {
struct ubus_context *ubus;
struct uloop_timeout t;
void udebug_ubus_init(struct udebug_ubus *ctx, struct ubus_context *ubus,
const char *service, udebug_config_cb cb);
+void udebug_ubus_ring_init(struct udebug *ud, struct udebug_ubus_ring *ring);
+void udebug_ubus_apply_config(struct udebug *ud, struct udebug_ubus_ring *rings, int n,
+ struct blob_attr *data, bool enabled);
void udebug_ubus_free(struct udebug_ubus *ctx);