From 96174e04a69805671fa7b52c53807196685e1c2b Mon Sep 17 00:00:00 2001 From: Christopher Aillon Date: Sun, 11 Sep 2005 01:46:40 +0000 Subject: [PATCH] 2005-09-10 Christopher Aillon * NetworkManager.h: * gnome/applet/applet-dbus-info.c: * gnome/applet/applet-dbus-info.h: * gnome/applet/applet.c: * gnome/applet/applet.h: * src/NetworkManager.c: * src/NetworkManagerDbus.c: * src/NetworkManagerDbus.h: * src/NetworkManagerDevice.c: * src/NetworkManagerDevice.h: * src/NetworkManagerMain.h: * src/NetworkManagerWireless.c: * src/NetworkManagerWireless.h: * src/nm-dbus-nm.c: Make NetworkManager be smart about how frequently to scan based on its current state. Remove the UI for choosing when to scan. Scanning still may disabled completely by the user via the "Wireless Enabled" menu item. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@958 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 21 +++++ NetworkManager.h | 13 --- gnome/applet/applet-dbus-info.c | 69 ++++------------ gnome/applet/applet-dbus-info.h | 4 +- gnome/applet/applet.c | 141 +++----------------------------- gnome/applet/applet.h | 5 -- src/NetworkManager.c | 3 - src/NetworkManagerDbus.c | 77 ++--------------- src/NetworkManagerDbus.h | 2 - src/NetworkManagerDevice.c | 62 +++++++++----- src/NetworkManagerDevice.h | 8 ++ src/NetworkManagerMain.h | 1 - src/NetworkManagerWireless.c | 53 ++++++++++++ src/NetworkManagerWireless.h | 1 + src/nm-dbus-nm.c | 14 ---- 15 files changed, 160 insertions(+), 314 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ba84ca882..6d1e2e0512 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2005-09-10 Christopher Aillon + + * NetworkManager.h: + * gnome/applet/applet-dbus-info.c: + * gnome/applet/applet-dbus-info.h: + * gnome/applet/applet.c: + * gnome/applet/applet.h: + * src/NetworkManager.c: + * src/NetworkManagerDbus.c: + * src/NetworkManagerDbus.h: + * src/NetworkManagerDevice.c: + * src/NetworkManagerDevice.h: + * src/NetworkManagerMain.h: + * src/NetworkManagerWireless.c: + * src/NetworkManagerWireless.h: + * src/nm-dbus-nm.c: + Make NetworkManager be smart about how frequently to scan + based on its current state. Remove the UI for choosing when + to scan. Scanning still may disabled completely by the user + via the "Wireless Enabled" menu item. + 2005-09-09 Christopher Aillon * gnome/applet/applet.c: diff --git a/NetworkManager.h b/NetworkManager.h index b3d849716b..835ff994b9 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -225,17 +225,4 @@ typedef enum NMActStage NM_ACT_STAGE_CANCELLED } NMActStage; - -/* - * Wireless scanning methods - * - */ -typedef enum NMWirelessScanMethod -{ - NM_SCAN_METHOD_UNKNOWN = 0, - NM_SCAN_METHOD_ALWAYS, - NM_SCAN_METHOD_WHEN_UNASSOCIATED, - NM_SCAN_METHOD_NEVER -} NMWirelessScanMethod; - #endif diff --git a/gnome/applet/applet-dbus-info.c b/gnome/applet/applet-dbus-info.c index 89f0328e5c..ab0e9cff32 100644 --- a/gnome/applet/applet-dbus-info.c +++ b/gnome/applet/applet-dbus-info.c @@ -213,55 +213,6 @@ void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, } -/* - * nmi_dbus_signal_update_scan_method - * - * Signal NetworkManager that it needs to update its wireless scanning method - * - */ -void nmi_dbus_signal_update_scan_method (DBusConnection *connection) -{ - DBusMessage *message; - - g_return_if_fail (connection != NULL); - - message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "WirelessScanMethodUpdate"); - if (!message) - { - nm_warning ("nmi_dbus_signal_update_scan_method(): Not enough memory for new dbus message!"); - return; - } - - if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nmi_dbus_signal_update_scan_method(): Could not raise the 'WirelessScanMethodUpdate' signal!"); - - dbus_message_unref (message); -} - - -/* - * nmi_dbus_get_wireless_scan_method - * - * Tell NetworkManager what wireless scanning method it should use - * - */ -static DBusMessage *nmi_dbus_get_wireless_scan_method (NMWirelessApplet *applet, DBusMessage *message) -{ - DBusMessage * reply = NULL; - NMWirelessScanMethod method = NM_SCAN_METHOD_ALWAYS; - GConfEntry * entry; - - g_return_val_if_fail (applet != NULL, NULL); - g_return_val_if_fail (message != NULL, NULL); - - method = nmwa_gconf_get_wireless_scan_method (applet); - reply = dbus_message_new_method_return (message); - dbus_message_append_args (reply, DBUS_TYPE_UINT32, &method, DBUS_TYPE_INVALID); - - return (reply); -} - - /* * nmi_dbus_signal_update_network * @@ -1143,8 +1094,6 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu } } #endif - else if (strcmp ("getWirelessScanMethod", method) == 0) - reply = nmi_dbus_get_wireless_scan_method (applet, message); else if (strcmp ("getNetworks", method) == 0) reply = nmi_dbus_get_networks (applet, message); else if (strcmp ("getNetworkProperties", method) == 0) @@ -1171,3 +1120,21 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu return (DBUS_HANDLER_RESULT_HANDLED); } +void nmi_dbus_signal_user_interface_activated (DBusConnection *connection) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + + message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "UserInterfaceActivated"); + if (!message) + { + nm_warning ("nmi_dbus_signal_user_interface_activated(): Not enough memory for new dbus message!"); + return; + } + + if (!dbus_connection_send (connection, message, NULL)) + nm_warning ("nmi_dbus_signal_user_interface_activated(): Could not raise the 'UserInterfaceActivated' signal!"); + + dbus_message_unref (message); +} diff --git a/gnome/applet/applet-dbus-info.h b/gnome/applet/applet-dbus-info.h index f5114241c8..375d870712 100644 --- a/gnome/applet/applet-dbus-info.h +++ b/gnome/applet/applet-dbus-info.h @@ -32,10 +32,10 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, D void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const NMEncKeyType key_type); -void nmi_dbus_signal_update_scan_method (DBusConnection *connection); - void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type); void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name); +void nmi_dbus_signal_user_interface_activated (DBusConnection *connection); + #endif diff --git a/gnome/applet/applet.c b/gnome/applet/applet.c index d5a6a85379..20cb9c0f13 100644 --- a/gnome/applet/applet.c +++ b/gnome/applet/applet.c @@ -1355,6 +1355,8 @@ static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data) nmwa_dbus_set_device (applet->connection, dev, net ? wireless_network_get_essid (net) : NULL, -1, NULL); network_device_unref (dev); + + nmi_dbus_signal_user_interface_activated (applet->connection); } @@ -1406,6 +1408,8 @@ static void nmwa_menu_vpn_item_activate (GtkMenuItem *item, gpointer user_data) } } } + + nmi_dbus_signal_user_interface_activated (applet->connection); } @@ -1428,6 +1432,8 @@ static void nmwa_menu_dialup_item_activate (GtkMenuItem *item, gpointer user_dat return; nmwa_dbus_dialup_activate_connection (applet, dialup); + + nmi_dbus_signal_user_interface_activated (applet->connection); } @@ -1446,6 +1452,8 @@ static void nmwa_menu_configure_vpn_item_activate (GtkMenuItem *item, gpointer u g_return_if_fail (applet != NULL); g_spawn_async (NULL, (gchar **) argv, NULL, 0, NULL, NULL, NULL, NULL); + + nmi_dbus_signal_user_interface_activated (applet->connection); } /* @@ -1462,51 +1470,8 @@ static void nmwa_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer g_return_if_fail (applet != NULL); nmwa_dbus_vpn_deactivate_connection (applet->connection); -} - -static void scanning_menu_update (GtkWidget *menu_item, GtkCheckMenuItem *active_item) -{ - g_return_if_fail (active_item != NULL); - - g_object_set_data (G_OBJECT (menu_item), "block-activate", GINT_TO_POINTER(1)); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), (GTK_CHECK_MENU_ITEM (menu_item) == active_item) ? TRUE : FALSE); - g_object_set_data (G_OBJECT (menu_item), "block-activate", GINT_TO_POINTER(0)); -} - - -/* - * nmwa_menu_scanning_item_activate - * - * Handle a request to change scanning behavior - * - */ -static void nmwa_menu_scanning_item_activate (GtkMenuItem *item, gpointer user_data) -{ - NMWirelessApplet * applet = (NMWirelessApplet *)user_data; - char * tag; - - g_return_if_fail (item != NULL); - g_return_if_fail (applet != NULL); - - if ((tag = g_object_get_data (G_OBJECT (item), "block-activate"))) - if (GPOINTER_TO_INT(tag) == 1) - return; - - if ((tag = g_object_get_data (G_OBJECT (item), "scan_method"))) - { - NMWirelessScanMethod method = GPOINTER_TO_UINT (tag); - - if ((method == NM_SCAN_METHOD_ALWAYS) || (method == NM_SCAN_METHOD_NEVER) - || (method == NM_SCAN_METHOD_WHEN_UNASSOCIATED)) - gconf_client_set_int (applet->gconf_client, GCONF_PATH_WIRELESS "/scan_method", method, NULL); - } - - /* Check only this menu item */ - if (!applet->scanning_menu) - return; - - gtk_container_foreach (GTK_CONTAINER (applet->scanning_menu), (GtkCallback) scanning_menu_update, (gpointer) item); + nmi_dbus_signal_user_interface_activated (applet->connection); } @@ -2056,6 +2021,8 @@ static void nmwa_dropdown_menu_show_cb (GtkWidget *menu, NMWirelessApplet *apple nmwa_dropdown_menu_populate (applet->dropdown_menu, applet); gtk_widget_show_all (applet->dropdown_menu); } + + nmi_dbus_signal_user_interface_activated (applet->connection); } /* @@ -2107,15 +2074,9 @@ static void nmwa_context_menu_update (NMWirelessApplet *applet) } if (have_wireless) - { - gtk_widget_show_all (applet->scanning_item); gtk_widget_show_all (applet->stop_wireless_item); - } else - { - gtk_widget_hide (applet->scanning_item); gtk_widget_hide (applet->stop_wireless_item); - } } @@ -2130,44 +2091,11 @@ static GtkWidget *nmwa_context_menu_create (NMWirelessApplet *applet) GtkWidget *menu; GtkWidget *menu_item; GtkWidget *image; - GtkWidget *scanning_subitem; g_return_val_if_fail (applet != NULL, NULL); menu = gtk_menu_new (); - /* Construct the wireless scanning submenu */ - applet->scan_method = nmwa_gconf_get_wireless_scan_method (applet); - applet->scanning_item = gtk_menu_item_new_with_mnemonic (_("Wireless Network _Discovery")); - applet->scanning_menu = gtk_menu_new (); - - scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("Always Search"))); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GUINT_TO_POINTER (NM_SCAN_METHOD_ALWAYS)); - if (applet->scan_method == NM_SCAN_METHOD_ALWAYS) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); - gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); - - scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("Search Only When Disconnected"))); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GINT_TO_POINTER (NM_SCAN_METHOD_WHEN_UNASSOCIATED)); - if (applet->scan_method == NM_SCAN_METHOD_WHEN_UNASSOCIATED) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); - gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); - - scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("Never Search"))); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GINT_TO_POINTER (NM_SCAN_METHOD_NEVER)); - if (applet->scan_method == NM_SCAN_METHOD_NEVER) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); - g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); - gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); - - gtk_menu_item_set_submenu (GTK_MENU_ITEM (applet->scanning_item), applet->scanning_menu); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), applet->scanning_item); - /* Wireless Enabled item */ applet->stop_wireless_item = gtk_check_menu_item_new_with_mnemonic (_("_Wireless Enabled")); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (applet->stop_wireless_item), TRUE); @@ -2296,38 +2224,6 @@ static void nmwa_setup_widgets (NMWirelessApplet *applet) } -/* - * nmwa_gconf_get_wireless_scan_method - * - * Grab the wireless scan method from GConf - * - */ -NMWirelessScanMethod nmwa_gconf_get_wireless_scan_method (NMWirelessApplet *applet) -{ - NMWirelessScanMethod method = NM_SCAN_METHOD_ALWAYS; - GConfEntry * entry; - - g_return_val_if_fail (applet, NM_SCAN_METHOD_ALWAYS); - g_return_val_if_fail (applet->gconf_client, NM_SCAN_METHOD_ALWAYS); - - if ((entry = gconf_client_get_entry (applet->gconf_client, GCONF_PATH_WIRELESS "/scan_method", NULL, TRUE, NULL))) - { - GConfValue * value = gconf_entry_get_value (entry); - - if (value && (value->type == GCONF_VALUE_INT)) - { - NMWirelessScanMethod temp_method = gconf_value_get_int (value); - - if ((method == NM_SCAN_METHOD_ALWAYS) || (method == NM_SCAN_METHOD_NEVER) - || (method == NM_SCAN_METHOD_WHEN_UNASSOCIATED)) - method = temp_method; - } - } - - return method; -} - - /* * nmwa_gconf_info_notify_callback * @@ -2347,19 +2243,6 @@ static void nmwa_gconf_info_notify_callback (GConfClient *client, guint connecti { int net_path_len = strlen (GCONF_PATH_WIRELESS_NETWORKS) + 1; - if (strcmp (GCONF_PATH_WIRELESS "/scan_method", key) == 0) - { - GConfValue * value = gconf_entry_get_value (entry); - - if (value && (value->type == GCONF_VALUE_INT)) - { - NMWirelessScanMethod method = gconf_value_get_int (value); - - if ((method == NM_SCAN_METHOD_ALWAYS) || (method == NM_SCAN_METHOD_NEVER) - || (method == NM_SCAN_METHOD_WHEN_UNASSOCIATED)) - nmi_dbus_signal_update_scan_method (applet->connection); - } - } if (strncmp (GCONF_PATH_WIRELESS_NETWORKS"/", key, net_path_len) == 0) { char *network = g_strdup ((key + net_path_len)); @@ -2495,8 +2378,6 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) applet->dialup_list = NULL; applet->nm_state = NM_STATE_DISCONNECTED; applet->tooltips = NULL; - applet->scanning_menu = NULL; - applet->scanning_item = NULL; applet->glade_file = g_build_filename (GLADEDIR, "wireless-applet.glade", NULL); if (!applet->glade_file || !g_file_test (applet->glade_file, G_FILE_TEST_IS_REGULAR)) diff --git a/gnome/applet/applet.h b/gnome/applet/applet.h index 63f0fb9b70..0ed958d137 100644 --- a/gnome/applet/applet.h +++ b/gnome/applet/applet.h @@ -82,7 +82,6 @@ typedef struct /* Data model elements */ gboolean is_adhoc; - NMWirelessScanMethod scan_method; gboolean wireless_enabled; gboolean nm_running; @@ -125,8 +124,6 @@ typedef struct GtkTooltips * tooltips; GtkWidget * context_menu; - GtkWidget * scanning_item; - GtkWidget * scanning_menu; GtkWidget * stop_wireless_item; GtkWidget * passphrase_dialog; @@ -150,8 +147,6 @@ void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const c NetworkDevice * nmwa_get_first_active_device (GSList *dev_list); VPNConnection * nmwa_get_first_active_vpn_connection (NMWirelessApplet *applet); -NMWirelessScanMethod nmwa_gconf_get_wireless_scan_method (NMWirelessApplet *applet); - int nm_null_safe_strcmp (const char *s1, const char *s2); #endif diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 7e5db21762..03ffa31a64 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -428,8 +428,6 @@ static NMData *nm_data_new (gboolean enable_test_devices) } data->enable_test_devices = enable_test_devices; - - data->scanning_method = NM_SCAN_METHOD_ALWAYS; data->wireless_enabled = TRUE; nm_policy_schedule_device_change_check (data); @@ -931,7 +929,6 @@ int main( int argc, char *argv[] ) { nm_policy_schedule_allowed_ap_list_update (nm_data); nm_dbus_vpn_schedule_vpn_connections_update (nm_data); - nm_dbus_update_wireless_scan_method (nm_data->dbus_connection, nm_data); } /* Right before we init hal, we have to make sure our mainloop diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index 58ef8c3fc0..154f727254 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -36,6 +36,7 @@ #include "NetworkManagerAP.h" #include "NetworkManagerAPList.h" #include "NetworkManagerPolicy.h" +#include "NetworkManagerWireless.h" #include "nm-dbus-nm.h" #include "nm-dbus-device.h" #include "nm-dbus-net.h" @@ -598,74 +599,6 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActR } -/* - * nm_dbus_update_wireless_scan_method_cb - * - * Callback from nm_dbus_update_wireless_scan_method - * - */ -static void nm_dbus_update_wireless_scan_method_cb (DBusPendingCall *pcall, NMData *data) -{ - DBusMessage * reply; - NMWirelessScanMethod method = NM_SCAN_METHOD_UNKNOWN; - - g_return_if_fail (pcall != NULL); - g_return_if_fail (data != NULL); - - if (!dbus_pending_call_get_completed (pcall)) - goto out; - - if (!(reply = dbus_pending_call_steal_reply (pcall))) - goto out; - - if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) - { - dbus_message_unref (reply); - goto out; - } - - if (dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &method, DBUS_TYPE_INVALID)) - { - if ((method == NM_SCAN_METHOD_ALWAYS) || (method == NM_SCAN_METHOD_NEVER) - || (method == NM_SCAN_METHOD_WHEN_UNASSOCIATED)) - data->scanning_method = method; - } - dbus_message_unref (reply); - -out: - dbus_pending_call_unref (pcall); -} - - -/* - * nm_dbus_update_wireless_scan_method - * - * Get the wireless scan method from NetworkManagerInfo - * - */ -void nm_dbus_update_wireless_scan_method (DBusConnection *connection, NMData *data) -{ - DBusMessage * message = NULL; - DBusPendingCall * pcall = NULL; - - g_return_if_fail (connection != NULL); - g_return_if_fail (data != NULL); - - if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getWirelessScanMethod"))) - { - nm_warning ("nm_dbus_update_wireless_scan_method(): Couldn't allocate the dbus message"); - return; - } - - if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall) - dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_update_wireless_scan_method_cb, data, NULL); - else - nm_warning ("nm_dbus_update_wireless_scan_method(): could not send dbus message"); - - dbus_message_unref (message); -} - - /* * nm_dbus_update_network_info * @@ -1097,8 +1030,11 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus handled = TRUE; } } - else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "WirelessScanMethodUpdate")) - nm_dbus_update_wireless_scan_method (data->dbus_connection, data); + else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "UserInterfaceActivated")) + { + nm_wireless_set_scan_interval (data, NULL, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); + handled = TRUE; + } } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "Disconnected")) { @@ -1126,7 +1062,6 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus dbus_bus_add_match (connection, match, NULL); nm_policy_schedule_allowed_ap_list_update (data); nm_dbus_vpn_schedule_vpn_connections_update (data); - nm_dbus_update_wireless_scan_method (data->dbus_connection, data); g_free (match); handled = TRUE; } diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h index fe71c28570..3fb0aca73f 100644 --- a/src/NetworkManagerDbus.h +++ b/src/NetworkManagerDbus.h @@ -71,8 +71,6 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActReque void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActRequest *req); -void nm_dbus_update_wireless_scan_method (DBusConnection *connection, NMData *data); - NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network); gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr); diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 8664a08b21..ec952dd918 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -325,7 +325,7 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev, nm_device_set_mode (dev, NETWORK_MODE_INFRA); - opts->scan_interval = 20; + nm_wireless_set_scan_interval (dev->app_data, dev, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); opts->scan_mutex = g_mutex_new (); opts->ap_list = nm_ap_list_new (NETWORK_TYPE_DEVICE); @@ -3221,7 +3221,7 @@ gboolean nm_device_deactivate (NMDevice *dev) nm_device_set_essid (dev, ""); nm_device_set_enc_key (dev, NULL, NM_DEVICE_AUTH_METHOD_NONE); nm_device_set_mode (dev, NETWORK_MODE_INFRA); - dev->options.wireless.scan_interval = 20; + nm_wireless_set_scan_interval (dev->app_data, dev, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); } return TRUE; @@ -3870,12 +3870,6 @@ static gboolean nm_device_wireless_process_scan_results (gpointer user_data) g_slist_free (outdated_list); } - /* If the list changed or we are unassociated, decrease our wireless scanning interval */ - if (list_changed || !nm_device_is_activated (dev)) - dev->options.wireless.scan_interval = 20; - else - dev->options.wireless.scan_interval = MIN (60, dev->options.wireless.scan_interval + 10); - nm_policy_schedule_device_change_check (dev->app_data); return FALSE; @@ -3953,18 +3947,6 @@ static gboolean nm_device_wireless_scan (gpointer user_data) return FALSE; } - /* Reschedule if scanning is off, or if scanning is AUTO and we are - * associated to an access point. - */ - if ( ((dev->app_data->scanning_method == NM_SCAN_METHOD_NEVER) - || ( (dev->app_data->scanning_method == NM_SCAN_METHOD_WHEN_UNASSOCIATED) - && nm_device_is_activated (dev))) - && !scan_cb->force) - { - dev->options.wireless.scan_interval = 10; - goto reschedule; - } - /* Reschedule ourselves if all wireless is disabled, we're asleep, * or we are currently activating. */ @@ -3972,7 +3954,18 @@ static gboolean nm_device_wireless_scan (gpointer user_data) || (dev->app_data->asleep == TRUE) || (nm_device_is_activating (dev) == TRUE)) { - dev->options.wireless.scan_interval = 10; + nm_wireless_set_scan_interval (dev->app_data, dev, NM_WIRELESS_SCAN_INTERVAL_INIT); + goto reschedule; + } + + /* + * A/B/G cards should only scan if they are disconnected. Set the timeout to active + * for the case we lose this connection shortly, it will reach this point and then + * nm_device_is_activated will return FALSE, letting the scan proceed. + */ + if (dev->options.wireless.num_freqs > 14 && nm_device_is_activated (dev) == TRUE) + { + nm_wireless_set_scan_interval (dev->app_data, dev, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); goto reschedule; } @@ -3980,7 +3973,7 @@ static gboolean nm_device_wireless_scan (gpointer user_data) if (dev->test_device) { nm_device_fake_ap_list (dev); - dev->options.wireless.scan_interval = 20; + nm_wireless_set_scan_interval (dev->app_data, dev, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); goto reschedule; } @@ -4118,6 +4111,31 @@ void nm_device_set_ip4_config (NMDevice *dev, NMIP4Config *config) nm_ip4_config_unref (old_config); } +void nm_device_set_wireless_scan_interval (NMDevice *dev, NMWirelessScanInterval interval) +{ + guint seconds; + + g_return_if_fail (dev != NULL); + + switch (interval) + { + case NM_WIRELESS_SCAN_INTERVAL_INIT: + seconds = 10; + break; + + case NM_WIRELESS_SCAN_INTERVAL_INACTIVE: + seconds = 120; + break; + + case NM_WIRELESS_SCAN_INTERVAL_ACTIVE: + default: + seconds = 20; + break; + } + + dev->options.wireless.scan_interval = seconds; +} + /* * nm_device_get_system_config_data diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h index 1a17f527eb..2ee8ca60a3 100644 --- a/src/NetworkManagerDevice.h +++ b/src/NetworkManagerDevice.h @@ -34,6 +34,12 @@ typedef struct NMDevice NMDevice; +typedef enum NMWirelessScanInterval +{ + NM_WIRELESS_SCAN_INTERVAL_INIT = 0, + NM_WIRELESS_SCAN_INTERVAL_ACTIVE, + NM_WIRELESS_SCAN_INTERVAL_INACTIVE +} NMWirelessScanInterval; NMDevice * nm_device_new (const char *iface, const char *udi, gboolean test_device, NMDeviceType test_dev_type, NMData *app_data); @@ -90,6 +96,8 @@ void nm_device_update_signal_strength (NMDevice *dev); NMAccessPoint *nm_device_get_best_ap (NMDevice *dev); +void nm_device_set_wireless_scan_interval (NMDevice *dev, NMWirelessScanInterval interval); + /* There is no function to get the WEP key since that's a slight security risk */ void nm_device_set_enc_key (NMDevice *dev, const char *key, NMDeviceAuthMethod auth_method); diff --git a/src/NetworkManagerMain.h b/src/NetworkManagerMain.h index b2bb9790c4..02caab1f35 100644 --- a/src/NetworkManagerMain.h +++ b/src/NetworkManagerMain.h @@ -81,7 +81,6 @@ typedef struct NMData GSList * dev_list; GMutex * dev_list_mutex; - NMWirelessScanMethod scanning_method; gboolean wireless_enabled; gboolean asleep; diff --git a/src/NetworkManagerWireless.c b/src/NetworkManagerWireless.c index 6f8f325b92..0783fe02cd 100644 --- a/src/NetworkManagerWireless.c +++ b/src/NetworkManagerWireless.c @@ -232,3 +232,56 @@ max_qual->updated); #endif return (CLAMP (percent, 0, 100)); } + + +void nm_update_device_wireless_timeouts (NMData *data, NMWirelessScanInterval interval) +{ + GSList *elt; + NMDevice *dev = NULL; + + for (elt = data->dev_list; elt; elt = g_slist_next (elt)) + { + dev = (NMDevice *)(elt->data); + if (dev && nm_device_is_wireless (dev)) + nm_device_set_wireless_scan_interval (dev, interval); + } +} + +static gboolean nm_wireless_set_scan_interval_cb (gpointer user_data) +{ + NMData *data = (NMData*) user_data; + + nm_wireless_set_scan_interval (data, NULL, NM_WIRELESS_SCAN_INTERVAL_INACTIVE); + + return FALSE; +} + +void nm_wireless_set_scan_interval (NMData *data, NMDevice *dev, NMWirelessScanInterval interval) +{ + static guint source_id = 0; + GSource *source = NULL; + GSList *elt; + + g_return_if_fail (data != NULL); + + if (source_id != 0) + g_source_remove (source_id); + + for (elt = data->dev_list; elt; elt = g_slist_next (elt)) + { + NMDevice *d = (NMDevice *)(elt->data); + if (dev && dev != d) + continue; + + if (d && nm_device_is_wireless (d)) + nm_device_set_wireless_scan_interval (d, interval); + } + + if (interval != NM_WIRELESS_SCAN_INTERVAL_INACTIVE) + { + source = g_timeout_source_new (120000); + g_source_set_callback (source, nm_wireless_set_scan_interval_cb, (gpointer) data, NULL); + source_id = g_source_attach (source, data->main_context); + g_source_unref (source); + } +} diff --git a/src/NetworkManagerWireless.h b/src/NetworkManagerWireless.h index 299f3b0f3d..f84d38f981 100644 --- a/src/NetworkManagerWireless.h +++ b/src/NetworkManagerWireless.h @@ -35,5 +35,6 @@ char * nm_wireless_128bit_key_from_passphrase (const char *passphrase); int nm_wireless_qual_to_percent (const struct iw_quality *qual, const struct iw_quality *max_qual, const struct iw_quality *avg_qual); +void nm_wireless_set_scan_interval (NMData *data, NMDevice *dev, NMWirelessScanInterval interval); #endif diff --git a/src/nm-dbus-nm.c b/src/nm-dbus-nm.c index 1c450f2517..6a4751de01 100644 --- a/src/nm-dbus-nm.c +++ b/src/nm-dbus-nm.c @@ -411,19 +411,6 @@ static DBusMessage *nm_dbus_nm_remove_test_device (DBusConnection *connection, D return (reply); } - -static DBusMessage *nm_dbus_nm_get_wireless_scan_method (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - DBusMessage *reply = NULL; - - g_return_val_if_fail (data && data->data && connection && message, NULL); - - if ((reply = dbus_message_new_method_return (message))) - dbus_message_append_args (reply, DBUS_TYPE_UINT32, &data->data->scanning_method, DBUS_TYPE_INVALID); - - return reply; -} - static DBusMessage *nm_dbus_nm_set_wireless_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { gboolean enabled = FALSE; @@ -562,7 +549,6 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void) nm_dbus_method_list_add_method (list, "activateDialup", nm_dbus_nm_activate_dialup); nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device); nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network); - nm_dbus_method_list_add_method (list, "getWirelessScanMethod", nm_dbus_nm_get_wireless_scan_method); nm_dbus_method_list_add_method (list, "setWirelessEnabled", nm_dbus_nm_set_wireless_enabled); nm_dbus_method_list_add_method (list, "getWirelessEnabled", nm_dbus_nm_get_wireless_enabled); nm_dbus_method_list_add_method (list, "sleep", nm_dbus_nm_sleep);