[network-manager-openvpn/th/vpn-editor-split-bgo765732] squash! properties: split libnm-vpn-plugin-openvpn.so in two libraries
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/th/vpn-editor-split-bgo765732] squash! properties: split libnm-vpn-plugin-openvpn.so in two libraries
- Date: Fri, 29 Apr 2016 11:13:51 +0000 (UTC)
commit 2b457f970872d22ffc63f3d6f871efa63277242f
Author: Thomas Haller <thaller redhat com>
Date: Fri Apr 29 10:53:25 2016 +0200
squash! properties: split libnm-vpn-plugin-openvpn.so in two libraries
Instead of letting libnm do the logic of loading the module, accessing
the factory and creating the editor, do it in the plugin.
However, add a independent header "nm-vpn-plugin-utils.h" which can be
copied to other plugins as is and reused there.
>>>>>>
properties: split libnm-vpn-plugin-openvpn.so in two libraries
Split "libnm-vpn-plugin-openvpn-editor.so" out of "libnm-vpn-plugin-openvpn.so".
The new library contains the GTK dependent code, making the remaining
core plugin independent of the GUI.
For the new libnm-based plugin, the get_editor() function will now
dlopen a second plugin and load the NMVpnEditor instance from there.
Makefile.am | 4 +-
configure.ac | 8 ++-
nm-openvpn-service.name.in | 1 -
po/POTFILES.in | 1 +
properties/Makefile.am | 5 +-
properties/nm-openvpn-editor-plugin.c | 38 +++++++++++--
properties/nm-openvpn-editor-plugin.h | 8 +++
properties/nm-openvpn-editor.c | 4 +-
properties/nm-vpn-plugin-utils.c | 99 +++++++++++++++++++++++++++++++++
properties/nm-vpn-plugin-utils.h | 40 +++++++++++++
10 files changed, 197 insertions(+), 11 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 558cfe9..b6f9cab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,7 @@ install-data-hook:
mkdir -p $(DESTDIR)$(sysconfdir)/NetworkManager/VPN
sed -e "1s|^|# This file is obsoleted by a file in $(NM_VPN_SERVICE_DIR)\n\n|" \
-e 's|[ ]LIBEXECDIR[@]|$(libexecdir)|g' \
- -e 's|[ ]PLUGINDIR[@]|$(libdir)/NetworkManager|g' \
+ -e 's|[ ]PLUGINDIR[@]|@NM_PLUGIN_DIR@|g' \
<$(srcdir)/nm-openvpn-service.name.in \
>$(DESTDIR)$(sysconfdir)/NetworkManager/VPN/nm-openvpn-service.name
@@ -34,7 +34,7 @@ appdata_in_files = appdata/network-manager-openvpn.metainfo.xml.in
nm-openvpn-service.name: $(srcdir)/nm-openvpn-service.name.in
sed -e 's|[ ]LIBEXECDIR[@]|$(libexecdir)|g' \
- -e 's|[ ]PLUGINDIR[@]/|@NM_PLUGIN_DIR@|g' \
+ -e 's|[ ]PLUGINDIR[@]/|@NM_PLUGIN_DIR_NAME_FILE@|g' \
$^ >$@
DISTCHECK_CONFIGURE_FLAGS = \
diff --git a/configure.ac b/configure.ac
index 825c8b4..397866b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,8 +95,14 @@ AC_SUBST(NM_VPN_SERVICE_DIR)
NM_COMPILER_WARNINGS
-test x"$enable_absolute_paths" = x"yes" && NM_PLUGIN_DIR='$(libdir)/NetworkManager/'
+NM_PLUGIN_DIR="$libdir/NetworkManager"
AC_SUBST(NM_PLUGIN_DIR)
+if test x"$enable_absolute_paths" == x"yes"; then
+ NM_PLUGIN_DIR_NAME_FILE="$NM_PLUGIN_DIR/"
+else
+ NM_PLUGIN_DIR_NAME_FILE=""
+fi
+AC_SUBST(NM_PLUGIN_DIR_NAME_FILE)
dnl
dnl Tests
diff --git a/nm-openvpn-service.name.in b/nm-openvpn-service.name.in
index a8abc77..973fa0a 100644
--- a/nm-openvpn-service.name.in
+++ b/nm-openvpn-service.name.in
@@ -8,7 +8,6 @@ supports-multiple-connections=true
plugin= PLUGINDIR@/libnm-vpn-plugin-openvpn.so
[GNOME]
-editor-plugin= PLUGINDIR@/libnm-vpn-plugin-openvpn-editor.so
auth-dialog= LIBEXECDIR@/nm-openvpn-auth-dialog
properties= PLUGINDIR@/libnm-openvpn-properties
supports-external-ui-mode=true
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5dc1db0..7aa5ca3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ properties/auth-helpers.c
properties/import-export.c
properties/nm-openvpn-editor-plugin.c
properties/nm-openvpn-editor.c
+properties/nm-vpn-plugin-utils.c
shared/nm-shared-utils.c
src/nm-openvpn-service.c
src/nm-openvpn-service-openvpn-helper.c
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 4ad32a5..887123b 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -33,11 +33,14 @@ common_CFLAGS = \
###############################################################################
libnm_vpn_plugin_openvpn_la_SOURCES = \
- $(plugin_sources)
+ $(plugin_sources) \
+ nm-vpn-plugin-utils.c \
+ nm-vpn-plugin-utils.h
libnm_vpn_plugin_openvpn_la_CFLAGS = \
$(common_CFLAGS) \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_BASE \
+ -DNM_PLUGIN_DIR=\"$(NM_PLUGIN_DIR)\" \
$(LIBNM_CFLAGS)
libnm_vpn_plugin_openvpn_la_LIBADD = \
diff --git a/properties/nm-openvpn-editor-plugin.c b/properties/nm-openvpn-editor-plugin.c
index 4b21077..339e24c 100644
--- a/properties/nm-openvpn-editor-plugin.c
+++ b/properties/nm-openvpn-editor-plugin.c
@@ -35,6 +35,8 @@
#ifdef NM_OPENVPN_OLD
#include "nm-openvpn-editor.h"
+#else
+#include "nm-vpn-plugin-utils.h"
#endif
#include "import-export.h"
@@ -124,14 +126,42 @@ get_capabilities (NMVpnEditorPlugin *iface)
NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
}
-#ifdef NM_OPENVPN_OLD
+#ifndef NM_OPENVPN_OLD
static NMVpnEditor *
-get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
+_call_editor_factory (gpointer factory,
+ NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ gpointer user_data,
+ GError **error)
{
- return openvpn_editor_new (connection, error);
+ return ((NMVpnEditorFactory) factory) (editor_plugin,
+ connection,
+ error);
}
#endif
+static NMVpnEditor *
+get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
+{
+ g_return_val_if_fail (OPENVPN_IS_EDITOR_PLUGIN (iface), NULL);
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ {
+#ifdef NM_OPENVPN_OLD
+ return openvpn_editor_new (connection, error);
+#else
+ return nm_vpn_plugin_utils_load_editor (NM_PLUGIN_DIR"/libnm-vpn-plugin-openvpn-editor.so",
+ "nm_vpn_editor_factory",
+ _call_editor_factory,
+ iface,
+ connection,
+ NULL,
+ error);
+#endif
+ }
+}
+
/*****************************************************************************/
static void
@@ -162,9 +192,7 @@ openvpn_editor_plugin_init (OpenvpnEditorPlugin *plugin)
static void
openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class)
{
-#ifdef NM_OPENVPN_OLD
iface_class->get_editor = get_editor;
-#endif
iface_class->get_capabilities = get_capabilities;
iface_class->import_from_file = import;
iface_class->export_to_file = export;
diff --git a/properties/nm-openvpn-editor-plugin.h b/properties/nm-openvpn-editor-plugin.h
index 2ccdd65..5bd0864 100644
--- a/properties/nm-openvpn-editor-plugin.h
+++ b/properties/nm-openvpn-editor-plugin.h
@@ -43,6 +43,14 @@ struct _OpenvpnEditorPluginClass {
GType openvpn_editor_plugin_get_type (void);
+typedef NMVpnEditor *(*NMVpnEditorFactory) (NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ GError **error);
+
+NMVpnEditor *
+nm_vpn_editor_factory (NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ GError **error);
#endif /* __NM_OPENVPN_EDITOR_PLUGIN_H__ */
diff --git a/properties/nm-openvpn-editor.c b/properties/nm-openvpn-editor.c
index 85f14a7..62b1a6f 100644
--- a/properties/nm-openvpn-editor.c
+++ b/properties/nm-openvpn-editor.c
@@ -590,10 +590,12 @@ openvpn_editor_plugin_widget_class_init (OpenvpnEditorClass *req_class)
/*****************************************************************************/
#ifndef NM_OPENVPN_OLD
+
+#include "nm-openvpn-editor-plugin.h"
+
G_MODULE_EXPORT NMVpnEditor *
nm_vpn_editor_factory (NMVpnEditorPlugin *editor_plugin,
NMConnection *connection,
- NMVpnEditorLoadData *load_data,
GError **error)
{
g_return_val_if_fail (!error || !*error, NULL);
diff --git a/properties/nm-vpn-plugin-utils.c b/properties/nm-vpn-plugin-utils.c
new file mode 100644
index 0000000..c0ff925
--- /dev/null
+++ b/properties/nm-vpn-plugin-utils.c
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2016 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "nm-vpn-plugin-utils.h"
+
+/*****************************************************************************/
+
+NMVpnEditor *
+nm_vpn_plugin_utils_load_editor (const char *module_name,
+ const char *factory_name,
+ NMVpnPluginUtilsEditorFactory editor_factory,
+ NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ gpointer user_data,
+ GError **error)
+
+{
+ GModule *module;
+ gpointer factory;
+ NMVpnEditor *editor;
+
+ g_return_val_if_fail (module_name && g_path_is_absolute (module_name), NULL);
+ g_return_val_if_fail (factory_name && factory_name[0], NULL);
+ g_return_val_if_fail (editor_factory, NULL);
+ g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (editor_plugin), NULL);
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (error && !*error, NULL);
+
+ if (!g_file_test (module_name, G_FILE_TEST_EXISTS)) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ G_FILE_ERROR_NOENT,
+ _("missing plugin file \"%s\""), module_name);
+ return NULL;
+ }
+
+ module = g_module_open (module_name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+ if (!module) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_FAILED,
+ _("cannot load editor plugin %s"), module_name);
+ return NULL;
+ }
+
+ if (!g_module_symbol (module, factory_name, &factory)) {
+ g_set_error (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_FAILED,
+ _("cannot load factory %s from plugin %s: %s"),
+ factory_name, module_name, g_module_error ());
+ g_module_close (module);
+ return NULL;
+ }
+
+ editor = editor_factory (factory,
+ editor_plugin,
+ connection,
+ user_data,
+ error);
+ if (!editor) {
+ g_module_close (module);
+ if (error && !*error ) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_FAILED,
+ _("unknown error creating editor instance"));
+ g_return_val_if_reached (NULL);
+ }
+ return NULL;
+ }
+
+ g_return_val_if_fail (NM_IS_VPN_EDITOR (editor), NULL);
+
+ g_object_set_data_full ((GObject *) editor, "gmodule", module,
+ (GDestroyNotify) g_module_close);
+ return editor;
+}
+
diff --git a/properties/nm-vpn-plugin-utils.h b/properties/nm-vpn-plugin-utils.h
new file mode 100644
index 0000000..3efad44
--- /dev/null
+++ b/properties/nm-vpn-plugin-utils.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2016 Red Hat, Inc.
+ */
+
+#ifndef __NM_VPN_PLUGIN_UTILS_H__
+#define __NM_VPN_PLUGIN_UTILS_H__
+
+typedef NMVpnEditor *(NMVpnPluginUtilsEditorFactory) (gpointer factory,
+ NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ gpointer user_data,
+ GError **error);
+
+NMVpnEditor *nm_vpn_plugin_utils_load_editor (const char *module_name,
+ const char *factory_name,
+ NMVpnPluginUtilsEditorFactory editor_factory,
+ NMVpnEditorPlugin *editor_plugin,
+ NMConnection *connection,
+ gpointer user_data,
+ GError **error);
+
+#endif /* __NM_VPN_PLUGIN_UTILS_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]