diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2014-06-24 13:06:13 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2014-06-24 13:06:13 +0100 |
commit | 089a39486f2c47994c6c0d34ac7abf34baf40d9d (patch) | |
tree | 07bf9220989162df8d29b99568d13ce6d5261822 /ui | |
parent | 27acb9dd2407f41550e453b85aa5ebf1bd618b79 (diff) | |
parent | d622cb5879ca8006d5482158e4e3b272a068c301 (diff) | |
download | qemu-089a39486f2c47994c6c0d34ac7abf34baf40d9d.zip qemu-089a39486f2c47994c6c0d34ac7abf34baf40d9d.tar.gz qemu-089a39486f2c47994c6c0d34ac7abf34baf40d9d.tar.bz2 |
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging
* remotes/qmp-unstable/queue/qmp: (43 commits)
monitor: protect event emission
monitor: protect outbuf and mux_out with mutex
qemu-char: make writes thread-safe
qemu-char: move pty_chr_update_read_handler around
qemu-char: do not call chr_write directly
qemu-char: introduce qemu_chr_alloc
qapi event: clean up
qapi event: convert QUORUM events
qapi event: convert GUEST_PANICKED
qapi event: convert BALLOON_CHANGE
qmp: convert ACPI_DEVICE_OST event
qapi event: convert SPICE events
qapi event: convert VNC events
qapi event: convert NIC_RX_FILTER_CHANGED
qapi event: convert other BLOCK_JOB events
qapi event: convert BLOCK_IMAGE_CORRUPTED
qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
qapi event: convert DEVICE_TRAY_MOVED
qapi event: convert DEVICE_DELETED
qapi event: convert WATCHDOG
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/console.c | 2 | ||||
-rw-r--r-- | ui/spice-core.c | 77 | ||||
-rw-r--r-- | ui/vnc.c | 120 | ||||
-rw-r--r-- | ui/vnc.h | 4 |
4 files changed, 105 insertions, 98 deletions
diff --git a/ui/console.c b/ui/console.c index 7dc4c14..ab84549 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1821,7 +1821,7 @@ static CharDriverState *text_console_init(ChardevVC *vc) unsigned width = 0; unsigned height = 0; - chr = g_malloc0(sizeof(CharDriverState)); + chr = qemu_chr_alloc(); if (vc->has_width) { width = vc->width; diff --git a/ui/spice-core.c b/ui/spice-core.c index d10818a..70df446 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -35,9 +35,9 @@ #include "qapi/qmp/qjson.h" #include "qemu/notify.h" #include "migration/migration.h" -#include "monitor/monitor.h" #include "hw/hw.h" #include "ui/spice-display.h" +#include "qapi-event.h" /* core bits */ @@ -174,39 +174,34 @@ static void channel_list_del(SpiceChannelEventInfo *info) } } -static void add_addr_info(QDict *dict, struct sockaddr *addr, int len) +static void add_addr_info(SpiceBasicInfo *info, struct sockaddr *addr, int len) { char host[NI_MAXHOST], port[NI_MAXSERV]; - const char *family; getnameinfo(addr, len, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); - family = inet_strfamily(addr->sa_family); - qdict_put(dict, "host", qstring_from_str(host)); - qdict_put(dict, "port", qstring_from_str(port)); - qdict_put(dict, "family", qstring_from_str(family)); + info->host = g_strdup(host); + info->port = g_strdup(port); + info->family = inet_netfamily(addr->sa_family); } -static void add_channel_info(QDict *dict, SpiceChannelEventInfo *info) +static void add_channel_info(SpiceChannel *sc, SpiceChannelEventInfo *info) { int tls = info->flags & SPICE_CHANNEL_EVENT_FLAG_TLS; - qdict_put(dict, "connection-id", qint_from_int(info->connection_id)); - qdict_put(dict, "channel-type", qint_from_int(info->type)); - qdict_put(dict, "channel-id", qint_from_int(info->id)); - qdict_put(dict, "tls", qbool_from_int(tls)); + sc->connection_id = info->connection_id; + sc->channel_type = info->type; + sc->channel_id = info->id; + sc->tls = !!tls; } static void channel_event(int event, SpiceChannelEventInfo *info) { - static const int qevent[] = { - [ SPICE_CHANNEL_EVENT_CONNECTED ] = QEVENT_SPICE_CONNECTED, - [ SPICE_CHANNEL_EVENT_INITIALIZED ] = QEVENT_SPICE_INITIALIZED, - [ SPICE_CHANNEL_EVENT_DISCONNECTED ] = QEVENT_SPICE_DISCONNECTED, - }; - QDict *server, *client; - QObject *data; + SpiceServerInfo *server = g_malloc0(sizeof(*server)); + SpiceChannel *client = g_malloc0(sizeof(*client)); + server->base = g_malloc0(sizeof(*server->base)); + client->base = g_malloc0(sizeof(*client->base)); /* * Spice server might have called us from spice worker thread @@ -222,36 +217,43 @@ static void channel_event(int event, SpiceChannelEventInfo *info) qemu_mutex_lock_iothread(); } - client = qdict_new(); - server = qdict_new(); - if (info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) { - add_addr_info(client, (struct sockaddr *)&info->paddr_ext, + add_addr_info(client->base, (struct sockaddr *)&info->paddr_ext, info->plen_ext); - add_addr_info(server, (struct sockaddr *)&info->laddr_ext, + add_addr_info(server->base, (struct sockaddr *)&info->laddr_ext, info->llen_ext); } else { error_report("spice: %s, extended address is expected", __func__); } - if (event == SPICE_CHANNEL_EVENT_INITIALIZED) { - qdict_put(server, "auth", qstring_from_str(auth)); + switch (event) { + case SPICE_CHANNEL_EVENT_CONNECTED: + qapi_event_send_spice_connected(server->base, client->base, &error_abort); + break; + case SPICE_CHANNEL_EVENT_INITIALIZED: + if (auth) { + server->has_auth = true; + server->auth = g_strdup(auth); + } add_channel_info(client, info); channel_list_add(info); - } - if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) { + qapi_event_send_spice_initialized(server, client, &error_abort); + break; + case SPICE_CHANNEL_EVENT_DISCONNECTED: channel_list_del(info); + qapi_event_send_spice_disconnected(server->base, client->base, &error_abort); + break; + default: + break; } - data = qobject_from_jsonf("{ 'client': %p, 'server': %p }", - QOBJECT(client), QOBJECT(server)); - monitor_protocol_event(qevent[event], data); - qobject_decref(data); - if (need_lock) { qemu_mutex_unlock_iothread(); } + + qapi_free_SpiceServerInfo(server); + qapi_free_SpiceChannel(client); } static SpiceCoreInterface core_interface = { @@ -305,7 +307,7 @@ static void migrate_connect_complete_cb(SpiceMigrateInstance *sin) static void migrate_end_complete_cb(SpiceMigrateInstance *sin) { - monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL); + qapi_event_send_spice_migrate_completed(&error_abort); spice_migration_completed = true; } @@ -391,15 +393,16 @@ static SpiceChannelList *qmp_query_spice_channels(void) chan = g_malloc0(sizeof(*chan)); chan->value = g_malloc0(sizeof(*chan->value)); + chan->value->base = g_malloc0(sizeof(*chan->value->base)); paddr = (struct sockaddr *)&item->info->paddr_ext; plen = item->info->plen_ext; getnameinfo(paddr, plen, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); - chan->value->host = g_strdup(host); - chan->value->port = g_strdup(port); - chan->value->family = g_strdup(inet_strfamily(paddr->sa_family)); + chan->value->base->host = g_strdup(host); + chan->value->base->port = g_strdup(port); + chan->value->base->family = inet_netfamily(paddr->sa_family); chan->value->connection_id = item->info->connection_id; chan->value->channel_type = item->info->type; @@ -35,6 +35,7 @@ #include "qmp-commands.h" #include "qemu/osdep.h" #include "ui/input.h" +#include "qapi-event.h" #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT #define VNC_REFRESH_INTERVAL_INC 50 @@ -124,9 +125,10 @@ char *vnc_socket_remote_addr(const char *format, int fd) { return addr_to_string(format, &sa, salen); } -static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa, - socklen_t salen) +static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa, + socklen_t salen) { + VncBasicInfo *info; char host[NI_MAXHOST]; char serv[NI_MAXSERV]; int err; @@ -137,40 +139,40 @@ static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa, NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { VNC_DEBUG("Cannot resolve address %d: %s\n", err, gai_strerror(err)); - return -1; + return NULL; } - qdict_put(qdict, "host", qstring_from_str(host)); - qdict_put(qdict, "service", qstring_from_str(serv)); - qdict_put(qdict, "family",qstring_from_str(inet_strfamily(sa->ss_family))); - - return 0; + info = g_malloc0(sizeof(VncBasicInfo)); + info->host = g_strdup(host); + info->service = g_strdup(serv); + info->family = inet_netfamily(sa->ss_family); + return info; } -static int vnc_server_addr_put(QDict *qdict, int fd) +static VncBasicInfo *vnc_basic_info_get_from_server_addr(int fd) { struct sockaddr_storage sa; socklen_t salen; salen = sizeof(sa); if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) { - return -1; + return NULL; } - return put_addr_qdict(qdict, &sa, salen); + return vnc_basic_info_get(&sa, salen); } -static int vnc_qdict_remote_addr(QDict *qdict, int fd) +static VncBasicInfo *vnc_basic_info_get_from_remote_addr(int fd) { struct sockaddr_storage sa; socklen_t salen; salen = sizeof(sa); if (getpeername(fd, (struct sockaddr*)&sa, &salen) < 0) { - return -1; + return NULL; } - return put_addr_qdict(qdict, &sa, salen); + return vnc_basic_info_get(&sa, salen); } static const char *vnc_auth_name(VncDisplay *vd) { @@ -224,81 +226,82 @@ static const char *vnc_auth_name(VncDisplay *vd) { return "unknown"; } -static int vnc_server_info_put(QDict *qdict) +static VncServerInfo *vnc_server_info_get(void) { - if (vnc_server_addr_put(qdict, vnc_display->lsock) < 0) { - return -1; + VncServerInfo *info; + VncBasicInfo *bi = vnc_basic_info_get_from_server_addr(vnc_display->lsock); + if (!bi) { + return NULL; } - qdict_put(qdict, "auth", qstring_from_str(vnc_auth_name(vnc_display))); - return 0; + info = g_malloc(sizeof(*info)); + info->base = bi; + info->has_auth = true; + info->auth = g_strdup(vnc_auth_name(vnc_display)); + return info; } static void vnc_client_cache_auth(VncState *client) { -#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL) - QDict *qdict; -#endif - if (!client->info) { return; } -#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL) - qdict = qobject_to_qdict(client->info); -#endif - #ifdef CONFIG_VNC_TLS if (client->tls.session && client->tls.dname) { - qdict_put(qdict, "x509_dname", qstring_from_str(client->tls.dname)); + client->info->has_x509_dname = true; + client->info->x509_dname = g_strdup(client->tls.dname); } #endif #ifdef CONFIG_VNC_SASL if (client->sasl.conn && client->sasl.username) { - qdict_put(qdict, "sasl_username", - qstring_from_str(client->sasl.username)); + client->info->has_sasl_username = true; + client->info->sasl_username = g_strdup(client->sasl.username); } #endif } static void vnc_client_cache_addr(VncState *client) { - QDict *qdict; + VncBasicInfo *bi = vnc_basic_info_get_from_remote_addr(client->csock); - qdict = qdict_new(); - if (vnc_qdict_remote_addr(qdict, client->csock) < 0) { - QDECREF(qdict); - /* XXX: how to report the error? */ - return; + if (bi) { + client->info = g_malloc0(sizeof(*client->info)); + client->info->base = bi; } - - client->info = QOBJECT(qdict); } -static void vnc_qmp_event(VncState *vs, MonitorEvent event) +static void vnc_qmp_event(VncState *vs, QAPIEvent event) { - QDict *server; - QObject *data; + VncServerInfo *si; if (!vs->info) { return; } + g_assert(vs->info->base); - server = qdict_new(); - if (vnc_server_info_put(server) < 0) { - QDECREF(server); + si = vnc_server_info_get(); + if (!si) { return; } - data = qobject_from_jsonf("{ 'client': %p, 'server': %p }", - vs->info, QOBJECT(server)); - - monitor_protocol_event(event, data); + switch (event) { + case QAPI_EVENT_VNC_CONNECTED: + qapi_event_send_vnc_connected(si, vs->info->base, &error_abort); + break; + case QAPI_EVENT_VNC_INITIALIZED: + qapi_event_send_vnc_initialized(si, vs->info, &error_abort); + break; + case QAPI_EVENT_VNC_DISCONNECTED: + qapi_event_send_vnc_disconnected(si, vs->info, &error_abort); + break; + default: + break; + } - qobject_incref(vs->info); - qobject_decref(data); + qapi_free_VncServerInfo(si); } static VncClientInfo *qmp_query_vnc_client(const VncState *client) @@ -321,9 +324,10 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) } info = g_malloc0(sizeof(*info)); - info->host = g_strdup(host); - info->service = g_strdup(serv); - info->family = g_strdup(inet_strfamily(sa.ss_family)); + info->base = g_malloc0(sizeof(*info->base)); + info->base->host = g_strdup(host); + info->base->service = g_strdup(serv); + info->base->family = inet_netfamily(sa.ss_family); #ifdef CONFIG_VNC_TLS if (client->tls.session && client->tls.dname) { @@ -398,7 +402,7 @@ VncInfo *qmp_query_vnc(Error **errp) info->service = g_strdup(serv); info->has_family = true; - info->family = g_strdup(inet_strfamily(sa.ss_family)); + info->family = inet_netfamily(sa.ss_family); info->has_auth = true; info->auth = g_strdup(vnc_auth_name(vnc_display)); @@ -1039,7 +1043,7 @@ void vnc_disconnect_finish(VncState *vs) vnc_jobs_join(vs); /* Wait encoding jobs */ vnc_lock_output(vs); - vnc_qmp_event(vs, QEVENT_VNC_DISCONNECTED); + vnc_qmp_event(vs, QAPI_EVENT_VNC_DISCONNECTED); buffer_free(&vs->input); buffer_free(&vs->output); @@ -1048,7 +1052,7 @@ void vnc_disconnect_finish(VncState *vs) buffer_free(&vs->ws_output); #endif /* CONFIG_VNC_WS */ - qobject_decref(vs->info); + qapi_free_VncClientInfo(vs->info); vnc_zlib_clear(vs); vnc_tight_clear(vs); @@ -2323,7 +2327,7 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) vnc_flush(vs); vnc_client_cache_auth(vs); - vnc_qmp_event(vs, QEVENT_VNC_INITIALIZED); + vnc_qmp_event(vs, QAPI_EVENT_VNC_INITIALIZED); vnc_read_when(vs, protocol_client_msg, 1); @@ -2846,7 +2850,7 @@ static void vnc_connect(VncDisplay *vd, int csock, } vnc_client_cache_addr(vs); - vnc_qmp_event(vs, QEVENT_VNC_CONNECTED); + vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED); vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING); vs->vd = vd; @@ -31,7 +31,6 @@ #include "qemu/queue.h" #include "qemu/thread.h" #include "ui/console.h" -#include "monitor/monitor.h" #include "audio/audio.h" #include "qemu/bitmap.h" #include <zlib.h> @@ -40,6 +39,7 @@ #include "keymaps.h" #include "vnc-palette.h" #include "vnc-enc-zrle.h" +#include "qapi-types.h" // #define _VNC_DEBUG 1 @@ -292,7 +292,7 @@ struct VncState bool websocket; #endif /* CONFIG_VNC_WS */ - QObject *info; + VncClientInfo *info; Buffer output; Buffer input; |