[virt-tools-list] [libosinfo 07/11] OsinfoInstallScript: Use an OsinfoInstallConfigParamList
Christophe Fergeau
cfergeau at redhat.com
Mon Dec 10 16:46:03 UTC 2012
Currently the install script config parameters are stored in a
raw GList. However, OsinfoInstallScript ends up reimplementing
part of the OsinfoList API, and the raw GList also does not make
it convenient to pass the list of config parameters around.
Replace the internal GList with an OsinfoInstallConfigParamList,
which has the side-effect of nicely simplifying the code.
---
osinfo/libosinfo.syms | 1 +
osinfo/osinfo_install_script.c | 69 +++++++++++++++++++++---------------------
osinfo/osinfo_install_script.h | 1 +
3 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index d96ac53..7ec1bbd 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -374,6 +374,7 @@ LIBOSINFO_0.2.2 {
osinfo_install_script_get_avatar_format;
osinfo_install_script_get_can_pre_install_drivers;
osinfo_install_script_get_can_post_install_drivers;
+ osinfo_install_script_get_config_paramlist;
osinfo_install_script_get_path_format;
osinfo_install_script_get_product_key_format;
diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index cecad04..bb7ad29 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -50,7 +50,7 @@ struct _OsinfoInstallScriptPrivate
{
gchar *output_prefix;
gchar *output_filename;
- GList *config_param_list;
+ OsinfoInstallConfigParamList *config_params;
OsinfoAvatarFormat *avatar;
};
@@ -164,8 +164,11 @@ osinfo_install_script_finalize (GObject *object)
OsinfoInstallScript *script = OSINFO_INSTALL_SCRIPT (object);
g_free(script->priv->output_prefix);
g_free(script->priv->output_filename);
- g_list_free_full(script->priv->config_param_list, g_object_unref);
- if (script->priv->avatar != NULL)
+
+ if (script->priv->config_params)
+ g_object_unref(script->priv->config_params);
+
+ if (script->priv->avatar)
g_object_unref(script->priv->avatar);
/* Chain up to the parent class */
@@ -258,35 +261,20 @@ void osinfo_install_script_add_config_param(OsinfoInstallScript *script, OsinfoI
g_return_if_fail(OSINFO_IS_INSTALL_SCRIPT(script));
g_return_if_fail(OSINFO_IS_INSTALL_CONFIG_PARAM(param));
- script->priv->config_param_list =
- g_list_prepend(script->priv->config_param_list, param);
+ osinfo_list_add(OSINFO_LIST(script->priv->config_params),
+ OSINFO_ENTITY(param));
}
gboolean osinfo_install_script_has_config_param(const OsinfoInstallScript *script, const OsinfoInstallConfigParam *config_param)
{
- GList *l;
-
- for (l = script->priv->config_param_list; l != NULL; l = l->next) {
- OsinfoInstallConfigParam *tmp = l->data;
-
- if (g_strcmp0(osinfo_install_config_param_get_name(tmp),
- osinfo_install_config_param_get_name(config_param)) == 0)
- return TRUE;
- }
- return FALSE;
+ const char *name = osinfo_install_config_param_get_name(config_param);
+ return osinfo_install_script_has_config_param_name(script, name);
}
gboolean osinfo_install_script_has_config_param_name(const OsinfoInstallScript *script, const gchar *name)
{
- GList *l;
-
- for (l = script->priv->config_param_list; l != NULL; l = l->next) {
- OsinfoInstallConfigParam *tmp = l->data;
-
- if (g_strcmp0(osinfo_install_config_param_get_name(tmp), name) == 0)
- return TRUE;
- }
- return FALSE;
+ OsinfoList *l = OSINFO_LIST(script->priv->config_params);
+ return (osinfo_list_find_by_id(l, name) != NULL);
}
/**
@@ -300,7 +288,21 @@ gboolean osinfo_install_script_has_config_param_name(const OsinfoInstallScript *
*/
GList *osinfo_install_script_get_config_param_list(const OsinfoInstallScript *script)
{
- return g_list_copy(script->priv->config_param_list);
+ return osinfo_list_get_elements(OSINFO_LIST(script->priv->config_params));
+}
+
+/**
+ * osinfo_install_script_get_config_paramlist:
+ *
+ * Get the list of valid config parameters for @script.
+ *
+ * Returns: (transfer none): the
+ * list of valid #OsinfoInstallConfigParam parameters. Free with
+ * g_list_free() when done. The elements are owned by libosinfo.
+ */
+OsinfoInstallConfigParamList *osinfo_install_script_get_config_paramlist(const OsinfoInstallScript *script)
+{
+ return script->priv->config_params;
}
/**
@@ -317,16 +319,13 @@ OsinfoInstallConfigParam *
osinfo_install_script_get_config_param(const OsinfoInstallScript *script,
const gchar *name)
{
- GList *l;
-
- for (l = script->priv->config_param_list; l != NULL; l = l->next) {
- OsinfoInstallConfigParam *tmp = l->data;
-
- if (g_strcmp0(osinfo_install_config_param_get_name(tmp), name) == 0)
- return g_object_ref(tmp);
- }
+ OsinfoInstallConfigParam *param;
+ OsinfoList *l = OSINFO_LIST(script->priv->config_params);
+ param = OSINFO_INSTALL_CONFIG_PARAM(osinfo_list_find_by_id(l, name));
+ if (param == NULL)
+ return NULL;
- return NULL;
+ return g_object_ref(G_OBJECT(param));
}
static void
@@ -335,7 +334,7 @@ osinfo_install_script_init (OsinfoInstallScript *list)
OsinfoInstallScriptPrivate *priv;
list->priv = priv = OSINFO_INSTALL_SCRIPT_GET_PRIVATE(list);
- list->priv->config_param_list = NULL;
+ list->priv->config_params = osinfo_install_config_paramlist_new();
}
diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h
index f610716..af7ebea 100644
--- a/osinfo/osinfo_install_script.h
+++ b/osinfo/osinfo_install_script.h
@@ -157,6 +157,7 @@ OsinfoInstallConfigParam *osinfo_install_script_get_config_param(const OsinfoIns
void osinfo_install_script_add_config_param(OsinfoInstallScript *script, OsinfoInstallConfigParam *param);
GList *osinfo_install_script_get_config_param_list(const OsinfoInstallScript *script);
+OsinfoInstallConfigParamList *osinfo_install_script_get_config_paramlist(const OsinfoInstallScript *script);
OsinfoPathFormat osinfo_install_script_get_path_format(OsinfoInstallScript *script);
gboolean osinfo_install_script_get_can_pre_install_drivers(OsinfoInstallScript *script);
--
1.8.0.1
More information about the virt-tools-list
mailing list