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. --- osinfo/osinfo_install_config.c | 84 ++++++++++++++++++++++++++++++++++ osinfo/osinfo_install_config_private.h | 1 + 2 files changed, 85 insertions(+) diff --git a/osinfo/osinfo_install_config.c b/osinfo/osinfo_install_config.c index a77317b..4c42746 100644 --- a/osinfo/osinfo_install_config.c +++ b/osinfo/osinfo_install_config.c @@ -737,6 +737,90 @@ OsinfoInstallConfigParamList *osinfo_install_config_get_config_params(OsinfoInst return config->priv->config_params; } + +static const gchar * +osinfo_install_config_transform_value(OsinfoInstallConfig *config, + const gchar *key, + const gchar *value) +{ + OsinfoDatamap *map; + OsinfoEntity *entity; + OsinfoInstallConfigParam *param; + const gchar *transformed_value; + + if (!config->priv->config_params) + return value; + + entity = osinfo_list_find_by_id(OSINFO_LIST(config->priv->config_params), + key); + if (entity == NULL) { + g_warning("%s is not a known parameter for this config", key); + return value; + } + + param = OSINFO_INSTALL_CONFIG_PARAM(entity);; + map = osinfo_install_config_param_get_value_map(param); + if (map == NULL) { + g_debug("no remapping to be done for %s", key); + return value; + } + transformed_value = osinfo_datamap_lookup(map, value); + if (transformed_value == NULL) { + g_warning("value not present in %s datamap: %s", key, value); + return value; + } + + return transformed_value; +} + +static GHashTable *get_remapped_keys_once(void) +{ + const char *remapped_properties[] = { + OSINFO_INSTALL_CONFIG_PROP_HARDWARE_ARCH, + OSINFO_INSTALL_CONFIG_PROP_L10N_KEYBOARD, + OSINFO_INSTALL_CONFIG_PROP_L10N_LANGUAGE, + OSINFO_INSTALL_CONFIG_PROP_L10N_TIMEZONE, + NULL + }; + const char **it; + GHashTable *remapped_keys; + + remapped_keys = g_hash_table_new(g_str_hash, g_str_equal); + for (it = remapped_properties; *it != NULL; it++) { + g_hash_table_add(remapped_keys, (gpointer)*it); + } + + return remapped_keys; +} + +GList * +osinfo_install_config_get_param_value_list(OsinfoInstallConfig *config, + const gchar *key) +{ + GList *values; + GList *it; + static GOnce remapped_keys_once = G_ONCE_INIT; + GHashTable *remapped_keys; + + values = osinfo_entity_get_param_value_list(OSINFO_ENTITY(config), key); + if (values == NULL) + return NULL; + + remapped_keys = g_once(&remapped_keys_once, + (GThreadFunc)get_remapped_keys_once, + NULL); + if (!g_hash_table_contains(remapped_keys, key)) + return values; + + for (it = values; it != NULL; it = it->next) { + it->data = (gpointer)osinfo_install_config_transform_value(config, + key, + it->data); + } + + 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 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo