Commit 84def2fe authored by Dan Williams's avatar Dan Williams

settings: remove connection tracking from NMManager

NMSysconfigSettings has the authoritative list of connections, no reason
to duplicate all that tracking code in NMManager.  Add the missing bits
that the manager had to NMSysconfigSettings, and point NMPolicy at the
settings object instead of NMManager for that.
parent b51cef3c
......@@ -453,6 +453,7 @@ main (int argc, char *argv[])
NMDBusManager *dbus_mgr = NULL;
NMSupplicantManager *sup_mgr = NULL;
NMDHCPManager *dhcp_mgr = NULL;
NMSysconfigSettings *settings = NULL;
GError *error = NULL;
gboolean wrote_pidfile = FALSE;
char *cfg_log_level = NULL, *cfg_log_domains = NULL;
......@@ -672,7 +673,14 @@ main (int argc, char *argv[])
goto done;
}
manager = nm_manager_get (config,
settings = nm_sysconfig_settings_new (config, plugins, &error);
if (!settings) {
nm_log_err (LOGD_CORE, "failed to initialize settings storage.");
goto done;
}
manager = nm_manager_get (settings,
config,
plugins,
state_file,
net_enabled,
......@@ -685,7 +693,7 @@ main (int argc, char *argv[])
goto done;
}
policy = nm_policy_new (manager, vpn_manager);
policy = nm_policy_new (manager, vpn_manager, settings);
if (policy == NULL) {
nm_log_err (LOGD_CORE, "failed to initialize the policy.");
goto done;
......@@ -733,6 +741,9 @@ done:
if (manager)
g_object_unref (manager);
if (settings)
g_object_unref (settings);
if (vpn_manager)
g_object_unref (vpn_manager);
......
......@@ -652,7 +652,7 @@ dispose (GObject *object)
device_cleanup (self);
manager = nm_manager_get (NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
manager = nm_manager_get (NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
if (priv->device_added_id)
g_signal_handler_disconnect (manager, priv->device_added_id);
g_object_unref (manager);
......@@ -850,7 +850,7 @@ is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
priv->companion = other;
/* When we've found the companion, stop listening for other devices */
manager = nm_manager_get (NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
manager = nm_manager_get (NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
if (priv->device_added_id) {
g_signal_handler_disconnect (manager, priv->device_added_id);
priv->device_added_id = 0;
......@@ -905,7 +905,7 @@ check_companion_cb (gpointer user_data)
if (priv->device_added_id != 0)
return FALSE;
manager = nm_manager_get (NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
manager = nm_manager_get (NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, NULL);
priv->device_added_id = g_signal_connect (manager, "device-added",
G_CALLBACK (device_added_cb), self);
......
This diff is collapsed.
......@@ -20,13 +20,14 @@
*/
#ifndef NM_MANAGER_H
#define NM_MANAGER_H 1
#define NM_MANAGER_H
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include "nm-device.h"
#include "nm-device-interface.h"
#include "nm-sysconfig-settings.h"
#define NM_TYPE_MANAGER (nm_manager_get_type ())
#define NM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MANAGER, NMManager))
......@@ -60,22 +61,12 @@ typedef struct {
void (*device_removed) (NMManager *manager, NMDevice *device);
void (*state_changed) (NMManager *manager, guint state);
void (*properties_changed) (NMManager *manager, GHashTable *properties);
void (*connections_added) (NMManager *manager);
void (*connection_added) (NMManager *manager,
NMConnection *connection);
void (*connection_updated) (NMManager *manager,
NMConnection *connection);
void (*connection_removed) (NMManager *manager,
NMConnection *connection);
} NMManagerClass;
GType nm_manager_get_type (void);
NMManager *nm_manager_get (const char *config_file,
NMManager *nm_manager_get (NMSysconfigSettings *settings,
const char *config_file,
const char *plugins,
const char *state_file,
gboolean initial_net_enabled,
......@@ -105,13 +96,6 @@ gboolean nm_manager_deactivate_connection (NMManager *manager,
NMState nm_manager_get_state (NMManager *manager);
/* Connections */
GSList *nm_manager_get_connections (NMManager *manager);
NMConnection * nm_manager_get_connection_by_object_path (NMManager *manager,
const char *path);
GPtrArray * nm_manager_get_active_connections_by_connection (NMManager *manager,
NMConnection *connection);
......
......@@ -56,6 +56,8 @@ struct NMPolicy {
gulong vpn_activated_id;
gulong vpn_deactivated_id;
NMSysconfigSettings *settings;
NMDevice *default_device4;
NMDevice *default_device6;
......@@ -739,7 +741,7 @@ auto_activate_device (gpointer user_data)
if (nm_device_get_act_request (data->device))
goto out;
connections = nm_manager_get_connections (policy->manager);
connections = nm_sysconfig_settings_get_connections (policy->settings);
/* Remove connections that are in the invalid list. */
iter = connections;
......@@ -822,6 +824,7 @@ hostname_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
static void
sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
{
NMPolicy *policy = user_data;
gboolean sleeping = FALSE, enabled = FALSE;
GSList *connections, *iter;
......@@ -830,7 +833,7 @@ sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
/* Clear the invalid flag on all connections so they'll get retried on wakeup */
if (sleeping || !enabled) {
connections = nm_manager_get_connections (manager);
connections = nm_sysconfig_settings_get_connections (policy->settings);
for (iter = connections; iter; iter = g_slist_next (iter))
g_object_set_data (G_OBJECT (iter->data), INVALID_TAG, NULL);
g_slist_free (connections);
......@@ -1043,14 +1046,7 @@ schedule_activate_all (NMPolicy *policy)
}
static void
connections_added (NMManager *manager,
gpointer user_data)
{
schedule_activate_all ((NMPolicy *) user_data);
}
static void
connection_added (NMManager *manager,
connection_added (NMSysconfigSettings *settings,
NMConnection *connection,
gpointer user_data)
{
......@@ -1058,7 +1054,7 @@ connection_added (NMManager *manager,
}
static void
connection_updated (NMManager *manager,
connection_updated (NMSysconfigSettings *settings,
NMConnection *connection,
gpointer user_data)
{
......@@ -1069,22 +1065,19 @@ connection_updated (NMManager *manager,
}
static void
connection_removed (NMManager *manager,
NMConnection *connection,
gpointer user_data)
_deactivate_if_active (NMManager *manager, NMConnection *connection)
{
NMSettingConnection *s_con;
GPtrArray *list;
int i;
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
if (!s_con)
return;
list = nm_manager_get_active_connections_by_connection (manager, connection);
if (!list)
return;
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
for (i = 0; i < list->len; i++) {
char *path = g_ptr_array_index (list, i);
GError *error = NULL;
......@@ -1100,13 +1093,32 @@ connection_removed (NMManager *manager,
}
static void
manager_user_permissions_changed (NMManager *manager, NMPolicy *policy)
connection_removed (NMSysconfigSettings *settings,
NMConnection *connection,
gpointer user_data)
{
NMPolicy *policy = user_data;
_deactivate_if_active (policy->manager, connection);
}
static void
connection_visibility_changed (NMSysconfigSettings *settings,
NMSysconfigConnection *connection,
gpointer user_data)
{
schedule_activate_all (policy);
NMPolicy *policy = user_data;
if (nm_sysconfig_connection_is_visible (connection))
schedule_activate_all (policy);
else
_deactivate_if_active (policy->manager, NM_CONNECTION (connection));
}
NMPolicy *
nm_policy_new (NMManager *manager, NMVPNManager *vpn_manager)
nm_policy_new (NMManager *manager,
NMVPNManager *vpn_manager,
NMSysconfigSettings *settings)
{
NMPolicy *policy;
static gboolean initialized = FALSE;
......@@ -1160,28 +1172,25 @@ nm_policy_new (NMManager *manager, NMVPNManager *vpn_manager)
G_CALLBACK (device_removed), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
/* Large batch of connections added, manager doesn't want us to
* process each one individually.
*/
id = g_signal_connect (manager, "connections-added",
G_CALLBACK (connections_added), policy);
/* Listen for events related to connections */
id = g_signal_connect (policy->settings, NM_SYSCONFIG_SETTINGS_CONNECTIONS_LOADED,
G_CALLBACK (connection_added), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
/* Single connection added */
id = g_signal_connect (manager, "connection-added",
id = g_signal_connect (policy->settings, NM_SYSCONFIG_SETTINGS_CONNECTION_ADDED,
G_CALLBACK (connection_added), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
id = g_signal_connect (manager, "connection-updated",
id = g_signal_connect (policy->settings, NM_SYSCONFIG_SETTINGS_CONNECTION_UPDATED,
G_CALLBACK (connection_updated), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
id = g_signal_connect (manager, "connection-removed",
id = g_signal_connect (policy->settings, NM_SYSCONFIG_SETTINGS_CONNECTION_REMOVED,
G_CALLBACK (connection_removed), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
id = g_signal_connect (manager, "user-permissions-changed",
G_CALLBACK (manager_user_permissions_changed), policy);
id = g_signal_connect (policy->settings, NM_SYSCONFIG_SETTINGS_CONNECTION_VISIBILITY_CHANGED,
G_CALLBACK (connection_visibility_changed), policy);
policy->signal_ids = g_slist_append (policy->signal_ids, (gpointer) id);
return policy;
......@@ -1227,6 +1236,8 @@ nm_policy_destroy (NMPolicy *policy)
}
g_slist_free (policy->dev_signal_ids);
g_object_unref (policy->settings);
/* Rewrite /etc/hosts on exit to ensure we don't leave stale IP addresses
* lying around. FIXME: this will take out a valid IP address of an
* ethernet device we're leaving active (ie, a connection we can "assume"
......
......@@ -15,22 +15,22 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2004 - 2008 Red Hat, Inc.
* Copyright (C) 2004 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc.
*/
#ifndef NETWORK_MANAGER_POLICY_H
#define NETWORK_MANAGER_POLICY_H
#include "NetworkManager.h"
#include "nm-manager.h"
#include "nm-vpn-manager.h"
#include "nm-device.h"
#include "nm-activation-request.h"
#include "nm-sysconfig-settings.h"
typedef struct NMPolicy NMPolicy;
NMPolicy *nm_policy_new (NMManager *manager, NMVPNManager *vpn_manager);
NMPolicy *nm_policy_new (NMManager *manager,
NMVPNManager *vpn_manager,
NMSysconfigSettings *settings);
void nm_policy_destroy (NMPolicy *policy);
#endif /* NETWORK_MANAGER_POLICY_H */
This diff is collapsed.
......@@ -43,7 +43,11 @@
#define NM_SYSCONFIG_SETTINGS_HOSTNAME "hostname"
#define NM_SYSCONFIG_SETTINGS_CAN_MODIFY "can-modify"
#define NM_SYSCONFIG_SETTINGS_NEW_CONNECTION "new-connection"
#define NM_SYSCONFIG_SETTINGS_CONNECTION_ADDED "connection-added"
#define NM_SYSCONFIG_SETTINGS_CONNECTION_UPDATED "connection-updated"
#define NM_SYSCONFIG_SETTINGS_CONNECTION_REMOVED "connection-removed"
#define NM_SYSCONFIG_SETTINGS_CONNECTION_VISIBILITY_CHANGED "connection-visibility-changed"
#define NM_SYSCONFIG_SETTINGS_CONNECTIONS_LOADED "connections-loaded"
typedef struct {
GObject parent_instance;
......@@ -54,6 +58,16 @@ typedef struct {
/* Signals */
void (*properties_changed) (NMSysconfigSettings *self, GHashTable *properties);
void (*connection_added) (NMSysconfigSettings *self, NMConnection *connection);
void (*connection_updated) (NMSysconfigSettings *self, NMConnection *connection);
void (*connection_removed) (NMSysconfigSettings *self, NMConnection *connection);
void (*connection_visibility_changed) (NMSysconfigSettings *self, NMConnection *connection);
void (*connections_loaded) (NMSysconfigSettings *self);
} NMSysconfigSettingsClass;
GType nm_sysconfig_settings_get_type (void);
......@@ -70,10 +84,13 @@ void nm_sysconfig_settings_for_each_connection (NMSysconfigSettings *settings,
NMSysconfigSettingsForEachFunc for_each_func,
gpointer user_data);
GSList * nm_sysconfig_settings_list_connections (NMSysconfigSettings *settings);
/* Returns a list of NMSysconfigConnections. Caller must free the list with
* g_slist_free().
*/
GSList *nm_sysconfig_settings_get_connections (NMSysconfigSettings *settings);
NMSysconfigConnection * nm_sysconfig_settings_get_connection_by_path (NMSysconfigSettings *settings,
const char *path);
NMSysconfigConnection *nm_sysconfig_settings_get_connection_by_path (NMSysconfigSettings *settings,
const char *path);
const GSList *nm_sysconfig_settings_get_unmanaged_specs (NMSysconfigSettings *self);
......
......@@ -30,11 +30,11 @@
#include "NetworkManager.h"
#include "NetworkManagerVPN.h"
#include "nm-vpn-connection.h"
#include "nm-device-interface.h"
#include "nm-setting-connection.h"
#include "nm-setting-vpn.h"
#include "nm-setting-ip4-config.h"
#include "nm-dbus-manager.h"
#include "nm-manager.h"
#include "nm-system.h"
#include "nm-logging.h"
#include "nm-utils.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment