diff mbox

[v3] hmp: info spice: Show string channel name

Message ID f4ffdc4fd79458c99bb09bdf70e99a2a698d0a18.1425220042.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson March 1, 2015, 2:29 p.m. UTC
Useful for debugging.

https://bugzilla.redhat.com/show_bug.cgi?id=822418
Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
v3:
    Fix checkpatch warnings
    Change INPUTS string from 'input' to 'inputs'
    Extra check to ensure array element isn't empty

v2:
    Explicitly list spice channel mappings
    Use ARRAY_SIZE macro

 hmp.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Eric Blake March 2, 2015, 4:02 p.m. UTC | #1
On 03/01/2015 07:29 AM, Cole Robinson wrote:
> Useful for debugging.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=822418
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
> v3:
>     Fix checkpatch warnings
>     Change INPUTS string from 'input' to 'inputs'
>     Extra check to ensure array element isn't empty
> 
> v2:
>     Explicitly list spice channel mappings
>     Use ARRAY_SIZE macro
> 
>  hmp.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>
Gerd Hoffmann March 2, 2015, 4:12 p.m. UTC | #2
On So, 2015-03-01 at 09:29 -0500, Cole Robinson wrote:
> Useful for debugging.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=822418
> Signed-off-by: Cole Robinson <crobinso@redhat.com>

Added to spice patch queue.

thanks,
  Gerd
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index 735097c..eacfb1b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -29,6 +29,10 @@ 
 #include "block/qapi.h"
 #include "qemu-io.h"
 
+#ifdef CONFIG_SPICE
+#include <spice/enums.h>
+#endif
+
 static void hmp_handle_error(Monitor *mon, Error **errp)
 {
     assert(errp);
@@ -545,6 +549,20 @@  void hmp_info_spice(Monitor *mon, const QDict *qdict)
 {
     SpiceChannelList *chan;
     SpiceInfo *info;
+    const char *channel_name;
+    const char * const channel_names[] = {
+        [SPICE_CHANNEL_MAIN] = "main",
+        [SPICE_CHANNEL_DISPLAY] = "display",
+        [SPICE_CHANNEL_INPUTS] = "inputs",
+        [SPICE_CHANNEL_CURSOR] = "cursor",
+        [SPICE_CHANNEL_PLAYBACK] = "playback",
+        [SPICE_CHANNEL_RECORD] = "record",
+        [SPICE_CHANNEL_TUNNEL] = "tunnel",
+        [SPICE_CHANNEL_SMARTCARD] = "smartcard",
+        [SPICE_CHANNEL_USBREDIR] = "usbredir",
+        [SPICE_CHANNEL_PORT] = "port",
+        [SPICE_CHANNEL_WEBDAV] = "webdav",
+    };
 
     info = qmp_query_spice(NULL);
 
@@ -581,6 +599,15 @@  void hmp_info_spice(Monitor *mon, const QDict *qdict)
                            chan->value->connection_id);
             monitor_printf(mon, "     channel: %" PRId64 ":%" PRId64 "\n",
                            chan->value->channel_type, chan->value->channel_id);
+
+            channel_name = "unknown";
+            if (chan->value->channel_type > 0 &&
+                chan->value->channel_type < ARRAY_SIZE(channel_names) &&
+                channel_names[chan->value->channel_type]) {
+                channel_name = channel_names[chan->value->channel_type];
+            }
+
+            monitor_printf(mon, "     channel name: %s\n", channel_name);
         }
     }