summaryrefslogtreecommitdiffstats
path: root/src/controller/dump.c
blob: b260264fbc7b61468e70f7820ce5f74e15a04cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* 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/>. */

#include "config.h"

#include <stdio.h>
#include <stdint.h>

#ifdef WIN32
#include <windows.h>
#else
#include <sys/socket.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#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[])
{
    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;
}