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

[virt-tools-list] [libosinfo 01/10] Add DeviceDriver class



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 osinfo/Makefile.am                    |   3 +
 osinfo/libosinfo.syms                 |   7 ++
 osinfo/osinfo.h                       |   1 +
 osinfo/osinfo_device_driver.c         | 181 ++++++++++++++++++++++++++++++++++
 osinfo/osinfo_device_driver.h         |  93 +++++++++++++++++
 osinfo/osinfo_device_driver_private.h |  41 ++++++++
 6 files changed, 326 insertions(+)
 create mode 100644 osinfo/osinfo_device_driver.c
 create mode 100644 osinfo/osinfo_device_driver.h
 create mode 100644 osinfo/osinfo_device_driver_private.h

diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index c8a831b..996a498 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -59,6 +59,7 @@ libosinfo_1_0_include_HEADERS = \
   osinfo_db.h			\
   osinfo_loader.h		\
   osinfo_device.h		\
+  osinfo_device_driver.h	\
   osinfo_devicelink.h		\
   osinfo_devicelist.h		\
   osinfo_devicelinklist.h	\
@@ -95,6 +96,8 @@ libosinfo_1_0_la_SOURCES =	  \
   osinfo_filter.c		  \
   osinfo_list.c			  \
   osinfo_device.c		  \
