summaryrefslogtreecommitdiff
path: root/ui/spice-core.c
diff options
context:
space:
mode:
authorWenchao Xia <wenchaoqemu@gmail.com>2014-06-18 08:43:50 +0200
committerLuiz Capitulino <lcapitulino@redhat.com>2014-06-23 11:12:28 -0400
commit7cfadb6b5291765d360137ac5cab78729bde0272 (patch)
treeb0775d34afb98cad5838bb263174880810b9e2cc /ui/spice-core.c
parentfb6ba0d5256cca2f1e844c03a7a51dd0a7982ac2 (diff)
downloadqemu-7cfadb6b5291765d360137ac5cab78729bde0272.tar.gz
qapi event: convert SPICE events
SPICE_INITIALIZED, SPICE_CONNECTED, SPICE_DISCONNECTED and SPICE_MIGRATE_COMPLETED are converted in one patch, since they use some common functions. inet_strfamily() is removed since no callers exist anymore. Note that there is no existing doc for SPICE_MIGRATE_COMPLETED in docs/qmp/qmp-events.txt before this patch. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'ui/spice-core.c')
-rw-r--r--ui/spice-core.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 8d54fb320f..70df4460e4 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;
}