Patchwork [09/17] monitor: Convert do_info_uuid() to QObject

login
register
mail settings
Submitter Luiz Capitulino
Date Nov. 17, 2009, 8:32 p.m.
Message ID <1258489944-12159-10-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/38692/
State New
Headers show

Comments

Luiz Capitulino - Nov. 17, 2009, 8:32 p.m.
The returned QObject is a QString, snprintf() is used because the
UUID_FMT is too complex for qobject_from_jsonf().

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
Markus Armbruster - Nov. 20, 2009, 1:38 p.m.
Luiz Capitulino <lcapitulino@redhat.com> writes:

> The returned QObject is a QString, snprintf() is used because the
> UUID_FMT is too complex for qobject_from_jsonf().

If this turns out to be a common problem, we should consider fixing it
at the source: qobject_from_jsonf().

Patch

diff --git a/monitor.c b/monitor.c
index 9ecf5ff..c86c7a5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -385,13 +385,21 @@  static void do_info_hpet(Monitor *mon, QObject **ret_data)
 }
 #endif
 
-static void do_info_uuid(Monitor *mon)
+/**
+ * do_info_uuid(): Show VM UUID
+ *
+ * Return a QString with the current VM UUID.
+ */
+static void do_info_uuid(Monitor *mon, QObject **ret_data)
 {
-    monitor_printf(mon, UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1],
+    char uuid[64];
+
+    snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
                    qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
                    qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
                    qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
                    qemu_uuid[14], qemu_uuid[15]);
+    *ret_data = QOBJECT(qstring_from_str(uuid));
 }
 
 /* get the current CPU defined by the user */
@@ -2216,7 +2224,8 @@  static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the current VM UUID",
-        .mhandler.info = do_info_uuid,
+        .user_print = monitor_print_qobject,
+        .mhandler.info_new = do_info_uuid,
     },
 #if defined(TARGET_PPC)
     {