[Spice-devel] [PATCH spice-gtk 2/2] Add a spice-controller-dump testing tool

Christophe Fergeau cfergeau at redhat.com
Wed Feb 29 08:45:00 PST 2012


On Wed, Feb 29, 2012 at 03:04:18PM +0100, Marc-André Lureau wrote:
> By default, start a controller listener.
> If ran with --menu, start a foreign-menu listener.

ACK for this one too

> ---
>  gtk/controller/Makefile.am |    5 ++-
>  gtk/controller/dump.c      |  117 ++++++++++++++++++++++++++++++++++++++++++++
>  gtk/controller/test.c      |   21 ++++++--
>  3 files changed, 137 insertions(+), 6 deletions(-)
>  create mode 100644 gtk/controller/dump.c
> 
> diff --git a/gtk/controller/Makefile.am b/gtk/controller/Makefile.am
> index 20f1a48..916309e 100644
> --- a/gtk/controller/Makefile.am
> +++ b/gtk/controller/Makefile.am
> @@ -20,7 +20,7 @@ AM_VALAFLAGS =							\
>  	$(NULL)
>  
>  lib_LTLIBRARIES = libspice-controller.la
> -noinst_PROGRAMS = test-controller
> +noinst_PROGRAMS = test-controller spice-controller-dump
>  
>  BUILT_SOURCES = controller.vala.stamp
>  
> @@ -60,6 +60,9 @@ libspice_controllerinclude_HEADERS =		\
>  test_controller_SOURCES = test.c
>  test_controller_LDADD = libspice-controller.la
>  
> +spice_controller_dump_SOURCES = dump.c
> +spice_controller_dump_LDADD = libspice-controller.la
> +
>  controller.vala.stamp: $(libspice_controller_la_VALASOURCES) custom.vapi
>  	@if test -z "$(VALAC)"; then \
>  		echo "" ; \
> diff --git a/gtk/controller/dump.c b/gtk/controller/dump.c
> new file mode 100644
> index 0000000..6541dec
> --- /dev/null
> +++ b/gtk/controller/dump.c
> @@ -0,0 +1,117 @@
> +/* Copyright (C) 2011 Red Hat, Inc. */
> +
> +/* This library is free software; you can redistribute it and/or */
> +/* modify it under the terms of the GNU Lesser General Public */
> +/* License as published by the Free Software Foundation; either */
> +/* version 2.1 of the License, or (at your option) any later version. */
> +
> +/* This library is distributed in the hope that it will be useful, */
> +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
> +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU */
> +/* Lesser General Public License for more details. */
> +
> +/* You should have received a copy of the GNU Lesser General Public */
> +/* License along with this library; if not, see <http://www.gnu.org/licenses/>. */
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <stdio.h>
> +#include <stdint.h>
> +
> +#ifdef WIN32
> +#include <windows.h>
> +#else
> +#include <sys/socket.h>
> +#include <sys/types.h>
> +#include <sys/un.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <errno.h>
> +#endif
> +
> +#include "spice-controller.h"
> +
> +SpiceCtrlController *ctrl = NULL;
> +SpiceCtrlForeignMenu *menu = NULL;
> +GMainLoop *loop = NULL;
> +
> +void signaled (GObject *gobject, const gchar *signal_name)
> +{
> +    g_message ("signaled: %s", signal_name);
> +}
> +
> +void notified (GObject *gobject, GParamSpec *pspec,
> +               gpointer user_data)
> +{
> +    GValue value = { 0, };
> +    GValue strvalue = { 0, };
> +
> +    g_return_if_fail (gobject != NULL);
> +    g_return_if_fail (pspec != NULL);
> +
> +    g_value_init (&value, pspec->value_type);
> +    g_value_init (&strvalue, G_TYPE_STRING);
> +    g_object_get_property (gobject, pspec->name, &value);
> +
> +    if (pspec->value_type == G_TYPE_STRV) {
> +      gchar** p = (gchar **)g_value_get_boxed (&value);
> +      g_message ("notify::%s == ", pspec->name);
> +      while (*p)
> +        g_message ("%s", *p++);
> +    } else if (G_TYPE_IS_OBJECT(pspec->value_type)) {
> +      GObject *o = g_value_get_object (&value);
> +      g_message ("notify::%s == %s", pspec->name, o ? G_OBJECT_TYPE_NAME (o) : "null");
> +    } else {
> +      g_value_transform (&value, &strvalue);
> +      g_message ("notify::%s  = %s", pspec->name, g_value_get_string (&strvalue));
> +    }
> +
> +    g_value_unset (&value);
> +    g_value_unset (&strvalue);
> +}
> +
> +void connect_signals (gpointer obj)
> +{
> +    guint i, n_ids = 0;
> +    guint *ids = NULL;
> +    GType type = G_OBJECT_TYPE (obj);
> +
> +    ids = g_signal_list_ids (type, &n_ids);
> +    for (i = 0; i < n_ids; i++) {
> +        const gchar *name = g_signal_name (ids[i]);
> +        g_signal_connect (obj, name, G_CALLBACK (signaled), (gpointer)name);
> +    }
> +}
> +
> +int main (int argc, char *argv[])
> +{
> +    g_type_init ();
> +    loop = g_main_loop_new (NULL, FALSE);
> +
> +    if (argc > 1 && g_str_equal(argv[1], "--menu")) {
> +        menu = spice_ctrl_foreign_menu_new ();
> +        g_signal_connect (menu, "notify", G_CALLBACK (notified), NULL);
> +        connect_signals (menu);
> +
> +        spice_ctrl_foreign_menu_listen (menu, NULL, NULL, NULL);
> +    } else {
> +        ctrl = spice_ctrl_controller_new ();
> +        g_signal_connect (ctrl, "notify", G_CALLBACK (notified), NULL);
> +        connect_signals (ctrl);
> +
> +        spice_ctrl_controller_listen (ctrl, NULL, NULL, NULL);
> +    }
> +
> +    g_main_loop_run (loop);
> +
> +    if (ctrl != NULL)
> +        g_object_unref (ctrl);
> +    if (menu != NULL)
> +        g_object_unref (menu);
> +
> +    return 0;
> +}
> +
> diff --git a/gtk/controller/test.c b/gtk/controller/test.c
> index e43d299..3f3eb55 100644
> --- a/gtk/controller/test.c
> +++ b/gtk/controller/test.c
> @@ -174,9 +174,9 @@ void notified (GObject    *gobject, GParamSpec *pspec,
>        g_message ("notify::%s == ", pspec->name);
>        while (*p)
>          g_message ("%s", *p++);
> -    } else if (pspec->value_type == G_TYPE_OBJECT) {
> +    } else if (G_TYPE_IS_OBJECT(pspec->value_type)) {
>        GObject *o = g_value_get_object (&value);
> -      g_message ("notify::%s == %s", pspec->name, G_OBJECT_TYPE_NAME (o));
> +      g_message ("notify::%s == %s", pspec->name, o ? G_OBJECT_TYPE_NAME (o) : "null");
>      } else {
>        g_value_transform (&value, &strvalue);
>        g_message ("notify::%s  = %s", pspec->name, g_value_get_string (&strvalue));
> @@ -186,6 +186,19 @@ void notified (GObject    *gobject, GParamSpec *pspec,
>      g_value_unset (&strvalue);
>  }
>  
> +void connect_signals (gpointer obj)
> +{
> +    guint i, n_ids = 0;
> +    guint *ids = NULL;
> +    GType type = G_OBJECT_TYPE (obj);
> +
> +    ids = g_signal_list_ids (type, &n_ids);
> +    for (i = 0; i < n_ids; i++) {
> +        const gchar *name = g_signal_name (ids[i]);
> +        g_signal_connect (obj, name, G_CALLBACK (signaled), (gpointer)name);
> +    }
> +}
> +
>  int main (int argc, char *argv[])
>  {
>      int spicec_pid = (argc > 1 ? atoi (argv[1]) : 0);
> @@ -199,9 +212,7 @@ int main (int argc, char *argv[])
>      ctrl = spice_ctrl_controller_new ();
>      loop = g_main_loop_new (NULL, FALSE);
>      g_signal_connect (ctrl, "notify", G_CALLBACK (notified), NULL);
> -    g_signal_connect (ctrl, "show", G_CALLBACK (signaled), "show");
> -    g_signal_connect (ctrl, "hide", G_CALLBACK (signaled), "hide");
> -    g_signal_connect (ctrl, "do_connect", G_CALLBACK (signaled), "do_connect");
> +    connect_signals (ctrl);
>  
>  #ifdef WIN32
>      snprintf (pipe_name, PIPE_NAME_MAX_LEN, PIPE_NAME, spicec_pid);
> -- 
> 1.7.7.6
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20120229/cba4ee5f/attachment.pgp>


More information about the Spice-devel mailing list