From 32c26a859bd869a5a910c5047685bcd2badce6d2 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 12 Aug 2014 17:25:26 -0400 Subject: [PATCH] libnm-core: move some fake NMConnection methods over to NMSetting nm_connection_lookup_setting_type() and nm_connection_lookup_setting_type_by_quark() have nothing to do with NMConnection. So move them to NMSetting (and rename them to nm_setting_lookup_type() and nm_setting_lookup_type_by_quark()). --- clients/cli/settings.c | 4 +-- clients/tui/nm-editor-utils.c | 4 +-- include/nm-test-utils.h | 2 +- libnm-core/nm-connection.c | 35 +++------------------------ libnm-core/nm-connection.h | 4 --- libnm-core/nm-setting-private.h | 2 -- libnm-core/nm-setting.c | 21 ++++++++++++++-- libnm-core/nm-setting.h | 3 +++ libnm/libnm.ver | 4 +-- libnm/nm-vpn-plugin.c | 2 +- src/settings/nm-settings.c | 2 +- src/settings/plugins/example/plugin.c | 2 +- src/settings/plugins/keyfile/reader.c | 6 ++--- 13 files changed, 38 insertions(+), 53 deletions(-) diff --git a/clients/cli/settings.c b/clients/cli/settings.c index e3c66d05e7..3275c4793e 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -1539,7 +1539,7 @@ nmc_setting_new_for_name (const char *name) NMSetting *setting = NULL; if (name) { - stype = nm_connection_lookup_setting_type (name); + stype = nm_setting_lookup_type (name); if (stype != G_TYPE_INVALID) { setting = g_object_new (stype, NULL); g_warn_if_fail (NM_IS_SETTING (setting)); @@ -7225,7 +7225,7 @@ setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop) g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); while (iter->sname) { - if (nm_connection_lookup_setting_type (iter->sname) == G_OBJECT_TYPE (setting)) + if (nm_setting_lookup_type (iter->sname) == G_OBJECT_TYPE (setting)) return iter->func (setting, nmc, one_prop); iter++; } diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c index 96f35cc670..0abcf411b0 100644 --- a/clients/tui/nm-editor-utils.c +++ b/clients/tui/nm-editor-utils.c @@ -329,7 +329,7 @@ nm_editor_utils_create_connection (GType type, master_s_con = nm_connection_get_setting_connection (master); master_setting_type = nm_setting_connection_get_connection_type (master_s_con); master_uuid = nm_setting_connection_get_uuid (master_s_con); - master_type = nm_connection_lookup_setting_type (master_setting_type); + master_type = nm_setting_lookup_type (master_setting_type); } types = nm_editor_utils_get_connection_type_list (); @@ -401,7 +401,7 @@ nm_editor_utils_get_connection_type_data (NMConnection *conn) g_return_val_if_fail (s_con != NULL, NULL); conn_type = nm_setting_connection_get_connection_type (s_con); - conn_gtype = nm_connection_lookup_setting_type (conn_type); + conn_gtype = nm_setting_lookup_type (conn_type); g_return_val_if_fail (conn_gtype != G_TYPE_INVALID, NULL); types = nm_editor_utils_get_connection_type_list (); diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 5188cd2627..5587e4ec4c 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -698,7 +698,7 @@ nmtst_create_minimal_connection (const char *id, const char *uuid, const char *t uuid = uuid_free = nm_utils_uuid_generate (); if (type) { - GType type_g = nm_connection_lookup_setting_type (type); + GType type_g = nm_setting_lookup_type (type); g_assert (type_g != G_TYPE_INVALID); diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 48d7777416..56879fe45d 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -124,35 +124,6 @@ static NMSettingVerifyResult _nm_connection_verify (NMConnection *connection, GE /*************************************************************/ -/** - * nm_connection_lookup_setting_type: - * @name: a setting name - * - * Returns the #GType of the setting's class for a given setting name. - * - * Returns: the #GType of the setting's class - **/ -GType -nm_connection_lookup_setting_type (const char *name) -{ - return _nm_setting_lookup_setting_type (name); -} - -/** - * nm_connection_lookup_setting_type_by_quark: - * @error_quark: a setting error quark - * - * Returns the #GType of the setting's class for a given setting error quark. - * Useful for figuring out which setting a returned error is for. - * - * Returns: the #GType of the setting's class - **/ -GType -nm_connection_lookup_setting_type_by_quark (GQuark error_quark) -{ - return _nm_setting_lookup_setting_type_by_quark (error_quark); -} - static void setting_changed_cb (NMSetting *setting, GParamSpec *pspec, @@ -259,7 +230,7 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name) g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (name != NULL, NULL); - type = nm_connection_lookup_setting_type (name); + type = nm_setting_lookup_type (name); return type ? nm_connection_get_setting (connection, type) : NULL; } @@ -327,7 +298,7 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error) g_hash_table_iter_init (&iter, new); while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) { - GType type = nm_connection_lookup_setting_type (setting_name); + GType type = nm_setting_lookup_type (setting_name); if (type) { NMSetting *setting = nm_setting_new_from_hash (type, setting_hash); @@ -964,7 +935,7 @@ nm_connection_update_secrets (NMConnection *connection, */ g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL)) { - if (_nm_setting_lookup_setting_type (key) != G_TYPE_INVALID) { + if (nm_setting_lookup_type (key) != G_TYPE_INVALID) { /* @secrets looks like a hashed connection */ hashed_connection = TRUE; break; diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h index d8c3b5e113..b66094f5c3 100644 --- a/libnm-core/nm-connection.h +++ b/libnm-core/nm-connection.h @@ -209,10 +209,6 @@ GHashTable *nm_connection_to_hash (NMConnection *connection, void nm_connection_dump (NMConnection *connection); -GType nm_connection_lookup_setting_type (const char *name); - -GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark); - /* Helpers */ const char * nm_connection_get_uuid (NMConnection *connection); const char * nm_connection_get_id (NMConnection *connection); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 19849aa4c9..338364cec4 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -56,8 +56,6 @@ void _nm_register_setting (const char *name, gboolean _nm_setting_is_base_type (NMSetting *setting); gboolean _nm_setting_type_is_base_type (GType type); -GType _nm_setting_lookup_setting_type (const char *name); -GType _nm_setting_lookup_setting_type_by_quark (GQuark error_quark); gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b); typedef enum NMSettingUpdateSecretResult { diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index a2842fa13a..6acb75ef27 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -225,8 +225,16 @@ _nm_setting_is_base_type (NMSetting *setting) return _nm_setting_type_is_base_type (G_OBJECT_TYPE (setting)); } +/** + * nm_setting_lookup_type: + * @name: a setting name + * + * Returns the #GType of the setting's class for a given setting name. + * + * Returns: the #GType of the setting's class + **/ GType -_nm_setting_lookup_setting_type (const char *name) +nm_setting_lookup_type (const char *name) { SettingInfo *info; @@ -238,8 +246,17 @@ _nm_setting_lookup_setting_type (const char *name) return info ? info->type : G_TYPE_INVALID; } +/** + * nm_setting_lookup_type_by_quark: + * @error_quark: a setting error quark + * + * Returns the #GType of the setting's class for a given setting error quark. + * Useful for figuring out which setting a returned error is for. + * + * Returns: the #GType of the setting's class + **/ GType -_nm_setting_lookup_setting_type_by_quark (GQuark error_quark) +nm_setting_lookup_type_by_quark (GQuark error_quark) { SettingInfo *info; GHashTableIter iter; diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index 154bd0c577..793d24ed5b 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -229,6 +229,9 @@ typedef void (*NMSettingValueIterFn) (NMSetting *setting, GType nm_setting_get_type (void); +GType nm_setting_lookup_type (const char *name); +GType nm_setting_lookup_type_by_quark (GQuark error_quark); + /** * NMSettingHashFlags: * @NM_SETTING_HASH_FLAG_ALL: hash all properties (including secrets) diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 986c235244..40f5081ff6 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -119,8 +119,6 @@ global: nm_connection_get_virtual_device_description; nm_connection_get_virtual_iface_name; nm_connection_is_type; - nm_connection_lookup_setting_type; - nm_connection_lookup_setting_type_by_quark; nm_connection_need_secrets; nm_connection_new; nm_connection_new_from_hash; @@ -678,6 +676,8 @@ global: nm_setting_ip6_config_remove_dns_search_by_value; nm_setting_ip6_config_remove_route; nm_setting_ip6_config_remove_route_by_value; + nm_setting_lookup_type; + nm_setting_lookup_type_by_quark; nm_setting_need_secrets; nm_setting_new_from_hash; nm_setting_olpc_mesh_error_get_type; diff --git a/libnm/nm-vpn-plugin.c b/libnm/nm-vpn-plugin.c index 289d27a0c5..cff632f9c5 100644 --- a/libnm/nm-vpn-plugin.c +++ b/libnm/nm-vpn-plugin.c @@ -532,7 +532,7 @@ impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, "The connection was invalid: '%s' / '%s' invalid: %d.", - g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_err->domain)), + g_type_name (nm_setting_lookup_type_by_quark (cnfh_err->domain)), cnfh_err->message, cnfh_err->code); g_error_free (cnfh_err); return FALSE; diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 1b88055c9d..e18224961e 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -835,7 +835,7 @@ claim_connection (NMSettings *self, if (!nm_connection_normalize (NM_CONNECTION (connection), NULL, NULL, &error)) { nm_log_warn (LOGD_SETTINGS, "plugin provided invalid connection: '%s' / '%s' invalid: %d", - g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)), + g_type_name (nm_setting_lookup_type_by_quark (error->domain)), error->message, error->code); g_error_free (error); return; diff --git a/src/settings/plugins/example/plugin.c b/src/settings/plugins/example/plugin.c index 23ce44c665..35fc4a0f63 100644 --- a/src/settings/plugins/example/plugin.c +++ b/src/settings/plugins/example/plugin.c @@ -199,7 +199,7 @@ update_connection_settings_commit_cb (NMSettingsConnection *orig, GError *error, if (error) { nm_log_warn (LOGD_SETTINGS, "%s: '%s' / '%s' invalid: %d", __func__, - error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)", + error ? g_type_name (nm_setting_lookup_type_by_quark (error->domain)) : "(none)", (error && error->message) ? error->message : "(none)", error ? error->code : -1); g_clear_error (&error); diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c index 2448e5521e..46dc108b32 100644 --- a/src/settings/plugins/keyfile/reader.c +++ b/src/settings/plugins/keyfile/reader.c @@ -1172,7 +1172,7 @@ read_setting (GKeyFile *file, const char *keyfile_path, const char *group) if (alias) group = alias; - type = nm_connection_lookup_setting_type (group); + type = nm_setting_lookup_type (group); if (type) { setting = g_object_new (type, NULL); nm_setting_enumerate_values (setting, read_one_setting_value, &info); @@ -1289,7 +1289,7 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) NMSetting *base_setting; GType base_setting_type; - base_setting_type = nm_connection_lookup_setting_type (ctype); + base_setting_type = nm_setting_lookup_type (ctype); if (base_setting_type != G_TYPE_INVALID) { base_setting = (NMSetting *) g_object_new (base_setting_type, NULL); g_assert (base_setting); @@ -1334,7 +1334,7 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) if (!nm_connection_verify (connection, &verify_error)) { g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "invalid or missing connection property '%s/%s'", - verify_error ? g_type_name (nm_connection_lookup_setting_type_by_quark (verify_error->domain)) : "(unknown)", + verify_error ? g_type_name (nm_setting_lookup_type_by_quark (verify_error->domain)) : "(unknown)", (verify_error && verify_error->message) ? verify_error->message : "(unknown)"); g_clear_error (&verify_error); g_object_unref (connection);