[PATCH] wayland-server: Add APIs to get some structure's value

JengHyun Kang jhyuni.kang at samsung.com
Tue Jun 21 04:45:16 UTC 2016


This patch's purpose is getting global interface information
registerred in the server.
If global is created (used wl_global_create()),
information are saved in global_list.
But almost structures used in wayland is defined statically.
So it is hard to get structure's values in server side.

Added following APIs.
  - wl_display_get_global_list()
  - wl_global_get_interface()
  - wl_interface_get_name()
  - wl_interface_get_method_count()
  - wl_interface_get_methods()
  - wl_interface_get_event_count()
  - wl_interface_get_events()
  - wl_message_get_name()
  - wl_global_list_get_global()

You can get interface information to combine added APIs.
(Such as interface's name and events/requests name)

1st, you can get wl_list:global_list to use wl_display_get_global_list().
2nd, you can get length of wl_list to use wl_list_length() and
     wl_global to use wl_global_list_get_global().
     wl_global is saved in list, so you need index to get wl_global.
3rd, you can get wl_interface to use wl_global_get_interface().
4th, in wl_interface structure, there are so many information about
     interface name and events/requests information.
     so you can get information to use wl_interface_get_name(),
     wl_interface_get_method_count(), wl_interface_get_method(),
     wl_interface_get_event_count(), wl_interface_get_event().
---
 src/wayland-server.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/wayland-server.h | 27 ++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 19aa2e8..ac5c2e5 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -997,6 +997,63 @@ wl_global_destroy(struct wl_global *global)
 	free(global);
 }
 
+WL_EXPORT const struct wl_interface *
+wl_global_get_interface(struct wl_global *global)
+{
+	return global->interface;
+}
+
+WL_EXPORT struct wl_global *
+wl_global_list_get_global(struct wl_list *list, int idx)
+{
+	int i = 0;
+	struct wl_global *global;
+
+	wl_list_for_each(global, list, link)
+	{
+		if (idx == i) break;
+		i++;
+	}
+
+	return global;
+}
+
+WL_EXPORT const char *
+wl_interface_get_name(const struct wl_interface *interface)
+{
+	return interface->name;
+}
+
+WL_EXPORT int
+wl_interface_get_method_count(const struct wl_interface *interface)
+{
+	return interface->method_count;
+}
+
+WL_EXPORT const struct wl_message *
+wl_interface_get_methods(const struct wl_interface *interface)
+{
+	return interface->methods;
+}
+
+WL_EXPORT int
+wl_interface_get_event_count(const struct wl_interface *interface)
+{
+	return interface->event_count;
+}
+
+WL_EXPORT const struct wl_message *
+wl_interface_get_events(const struct wl_interface *interface)
+{
+	return interface->events;
+}
+
+WL_EXPORT const char *
+wl_message_get_name(const struct wl_message *message)
+{
+	return message->name;
+}
+
 /** Get the current serial number
  *
  * \param display The display object
@@ -1035,6 +1092,12 @@ wl_display_get_event_loop(struct wl_display *display)
 	return display->loop;
 }
 
+WL_EXPORT struct wl_list *
+wl_display_get_global_list(struct wl_display *display)
+{
+	return &display->global_list;
+}
+
 WL_EXPORT void
 wl_display_terminate(struct wl_display *display)
 {
diff --git a/src/wayland-server.h b/src/wayland-server.h
index a6e7951..3494641 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -92,6 +92,33 @@ wl_display_remove_global(struct wl_display *display,
 
 #endif
 
+struct wl_list *
+wl_display_get_global_list(struct wl_display *display);
+
+const struct wl_interface *
+wl_global_get_interface(struct wl_global *global);
+
+const char *
+wl_interface_get_name(const struct wl_interface *interface);
+
+int
+wl_interface_get_method_count(const struct wl_interface *interface);
+
+const struct wl_message *
+wl_interface_get_methods(const struct wl_interface *interface);
+
+int
+wl_interface_get_event_count(const struct wl_interface *interface);
+
+const struct wl_message *
+wl_interface_get_events(const struct wl_interface *interface);
+
+const char *
+wl_message_get_name(const struct wl_message *message);
+
+struct wl_global *
+wl_global_list_get_global(struct wl_list *list, int idx);
+
 #ifdef  __cplusplus
 }
 #endif
-- 
1.9.1



More information about the wayland-devel mailing list