2008-10-11 Dan Williams <dcbw@redhat.com>

* include/NetworkManager.h
	  introspection/nm-device.xml
	  include/NetworkManagerVPN.h
		- Add a few more state reasons for the device deactivated state

	* src/nm-device-interface.c
	  src/nm-device-interface.h
		- (nm_device_interface_deactivate): add a 'reason' argument

	* src/nm-device.c
	  src/nm-device.h
		- (nm_device_deactivate, nm_device_take_down): add a 'reason' argument
		- (nm_device_state_changed): pass the state change reason to
			nm_device_take_down()
		- (nm_device_set_managed): take a 'reason' argument, and pass it along
			to the state change function

	* src/nm-manager.c
	  src/nm-manager.h
		- (remove_one_device, handle_unmanaged_devices, sync_devices,
		   impl_manager_sleep): pass a reason code to nm_device_set_managed()
		- (nm_manager_deactivate_connection): add a 'reason' argument and pass
			something reasonable along to VPN deactivation

	* src/vpn-manager/nm-vpn-manager.c
	  src/vpn-manager/nm-vpn-manager.h
		- (nm_vpn_manager_deactivate_connection): add a 'reason' argument and
			pass that along to nm_vpn_connection_disconnect()



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4174 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2008-10-11 19:57:45 +00:00
parent 98f392b085
commit f078992e4d
13 changed files with 122 additions and 37 deletions

View file

@ -1,3 +1,34 @@
2008-10-11 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
introspection/nm-device.xml
include/NetworkManagerVPN.h
- Add a few more state reasons for the device deactivated state
* src/nm-device-interface.c
src/nm-device-interface.h
- (nm_device_interface_deactivate): add a 'reason' argument
* src/nm-device.c
src/nm-device.h
- (nm_device_deactivate, nm_device_take_down): add a 'reason' argument
- (nm_device_state_changed): pass the state change reason to
nm_device_take_down()
- (nm_device_set_managed): take a 'reason' argument, and pass it along
to the state change function
* src/nm-manager.c
src/nm-manager.h
- (remove_one_device, handle_unmanaged_devices, sync_devices,
impl_manager_sleep): pass a reason code to nm_device_set_managed()
- (nm_manager_deactivate_connection): add a 'reason' argument and pass
something reasonable along to VPN deactivation
* src/vpn-manager/nm-vpn-manager.c
src/vpn-manager/nm-vpn-manager.h
- (nm_vpn_manager_deactivate_connection): add a 'reason' argument and
pass that along to nm_vpn_connection_disconnect()
2008-10-11 Dan Williams <dcbw@redhat.com>
* src/nm-device-wifi.c

View file

@ -325,6 +325,18 @@ typedef enum {
/* Necessary firmware for the device may be missing */
NM_DEVICE_STATE_REASON_FIRMWARE_MISSING,
/* The device was removed */
NM_DEVICE_STATE_REASON_REMOVED,
/* NetworkManager went to sleep */
NM_DEVICE_STATE_REASON_SLEEPING,
/* The device's active connection disappeared */
NM_DEVICE_STATE_REASON_CONNECTION_REMOVED,
/* Device disconnected by user or client */
NM_DEVICE_STATE_REASON_USER_REQUESTED,
/* Unused */
NM_DEVICE_STATE_REASON_LAST = 0xFFFF
} NMDeviceStateReason;

View file

