ubusd_id.h 659 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef __UBUSD_ID_H
  2. #define __UBUSD_ID_H
  3. #include <libubox/avl.h>
  4. #include <stdint.h>
  5. struct ubus_id {
  6. struct avl_node avl;
  7. uint32_t id;
  8. };
  9. void ubus_init_id_tree(struct avl_tree *tree);
  10. void ubus_init_string_tree(struct avl_tree *tree, bool dup);
  11. bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val);
  12. static inline void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
  13. {
  14. avl_delete(tree, &id->avl);
  15. }
  16. static inline struct ubus_id *ubus_find_id(struct avl_tree *tree, uint32_t id)
  17. {
  18. struct avl_node *avl;
  19. avl = avl_find(tree, &id);
  20. if (!avl)
  21. return NULL;
  22. return container_of(avl, struct ubus_id, avl);
  23. }
  24. #endif