1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-23 22:52:33 +01:00

Tweak autoconnect logic be more likely to work if initial scans don't give us good results.

This commit is contained in:
Dan O'Reilly
2009-01-22 21:26:05 -05:00
parent 33a08b696e
commit c494387a80
2 changed files with 45 additions and 35 deletions

View File

@@ -484,7 +484,7 @@ class appGui(object):
""" Kick off an asynchronous wireless scan. """ """ Kick off an asynchronous wireless scan. """
if not DBUS_AVAIL: return if not DBUS_AVAIL: return
self.refreshing = True self.refreshing = True
wireless.Scan(reply_handler=None, error_handler=None) wireless.Scan(False)
def refresh_networks(self, widget=None, fresh=True, hidden=None): def refresh_networks(self, widget=None, fresh=True, hidden=None):
""" Refreshes the network list. """ Refreshes the network list.

View File

@@ -99,30 +99,23 @@ class WicdDaemon(dbus.service.Object):
self.dhcp_client = 0 self.dhcp_client = 0
self.link_detect_tool = 0 self.link_detect_tool = 0
self.flush_tool = 0 self.flush_tool = 0
# Load the config file
self.ReadConfig()
# This will speed up the scanning process - if a client doesn't # This will speed up the scanning process - if a client doesn't
# need a fresh scan, just feed them the old one. A fresh scan # need a fresh scan, just feed them the old one. A fresh scan
# can be done by calling Scan(fresh=True). # can be done by calling Scan(fresh=True).
self.LastScan = [] self.LastScan = []
# Load the config file
self.ReadConfig()
signal.signal(signal.SIGTERM, self.DaemonClosing) signal.signal(signal.SIGTERM, self.DaemonClosing)
self.DaemonStarting() self.DaemonStarting()
# Scan since we just got started # Scan since we just got started
if auto_connect: if not auto_connect:
print "autoconnecting if needed...", str(self.GetWirelessInterface())
if not self.auto_reconnect:
self.AutoConnect(True)
else:
self.wireless_bus.Scan()
else:
print 'scan start'
self.wireless_bus.Scan()
self.SetForcedDisconnect(True)
print "--no-autoconnect detected, not autoconnecting..." print "--no-autoconnect detected, not autoconnecting..."
self.SetForcedDisconnect(True)
self.wireless_bus.Scan()
def get_debug_mode(self): def get_debug_mode(self):
return self._debug_mode return self._debug_mode
@@ -328,16 +321,21 @@ class WicdDaemon(dbus.service.Object):
fails it tries a wireless connection. fails it tries a wireless connection.
""" """
print "Autoconnecting..."
# We don't want to rescan/connect if the gui is open. # We don't want to rescan/connect if the gui is open.
if self.gui_open: if self.gui_open:
if self.debug_mode:
print "Skipping autoconnect because GUI is open."
return return
if fresh:
self.wireless_bus.Scan()
if self.wired_bus.CheckPluggedIn(): if self.wired_bus.CheckPluggedIn():
self._wired_autoconnect() if self.debug_mode:
print "Starting wired autoconnect..."
self._wired_autoconnect(fresh)
else: else:
self.wireless_bus._wireless_autoconnect() if self.debug_mode:
print "Starting wireless autoconnect..."
self.wireless_bus._wireless_autoconnect(fresh)
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetAutoReconnect(self): def GetAutoReconnect(self):
@@ -353,7 +351,7 @@ class WicdDaemon(dbus.service.Object):
and wait for the user to initiate reconnection. and wait for the user to initiate reconnection.
""" """
print 'setting automatically reconnect when connection drops' print 'setting automatically reconnect when connection drops %s' % value
self.config.set("Settings", "auto_reconnect", misc.to_bool(value), True) self.config.set("Settings", "auto_reconnect", misc.to_bool(value), True)
self.auto_reconnect = misc.to_bool(value) self.auto_reconnect = misc.to_bool(value)
@@ -680,7 +678,7 @@ class WicdDaemon(dbus.service.Object):
size.append(int(height)) size.append(int(height))
return size return size
def _wired_autoconnect(self): def _wired_autoconnect(self, fresh=True):
""" Attempts to autoconnect to a wired network. """ """ Attempts to autoconnect to a wired network. """
wiredb = self.wired_bus wiredb = self.wired_bus
if self.GetWiredAutoConnectMethod() == 3 and \ if self.GetWiredAutoConnectMethod() == 3 and \
@@ -700,7 +698,7 @@ class WicdDaemon(dbus.service.Object):
if not network: if not network:
print "Couldn't find a default wired connection," + \ print "Couldn't find a default wired connection," + \
" wired autoconnect failed." " wired autoconnect failed."
self.wireless_bus._wireless_autoconnect() self.wireless_bus._wireless_autoconnect(fresh)
return return
# Last-Used. # Last-Used.
@@ -709,7 +707,7 @@ class WicdDaemon(dbus.service.Object):
if not network: if not network:
print "no previous wired profile available, wired " + \ print "no previous wired profile available, wired " + \
"autoconnect failed." "autoconnect failed."
self.wireless_bus._wireless_autoconnect() self.wireless_bus._wireless_autoconnect(fresh)
return return
wiredb.ReadWiredNetworkProfile(network) wiredb.ReadWiredNetworkProfile(network)
@@ -718,12 +716,13 @@ class WicdDaemon(dbus.service.Object):
self.auto_connecting = True self.auto_connecting = True
time.sleep(1.5) time.sleep(1.5)
try: try:
gobject.timeout_add_seconds(3, self._monitor_wired_autoconnect) gobject.timeout_add_seconds(3, self._monitor_wired_autoconnect,
fresh)
except: except:
gobject.timeout_add(3000, self._monitor_wired_autoconnect) gobject.timeout_add(3000, self._monitor_wired_autoconnect, fresh)
return True return True
def _monitor_wired_autoconnect(self): def _monitor_wired_autoconnect(self, fresh):
""" Monitor a wired auto-connection attempt. """ Monitor a wired auto-connection attempt.
Helper method called on a timer that monitors a wired Helper method called on a timer that monitors a wired
@@ -738,7 +737,7 @@ class WicdDaemon(dbus.service.Object):
self.auto_connecting = False self.auto_connecting = False
return False return False
elif not self.wireless_bus.CheckIfWirelessConnecting(): elif not self.wireless_bus.CheckIfWirelessConnecting():
self.wireless_bus._wireless_autoconnect() self.wireless_bus._wireless_autoconnect(fresh)
return False return False
self.auto_connecting = False self.auto_connecting = False
return False return False
@@ -902,6 +901,7 @@ class WirelessDaemon(dbus.service.Object):
self.wifi = wifi self.wifi = wifi
self._debug_mode = debug self._debug_mode = debug
self.forced_disconnect = False self.forced_disconnect = False
self.LastScan = []
self.config = ConfigManager(os.path.join(wpath.etc, self.config = ConfigManager(os.path.join(wpath.etc,
"wireless-settings.conf"), "wireless-settings.conf"),
debug=debug) debug=debug)
@@ -917,23 +917,30 @@ class WirelessDaemon(dbus.service.Object):
def SetHiddenNetworkESSID(self, essid): def SetHiddenNetworkESSID(self, essid):
""" Sets the ESSID of a hidden network for use with Scan(). """ """ Sets the ESSID of a hidden network for use with Scan(). """
self.hidden_essid = str(misc.Noneify(essid)) self.hidden_essid = str(misc.Noneify(essid))
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def Scan(self): def Scan(self, sync=False):
""" Scan for wireless networks. """ Scan for wireless networks.
Scans for wireless networks,optionally using a (hidden) essid Scans for wireless networks, optionally using a (hidden) essid
set with SetHiddenNetworkESSID. set with SetHiddenNetworkESSID.
""" """
if self.debug_mode: if self.debug_mode:
print 'scanning start' print 'scanning start'
self.SendStartScanSignal() self.SendStartScanSignal()
self._Scan() if sync:
self._sync_scan()
else:
self._async_scan()
@misc.threaded @misc.threaded
def _Scan(self): def _async_scan(self):
""" Run a scan in its own thread. """
self._sync_scan()
def _sync_scan(self):
""" Run a scan and send a signal when its finished. """
scan = self.wifi.Scan(str(self.hidden_essid)) scan = self.wifi.Scan(str(self.hidden_essid))
self.LastScan = scan self.LastScan = scan
if self.debug_mode: if self.debug_mode:
@@ -1225,14 +1232,18 @@ class WirelessDaemon(dbus.service.Object):
""" Emits a signal announcing a scan has finished. """ """ Emits a signal announcing a scan has finished. """
pass pass
def _wireless_autoconnect(self): def _wireless_autoconnect(self, fresh=True):
""" Attempts to autoconnect to a wireless network. """ """ Attempts to autoconnect to a wireless network. """
print "No wired connection present, attempting to autoconnect " + \ print "No wired connection present, attempting to autoconnect " + \
"to wireless network" "to wireless network"
if self.wifi.wireless_interface is None: if self.wifi.wireless_interface is None:
print 'Autoconnect failed because wireless interface returned None' print 'Autoconnect failed because wireless interface returned None'
return return
if fresh:
print 'start scan'
self.Scan(sync=True)
print 'end scan'
for x, network in enumerate(self.LastScan): for x, network in enumerate(self.LastScan):
if bool(network["has_profile"]): if bool(network["has_profile"]):
if self.debug_mode: if self.debug_mode:
@@ -1633,7 +1644,6 @@ def main(argv):
bus = dbus.SystemBus() bus = dbus.SystemBus()
wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus) wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus)
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect) daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
gobject.threads_init()
if not no_poll: if not no_poll:
(child_pid, x, x, x) = gobject.spawn_async( (child_pid, x, x, x) = gobject.spawn_async(
[misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")], [misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")],