summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2012-03-02 15:16:33 +0200
committerPekka Paalanen <ppaalanen@gmail.com>2012-03-02 17:55:45 +0200
commit86a5d17afe71626d8a4f48781805c040d97d6c69 (patch)
tree65e6e90de2b711b60eedb8034bd50174f9eef5b3
parent0d22d25b8740688a4f243c70cdfd32bc05993778 (diff)
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>
-rw-r--r--src/scanner.c42
-rw-r--r--src/wayland-server.h17
2 files changed, 51 insertions, 8 deletions
diff --git a/src/scanner.c b/src/scanner.c
index 91e2ad2..48eea25 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -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);
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 49ab5b1..38e099e 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -30,7 +30,6 @@ extern "C" {
#include <sys/types.h>
#include <stdint.h>
#include "wayland-util.h"
-#include "wayland-server-protocol.h"
enum {
WL_EVENT_READABLE = 0x01,
@@ -121,6 +120,13 @@ struct wl_resource {
void *data;
};
+struct wl_buffer {
+ struct wl_resource resource;
+ int32_t width, height;
+ uint32_t busy_count;
+ void *user_data;
+};
+
struct wl_shm_callbacks {
void (*buffer_created)(struct wl_buffer *buffer);
@@ -131,13 +137,6 @@ struct wl_shm_callbacks {
void (*buffer_destroyed)(struct wl_buffer *buffer);
};
-struct wl_buffer {
- struct wl_resource resource;
- int32_t width, height;
- uint32_t busy_count;
- void *user_data;
-};
-
struct wl_listener {
struct wl_list link;
void (*func)(struct wl_listener *listener,
@@ -265,6 +264,8 @@ void wl_resource_post_error(struct wl_resource *resource,
uint32_t code, const char *msg, ...);
void wl_resource_post_no_memory(struct wl_resource *resource);
+#include "wayland-server-protocol.h"
+
void
wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
uint32_t msecs);