summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-olpc-mesh.c26
-rw-r--r--src/nm-device-manager.c61
-rw-r--r--src/nm-device-manager.h50
-rw-r--r--src/nm-manager.c69
-rw-r--r--src/nm-manager.h5
-rw-r--r--src/settings/nm-settings.c20
-rw-r--r--src/settings/nm-settings.h4
8 files changed, 168 insertions, 69 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 121c367a4b..42be9bdf1f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -208,6 +208,8 @@ nm_sources = \
nm-connection-provider.h \
nm-connectivity.c \
nm-connectivity.h \
+ nm-device-manager.c \
+ nm-device-manager.h \
nm-dbus-manager.c \
nm-dbus-manager.h \
nm-dcb.c \
diff --git a/src/devices/nm-device-olpc-mesh.c b/src/devices/nm-device-olpc-mesh.c
index b85956ef63..5175bf0355 100644
--- a/src/devices/nm-device-olpc-mesh.c
+++ b/src/devices/nm-device-olpc-mesh.c
@@ -50,7 +50,7 @@
#include "nm-activation-request.h"
#include "nm-setting-connection.h"
#include "nm-setting-olpc-mesh.h"
-#include "nm-manager.h"
+#include "nm-device-manager.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "wifi-utils.h"
@@ -375,9 +375,9 @@ dispose (GObject *object)
companion_cleanup (self);
if (priv->device_added_id)
- g_signal_handler_disconnect (nm_manager_get (), priv->device_added_id);
+ g_signal_handler_disconnect (nm_device_manager_get (), priv->device_added_id);
if (priv->device_removed_id)
- g_signal_handler_disconnect (nm_manager_get (), priv->device_removed_id);
+ g_signal_handler_disconnect (nm_device_manager_get (), priv->device_removed_id);
G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
}
@@ -547,7 +547,7 @@ is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
/* When we've found the companion, stop listening for other devices */
if (priv->device_added_id) {
- g_signal_handler_disconnect (nm_manager_get (), priv->device_added_id);
+ g_signal_handler_disconnect (nm_device_manager_get (), priv->device_added_id);
priv->device_added_id = 0;
}
@@ -577,7 +577,7 @@ is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
}
static void
-device_added_cb (NMManager *manager, NMDevice *other, gpointer user_data)
+device_added_cb (NMDeviceManager *device_manager, NMDevice *other, gpointer user_data)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (user_data);
@@ -585,7 +585,7 @@ device_added_cb (NMManager *manager, NMDevice *other, gpointer user_data)
}
static void
-device_removed_cb (NMManager *manager, NMDevice *other, gpointer user_data)
+device_removed_cb (NMDeviceManager *device_manager, NMDevice *other, gpointer user_data)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (user_data);
@@ -598,8 +598,8 @@ check_companion_cb (gpointer user_data)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (user_data);
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
- NMManager *manager;
- GSList *list;
+ NMDeviceManager *device_manager;
+ const GSList *list;
if (priv->companion != NULL) {
nm_device_state_changed (NM_DEVICE (user_data),
@@ -611,17 +611,17 @@ check_companion_cb (gpointer user_data)
if (priv->device_added_id != 0)
goto done;
- manager = nm_manager_get ();
+ device_manager = nm_device_manager_get ();
- priv->device_added_id = g_signal_connect (manager, "device-added",
+ priv->device_added_id = g_signal_connect (device_manager, NM_DM_SIGNAL_DEVICE_ADDED,
G_CALLBACK (device_added_cb), self);
if (!priv->device_removed_id) {
- priv->device_removed_id = g_signal_connect (manager, "device-removed",
+ priv->device_removed_id = g_signal_connect (device_manager, NM_DM_SIGNAL_DEVICE_REMOVED,
G_CALLBACK (device_removed_cb), self);
}
- /* Try to find the companion if it's already known to the NMManager */
- for (list = nm_manager_get_devices (manager); list ; list = g_slist_next (list)) {
+ /* Try to find the companion if it's already known to the NMDeviceManager */
+ for (list = nm_device_manager_get_devices (device_manager); list ; list = g_slist_next (list)) {
if (is_companion (self, NM_DEVICE (list->data)))
break;
}
diff --git a/src/nm-device-manager.c b/src/nm-device-manager.c
new file mode 100644
index 0000000000..4e4509c16e
--- /dev/null
+++ b/src/nm-device-manager.c
@@ -0,0 +1,61 @@
+/* -*- 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 2013 Red Hat, Inc.
+ */
+
+#include "nm-device-manager.h"
+
+G_DEFINE_INTERFACE (NMDeviceManager, nm_device_manager, G_TYPE_OBJECT)
+
+/**
+ * nm_device_manager_get_devices:
+ * @self: the #NMDeviceManager
+ *
+ * Returns: a #GSList of #NMDevice objects representing all known
+ * devices. Returned list is owned by the device manager and must
+ * not be freed.
+ */
+const GSList *
+nm_device_manager_get_devices (NMDeviceManager *self)
+{
+ g_return_val_if_fail (NM_IS_DEVICE_MANAGER (self), NULL);
+
+ if (NM_DEVICE_MANAGER_GET_INTERFACE (self)->get_devices)
+ return NM_DEVICE_MANAGER_GET_INTERFACE (self)->get_devices (self);
+ return NULL;
+}
+
+/*****************************************************************************/
+
+static void
+nm_device_manager_default_init (NMDeviceManagerInterface *iface)
+{
+ GType iface_type = G_TYPE_FROM_INTERFACE (iface);
+
+ /* Signals */
+ g_signal_new (NM_DM_SIGNAL_DEVICE_ADDED,
+ iface_type,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMDeviceManagerInterface, device_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, NM_TYPE_DEVICE);
+
+ g_signal_new (NM_DM_SIGNAL_DEVICE_REMOVED,
+ iface_type,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NMDeviceManagerInterface, device_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, NM_TYPE_DEVICE);
+}
diff --git a/src/nm-device-manager.h b/src/nm-device-manager.h
new file mode 100644
index 0000000000..7e6feaa458
--- /dev/null
+++ b/src/nm-device-manager.h
@@ -0,0 +1,50 @@
+/* -*- 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 2013 Red Hat, Inc.
+ */
+
+#ifndef NM_DEVICE_MANAGER_H
+#define NM_DEVICE_MANAGER_H
+
+#include <glib-object.h>
+#include <nm-device.h>
+
+#define NM_TYPE_DEVICE_MANAGER (nm_device_manager_get_type ())
+#define NM_DEVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_MANAGER, NMDeviceManager))
+#define NM_IS_DEVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_MANAGER))
+#define NM_DEVICE_MANAGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NM_TYPE_DEVICE_MANAGER, NMDeviceManagerInterface))
+
+typedef struct _NMDeviceManager NMDeviceManager;
+typedef struct _NMDeviceManagerInterface NMDeviceManagerInterface;
+
+#define NM_DM_SIGNAL_DEVICE_ADDED "dm-device-added"
+#define NM_DM_SIGNAL_DEVICE_REMOVED "dm-device-removed"
+
+struct _NMDeviceManagerInterface {
+ GTypeInterface g_iface;
+
+ /* Methods */
+ const GSList * (*get_devices) (NMDeviceManager *self);
+
+ /* Signals */
+ void (*device_added) (NMDeviceManager *self, NMDevice *device);
+ void (*device_removed) (NMDeviceManager *self, NMDevice *device, gboolean quitting);
+};
+
+GType nm_device_manager_get_type (void);
+
+NMDeviceManager *nm_device_manager_get (void);
+
+const GSList *nm_device_manager_get_devices (NMDeviceManager *self);
+
+#endif /* NM_DEVICE_MANAGER_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 8edab333d2..aa6bc879fb 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -40,6 +40,7 @@
#include "nm-dbus-manager.h"
#include "nm-vpn-manager.h"
#include "nm-device.h"
+#include "nm-device-manager.h"
#include "nm-device-ethernet.h"
#include "nm-device-wifi.h"
#include "nm-device-olpc-mesh.h"
@@ -134,6 +135,7 @@ static void add_device (NMManager *self, NMDevice *device, gboolean generate_con
static void remove_device (NMManager *self, NMDevice *device, gboolean quitting);
static void hostname_provider_init (NMHostnameProviderInterface *provider_iface);
+static void device_manager_init (NMDeviceManagerInterface *manager_iface);
static NMActiveConnection *_new_active_connection (NMManager *self,
NMConnection *connection,
@@ -229,12 +231,12 @@ typedef struct {
#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate))
G_DEFINE_TYPE_EXTENDED (NMManager, nm_manager, G_TYPE_OBJECT, 0,
- G_IMPLEMENT_INTERFACE (NM_TYPE_HOSTNAME_PROVIDER,
- hostname_provider_init))
+ G_IMPLEMENT_INTERFACE (NM_TYPE_HOSTNAME_PROVIDER,
+ hostname_provider_init)
+ G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_MANAGER,
+ device_manager_init))
enum {
- DEVICE_ADDED,
- DEVICE_REMOVED,
STATE_CHANGED,
CHECK_PERMISSIONS,
USER_PERMISSIONS_CHANGED,
@@ -491,24 +493,6 @@ nm_manager_get_device_by_path (NMManager *manager, const char *path)
}
NMDevice *
-nm_manager_get_device_by_master (NMManager *manager, const char *master, const char *driver)
-{
- GSList *iter;
-
- g_return_val_if_fail (master != NULL, NULL);
-
- for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
- NMDevice *device = NM_DEVICE (iter->data);
-
- if (!strcmp (nm_device_get_iface (device), master) &&
- (!driver || !strcmp (nm_device_get_driver (device), driver)))
- return device;
- }
-
- return NULL;
-}
-
-NMDevice *
nm_manager_get_device_by_ifindex (NMManager *manager, int ifindex)
{
GSList *iter;
@@ -764,8 +748,7 @@ remove_device (NMManager *manager, NMDevice *device, gboolean quitting)
g_signal_handlers_disconnect_matched (device, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, manager);
- nm_settings_device_removed (priv->settings, device, quitting);
- g_signal_emit (manager, signals[DEVICE_REMOVED], 0, device);
+ g_signal_emit_by_name (manager, NM_DM_SIGNAL_DEVICE_REMOVED, 0, device, quitting);
g_object_notify (G_OBJECT (manager), NM_MANAGER_DEVICES);
g_object_unref (device);
@@ -832,6 +815,18 @@ hostname_provider_init (NMHostnameProviderInterface *provider_iface)
provider_iface->get_hostname = hostname_provider_get_hostname;
}
+static const GSList *
+device_manager_get_devices (NMDeviceManager *device_manager)
+{
+ return NM_MANAGER_GET_PRIVATE (device_manager)->devices;
+}
+
+static void
+device_manager_init (NMDeviceManagerInterface *manager_iface)
+{
+ manager_iface->get_devices = device_manager_get_devices;
+}
+
NMState
nm_manager_get_state (NMManager *manager)
{
@@ -1862,8 +1857,7 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con)
NM_DEVICE_STATE_REASON_NOW_MANAGED);
}
- nm_settings_device_added (priv->settings, device);
- g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
+ g_signal_emit_by_name (self, NM_DM_SIGNAL_DEVICE_ADDED, 0, device);
g_object_notify (G_OBJECT (self), NM_MANAGER_DEVICES);
/* New devices might be master interfaces for virtual interfaces; so we may
@@ -4590,6 +4584,13 @@ nm_connection_provider_get (void)
return NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton)->settings);
}
+NMDeviceManager *
+nm_device_manager_get (void)
+{
+ g_assert (singleton);
+ return NM_DEVICE_MANAGER (singleton);
+}
+
NMManager *
nm_manager_new (NMSettings *settings,
const char *state_file,
@@ -5158,22 +5159,6 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_PARAM_READABLE));
/* signals */
- signals[DEVICE_ADDED] =
- g_signal_new ("device-added",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NMManagerClass, device_added),
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
- signals[DEVICE_REMOVED] =
- g_signal_new ("device-removed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NMManagerClass, device_removed),
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
signals[STATE_CHANGED] =
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
diff --git a/src/nm-manager.h b/src/nm-manager.h
index 1b0865fe0d..419c4ab566 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -85,8 +85,6 @@ typedef struct {
GObjectClass parent;
/* Signals */
- void (*device_added) (NMManager *manager, NMDevice *device);
- void (*device_removed) (NMManager *manager, NMDevice *device);
void (*state_changed) (NMManager *manager, guint state);
} NMManagerClass;
@@ -112,9 +110,6 @@ GSList *nm_manager_get_activatable_connections (NMManager *manager);
GSList *nm_manager_get_devices (NMManager *manager);
-NMDevice *nm_manager_get_device_by_master (NMManager *manager,
- const char *master,
- const char *driver);
NMDevice *nm_manager_get_device_by_ifindex (NMManager *manager,
int ifindex);
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 3c59a5925e..354ec57553 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -67,6 +67,7 @@
#include "nm-settings-utils.h"
#include "nm-connection-provider.h"
#include "nm-config.h"
+#include "nm-device-manager.h"
#include "NetworkManagerUtils.h"
/* LINKER CRACKROCK */
@@ -128,7 +129,6 @@ G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, G_TYPE_OBJECT, 0,
typedef struct {
NMDBusManager *dbus_mgr;
-
NMAgentManager *agent_mgr;
NMConfig *config;
@@ -1585,8 +1585,8 @@ default_wired_clear_tag (NMSettings *self,
nm_config_set_ethernet_no_auto_default (NM_SETTINGS_GET_PRIVATE (self)->config, NM_CONFIG_DEVICE (device));
}
-void
-nm_settings_device_added (NMSettings *self, NMDevice *device)
+static void
+device_added (NMDeviceManager *device_mgr, NMDevice *device, NMSettings *self)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMConnection *connection;
@@ -1666,8 +1666,8 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
nm_connection_get_id (NM_CONNECTION (added)));
}
-void
-nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting)
+static void
+device_removed (NMDeviceManager *device_mgr, NMDevice *device, gboolean quitting, NMSettings *self)
{
NMSettingsConnection *connection;
@@ -1802,6 +1802,11 @@ nm_settings_new (GError **error)
priv->config = nm_config_get ();
priv->dbus_mgr = nm_dbus_manager_get ();
+ g_signal_connect (nm_device_manager_get (), NM_DM_SIGNAL_DEVICE_ADDED,
+ G_CALLBACK (device_added), self);
+ g_signal_connect (nm_device_manager_get (), NM_DM_SIGNAL_DEVICE_REMOVED,
+ G_CALLBACK (device_removed), self);
+
/* Load the plugins; fail if a plugin is not found. */
if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) {
g_object_unref (self);
@@ -1851,6 +1856,11 @@ dispose (GObject *object)
priv->dbus_mgr = NULL;
+ g_signal_handlers_disconnect_by_func (nm_device_manager_get (),
+ G_CALLBACK (device_added), self);
+ g_signal_handlers_disconnect_by_func (nm_device_manager_get (),
+ G_CALLBACK (device_removed), self);
+
g_object_unref (priv->agent_mgr);
G_OBJECT_CLASS (nm_settings_parent_class)->dispose (object);
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index 67b7d0f690..f6b1a026f7 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -117,10 +117,6 @@ const GSList *nm_settings_get_unmanaged_specs (NMSettings *self);
char *nm_settings_get_hostname (NMSettings *self);
-void nm_settings_device_added (NMSettings *self, NMDevice *device);
-
-void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting);
-
gint nm_settings_sort_connections (gconstpointer a, gconstpointer b);
#endif /* __NM_SETTINGS_H__ */