[virt-tools-list] [libosinfo 3/8] Add Media class
Zeeshan Ali (Khattak)
zeeshanak at gnome.org
Thu Aug 4 18:21:10 UTC 2011
From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
Add a new class to represent installation media, typically an CD/DVD ISO
or an online filesystem hierarchy.
---
docs/reference/Libosinfo-sections.txt | 22 ++++
docs/reference/Libosinfo.types | 1 +
osinfo/Makefile.am | 4 +-
osinfo/libosinfo.syms | 13 +++
osinfo/osinfo.h | 1 +
osinfo/osinfo_media.c | 178 +++++++++++++++++++++++++++++++++
osinfo/osinfo_media.h | 90 +++++++++++++++++
7 files changed, 308 insertions(+), 1 deletions(-)
create mode 100644 osinfo/osinfo_media.c
create mode 100644 osinfo/osinfo_media.h
diff --git a/docs/reference/Libosinfo-sections.txt b/docs/reference/Libosinfo-sections.txt
index e7e9b8b..8c1100b 100644
--- a/docs/reference/Libosinfo-sections.txt
+++ b/docs/reference/Libosinfo-sections.txt
@@ -394,6 +394,28 @@ OSINFO_DEVICE_GET_CLASS
</SECTION>
<SECTION>
+<FILE>osinfo_media</FILE>
+<TITLE>OsinfoMedia</TITLE>
+OsinfoMedia
+OsinfMediaoClass
+OsinfMediaoPrivate
+osinfo_media_new
+osinfo_media_get_architecture
+osinfo_media_get_url
+osinfo_media_get_volume_id
+osinfo_media_get_system_id
+osinfo_media_get_publisher_id
+<SUBSECTION Standard>
+OSINFO_MEDIA
+OSINFO_IS_MEDIA
+OSINFO_TYPE_MEDIA
+osinfo_media_get_type
+OSINFO_MEDIA_CLASS
+OSINFO_IS_MEDIA_CLASS
+OSINFO_MEDIA_GET_CLASS
+</SECTION>
+
+<SECTION>
<FILE>osinfo_devicelink</FILE>
<TITLE>OsinfoDeviceLink</TITLE>
OsinfoDeviceLink
diff --git a/docs/reference/Libosinfo.types b/docs/reference/Libosinfo.types
index 8add117..dc60a54 100644
--- a/docs/reference/Libosinfo.types
+++ b/docs/reference/Libosinfo.types
@@ -17,3 +17,4 @@ osinfo_oslist_get_type
osinfo_devicelink_get_type
osinfo_devicelinklist_get_type
osinfo_devicelinkfilter_get_type
+osinfo_media_get_type
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 6cb824c..122e6dc 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -61,7 +61,8 @@ libosinfo_1_0_include_HEADERS = \
osinfo_os.h \
osinfo_oslist.h \
osinfo_deployment.h \
- osinfo_deploymentlist.h
+ osinfo_deploymentlist.h \
+ osinfo_media.h
libosinfo_1_0_la_SOURCES = \
osinfo_entity.c \
@@ -81,6 +82,7 @@ libosinfo_1_0_la_SOURCES = \
osinfo_os.c \
osinfo_deployment.c \
osinfo_deploymentlist.c \
+ osinfo_media.c \
osinfo_db.c \
osinfo_loader.c
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 47d0449..bb35021 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -137,6 +137,19 @@ LIBOSINFO_0.0.1 {
osinfo_deploymentlist_new_filtered;
osinfo_deploymentlist_new_intersection;
osinfo_deploymentlist_new_union;
+ osinfo_media_get_type;
+ osinfo_media_new;
+ osinfo_media_get_architecture;
+ osinfo_media_get_url;
+ osinfo_media_get_volume_id;
+ osinfo_media_get_system_id;
+ osinfo_media_get_publisher_id;
+ osinfo_medialist_get_type;
+ osinfo_medialist_new;
+ osinfo_medialist_new_copy;
+ osinfo_medialist_new_filtered;
+ osinfo_medialist_new_intersection;
+ osinfo_medialist_new_union;
local:
*;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index c1d79d6..72986ed 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -42,6 +42,7 @@
#include <osinfo/osinfo_os.h>
#include <osinfo/osinfo_deploymentlist.h>
#include <osinfo/osinfo_deployment.h>
+#include <osinfo/osinfo_media.h>
#include <osinfo/osinfo_db.h>
#include <osinfo/osinfo_loader.h>
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
new file mode 100644
index 0000000..5af6d67
--- /dev/null
+++ b/osinfo/osinfo_media.c
@@ -0,0 +1,178 @@
+/*
+ * libosinfo: An installation media for a (guest) OS
+ *
+ * Copyright (C) 2009-2011 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
+ *
+ * Authors:
+ * Zeeshan Ali <zeenix at redhat.com>
+ * Arjun Roy <arroy at redhat.com>
+ * Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <osinfo/osinfo.h>
+
+G_DEFINE_TYPE (OsinfoMedia, osinfo_media, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_MEDIA_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ OSINFO_TYPE_MEDIA, \
+ OsinfoMediaPrivate))
+
+/**
+ * SECTION:osinfo_media
+ * @short_description: An installation media for a (guest) OS
+ * @see_also: #OsinfoOs
+ *
+ * #OsinfoMedia is an entity representing an installation media
+ * a (guest) operating system.
+ */
+
+struct _OsinfoMediaPrivate
+{
+ gboolean unused;
+};
+
+
+static void
+osinfo_media_finalize (GObject *object)
+{
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (osinfo_media_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_media_class_init (OsinfoMediaClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+ g_klass->finalize = osinfo_media_finalize;
+ g_type_class_add_private (klass, sizeof (OsinfoMediaPrivate));
+}
+
+static void
+osinfo_media_init (OsinfoMedia *media)
+{
+ OsinfoMediaPrivate *priv;
+ media->priv = priv = OSINFO_MEDIA_GET_PRIVATE(media);
+}
+
+OsinfoMedia *osinfo_media_new(const gchar *id,
+ const gchar *architecture)
+{
+ OsinfoMedia *media;
+
+ media = g_object_new(OSINFO_TYPE_MEDIA,
+ "id", id,
+ NULL);
+
+ osinfo_entity_set_param(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_ARCHITECTURE,
+ architecture);
+
+ return media;
+}
+
+/**
+ * osinfo_entity_get_architecture:
+ * @media: a #OsinfoMedia instance
+ *
+ * Retrieves the target hardware architecture of the OS @media provides.
+ *
+ * Returns: (transfer none): the hardware architecture, or NULL
+ */
+const gchar *osinfo_media_get_architecture(OsinfoMedia *media)
+{
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_ARCHITECTURE);
+}
+
+/**
+ * osinfo_entity_get_url:
+ * @media: a #OsinfoMedia instance
+ *
+ * The URL to the @media
+ *
+ * Returns: (transfer none): the URL, or NULL
+ */
+const gchar *osinfo_media_get_url(OsinfoMedia *media)
+{
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_URL);
+}
+
+/**
+ * osinfo_entity_get_volume_id:
+ * @media: a #OsinfoMedia instance
+ *
+ * If @media is an ISO9660 image/device, this function retrieves the expected
+ * volume ID.
+ *
+ * Note: In practice, this will usually not be an exact match to the volume ID
+ * on the ISO image/device but rather a substring of it.
+ *
+ * Returns: (transfer none): the volume id, or NULL
+ */
+const gchar *osinfo_media_get_volume_id(OsinfoMedia *media)
+{
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_VOLUME_ID);
+}
+
+/**
+ * osinfo_entity_get_system_id:
+ * @media: a #OsinfoMedia instance
+ *
+ * If @media is an ISO9660 image/device, this function retrieves the expected
+ * system ID.
+ *
+ * Note: In practice, this will usually not be an exact match to the system ID
+ * on the ISO image/device but rather a substring of it.
+ *
+ * Returns: (transfer none): the system id, or NULL
+ */
+const gchar *osinfo_media_get_system_id(OsinfoMedia *media)
+{
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_SYSTEM_ID);
+}
+
+/**
+ * osinfo_entity_get_publisher_id:
+ * @media: a #OsinfoMedia instance
+ *
+ * If @media is an ISO9660 image/device, this function retrieves the expected
+ * publisher ID.
+ *
+ * Note: In practice, this will usually not be an exact match to the system ID
+ * on the ISO image/device but rather a substring of it.
+ *
+ * Returns: (transfer none): the publisher id, or NULL
+ */
+const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media)
+{
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+ OSINFO_MEDIA_PROP_PUBLISHER_ID);
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
new file mode 100644
index 0000000..4552da9
--- /dev/null
+++ b/osinfo/osinfo_media.h
@@ -0,0 +1,90 @@
+/*
+ * libosinfo: An installation media for a (guest) OS
+ *
+ * Copyright (C) 2009-2011 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
+ *
+ * Authors:
+ * Zeeshan Ali <zeenix at redhat.com>
+ * Arjun Roy <arroy at redhat.com>
+ * Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_entity.h>
+
+#ifndef __OSINFO_MEDIA_H__
+#define __OSINFO_MEDIA_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_MEDIA (osinfo_media_get_type ())
+#define OSINFO_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_MEDIA, OsinfoMedia))
+#define OSINFO_IS_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_MEDIA))
+#define OSINFO_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_MEDIA, OsinfoMediaClass))
+#define OSINFO_IS_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_MEDIA))
+#define OSINFO_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_MEDIA, OsinfoMediaClass))
+
+typedef struct _OsinfoMedia OsinfoMedia;
+
+typedef struct _OsinfoMediaClass OsinfoMediaClass;
+
+typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
+
+#define OSINFO_MEDIA_PROP_ARCHITECTURE "architecture"
+#define OSINFO_MEDIA_PROP_URL "url"
+#define OSINFO_MEDIA_PROP_VOLUME_ID "volume-id"
+#define OSINFO_MEDIA_PROP_SYSTEM_ID "system-id"
+#define OSINFO_MEDIA_PROP_PUBLISHER_ID "publisher-id"
+
+/* object */
+struct _OsinfoMedia
+{
+ OsinfoEntity parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoMediaPrivate *priv;
+};
+
+/* class */
+struct _OsinfoMediaClass
+{
+ OsinfoEntityClass parent_class;
+
+ /* class members */
+};
+
+GType osinfo_media_get_type(void);
+
+OsinfoMedia *osinfo_media_new(const gchar *id, const gchar *architecture);
+
+const gchar *osinfo_media_get_architecture(OsinfoMedia *media);
+const gchar *osinfo_media_get_url(OsinfoMedia *media);
+const gchar *osinfo_media_get_volume_id(OsinfoMedia *media);
+const gchar *osinfo_media_get_system_id(OsinfoMedia *media);
+const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media);
+
+#endif /* __OSINFO_MEDIA_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
--
1.7.6
More information about the virt-tools-list
mailing list