mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-02 09:01:39 -05:00
scanner: emit event wrapper functions for server
Generate typed wrapper functions for sending events in a server. This allows compile time type checking, unlike the existing method of calling the variadic function wl_resource_post_event(). The stuff in wayland-server.h had to be slightly reordered to have all (forward) declarations before use. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
parent
0d22d25b87
commit
86a5d17afe
2 changed files with 51 additions and 8 deletions
|
|
@ -560,6 +560,47 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
emit_event_wrappers(struct wl_list *message_list, struct interface *interface)
|
||||
{
|
||||
struct message *m;
|
||||
struct arg *a;
|
||||
|
||||
/* We provide hand written functions for the display object */
|
||||
if (strcmp(interface->name, "wl_display") == 0)
|
||||
return;
|
||||
|
||||
wl_list_for_each(m, message_list, link) {
|
||||
printf("static inline void\n"
|
||||
"%s_send_%s(struct wl_resource *resource_",
|
||||
interface->name, m->name);
|
||||
|
||||
wl_list_for_each(a, &m->arg_list, link) {
|
||||
printf(", ");
|
||||
switch (a->type) {
|
||||
case NEW_ID:
|
||||
case OBJECT:
|
||||
printf("struct wl_resource *");
|
||||
break;
|
||||
default:
|
||||
emit_type(a);
|
||||
}
|
||||
printf("%s", a->name);
|
||||
}
|
||||
|
||||
printf(")\n"
|
||||
"{\n"
|
||||
"\twl_resource_post_event(resource_, %s_%s",
|
||||
interface->uppercase_name, m->uppercase_name);
|
||||
|
||||
wl_list_for_each(a, &m->arg_list, link)
|
||||
printf(", %s", a->name);
|
||||
|
||||
printf(");\n");
|
||||
printf("}\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
static const char *indent(int n)
|
||||
{
|
||||
const char *whitespace[] = {
|
||||
|
|
@ -774,6 +815,7 @@ emit_header(struct protocol *protocol, int server)
|
|||
if (server) {
|
||||
emit_structs(&i->request_list, i);
|
||||
emit_opcodes(&i->event_list, i);
|
||||
emit_event_wrappers(&i->event_list, i);
|
||||
} else {
|
||||
emit_structs(&i->event_list, i);
|
||||
emit_opcodes(&i->request_list, i);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue