diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-22 19:39:45 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-28 15:08:17 +0200 |
commit | 4800cab8fdf02a0a128558db5c8759b50edb6eb8 (patch) | |
tree | 74365c36dc482a8dd58ceb4357b503f2725db9ea | |
parent | 7ec030b9be557dec89c0676ea6dffd2621c71e65 (diff) | |
download | NetworkManager-th/vpn-gtk-split.tar.gz |
libnm/vpn: pass the NMVpnPluginInfo to the NMVpnEditorPluginth/vpn-gtk-split
Usually, we create first the NMVpnPluginInfo and possible load from
there the NMVpnEditorPlugin instance (via nm_vpn_plugin_info_load_editor_plugin()).
So, usually, the NMVpnPluginInfo owns a reference to the
NMVpnEditorPlugin instance and the editor-plugin has no knowledge about
the plugin-info.
Now, also pass the plugin-info to the editor-plugin. When doing that, we
cannot take a string reference, but that is ok. Also, NMVpnEditorPlugin
is an interface, so we cannot easily associate the date with the
interface, but that is solvable too (the alternative would be to have
type implementations receive the plugin-info, but that would mean that
each of them would need to reimplement registering the weak-pointer).
-rw-r--r-- | libnm-core/nm-vpn-editor-plugin.c | 63 | ||||
-rw-r--r-- | libnm-core/nm-vpn-editor-plugin.h | 8 | ||||
-rw-r--r-- | libnm-core/nm-vpn-plugin-info.c | 3 | ||||
-rw-r--r-- | libnm-core/nm-vpn-plugin-info.h | 4 | ||||
-rw-r--r-- | libnm/libnm.ver | 2 |
5 files changed, 76 insertions, 4 deletions
diff --git a/libnm-core/nm-vpn-editor-plugin.c b/libnm-core/nm-vpn-editor-plugin.c index 36ce385425..e49d8b2679 100644 --- a/libnm-core/nm-vpn-editor-plugin.c +++ b/libnm-core/nm-vpn-editor-plugin.c @@ -25,6 +25,7 @@ #include "nm-vpn-editor-plugin.h" #include "nm-core-internal.h" +#include "nm-vpn-plugin-info.h" G_DEFINE_INTERFACE (NMVpnEditorPlugin, nm_vpn_editor_plugin, G_TYPE_OBJECT) @@ -70,12 +71,14 @@ nm_vpn_editor_plugin_default_init (NMVpnEditorPluginInterface *iface) /******************************************************************************/ typedef struct { - int dummy; + NMVpnPluginInfo *plugin_info; } NMVpnEditorPluginPrivate; static void _nm_vpn_editor_plugin_private_destroy (NMVpnEditorPluginPrivate *priv) { + if (priv->plugin_info) + g_object_remove_weak_pointer ((GObject *) priv->plugin_info, (gpointer *) &priv->plugin_info); g_slice_free (NMVpnEditorPluginPrivate, priv); } @@ -306,7 +309,63 @@ nm_vpn_editor_plugin_load (const char *plugin_name, error); } -/*********************************************************************/ +/*****************************************************************************/ + +/** + * nm_vpn_editor_plugin_get_plugin_info: + * @self: the #NMVpnEditorPlugin instance + * + * Returns: the #NMVpnPluginInfo instance, if set. + * + * Since: 1.4 + **/ +NMVpnPluginInfo * +nm_vpn_editor_plugin_get_plugin_info (NMVpnEditorPlugin *self) +{ + NMVpnEditorPluginPrivate *priv; + + g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (self), NULL); + + priv = NM_VPN_EDITOR_PLUGIN_GET_PRIVATE (self); + return priv->plugin_info; +} + +/** + * nm_vpn_editor_plugin_set_plugin_info: + * @self: the #NMVpnEditorPlugin instance + * @plugin_info: (allow-none): the plugin info to set. + * Set to %NULL to clear. + * + * Set the plugin info of the editor plugin. This will only take + * a weak-ref to the plugin info, because usually the plugin-info + * itself already holds a strong reference to the editor-plugin. + * + * It is save to reset the the plugin-info to another instance or + * clear it by setting it to %NULL. + * + * Since: 1.4 + **/ +void +nm_vpn_editor_plugin_set_plugin_info (NMVpnEditorPlugin *self, + NMVpnPluginInfo *plugin_info) +{ + NMVpnEditorPluginPrivate *priv; + + g_return_if_fail (NM_IS_VPN_EDITOR_PLUGIN (self)); + g_return_if_fail (!plugin_info || NM_IS_VPN_PLUGIN_INFO (plugin_info)); + + priv = NM_VPN_EDITOR_PLUGIN_GET_PRIVATE (self); + + if (priv->plugin_info == plugin_info) + return; + if (priv->plugin_info) + g_object_remove_weak_pointer ((GObject *) priv->plugin_info, (gpointer *) &priv->plugin_info); + priv->plugin_info = plugin_info; + if (priv->plugin_info) + g_object_add_weak_pointer ((GObject *) priv->plugin_info, (gpointer *) &priv->plugin_info); +} + +/*****************************************************************************/ /** * nm_vpn_editor_plugin_get_editor: diff --git a/libnm-core/nm-vpn-editor-plugin.h b/libnm-core/nm-vpn-editor-plugin.h index 82c609b969..e941381a37 100644 --- a/libnm-core/nm-vpn-editor-plugin.h +++ b/libnm-core/nm-vpn-editor-plugin.h @@ -123,6 +123,12 @@ typedef struct { GType nm_vpn_editor_plugin_get_type (void); +struct _NMVpnPluginInfo; + +struct _NMVpnPluginInfo *nm_vpn_editor_plugin_get_plugin_info (NMVpnEditorPlugin *plugin); +void nm_vpn_editor_plugin_set_plugin_info (NMVpnEditorPlugin *plugin, + struct _NMVpnPluginInfo *info); + NMVpnEditor *nm_vpn_editor_plugin_get_editor (NMVpnEditorPlugin *plugin, NMConnection *connection, GError **error); @@ -154,4 +160,4 @@ NMVpnEditorPlugin *nm_vpn_editor_plugin_load (const char *plugin_name, G_END_DECLS -#endif /* __NM_VPN_EDITOR_PLUGIN_H__ */ +#endif /* __NM_VPN_EDITOR_PLUGIN_H__ */ diff --git a/libnm-core/nm-vpn-plugin-info.c b/libnm-core/nm-vpn-plugin-info.c index 90099cd0aa..19f24eb545 100644 --- a/libnm-core/nm-vpn-plugin-info.c +++ b/libnm-core/nm-vpn-plugin-info.c @@ -900,6 +900,9 @@ nm_vpn_plugin_info_load_editor_plugin (NMVpnPluginInfo *self, GError **error) NULL, NULL, error); + + if (priv->editor_plugin) + nm_vpn_editor_plugin_set_plugin_info (priv->editor_plugin, self); return priv->editor_plugin; } diff --git a/libnm-core/nm-vpn-plugin-info.h b/libnm-core/nm-vpn-plugin-info.h index 9844625cfc..e396066c1c 100644 --- a/libnm-core/nm-vpn-plugin-info.h +++ b/libnm-core/nm-vpn-plugin-info.h @@ -44,7 +44,9 @@ G_BEGIN_DECLS #define NM_VPN_PLUGIN_INFO_KF_GROUP_LIBNM "libnm" #define NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME "GNOME" -typedef struct { +struct _NMVpnPluginInfo; + +typedef struct _NMVpnPluginInfo { NM_AVAILABLE_IN_1_2 GObject parent; } NMVpnPluginInfo; diff --git a/libnm/libnm.ver b/libnm/libnm.ver index e40a8d8e2e..32784eef90 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1066,4 +1066,6 @@ global: nm_vpn_plugin_info_get_service; nm_vpn_plugin_info_new_search_file; nm_vpn_plugin_info_supports_hints; + nm_vpn_editor_plugin_get_plugin_info; + nm_vpn_editor_plugin_set_plugin_info; } libnm_1_2_0; |