add update_start/update_complete methods
[project/procd.git] / utils.h
1 #ifndef __PROCD_UTILS_H
2 #define __PROCD_UTILS_H
3
4 #include <libubox/avl.h>
5 #include <libubox/blob.h>
6 #include <libubox/blobmsg.h>
7
8 struct blobmsg_list_node {
9         struct avl_node avl;
10         struct blob_attr *data;
11 };
12
13 typedef bool (*blobmsg_list_cmp)(struct blobmsg_list_node *l1, struct blobmsg_list_node *l2);
14
15 struct blobmsg_list {
16         struct avl_tree avl;
17         int node_offset;
18         int node_len;
19
20         blobmsg_list_cmp cmp;
21 };
22
23 #define blobmsg_list_simple_init(list) \
24         __blobmsg_list_init(list, 0, sizeof(struct blobmsg_list_node), NULL)
25
26 #define blobmsg_list_init(list, type, field, cmp) \
27         __blobmsg_list_init(list, offsetof(type, field), sizeof(type), cmp)
28
29 #define blobmsg_list_for_each(list, element) \
30         avl_for_each_element(&(list)->avl, element, avl)
31
32 void __blobmsg_list_init(struct blobmsg_list *list, int offset, int len, blobmsg_list_cmp cmp);
33 int blobmsg_list_fill(struct blobmsg_list *list, void *data, int len, bool array);
34 void blobmsg_list_free(struct blobmsg_list *list);
35 bool blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2);
36 void blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src);
37
38 #endif