[PATCH wayland 5/6] Add wl_argument versions of event and request marshallers

Jason Ekstrand jason at jlekstrand.net
Fri Mar 8 20:28:15 PST 2013


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/wayland-client.c | 39 ++++++++++++++++++++++++++++++++++-----
 src/wayland-client.h |  2 ++
 src/wayland-server.c | 47 ++++++++++++++++++++++++++++++++++++-----------
 src/wayland-server.h |  4 ++++
 4 files changed, 76 insertions(+), 16 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 1b52e32..f07a1cd 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -356,16 +356,45 @@ wl_proxy_add_listener(struct wl_proxy *proxy,
 WL_EXPORT void
 wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
 {
-	struct wl_closure *closure;
+	union wl_argument args[WL_CLOSURE_MAX_ARGS];
 	va_list ap;
 
-	pthread_mutex_lock(&proxy->display->mutex);
-
 	va_start(ap, opcode);
-	closure = wl_closure_vmarshal(&proxy->object, opcode, ap,
-				      &proxy->object.interface->methods[opcode]);
+	wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature,
+				 args, WL_CLOSURE_MAX_ARGS, ap);
 	va_end(ap);
 
+	wl_proxy_marshal_a(proxy, opcode, args);
+}
+
+/** Prepare a request to be sent to the compositor
+ *
+ * \param proxy The proxy object
+ * \param opcode Opcode of the request to be sent
+ * \param args Extra arguments for the given request
+ *
+ * Translates the request given by opcode and the extra arguments into the
+ * wire format and write it to the connection buffer.  This version takes an
+ * array of the union type wl_argument.
+ *
+ * \note This is intended to be used by language bindings and not in
+ * non-generated code.
+ *
+ * \sa wl_proxy_marshal()
+ *
+ * \memberof wl_proxy
+ */
+WL_EXPORT void
+wl_proxy_marshal_a(struct wl_proxy *proxy, uint32_t opcode,
+		   union wl_argument *args)
+{
+	struct wl_closure *closure;
+
+	pthread_mutex_lock(&proxy->display->mutex);
+
+	closure = wl_closure_marshal(&proxy->object, opcode, args,
+				     &proxy->object.interface->methods[opcode]);
+
 	if (closure == NULL) {
 		fprintf(stderr, "Error marshalling request\n");
 		abort();
diff --git a/src/wayland-client.h b/src/wayland-client.h
index 8b1fd0d..442d221 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -122,6 +122,8 @@ struct wl_event_queue;
 void wl_event_queue_destroy(struct wl_event_queue *queue);
 
 void wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
+void wl_proxy_marshal_a(struct wl_proxy *p, uint32_t opcode,
+			union wl_argument *args);
 struct wl_proxy *wl_proxy_create(struct wl_proxy *factory,
 				 const struct wl_interface *interface);
 
diff --git a/src/wayland-server.c b/src/wayland-server.c
index dcb4435..1c6899e 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -113,16 +113,14 @@ destroy_client(void *data)
 }
 
 WL_EXPORT void
-wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
+wl_resource_post_event_a(struct wl_resource *resource, uint32_t opcode,
+			 union wl_argument *args)
 {
 	struct wl_closure *closure;
 	struct wl_object *object = &resource->object;
-	va_list ap;
 
-	va_start(ap, opcode);
-	closure = wl_closure_vmarshal(object, opcode, ap,
-				      &object->interface->events[opcode]);
-	va_end(ap);
+	closure = wl_closure_marshal(object, opcode, args,
+				     &object->interface->events[opcode]);
 
 	if (closure == NULL)
 		return;
@@ -137,19 +135,31 @@ wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
 	wl_closure_destroy(closure);
 }
 
-
 WL_EXPORT void
-wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
+wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
 {
-	struct wl_closure *closure;
+	union wl_argument args[WL_CLOSURE_MAX_ARGS];
 	struct wl_object *object = &resource->object;
 	va_list ap;
 
 	va_start(ap, opcode);
-	closure = wl_closure_vmarshal(object, opcode, ap,
-				      &object->interface->events[opcode]);
+	wl_argument_from_va_list(object->interface->events[opcode].signature,
+				 args, WL_CLOSURE_MAX_ARGS, ap);
 	va_end(ap);
 
+	wl_resource_post_event_a(resource, opcode, args);
+}
+
+WL_EXPORT void
+wl_resource_queue_event_a(struct wl_resource *resource, uint32_t opcode,
+			  union wl_argument *args)
+{
+	struct wl_closure *closure;
+	struct wl_object *object = &resource->object;
+
+	closure = wl_closure_marshal(object, opcode, args,
+				     &object->interface->events[opcode]);
+
 	if (closure == NULL)
 		return;
 
@@ -164,6 +174,21 @@ wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
 }
 
 WL_EXPORT void
+wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
+{
+	union wl_argument args[WL_CLOSURE_MAX_ARGS];
+	struct wl_object *object = &resource->object;
+	va_list ap;
+
+	va_start(ap, opcode);
+	wl_argument_from_va_list(object->interface->events[opcode].signature,
+				 args, WL_CLOSURE_MAX_ARGS, ap);
+	va_end(ap);
+
+	wl_resource_queue_event_a(resource, opcode, args);
+}
+
+WL_EXPORT void
 wl_resource_post_error(struct wl_resource *resource,
 		       uint32_t code, const char *msg, ...)
 {
diff --git a/src/wayland-server.h b/src/wayland-server.h
index b720f32..091e3d3 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -403,8 +403,12 @@ struct wl_seat {
  * - type=new_id:	(struct wl_object *) or (struct wl_resource *)
  * - type=object:	(struct wl_object *) or (struct wl_resource *)
  */
+void wl_resource_post_event_a(struct wl_resource *resource,
+			      uint32_t opcode, union wl_argument *args);
 void wl_resource_post_event(struct wl_resource *resource,
 			    uint32_t opcode, ...);
+void wl_resource_queue_event_a(struct wl_resource *resource,
+			       uint32_t opcode, union wl_argument *args);
 void wl_resource_queue_event(struct wl_resource *resource,
 			     uint32_t opcode, ...);
 
-- 
1.8.1.4



More information about the wayland-devel mailing list