[virt-tools-list] [libosinfo PATCHv2 1/9] Add OsinfoMedia::os property
Christophe Fergeau
cfergeau at redhat.com
Tue Dec 11 20:17:03 UTC 2012
---
osinfo/osinfo_media.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-
osinfo/osinfo_media.h | 2 ++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index ffc37b7..e073ff6 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -136,7 +136,7 @@ G_DEFINE_TYPE (OsinfoMedia, osinfo_media, OSINFO_TYPE_ENTITY);
struct _OsinfoMediaPrivate
{
- gboolean unused;
+ GWeakRef os;
};
enum {
@@ -153,6 +153,7 @@ enum {
PROP_INSTALLER,
PROP_LIVE,
PROP_INSTALLER_REBOOTS,
+ PROP_OS
};
static void
@@ -219,6 +220,10 @@ osinfo_media_get_property (GObject *object,
osinfo_media_get_installer_reboots (media));
break;
+ case PROP_OS:
+ g_value_take_object (value, osinfo_media_get_os (media));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -301,6 +306,10 @@ osinfo_media_set_property(GObject *object,
g_value_get_int (value));
break;
+ case PROP_OS:
+ osinfo_media_set_os(media, g_value_get_object(value));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -315,6 +324,16 @@ osinfo_media_finalize (GObject *object)
G_OBJECT_CLASS (osinfo_media_parent_class)->finalize (object);
}
+static void osinfo_media_dispose(GObject *obj)
+{
+ OsinfoMedia *media = OSINFO_MEDIA(obj);
+
+ g_weak_ref_clear(&media->priv->os);
+
+ G_OBJECT_CLASS(osinfo_media_parent_class)->dispose(obj);
+}
+
+
/* Init functions */
static void
osinfo_media_class_init (OsinfoMediaClass *klass)
@@ -322,6 +341,7 @@ osinfo_media_class_init (OsinfoMediaClass *klass)
GObjectClass *g_klass = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
+ g_klass->dispose = osinfo_media_dispose;
g_klass->finalize = osinfo_media_finalize;
g_klass->get_property = osinfo_media_get_property;
g_klass->set_property = osinfo_media_set_property;
@@ -480,6 +500,19 @@ osinfo_media_class_init (OsinfoMediaClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_property (g_klass, PROP_INSTALLER_REBOOTS, pspec);
+
+ /**
+ * OsinfoMedia::os:
+ *
+ * Os information for the current media.
+ */
+ pspec = g_param_spec_object ("os",
+ "Os",
+ _("Information about the operating system on this media"),
+ OSINFO_TYPE_OS,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (g_klass, PROP_OS, pspec);
}
static void
@@ -487,6 +520,7 @@ osinfo_media_init (OsinfoMedia *media)
{
OsinfoMediaPrivate *priv;
media->priv = priv = OSINFO_MEDIA_GET_PRIVATE(media);
+ g_weak_ref_init(&media->priv->os, NULL);
}
OsinfoMedia *osinfo_media_new(const gchar *id,
@@ -1046,6 +1080,24 @@ gint osinfo_media_get_installer_reboots(OsinfoMedia *media)
(OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_INSTALLER_REBOOTS, 1);
}
+/* osinfo_media_get_os:
+ * Returns: (transfer full):
+ */
+OsinfoOs *osinfo_media_get_os(OsinfoMedia *media)
+{
+ g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+
+ return g_weak_ref_get(&media->priv->os);
+}
+
+void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os)
+{
+ g_return_if_fail(OSINFO_IS_MEDIA(media));
+
+ g_object_ref(os);
+ g_weak_ref_set(&media->priv->os, os);
+ g_object_unref(os);
+}
/*
* Local variables:
* indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index ee37905..2a4f392 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -124,6 +124,8 @@ const gchar *osinfo_media_get_publisher_id(OsinfoMedia *media);
const gchar *osinfo_media_get_application_id(OsinfoMedia *media);
const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
+OsinfoOs *osinfo_media_get_os(OsinfoMedia *media);
+void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os);
gboolean osinfo_media_get_installer(OsinfoMedia *media);
gboolean osinfo_media_get_live(OsinfoMedia *media);
gint osinfo_media_get_installer_reboots(OsinfoMedia *media);
--
1.8.0.1
More information about the virt-tools-list
mailing list