+  osinfo_device_driver.c	  \
+  osinfo_device_driver_private.h  \
   osinfo_devicelink.c		  \
   osinfo_devicelist.c		  \
   osinfo_devicelinklist.c	  \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 2824678..09c0d3e 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -323,6 +323,13 @@ LIBOSINFO_0.2.2 {
 	osinfo_avatar_format_get_height;
 	osinfo_avatar_format_get_alpha;
 
+	osinfo_device_driver_get_type;
+	osinfo_device_driver_get_architecture;
+	osinfo_device_driver_get_devices;
+	osinfo_device_driver_get_location;
+	osinfo_device_driver_get_files;
+	osinfo_device_driver_get_pre_installable;
+
 	osinfo_install_config_param_policy_get_type;
 	osinfo_media_error_get_type;
 	osinfo_product_relationship_get_type;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 559eaa8..7acd70a 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -32,6 +32,7 @@
 #include <osinfo/osinfo_filter.h>
 #include <osinfo/osinfo_list.h>
 #include <osinfo/osinfo_device.h>
+#include <osinfo/osinfo_device_driver.h>
 #include <osinfo/osinfo_devicelink.h>
 #include <osinfo/osinfo_devicelist.h>
 #include <osinfo/osinfo_devicelinklist.h>
diff --git a/osinfo/osinfo_device_driver.c b/osinfo/osinfo_device_driver.c
new file mode 100644
index 0000000..9a7e5e2
--- /dev/null
+++ b/osinfo/osinfo_device_driver.c
@@ -0,0 +1,181 @@
+/*
+ * libosinfo: Device driver
+ *
+ * Copyright (C) 2009-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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Zeeshan Ali <zeenix redhat com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+
+#include "osinfo_device_driver_private.h"
+
+G_DEFINE_TYPE (OsinfoDeviceDriver, osinfo_device_driver, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_DEVICE_DRIVER_GET_PRIVATE(obj) \
+        (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+                                      OSINFO_TYPE_DEVICE_DRIVER, \
+                                      OsinfoDeviceDriverPrivate))
+
+/**
+ * SECTION:osinfo_device_driver
+ * @short_description: Information about device driver
+ * @see_also: #OsinfoOs
+ *
+ * #OsinfoDeviceDriver is an entity representing device drivers for an (guest)
+ * operating system.
+ */
+
+struct _OsinfoDeviceDriverPrivate
+{
+    OsinfoDeviceList *devices;
+};
+
+static void
+osinfo_device_driver_finalize (GObject *object)
+{
+    OsinfoDeviceDriver *driver = OSINFO_DEVICE_DRIVER (object);
+
+    g_object_unref(driver->priv->devices);
+
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_device_driver_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_device_driver_class_init (OsinfoDeviceDriverClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+    g_klass->finalize = osinfo_device_driver_finalize;
+    g_type_class_add_private (klass, sizeof (OsinfoDeviceDriverPrivate));
+}
+
+static void
+osinfo_device_driver_init (OsinfoDeviceDriver *driver)
+{
+    OsinfoDeviceDriverPrivate *priv;
+    driver->priv = priv = OSINFO_DEVICE_DRIVER_GET_PRIVATE(driver);
+
+    priv->devices = osinfo_devicelist_new ();
+}
+
+OsinfoDeviceDriver *osinfo_device_driver_new(const gchar *id)
+{
+    OsinfoDeviceDriver *driver;
+
+    driver = g_object_new (OSINFO_TYPE_DEVICE_DRIVER,
+                           "id", id,
+                           NULL);
+
+    return driver;
+}
+
+/**
+ * osinfo_device_driver_get_architecture:
+ * @driver: a #OsinfoDeviceDriver instance
+ *
+ * Retrieves the target hardware architecture of @driver.
+ *
+ * Returns: (transfer none): the hardware architecture.
+ */
+const gchar *osinfo_device_driver_get_architecture(OsinfoDeviceDriver *driver)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(driver),
+                                         OSINFO_DEVICE_DRIVER_PROP_ARCHITECTURE);
+}
+
+/**
+ * osinfo_device_driver_get_location:
+ * @driver: a #OsinfoDeviceDriver instance
+ *
+ * Retrieves the location of the @driver as a URL.
+ *
+ * Returns: (transfer none): the location of the driver.
+ */
+const gchar *osinfo_device_driver_get_location(OsinfoDeviceDriver *driver)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(driver),
+                                         OSINFO_DEVICE_DRIVER_PROP_LOCATION);
+}
+
+/**
+ * osinfo_device_driver_get_files:
+ * @driver: a #OsinfoDeviceDriver instance
+ *
+ * Retrieves the names of driver files under the location returned by
+ * #osinfo_device_driver_get_location.
+ *
+ * Returns: (transfer container) (element-type utf8): The list of driver files.
+ */
+GList *osinfo_device_driver_get_files(OsinfoDeviceDriver *driver)
+{
+    return osinfo_entity_get_param_value_list(OSINFO_ENTITY(driver),
+                                              OSINFO_DEVICE_DRIVER_PROP_FILE);
+}
+
+/**
+ * osinfo_device_driver_get_pre_installable:
+ * @driver: a #OsinfoDeviceDriver instance
+ *
+ * Returns: TRUE if @driver is pre-installable, FALSE otherwise.
+ */
+gboolean osinfo_device_driver_get_pre_installable(OsinfoDeviceDriver *driver)
+{
+    return osinfo_entity_get_param_value_boolean
+                (OSINFO_ENTITY(driver),
+                 OSINFO_DEVICE_DRIVER_PROP_PRE_INSTALLABLE);
+}
+
+/**
+ * osinfo_device_driver_get_devices:
+ * @driver: a #OsinfoDeviceDriver instance
+ *
+ * Returns: (transfer none): The list of devices supported by this driver.
+ */
+OsinfoDeviceList *osinfo_device_driver_get_devices(OsinfoDeviceDriver *driver)
+{
+    g_return_val_if_fail(OSINFO_IS_DEVICE_DRIVER(driver), NULL);
+
+    return driver->priv->devices;
+}
+
+void osinfo_device_driver_add_device(OsinfoDeviceDriver *driver,
+                                     OsinfoDevice *device)
+{
+    g_return_if_fail(OSINFO_IS_DEVICE_DRIVER(driver));
+    g_return_if_fail(OSINFO_IS_DEVICE(device));
+
+    osinfo_list_add(OSINFO_LIST(driver->priv->devices),
+                    OSINFO_ENTITY(device));
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_device_driver.h b/osinfo/osinfo_device_driver.h
new file mode 100644
index 0000000..81e462c
--- /dev/null
+++ b/osinfo/osinfo_device_driver.h
@@ -0,0 +1,93 @@
+/*
+ * libosinfo: Device driver
+ *
+ * Copyright (C) 2009-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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Zeeshan Ali <zeenix redhat com>
+ */
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <osinfo/osinfo_entity.h>
+#include <osinfo/osinfo_devicelist.h>
+
+#ifndef __OSINFO_DEVICE_DRIVER_H__
+#define __OSINFO_DEVICE_DRIVER_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_DEVICE_DRIVER                  (osinfo_device_driver_get_type ())
+#define OSINFO_DEVICE_DRIVER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                OSINFO_TYPE_DEVICE_DRIVER, OsinfoDeviceDriver))
+#define OSINFO_IS_DEVICE_DRIVER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                                                OSINFO_TYPE_DEVICE_DRIVER))
+#define OSINFO_DEVICE_DRIVER_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                                OSINFO_TYPE_DEVICE_DRIVER, OsinfoDeviceDriverClass))
+#define OSINFO_IS_DEVICE_DRIVER_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+                                                OSINFO_TYPE_DEVICE_DRIVER))
+#define OSINFO_DEVICE_DRIVER_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                                OSINFO_TYPE_DEVICE_DRIVER, OsinfoDeviceDriverClass))
+
+typedef struct _OsinfoDeviceDriver        OsinfoDeviceDriver;
+
+typedef struct _OsinfoDeviceDriverClass   OsinfoDeviceDriverClass;
+
+typedef struct _OsinfoDeviceDriverPrivate OsinfoDeviceDriverPrivate;
+
+#define OSINFO_DEVICE_DRIVER_PROP_ARCHITECTURE    "arch"
+#define OSINFO_DEVICE_DRIVER_PROP_LOCATION        "location"
+#define OSINFO_DEVICE_DRIVER_PROP_PRE_INSTALLABLE "pre-installable"
+#define OSINFO_DEVICE_DRIVER_PROP_FILE            "file"
+#define OSINFO_DEVICE_DRIVER_PROP_DEVICE          "device"
+
+/* object */
+struct _OsinfoDeviceDriver
+{
+    OsinfoEntity parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoDeviceDriverPrivate *priv;
+};
+
+/* class */
+struct _OsinfoDeviceDriverClass
+{
+    OsinfoEntityClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_device_driver_get_type(void);
+
+const gchar *osinfo_device_driver_get_architecture(OsinfoDeviceDriver *driver);
+const gchar *osinfo_device_driver_get_location(OsinfoDeviceDriver *driver);
+gboolean osinfo_device_driver_get_pre_installable(OsinfoDeviceDriver *driver);
+GList *osinfo_device_driver_get_files(OsinfoDeviceDriver *driver);
+OsinfoDeviceList *osinfo_device_driver_get_devices(OsinfoDeviceDriver *driver);
+
+#endif /* __OSINFO_DEVICE_DRIVER_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_device_driver_private.h b/osinfo/osinfo_device_driver_private.h
new file mode 100644
index 0000000..d49ffa1
--- /dev/null
+++ b/osinfo/osinfo_device_driver_private.h
@@ -0,0 +1,41 @@
+/*
+ * libosinfo: Device driver
+ *
+ * Copyright (C) 2009-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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Zeeshan Ali <zeenix redhat com>
+ */
+
+#include "osinfo_device_driver.h"
+
+#ifndef __OSINFO_DEVICE_DRIVER_PRIVATE_H__
+#define __OSINFO_DEVICE_DRIVER_PRIVATE_H__
+
+OsinfoDeviceDriver *osinfo_device_driver_new(const gchar *id);
+void osinfo_device_driver_add_device(OsinfoDeviceDriver *driver,
+                                     OsinfoDevice *device);
+
+#endif /* __OSINFO_DEVICE_DRIVER_PRIVATE_H__ */
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
1.8.0.1


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