qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 07/20] monitor: do_info_cpus(): Use QBool
Date: Thu, 10 Dec 2009 17:15:57 -0200	[thread overview]
Message-ID: <1260472570-13973-8-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1260472570-13973-1-git-send-email-lcapitulino@redhat.com>

While there update the documentation as well.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/monitor.c b/monitor.c
index 5010ce4..49db7cf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -635,8 +635,9 @@ static void print_cpu_iter(QObject *obj, void *opaque)
     assert(qobject_type(obj) == QTYPE_QDICT);
     cpu = qobject_to_qdict(obj);
 
-    if (strcmp(qdict_get_str(cpu, "current"), "yes") == 0)
+    if (qdict_get_bool(cpu, "current")) {
         active = '*';
+    }
 
     monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU"));
 
@@ -656,8 +657,9 @@ static void print_cpu_iter(QObject *obj, void *opaque)
                    (target_long) qdict_get_int(cpu, "PC"));
 #endif
 
-    if (strcmp(qdict_get_str(cpu, "halted"), "yes") == 0)
+    if (qdict_get_bool(cpu, "halted")) {
         monitor_printf(mon, " (halted)");
+    }
 
     monitor_printf(mon, "\n");
 }
@@ -674,12 +676,21 @@ static void monitor_print_cpus(Monitor *mon, const QObject *data)
 /**
  * do_info_cpus(): Show CPU information
  *
- * Return a QList with a QDict for each CPU.
+ * Return a QList. Each CPU is represented by a QDict, which contains:
  *
- * For example:
+ * - "cpu": CPU index
+ * - "current": true if this is the current CPU, false otherwise
+ * - "halted": true if the cpu is halted, false otherwise
+ * - Current program counter. The key's name depends on the architecture:
+ *      "pc": i386/x86)64
+ *      "nip": PPC
+ *      "pc" and "npc": sparc
+ *      "PC": mips
  *
- * [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" },
- *   { "CPU": 1, "current": "no",  "pc": 0x..., "halted": "yes" } ]
+ * Example:
+ *
+ * [ { "CPU": 0, "current": true, "halted": false, "pc": 3227107138 },
+ *   { "CPU": 1, "current": false, "halted": true, "pc": 7108165 } ]
  */
 static void do_info_cpus(Monitor *mon, QObject **ret_data)
 {
@@ -692,14 +703,17 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data)
     mon_get_cpu();
 
     for(env = first_cpu; env != NULL; env = env->next_cpu) {
-        const char *answer;
-        QDict *cpu = qdict_new();
+        QDict *cpu;
+        QObject *obj;
 
         cpu_synchronize_state(env);
 
-        qdict_put(cpu, "CPU", qint_from_int(env->cpu_index));
-        answer = (env == mon->mon_cpu) ? "yes" : "no";
-        qdict_put(cpu, "current", qstring_from_str(answer));
+        obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }",
+                                 env->cpu_index, env == mon->mon_cpu,
+                                 env->halted);
+        assert(obj != NULL);
+
+        cpu = qobject_to_qdict(obj);
 
 #if defined(TARGET_I386)
         qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base));
@@ -711,8 +725,6 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data)
 #elif defined(TARGET_MIPS)
         qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC));
 #endif
-        answer = env->halted ? "yes" : "no";
-        qdict_put(cpu, "halted", qstring_from_str(answer));
 
         qlist_append(cpu_list, cpu);
     }
-- 
1.6.6.rc1.39.g9a42

  parent reply	other threads:[~2009-12-10 19:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-10 19:15 [Qemu-devel] [FOR 0.12 v5 00/20]: info handlers conversions to QObject Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 01/20] Introduce qemu-objects.h header file Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 02/20] Makefile: move QObject objs to their own entry Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 03/20] QDict: Introduce qdict_get_qbool() Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 04/20] QDict: Introduce qdict_get_qlist() Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 05/20] monitor: Fix do_info_balloon() output Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 06/20] monitor: Fix do_info_commands() output Luiz Capitulino
2009-12-10 19:15 ` Luiz Capitulino [this message]
2009-12-10 19:15 ` [Qemu-devel] [PATCH 08/20] monitor: do_info_version(): Use QDict Luiz Capitulino
2009-12-10 19:15 ` [Qemu-devel] [PATCH 09/20] monitor: Convert do_info_status() to QObject Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 10/20] monitor: Convert do_info_kvm() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 11/20] monitor: Convert do_info_name() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 12/20] monitor: Convert do_info_hpet() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 13/20] monitor: Convert do_info_uuid() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 14/20] monitor: Convert do_info_mice() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 15/20] migration: Convert do_info_migrate() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 16/20] block: Convert bdrv_info() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 17/20] block: Convert bdrv_info_stats() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 18/20] char: Convert qemu_chr_info() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 19/20] PCI: Convert pci_device_hot_add() " Luiz Capitulino
2009-12-10 19:16 ` [Qemu-devel] [PATCH 20/20] VNC: Convert do_info_vnc() " Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2009-12-10 14:43 [Qemu-devel] [FOR 0.12 v4 00/20]: info handlers conversions " Luiz Capitulino
2009-12-10 14:43 ` [Qemu-devel] [PATCH 07/20] monitor: do_info_cpus(): Use QBool 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=1260472570-13973-8-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).