summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-05-16 18:08:08 +0200
committerThomas Haller <thaller@redhat.com>2016-05-22 11:32:10 +0200
commite5f861ab3f6da37a83483ca018dbf95c8f718288 (patch)
treef23c36c632a7417eac6f34c29b23f5a0f068c8be
parent8d44e34eed029effcc7876f9e9be55e140f71213 (diff)
downloadNetworkManager-th/drop-connection-provider-bgo766560.tar.gz
core: drop NMConnectionProvider and use NMSettings directlyth/drop-connection-provider-bgo766560
This is not C# but glib. Using interfaces is so cumbersome, that they don't simplify code but make it more complicated. E.g. following signals and its subscribers is complicated enough. It gets more complicated by having NM_SETTINGS_SIGNAL_CONNECTION_ADDED and NM_CP_SIGNAL_CONNECTION_ADDED. Of course, your favorite IDE has no idea about glib interfaces, so figuring out who calls who gets more complicated. This undoes commit 4fe48b1273cff8dde3688a1dc4b7bcbf0a9e16f4. Originally, NMConnectionProvider had only one function get_best_connection(). But it kept growing and more functions were added. If we want to ~hide~ certain part of the NMSettings API, we should move them to a separate header which gives internal access.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/nm-connection-provider.c120
-rw-r--r--src/nm-connection-provider.h86
-rw-r--r--src/nm-manager.c16
-rw-r--r--src/settings/nm-settings.c61
5 files changed, 5 insertions, 280 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ff890ff56..e61e5aa9dd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -397,8 +397,6 @@ libNetworkManager_la_SOURCES = \
nm-config.h \
nm-config-data.c \
nm-config-data.h \
- nm-connection-provider.c \
- nm-connection-provider.h \
nm-connectivity.c \
nm-connectivity.h \
nm-dcb.c \
diff --git a/src/nm-connection-provider.c b/src/nm-connection-provider.c
deleted file mode 100644
index 557340adff..0000000000
--- a/src/nm-connection-provider.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details:
- *
- * Copyright (C) 2012 Red Hat, Inc.
- */
-
-#include "nm-default.h"
-
-#include "nm-connection-provider.h"
-
-#include "nm-utils.h"
-
-G_DEFINE_INTERFACE (NMConnectionProvider, nm_connection_provider, G_TYPE_OBJECT)
-
-const GSList *
-nm_connection_provider_get_connections (NMConnectionProvider *self)
-{
- g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
-
- if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections)
- return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections (self);
- return NULL;
-}
-
-/**
- * nm_connection_provider_add_connection:
- * @self: the #NMConnectionProvider
- * @connection: the source connection to create a new #NMSettingsConnection from
- * @save_to_disk: %TRUE to save the connection to disk immediately, %FALSE to
- * not save to disk
- * @error: on return, a location to store any errors that may occur
- *
- * Creates a new #NMSettingsConnection for the given source @connection.
- * The plugin owns the returned object and the caller must reference the object
- * to continue using it.
- *
- * Returns: the new #NMSettingsConnection or %NULL
- */
-NMConnection *
-nm_connection_provider_add_connection (NMConnectionProvider *self,
- NMConnection *connection,
- gboolean save_to_disk,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
-
- g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection);
- return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection (self, connection, save_to_disk, error);
-}
-
-/**
- * nm_connection_provider_get_connection_by_uuid:
- * @self: the #NMConnectionProvider
- * @uuid: the UUID to search for
- *
- * Returns: the connection with the given @uuid, or %NULL
- */
-NMConnection *
-nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self,
- const char *uuid)
-{
- g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
- g_return_val_if_fail (uuid != NULL, NULL);
- g_return_val_if_fail (nm_utils_is_uuid (uuid), NULL);
-
- g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid);
- return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid (self, uuid);
-}
-
-const GSList *
-nm_connection_provider_get_unmanaged_specs (NMConnectionProvider *self)
-{
- g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
-
- return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_unmanaged_specs (self);
-}
-
-/*****************************************************************************/
-
-static void
-nm_connection_provider_default_init (NMConnectionProviderInterface *g_iface)
-{
- GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
- static gboolean initialized = FALSE;
-
- if (initialized)
- return;
- initialized = TRUE;
-
- /* Signals */
- g_signal_new (NM_CP_SIGNAL_CONNECTION_ADDED,
- iface_type,
- G_SIGNAL_RUN_FIRST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
- g_signal_new (NM_CP_SIGNAL_CONNECTION_UPDATED,
- iface_type,
- G_SIGNAL_RUN_FIRST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
- g_signal_new (NM_CP_SIGNAL_CONNECTION_REMOVED,
- iface_type,
- G_SIGNAL_RUN_FIRST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-}
diff --git a/src/nm-connection-provider.h b/src/nm-connection-provider.h
deleted file mode 100644
index 50a18c25d3..0000000000
--- a/src/nm-connection-provider.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details:
- *
- * Copyright (C) 2012 Red Hat, Inc.
- */
-
-#ifndef __NETWORKMANAGER_CONNECTION_PROVIDER_H__
-#define __NETWORKMANAGER_CONNECTION_PROVIDER_H__
-
-#include "nm-connection.h"
-
-#define NM_TYPE_CONNECTION_PROVIDER (nm_connection_provider_get_type ())
-#define NM_CONNECTION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProvider))
-#define NM_IS_CONNECTION_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_PROVIDER))
-#define NM_CONNECTION_PROVIDER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_CONNECTION_PROVIDER, NMConnectionProviderInterface))
-
-#define NM_CP_SIGNAL_CONNECTION_ADDED "cp-connection-added"
-#define NM_CP_SIGNAL_CONNECTION_UPDATED "cp-connection-updated"
-#define NM_CP_SIGNAL_CONNECTION_REMOVED "cp-connection-removed"
-
-
-typedef struct {
- GTypeInterface g_iface;
-
- /* Methods */
- const GSList * (*get_connections) (NMConnectionProvider *self);
-
- NMConnection * (*add_connection) (NMConnectionProvider *self,
- NMConnection *connection,
- gboolean save_to_disk,
- GError **error);
-
- NMConnection * (*get_connection_by_uuid) (NMConnectionProvider *self,
- const char *uuid);
-
- const GSList * (*get_unmanaged_specs) (NMConnectionProvider *self);
-} NMConnectionProviderInterface;
-
-GType nm_connection_provider_get_type (void);
-
-/**
- * nm_connection_provider_get:
- *
- * Returns: the global #NMConnectionProvider
- */
-NMConnectionProvider *nm_connection_provider_get (void);
-
-/**
- * nm_connection_provider_get_connections:
- * @self: the #NMConnectionProvider
- *
- * Returns: a #GSList of #NMConnection objects representing all known
- * connections. Returned list is owned by the connection provider and must
- * not be freed.
- */
-const GSList *nm_connection_provider_get_connections (NMConnectionProvider *self);
-
-/**
- * nm_connection_provider_add_connection:
- * @self: the #NMConnectionProvider
- * @connection: the connection to be added
- * @save_to_disk: whether to store the connection on disk
- * @error: returns any error if adding fails
- *
- * returns: a newly added #NMConnection.
- */
-NMConnection *nm_connection_provider_add_connection (NMConnectionProvider *self,
- NMConnection *connection,
- gboolean save_to_disk,
- GError **error);
-
-NMConnection *nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self,
- const char *uuid);
-
-const GSList *nm_connection_provider_get_unmanaged_specs (NMConnectionProvider *self);
-
-#endif /* __NETWORKMANAGER_CONNECTION_PROVIDER_H__ */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 7108447f6b..f6a31e3c93 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -21,13 +21,14 @@
#include "nm-default.h"
+#include "nm-manager.h"
+
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include "nm-manager.h"
#include "nm-bus-manager.h"
#include "nm-vpn-manager.h"
#include "nm-device.h"
@@ -45,7 +46,6 @@
#include "nm-sleep-monitor.h"
#include "nm-connectivity.h"
#include "nm-policy.h"
-#include "nm-connection-provider.h"
#include "nm-session-monitor.h"
#include "nm-activation-request.h"
#include "nm-core-internal.h"
@@ -5174,18 +5174,6 @@ nm_manager_get (void)
return singleton_instance;
}
-NMConnectionProvider *
-nm_connection_provider_get (void)
-{
- NMConnectionProvider *p;
-
- g_return_val_if_fail (singleton_instance, NULL);
-
- p = NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton_instance)->settings);
- g_return_val_if_fail (p, NULL);
- return p;
-}
-
NMSettings *
nm_settings_get (void)
{
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 895e128a27..fab5383c79 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -25,6 +25,8 @@
#include "nm-default.h"
+#include "nm-settings.h"
+
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
@@ -59,7 +61,6 @@
#include "nm-core-internal.h"
#include "nm-device-ethernet.h"
-#include "nm-settings.h"
#include "nm-settings-connection.h"
#include "nm-settings-plugin.h"
#include "nm-bus-manager.h"
@@ -68,7 +69,6 @@
#include "nm-session-monitor.h"
#include "plugins/keyfile/plugin.h"
#include "nm-agent-manager.h"
-#include "nm-connection-provider.h"
#include "nm-config.h"
#include "nm-audit-manager.h"
#include "NetworkManagerUtils.h"
@@ -132,15 +132,11 @@ static void claim_connection (NMSettings *self,
static void unmanaged_specs_changed (NMSettingsPlugin *config, gpointer user_data);
static void unrecognized_specs_changed (NMSettingsPlugin *config, gpointer user_data);
-static void connection_provider_iface_init (NMConnectionProviderInterface *cp_iface);
-
static void connection_ready_changed (NMSettingsConnection *conn,
GParamSpec *pspec,
gpointer user_data);
-G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT, 0,
- G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION_PROVIDER, connection_provider_iface_init))
-
+G_DEFINE_TYPE (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT);
typedef struct {
NMAgentManager *agent_mgr;
@@ -155,7 +151,6 @@ typedef struct {
NMSettingsConnection **connections_cached_list;
GSList *unmanaged_specs;
GSList *unrecognized_specs;
- GSList *get_connections_cache;
gboolean started;
gboolean startup_complete;
@@ -942,7 +937,6 @@ connection_updated (NMSettingsConnection *connection, gboolean by_user, gpointer
0,
connection,
by_user);
- g_signal_emit_by_name (NM_SETTINGS (user_data), NM_CP_SIGNAL_CONNECTION_UPDATED, connection);
}
static void
@@ -988,7 +982,6 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data)
g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection);
/* Re-emit for listeners like NMPolicy */
- g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_REMOVED, connection);
_notify (self, PROP_CONNECTIONS);
if (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (connection)))
nm_exported_object_unexport (NM_EXPORTED_OBJECT (connection));
@@ -1137,7 +1130,6 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
if (priv->connections_loaded) {
/* Internal added signal */
g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection);
- g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_ADDED, connection);
_notify (self, PROP_CONNECTIONS);
/* Exported D-Bus signal */
@@ -1213,16 +1205,6 @@ nm_settings_add_connection (NMSettings *self,
return NULL;
}
-static NMConnection *
-_nm_connection_provider_add_connection (NMConnectionProvider *provider,
- NMConnection *connection,
- gboolean save_to_disk,
- GError **error)
-{
- g_assert (NM_IS_CONNECTION_PROVIDER (provider) && NM_IS_SETTINGS (provider));
- return NM_CONNECTION (nm_settings_add_connection (NM_SETTINGS (provider), connection, save_to_disk, error));
-}
-
static gboolean
secrets_filter_cb (NMSetting *setting,
const char *secret,
@@ -2199,33 +2181,6 @@ nm_settings_get_best_connections (NMSettings *self,
return g_slist_reverse (sorted);
}
-static const GSList *
-get_connections (NMConnectionProvider *provider)
-{
- GSList *list = NULL;
- NMSettings *self = NM_SETTINGS (provider);
- NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
-
- list = _nm_utils_hash_values_to_slist (priv->connections);
-
- /* Cache the list every call so we can keep it 'const' for callers */
- g_slist_free (priv->get_connections_cache);
- priv->get_connections_cache = list;
- return list;
-}
-
-static NMConnection *
-cp_get_connection_by_uuid (NMConnectionProvider *provider, const char *uuid)
-{
- return NM_CONNECTION (nm_settings_get_connection_by_uuid (NM_SETTINGS (provider), uuid));
-}
-
-static const GSList *
-cp_get_unmanaged_specs (NMConnectionProvider *provider)
-{
- return nm_settings_get_unmanaged_specs (NM_SETTINGS (provider));
-}
-
/***************************************************************/
gboolean
@@ -2387,15 +2342,6 @@ nm_settings_start (NMSettings *self, GError **error)
}
static void
-connection_provider_iface_init (NMConnectionProviderInterface *cp_iface)
-{
- cp_iface->get_connections = get_connections;
- cp_iface->add_connection = _nm_connection_provider_add_connection;
- cp_iface->get_connection_by_uuid = cp_get_connection_by_uuid;
- cp_iface->get_unmanaged_specs = cp_get_unmanaged_specs;
-}
-
-static void
nm_settings_init (NMSettings *self)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
@@ -2460,7 +2406,6 @@ finalize (GObject *object)
g_hash_table_destroy (priv->connections);
g_clear_pointer (&priv->connections_cached_list, g_free);
- g_slist_free (priv->get_connections_cache);
g_slist_free_full (priv->unmanaged_specs, g_free);
g_slist_free_full (priv->unrecognized_specs, g_free);