[Libosinfo] [libosinfo] OsinfoInstallConfig: Use config-params if set

Christophe Fergeau cfergeau at redhat.com
Fri Dec 21 10:46:41 UTC 2012


Now that OsinfoInstallConfig has a 'config-params' property
which describes the config parameters when it's set, we can
use it when it's available. OsinfoInstallConfigParams can indeed
contain a datamap to be used to translate generic libosinfo values
to OS-specific values.
This commit introduces an osinfo_install_config_get_param_value_list
method that will be used in subsequent commits to get these
OS-specific values when generating install scripts.
---
I've now removed the GOnce hash, this makes the code simpler, but quite
different from what was reviewed, resending just this patch for a quick review.

Christophe


 osinfo/osinfo_install_config.c         | 50 ++++++++++++++++++++++++++++++++++
 osinfo/osinfo_install_config_private.h |  1 +
 2 files changed, 51 insertions(+)

diff --git a/osinfo/osinfo_install_config.c b/osinfo/osinfo_install_config.c
index a77317b..e912441 100644
--- a/osinfo/osinfo_install_config.c
+++ b/osinfo/osinfo_install_config.c
@@ -737,6 +737,56 @@ OsinfoInstallConfigParamList *osinfo_install_config_get_config_params(OsinfoInst
     return config->priv->config_params;
 }
 
+
+static OsinfoDatamap *
+osinfo_install_config_get_param_datamap(OsinfoInstallConfig *config,
+                                        const gchar *param_name)
+{
+    OsinfoEntity *entity;
+    OsinfoInstallConfigParam *param;
+
+    if (!config->priv->config_params)
+        return NULL;
+
+    entity = osinfo_list_find_by_id(OSINFO_LIST(config->priv->config_params),
+                                    param_name);
+    if (entity == NULL) {
+        g_debug("%s is not a known parameter for this config", param_name);
+        return NULL;
+    }
+
+    param = OSINFO_INSTALL_CONFIG_PARAM(entity);;
+    return osinfo_install_config_param_get_value_map(param);
+}
+
+
+GList *
+osinfo_install_config_get_param_value_list(OsinfoInstallConfig *config,
+                                           const gchar *key)
+{
+    GList *values;
+    GList *it;
+    OsinfoDatamap *map;
+
+    values = osinfo_entity_get_param_value_list(OSINFO_ENTITY(config), key);
+    if (values == NULL)
+        return NULL;
+
+    map = osinfo_install_config_get_param_datamap(config, key);
+    if (map != NULL) {
+        for (it = values; it != NULL; it = it->next) {
+            const char *transformed_value;
+            transformed_value = osinfo_datamap_lookup(map, it->data);
+            if (transformed_value == NULL) {
+                continue;
+            }
+            it->data = (gpointer)transformed_value;
+        }
+    }
+
+    return values;
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_install_config_private.h b/osinfo/osinfo_install_config_private.h
index 5a1edd3..5ad2162 100644
--- a/osinfo/osinfo_install_config_private.h
+++ b/osinfo/osinfo_install_config_private.h
@@ -28,6 +28,7 @@
 
 void osinfo_install_config_set_config_params(OsinfoInstallConfig *config,
                                              OsinfoInstallConfigParamList *config_params);
+GList *osinfo_install_config_get_param_value_list(OsinfoInstallConfig *config, const gchar *key);
 
 #endif /* __OSINFO_INSTALL_CONFIG_PRIVATE_H__ */
 /*
-- 
1.8.0.2




More information about the Libosinfo mailing list