ubusd_obj.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_OBJ_H
  14. #define __UBUSD_OBJ_H
  15. #include "ubusd_id.h"
  16. extern struct avl_tree obj_types;
  17. extern struct avl_tree objects;
  18. extern struct avl_tree path;
  19. struct ubus_client;
  20. struct ubus_msg_buf;
  21. struct ubus_object_type {
  22. struct ubus_id id;
  23. int refcount;
  24. struct list_head methods;
  25. };
  26. struct ubus_method {
  27. struct list_head list;
  28. const char *name;
  29. struct blob_attr data[];
  30. };
  31. struct ubus_object {
  32. struct ubus_id id;
  33. struct list_head list;
  34. struct list_head events;
  35. struct ubus_object_type *type;
  36. struct avl_node path;
  37. struct ubus_client *client;
  38. int (*recv_msg)(struct ubus_client *client, const char *method, struct blob_attr *msg);
  39. int event_seen;
  40. };
  41. struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr);
  42. struct ubus_object *ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id);
  43. void ubusd_free_object(struct ubus_object *obj);
  44. static inline struct ubus_object *ubusd_find_object(uint32_t objid)
  45. {
  46. struct ubus_object *obj;
  47. struct ubus_id *id;
  48. id = ubus_find_id(&objects, objid);
  49. if (!id)
  50. return NULL;
  51. obj = container_of(id, struct ubus_object, id);
  52. return obj;
  53. }
  54. #endif