
On Mon, Aug 27, 2018 at 06:17:05PM +0200, Peter Krempa wrote:
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@redhat.com> --- 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)
Just curious, was ^this on purpose to emphasize the fact that it would really work with TristateSwitch since both _ABSENTs == 0 or just a coincidence? I'd probably prefer _SWITCH_ABSENT slightly more to be consistent with the enum being tested below. Reviewed-by: Erik Skultety <eskultet@redhat.com>
+ 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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list