[virt-tools-list] [libosinfo 1/8] Add OsinfoMedia::os property

Christophe Fergeau cfergeau at redhat.com
Mon Dec 3 11:23:30 UTC 2012


---
 osinfo/osinfo_media.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_media.h |  2 ++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index ffc37b7..6d0bdec 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;
+    OsinfoOs *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_set_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_clear_object(&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,20 @@ 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. Won't get filled before a call
+     * to osinfo_db_fill_media_info
+     */
+    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
@@ -1046,6 +1080,21 @@ gint osinfo_media_get_installer_reboots(OsinfoMedia *media)
             (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_INSTALLER_REBOOTS, 1);
 }
 
+OsinfoOs *osinfo_media_get_os(OsinfoMedia *media)
+{
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+
+    return media->priv->os;
+}
+
+void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os)
+{
+    g_return_if_fail(OSINFO_IS_MEDIA(media));
+
+    if (media->priv->os != NULL)
+        g_object_unref(media->priv->os);
+    media->priv->os = g_object_ref(os);
+}
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 5982580..3052abe 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -123,6 +123,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