2007-02-09 Tambet Ingo <tambet@ximian.com>

* src/nm-device-802-11-wireless.c:
		- Add "network-added" and "network-removed" signals.
		- Use gobject boilerplate macros to define the GObject.
		- Implement wireless device activation.
		- Remove activation_failure_handler and activation_success_handler
		  and instead listen on state-changed signals and run the same code
		  from there.

	* src/nm-device.c:
		- Implment NMDeviceInterface::deactivate.
		- Remove activation_failure_handler and activation_success_handler
		  virtual methods. Each device which is interested in these events
		  can just listen on it's state changed signals.

	* src/NetworkManagerPolicy.c:
		- Move a bit more NMData usage to NMManager.
		- Remove activation scheduling bits.
		- Add listeners for wireless device's "network-added" and
		  "network-removed" signals.
		- Listen device changed signals and deactivate currently activated
		  device when another device start activating (for now).
		- Remove (nm_policy_schedule_device_change_check): There's never a need
		  for calling this, the policy code knows exactly when this should happen,
		  by listening on events from NMManager and NMDevices.

	* src/nm-device-802-3-ethernet.c (nm_device_802_3_ethernet_activate):
	Implement.

	* src/nm-dbus-nm.c (nm_dbus_nm_set_active_device): Call the activation
	method on the specific device instead of going to through policy code
	and determining the device type by passed in AP's existance.

	* src/nm-device-interface.c (nm_device_interface_deactivate): Implement the
	abstract NMDevice deactivation.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2298 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo
2007-02-09 08:50:35 +00:00
committed by Tambet Ingo
parent da934f9605
commit a8191ddaa3
15 changed files with 233 additions and 267 deletions

View File

@@ -40,6 +40,7 @@
#include "NetworkManager.h"
#include "nm-utils.h"
#include "NetworkManagerUtils.h"
#include "nm-device-interface.h"
#include "nm-manager.h"
#include "nm-hal-manager.h"
#include "nm-device.h"
@@ -479,7 +480,6 @@ main (int argc, char *argv[])
nm_data->dialup_list = nm_system_get_dialup_config ();
/* Run the main loop */
nm_policy_schedule_device_change_check (nm_data);
nm_schedule_state_change_signal_broadcast (nm_data);
exit_status = EXIT_SUCCESS;
g_main_loop_run (nm_data->main_loop);

View File

