tools/virtiofsd: xattr name mapping examples
[qemu/ar7.git] / ui / spice-app.c
blob026124ef56a0ef26fbe3cf0a1aba5e4f3450d61d
1 /*
2 * QEMU external Spice client display driver
4 * Copyright (c) 2018 Marc-André Lureau <marcandre.lureau@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
27 #include <gio/gio.h>
29 #include "ui/console.h"
30 #include "qemu/config-file.h"
31 #include "qemu/option.h"
32 #include "qemu/cutils.h"
33 #include "qemu/module.h"
34 #include "qapi/error.h"
35 #include "io/channel-command.h"
36 #include "chardev/spice.h"
37 #include "sysemu/sysemu.h"
38 #include "qom/object.h"
40 static const char *tmp_dir;
41 static char *app_dir;
42 static char *sock_path;
44 struct VCChardev {
45 SpiceChardev parent;
48 struct VCChardevClass {
49 ChardevClass parent;
50 void (*parent_open)(Chardev *chr, ChardevBackend *backend,
51 bool *be_opened, Error **errp);
54 #define TYPE_CHARDEV_VC "chardev-vc"
55 OBJECT_DECLARE_TYPE(VCChardev, VCChardevClass, CHARDEV_VC)
57 static ChardevBackend *
58 chr_spice_backend_new(void)
60 ChardevBackend *be = g_new0(ChardevBackend, 1);
62 be->type = CHARDEV_BACKEND_KIND_SPICEPORT;
63 be->u.spiceport.data = g_new0(ChardevSpicePort, 1);
65 return be;
68 static void vc_chr_open(Chardev *chr,
69 ChardevBackend *backend,
70 bool *be_opened,
71 Error **errp)
73 VCChardevClass *vc = CHARDEV_VC_GET_CLASS(chr);
74 ChardevBackend *be;
75 const char *fqdn = NULL;
77 if (strstart(chr->label, "serial", NULL)) {
78 fqdn = "org.qemu.console.serial.0";
79 } else if (strstart(chr->label, "parallel", NULL)) {
80 fqdn = "org.qemu.console.parallel.0";
81 } else if (strstart(chr->label, "compat_monitor", NULL)) {
82 fqdn = "org.qemu.monitor.hmp.0";
85 be = chr_spice_backend_new();
86 be->u.spiceport.data->fqdn = fqdn ?
87 g_strdup(fqdn) : g_strdup_printf("org.qemu.console.%s", chr->label);
88 vc->parent_open(chr, be, be_opened, errp);
89 qapi_free_ChardevBackend(be);
92 static void vc_chr_set_echo(Chardev *chr, bool echo)
94 /* TODO: set echo for frontends QMP and qtest */
97 static void char_vc_class_init(ObjectClass *oc, void *data)
99 VCChardevClass *vc = CHARDEV_VC_CLASS(oc);
100 ChardevClass *cc = CHARDEV_CLASS(oc);
102 vc->parent_open = cc->open;
104 cc->parse = qemu_chr_parse_vc;
105 cc->open = vc_chr_open;
106 cc->chr_set_echo = vc_chr_set_echo;
109 static const TypeInfo char_vc_type_info = {
110 .name = TYPE_CHARDEV_VC,
111 .parent = TYPE_CHARDEV_SPICEPORT,
112 .instance_size = sizeof(VCChardev),
113 .class_init = char_vc_class_init,
114 .class_size = sizeof(VCChardevClass),
117 static void spice_app_atexit(void)
119 if (sock_path) {
120 unlink(sock_path);
122 if (tmp_dir) {
123 rmdir(tmp_dir);
125 g_free(sock_path);
126 g_free(app_dir);
129 static void spice_app_display_early_init(DisplayOptions *opts)
131 QemuOpts *qopts;
132 GError *err = NULL;
134 if (opts->has_full_screen) {
135 error_report("spice-app full-screen isn't supported yet.");
136 exit(1);
138 if (opts->has_window_close) {
139 error_report("spice-app window-close isn't supported yet.");
140 exit(1);
143 atexit(spice_app_atexit);
145 if (qemu_name) {
146 app_dir = g_build_filename(g_get_user_runtime_dir(),
147 "qemu", qemu_name, NULL);
148 if (g_mkdir_with_parents(app_dir, S_IRWXU) < -1) {
149 error_report("Failed to create directory %s: %s",
150 app_dir, strerror(errno));
151 exit(1);
153 } else {
154 app_dir = g_dir_make_tmp(NULL, &err);
155 tmp_dir = app_dir;
156 if (err) {
157 error_report("Failed to create temporary directory: %s",
158 err->message);
159 exit(1);
163 type_register(&char_vc_type_info);
165 sock_path = g_strjoin("", app_dir, "/", "spice.sock", NULL);
166 qopts = qemu_opts_create(qemu_find_opts("spice"), NULL, 0, &error_abort);
167 qemu_opt_set(qopts, "disable-ticketing", "on", &error_abort);
168 qemu_opt_set(qopts, "unix", "on", &error_abort);
169 qemu_opt_set(qopts, "addr", sock_path, &error_abort);
170 qemu_opt_set(qopts, "image-compression", "off", &error_abort);
171 qemu_opt_set(qopts, "streaming-video", "off", &error_abort);
172 #ifdef CONFIG_OPENGL
173 qemu_opt_set(qopts, "gl", opts->has_gl ? "on" : "off", &error_abort);
174 display_opengl = opts->has_gl;
175 #endif
178 static void spice_app_display_init(DisplayState *ds, DisplayOptions *opts)
180 ChardevBackend *be = chr_spice_backend_new();
181 QemuOpts *qopts;
182 GError *err = NULL;
183 gchar *uri;
185 be->u.spiceport.data->fqdn = g_strdup("org.qemu.monitor.qmp.0");
186 qemu_chardev_new("org.qemu.monitor.qmp", TYPE_CHARDEV_SPICEPORT,
187 be, NULL, &error_abort);
188 qopts = qemu_opts_create(qemu_find_opts("mon"),
189 NULL, 0, &error_fatal);
190 qemu_opt_set(qopts, "chardev", "org.qemu.monitor.qmp", &error_abort);
191 qemu_opt_set(qopts, "mode", "control", &error_abort);
193 qapi_free_ChardevBackend(be);
194 uri = g_strjoin("", "spice+unix://", app_dir, "/", "spice.sock", NULL);
195 info_report("Launching display with URI: %s", uri);
196 g_app_info_launch_default_for_uri(uri, NULL, &err);
197 if (err) {
198 error_report("Failed to launch %s URI: %s", uri, err->message);
199 error_report("You need a capable Spice client, "
200 "such as virt-viewer 8.0");
201 exit(1);
203 g_free(uri);
206 static QemuDisplay qemu_display_spice_app = {
207 .type = DISPLAY_TYPE_SPICE_APP,
208 .early_init = spice_app_display_early_init,
209 .init = spice_app_display_init,
212 static void register_spice_app(void)
214 qemu_display_register(&qemu_display_spice_app);
217 type_init(register_spice_app);