@ -103,7 +103,8 @@ typedef enum NMVPNConnectionStateReason
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT,
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED,
NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS,
NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED
NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED,
NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED
} NMVPNConnectionStateReason;
typedef enum {

View file

@ -319,6 +319,26 @@
<tp:docstring>
Necessary firmware for the device may be missing.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="REMOVED" value="36">
<tp:docstring>
The device was removed.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="SLEEPING" value="37">
<tp:docstring>
NetworkManager went to sleep.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="CONNECTION_REMOVED" value="38">
<tp:docstring>
The device's active connection was removed or disappeared.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="USER_REQUESTED" value="39">
<tp:docstring>
A user or client requested the disconnection.
</tp:docstring>
</tp:enumvalue>
</tp:enum>

View file

@ -921,7 +921,7 @@ connection_removed (NMManager *manager,
char *path = g_ptr_array_index (list, i);
GError *error = NULL;
if (!nm_manager_deactivate_connection (manager, path, &error)) {
if (!nm_manager_deactivate_connection (manager, path, NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, &error)) {
nm_warning ("Connection '%s' disappeared, but error deactivating it: (%d) %s",
s_con->id, error->code, error->message);
g_error_free (error);

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#include "nm-marshal.h"
#include "nm-setting-connection.h"
@ -234,11 +234,11 @@ nm_device_interface_activate (NMDeviceInterface *device,
}
void
nm_device_interface_deactivate (NMDeviceInterface *device)
nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
{
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device);
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device, reason);
}
NMDeviceState

View file

@ -1,3 +1,4 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#ifndef NM_DEVICE_INTERFACE_H
#define NM_DEVICE_INTERFACE_H
@ -62,7 +63,7 @@ struct _NMDeviceInterface {
NMActRequest *req,
GError **error);
void (*deactivate) (NMDeviceInterface *device);
void (*deactivate) (NMDeviceInterface *device, NMDeviceStateReason reason);
/* Signals */
void (*state_changed) (NMDeviceInterface *device,
@ -84,7 +85,7 @@ gboolean nm_device_interface_activate (NMDeviceInterface *device,
NMActRequest *req,
GError **error);
void nm_device_interface_deactivate (NMDeviceInterface *device);
void nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason);
NMDeviceState nm_device_interface_get_state (NMDeviceInterface *device);

View file

@ -114,7 +114,9 @@ static gboolean nm_device_activate (NMDeviceInterface *device,
GError **error);
static void nm_device_activate_schedule_stage5_ip_config_commit (NMDevice *self);
static void nm_device_deactivate (NMDeviceInterface *device);
static void nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason);
static void nm_device_take_down (NMDevice *dev, gboolean wait, NMDeviceStateReason reason);
static gboolean nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware);
static gboolean nm_device_is_up (NMDevice *self);
@ -1527,19 +1529,21 @@ nm_device_deactivate_quickly (NMDevice *self)
*
*/
static void
nm_device_deactivate (NMDeviceInterface *device)
nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
{
NMDevice *self = NM_DEVICE (device);
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
g_return_if_fail (self != NULL);
nm_info ("(%s): deactivating device.", nm_device_get_iface (self));
nm_info ("(%s): deactivating device (reason: %d).",
nm_device_get_iface (self),
reason);
nm_device_deactivate_quickly (self);
/* Clean up nameservers and addresses */
nm_device_set_ip4_config (self, NULL, &reason);
nm_device_set_ip4_config (self, NULL, &ignored);
/* Take out any entries in the routing table and any IP address the device had. */
nm_system_device_flush_ip4_routes (self);
@ -2061,13 +2065,13 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
return success;
}
void
nm_device_take_down (NMDevice *self, gboolean block)
static void
nm_device_take_down (NMDevice *self, gboolean block, NMDeviceStateReason reason)
{
g_return_if_fail (NM_IS_DEVICE (self));
if (nm_device_get_act_request (self))
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self));
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self), reason);
if (nm_device_is_up (self)) {
nm_info ("(%s): cleaning up...", nm_device_get_iface (self));
@ -2107,10 +2111,10 @@ nm_device_dispose (GObject *object)
*/
if (self->priv->managed) {
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
nm_device_take_down (self, FALSE);
nm_device_set_ip4_config (self, NULL, &reason);
nm_device_take_down (self, FALSE, NM_DEVICE_STATE_REASON_REMOVED);
nm_device_set_ip4_config (self, NULL, &ignored);
}
clear_act_request (self);
@ -2348,7 +2352,7 @@ nm_info ("(%s): device state change: %d -> %d", nm_device_get_iface (device), ol
switch (state) {
case NM_DEVICE_STATE_UNMANAGED:
if (old_state > NM_DEVICE_STATE_UNMANAGED)
nm_device_take_down (device, TRUE);
nm_device_take_down (device, TRUE, reason);
break;
case NM_DEVICE_STATE_UNAVAILABLE:
if (old_state == NM_DEVICE_STATE_UNMANAGED) {
@ -2359,7 +2363,7 @@ nm_info ("(%s): device state change: %d -> %d", nm_device_get_iface (device), ol
* eg carrier changes we actually deactivate it */
case NM_DEVICE_STATE_DISCONNECTED:
if (old_state != NM_DEVICE_STATE_UNAVAILABLE)
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device), reason);
break;
default:
break;
@ -2408,7 +2412,9 @@ nm_device_get_managed (NMDevice *device)
}
void
nm_device_set_managed (NMDevice *device, gboolean managed)
nm_device_set_managed (NMDevice *device,
gboolean managed,
NMDeviceStateReason reason)
{
NMDevicePrivate *priv;
@ -2430,8 +2436,8 @@ nm_device_set_managed (NMDevice *device, gboolean managed)
/* If now managed, jump to unavailable */
if (managed)
nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, reason);
else
nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, reason);
}

View file

@ -143,8 +143,6 @@ gboolean nm_device_set_ip4_config (NMDevice *dev,
NMIP4Config *config,
NMDeviceStateReason *reason);
void nm_device_take_down (NMDevice *dev, gboolean wait);
void * nm_device_get_system_config_data (NMDevice *dev);
NMActRequest * nm_device_get_act_request (NMDevice *dev);
@ -166,7 +164,9 @@ gboolean nm_device_can_interrupt_activation (NMDevice *self);
NMDeviceState nm_device_get_state (NMDevice *device);
gboolean nm_device_get_managed (NMDevice *device);
void nm_device_set_managed (NMDevice *device, gboolean managed);
void nm_device_set_managed (NMDevice *device,
gboolean managed,
NMDeviceStateReason reason);
G_END_DECLS

