From ee66964208c7c0c404e61fe293a380e500f840eb Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 10 Feb 2014 08:49:47 -0600 Subject: [PATCH] core: allow devices to indicate when they should be removed Devices created by plugins will use this to indicate when their backing resources have disappeared, at which point the manager should remove them. --- src/devices/nm-device.c | 8 ++++++++ src/devices/nm-device.h | 3 ++- src/nm-manager.c | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 5c18a3cb8c..e43df20d07 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -112,6 +112,7 @@ enum { AUTH_REQUEST, IP4_CONFIG_CHANGED, IP6_CONFIG_CHANGED, + REMOVED, LAST_SIGNAL, }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -6117,6 +6118,13 @@ nm_device_class_init (NMDeviceClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_OBJECT); + signals[REMOVED] = + g_signal_new (NM_DEVICE_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 0); + nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_object_info); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index c973b9864d..807cf6873e 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -71,9 +71,10 @@ #define NM_DEVICE_HAS_PENDING_ACTION "has-pending-action" /* Internal only */ /* Internal signals */ -#define NM_DEVICE_AUTH_REQUEST "auth-request" +#define NM_DEVICE_AUTH_REQUEST "auth-request" #define NM_DEVICE_IP4_CONFIG_CHANGED "ip4-config-changed" #define NM_DEVICE_IP6_CONFIG_CHANGED "ip6-config-changed" +#define NM_DEVICE_REMOVED "removed" G_BEGIN_DECLS diff --git a/src/nm-manager.c b/src/nm-manager.c index 9b00f7e7da..a91e1bf153 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -836,6 +836,12 @@ remove_device (NMManager *manager, NMDevice *device, gboolean quitting) check_if_startup_complete (manager); } +static void +device_removed_cb (NMDevice *device, gpointer user_data) +{ + remove_device (NM_MANAGER (user_data), device, FALSE); +} + static void modem_removed (NMModemManager *modem_manager, NMModem *modem, @@ -1852,6 +1858,10 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con) G_CALLBACK (device_auth_request_cb), self); + g_signal_connect (device, NM_DEVICE_REMOVED, + G_CALLBACK (device_removed_cb), + self); + if (priv->startup) { g_signal_connect (device, "notify::" NM_DEVICE_HAS_PENDING_ACTION, G_CALLBACK (device_has_pending_action_changed),