[PATCH 5/8] scanner: Send interface name and version for types new_id args

Kristian Høgsberg krh at bitplanet.net
Tue Oct 9 19:38:02 PDT 2012


This makes the scanner generate the code and meta data to send the
interface name and version when we pass a typeless new_id.  This way, the
generic factory mechanism provided by wl_display.bind can be provided by
any interface.
---
 protocol/wayland.xml |    6 ++----
 src/scanner.c        |   56 ++++++++++++++++++++++++++++++++++----------------
 2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index e9f8034..86b82b8 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -38,9 +38,7 @@
 	the identifier.
       </description>
       <arg name="name" type="uint" summary="unique number id for object"/>
-      <arg name="interface" type="string"/>
-      <arg name="version" type="uint"/>
-      <arg name="id" type="new_id" interface="wl_object"/>
+      <arg name="id" type="new_id"/>
     </request>
 
     <request name="sync">
@@ -58,7 +56,7 @@
 	The error event is sent out when a fatal (non-recoverable)
 	error has occurred.
       </description>
-      <arg name="object_id" type="object" interface="wl_object"/>
+      <arg name="object_id" type="object"/>
       <arg name="code" type="uint"/>
       <arg name="message" type="string"/>
     </event>
diff --git a/src/scanner.c b/src/scanner.c
index 0fc26e7..bf5df26 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -374,9 +374,8 @@ start_element(void *data, const char *element_name, const char **atts)
 		switch (arg->type) {
 		case NEW_ID:
 		case OBJECT:
-			if (interface_name == NULL)
-				fail(ctx, "no interface name given");
-			arg->interface_name = strdup(interface_name);
+			if (interface_name)
+				arg->interface_name = strdup(interface_name);
 			break;
 		default:
 			if (interface_name != NULL)
@@ -575,7 +574,7 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 		exit(EXIT_FAILURE);
 	}
 
-	if (!has_destructor)
+	if (!has_destructor && strcmp(interface->name, "wl_display") != 0)
 		printf("static inline void\n"
 		       "%s_destroy(struct %s *%s)\n"
 		       "{\n"
@@ -595,7 +594,9 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 				ret = a;
 		}
 
-		if (ret)
+		if (ret && ret->interface_name == NULL)
+			printf("static inline void *\n");
+		else if (ret)
 			printf("static inline struct %s *\n",
 			       ret->interface_name);
 		else
@@ -606,7 +607,11 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 		       interface->name, interface->name);
 
 		wl_list_for_each(a, &m->arg_list, link) {
-			if (a->type == NEW_ID)
+			if (a->type == NEW_ID && a->interface_name == NULL) {
+				printf(", const struct wl_interface *interface"
+				       ", uint32_t version");
+				continue;
+			} else if (a->type == NEW_ID)
 				continue;
 			printf(", ");
 			emit_type(a);
@@ -615,17 +620,21 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 
 		printf(")\n"
 		       "{\n");
-		if (ret)
+		if (ret) {
 			printf("\tstruct wl_proxy *%s;\n\n"
 			       "\t%s = wl_proxy_create("
-			       "(struct wl_proxy *) %s,\n"
-			       "\t\t\t     &%s_interface);\n"
-			       "\tif (!%s)\n"
+			       "(struct wl_proxy *) %s,\n",
+			       ret->name, ret->name, interface->name);
+			if (ret->interface_name == NULL)
+				printf("\t\t\t     interface);\n");
+			else
+				printf("\t\t\t     &%s_interface);\n",
+				       ret->interface_name);
+
+			printf("\tif (!%s)\n"
 			       "\t\treturn NULL;\n\n",
-			       ret->name,
-			       ret->name,
-			       interface->name, ret->interface_name,
 			       ret->name);
+		}
 
 		printf("\twl_proxy_marshal((struct wl_proxy *) %s,\n"
 		       "\t\t\t %s_%s",
@@ -634,8 +643,10 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 		       m->uppercase_name);
 
 		wl_list_for_each(a, &m->arg_list, link) {
+			if (a->type == NEW_ID && a->interface_name == NULL)
+				printf(", interface->name, version");
 			printf(", ");
-				printf("%s", a->name);
+			printf("%s", a->name);
 		}
 		printf(");\n");
 
@@ -645,8 +656,8 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
 			       interface->name);
 
 		if (ret)
-			printf("\n\treturn (struct %s *) %s;\n",
-			       ret->interface_name, ret->name);
+			printf("\n\treturn (void *) %s;\n",
+			       ret->name);
 
 		printf("}\n\n");
 	}
@@ -799,6 +810,11 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
 
 			if (is_interface && a->type == OBJECT)
 				printf("struct wl_resource *");
+			else if (is_interface && a->type == NEW_ID && a->interface_name == NULL)
+				printf("const char *interface, uint32_t version, uint32_t ");
+			else if (!is_interface && a->type == OBJECT && a->interface_name == NULL)
+				printf("struct wl_object *");
+
 			else if (!is_interface && a->type == NEW_ID)
 				printf("struct %s *", a->interface_name);
 			else
@@ -925,6 +941,9 @@ emit_types_forward_declarations(struct protocol *protocol,
 			switch (a->type) {
 			case NEW_ID:
 			case OBJECT:
+				if (!a->interface_name)
+					continue;
+
 				m->all_null = 0;
 				printf("extern const struct wl_interface %s_interface;\n",
 				       a->interface_name);
@@ -968,8 +987,7 @@ emit_types(struct protocol *protocol, struct wl_list *message_list)
 			switch (a->type) {
 			case NEW_ID:
 			case OBJECT:
-				if (strcmp(a->interface_name,
-					   "wl_object") != 0)
+				if (a->interface_name)
 					printf("\t&%s_interface,\n",
 					       a->interface_name);
 				else
@@ -1009,6 +1027,8 @@ emit_messages(struct wl_list *message_list,
 				printf("i");
 				break;
 			case NEW_ID:
+				if (a->interface_name == NULL)
+					printf("su");
 				printf("n");
 				break;
 			case UNSIGNED:
-- 
1.7.10.2



More information about the wayland-devel mailing list