[libvirt-glib v3 1/2] Make GVirConfigCapabilitiesCpu.get_features virtual

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

Also provide helper function for subclasses that will have the exact
same implementation except that they'll return instances of another type
(subclasses of GVirConfigDomainCpuFeature rather than
GVirConfigDomainCpuFeature itself).
---
 libvirt-gconfig/Makefile.am                        |    1 +
 .../libvirt-gconfig-capabilities-cpu-private.h     |   35 ++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c |   42 +++++++++++++++-----
 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h |    4 +-
 libvirt-gconfig/libvirt-gconfig-private.h          |    1 +
 5 files changed, 71 insertions(+), 12 deletions(-)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 7f0ea3b..52f2d52 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -73,6 +73,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-storage-vol-target.h
 noinst_HEADERS = \
 			libvirt-gconfig-private.h \
+			libvirt-gconfig-capabilities-cpu-private.h \
 			libvirt-gconfig-domain-device-private.h \
 			libvirt-gconfig-helpers-private.h \
 			libvirt-gconfig-object-private.h \
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h
new file mode 100644
index 0000000..4832656
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h
@@ -0,0 +1,35 @@
+/*
+ * libvirt-gconfig-capabilities-cpu-private.h: libvirt CPU capabilities
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak@xxxxxxxxx>
+ */
+#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__
+#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__
+
+G_BEGIN_DECLS
+
+#include <libvirt-gconfig/libvirt-gconfig.h>
+
+GList *
+gvir_config_capabilities_cpu_get_features_with_type(GVirConfigCapabilitiesCpu *cpu,
+                                                    GType type);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
index e517a20..5b619b5 100644
--- a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
+++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
@@ -37,10 +37,14 @@ struct _GVirConfigCapabilitiesCpuPrivate
 
 G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT);
 
+static GList *
+_gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu);
 
 static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass)
 {
     g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate));
+
+    klass->get_features = _gvir_config_capabilities_cpu_get_features;
 }
 
 static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu)
@@ -75,6 +79,7 @@ struct GetFeatureData {
     GVirConfigXmlDoc *doc;
     const gchar *schema;
     GList *features;
+    GType type;
 };
 
 static gboolean add_feature(xmlNodePtr node, gpointer opaque)
@@ -86,7 +91,7 @@ static gboolean add_feature(xmlNodePtr node, gpointer opaque)
         return TRUE;
 
     feature = gvir_config_object_new_from_tree
-                                (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE,
+                                (data->type,
                                  data->doc,
                                  data->schema,
                                  node);
@@ -98,16 +103,9 @@ static gboolean add_feature(xmlNodePtr node, gpointer opaque)
     return TRUE;
 }
 
-/**
- * gvir_config_capabilities_cpu_get_features:
- *
- * Gets the features of this CPU.
- *
- * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full):
- * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature.
- */
-GList *
-gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
+G_GNUC_INTERNAL GList *
+gvir_config_capabilities_cpu_get_features_with_type(GVirConfigCapabilitiesCpu *cpu,
+                                                    GType type)
 {
     struct GetFeatureData data;
 
@@ -117,6 +115,7 @@ gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
     g_object_get(G_OBJECT(cpu), "doc", &data.doc, NULL);
     g_return_val_if_fail(data.doc != NULL, NULL);
     data.features = NULL;
+    data.type = type;
 
     gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(cpu),
                                      NULL,
@@ -127,6 +126,27 @@ gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
     return data.features;
 }
 
+static GList *
+_gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
+{
+    return gvir_config_capabilities_cpu_get_features_with_type(
+                        cpu, GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE);
+}
+
+/**
+ * gvir_config_capabilities_cpu_get_features:
+ *
+ * Gets the features of this CPU.
+ *
+ * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full):
+ * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature.
+ */
+GList *
+gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
+{
+    return GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(cpu)->get_features(cpu);
+}
+
 /**
  * gvir_config_capabilities_cpu_get_topology:
  *
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
index 67fe607..be6c06f 100644
--- a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
+++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
@@ -57,7 +57,9 @@ struct _GVirConfigCapabilitiesCpuClass
 {
     GVirConfigObjectClass parent_class;
 
-    gpointer padding[20];
+    GList *(*get_features)(GVirConfigCapabilitiesCpu *cpu);
+
+    gpointer padding[19];
 };
 
 GType gvir_config_capabilities_cpu_get_type(void);
diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h
index d4df030..ea532ad 100644
--- a/libvirt-gconfig/libvirt-gconfig-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-private.h
@@ -23,6 +23,7 @@
 #ifndef __LIBVIRT_GCONFIG_PRIVATE_H__
 #define __LIBVIRT_GCONFIG_PRIVATE_H__
 
+#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h>
 #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h>
 #include <libvirt-gconfig/libvirt-gconfig-object-private.h>
-- 
1.7.10.4

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]