]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: typedparam: Introduce virTypedParamListAddUnsigned
authorPeter Krempa <pkrempa@redhat.com>
Tue, 18 Apr 2023 11:30:02 +0000 (13:30 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 May 2023 12:32:46 +0000 (14:32 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virtypedparam.c
src/util/virtypedparam.h

index b58be6aa3330719ff8f7d3dff768c061faa84db8..4e21851c532d7beed92b14c3eefc4ff221f29d3e 100644 (file)
@@ -3555,6 +3555,7 @@ virTypedParamListAddLLong;
 virTypedParamListAddString;
 virTypedParamListAddUInt;
 virTypedParamListAddULLong;
+virTypedParamListAddUnsigned;
 virTypedParamListConcat;
 virTypedParamListFetch;
 virTypedParamListFree;
index abd5f4cd0e941140c3a51fbbd4777a5182463823..4490746631bcf9063f75968bf4eaf07176e05bb4 100644 (file)
@@ -920,6 +920,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,
index 70656832975a12f327f0497e7b90054684071625..88f810bf78807d1cb8a42a200f66c0ba94dbff7d 100644 (file)
@@ -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,