@@ -36,6 +36,7 @@
#include "nm-activation-request.h"
#include "nm-utils.h"
#include "nm-dbus-nmi.h"
#include "nm-device-interface.h"
#include "nm-device-802-11-wireless.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-dbus-manager.h"
@@ -45,6 +46,8 @@ struct NMPolicy {
guint device_state_changed_idle_id;
};
static void schedule_change_check (NMPolicy *policy);
/* NMPolicy is supposed to be one of the highest classes of the
NM class hierarchy and the only public API it needs is:
NMPolicy *nm_policy_new (NMManager *manager);
@@ -80,9 +83,6 @@ static gboolean nm_policy_activation_finish (gpointer user_data)
if (NM_IS_DEVICE_802_11_WIRELESS (dev))
ap = nm_act_request_get_ap (req);
nm_device_activation_success_handler (dev, req);
nm_info ("Activation (%s) successful, device activated.", nm_device_get_iface (dev));
nm_dbus_schedule_device_status_change_signal (data, dev, ap, DEVICE_NOW_ACTIVE);
nm_schedule_state_change_signal_broadcast (data);
@@ -138,17 +138,14 @@ static gboolean nm_policy_activation_failed (gpointer user_data)
dev = nm_act_request_get_dev (req);
g_assert (dev);
nm_device_activation_failure_handler (dev, req);
if (NM_IS_DEVICE_802_11_WIRELESS (dev))
ap = nm_act_request_get_ap (req);
nm_info ("Activation (%s) failed.", nm_device_get_iface (dev));
nm_dbus_schedule_device_status_change_signal (data, dev, ap, DEVICE_ACTIVATION_FAILED);
nm_device_deactivate (dev);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
nm_schedule_state_change_signal_broadcast (data);
nm_policy_schedule_device_change_check (data);
schedule_change_check ((gpointer) global_policy);
return FALSE;
}
@@ -187,7 +184,7 @@ void nm_policy_schedule_activation_failed (NMActRequest *req)
* "locked" on one device at this time.
*
*/
static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **ap)
static NMDevice * nm_policy_auto_get_best_device (NMPolicy *policy, NMAccessPoint **ap)
{
GSList * elt;
NMDevice8023Ethernet * best_wired_dev = NULL;
@@ -196,14 +193,12 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
guint best_wireless_prio = 0;
NMDevice * highest_priority_dev = NULL;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (ap != NULL, NULL);
if (data->asleep)
if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP)
return NULL;
for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt))
{
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
guint dev_type;
gboolean link_active;
guint prio = 0;
@@ -218,8 +213,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
if (!(caps & NM_DEVICE_CAP_NM_SUPPORTED))
continue;
if (NM_IS_DEVICE_802_3_ETHERNET (dev))
{
if (NM_IS_DEVICE_802_3_ETHERNET (dev)) {
/* We never automatically choose devices that don't support carrier detect */
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
continue;
@@ -236,8 +230,8 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
best_wired_prio = prio;
}
}
else if (NM_IS_DEVICE_802_11_WIRELESS (dev) && data->wireless_enabled)
{
else if (NM_IS_DEVICE_802_11_WIRELESS (dev) &&
nm_manager_wireless_enabled (policy->manager)) {
/* Don't automatically choose a device that doesn't support wireless scanning */
if (!(caps & NM_DEVICE_CAP_WIRELESS_SCAN))
continue;
@@ -298,18 +292,13 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
static gboolean
nm_policy_device_change_check (gpointer user_data)
{
NMData * data = (NMData *) user_data;
NMPolicy *policy = (NMPolicy *) user_data;
NMAccessPoint * ap = NULL;
NMDevice * new_dev;
NMDevice * old_dev;
gboolean do_switch = FALSE;
g_return_val_if_fail (data != NULL, FALSE);
data->dev_change_check_idle_id = 0;
g_assert (global_policy != NULL);
old_dev = nm_manager_get_active_device (global_policy->manager);
old_dev = nm_manager_get_active_device (policy->manager);
if (old_dev) {
guint32 caps = nm_device_get_capabilities (old_dev);
@@ -332,7 +321,7 @@ nm_policy_device_change_check (gpointer user_data)
}
}
new_dev = nm_policy_auto_get_best_device (data, &ap);
new_dev = nm_policy_auto_get_best_device (policy, &ap);
/* Four cases here:
*
@@ -361,7 +350,7 @@ nm_policy_device_change_check (gpointer user_data)
} else if (old_dev && !new_dev) {
/* Terminate current connection */
nm_info ("SWITCH: terminating current connection '%s' because it's no longer valid.", nm_device_get_iface (old_dev));
nm_device_deactivate (old_dev);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (old_dev));
do_switch = TRUE;
} else if (old_dev && new_dev) {
NMActRequest * old_act_req = nm_device_get_act_request (old_dev);
@@ -421,13 +410,18 @@ nm_policy_device_change_check (gpointer user_data)
}
}
if (do_switch && (NM_IS_DEVICE_802_3_ETHERNET (new_dev) || (NM_IS_DEVICE_802_11_WIRELESS (new_dev) && ap))) {
NMActRequest * act_req = NULL;
if ((act_req = nm_act_request_new (data, new_dev, ap, FALSE))) {
nm_info ("Will activate connection '%s%s%s'.", nm_device_get_iface (new_dev), ap ? "/" : "", ap ? nm_ap_get_essid (ap) : "");
nm_policy_schedule_device_activation (act_req);
}
if (do_switch) {
if (NM_IS_DEVICE_802_3_ETHERNET (new_dev)) {
nm_info ("Will activate connection '%s'.",
nm_device_get_iface (new_dev));
nm_device_802_3_ethernet_activate (NM_DEVICE_802_3_ETHERNET (new_dev), FALSE);
} else if (NM_IS_DEVICE_802_11_WIRELESS (new_dev) && ap) {
nm_info ("Will activate connection '%s/%s'.",
nm_device_get_iface (new_dev),
nm_ap_get_essid (ap));
nm_device_802_11_wireless_activate (NM_DEVICE_802_11_WIRELESS (new_dev), ap, FALSE);
} else
nm_warning ("Unhandled device activation");
}
if (ap)
@@ -438,85 +432,6 @@ out:
}
/*
* nm_policy_schedule_device_change_check
*
* Queue up an idle handler to deal with state changes that could
* cause us to activate a different device or wireless network.
*
*/
void nm_policy_schedule_device_change_check (NMData *data)
{
guint id;
g_return_if_fail (data != NULL);
if (data->dev_change_check_idle_id > 0)
return;
id = g_idle_add (nm_policy_device_change_check, data);
data->dev_change_check_idle_id = id;
}
/*
* nm_policy_device_activation
*
* Handle device activation, shutting down all other devices and starting
* activation on the requested device.
*
*/
static gboolean
nm_policy_device_activation (gpointer user_data)
{
NMActRequest * req = (NMActRequest *) user_data;
NMDevice * new_dev;
NMDevice * old_dev;
g_return_val_if_fail (req != NULL, FALSE);
g_assert (global_policy != NULL);
if ((old_dev = nm_manager_get_active_device (global_policy->manager)))
nm_device_deactivate (old_dev);
new_dev = nm_act_request_get_dev (req);
if (nm_device_is_activating (new_dev))
return FALSE;
nm_device_activation_start (req);
return FALSE;
}
/*
* nm_policy_schedule_device_activation
*
* Activate a particular device (and possibly access point)
*
*/
void
nm_policy_schedule_device_activation (NMActRequest * req)
{
GSource * source;
NMDevice * dev;
guint id;
g_return_if_fail (req != NULL);
dev = nm_act_request_get_dev (req);
g_assert (dev);
id = g_idle_add (nm_policy_device_activation, req);
source = g_main_context_find_source_by_id (NULL, id);
if (source) {
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
}
nm_info ("Device %s activation scheduled...", nm_device_get_iface (dev));
}
static guint allowed_list_update_id = 0;
/*
@@ -590,7 +505,7 @@ nm_policy_device_list_update_from_allowed_list (gpointer user_data)
g_return_val_if_fail (data != NULL, FALSE);
for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt)) {
for (elt = nm_manager_get_devices (global_policy->manager); elt; elt = elt->next) {
NMDevice *dev = (NMDevice *)(elt->data);
NMDevice80211Wireless * wdev;
@@ -615,7 +530,7 @@ nm_policy_device_list_update_from_allowed_list (gpointer user_data)
nm_ap_list_remove_duplicate_essids (nm_device_802_11_wireless_ap_list_get (wdev));
}
nm_policy_schedule_device_change_check (data);
schedule_change_check ((gpointer) global_policy);
return FALSE;
}
@@ -662,14 +577,10 @@ schedule_change_check (NMPolicy *policy)
if (policy->device_state_changed_idle_id > 0)
return;
/* FIXME: Uncomment this when nm_policy_schedule_device_change_check and
all it's callers have been removed. */
#if 0
policy->device_state_changed_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
nm_policy_device_change_check,
policy,
device_change_check_done);
#endif
}
static void
@@ -689,6 +600,14 @@ device_carrier_changed (NMDevice *device, gboolean carrier_on, gpointer user_dat
schedule_change_check (policy);
}
static void
wireless_networks_changed (NMDevice80211Wireless *device, NMAccessPoint *ap, gpointer user_data)
{
NMPolicy *policy = (NMPolicy *) user_data;
schedule_change_check (policy);
}
static void
device_added (NMManager *manager, NMDevice *device, gpointer user_data)
{
@@ -708,8 +627,6 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data)
nm_data->dev_list = g_slist_append (nm_data->dev_list, device);
}
/* FIXME: Uncomment once the patch to add these signals to wireless devices is committed */
#if 0
if (NM_IS_DEVICE_802_11_WIRELESS (device)) {
g_signal_connect (device, "network-added",
G_CALLBACK (wireless_networks_changed),
@@ -718,7 +635,6 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data)
G_CALLBACK (wireless_networks_changed),
policy);
}
#endif
schedule_change_check (policy);
}
@@ -740,7 +656,18 @@ device_removed (NMManager *manager, NMDevice *device, gpointer user_data)
static void
state_changed (NMManager *manager, NMState state, gpointer user_data)
{
/* FIXME: Do cool stuff here */
NMPolicy *policy = (NMPolicy *) user_data;
if (state == NM_ACT_STAGE_DEVICE_PREPARE) {
/* A device starts activation, bring all devices down
* Remove this when we support multiple active devices.
*/
NMDevice *old_dev;
if ((old_dev = nm_manager_get_active_device (policy->manager)))
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (old_dev));
}
}
NMPolicy *

