ubusd.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __UBUSD_H
  2. #define __UBUSD_H
  3. #include <libubox/list.h>
  4. #include <libubox/uloop.h>
  5. #include <libubox/blobmsg.h>
  6. #include "ubus_common.h"
  7. #include "ubusd_id.h"
  8. #include "ubusd_obj.h"
  9. #include "ubusmsg.h"
  10. #define UBUS_UNIX_SOCKET "./ubus.sock"
  11. #define UBUSD_CLIENT_BACKLOG 32
  12. #define UBUS_OBJ_HASH_BITS 4
  13. struct ubus_msg_buf {
  14. struct ubus_msg_buf *next;
  15. uint32_t refcount; /* ~0: uses external data buffer */
  16. struct ubus_msghdr hdr;
  17. struct blob_attr *data;
  18. int len;
  19. };
  20. struct ubus_client {
  21. struct ubus_id id;
  22. struct uloop_fd sock;
  23. struct {
  24. struct ubus_msghdr hdr;
  25. struct blob_attr data;
  26. } hdrbuf;
  27. struct list_head objects;
  28. int pending_msg_offset;
  29. struct ubus_msg_buf *pending_msg;
  30. unsigned int buf_head_ofs;
  31. struct ubus_msg_buf *buf_head;
  32. struct ubus_msg_buf **buf_tail;
  33. struct ubus_msg_buf *requests[UBUSD_CLIENT_BACKLOG];
  34. unsigned int req_head, req_tail;
  35. };
  36. struct ubus_path {
  37. struct list_head list;
  38. const char name[];
  39. };
  40. struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
  41. void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub);
  42. struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub);
  43. void ubus_msg_free(struct ubus_msg_buf *ub);
  44. struct ubus_client *ubusd_get_client_by_id(uint32_t id);
  45. void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
  46. bool ubusd_send_hello(struct ubus_client *cl);
  47. struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
  48. #endif