ubusd_obj.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_subscription {
  32. struct list_head list, target_list;
  33. struct ubus_object *subscriber, *target;
  34. };
  35. struct ubus_object {
  36. struct ubus_id id;
  37. struct list_head list;
  38. struct list_head events;
  39. struct list_head subscribers, target_list;
  40. struct ubus_object_type *type;
  41. struct avl_node path;
  42. struct ubus_client *client;
  43. int (*recv_msg)(struct ubus_client *client, struct ubus_msg_buf *ub,
  44. const char *method, struct blob_attr *msg);
  45. int event_seen;
  46. unsigned int invoke_seq;
  47. };
  48. struct ubus_object *ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr);
  49. struct ubus_object *ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id);
  50. void ubusd_free_object(struct ubus_object *obj);
  51. static inline struct ubus_object *ubusd_find_object(uint32_t objid)
  52. {
  53. struct ubus_object *obj;
  54. struct ubus_id *id;
  55. id = ubus_find_id(&objects, objid);
  56. if (!id)
  57. return NULL;
  58. obj = container_of(id, struct ubus_object, id);
  59. return obj;
  60. }
  61. void ubus_subscribe(struct ubus_object *obj, struct ubus_object *target);
  62. void ubus_unsubscribe(struct ubus_subscription *s);
  63. void ubus_notify_unsubscribe(struct ubus_subscription *s);
  64. void ubus_notify_subscription(struct ubus_object *obj);
  65. #endif