View File

@@ -34,14 +34,10 @@ NMPolicy *nm_policy_new (NMManager *manager);
void nm_policy_destroy (NMPolicy *policy);
void nm_policy_schedule_device_change_check (NMData *data);
void nm_policy_schedule_device_activation (NMActRequest *req);
void nm_policy_schedule_allowed_ap_list_update (NMData *app_data);
void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data);
void nm_policy_schedule_activation_finish (NMActRequest *req);
void nm_policy_schedule_activation_failed (NMActRequest *req);
#endif
#endif /* NETWORK_MANAGER_POLICY_H */

View File

@@ -448,8 +448,6 @@ nm_dbus_device_set_link_active (DBusConnection *connection,
}
nm_device_set_active_link (data->dev, have_link);
nm_policy_schedule_device_change_check (data->data);
out:
return reply;
}

View File

@@ -35,6 +35,7 @@
#include "NetworkManagerSystem.h"
#include "NetworkManager.h"
#include "nm-ap-security.h"
#include "nm-device-interface.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
@@ -266,6 +267,9 @@ nm_dbus_nm_set_active_device (DBusConnection *connection,
goto out;
}
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
nm_schedule_state_change_signal_broadcast (data);
if (NM_IS_DEVICE_802_11_WIRELESS (dev)) {
NMAPSecurity * security = NULL;
char * essid = NULL;
@@ -315,14 +319,14 @@ nm_dbus_nm_set_active_device (DBusConnection *connection,
g_object_unref (G_OBJECT (security));
nm_info ("User Switch: %s / %s", dev_path, essid);
nm_device_802_11_wireless_activate (NM_DEVICE_802_11_WIRELESS (dev), ap, TRUE);
} else if (NM_IS_DEVICE_802_3_ETHERNET (dev)) {
nm_info ("User Switch: %s", dev_path);
nm_device_802_3_ethernet_activate (NM_DEVICE_802_3_ETHERNET (dev), TRUE);
} else {
nm_warning ("Unhandled device activation");
}
nm_device_deactivate (dev);
nm_schedule_state_change_signal_broadcast (data);
nm_policy_schedule_device_activation (nm_act_request_new (data, dev, ap, TRUE));
/* empty success message */
reply = dbus_message_new_method_return (message);
if (!reply)
@@ -356,7 +360,6 @@ nm_dbus_nm_create_wireless_network (DBusConnection *connection,
NMAPSecurity * security = NULL;
char * essid = NULL;
DBusMessageIter iter;
NMActRequest * req;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
@@ -410,8 +413,7 @@ nm_dbus_nm_create_wireless_network (DBusConnection *connection,
g_object_unref (G_OBJECT (security));
nm_ap_set_user_created (new_ap, TRUE);
req = nm_act_request_new (data, dev, new_ap, TRUE);
nm_policy_schedule_device_activation (req);
nm_device_802_11_wireless_activate (NM_DEVICE_802_11_WIRELESS (dev), new_ap, TRUE);
out:
if (dev)
@@ -553,14 +555,12 @@ nm_dbus_nm_set_wireless_enabled (DBusConnection *connection,
NMDevice * dev = NM_DEVICE (elt->data);
if (NM_IS_DEVICE_802_11_WIRELESS (dev)) {
nm_device_deactivate (dev);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
nm_device_bring_down (dev);
}
}
}
nm_policy_schedule_device_change_check (data);
out:
return reply;
}
@@ -615,7 +615,7 @@ nm_dbus_nm_sleep (DBusConnection *connection,
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
NMDevice *dev = NM_DEVICE (elt->data);
nm_device_set_removed (dev, TRUE);
nm_device_deactivate_quickly (dev);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
nm_system_device_set_up_down (dev, FALSE);
}
@@ -654,7 +654,6 @@ nm_dbus_nm_wake (DBusConnection *connection,
#endif
nm_schedule_state_change_signal_broadcast (data);
nm_policy_schedule_device_change_check (data);
return NULL;
}

View File

@@ -20,6 +20,7 @@
*/
#include "NetworkManager.h"
#include "nm-device-interface.h"
#include "nm-device.h"
#include "nm-activation-request.h"
#include "NetworkManagerAPList.h"
@@ -93,8 +94,7 @@ nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall,
* here... ad nauseum. Figure out how to deal with a failure here.
*/
nm_ap_list_append_ap (data->invalid_ap_list, ap);
nm_device_deactivate (dev);
nm_policy_schedule_device_change_check (data);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
goto out;
}

