Re: [libvirt] [PATCH v2 02/10] qemu: qapi: Split up virQEMUQAPISchemaObjectGetType

2018-08-23 Thread John Ferlan



On 08/15/2018 05:18 AM, Peter Krempa wrote:
> Split it into a function that returns the whole schema entry so that we
> can do additional checks and a helper getting the type string from the
> schema entry.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_qapi.c | 51 ---
>  1 file changed, 40 insertions(+), 11 deletions(-)
> 

With pointed out nits below handled..

Reviewed-by: John Ferlan 

John

> diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
> index fea6683336..cd28c69a96 100644
> --- a/src/qemu/qemu_qapi.c
> +++ b/src/qemu/qemu_qapi.c
> @@ -33,24 +33,23 @@ VIR_LOG_INIT("qemu.qemu_qapi");
> 
> 
>  /**
> - * virQEMUQAPISchemaObjectGetType:
> + * virQEMUQAPISchemaObjectGet:
>   * @field: name of the object containing the requested type
>   * @name: name of the requested type
>   * @namefield: name of the object property holding @name

existing, but @elem isn't described

>   *
>   * Helper that selects the type of a QMP schema object member or it's variant
> - * member. Returns the type string on success or NULL on error.
> + * member. Returns the QMP entry on success or NULL on error.
>   */
> -static const char *
> -virQEMUQAPISchemaObjectGetType(const char *field,
> -   const char *name,
> -   const char *namefield,
> -   virJSONValuePtr elem)

[...]

> +/**
> + * virQEMUQAPISchemaObjectGetType:
> + * @field: name of the object containing the requested type
> + * @name: name of the requested type
> + * @namefield: name of the object property holding @name

@elem not described

> + *
> + * Helper that selects the type of a QMP schema object member or it's variant
> + * member. Returns the type string on success or NULL on error.
> + */
> +static const char *
> +virQEMUQAPISchemaObjectGetType(const char *field,
> +   const char *name,
> +   const char *namefield,
> +   virJSONValuePtr elem)
> +{
> +virJSONValuePtr obj = virQEMUQAPISchemaObjectGet(field, name, namefield, 
> elem);
> +
> +return virQEMUQAPISchemaTypeFromObject(obj);
> +}
> +
> +
>  static virJSONValuePtr
>  virQEMUQAPISchemaTraverse(const char *baseName,
>char **query,
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 02/10] qemu: qapi: Split up virQEMUQAPISchemaObjectGetType

2018-08-15 Thread Peter Krempa
Split it into a function that returns the whole schema entry so that we
can do additional checks and a helper getting the type string from the
schema entry.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_qapi.c | 51 ---
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index fea6683336..cd28c69a96 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -33,24 +33,23 @@ VIR_LOG_INIT("qemu.qemu_qapi");


 /**
- * virQEMUQAPISchemaObjectGetType:
+ * virQEMUQAPISchemaObjectGet:
  * @field: name of the object containing the requested type
  * @name: name of the requested type
  * @namefield: name of the object property holding @name
  *
  * Helper that selects the type of a QMP schema object member or it's variant
- * member. Returns the type string on success or NULL on error.
+ * member. Returns the QMP entry on success or NULL on error.
  */
-static const char *
-virQEMUQAPISchemaObjectGetType(const char *field,
-   const char *name,
-   const char *namefield,
-   virJSONValuePtr elem)
+static virJSONValuePtr
+virQEMUQAPISchemaObjectGet(const char *field,
+   const char *name,
+   const char *namefield,
+   virJSONValuePtr elem)
 {
 virJSONValuePtr arr;
 virJSONValuePtr cur;
 const char *curname;
-const char *type;
 size_t i;

 if (!(arr = virJSONValueObjectGetArray(elem, field)))
@@ -58,18 +57,48 @@ virQEMUQAPISchemaObjectGetType(const char *field,

 for (i = 0; i < virJSONValueArraySize(arr); i++) {
 if (!(cur = virJSONValueArrayGet(arr, i)) ||
-!(curname = virJSONValueObjectGetString(cur, namefield)) ||
-!(type = virJSONValueObjectGetString(cur, "type")))
+!(curname = virJSONValueObjectGetString(cur, namefield)))
 continue;

 if (STREQ(name, curname))
-return type;
+return cur;
 }

 return NULL;
 }


+static const char *
+virQEMUQAPISchemaTypeFromObject(virJSONValuePtr obj)
+{
+if (!obj)
+return NULL;
+
+return virJSONValueObjectGetString(obj, "type");
+}
+
+
+/**
+ * virQEMUQAPISchemaObjectGetType:
+ * @field: name of the object containing the requested type
+ * @name: name of the requested type
+ * @namefield: name of the object property holding @name
+ *
+ * Helper that selects the type of a QMP schema object member or it's variant
+ * member. Returns the type string on success or NULL on error.
+ */
+static const char *
+virQEMUQAPISchemaObjectGetType(const char *field,
+   const char *name,
+   const char *namefield,
+   virJSONValuePtr elem)
+{
+virJSONValuePtr obj = virQEMUQAPISchemaObjectGet(field, name, namefield, 
elem);
+
+return virQEMUQAPISchemaTypeFromObject(obj);
+}
+
+
 static virJSONValuePtr
 virQEMUQAPISchemaTraverse(const char *baseName,
   char **query,
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list