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

Christophe Fergeau cfergeau at redhat.com
Wed Dec 12 14:26:30 UTC 2012


---
 osinfo/Makefile.am            |  1 +
 osinfo/libosinfo.syms         |  2 ++
 osinfo/osinfo_media.c         | 55 ++++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_media.h         |  1 +
 osinfo/osinfo_media_private.h | 38 ++++++++++++++++++++++++++++++
 5 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 osinfo/osinfo_media_private.h

diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 20b1ac4..056373f 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -127,6 +127,7 @@ libosinfo_1_0_la_SOURCES =		\
   osinfo_deployment.c			\
   osinfo_deploymentlist.c		\
   osinfo_media.c			\
+  osinfo_media_private.h		\
   osinfo_medialist.c			\
   osinfo_resources.c			\
   osinfo_resourceslist.c		\
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index c5ab005..95fde94 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -395,6 +395,8 @@ LIBOSINFO_0.2.3 {
 	osinfo_install_config_paramlist_new;
 
 	osinfo_install_script_get_config_params;
+
+	osinfo_media_get_os;
 } LIBOSINFO_0.2.2;
 
 /* Symbols in next release...
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index ffc37b7..1db374c 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -26,6 +26,7 @@
 #include <config.h>
 
 #include <osinfo/osinfo.h>
+#include "osinfo_media_private.h"
 #include <gio/gio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -136,7 +137,7 @@ G_DEFINE_TYPE (OsinfoMedia, osinfo_media, OSINFO_TYPE_ENTITY);
 
 struct _OsinfoMediaPrivate
 {
-    gboolean unused;
+    GWeakRef os;
 };
 
 enum {
@@ -153,6 +154,7 @@ enum {
     PROP_INSTALLER,
     PROP_LIVE,
     PROP_INSTALLER_REBOOTS,
+    PROP_OS
 };
 
 static void
@@ -219,6 +221,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 +307,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 +325,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 +342,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 +501,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 +521,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 +1081,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..8d34688 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -124,6 +124,7 @@ 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);
 gboolean osinfo_media_get_installer(OsinfoMedia *media);
 gboolean osinfo_media_get_live(OsinfoMedia *media);
 gint osinfo_media_get_installer_reboots(OsinfoMedia *media);
diff --git a/osinfo/osinfo_media_private.h b/osinfo/osinfo_media_private.h
new file mode 100644
index 0000000..00ae697
--- /dev/null
+++ b/osinfo/osinfo_media_private.h
@@ -0,0 +1,38 @@
+/*
+ * libosinfo: An installation media for a (guest) OS
+ *
+ * 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:
+ *   Christophe Fergeau <cfergeau at redhat.com>
+ */
+
+#include <osinfo/osinfo_media.h>
+
+#ifndef __OSINFO_MEDIA_PRIVATE_H__
+#define __OSINFO_MEDIA_PRIVATE_H__
+
+void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os);
+
+#endif /* __OSINFO_MEDIA_PRIVATE_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
1.8.0.1




More information about the virt-tools-list mailing list