View File

@@ -50,8 +50,19 @@
/* #define IW_QUAL_DEBUG */
G_DEFINE_TYPE (NMDevice80211Wireless, nm_device_802_11_wireless, NM_TYPE_DEVICE)
#define NM_DEVICE_802_11_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessPrivate))
enum {
NETWORK_ADDED,
NETWORK_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct Supplicant {
NMSupplicantManager * mgr;
NMSupplicantInterface * iface;
@@ -151,6 +162,19 @@ static void supplicant_mgr_state_cb (NMSupplicantInterface * iface,
static void cleanup_supplicant_interface (NMDevice80211Wireless * self);
static void
network_added (NMDevice80211Wireless *device, NMAccessPoint *ap)
{
g_signal_emit (device, signals[NETWORK_ADDED], 0, ap);
}
static void
network_removed (NMDevice80211Wireless *device, NMAccessPoint *ap)
{
g_signal_emit (device, signals[NETWORK_REMOVED], 0, ap);
}
/*
* nm_device_802_11_wireless_update_bssid
*
@@ -596,6 +620,28 @@ real_deactivate (NMDevice *dev)
}
void
nm_device_802_11_wireless_activate (NMDevice80211Wireless *self,
NMAccessPoint *ap,
gboolean user_requested)
{
NMDevice *device;
NMActRequest *req;
g_return_if_fail (NM_IS_DEVICE_802_11_WIRELESS (self));
g_return_if_fail (ap != NULL);
device = NM_DEVICE (self);
req = nm_act_request_new (nm_device_get_app_data (device),
device,
ap,
user_requested);
nm_device_activate (device, req);
nm_act_request_unref (req);
}
/*
* nm_device_copy_allowed_to_dev_list
*
@@ -2062,6 +2108,7 @@ merge_scanned_ap (NMDevice80211Wireless *dev,
/* Did the AP's name change? */
if (!devlist_essid || !merge_essid || nm_null_safe_strcmp (devlist_essid, merge_essid)) {
network_removed (dev, list_ap);
nm_dbus_signal_wireless_network_change (dev, list_ap,
NETWORK_STATUS_DISAPPEARED, -1);
new = TRUE;
@@ -2085,6 +2132,8 @@ merge_scanned_ap (NMDevice80211Wireless *dev,
* has gone out.
*/
nm_ap_set_essid (list_ap, merge_essid);
network_added (dev, list_ap);
}
else if ((list_ap = nm_ap_list_get_ap_by_essid (list, nm_ap_get_essid (merge_ap))))
{
@@ -2119,6 +2168,7 @@ merge_scanned_ap (NMDevice80211Wireless *dev,
} else {
/* Add the merge AP to the list. */
nm_ap_list_append_ap (list, merge_ap);
network_added (dev, merge_ap);
list_ap = merge_ap;
new = TRUE;
}
@@ -2137,26 +2187,18 @@ cull_scan_list (NMDevice80211Wireless * self)
NMAccessPoint * outdated_ap;
GSList * outdated_list = NULL;
GSList * elt;
NMActRequest * req;
NMAccessPoint * cur_ap = NULL;
NMAPListIter * iter = NULL;
NMData * app_data;
g_return_if_fail (self != NULL);
app_data = nm_device_get_app_data (NM_DEVICE (self));
g_assert (app_data);
if ((req = nm_device_get_act_request (NM_DEVICE (self))))
cur_ap = nm_act_request_get_ap (req);
g_get_current_time (&cur_time);
if (!(ap_list = nm_device_802_11_wireless_ap_list_get (self)))
goto out;
return;
if (!(iter = nm_ap_list_iter_new (ap_list)))
goto out;
return;
/* Walk the access point list and remove any access points older than
* thrice the inactive scan interval.
@@ -2187,13 +2229,11 @@ cull_scan_list (NMDevice80211Wireless * self)
for (elt = outdated_list; elt; elt = g_slist_next (elt)) {
if (!(outdated_ap = (NMAccessPoint *)(elt->data)))
continue;
network_removed (self, outdated_ap);
nm_dbus_signal_wireless_network_change (self, outdated_ap, NETWORK_STATUS_DISAPPEARED, -1);
nm_ap_list_remove_ap (nm_device_802_11_wireless_ap_list_get (self), outdated_ap);
}
g_slist_free (outdated_list);
out:
nm_policy_schedule_device_change_check (app_data);
}
#define SET_QUALITY_MEMBER(qual_item, lc_member, uc_member) \
@@ -2428,15 +2468,10 @@ supplicant_iface_state_cb_handler (gpointer user_data)
old_state);
if (new_state == NM_SUPPLICANT_INTERFACE_STATE_READY) {
NMData * app_data = nm_device_get_app_data (NM_DEVICE (self));
/* Start the scanning timeout for devices that can do scanning */
if (nm_device_get_capabilities (NM_DEVICE (self)) & NM_DEVICE_CAP_WIRELESS_SCAN) {
self->priv->pending_scan_id = g_idle_add (request_wireless_scan, self);
}
/* Device may be able to be activated now */
nm_policy_schedule_device_change_check (app_data);
} else if (new_state == NM_SUPPLICANT_INTERFACE_STATE_DOWN) {
cancel_pending_scan (self);
cleanup_association_attempt (self, FALSE);
@@ -2609,7 +2644,6 @@ supplicant_mgr_state_cb_handler (gpointer user_data)
if (new_state == NM_SUPPLICANT_MANAGER_STATE_DOWN) {
if (self->priv->supplicant.iface) {
NMDevice * dev = NM_DEVICE (self);
NMData * app_data = nm_device_get_app_data (dev);
cleanup_association_attempt (self, FALSE);
cleanup_supplicant_interface (self);
@@ -2620,8 +2654,6 @@ supplicant_mgr_state_cb_handler (gpointer user_data)
NMActRequest * req = nm_device_get_act_request (dev);
nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED);
nm_policy_schedule_activation_failed (req);
} else if (nm_device_is_activated (dev)) {
nm_policy_schedule_device_change_check (app_data);
}
}
} else if (new_state == NM_SUPPLICANT_MANAGER_STATE_IDLE) {
@@ -3074,15 +3106,18 @@ real_act_stage4_ip_config_timeout (NMDevice *dev,
static void
real_activation_success_handler (NMDevice *dev,
NMActRequest *req)
activation_success_handler (NMDevice *dev)
{
NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev);
NMActRequest *req;
struct ether_addr addr;
NMAccessPoint * ap = nm_act_request_get_ap (req);
NMAccessPoint * ap;
gboolean automatic;
NMData * app_data;
req = nm_device_get_act_request (dev);
ap = nm_act_request_get_ap (req);
app_data = nm_act_request_get_data (req);
g_assert (app_data);
@@ -3106,13 +3141,14 @@ real_activation_success_handler (NMDevice *dev,
static void
real_activation_failure_handler (NMDevice *dev,
NMActRequest *req)
activation_failure_handler (NMDevice *dev)
{
NMData * app_data;
NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev);
NMActRequest *req;
NMAccessPoint * ap;
req = nm_device_get_act_request (dev);
app_data = nm_act_request_get_data (req);
g_assert (app_data);
@@ -3253,6 +3289,8 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMDevice80211WirelessPrivate));
object_class->dispose = nm_device_802_11_wireless_dispose;
object_class->finalize = nm_device_802_11_wireless_finalize;
@@ -3271,39 +3309,47 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
parent_class->deactivate_quickly = real_deactivate_quickly;
parent_class->can_interrupt_activation = real_can_interrupt_activation;
parent_class->activation_failure_handler = real_activation_failure_handler;
parent_class->activation_success_handler = real_activation_success_handler;
parent_class->activation_cancel_handler = real_activation_cancel_handler;
g_type_class_add_private (object_class, sizeof (NMDevice80211WirelessPrivate));
/* Signals */
signals[NETWORK_ADDED] =
g_signal_new ("network-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDevice80211WirelessClass, network_added),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
signals[NETWORK_REMOVED] =
g_signal_new ("network-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDevice80211WirelessClass, network_removed),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
}
GType
nm_device_802_11_wireless_get_type (void)
static void
state_changed_cb (NMDevice *device, NMDeviceState state, gpointer user_data)
{
static GType type = 0;
if (type == 0)
{
static const GTypeInfo info =
{
sizeof (NMDevice80211WirelessClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) nm_device_802_11_wireless_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (NMDevice80211Wireless),
0, /* n_preallocs */
(GInstanceInitFunc) nm_device_802_11_wireless_init,
NULL /* value_table */
};
type = g_type_register_static (NM_TYPE_DEVICE,
"NMDevice80211Wireless",
&info, 0);
switch (state) {
case NM_DEVICE_STATE_ACTIVATED:
activation_success_handler (device);
break;
case NM_DEVICE_STATE_FAILED:
activation_failure_handler (device);
break;
default:
break;
}
return type;
}
NMDevice80211Wireless *
nm_device_802_11_wireless_new (const char *iface,
const char *udi,
@@ -3325,10 +3371,9 @@ nm_device_802_11_wireless_new (const char *iface,
NM_DEVICE_INTERFACE_APP_DATA, app_data,
NULL);
/* FIXME */
/* g_signal_connect (obj, "state-changed", */
/* (GCallback) state_changed_cb, */
/* NULL); */
g_signal_connect (obj, "state-changed",
G_CALLBACK (state_changed_cb),
NULL);
return NM_DEVICE_802_11_WIRELESS (obj);

View File

@@ -69,6 +69,10 @@ struct _NMDevice80211Wireless
struct _NMDevice80211WirelessClass
{
NMDeviceClass parent;
/* Signals */
void (*network_added) (NMDevice80211Wireless *device, NMAccessPoint *ap);
void (*network_removed) (NMDevice80211Wireless *device, NMAccessPoint *ap);
};
@@ -80,6 +84,10 @@ NMDevice80211Wireless *nm_device_802_11_wireless_new (const char *iface,
gboolean test_dev,
NMData *app_data);
void nm_device_802_11_wireless_activate (NMDevice80211Wireless *device,
NMAccessPoint *ap,
gboolean user_requested);
void nm_device_802_11_wireless_set_essid (NMDevice80211Wireless *self,
const char *essid);

View File

@@ -240,6 +240,26 @@ nm_device_802_3_ethernet_new (const char *iface,
}
void
nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *self,
gboolean user_requested)
{
NMDevice *device;
NMActRequest *req;
g_return_if_fail (NM_IS_DEVICE_802_3_ETHERNET (self));
device = NM_DEVICE (self);
req = nm_act_request_new (nm_device_get_app_data (device),
device,
NULL,
user_requested);
nm_device_activate (device, req);
nm_act_request_unref (req);
}
/*
* nm_device_802_3_ethernet_get_address
*

View File

@@ -65,6 +65,9 @@ NMDevice8023Ethernet *nm_device_802_3_ethernet_new (const char *iface,
gboolean test_dev,
NMData *app_data);
void nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *self,
gboolean user_requested);
void nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *dev,
struct ether_addr *addr);

View File

@@ -51,5 +51,6 @@ struct _NMDeviceInterface {
GType nm_device_interface_get_type (void);
void nm_device_interface_deactivate (NMDeviceInterface *device);
#endif /* NM_DEVICE_INTERFACE_H */

View File

@@ -40,6 +40,8 @@ NMIP4Config * nm_device_new_ip4_autoip_config (NMDevice *self);
void nm_device_activate_schedule_stage3_ip_config_start (struct NMActRequest *req);
void nm_device_activate (NMDevice *device, NMActRequest *req);
void nm_device_state_changed (NMDevice *device, NMDeviceState state);

View File

@@ -78,7 +78,7 @@ struct _NMDevicePrivate
};
static void nm_device_activate_schedule_stage5_ip_config_commit (NMActRequest *req);
static void nm_device_deactivate (NMDeviceInterface *device);
void nm_device_bring_up (NMDevice *dev);
gboolean nm_device_bring_up_wait (NMDevice *self, gboolean cancelable);
@@ -93,6 +93,8 @@ nm_device_set_address (NMDevice *device)
static void
device_interface_init (NMDeviceInterface *device_interface_class)
{
/* interface implementation */
device_interface_class->deactivate = nm_device_deactivate;
}
@@ -195,7 +197,7 @@ nm_device_stop (NMDevice *self)
{
g_return_if_fail (self != NULL);
nm_device_deactivate (self);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self));
nm_device_bring_down (self);
}
@@ -296,7 +298,7 @@ nm_device_get_driver (NMDevice *self)
NMDeviceType
nm_device_get_device_type (NMDevice *self)
{
g_return_val_if_fail (self != NULL, DEVICE_TYPE_UNKNOWN);
g_return_val_if_fail (NM_IS_DEVICE (self), DEVICE_TYPE_UNKNOWN);
return self->priv->type;
}
@@ -434,45 +436,37 @@ nm_device_set_active_link (NMDevice *self,
/*
* nm_device_activation_start
*
* Tell the device thread to begin activation.
*
* Returns: TRUE on success activation beginning
* FALSE on error beginning activation (bad params, couldn't create thread)
*
* Tell the device to begin activation.
*/
gboolean
nm_device_activation_start (NMActRequest *req)
void
nm_device_activate (NMDevice *device,
NMActRequest *req)
{
NMDevicePrivate *priv;
NMData * data = NULL;
NMDevice * self = NULL;
NMData *data = NULL;
g_return_val_if_fail (req != NULL, FALSE);
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (req != NULL);
priv = NM_DEVICE_GET_PRIVATE (device);
if (priv->state != NM_DEVICE_STATE_DISCONNECTED)
/* Already activating or activated */
return;
nm_info ("Activation (%s) started...", nm_device_get_iface (device));
data = nm_act_request_get_data (req);
g_assert (data);
self = nm_act_request_get_dev (req);
g_assert (self);
priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->state != NM_DEVICE_STATE_DISCONNECTED)
/* Already activating or activated */
return FALSE;
nm_act_request_ref (req);
self->priv->act_request = req;
nm_info ("Activation (%s) started...", nm_device_get_iface (self));
priv->act_request = req;
nm_act_request_set_stage (req, NM_ACT_STAGE_DEVICE_PREPARE);
nm_device_activate_schedule_stage1_device_prepare (req);
nm_schedule_state_change_signal_broadcast (data);
nm_dbus_schedule_device_status_change_signal (data, self, NULL, DEVICE_ACTIVATING);
return TRUE;
nm_dbus_schedule_device_status_change_signal (data, device, NULL, DEVICE_ACTIVATING);
}
@@ -1192,9 +1186,10 @@ nm_device_deactivate_quickly (NMDevice *self)
* Remove a device's routing table entries and IP address.
*
*/
void
nm_device_deactivate (NMDevice *self)
static void
nm_device_deactivate (NMDeviceInterface *device)
{
NMDevice *self = NM_DEVICE (device);
NMData * app_data;
NMIP4Config * config;
@@ -1296,28 +1291,6 @@ nm_device_is_activated (NMDevice *dev)
}
void
nm_device_activation_failure_handler (NMDevice *self,
struct NMActRequest *req)
{
g_return_if_fail (self != NULL);
g_return_if_fail (req != NULL);
if (NM_DEVICE_GET_CLASS (self)->activation_failure_handler)
NM_DEVICE_GET_CLASS (self)->activation_failure_handler (self, req);
}
void nm_device_activation_success_handler (NMDevice *self,
struct NMActRequest *req)
{
g_return_if_fail (self != NULL);
g_return_if_fail (req != NULL);
if (NM_DEVICE_GET_CLASS (self)->activation_success_handler)
NM_DEVICE_GET_CLASS (self)->activation_success_handler (self, req);
}
gboolean
nm_device_can_interrupt_activation (NMDevice *self)
{
@@ -1816,7 +1789,7 @@ nm_device_state_changed (NMDevice *device, NMDeviceState state)
break;
case NM_DEVICE_STATE_FAILED:
nm_info ("Activation (%s) failed.", nm_device_get_iface (device));
nm_device_deactivate (device);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
break;
default:
break;

View File

@@ -107,10 +107,6 @@ struct _NMDeviceClass
void (* deactivate) (NMDevice *self);
void (* deactivate_quickly) (NMDevice *self);
void (* activation_failure_handler) (NMDevice *self,
struct NMActRequest *req);
void (* activation_success_handler) (NMDevice *self,
struct NMActRequest *req);
void (* activation_cancel_handler) (NMDevice *self,
struct NMActRequest *req);
@@ -169,21 +165,14 @@ NMDevice * nm_get_device_by_iface (struct NMData *data,
gboolean nm_device_is_test_device (NMDevice *dev);
gboolean nm_device_activation_start (struct NMActRequest *req);
void nm_device_activate_schedule_stage1_device_prepare (struct NMActRequest *req);
void nm_device_activate_schedule_stage2_device_config (struct NMActRequest *req);
void nm_device_activate_schedule_stage4_ip_config_get (struct NMActRequest *req);
void nm_device_activate_schedule_stage4_ip_config_timeout (struct NMActRequest *req);
void nm_device_deactivate (NMDevice *dev);
gboolean nm_device_deactivate_quickly (NMDevice *dev);
gboolean nm_device_is_activating (NMDevice *dev);
void nm_device_activation_cancel (NMDevice *dev);
void nm_device_activation_failure_handler (NMDevice *dev,
struct NMActRequest *req);
void nm_device_activation_success_handler (NMDevice *dev,
struct NMActRequest *req);
gboolean nm_device_can_interrupt_activation (NMDevice *self);
NMDeviceState nm_device_get_state (NMDevice *device);

View File

@@ -3,6 +3,7 @@
#include "nm-manager.h"
#include "nm-utils.h"
#include "nm-dbus-manager.h"
#include "nm-device-interface.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerSystem.h"
// #include "NetworkManagerDbus.h"
@@ -39,8 +40,12 @@ enum {
};
static void
nm_manager_init (NMManager *msg)
nm_manager_init (NMManager *manager)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
priv->wireless_enabled = TRUE;
priv->sleeping = FALSE;
}
static void
@@ -49,7 +54,7 @@ device_stop_and_free (gpointer data, gpointer user_data)
NMDevice *device = NM_DEVICE (data);
nm_device_set_removed (device, TRUE);
nm_device_deactivate (device);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
g_object_unref (device);
}
@@ -199,7 +204,7 @@ manager_set_wireless_enabled (NMManager *manager, gboolean enabled)
NMDevice *dev = NM_DEVICE (iter->data);
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) {
nm_device_deactivate (dev);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev));
nm_device_bring_down (dev);
}
}
@@ -239,7 +244,7 @@ nm_manager_add_device (NMManager *manager, NMDevice *device)
g_signal_connect (device, "state-changed",
G_CALLBACK (manager_device_state_changed),
manager);
nm_device_deactivate (device);
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
manager_device_added (manager, device);
}