[PATCH-for-10.1 2/6] qom: Add object_class_implements_type()

Philippe Mathieu-Daudé posted 6 patches 10 months, 3 weeks ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, Richard Henderson <richard.henderson@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Yoshinori Sato <ysato@users.sourceforge.jp>
[PATCH-for-10.1 2/6] qom: Add object_class_implements_type()
Posted by Philippe Mathieu-Daudé 10 months, 3 weeks ago
Add the object_class_implements_type() method to check whether
a class implement a type, which can be ambiguous for interfaces.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qom/object.h | 10 ++++++++++
 qom/object.c         | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 9192265db76..fd74d4be89f 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -995,6 +995,16 @@ const char *object_class_get_name(ObjectClass *klass);
  */
 bool object_class_is_abstract(ObjectClass *klass);
 
+/**
+ * object_class_implements_type:
+ * @klass: The class to check the implementation for.
+ * @typename: The QOM typename of the implementation to check to.
+ *
+ * Returns: %true if @klass implements %typename, %false otherwise.
+ */
+bool object_class_implements_type(ObjectClass *class,
+                                  const char *typename);
+
 /**
  * object_class_by_name:
  * @typename: The QOM typename to obtain the class for.
diff --git a/qom/object.c b/qom/object.c
index 1620a87ef44..b9948937935 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -992,6 +992,17 @@ static ObjectClass *object_class_dynamic_cast_ambiguous(ObjectClass *class,
     return ret;
 }
 
+bool object_class_implements_type(ObjectClass *class,
+                                  const char *typename)
+{
+    ObjectClass *k;
+    bool ambiguous = false;
+
+    k = object_class_dynamic_cast_ambiguous(class, typename, &ambiguous);
+
+    return k || ambiguous;
+}
+
 ObjectClass *object_class_dynamic_cast(ObjectClass *class,
                                        const char *typename)
 {
-- 
2.47.1