[virt-tools-list] [libosinfo 08/11] Add OsinfoInstallConfig::valid-params property

Christophe Fergeau cfergeau at redhat.com
Mon Dec 10 16:46:04 UTC 2012


This property lists the parameters that can be set for a given
OsinfoInstallConfig. This is not enforced, it's only there for
informative purpose. This will also be used in later commits
in order to automatically apply transformations on values
for parameters which have an associated OsinfoDatamap.
---
 osinfo/libosinfo.syms          |  2 +
 osinfo/osinfo_install_config.c | 95 +++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_install_config.h |  7 ++++
 3 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 7ec1bbd..a0a5891 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -367,6 +367,8 @@ LIBOSINFO_0.2.2 {
 	osinfo_install_config_set_script_disk;
 	osinfo_install_config_get_target_disk;
 	osinfo_install_config_set_target_disk;
+	osinfo_install_config_get_valid_params;
+	osinfo_install_config_set_valid_params;
 
 	osinfo_install_config_paramlist_get_type;
 	osinfo_install_config_paramlist_new;
diff --git a/osinfo/osinfo_install_config.c b/osinfo/osinfo_install_config.c
index 64e7ed5..6fdc61f 100644
--- a/osinfo/osinfo_install_config.c
+++ b/osinfo/osinfo_install_config.c
@@ -42,14 +42,91 @@ G_DEFINE_TYPE (OsinfoInstallConfig, osinfo_install_config, OSINFO_TYPE_ENTITY);
 
 struct _OsinfoInstallConfigPrivate
 {
-    gboolean unused;
+    OsinfoInstallConfigParamList *valid_params;
 };
 
+enum {
+    PROP_0,
+
+    PROP_VALID_PARAMS,
+};
+
+static void
+osinfo_install_config_set_property(GObject    *object,
+                                   guint       property_id,
+                                   const GValue     *value,
+                                   GParamSpec *pspec)
+{
+    OsinfoInstallConfig *config = OSINFO_INSTALL_CONFIG(object);
+
+    switch (property_id) {
+    case PROP_VALID_PARAMS:
+        osinfo_install_config_set_valid_params(config, g_value_get_object(value));
+        break;
+
+    default:
+        /* We don't have any other property... */
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+osinfo_install_config_get_property(GObject    *object,
+                                   guint       property_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+    OsinfoInstallConfig *config = OSINFO_INSTALL_CONFIG(object);
+
+    switch (property_id) {
+    case PROP_VALID_PARAMS:
+        g_value_set_object(value, osinfo_install_config_get_valid_params(config));
+        break;
+
+    default:
+        /* We don't have any other property... */
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+
+static void
+osinfo_install_config_finalize (GObject *object)
+{
+    OsinfoInstallConfig *config = OSINFO_INSTALL_CONFIG (object);
+
+    if (config->priv->valid_params)
+        g_object_unref(config->priv->valid_params);
+
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_install_config_parent_class)->finalize (object);
+}
+
 
 /* Init functions */
 static void
 osinfo_install_config_class_init (OsinfoInstallConfigClass *klass)
 {
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+    GParamSpec *pspec;
+
+    g_klass->get_property = osinfo_install_config_get_property;
+    g_klass->set_property = osinfo_install_config_set_property;
+    g_klass->finalize = osinfo_install_config_finalize;
+
+    pspec = g_param_spec_object("valid-params",
+                                "Valid Parameters",
+                                _("Valid configuration parameters"),
+                                OSINFO_TYPE_INSTALL_CONFIG_PARAMLIST,
+                                G_PARAM_READWRITE |
+                                G_PARAM_CONSTRUCT_ONLY |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass,
+                                    PROP_VALID_PARAMS,
+                                    pspec);
+
     g_type_class_add_private (klass, sizeof (OsinfoInstallConfigPrivate));
 }
 
@@ -637,6 +714,22 @@ const gchar *osinfo_install_config_get_post_install_drivers_location(OsinfoInsta
              OSINFO_INSTALL_CONFIG_PROP_POST_INSTALL_DRIVERS_LOCATION);
 }
 
+void osinfo_install_config_set_valid_params(OsinfoInstallConfig *config,
+                                            OsinfoInstallConfigParamList *valid_params)
+{
+    if (config->priv->valid_params != NULL)
+        g_object_unref(config->priv->valid_params);
+    if (valid_params != NULL)
+        config->priv->valid_params = g_object_ref(G_OBJECT(valid_params));
+    else
+        config->priv->valid_params = NULL;
+}
+
+OsinfoInstallConfigParamList *osinfo_install_config_get_valid_params(OsinfoInstallConfig *config)
+{
+    return config->priv->valid_params;
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_install_config.h b/osinfo/osinfo_install_config.h
index d650a0a..e0f7e65 100644
--- a/osinfo/osinfo_install_config.h
+++ b/osinfo/osinfo_install_config.h
@@ -22,6 +22,7 @@
  */
 
 #include <glib-object.h>
+#include <osinfo/osinfo_install_config_paramlist.h>
 
 #ifndef __OSINFO_INSTALL_CONFIG_H__
 #define __OSINFO_INSTALL_CONFIG_H__
@@ -182,6 +183,7 @@ const gchar *osinfo_install_config_get_avatar_disk(OsinfoInstallConfig *config);
 void osinfo_install_config_set_pre_install_drivers_disk(OsinfoInstallConfig *config,
                                                         const gchar *disk);
 const gchar *osinfo_install_config_get_pre_install_drivers_disk(OsinfoInstallConfig *config);
+
 void osinfo_install_config_set_pre_install_drivers_location(OsinfoInstallConfig *config,
                                                             const gchar *location);
 const gchar *osinfo_install_config_get_pre_install_drivers_location(OsinfoInstallConfig *config);
@@ -189,10 +191,15 @@ const gchar *osinfo_install_config_get_pre_install_drivers_location(OsinfoInstal
 void osinfo_install_config_set_post_install_drivers_disk(OsinfoInstallConfig *config,
                                                          const gchar *disk);
 const gchar *osinfo_install_config_get_post_install_drivers_disk(OsinfoInstallConfig *config);
+
 void osinfo_install_config_set_post_install_drivers_location(OsinfoInstallConfig *config,
                                                              const gchar *location);
 const gchar *osinfo_install_config_get_post_install_drivers_location(OsinfoInstallConfig *config);
 
+void osinfo_install_config_set_valid_params(OsinfoInstallConfig *config,
+                                            OsinfoInstallConfigParamList *valid_params);
+OsinfoInstallConfigParamList *osinfo_install_config_get_valid_params(OsinfoInstallConfig *config);
+
 #endif /* __OSINFO_INSTALL_CONFIG_H__ */
 /*
  * Local variables:
-- 
1.8.0.1




More information about the virt-tools-list mailing list