diff options
author | Thomas Haller <thaller@redhat.com> | 2015-05-28 22:12:31 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-07-29 22:34:35 +0200 |
commit | eafa6c3584421d14e09a18f76bad7b1b5ebc2288 (patch) | |
tree | 2c1a9b7dca29146402c5284a1423e101fb09f8d3 | |
parent | eed0d0c58f7f13638eb587e240737048d729cb68 (diff) | |
download | NetworkManager-eafa6c3584421d14e09a18f76bad7b1b5ebc2288.tar.gz |
libnm: add load method to NMVpnPluginInfo
https://bugzilla.gnome.org/show_bug.cgi?id=749877
-rw-r--r-- | libnm-core/nm-vpn-plugin-info.c | 121 | ||||
-rw-r--r-- | libnm-core/nm-vpn-plugin-info.h | 11 | ||||
-rw-r--r-- | libnm/libnm.ver | 3 |
3 files changed, 135 insertions, 0 deletions
diff --git a/libnm-core/nm-vpn-plugin-info.c b/libnm-core/nm-vpn-plugin-info.c index 2842ce2937..762064a5b7 100644 --- a/libnm-core/nm-vpn-plugin-info.c +++ b/libnm-core/nm-vpn-plugin-info.c @@ -56,6 +56,9 @@ typedef struct { * value somewhere... let's put it in an internal hash table. * This contains a clone of all the strings in keyfile. */ GHashTable *keys; + + gboolean editor_plugin_loaded; + NMVpnEditorPlugin *editor_plugin; } NMVpnPluginInfoPrivate; static void nm_vpn_plugin_info_initable_iface_init (GInitableIface *iface); @@ -647,6 +650,112 @@ nm_vpn_plugin_info_lookup_property (NMVpnPluginInfo *self, const char *group, co /*********************************************************************/ /** + * nm_vpn_plugin_info_get_editor_plugin: + * @self: plugin info instance + * + * Returns: the cached #NMVpnEditorPlugin instance. + * + * Since: 1.2 + */ +NMVpnEditorPlugin * +nm_vpn_plugin_info_get_editor_plugin (NMVpnPluginInfo *self) +{ + g_return_val_if_fail (NM_IS_VPN_PLUGIN_INFO (self), NULL); + + return NM_VPN_PLUGIN_INFO_GET_PRIVATE (self)->editor_plugin; +} + +/** + * nm_vpn_plugin_info_set_editor_plugin: + * @self: plugin info instance + * @plugin: (allow-none): plugin instance + * + * Set the internal plugin instance. If %NULL, only clear the previous instance. + * + * Since: 1.2 + */ +void +nm_vpn_plugin_info_set_editor_plugin (NMVpnPluginInfo *self, NMVpnEditorPlugin *plugin) +{ + NMVpnPluginInfoPrivate *priv; + NMVpnEditorPlugin *old; + + g_return_if_fail (NM_IS_VPN_PLUGIN_INFO (self)); + g_return_if_fail (!plugin || G_IS_OBJECT (plugin)); + + priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (self); + + if (!plugin) { + priv->editor_plugin_loaded = FALSE; + g_clear_object (&priv->editor_plugin); + } else { + old = priv->editor_plugin; + priv->editor_plugin = g_object_ref (plugin); + priv->editor_plugin_loaded = TRUE; + if (old) + g_object_unref (old); + } +} + +/** + * nm_vpn_plugin_info_load_editor_plugin: + * @self: plugin info instance + * @error: error reason on failure + * + * Returns: loads the plugin and returns the newly created instance. + * The plugin is owned by @self and can be later retrieved again + * via nm_vpn_plugin_info_get_editor_plugin(). You can load the + * plugin only once, unless you reset the state via + * nm_vpn_plugin_info_set_editor_plugin(). + * + * Since: 1.2 + */ +NMVpnEditorPlugin * +nm_vpn_plugin_info_load_editor_plugin (NMVpnPluginInfo *self, GError **error) +{ + NMVpnPluginInfoPrivate *priv; + const char *plugin_filename; + + g_return_val_if_fail (NM_IS_VPN_PLUGIN_INFO (self), NULL); + + priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (self); + + if (priv->editor_plugin) + return priv->editor_plugin; + + plugin_filename = nm_vpn_plugin_info_get_plugin (self); + if (!plugin_filename || !*plugin_filename) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("missing \"plugin\" setting")); + return NULL; + } + + /* We only try once to load the plugin. If we previously tried and it was + * unsuccessful, error out immediately. */ + if (priv->editor_plugin_loaded) { + g_set_error (error, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_FAILED, + _("%s: don't retry loading plugin which already failed previously"), priv->name); + return NULL; + } + + priv->editor_plugin_loaded = TRUE; + priv->editor_plugin = nm_vpn_editor_plugin_load_from_file (plugin_filename, + priv->name, + nm_vpn_plugin_info_get_service (self), + getuid (), + NULL, + NULL, + error); + return priv->editor_plugin; +} + +/*********************************************************************/ + +/** * nm_vpn_plugin_info_new_from_file: * @filename: filename to read. * @error: on failure, the error reason. @@ -809,6 +918,17 @@ get_property (GObject *object, guint prop_id, } static void +dispose (GObject *object) +{ + NMVpnPluginInfo *self = NM_VPN_PLUGIN_INFO (object); + NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE (self); + + g_clear_object (&priv->editor_plugin); + + G_OBJECT_CLASS (nm_vpn_plugin_info_parent_class)->dispose (object); +} + +static void finalize (GObject *object) { NMVpnPluginInfo *self = NM_VPN_PLUGIN_INFO (object); @@ -833,6 +953,7 @@ nm_vpn_plugin_info_class_init (NMVpnPluginInfoClass *plugin_class) /* virtual methods */ object_class->set_property = set_property; object_class->get_property = get_property; + object_class->dispose = dispose; object_class->finalize = finalize; /* properties */ diff --git a/libnm-core/nm-vpn-plugin-info.h b/libnm-core/nm-vpn-plugin-info.h index 8e937b57b7..9a7246f840 100644 --- a/libnm-core/nm-vpn-plugin-info.h +++ b/libnm-core/nm-vpn-plugin-info.h @@ -25,6 +25,7 @@ #include <glib-object.h> #include "nm-utils.h" +#include "nm-vpn-editor-plugin.h" G_BEGIN_DECLS @@ -98,6 +99,16 @@ NMVpnPluginInfo *nm_vpn_plugin_info_list_find_by_filename (GSList *list, const c NM_AVAILABLE_IN_1_2 NMVpnPluginInfo *nm_vpn_plugin_info_list_find_by_service (GSList *list, const char *service); + +NM_AVAILABLE_IN_1_2 +NMVpnEditorPlugin *nm_vpn_plugin_info_get_editor_plugin (NMVpnPluginInfo *plugin_info); +NM_AVAILABLE_IN_1_2 +void nm_vpn_plugin_info_set_editor_plugin (NMVpnPluginInfo *self, + NMVpnEditorPlugin *plugin); +NM_AVAILABLE_IN_1_2 +NMVpnEditorPlugin *nm_vpn_plugin_info_load_editor_plugin (NMVpnPluginInfo *plugin_info, + GError **error); + G_END_DECLS #endif /* __NM_VPN_PLUGIN_INFO_H__ */ diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 43684195e3..ce94276533 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -884,14 +884,17 @@ global: nm_utils_enum_to_str; nm_vpn_editor_plugin_load_from_file; nm_vpn_plugin_info_get_filename; + nm_vpn_plugin_info_get_editor_plugin; nm_vpn_plugin_info_get_name; nm_vpn_plugin_info_get_plugin; nm_vpn_plugin_info_get_program; nm_vpn_plugin_info_get_service; nm_vpn_plugin_info_get_type; + nm_vpn_plugin_info_load_editor_plugin; nm_vpn_plugin_info_lookup_property; nm_vpn_plugin_info_new_from_file; nm_vpn_plugin_info_new_with_data; + nm_vpn_plugin_info_set_editor_plugin; nm_vpn_plugin_info_validate_filename; nm_vpn_plugin_info_list_add; nm_vpn_plugin_info_list_find_by_filename; |