[libvirt-glib 08/13] Implement GVirConfigDomainAddressPci

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

 



It already has the needed setters.
---
 libvirt-gconfig/Makefile.am                        |    2 +
 .../libvirt-gconfig-domain-address-pci.c           |  124 ++++++++++++++++++++
 .../libvirt-gconfig-domain-address-pci.h           |   78 ++++++++++++
 libvirt-gconfig/libvirt-gconfig.h                  |    1 +
 libvirt-gconfig/libvirt-gconfig.sym                |    9 ++
 5 files changed, 214 insertions(+)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-pci.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-pci.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 0172d06..b69ed9d 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -14,6 +14,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-capabilities.h \
 			libvirt-gconfig-domain.h \
 			libvirt-gconfig-domain-address.h \
+			libvirt-gconfig-domain-address-pci.h \
 			libvirt-gconfig-domain-channel.h \
 			libvirt-gconfig-domain-chardev.h \
 			libvirt-gconfig-domain-chardev-source.h \
@@ -70,6 +71,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-capabilities.c \
 			libvirt-gconfig-domain.c \
 			libvirt-gconfig-domain-address.c \
+			libvirt-gconfig-domain-address-pci.c \
 			libvirt-gconfig-domain-channel.c \
 			libvirt-gconfig-domain-chardev.c \
 			libvirt-gconfig-domain-chardev-source.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c
new file mode 100644
index 0000000..48e3872
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c
@@ -0,0 +1,124 @@
+/*
+ * libvirt-gconfig-domain-address-pci.c: libvirt pci device address configuration
+ *
+ * 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: Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciPrivate))
+
+struct _GVirConfigDomainAddressPciPrivate
+{
+    gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainAddressPci, gvir_config_domain_address_pci, GVIR_CONFIG_TYPE_DOMAIN_ADDRESS);
+
+
+static void gvir_config_domain_address_pci_class_init(GVirConfigDomainAddressPciClass *klass)
+{
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainAddressPciPrivate));
+}
+
+
+static void gvir_config_domain_address_pci_init(GVirConfigDomainAddressPci *address)
+{
+    g_debug("Init GVirConfigDomainAddressPci=%p", address);
+
+    address->priv = GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_PRIVATE(address);
+}
+
+
+GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI,
+                                    "address", NULL);
+    gvir_config_object_set_attribute(object, "type", "pci", NULL);
+    return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object);
+}
+
+GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml,
+                                                                        GError **error)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI,
+                                             "address", NULL, xml, error);
+    gvir_config_object_set_attribute(object, "type", "pci", NULL);
+    return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object);
+}
+
+static void set_attribute_hex(GVirConfigDomainAddressPci *address,
+                              const char *attr_name,
+                              guint attr_val,
+                              guint min_val,
+                              guint max_val,
+                              guint size)
+{
+    char *hex_str;
+    char *format;
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address));
+    g_return_if_fail((attr_val >= min_val) && (attr_val <= max_val));
+
+    format = g_strdup_printf("0x%%0%dx", size);
+    hex_str = g_strdup_printf(format, attr_val);
+    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address),
+                                     attr_name, hex_str, NULL);
+    g_free(hex_str);
+    g_free(format);
+}
+
+void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address,
+                                               guint16 pci_domain)
+{
+    set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4);
+}
+
+void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address,
+                                            guchar bus)
+{
+    set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2);
+}
+
+void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address,
+                                             guchar slot)
+{
+    set_attribute_hex(address, "slot", slot, 0, 0x1f, 2);
+}
+
+void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address,
+                                                 guchar function)
+{
+    set_attribute_hex(address, "function", function, 0, 7, 1);
+}
+
+void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address,
+                                                      gboolean multifunction)
+{
+    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address),
+                                     "multifunction",
+                                     multifunction?"on":"off", NULL);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h
new file mode 100644
index 0000000..8d722bb
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h
@@ -0,0 +1,78 @@
+/*
+ * libvirt-gconfig-domain-address-pci.h: libvirt PCI device address configuration
+ *
+ * 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: Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_PCI_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_PCI_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI            (gvir_config_domain_address_pci_get_type ())
+#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPci))
+#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciClass))
+#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI))
+#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI))
+#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciClass))
+
+typedef struct _GVirConfigDomainAddressPci GVirConfigDomainAddressPci;
+typedef struct _GVirConfigDomainAddressPciPrivate GVirConfigDomainAddressPciPrivate;
+typedef struct _GVirConfigDomainAddressPciClass GVirConfigDomainAddressPciClass;
+
+struct _GVirConfigDomainAddressPci
+{
+    GVirConfigDomainAddress parent;
+
+    GVirConfigDomainAddressPciPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainAddressPciClass
+{
+    GVirConfigDomainAddressClass parent_class;
+
+    gpointer padding[20];
+};
+
+GType gvir_config_domain_address_pci_get_type(void);
+
+GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void);
+GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml,
+                                                                        GError **error);
+
+void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address,
+                                               guint16 pci_domain);
+void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address,
+                                            guchar bus);
+void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address,
+                                             guchar slot);
+void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address,
+                                                 guchar function);
+void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address,
+                                                      gboolean multifunction);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_PCI_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 69fbd42..28d9c86 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -31,6 +31,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-capabilities.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-address.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 21c9530..39e8623 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -36,6 +36,15 @@ LIBVIRT_GCONFIG_0.0.4 {
 
 	gvir_config_domain_address_get_type;
 
+	gvir_config_domain_address_pci_get_type;
+	gvir_config_domain_address_pci_new;
+	gvir_config_domain_address_pci_new_from_xml;
+	gvir_config_domain_address_pci_set_bus;
+	gvir_config_domain_address_pci_set_domain;
+	gvir_config_domain_address_pci_set_function;
+	gvir_config_domain_address_pci_set_multifunction;
+	gvir_config_domain_address_pci_set_slot;
+
 	gvir_config_domain_channel_get_type;
 	gvir_config_domain_channel_new;
 	gvir_config_domain_channel_new_from_xml;
-- 
1.7.9.3

--
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]