View file

@ -420,7 +420,7 @@ static void
remove_one_device (NMManager *manager, NMDevice *device)
{
if (nm_device_get_managed (device))
nm_device_set_managed (device, FALSE);
nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_REMOVED);
g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
@ -1153,7 +1153,7 @@ handle_unmanaged_devices (NMManager *manager, GPtrArray *ops)
device = nm_manager_get_device_by_udi (manager, udi);
if (device) {
unmanaged = g_slist_prepend (unmanaged, device);
nm_device_set_managed (device, FALSE);
nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
}
}
@ -1162,7 +1162,7 @@ handle_unmanaged_devices (NMManager *manager, GPtrArray *ops)
NMDevice *device = NM_DEVICE (iter->data);
if (!g_slist_find (unmanaged, device))
nm_device_set_managed (device, TRUE);
nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
}
g_slist_free (unmanaged);
@ -1394,7 +1394,10 @@ sync_devices (NMManager *self)
const char *udi = nm_device_get_udi (device);
if (nm_hal_manager_udi_exists (priv->hal_mgr, udi)) {
nm_device_set_managed (device, nm_manager_udi_is_managed (self, udi));
if (nm_manager_udi_is_managed (self, udi))
nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
else
nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
} else {
priv->devices = g_slist_delete_link (priv->devices, iter);
remove_one_device (self, device);
@ -2006,12 +2009,14 @@ impl_manager_activate_connection (NMManager *manager,
gboolean
nm_manager_deactivate_connection (NMManager *manager,
const char *connection_path,
NMDeviceStateReason reason,
GError **error)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
NMVPNManager *vpn_manager;
GSList *iter;
gboolean success = FALSE;
NMVPNConnectionStateReason vpn_reason = NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED;
/* Check for device connections first */
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
@ -2025,7 +2030,7 @@ nm_manager_deactivate_connection (NMManager *manager,
if (!strcmp (connection_path, nm_act_request_get_active_connection_path (req))) {
nm_device_state_changed (device,
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_NONE);
reason);
success = TRUE;
goto done;
}
@ -2033,7 +2038,9 @@ nm_manager_deactivate_connection (NMManager *manager,
/* Check for VPN connections next */
vpn_manager = nm_vpn_manager_get ();
if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path)) {
if (reason == NM_DEVICE_STATE_REASON_CONNECTION_REMOVED)
vpn_reason = NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED;
if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path, vpn_reason)) {
success = TRUE;
} else {
g_set_error (error,
@ -2052,7 +2059,10 @@ impl_manager_deactivate_connection (NMManager *manager,
const char *connection_path,
GError **error)
{
return nm_manager_deactivate_connection (manager, connection_path, error);
return nm_manager_deactivate_connection (manager,
connection_path,
NM_DEVICE_STATE_REASON_USER_REQUESTED,
error);
}
static gboolean
@ -2082,7 +2092,7 @@ impl_manager_sleep (NMManager *manager, gboolean sleep, GError **error)
* we'll remove them in 'wake' for speed's sake.
*/
for (iter = priv->devices; iter; iter = iter->next)
nm_device_set_managed (NM_DEVICE (iter->data), FALSE);
nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING);
} else {
nm_info ("Waking up...");

View file

@ -70,6 +70,7 @@ const char * nm_manager_activate_connection (NMManager *manager,
gboolean nm_manager_deactivate_connection (NMManager *manager,
const char *connection_path,
NMDeviceStateReason reason,
GError **error);
/* State handling */

View file

@ -206,7 +206,9 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
}
gboolean
nm_vpn_manager_deactivate_connection (NMVPNManager *manager, const char *path)
nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
const char *path,
NMVPNConnectionStateReason reason)
{
NMVPNManagerPrivate *priv;
GSList *iter;
@ -226,7 +228,7 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *manager, const char *path)
vpn_path = nm_vpn_connection_get_active_connection_path (vpn);
if (!strcmp (path, vpn_path)) {
nm_vpn_connection_disconnect (vpn, NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED);
nm_vpn_connection_disconnect (vpn, reason);
found = TRUE;
}
}

View file

@ -55,7 +55,8 @@ const char *nm_vpn_manager_activate_connection (NMVPNManager *manager,
GError **error);
gboolean nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
const char *path);
const char *path,
NMVPNConnectionStateReason reason);
void nm_vpn_manager_add_active_connections (NMVPNManager *manager,
NMConnection *filter,