Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- src/util/virenum.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/util/virenum.h | 15 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/util/virenum.c b/src/util/virenum.c index c6936e58ff..8474db9b2b 100644 --- a/src/util/virenum.c +++ b/src/util/virenum.c @@ -35,6 +35,14 @@ VIR_ENUM_IMPL(virTristateSwitch, "off", ); +VIR_ENUM_IMPL(virQuadstateOption, + VIR_QUADSTATE_OPTION_LAST, + "default", + "yes", + "no", + "optional", +); + virTristateBool virTristateBoolFromBool(bool val) @@ -110,6 +118,44 @@ virTristateSwitchToBool(virTristateSwitch t, } +virQuadstateOption +virQuadstateOptionFromBool(bool val) +{ + if (val) + return VIR_QUADSTATE_OPTION_YES; + else + return VIR_QUADSTATE_OPTION_NO; +} + + +/** + * virQuadstateOptionToBool: + * @t: a virQuadstateOption value + * @b: pointer to a boolean to be updated according to the value of @t + * + * The value pointed to by @b is updated if the quadstate value @t is neither absent or optional. + */ +void +virQuadstateOptionToBool(virQuadstateOption t, + bool *b) +{ + switch (t) { + case VIR_QUADSTATE_OPTION_YES: + *b = true; + break; + + case VIR_QUADSTATE_OPTION_NO: + *b = false; + break; + + case VIR_QUADSTATE_OPTION_ABSENT: + case VIR_QUADSTATE_OPTION_OPTIONAL: + case VIR_QUADSTATE_OPTION_LAST: + break; + } +} + + int virEnumFromString(const char * const *types, unsigned int ntypes, diff --git a/src/util/virenum.h b/src/util/virenum.h index 98f01d574d..bd45d470c4 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -64,16 +64,31 @@ typedef enum { VIR_TRISTATE_SWITCH_LAST } virTristateSwitch; +typedef enum { + VIR_QUADSTATE_OPTION_ABSENT = 0, + VIR_QUADSTATE_OPTION_YES, + VIR_QUADSTATE_OPTION_NO, + VIR_QUADSTATE_OPTION_OPTIONAL, + + VIR_QUADSTATE_OPTION_LAST +} virQuadstateOption; + VIR_ENUM_DECL(virTristateBool); VIR_ENUM_DECL(virTristateSwitch); +VIR_ENUM_DECL(virQuadstateOption); virTristateBool virTristateBoolFromBool(bool val); void virTristateBoolToBool(virTristateBool t, bool *b); virTristateSwitch virTristateSwitchFromBool(bool val); void virTristateSwitchToBool(virTristateSwitch t, bool *b); +virQuadstateOption virQuadstateOptionFromBool(bool val); +void virQuadstateOptionToBool(virQuadstateOption t, bool *b); /* the two enums must be in sync to be able to use helpers interchangeably in * some special cases */ G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON); G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_NO == (int)VIR_TRISTATE_SWITCH_OFF); G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT); +G_STATIC_ASSERT((int)VIR_QUADSTATE_OPTION_YES == (int)VIR_TRISTATE_SWITCH_ON); +G_STATIC_ASSERT((int)VIR_QUADSTATE_OPTION_NO == (int)VIR_TRISTATE_SWITCH_OFF); +G_STATIC_ASSERT((int)VIR_QUADSTATE_OPTION_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT); -- 2.41.0