[PATCH] util: json: Allow converting a virTristate(Bool|Switch) into JSON

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a new modifier letter for virJSONValueObjectAddVArgs which will add
a boolean value with our tristate semantics. The value is omitted when
the _ABSENT value is used.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virjson.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 29530dcb15..e45f1fab06 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -142,6 +142,8 @@ virJSONValueGetType(const virJSONValue *value)
  *
  * b: boolean value
  * B: boolean value, omitted if false
+ * T: boolean value specified by a virTristate(Bool|Switch) value, omitted on
+ * the _ABSENT value
  *
  * d: double precision floating point number
  * n: json null value
@@ -266,12 +268,23 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
         }   break;

         case 'B':
+        case 'T':
         case 'b': {
             int val = va_arg(args, int);

             if (!val && type == 'B')
                 continue;

+            if (type == 'T') {
+                if (val == VIR_TRISTATE_SWITCH_ABSENT)
+                    continue;
+
+                if (val == VIR_TRISTATE_BOOL_NO)
+                    val = 0;
+                else
+                    val = 1;
+            }
+
             rc = virJSONValueObjectAppendBoolean(obj, key, val);
         }   break;

-- 
2.16.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux