All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: wenchaoqemu@gmail.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 2.1 26/36] qapi event: convert SPICE events
Date: Wed, 18 Jun 2014 08:43:50 +0200	[thread overview]
Message-ID: <1403073840-32603-27-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1403073840-32603-1-git-send-email-pbonzini@redhat.com>

From: Wenchao Xia <wenchaoqemu@gmail.com>

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>
---
 docs/qmp/qmp-events.txt | 62 -------------------------------------------
 include/qemu/sockets.h  |  1 -
 qapi-event.json         | 55 ++++++++++++++++++++++++++++++++++++++
 ui/spice-core.c         | 70 +++++++++++++++++++++++++------------------------
 util/qemu-sockets.c     | 10 -------
 5 files changed, 91 insertions(+), 107 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 37bc891..4fbc3de 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -70,65 +70,3 @@ Example:
 { "event": "QUORUM_REPORT_BAD",
      "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
      "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
-
-SPICE_CONNECTED, SPICE_DISCONNECTED
------------------------------------
-
-Emitted when a SPICE client connects or disconnects.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-
-Example:
-
-{ "timestamp": {"seconds": 1290688046, "microseconds": 388707},
-  "event": "SPICE_CONNECTED",
-  "data": {
-    "server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
-    "client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
-}}
-
-SPICE_INITIALIZED
------------------
-
-Emitted after initial handshake and authentication takes place (if any)
-and the SPICE channel is up'n'running
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "connection-id": spice connection id.  All channels with the same id
-                     belong to the same spice session (json-int)
-  - "channel-type": channel type.  "1" is the main control channel, filter for
-                    this one if you want track spice sessions only (json-int)
-  - "channel-id": channel id.  Usually "0", might be different needed when
-                  multiple channels of the same type exist, such as multiple
-                  display channels in a multihead setup (json-int)
-  - "tls": whevener the channel is encrypted (json-bool)
-
-Example:
-
-{ "timestamp": {"seconds": 1290688046, "microseconds": 417172},
-  "event": "SPICE_INITIALIZED",
-  "data": {"server": {"auth": "spice", "port": "5921",
-                      "family": "ipv4", "host": "127.0.0.1"},
-           "client": {"port": "49004", "family": "ipv4", "channel-type": 3,
-                      "connection-id": 1804289383, "host": "127.0.0.1",
-                      "channel-id": 0, "tls": true}
-}}
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index af24669..fdbb196 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -61,7 +61,6 @@ int inet_nonblocking_connect(const char *str,
                              void *opaque, Error **errp);
 
 int inet_dgram_opts(QemuOpts *opts, Error **errp);
-const char *inet_strfamily(int family);
 NetworkAddressFamily inet_netfamily(int family);
 
 int unix_listen_opts(QemuOpts *opts, Error **errp);
diff --git a/qapi-event.json b/qapi-event.json
index a86f8c9..1e23549 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -186,3 +186,58 @@
 { 'event': 'VNC_DISCONNECTED',
   'data': { 'server': 'VncServerInfo',
             'client': 'VncClientInfo' } }
+
+##
+# @SPICE_CONNECTED
+#
+# Emitted when a SPICE client establishes a connection
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 0.14.0
+##
+{ 'event': 'SPICE_CONNECTED',
+  'data': { 'server': 'SpiceBasicInfo',
+            'client': 'SpiceBasicInfo' } }
+
+##
+# @SPICE_INITIALIZED
+#
+# Emitted after initial handshake and authentication takes place (if any)
+# and the SPICE channel is up and running
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 0.14.0
+##
+{ 'event': 'SPICE_INITIALIZED',
+  'data': { 'server': 'SpiceServerInfo',
+            'client': 'SpiceChannel' } }
+
+##
+# @SPICE_DISCONNECTED
+#
+# Emitted when the SPICE connection is closed
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 0.14.0
+##
+{ 'event': 'SPICE_DISCONNECTED',
+  'data': { 'server': 'SpiceBasicInfo',
+            'client': 'SpiceBasicInfo' } }
+
+##
+# @SPICE_MIGRATE_COMPLETED
+#
+# Emitted when SPICE migration has completed
+#
+# Since: 1.3
+##
+{ 'event': 'SPICE_MIGRATE_COMPLETED' }
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 8d54fb3..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;
 }
 
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 447720f..74cf078 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -92,16 +92,6 @@ static void inet_setport(struct addrinfo *e, int port)
     }
 }
 
