[PATCH v3 10/13] ch: add virCHMonitorBuildKeyValueJson

Stefan Kober posted 13 patches 5 months, 1 week ago
[PATCH v3 10/13] ch: add virCHMonitorBuildKeyValueJson
Posted by Stefan Kober 5 months, 1 week ago
On-behalf-of: SAP stefan.kober@sap.com
Signed-off-by: Stefan Kober <stefan.kober@cyberus-technology.de>
---
 src/ch/ch_monitor.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 710ba06d2d..6ed78c09c7 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -584,15 +584,25 @@ virCHMonitorBuildVMJson(virCHDriver *driver, virDomainDef *vmdef,
     return 0;
 }
 
+static virJSONValue*
+virCHMonitorBuildKeyValueJson(const char *key,
+                              const char *value)
+{
+    g_autoptr(virJSONValue) content = virJSONValueNewObject();
+
+    if (virJSONValueObjectAppendString(content, key, value) < 0)
+        return NULL;
+
+    return g_steal_pointer(&content);
+}
+
 static int
 virCHMonitorBuildKeyValueStringJson(char **jsonstr,
                                     const char *key,
                                     const char *value)
 {
-    g_autoptr(virJSONValue) content = virJSONValueNewObject();
-
-    if (virJSONValueObjectAppendString(content, key, value) < 0)
-        return -1;
+    g_autoptr(virJSONValue) content =
+        virCHMonitorBuildKeyValueJson(key, value);
 
     if (!(*jsonstr = virJSONValueToString(content, false)))
         return -1;
-- 
2.50.1
Re: [PATCH v3 10/13] ch: add virCHMonitorBuildKeyValueJson
Posted by Michal Prívozník via Devel 5 months ago
On 9/4/25 14:10, Stefan Kober wrote:
> On-behalf-of: SAP stefan.kober@sap.com
> Signed-off-by: Stefan Kober <stefan.kober@cyberus-technology.de>
> ---
>  src/ch/ch_monitor.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
> index 710ba06d2d..6ed78c09c7 100644
> --- a/src/ch/ch_monitor.c
> +++ b/src/ch/ch_monitor.c
> @@ -584,15 +584,25 @@ virCHMonitorBuildVMJson(virCHDriver *driver, virDomainDef *vmdef,
>      return 0;
>  }
>  
> +static virJSONValue*
> +virCHMonitorBuildKeyValueJson(const char *key,
> +                              const char *value)
> +{
> +    g_autoptr(virJSONValue) content = virJSONValueNewObject();
> +
> +    if (virJSONValueObjectAppendString(content, key, value) < 0)
> +        return NULL;
> +
> +    return g_steal_pointer(&content);
> +}
> +
>  static int
>  virCHMonitorBuildKeyValueStringJson(char **jsonstr,
>                                      const char *key,
>                                      const char *value)
>  {
> -    g_autoptr(virJSONValue) content = virJSONValueNewObject();
> -
> -    if (virJSONValueObjectAppendString(content, key, value) < 0)
> -        return -1;
> +    g_autoptr(virJSONValue) content =
> +        virCHMonitorBuildKeyValueJson(key, value);

This fits onto one line perfectly.

>  
>      if (!(*jsonstr = virJSONValueToString(content, false)))
>          return -1;

Michal