[PATCH 1/2] Wayland logging functionality

Martin Minarik minarik11 at student.fiit.stuba.sk
Wed May 23 07:17:06 PDT 2012


The core libwayland libraries should not handle logging, only passing
the error messages to subscribed functions.
An application linked to libwayland-server or libwayland-client
will be able to set own functions (one per library) to handle error
messages.
---
 src/wayland-client.c  |    6 ++++++
 src/wayland-client.h  |    2 ++
 src/wayland-private.h |    2 ++
 src/wayland-server.c  |    6 ++++++
 src/wayland-server.h  |    2 ++
 src/wayland-util.c    |   18 ++++++++++++++++++
 src/wayland-util.h    |    8 ++++++++
 7 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 1a24abf..ecedd99 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -589,3 +589,9 @@ wl_proxy_get_id(struct wl_proxy *proxy)
 {
 	return proxy->object.id;
 }
+
+WL_EXPORT void
+wl_log_set_handler_client(wl_log_func_t handler)
+{
+	wl_log_handler = handler;
+}
diff --git a/src/wayland-client.h b/src/wayland-client.h
index 5c7fd2f..06dc6fe 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -96,6 +96,8 @@ uint32_t
 wl_display_get_global(struct wl_display *display,
 		      const char *interface, uint32_t version);
 
+void wl_log_set_handler_client(wl_log_func_t handler);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/wayland-private.h b/src/wayland-private.h
index 61b07a2..975d8c0 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -105,4 +105,6 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 void
 wl_closure_destroy(struct wl_closure *closure);
 
+extern wl_log_func_t wl_log_handler;
+
 #endif
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 6ccc097..9f07b88 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1178,3 +1178,9 @@ wl_client_new_object(struct wl_client *client,
 				    interface, implementation, id, data);
 
 }
+
+WL_EXPORT void
+wl_log_set_handler_server(wl_log_func_t handler)
+{
+	wl_log_handler = handler;
+}
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 31f6fe5..bf46e0a 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -417,6 +417,8 @@ wl_buffer_is_shm(struct wl_buffer *buffer);
 int
 wl_display_init_shm(struct wl_display *display);
 
+void wl_log_set_handler_server(wl_log_func_t handler);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 7bf8924..8df7a07 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <stdarg.h>
 
 #include "wayland-util.h"
 #include "wayland-private.h"
@@ -270,3 +271,20 @@ wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
 	for_each_helper(&map->client_entries, func, data);
 	for_each_helper(&map->server_entries, func, data);
 }
+
+void
+wl_log_noop_handler(const char *message, void * args)
+{
+}
+
+wl_log_func_t wl_log_handler = wl_log_noop_handler;
+
+
+void
+wl_log(const char *message, ...)
+{
+	va_list argp;
+	va_start(argp, message);
+	wl_log_handler(message, &argp);
+	va_end(argp);
+}
diff --git a/src/wayland-util.h b/src/wayland-util.h
index fa5c6c5..2dfe920 100644
--- a/src/wayland-util.h
+++ b/src/wayland-util.h
@@ -203,6 +203,14 @@ static inline wl_fixed_t wl_fixed_from_int(int i)
 	return i * 256;
 }
 
+typedef void (*wl_log_func_t)(const char *, void * args);
+
+/* Log to default handler */
+void wl_log(const char *message, ...);
+#define WL_PRINTF(...) wl_log(__VA_ARGS__)
+
+void wl_log_noop_handler(const char *message, void * args);
+
 #ifdef  __cplusplus
 }
 #endif
-- 
1.7.5.4



More information about the wayland-devel mailing list