xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Xen Devel <xen-devel@lists.xen.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH V3 03/10] libxl_json: Replace JSON_TRUE/FALSE by JSON_BOOL.
Date: Wed, 26 Sep 2012 19:15:18 +0100	[thread overview]
Message-ID: <1348683325-12367-4-git-send-email-anthony.perard@citrix.com> (raw)
In-Reply-To: <1348683325-12367-1-git-send-email-anthony.perard@citrix.com>

Those two JSON_TRUE and JSON_FALSE were types of node. But it's better to have
a unique JSON_BOOL type.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_internal.h | 15 +++++++++++++--
 tools/libxl/libxl_json.c     |  4 ++--
 tools/libxl/libxl_qmp.c      |  3 ++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 49c62c0..5604256 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1428,8 +1428,7 @@ _hidden yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, const char *str);
 
 typedef enum {
     JSON_NULL,
-    JSON_TRUE,
-    JSON_FALSE,
+    JSON_BOOL,
     JSON_INTEGER,
     JSON_DOUBLE,
     /* number is store in string, it's too big to be a long long or a double */
@@ -1443,6 +1442,7 @@ typedef enum {
 typedef struct libxl__json_object {
     libxl__json_node_type type;
     union {
+        bool b;
         long long i;
         double d;
         char *string;
@@ -1461,6 +1461,10 @@ typedef struct {
 
 typedef struct libxl__yajl_ctx libxl__yajl_ctx;
 
+static inline bool libxl__json_object_is_bool(const libxl__json_object *o)
+{
+    return o != NULL && o->type == JSON_BOOL;
+}
 static inline bool libxl__json_object_is_string(const libxl__json_object *o)
 {
     return o != NULL && o->type == JSON_STRING;
@@ -1478,6 +1482,13 @@ static inline bool libxl__json_object_is_array(const libxl__json_object *o)
     return o != NULL && o->type == JSON_ARRAY;
 }
 
+static inline bool libxl__json_object_get_bool(const libxl__json_object *o)
+{
+    if (libxl__json_object_is_bool(o))
+        return o->u.b;
+    else
+        return false;
+}
 static inline
 const char *libxl__json_object_get_string(const libxl__json_object *o)
 {
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c
index 30b2980..34fd8c7 100644
--- a/tools/libxl/libxl_json.c
+++ b/tools/libxl/libxl_json.c
@@ -350,8 +350,8 @@ static int json_callback_boolean(void *opaque, int boolean)
 
     DEBUG_GEN_VALUE(ctx, bool, boolean);
 
-    obj = libxl__json_object_alloc(ctx->gc,
-                                   boolean ? JSON_TRUE : JSON_FALSE);
+    obj = libxl__json_object_alloc(ctx->gc, JSON_BOOL);
+    obj->u.b = boolean;
 
     if (libxl__json_object_append_to(ctx->gc, obj, ctx->current) == -1) {
         return 0;
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 15550e7..9109ac5 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -178,7 +178,8 @@ static int qmp_register_vnc_callback(libxl__qmp_handler *qmp,
         goto out;
     }
 
-    if (libxl__json_map_get("enabled", o, JSON_FALSE)) {
+    obj = libxl__json_map_get("enabled", o, JSON_BOOL);
+    if (!obj || !libxl__json_object_get_bool(obj)) {
         rc = 0;
         goto out;
     }
-- 
Anthony PERARD

  parent reply	other threads:[~2012-09-26 18:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-26 18:15 [PATCH V3 00/10] Set dirty log on qemu-xen Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 01/10] libxl_json: Export json_object related function Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 02/10] libxl_json: Remove JSON_ERROR from enum Anthony PERARD
2012-10-05 13:08   ` Ian Campbell
2012-09-26 18:15 ` Anthony PERARD [this message]
2012-10-05 13:10   ` [PATCH V3 03/10] libxl_json: Replace JSON_TRUE/FALSE by JSON_BOOL Ian Campbell
2012-10-05 16:27     ` Ian Jackson
2012-10-05 16:28       ` Ian Campbell
2012-09-26 18:15 ` [PATCH V3 04/10] libxl_json: Introduce libxl__json_object_to_yajl_gen Anthony PERARD
2012-10-05 13:12   ` Ian Campbell
2012-09-26 18:15 ` [PATCH V3 05/10] libxl_qmp: Introduces helpers to create an argument list Anthony PERARD
2012-10-05 13:15   ` Ian Campbell
2012-09-26 18:15 ` [PATCH V3 06/10] libxl_qmp: Use qmp_parameters_* functions for param list of a QMP command Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 07/10] libxl_qmp: Simplify run of single QMP commands Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 08/10] libxl_qmp: Introduce libxl__qmp_set_global_dirty_log Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 09/10] libxl_dom: Call the right switch logdirty for the right DM Anthony PERARD
2012-09-26 18:15 ` [PATCH V3 10/10] libxl: Allow migration with qemu-xen Anthony PERARD
2012-10-05 13:19   ` Ian Campbell

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=1348683325-12367-4-git-send-email-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xen.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).