2
0

ubusd_id.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License version 2.1
  6. * as published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __UBUSD_ID_H
  14. #define __UBUSD_ID_H
  15. #include <libubox/avl.h>
  16. #include <stdint.h>
  17. struct ubus_id {
  18. struct avl_node avl;
  19. uint32_t id;
  20. };
  21. void ubus_init_id_tree(struct avl_tree *tree);
  22. void ubus_init_string_tree(struct avl_tree *tree, bool dup);
  23. bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val);
  24. static inline void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
  25. {
  26. avl_delete(tree, &id->avl);
  27. }
  28. static inline struct ubus_id *ubus_find_id(struct avl_tree *tree, uint32_t id)
  29. {
  30. struct avl_node *avl;
  31. avl = avl_find(tree, &id);
  32. if (!avl)
  33. return NULL;
  34. return container_of(avl, struct ubus_id, avl);
  35. }
  36. #endif