mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Use type strings for method and event signatures.
This commit is contained in:
		
							parent
							
								
									d4de54efe7
								
							
						
					
					
						commit
						87e0a384da
					
				
					 2 changed files with 56 additions and 125 deletions
				
			
		
							
								
								
									
										174
									
								
								wayland.c
									
										
									
									
									
								
							
							
						
						
									
										174
									
								
								wayland.c
									
										
									
									
									
								
							| 
						 | 
					@ -115,13 +115,6 @@ wl_surface_attach(struct wl_client *client,
 | 
				
			||||||
					 surface, name, width, height, stride);
 | 
										 surface, name, width, height, stride);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument attach_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
wl_surface_map(struct wl_client *client, struct wl_surface *surface,
 | 
					wl_surface_map(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
	       int32_t x, int32_t y, int32_t width, int32_t height)
 | 
						       int32_t x, int32_t y, int32_t width, int32_t height)
 | 
				
			||||||
| 
						 | 
					@ -141,13 +134,6 @@ wl_surface_map(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
				      surface, &surface->map);
 | 
									      surface, &surface->map);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument map_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
wl_surface_copy(struct wl_client *client, struct wl_surface *surface,
 | 
					wl_surface_copy(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
		int32_t dst_x, int32_t dst_y, uint32_t name, uint32_t stride,
 | 
							int32_t dst_x, int32_t dst_y, uint32_t name, uint32_t stride,
 | 
				
			||||||
| 
						 | 
					@ -161,19 +147,6 @@ wl_surface_copy(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
				       name, stride, x, y, width, height);
 | 
									       name, stride, x, y, width, height);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument copy_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
wl_surface_damage(struct wl_client *client, struct wl_surface *surface,
 | 
					wl_surface_damage(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
		  int32_t x, int32_t y, int32_t width, int32_t height)
 | 
							  int32_t x, int32_t y, int32_t width, int32_t height)
 | 
				
			||||||
| 
						 | 
					@ -185,24 +158,12 @@ wl_surface_damage(struct wl_client *client, struct wl_surface *surface,
 | 
				
			||||||
					 surface, x, y, width, height);
 | 
										 surface, x, y, width, height);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument damage_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_method surface_methods[] = {
 | 
					static const struct wl_method surface_methods[] = {
 | 
				
			||||||
	{ "destroy", wl_surface_destroy,
 | 
						{ "destroy", wl_surface_destroy, "" },
 | 
				
			||||||
	  0, NULL },
 | 
						{ "attach", wl_surface_attach, "uuuu" },
 | 
				
			||||||
	{ "attach", wl_surface_attach,
 | 
						{ "map", wl_surface_map, "iiii" },
 | 
				
			||||||
	  ARRAY_LENGTH(attach_arguments), attach_arguments },
 | 
						{ "copy", wl_surface_copy, "iiuuiiii" },
 | 
				
			||||||
	{ "map", wl_surface_map,
 | 
						{ "damage", wl_surface_damage, "iiii" }
 | 
				
			||||||
	  ARRAY_LENGTH(map_arguments), map_arguments },
 | 
					 | 
				
			||||||
	{ "copy", wl_surface_copy,
 | 
					 | 
				
			||||||
	  ARRAY_LENGTH(copy_arguments), copy_arguments },
 | 
					 | 
				
			||||||
	{ "damage", wl_surface_damage,
 | 
					 | 
				
			||||||
	  ARRAY_LENGTH(damage_arguments), damage_arguments }
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_interface surface_interface = {
 | 
					static const struct wl_interface surface_interface = {
 | 
				
			||||||
| 
						 | 
					@ -253,31 +214,33 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const struct wl_event *event;
 | 
						const struct wl_event *event;
 | 
				
			||||||
	struct wl_object *object;
 | 
						struct wl_object *object;
 | 
				
			||||||
	uint32_t args[10], size, *p;
 | 
						uint32_t args[10], size;
 | 
				
			||||||
	va_list ap;
 | 
						va_list ap;
 | 
				
			||||||
	int i;
 | 
						int i, count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	event = &sender->interface->events[opcode];
 | 
						event = &sender->interface->events[opcode];
 | 
				
			||||||
 | 
						count = strlen(event->signature) + 2;
 | 
				
			||||||
 | 
						assert(count <= ARRAY_LENGTH(args));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size = 0;
 | 
						size = 0;
 | 
				
			||||||
	va_start(ap, opcode);
 | 
						va_start(ap, opcode);
 | 
				
			||||||
	p = &args[2];
 | 
						for (i = 2; i < count; i++) {
 | 
				
			||||||
	for (i = 0; i < event->argument_count; i++) {
 | 
							switch (event->signature[i - 2]) {
 | 
				
			||||||
		switch (event->arguments[i].type) {
 | 
							case 'u':
 | 
				
			||||||
		case WL_ARGUMENT_UINT32:
 | 
							case 'i':
 | 
				
			||||||
			p[i] = va_arg(ap, uint32_t);
 | 
								args[i] = va_arg(ap, uint32_t);
 | 
				
			||||||
			size += sizeof p[i];
 | 
								size += sizeof args[i];
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_STRING:
 | 
							case 's':
 | 
				
			||||||
			/* FIXME */
 | 
								/* FIXME */
 | 
				
			||||||
			p[i] = 0;
 | 
								args[i] = 0;
 | 
				
			||||||
			size += sizeof p[i];
 | 
								size += sizeof args[i];
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_OBJECT:
 | 
							case 'o':
 | 
				
			||||||
			object = va_arg(ap, struct wl_object *);
 | 
								object = va_arg(ap, struct wl_object *);
 | 
				
			||||||
			p[i] = object->id;
 | 
								args[i] = object->id;
 | 
				
			||||||
			size += sizeof p[i];
 | 
								size += sizeof args[i];
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_NEW_ID:
 | 
					 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			assert(0);
 | 
								assert(0);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
| 
						 | 
					@ -298,7 +261,7 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
 | 
				
			||||||
	ffi_type *types[20];
 | 
						ffi_type *types[20];
 | 
				
			||||||
	ffi_cif cif;
 | 
						ffi_cif cif;
 | 
				
			||||||
	uint32_t *p, result;
 | 
						uint32_t *p, result;
 | 
				
			||||||
	int i;
 | 
						int i, j, count;
 | 
				
			||||||
	union {
 | 
						union {
 | 
				
			||||||
		uint32_t uint32;
 | 
							uint32_t uint32;
 | 
				
			||||||
		const char *string;
 | 
							const char *string;
 | 
				
			||||||
| 
						 | 
					@ -309,8 +272,9 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
 | 
				
			||||||
	struct wl_object *object;
 | 
						struct wl_object *object;
 | 
				
			||||||
	uint32_t data[64];
 | 
						uint32_t data[64];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (method->argument_count > ARRAY_LENGTH(types)) {
 | 
						count = strlen(method->signature) + 2;
 | 
				
			||||||
		printf("too many args (%d)\n", method->argument_count);
 | 
						if (count > ARRAY_LENGTH(types)) {
 | 
				
			||||||
 | 
							printf("too many args (%d)\n", count);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -329,31 +293,34 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_connection_copy(client->connection, data, size);
 | 
						wl_connection_copy(client->connection, data, size);
 | 
				
			||||||
	p = &data[2];
 | 
						p = &data[2];
 | 
				
			||||||
	for (i = 0; i < method->argument_count; i++) {
 | 
						j = 0;
 | 
				
			||||||
		switch (method->arguments[i].type) {
 | 
						for (i = 2; i < count; i++) {
 | 
				
			||||||
		case WL_ARGUMENT_UINT32:
 | 
							switch (method->signature[i - 2]) {
 | 
				
			||||||
			types[i + 2] = &ffi_type_uint32;
 | 
							case 'u':
 | 
				
			||||||
			values[i + 2].uint32 = *p;
 | 
							case 'i':
 | 
				
			||||||
 | 
								types[i] = &ffi_type_uint32;
 | 
				
			||||||
 | 
								values[i].uint32 = *p;
 | 
				
			||||||
			p++;
 | 
								p++;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_STRING:
 | 
							case 's':
 | 
				
			||||||
			types[i + 2] = &ffi_type_pointer;
 | 
								types[i] = &ffi_type_pointer;
 | 
				
			||||||
			/* FIXME */
 | 
								/* FIXME */
 | 
				
			||||||
			values[i + 2].uint32 = *p++;
 | 
								values[i].uint32 = *p++;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_OBJECT:
 | 
							case 'o':
 | 
				
			||||||
			types[i + 2] = &ffi_type_pointer;
 | 
								types[i] = &ffi_type_pointer;
 | 
				
			||||||
			object = wl_hash_lookup(&client->display->objects, *p);
 | 
								object = wl_hash_lookup(&client->display->objects, *p);
 | 
				
			||||||
			if (object == NULL)
 | 
								if (object == NULL)
 | 
				
			||||||
				printf("unknown object (%d)\n", *p);
 | 
									printf("unknown object (%d)\n", *p);
 | 
				
			||||||
			if (object->interface != method->arguments[i].data)
 | 
								if (object->interface != method->types[j])
 | 
				
			||||||
				printf("wrong object type\n");
 | 
									printf("wrong object type\n");
 | 
				
			||||||
			values[i + 2].object = object;
 | 
								values[i].object = object;
 | 
				
			||||||
			p++;
 | 
								p++;
 | 
				
			||||||
 | 
								j++;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case WL_ARGUMENT_NEW_ID:
 | 
							case 'n':
 | 
				
			||||||
			types[i + 2] = &ffi_type_uint32;
 | 
								types[i] = &ffi_type_uint32;
 | 
				
			||||||
			values[i + 2].new_id = *p;
 | 
								values[i].new_id = *p;
 | 
				
			||||||
			object = wl_hash_lookup(&client->display->objects, *p);
 | 
								object = wl_hash_lookup(&client->display->objects, *p);
 | 
				
			||||||
			if (object != NULL)
 | 
								if (object != NULL)
 | 
				
			||||||
				printf("object already exists (%d)\n", *p);
 | 
									printf("object already exists (%d)\n", *p);
 | 
				
			||||||
| 
						 | 
					@ -363,11 +330,10 @@ wl_client_demarshal(struct wl_client *client, struct wl_object *target,
 | 
				
			||||||
			printf("unknown type\n");
 | 
								printf("unknown type\n");
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		args[i + 2] = &values[i + 2];
 | 
							args[i] = &values[i];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ffi_prep_cif(&cif, FFI_DEFAULT_ABI, method->argument_count + 2,
 | 
						ffi_prep_cif(&cif, FFI_DEFAULT_ABI, count, &ffi_type_uint32, types);
 | 
				
			||||||
		     &ffi_type_uint32, types);
 | 
					 | 
				
			||||||
	ffi_call(&cif, FFI_FN(method->func), &result, args);
 | 
						ffi_call(&cif, FFI_FN(method->func), &result, args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -550,10 +516,6 @@ wl_display_create_surface(struct wl_client *client,
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument create_surface_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_NEW_ID }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
wl_display_commit(struct wl_client *client,
 | 
					wl_display_commit(struct wl_client *client,
 | 
				
			||||||
		  struct wl_display *display, uint32_t key)
 | 
							  struct wl_display *display, uint32_t key)
 | 
				
			||||||
| 
						 | 
					@ -571,47 +533,17 @@ wl_display_commit(struct wl_client *client,
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_argument commit_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_method display_methods[] = {
 | 
					static const struct wl_method display_methods[] = {
 | 
				
			||||||
	{ "create_surface", wl_display_create_surface,
 | 
						{ "create_surface", wl_display_create_surface, "n" },
 | 
				
			||||||
	  ARRAY_LENGTH(create_surface_arguments), create_surface_arguments },
 | 
						{ "commit", wl_display_commit, "u" }
 | 
				
			||||||
	{ "commit", wl_display_commit,
 | 
					 | 
				
			||||||
	  ARRAY_LENGTH(commit_arguments), commit_arguments },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_argument invalid_object_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_argument invalid_method_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_argument acknowledge_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct wl_argument frame_arguments[] = {
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 },
 | 
					 | 
				
			||||||
	{ WL_ARGUMENT_UINT32 }
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_event display_events[] = {
 | 
					static const struct wl_event display_events[] = {
 | 
				
			||||||
	{ "invalid_object",
 | 
						{ "invalid_object", "u" },
 | 
				
			||||||
	  ARRAY_LENGTH(invalid_object_arguments), invalid_object_arguments },
 | 
						{ "invalid_method", "uu" },
 | 
				
			||||||
	{ "invalid_method",
 | 
						{ "no_memory", "" },
 | 
				
			||||||
	  ARRAY_LENGTH(invalid_method_arguments), invalid_method_arguments },
 | 
						{ "acknowledge", "uu" },
 | 
				
			||||||
	{ "no_memory",
 | 
						{ "frame", "uu" }
 | 
				
			||||||
	  0, NULL },
 | 
					 | 
				
			||||||
	{ "acknowledge",
 | 
					 | 
				
			||||||
	  ARRAY_LENGTH(acknowledge_arguments), acknowledge_arguments },
 | 
					 | 
				
			||||||
	{ "frame",
 | 
					 | 
				
			||||||
	  ARRAY_LENGTH(frame_arguments), frame_arguments },
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wl_interface display_interface = {
 | 
					static const struct wl_interface display_interface = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,14 +74,13 @@ struct wl_argument {
 | 
				
			||||||
struct wl_method {
 | 
					struct wl_method {
 | 
				
			||||||
	const char *name;
 | 
						const char *name;
 | 
				
			||||||
	void *func;
 | 
						void *func;
 | 
				
			||||||
	int argument_count;
 | 
						const char *signature;
 | 
				
			||||||
	const struct wl_argument *arguments;
 | 
						const void **types;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_event {
 | 
					struct wl_event {
 | 
				
			||||||
	const char *name;
 | 
						const char *name;
 | 
				
			||||||
	int argument_count;
 | 
						const char *signature;
 | 
				
			||||||
	const struct wl_argument *arguments;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_interface {
 | 
					struct wl_interface {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue