Add a QA client and plugin 51/31451/1
authorManuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Fri, 5 Dec 2014 00:28:04 +0000 (01:28 +0100)
committerManuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Fri, 5 Dec 2014 00:28:04 +0000 (01:28 +0100)
We add a new "qa-plugin" package, which contains a Weston
plugin (disabled by default) and a client named "weston-
qa-client".

Currently, if the plugin is enabled in "weston.ini", the
client will retrieve a list of the currently displayed
surfaces along with their positions and sizes.

Change-Id: I881131f1985ef527dfd45e27a66edd5fce2d55c8
Signed-off-by: Manuel Bachmann <manuel.bachmann@open.eurogiciel.org>
packaging/weston-common.spec
src/COPYING
src/Makefile.am
src/configure.ac
src/qa-plugin/Makefile.am [new file with mode: 0644]
src/qa-plugin/qa-client.c [new file with mode: 0644]
src/qa-plugin/qa-plugin.c [new file with mode: 0644]
src/qa-plugin/qa.xml [new file with mode: 0644]
weston.ini

index 6faae7f..138d003 100644 (file)
@@ -25,6 +25,8 @@ BuildRequires:  pkgconfig(xkbcommon)
 BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(wayland-cursor)
 BuildRequires:  pkgconfig(wayland-egl)
+BuildRequires:  pkgconfig(wayland-scanner)
+BuildRequires:  pkgconfig(wayland-server)
 BuildRequires:  pkgconfig(egl)
 BuildRequires:  pkgconfig(glesv2)
 BuildRequires:  pkgconfig(pixman-1)
@@ -45,6 +47,12 @@ Summary: A small launcher for Wayland compositors
 
 %description tz-launcher
 A small launcher for Wayland compositors, which reads .desktop files from paths given on the command line or in a config file, and then displays them graphically.
+############ qa-plugin
+%package qa-plugin
+Summary: A Q&A plugin for Weston
+
+%description qa-plugin
+A small Weston plugin, disabled by default, which enables features such as listing surfaces along with positions and coordinates.
 ############
 
 %description
@@ -172,3 +180,10 @@ rm -f %{_unitdir_user}/default.target.requires/weston-user.service
 %license src/COPYING
 %{_bindir}/tz-launcher
 %{_bindir}/wl-pre
+
+%files qa-plugin
+%manifest %{name}.manifest
+%defattr(-,root,root)
+%license src/COPYING
+%{_bindir}/weston-qa-client
+%{_libdir}/weston/qa-plugin.so
index 6ba3d98..cfbf164 100644 (file)
@@ -2,6 +2,7 @@ Copyright © 2008-2012 Kristian Høgsberg
 Copyright © 2010-2012 Intel Corporation
 Copyright © 2011 Benjamin Franzke
 Copyright © 2012 Collabora, Ltd.
+Copyright © 2014 Manuel Bachmann
 
 Permission to use, copy, modify, distribute, and sell this software and its
 documentation for any purpose is hereby granted without fee, provided that
index ce29423..4c0a48e 100644 (file)
@@ -1,5 +1,7 @@
 bin_PROGRAMS =
 
+SUBDIRS=qa-plugin
+
 all-local :
 
 AM_CFLAGS = $(GCC_CFLAGS)
index 002bf69..d175d14 100644 (file)
@@ -93,6 +93,8 @@ PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0])
 
 PKG_CHECK_MODULES(CLIENT, [wayland-client cairo >= 1.10.0 xkbcommon wayland-cursor])
 
+PKG_CHECK_MODULES(SERVER, [wayland-server])
+
   # Only check for cairo-egl if a GL or GLES renderer requested
   AS_IF([test "x$cairo_modules" = "xcairo-glesv2"], [
     PKG_CHECK_MODULES(CAIRO_EGL, [wayland-egl egl >= 7.10 cairo-egl >= 1.11.3 $cairo_modules],
@@ -105,7 +107,14 @@ PKG_CHECK_MODULES(CLIENT, [wayland-client cairo >= 1.10.0 xkbcommon wayland-curs
 AM_CONDITIONAL(HAVE_CAIRO_GLESV2,
               [test "x$have_cairo_egl" = "xyes" -a "x$cairo_modules" = "xcairo-glesv2" -a "x$enable_egl" = "xyes"])
 
-AC_CONFIG_FILES([Makefile])
+AC_PATH_PROG([wayland_scanner], [wayland-scanner])
+if test x$wayland_scanner = x; then
+       AC_MSG_ERROR([wayland-scanner is needed to compile the qa plugin])
+fi
+
+PKG_CHECK_MODULES(WAYLAND_SCANNER, wayland-scanner)
+
+AC_CONFIG_FILES([Makefile qa-plugin/Makefile])
 
 AC_OUTPUT
 
diff --git a/src/qa-plugin/Makefile.am b/src/qa-plugin/Makefile.am
new file mode 100644 (file)
index 0000000..7d217f7
--- /dev/null
@@ -0,0 +1,45 @@
+bin_PROGRAMS =
+moduledir = $(libdir)/weston
+module_LTLIBRARIES =
+
+all-local :
+
+AM_CFLAGS = $(GCC_CFLAGS)
+
+AM_CPPFLAGS = 
+
+CLEANFILES =
+
+BUILT_SOURCES =                                        \
+       qa-protocol.c                           \
+       qa-server-protocol.h                    \
+       qa-client-protocol.h
+
+qa-protocol.c : qa.xml
+       $(wayland_scanner) code < $< > $@
+qa-server-protocol.h : qa.xml
+       $(wayland_scanner) server-header < $< > $@
+qa-client-protocol.h : qa.xml
+       $(wayland_scanner) client-header < $< > $@
+
+bin_PROGRAMS += weston-qa-client
+
+weston_qa_client_LDFLAGS = -export-dynamic
+weston_qa_client_CPPFLAGS = $(AM_CPPFLAGS)
+weston_qa_client_CFLAGS = $(GCC_CFLAGS) $(CLIENT_CFLAGS)
+weston_qa_client_LDADD = $(DLOPEN_LIBS) $(CLIENT_LIBS)
+
+weston_qa_client_SOURCES =                             \
+       qa-client.c                                     \
+       qa-protocol.c
+
+module_LTLIBRARIES += qa-plugin.la
+
+qa_plugin_la_LDFLAGS = -module -avoid-version
+qa_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -Wno-unused-result
+qa_plugin_la_CFLAGS = $(GCC_CFLAGS) $(SERVER_CFLAGS) $(PIXMAN_CFLAGS)
+qa_plugin_la_LIBADD = $(DLOPEN_LIBS) $(SERVER_LIBS) $(PIXMAN_LIBS)
+
+qa_plugin_la_SOURCES =                                 \
+       qa-plugin.c                                     \
+       qa-protocol.c
diff --git a/src/qa-plugin/qa-client.c b/src/qa-plugin/qa-client.c
new file mode 100644 (file)
index 0000000..24451f0
--- /dev/null
@@ -0,0 +1,87 @@
+ /* Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net> */
+
+#include <stdio.h>
+#include <string.h>
+#include <wayland-client.h>
+
+#include "qa-client-protocol.h"
+struct qa *qa = NULL;
+int done = 0;
+
+
+static void
+qa_handle_surface_list (void *data, struct qa *qa,
+                       const char *list)
+{
+       printf ("qa-client: SURFACES LIST :\n%s", list);
+       done = 1;
+}
+
+static const struct qa_listener qa_listener = {
+       qa_handle_surface_list
+};
+
+static void
+registry_handle_global (void *data, struct wl_registry *registry,
+                       uint32_t id, const char *interface, uint32_t version)
+{
+       if (strcmp (interface, "qa") == 0) {
+               qa = wl_registry_bind (registry, id,
+                                      &qa_interface, version);
+               printf ("qa-client: registered the \"qa\" interface.\n");
+       }
+}
+
+static void
+registry_handle_global_remove (void *data, struct wl_registry *registry,
+                              uint32_t name)
+{
+}
+
+static const struct wl_registry_listener registry_listener = {
+       registry_handle_global,
+       registry_handle_global_remove
+};
+
+
+int main (int argc, char *argv[])
+{
+       struct wl_display *display = NULL;
+       struct wl_registry *registry = NULL;
+       int res = 0;
+
+       display = wl_display_connect (NULL);
+       if (!display) {
+               printf ("qa-client: display error.\n");
+               printf ("Did you define XDG_RUNTIME_DIR ?\n");
+               return -1;
+       }
+
+       registry = wl_display_get_registry (display);
+       if (!registry) {
+               printf ("qa-client: registry error.\n");
+               return -1;
+       }
+
+       wl_registry_add_listener (registry, &registry_listener, NULL);
+
+       printf ("Waiting for the \"qa\" interface...\n");
+       while (!qa)
+               wl_display_roundtrip (display);
+
+
+       qa_add_listener (qa, &qa_listener, NULL);
+
+       qa_surface_list (qa);
+
+       while ((res != -1) && (done == 0))
+               res = wl_display_dispatch (display);
+
+
+       qa_destroy (qa);
+       wl_registry_destroy (registry);
+       wl_display_flush (display);
+       wl_display_disconnect (display);
+
+       return 0;
+}
diff --git a/src/qa-plugin/qa-plugin.c b/src/qa-plugin/qa-plugin.c
new file mode 100644 (file)
index 0000000..dc095d4
--- /dev/null
@@ -0,0 +1,83 @@
+ /* Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net> */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wayland-server.h>
+
+#include <weston/compositor.h>
+#include "qa-server-protocol.h"
+
+struct weston_compositor *ec = NULL;
+
+
+
+static void
+qa_surface_list (struct wl_client *client,
+                struct wl_resource *resource)
+{
+       struct weston_view *view;
+       char *resp, *temp;
+
+       weston_log ("qa-plugin: requested surfaces list...\n");
+
+       resp = strdup ("");
+
+       wl_list_for_each (view, &ec->view_list, link) { printf ("RHA ");
+               if ((view->surface) &&
+                   (view->geometry.x != 0.0) &&
+                   (view->geometry.y != 0.0)) {
+                       asprintf (&temp, "Surface %p : X+Y = %.2f+%.2f - WxH = %dx%d\n",
+                                 view->surface, view->geometry.x, view->geometry.y,
+                                 view->surface->width, view->surface->height);
+                       resp = realloc (resp, strlen(resp) + strlen (temp) + 1);
+                       strncat (resp, temp, strlen(temp));
+                       free (temp);
+               }
+       }
+
+       qa_send_list_surface (resource, resp);
+       free (resp);
+}
+
+static void
+qa_destroy (struct wl_client *client,
+           struct wl_resource *resource)
+{
+       wl_resource_destroy (resource);
+}
+
+static const struct qa_interface qa_implementation = {
+       qa_surface_list,
+       qa_destroy
+};
+
+static void
+bind_qa (struct wl_client *client, void *data,
+        uint32_t version, uint32_t id)
+{
+       struct wl_resource *resource;
+
+       resource = wl_resource_create (client, &qa_interface,
+                                      1, id);
+       wl_resource_set_implementation (resource, &qa_implementation,
+                                       NULL, NULL);
+}
+
+WL_EXPORT int
+module_init (struct weston_compositor *compositor,
+            int *argc, char *argv[])
+{
+       ec = compositor;
+
+       weston_log ("qa-plugin: initialization.\n");
+
+       if (wl_global_create (ec->wl_display, &qa_interface,
+                             1, NULL, bind_qa) == NULL)
+       {
+               weston_log ("qa-plugin: could not bind the \"qa\" interface, exiting...\n");
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/src/qa-plugin/qa.xml b/src/qa-plugin/qa.xml
new file mode 100644 (file)
index 0000000..b804b64
--- /dev/null
@@ -0,0 +1,14 @@
+<protocol name="qa">
+
+  <interface name="qa" version="1">
+
+    <request name="surface_list"/>
+    <request name="destroy" type="destructor"/>
+
+    <event name="list_surface">
+      <arg name="list" type="string"/>
+    </event>
+
+  </interface>
+
+</protocol>
index 23a2dc9..40d5695 100644 (file)
@@ -1,5 +1,6 @@
 [core]
 modules=desktop-shell.so
+#modules=desktop-shell.so,qa-plugin.so
 
 [shell]
 background-image=/usr/share/backgrounds/tizen/current