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.
This commit is contained in:
Dan Williams 2014-02-10 08:49:47 -06:00
parent fd3fe2200c
commit ee66964208
3 changed files with 20 additions and 1 deletions

View file

@ -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);

View file

@ -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

View file

@ -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),