diff mbox

[v2,01/24] qom: add object_class_get_parent

Message ID 1334179842-6061-1-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini April 11, 2012, 9:30 p.m. UTC
This simple bit of functionality was missing and we'll need it soon,
so add it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qemu/object.h |   14 ++++++++++++++
 qom/object.c          |   13 +++++++++++++
 2 files changed, 27 insertions(+)

Comments

Andreas Färber April 12, 2012, 4 p.m. UTC | #1
Am 11.04.2012 23:30, schrieb Paolo Bonzini:
> This simple bit of functionality was missing and we'll need it soon,
> so add it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/qemu/object.h |   14 ++++++++++++++
>  qom/object.c          |   13 +++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/include/qemu/object.h b/include/qemu/object.h
> index a675937..f814521 100644
> --- a/include/qemu/object.h
> +++ b/include/qemu/object.h
> @@ -548,6 +548,14 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
>                                         const char *typename);
>  
>  /**
> + * object_class_get_parent:
> + * @klass: The class to obtain the parent for.
> + *
> + * Returns: The parent for @klass.
> + */
> +ObjectClass *object_class_get_parent(ObjectClass *klass);
> +
> +/**
>   * object_class_get_name:
>   * @klass: The class to obtain the QOM typename for.
>   *
> @@ -555,6 +563,12 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
>   */
>  const char *object_class_get_name(ObjectClass *klass);
>  
> +/**
> + * object_class_by_name:
> + * @typename: The QOM typename to obtain the class for.
> + *
> + * Returns: The class for @typename.
> + */
>  ObjectClass *object_class_by_name(const char *typename);

Unrelated documentation addition. Please split it into its own patch.

Otherwise okay.

Andreas

>  
>  void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
> diff --git a/qom/object.c b/qom/object.c
> index e721fc2..3e9fed7 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -545,6 +545,19 @@ ObjectClass *object_class_by_name(const char *typename)
>      return type->class;
>  }
>  
> +ObjectClass *object_class_get_parent(ObjectClass *class)
> +{
> +    TypeImpl *type = type_get_parent(class->type);
> +
> +    if (!type) {
> +        return NULL;
> +    }
> +
> +    type_initialize(type);
> +
> +    return type->class;
> +}
> +
>  typedef struct OCFData
>  {
>      void (*fn)(ObjectClass *klass, void *opaque);
diff mbox

Patch

diff --git a/include/qemu/object.h b/include/qemu/object.h
index a675937..f814521 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -548,6 +548,14 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
                                        const char *typename);
 
 /**
+ * object_class_get_parent:
+ * @klass: The class to obtain the parent for.
+ *
+ * Returns: The parent for @klass.
+ */
+ObjectClass *object_class_get_parent(ObjectClass *klass);
+
+/**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
  *
@@ -555,6 +563,12 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 const char *object_class_get_name(ObjectClass *klass);
 
+/**
+ * object_class_by_name:
+ * @typename: The QOM typename to obtain the class for.
+ *
+ * Returns: The class for @typename.
+ */
 ObjectClass *object_class_by_name(const char *typename);
 
 void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
diff --git a/qom/object.c b/qom/object.c
index e721fc2..3e9fed7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -545,6 +545,19 @@  ObjectClass *object_class_by_name(const char *typename)
     return type->class;
 }
 
+ObjectClass *object_class_get_parent(ObjectClass *class)
+{
+    TypeImpl *type = type_get_parent(class->type);
+
+    if (!type) {
+        return NULL;
+    }
+
+    type_initialize(type);
+
+    return type->class;
+}
+
 typedef struct OCFData
 {
     void (*fn)(ObjectClass *klass, void *opaque);