wayland-client-core.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright © 2008 Kristian Høgsberg
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #ifndef WAYLAND_CLIENT_CORE_H
  26. #define WAYLAND_CLIENT_CORE_H
  27. #include "wayland-util.h"
  28. #include "wayland-version.h"
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /** \class wl_proxy
  33. *
  34. * \brief Represents a protocol object on the client side.
  35. *
  36. * A wl_proxy acts as a client side proxy to an object existing in the
  37. * compositor. The proxy is responsible for converting requests made by the
  38. * clients with \ref wl_proxy_marshal() into Wayland's wire format. Events
  39. * coming from the compositor are also handled by the proxy, which will in
  40. * turn call the handler set with \ref wl_proxy_add_listener().
  41. *
  42. * \note With the exception of function \ref wl_proxy_set_queue(), functions
  43. * accessing a wl_proxy are not normally used by client code. Clients
  44. * should normally use the higher level interface generated by the scanner to
  45. * interact with compositor objects.
  46. *
  47. */
  48. struct wl_proxy;
  49. /** \class wl_display
  50. *
  51. * \brief Represents a connection to the compositor and acts as a proxy to
  52. * the wl_display singleton object.
  53. *
  54. * A wl_display object represents a client connection to a Wayland
  55. * compositor. It is created with either \ref wl_display_connect() or
  56. * \ref wl_display_connect_to_fd(). A connection is terminated using
  57. * \ref wl_display_disconnect().
  58. *
  59. * A wl_display is also used as the \ref wl_proxy for the wl_display
  60. * singleton object on the compositor side.
  61. *
  62. * A wl_display object handles all the data sent from and to the
  63. * compositor. When a \ref wl_proxy marshals a request, it will write its wire
  64. * representation to the display's write buffer. The data is sent to the
  65. * compositor when the client calls \ref wl_display_flush().
  66. *
  67. * Incoming data is handled in two steps: queueing and dispatching. In the
  68. * queue step, the data coming from the display fd is interpreted and
  69. * added to a queue. On the dispatch step, the handler for the incoming
  70. * event set by the client on the corresponding \ref wl_proxy is called.
  71. *
  72. * A wl_display has at least one event queue, called the <em>default
  73. * queue</em>. Clients can create additional event queues with \ref
  74. * wl_display_create_queue() and assign \ref wl_proxy's to it. Events
  75. * occurring in a particular proxy are always queued in its assigned queue.
  76. * A client can ensure that a certain assumption, such as holding a lock
  77. * or running from a given thread, is true when a proxy event handler is
  78. * called by assigning that proxy to an event queue and making sure that
  79. * this queue is only dispatched when the assumption holds.
  80. *
  81. * The default queue is dispatched by calling \ref wl_display_dispatch().
  82. * This will dispatch any events queued on the default queue and attempt
  83. * to read from the display fd if it's empty. Events read are then queued
  84. * on the appropriate queues according to the proxy assignment.
  85. *
  86. * A user created queue is dispatched with \ref wl_display_dispatch_queue().
  87. * This function behaves exactly the same as wl_display_dispatch()
  88. * but it dispatches given queue instead of the default queue.
  89. *
  90. * A real world example of event queue usage is Mesa's implementation of
  91. * eglSwapBuffers() for the Wayland platform. This function might need
  92. * to block until a frame callback is received, but dispatching the default
  93. * queue could cause an event handler on the client to start drawing
  94. * again. This problem is solved using another event queue, so that only
  95. * the events handled by the EGL code are dispatched during the block.
  96. *
  97. * This creates a problem where a thread dispatches a non-default
  98. * queue, reading all the data from the display fd. If the application
  99. * would call \em poll(2) after that it would block, even though there
  100. * might be events queued on the default queue. Those events should be
  101. * dispatched with \ref wl_display_dispatch_pending() or \ref
  102. * wl_display_dispatch_queue_pending() before flushing and blocking.
  103. */
  104. struct wl_display;
  105. /** \class wl_event_queue
  106. *
  107. * \brief A queue for \ref wl_proxy object events.
  108. *
  109. * Event queues allows the events on a display to be handled in a thread-safe
  110. * manner. See \ref wl_display for details.
  111. *
  112. */
  113. struct wl_event_queue;
  114. void
  115. wl_event_queue_destroy(struct wl_event_queue *queue);
  116. void
  117. wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
  118. void
  119. wl_proxy_marshal_array(struct wl_proxy *p, uint32_t opcode,
  120. union wl_argument *args);
  121. struct wl_proxy *
  122. wl_proxy_create(struct wl_proxy *factory,
  123. const struct wl_interface *interface);
  124. void *
  125. wl_proxy_create_wrapper(void *proxy);
  126. void
  127. wl_proxy_wrapper_destroy(void *proxy_wrapper);
  128. struct wl_proxy *
  129. wl_proxy_marshal_constructor(struct wl_proxy *proxy,
  130. uint32_t opcode,
  131. const struct wl_interface *interface,
  132. ...);
  133. struct wl_proxy *
  134. wl_proxy_marshal_constructor_versioned(struct wl_proxy *proxy,
  135. uint32_t opcode,
  136. const struct wl_interface *interface,
  137. uint32_t version,
  138. ...);
  139. struct wl_proxy *
  140. wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,
  141. uint32_t opcode, union wl_argument *args,
  142. const struct wl_interface *interface);
  143. struct wl_proxy *
  144. wl_proxy_marshal_array_constructor_versioned(struct wl_proxy *proxy,
  145. uint32_t opcode,
  146. union wl_argument *args,
  147. const struct wl_interface *interface,
  148. uint32_t version);
  149. void
  150. wl_proxy_destroy(struct wl_proxy *proxy);
  151. int
  152. wl_proxy_add_listener(struct wl_proxy *proxy,
  153. void (**implementation)(void), void *data);
  154. const void *
  155. wl_proxy_get_listener(struct wl_proxy *proxy);
  156. int
  157. wl_proxy_add_dispatcher(struct wl_proxy *proxy,
  158. wl_dispatcher_func_t dispatcher_func,
  159. const void * dispatcher_data, void *data);
  160. void
  161. wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
  162. void *
  163. wl_proxy_get_user_data(struct wl_proxy *proxy);
  164. uint32_t
  165. wl_proxy_get_version(struct wl_proxy *proxy);
  166. uint32_t
  167. wl_proxy_get_id(struct wl_proxy *proxy);
  168. const char *
  169. wl_proxy_get_class(struct wl_proxy *proxy);
  170. void
  171. wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
  172. struct wl_display *
  173. wl_display_connect(const char *name);
  174. struct wl_display *
  175. wl_display_connect_to_fd(int fd);
  176. void
  177. wl_display_disconnect(struct wl_display *display);
  178. int
  179. wl_display_get_fd(struct wl_display *display);
  180. int
  181. wl_display_dispatch(struct wl_display *display);
  182. int
  183. wl_display_dispatch_queue(struct wl_display *display,
  184. struct wl_event_queue *queue);
  185. int
  186. wl_display_dispatch_queue_pending(struct wl_display *display,
  187. struct wl_event_queue *queue);
  188. int
  189. wl_display_dispatch_pending(struct wl_display *display);
  190. int
  191. wl_display_get_error(struct wl_display *display);
  192. uint32_t
  193. wl_display_get_protocol_error(struct wl_display *display,
  194. const struct wl_interface **interface,
  195. uint32_t *id);
  196. int
  197. wl_display_flush(struct wl_display *display);
  198. int
  199. wl_display_roundtrip_queue(struct wl_display *display,
  200. struct wl_event_queue *queue);
  201. int
  202. wl_display_roundtrip(struct wl_display *display);
  203. struct wl_event_queue *
  204. wl_display_create_queue(struct wl_display *display);
  205. int
  206. wl_display_prepare_read_queue(struct wl_display *display,
  207. struct wl_event_queue *queue);
  208. int
  209. wl_display_prepare_read(struct wl_display *display);
  210. void
  211. wl_display_cancel_read(struct wl_display *display);
  212. int
  213. wl_display_read_events(struct wl_display *display);
  214. void
  215. wl_log_set_handler_client(wl_log_func_t handler);
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #endif