Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 1 | #include "config-host.h" |
| 2 | #include "trace.h" |
| 3 | #include "ui/qemu-spice.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 4 | #include "sysemu/char.h" |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 5 | #include <spice.h> |
| 6 | #include <spice-experimental.h> |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 7 | #include <spice/protocol.h> |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 8 | |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 9 | #include "qemu/osdep.h" |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 10 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 11 | typedef struct SpiceCharDriver { |
| 12 | CharDriverState* chr; |
| 13 | SpiceCharDeviceInstance sin; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 14 | bool active; |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 15 | bool blocked; |
Alon Levy | b010cec | 2013-04-05 11:30:23 +0200 | [diff] [blame] | 16 | const uint8_t *datapos; |
| 17 | int datalen; |
Marc-André Lureau | 7a5448c | 2012-12-05 16:15:35 +0100 | [diff] [blame] | 18 | QLIST_ENTRY(SpiceCharDriver) next; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 19 | } SpiceCharDriver; |
| 20 | |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 21 | typedef struct SpiceCharSource { |
| 22 | GSource source; |
| 23 | SpiceCharDriver *scd; |
| 24 | } SpiceCharSource; |
| 25 | |
Marc-André Lureau | 7a5448c | 2012-12-05 16:15:35 +0100 | [diff] [blame] | 26 | static QLIST_HEAD(, SpiceCharDriver) spice_chars = |
| 27 | QLIST_HEAD_INITIALIZER(spice_chars); |
| 28 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 29 | static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) |
| 30 | { |
| 31 | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
| 32 | ssize_t out = 0; |
| 33 | ssize_t last_out; |
| 34 | uint8_t* p = (uint8_t*)buf; |
| 35 | |
| 36 | while (len > 0) { |
Hans de Goede | 75c439b | 2013-04-05 11:30:24 +0200 | [diff] [blame] | 37 | int can_write = qemu_chr_be_can_write(scd->chr); |
| 38 | last_out = MIN(len, can_write); |
Marc-André Lureau | 07a54d7 | 2012-12-05 16:15:32 +0100 | [diff] [blame] | 39 | if (last_out <= 0) { |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 40 | break; |
| 41 | } |
Anthony Liguori | fa5efcc | 2011-08-15 11:17:30 -0500 | [diff] [blame] | 42 | qemu_chr_be_write(scd->chr, p, last_out); |
Hans de Goede | 35106c2 | 2011-03-22 16:28:41 +0100 | [diff] [blame] | 43 | out += last_out; |
| 44 | len -= last_out; |
| 45 | p += last_out; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 46 | } |
| 47 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 48 | trace_spice_vmc_write(out, len + out); |
| 49 | return out; |
| 50 | } |
| 51 | |
| 52 | static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len) |
| 53 | { |
| 54 | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
| 55 | int bytes = MIN(len, scd->datalen); |
| 56 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 57 | if (bytes > 0) { |
| 58 | memcpy(buf, scd->datapos, bytes); |
| 59 | scd->datapos += bytes; |
| 60 | scd->datalen -= bytes; |
| 61 | assert(scd->datalen >= 0); |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 62 | } |
| 63 | if (scd->datalen == 0) { |
| 64 | scd->datapos = 0; |
| 65 | scd->blocked = false; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 66 | } |
| 67 | trace_spice_vmc_read(bytes, len); |
| 68 | return bytes; |
| 69 | } |
| 70 | |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 71 | #if SPICE_SERVER_VERSION >= 0x000c02 |
| 72 | static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event) |
| 73 | { |
| 74 | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
| 75 | int chr_event; |
| 76 | |
| 77 | switch (event) { |
| 78 | case SPICE_PORT_EVENT_BREAK: |
| 79 | chr_event = CHR_EVENT_BREAK; |
| 80 | break; |
| 81 | default: |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 85 | trace_spice_vmc_event(chr_event); |
| 86 | qemu_chr_be_event(scd->chr, chr_event); |
| 87 | } |
| 88 | #endif |
| 89 | |
Hans de Goede | f76e4c7 | 2011-11-19 10:22:44 +0100 | [diff] [blame] | 90 | static void vmc_state(SpiceCharDeviceInstance *sin, int connected) |
| 91 | { |
| 92 | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
| 93 | |
Hans de Goede | 16665b9 | 2013-03-26 11:07:53 +0100 | [diff] [blame] | 94 | if ((scd->chr->be_open && connected) || |
| 95 | (!scd->chr->be_open && !connected)) { |
Hans de Goede | f76e4c7 | 2011-11-19 10:22:44 +0100 | [diff] [blame] | 96 | return; |
| 97 | } |
| 98 | |
| 99 | qemu_chr_be_event(scd->chr, |
| 100 | connected ? CHR_EVENT_OPENED : CHR_EVENT_CLOSED); |
| 101 | } |
| 102 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 103 | static SpiceCharDeviceInterface vmc_interface = { |
| 104 | .base.type = SPICE_INTERFACE_CHAR_DEVICE, |
| 105 | .base.description = "spice virtual channel char device", |
| 106 | .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR, |
| 107 | .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR, |
Hans de Goede | f76e4c7 | 2011-11-19 10:22:44 +0100 | [diff] [blame] | 108 | .state = vmc_state, |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 109 | .write = vmc_write, |
| 110 | .read = vmc_read, |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 111 | #if SPICE_SERVER_VERSION >= 0x000c02 |
| 112 | .event = vmc_event, |
| 113 | #endif |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | |
| 117 | static void vmc_register_interface(SpiceCharDriver *scd) |
| 118 | { |
| 119 | if (scd->active) { |
| 120 | return; |
| 121 | } |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 122 | scd->sin.base.sif = &vmc_interface.base; |
| 123 | qemu_spice_add_interface(&scd->sin.base); |
| 124 | scd->active = true; |
| 125 | trace_spice_vmc_register_interface(scd); |
| 126 | } |
| 127 | |
| 128 | static void vmc_unregister_interface(SpiceCharDriver *scd) |
| 129 | { |
| 130 | if (!scd->active) { |
| 131 | return; |
| 132 | } |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 133 | spice_server_remove_interface(&scd->sin.base); |
| 134 | scd->active = false; |
| 135 | trace_spice_vmc_unregister_interface(scd); |
| 136 | } |
| 137 | |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 138 | static gboolean spice_char_source_prepare(GSource *source, gint *timeout) |
| 139 | { |
| 140 | SpiceCharSource *src = (SpiceCharSource *)source; |
| 141 | |
| 142 | *timeout = -1; |
| 143 | |
| 144 | return !src->scd->blocked; |
| 145 | } |
| 146 | |
| 147 | static gboolean spice_char_source_check(GSource *source) |
| 148 | { |
| 149 | SpiceCharSource *src = (SpiceCharSource *)source; |
| 150 | |
| 151 | return !src->scd->blocked; |
| 152 | } |
| 153 | |
| 154 | static gboolean spice_char_source_dispatch(GSource *source, |
| 155 | GSourceFunc callback, gpointer user_data) |
| 156 | { |
| 157 | GIOFunc func = (GIOFunc)callback; |
| 158 | |
| 159 | return func(NULL, G_IO_OUT, user_data); |
| 160 | } |
| 161 | |
| 162 | GSourceFuncs SpiceCharSourceFuncs = { |
| 163 | .prepare = spice_char_source_prepare, |
| 164 | .check = spice_char_source_check, |
| 165 | .dispatch = spice_char_source_dispatch, |
| 166 | }; |
| 167 | |
| 168 | static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond) |
| 169 | { |
| 170 | SpiceCharDriver *scd = chr->opaque; |
| 171 | SpiceCharSource *src; |
| 172 | |
| 173 | assert(cond == G_IO_OUT); |
| 174 | |
| 175 | src = (SpiceCharSource *)g_source_new(&SpiceCharSourceFuncs, |
| 176 | sizeof(SpiceCharSource)); |
| 177 | src->scd = scd; |
| 178 | |
| 179 | return (GSource *)src; |
| 180 | } |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 181 | |
| 182 | static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len) |
| 183 | { |
| 184 | SpiceCharDriver *s = chr->opaque; |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 185 | int read_bytes; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 186 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 187 | assert(s->datalen == 0); |
Alon Levy | b010cec | 2013-04-05 11:30:23 +0200 | [diff] [blame] | 188 | s->datapos = buf; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 189 | s->datalen = len; |
| 190 | spice_server_char_device_wakeup(&s->sin); |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 191 | read_bytes = len - s->datalen; |
| 192 | if (read_bytes != len) { |
| 193 | /* We'll get passed in the unconsumed data with the next call */ |
| 194 | s->datalen = 0; |
| 195 | s->datapos = NULL; |
| 196 | s->blocked = true; |
| 197 | } |
| 198 | return read_bytes; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static void spice_chr_close(struct CharDriverState *chr) |
| 202 | { |
| 203 | SpiceCharDriver *s = chr->opaque; |
| 204 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 205 | vmc_unregister_interface(s); |
Marc-André Lureau | 7a5448c | 2012-12-05 16:15:35 +0100 | [diff] [blame] | 206 | QLIST_REMOVE(s, next); |
Hans de Goede | 5e9b473 | 2013-03-13 10:41:31 +0100 | [diff] [blame] | 207 | |
| 208 | g_free((char *)s->sin.subtype); |
| 209 | #if SPICE_SERVER_VERSION >= 0x000c02 |
| 210 | g_free((char *)s->sin.portname); |
| 211 | #endif |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 212 | g_free(s); |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 215 | static void spice_vmc_set_fe_open(struct CharDriverState *chr, int fe_open) |
Hans de Goede | cd8f7df | 2011-03-24 11:12:04 +0100 | [diff] [blame] | 216 | { |
| 217 | SpiceCharDriver *s = chr->opaque; |
Hans de Goede | 574b711 | 2013-03-26 11:07:58 +0100 | [diff] [blame] | 218 | if (fe_open) { |
| 219 | vmc_register_interface(s); |
| 220 | } else { |
| 221 | vmc_unregister_interface(s); |
| 222 | } |
Hans de Goede | cd8f7df | 2011-03-24 11:12:04 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 225 | static void spice_port_set_fe_open(struct CharDriverState *chr, int fe_open) |
| 226 | { |
| 227 | #if SPICE_SERVER_VERSION >= 0x000c02 |
| 228 | SpiceCharDriver *s = chr->opaque; |
| 229 | |
| 230 | if (fe_open) { |
| 231 | spice_server_port_event(&s->sin, SPICE_PORT_EVENT_OPENED); |
| 232 | } else { |
| 233 | spice_server_port_event(&s->sin, SPICE_PORT_EVENT_CLOSED); |
| 234 | } |
| 235 | #endif |
| 236 | } |
| 237 | |
Marc-André Lureau | be733d6 | 2013-12-01 22:23:40 +0100 | [diff] [blame] | 238 | static void spice_chr_fe_event(struct CharDriverState *chr, int event) |
| 239 | { |
| 240 | #if SPICE_SERVER_VERSION >= 0x000c02 |
| 241 | SpiceCharDriver *s = chr->opaque; |
| 242 | |
| 243 | spice_server_port_event(&s->sin, event); |
| 244 | #endif |
| 245 | } |
| 246 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 247 | static void print_allowed_subtypes(void) |
| 248 | { |
| 249 | const char** psubtype; |
| 250 | int i; |
| 251 | |
| 252 | fprintf(stderr, "allowed names: "); |
| 253 | for(i=0, psubtype = spice_server_char_device_recognized_subtypes(); |
| 254 | *psubtype != NULL; ++psubtype, ++i) { |
| 255 | if (i == 0) { |
| 256 | fprintf(stderr, "%s", *psubtype); |
| 257 | } else { |
| 258 | fprintf(stderr, ", %s", *psubtype); |
| 259 | } |
| 260 | } |
| 261 | fprintf(stderr, "\n"); |
| 262 | } |
| 263 | |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 264 | static CharDriverState *chr_open(const char *subtype, |
| 265 | void (*set_fe_open)(struct CharDriverState *, int)) |
| 266 | |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 267 | { |
| 268 | CharDriverState *chr; |
| 269 | SpiceCharDriver *s; |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 270 | |
| 271 | chr = g_malloc0(sizeof(CharDriverState)); |
| 272 | s = g_malloc0(sizeof(SpiceCharDriver)); |
| 273 | s->chr = chr; |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 274 | s->active = false; |
Hans de Goede | 5e9b473 | 2013-03-13 10:41:31 +0100 | [diff] [blame] | 275 | s->sin.subtype = g_strdup(subtype); |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 276 | chr->opaque = s; |
| 277 | chr->chr_write = spice_chr_write; |
Hans de Goede | ae893e5 | 2013-04-05 11:30:22 +0200 | [diff] [blame] | 278 | chr->chr_add_watch = spice_chr_add_watch; |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 279 | chr->chr_close = spice_chr_close; |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 280 | chr->chr_set_fe_open = set_fe_open; |
Michael Roth | bd5c51e | 2013-06-07 15:19:53 -0500 | [diff] [blame] | 281 | chr->explicit_be_open = true; |
Marc-André Lureau | be733d6 | 2013-12-01 22:23:40 +0100 | [diff] [blame] | 282 | chr->chr_fe_event = spice_chr_fe_event; |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 283 | |
Marc-André Lureau | 7a5448c | 2012-12-05 16:15:35 +0100 | [diff] [blame] | 284 | QLIST_INSERT_HEAD(&spice_chars, s, next); |
| 285 | |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 286 | return chr; |
| 287 | } |
| 288 | |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 289 | CharDriverState *qemu_chr_open_spice_vmc(const char *type) |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 290 | { |
Marc-André Lureau | 71b423f | 2012-12-05 16:15:33 +0100 | [diff] [blame] | 291 | const char **psubtype = spice_server_char_device_recognized_subtypes(); |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 292 | |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 293 | if (type == NULL) { |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 294 | fprintf(stderr, "spice-qemu-char: missing name parameter\n"); |
| 295 | print_allowed_subtypes(); |
Markus Armbruster | 1f51470 | 2012-02-07 15:09:08 +0100 | [diff] [blame] | 296 | return NULL; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 297 | } |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 298 | for (; *psubtype != NULL; ++psubtype) { |
| 299 | if (strcmp(type, *psubtype) == 0) { |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 303 | if (*psubtype == NULL) { |
| 304 | fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type); |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 305 | print_allowed_subtypes(); |
Markus Armbruster | 1f51470 | 2012-02-07 15:09:08 +0100 | [diff] [blame] | 306 | return NULL; |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 309 | return chr_open(type, spice_vmc_set_fe_open); |
Alon Levy | cbcc633 | 2011-01-19 10:49:50 +0200 | [diff] [blame] | 310 | } |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 311 | |
| 312 | #if SPICE_SERVER_VERSION >= 0x000c02 |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 313 | CharDriverState *qemu_chr_open_spice_port(const char *name) |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 314 | { |
| 315 | CharDriverState *chr; |
| 316 | SpiceCharDriver *s; |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 317 | |
| 318 | if (name == NULL) { |
| 319 | fprintf(stderr, "spice-qemu-char: missing name parameter\n"); |
| 320 | return NULL; |
| 321 | } |
| 322 | |
Marc-André Lureau | 8909114 | 2014-01-11 00:20:24 +0100 | [diff] [blame] | 323 | chr = chr_open("port", spice_port_set_fe_open); |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 324 | s = chr->opaque; |
Hans de Goede | 5e9b473 | 2013-03-13 10:41:31 +0100 | [diff] [blame] | 325 | s->sin.portname = g_strdup(name); |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 326 | |
| 327 | return chr; |
| 328 | } |
Marc-André Lureau | afd0b40 | 2012-12-05 16:15:36 +0100 | [diff] [blame] | 329 | |
| 330 | void qemu_spice_register_ports(void) |
| 331 | { |
| 332 | SpiceCharDriver *s; |
| 333 | |
| 334 | QLIST_FOREACH(s, &spice_chars, next) { |
| 335 | if (s->sin.portname == NULL) { |
| 336 | continue; |
| 337 | } |
| 338 | vmc_register_interface(s); |
| 339 | } |
| 340 | } |
Marc-André Lureau | 5a49d3e | 2012-12-05 16:15:34 +0100 | [diff] [blame] | 341 | #endif |
Anthony Liguori | 26c6061 | 2013-03-05 23:21:29 +0530 | [diff] [blame] | 342 | |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 343 | static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend, |
| 344 | Error **errp) |
| 345 | { |
| 346 | const char *name = qemu_opt_get(opts, "name"); |
| 347 | |
| 348 | if (name == NULL) { |
| 349 | error_setg(errp, "chardev: spice channel: no name given"); |
| 350 | return; |
| 351 | } |
| 352 | backend->spicevmc = g_new0(ChardevSpiceChannel, 1); |
| 353 | backend->spicevmc->type = g_strdup(name); |
| 354 | } |
| 355 | |
| 356 | static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend, |
| 357 | Error **errp) |
| 358 | { |
| 359 | const char *name = qemu_opt_get(opts, "name"); |
| 360 | |
| 361 | if (name == NULL) { |
| 362 | error_setg(errp, "chardev: spice port: no name given"); |
| 363 | return; |
| 364 | } |
| 365 | backend->spiceport = g_new0(ChardevSpicePort, 1); |
| 366 | backend->spiceport->fqdn = g_strdup(name); |
| 367 | } |
| 368 | |
Anthony Liguori | 26c6061 | 2013-03-05 23:21:29 +0530 | [diff] [blame] | 369 | static void register_types(void) |
| 370 | { |
Gerd Hoffmann | cd153e2 | 2013-02-25 12:39:06 +0100 | [diff] [blame] | 371 | register_char_driver_qapi("spicevmc", CHARDEV_BACKEND_KIND_SPICEVMC, |
| 372 | qemu_chr_parse_spice_vmc); |
| 373 | register_char_driver_qapi("spiceport", CHARDEV_BACKEND_KIND_SPICEPORT, |
| 374 | qemu_chr_parse_spice_port); |
Anthony Liguori | 26c6061 | 2013-03-05 23:21:29 +0530 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | type_init(register_types); |