[PATCH v3 16/25] util: typedparam: Introduce virTypedParamListAddUnsigned

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

 



The new helper adds a unsigned value, stored as _UINT if it fits into
the type and stored as _ULLONG otherwise.

This is useful for the statistics code which is quite tolerant to
changes in type in cases when we'll need more range for the value.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virtypedparam.c | 36 ++++++++++++++++++++++++++++++++++++
 src/util/virtypedparam.h |  6 ++++++
 3 files changed, 43 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b58be6aa33..4e21851c53 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3555,6 +3555,7 @@ virTypedParamListAddLLong;
 virTypedParamListAddString;
 virTypedParamListAddUInt;
 virTypedParamListAddULLong;
+virTypedParamListAddUnsigned;
 virTypedParamListConcat;
 virTypedParamListFetch;
 virTypedParamListFree;
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index ee9c6d1c45..52eea0fc54 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -921,6 +921,42 @@ virTypedParamListAddULLong(virTypedParamList *list,
 }


+/**
+ * virTypedParamListAddUnsigned:
+ * @list: typed parameter list
+ * @value: value to add  (see below on details)
+ * @namefmt: formatting string for constructing the name of the added value
+ * @...: additional parameters to format the name
+ *
+ * Adds a new typed parameter to @list. The name of the parameter is formatted
+ * from @fmt.
+ *
+ * @value is added as VIR_TYPED_PARAM_UINT, unless it doesn't fit into the data
+ * type in which case it's added as VIR_TYPED_PARAM_ULLONG.
+ */
+void
+virTypedParamListAddUnsigned(virTypedParamList *list,
+                             unsigned long long value,
+                             const char *namefmt,
+                             ...)
+{
+    virTypedParameterPtr par = virTypedParamListExtend(list);
+    va_list ap;
+
+    if (value > UINT_MAX) {
+        virTypedParameterAssignValue(par, VIR_TYPED_PARAM_ULLONG, value);
+    } else {
+        unsigned int ival = value;
+
+        virTypedParameterAssignValue(par, VIR_TYPED_PARAM_UINT, ival);
+    }
+
+    va_start(ap, namefmt);
+    virTypedParamSetNameVPrintf(list, par, namefmt, ap);
+    va_end(ap);
+}
+
+
 void
 virTypedParamListAddString(virTypedParamList *list,
                            const char *value,
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 7065683297..88f810bf78 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -187,6 +187,12 @@ virTypedParamListAddULLong(virTypedParamList *list,
                            ...)
     G_GNUC_PRINTF(3, 4);
 void
+virTypedParamListAddUnsigned(virTypedParamList *list,
+                             unsigned long long value,
+                             const char *namefmt,
+                             ...)
+    G_GNUC_PRINTF(3, 4);
+void
 virTypedParamListAddString(virTypedParamList *list,
                            const char *value,
                            const char *namefmt,
-- 
2.39.2




[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