-const char *inet_strfamily(int family)
-{
-    switch (family) {
-    case PF_INET6: return "ipv6";
-    case PF_INET:  return "ipv4";
-    case PF_UNIX:  return "unix";
-    }
-    return "unknown";
-}
-
 NetworkAddressFamily inet_netfamily(int family)
 {
     switch (family) {
-- 
1.9.3

  parent reply	other threads:[~2014-06-18  6:45 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18  6:43 [Qemu-devel] [PATCH 2.1 00/36] Pending monitor patches for 2.1 Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 01/36] os-posix: include sys/time.h Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 02/36] qapi: Add includes from qapi/ as dependencies Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 03/36] qapi: add event helper functions Paolo Bonzini
2014-06-18 22:55   ` Wenchao Xia
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 04/36] qapi script: add event support Paolo Bonzini
2014-06-19 12:06   ` Eric Blake
2014-06-19 19:57   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 05/36] test: add test cases for qapi event Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 06/36] qapi: adjust existing defines Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 07/36] monitor: add an implemention of qapi event emit method Paolo Bonzini
2014-06-19  4:03   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 08/36] qapi: add new schema file qapi-event.json Paolo Bonzini
2014-06-19  4:04   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 09/36] qapi event: convert SHUTDOWN Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 10/36] qapi event: convert POWERDOWN Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 11/36] qapi event: convert RESET Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 12/36] qapi event: convert STOP Paolo Bonzini
2014-06-19 18:15   ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 13/36] qapi event: convert RESUME Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 14/36] qapi event: convert SUSPEND Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 15/36] qapi event: convert SUSPEND_DISK Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 16/36] qapi event: convert WAKEUP Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 17/36] qapi event: convert RTC_CHANGE Paolo Bonzini
2014-06-19  4:06   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 18/36] qapi event: convert WATCHDOG Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 19/36] qapi event: convert DEVICE_DELETED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 20/36] qapi event: convert DEVICE_TRAY_MOVED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 21/36] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Paolo Bonzini
2014-06-26 15:37   ` Markus Armbruster
2014-06-26 15:40     ` Paolo Bonzini
2014-06-26 15:44       ` Luiz Capitulino
2014-06-26 15:58       ` Markus Armbruster
2014-06-26 16:00         ` Luiz Capitulino
2014-06-27 12:21         ` Markus Armbruster
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 22/36] qapi event: convert BLOCK_IMAGE_CORRUPTED Paolo Bonzini
2014-06-19  4:09   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 23/36] qapi event: convert other BLOCK_JOB events Paolo Bonzini
2014-06-19  4:11   ` Eric Blake
2014-06-26 14:08   ` Markus Armbruster
2014-06-26 14:19     ` Paolo Bonzini
2014-06-26 14:24       ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 24/36] qapi event: convert NIC_RX_FILTER_CHANGED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 25/36] qapi event: convert VNC events Paolo Bonzini
2014-06-18  6:43 ` Paolo Bonzini [this message]
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 27/36] qapi event: convert BALLOON_CHANGE Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 28/36] qapi event: convert GUEST_PANICKED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 29/36] qapi event: convert QUORUM events Paolo Bonzini
2014-06-19  4:14   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 30/36] qapi event: clean up Paolo Bonzini
2014-06-19  4:17   ` Eric Blake
2014-06-19  8:00     ` Paolo Bonzini
2014-06-19 14:51       ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 32/36] qemu-char: do not call chr_write directly Paolo Bonzini
2014-06-19 14:47   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 33/36] qemu-char: move pty_chr_update_read_handler around Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 34/36] qemu-char: make writes thread-safe Paolo Bonzini
2014-06-25  6:06   ` Stefan Weil
2014-06-25  7:03     ` Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 35/36] monitor: protect outbuf and mux_out with mutex Paolo Bonzini
2014-06-18  6:44 ` [Qemu-devel] [PATCH 2.1 36/36] monitor: protect event emission Paolo Bonzini
     [not found] ` <1403073840-32603-32-git-send-email-pbonzini@redhat.com>
2014-06-19 12:03   ` [Qemu-devel] [PATCH 2.1 31/36] qemu-char: introduce qemu_chr_alloc Eric Blake
2014-06-19 12:52     ` Paolo Bonzini
2014-06-19 18:40 ` [Qemu-devel] [PATCH 2.1 00/36] Pending monitor patches for 2.1 Luiz Capitulino
2014-06-20 15:44 ` Eric Blake
2014-06-20 23:34   ` Wenchao Xia
2014-06-26 15:50 ` Markus Armbruster
2014-06-26 15:56   ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403073840-32603-27-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wenchaoqemu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.