1 Star 0 Fork 71

tzr/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
enum-Add-helpers-for-converting-virTristate-to-a-pla.patch 3.31 KB
一键复制 编辑 原始数据 按行查看 历史
Jiangjiacheng 提交于 2023-01-04 12:02 . Backport patches from upstream
From 04c5fee85547da11323b66b2fb79fb590e8307a1 Mon Sep 17 00:00:00 2001
From: jiangdawei15 <jiangdawei15@huawei.com>
Date: Thu, 18 Aug 2022 20:15:54 +0800
Subject: [PATCH 22/22] enum: Add helpers for converting virTristate* to a
plain bool
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The helpers will update the passed boolean if the tristate's value is
not _ABSENT.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/libvirt_private.syms | 2 ++
src/util/virenum.c | 54 ++++++++++++++++++++++++++++++++++++++++
src/util/virenum.h | 2 ++
3 files changed, 58 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f30eb7ffb5..a00e354859 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1965,9 +1965,11 @@ ebtablesRemoveForwardAllowIn;
virEnumFromString;
virEnumToString;
virTristateBoolFromBool;
+virTristateBoolToBool;
virTristateBoolTypeFromString;
virTristateBoolTypeToString;
virTristateSwitchFromBool;
+virTristateSwitchToBool;
virTristateSwitchTypeFromString;
virTristateSwitchTypeToString;
diff --git a/src/util/virenum.c b/src/util/virenum.c
index 26093bd795..dfedc28ba7 100644
--- a/src/util/virenum.c
+++ b/src/util/virenum.c
@@ -47,6 +47,33 @@ virTristateBoolFromBool(bool val)
}
+/**
+ * virTristateBoolToBool: The value pointed to by @b is
+ * updated if the tristate value @t is not absent.
+ *
+ * @t: a virTristateBool value
+ * @b: pointer to a boolean to be updated according to the value of @t
+ */
+void
+virTristateBoolToBool(virTristateBool t,
+ bool *b)
+{
+ switch (t) {
+ case VIR_TRISTATE_BOOL_YES:
+ *b = true;
+ break;
+
+ case VIR_TRISTATE_BOOL_NO:
+ *b = false;
+ break;
+
+ case VIR_TRISTATE_BOOL_ABSENT:
+ case VIR_TRISTATE_BOOL_LAST:
+ break;
+ }
+}
+
+
virTristateSwitch
virTristateSwitchFromBool(bool val)
{
@@ -57,6 +84,33 @@ virTristateSwitchFromBool(bool val)
}
+/**
+ * virTristateSwitchToBool: The value pointed to by @b
+ * is updated if the tristate value @t is not absent.
+ *
+ * @t: a virTristateSwitch value
+ * @b: pointer to a boolean to be updated according to the value of @t
+ */
+void
+virTristateSwitchToBool(virTristateSwitch t,
+ bool *b)
+{
+ switch (t) {
+ case VIR_TRISTATE_SWITCH_ON:
+ *b = true;
+ break;
+
+ case VIR_TRISTATE_SWITCH_OFF:
+ *b = false;
+ break;
+
+ case VIR_TRISTATE_SWITCH_ABSENT:
+ case VIR_TRISTATE_SWITCH_LAST:
+ break;
+ }
+}
+
+
int
virEnumFromString(const char * const *types,
unsigned int ntypes,
diff --git a/src/util/virenum.h b/src/util/virenum.h
index d74af35530..98f01d574d 100644
--- a/src/util/virenum.h
+++ b/src/util/virenum.h
@@ -68,7 +68,9 @@ VIR_ENUM_DECL(virTristateBool);
VIR_ENUM_DECL(virTristateSwitch);
virTristateBool virTristateBoolFromBool(bool val);
+void virTristateBoolToBool(virTristateBool t, bool *b);
virTristateSwitch virTristateSwitchFromBool(bool val);
+void virTristateSwitchToBool(virTristateSwitch t, bool *b);
/* the two enums must be in sync to be able to use helpers interchangeably in
* some special cases */
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tom0392/libvirt.git
git@gitee.com:tom0392/libvirt.git
tom0392
libvirt
libvirt
master

搜索帮助