1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-23 14:42:29 +01:00

If the monitor loses contact with the daemon for an extended period, die instead of ignoring the errors.

This commit is contained in:
Dan O'Reilly
2009-02-04 23:05:05 -05:00
parent 70c93746dd
commit cbbf438f34

View File

@@ -26,6 +26,7 @@ when appropriate.
import gobject import gobject
import time import time
import sys
from dbus import DBusException from dbus import DBusException
@@ -46,6 +47,23 @@ wireless = dbus_dict["wireless"]
monitor = to_time = update_callback = None monitor = to_time = update_callback = None
def diewithdbus(func):
def wrapper(self, *__args, **__kargs):
try:
ret = func(self, *__args, **__kargs)
self.__lost_dbus_count = 0
return ret
except dbusmanager.DBusException:
if self.__lost_dbus_count > 3:
sys.exit(1)
self.__lost_dbus_count += 1
return True
wrapper.__name__ = func.__name__
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
return wrapper
class ConnectionStatus(object): class ConnectionStatus(object):
""" Class for monitoring the computer's connection status. """ """ Class for monitoring the computer's connection status. """
def __init__(self): def __init__(self):
@@ -63,6 +81,7 @@ class ConnectionStatus(object):
self.signal_changed = False self.signal_changed = False
self.iwconfig = "" self.iwconfig = ""
self.trigger_reconnect = False self.trigger_reconnect = False
self.__lost_dbus_count = 0
bus = dbusmanager.get_bus() bus = dbusmanager.get_bus()
bus.add_signal_receiver(self._force_update_connection_status, bus.add_signal_receiver(self._force_update_connection_status,
@@ -143,6 +162,7 @@ class ConnectionStatus(object):
return True return True
@diewithdbus
def update_connection_status(self): def update_connection_status(self):
""" Updates the tray icon and current connection status. """ Updates the tray icon and current connection status.
@@ -153,56 +173,53 @@ class ConnectionStatus(object):
""" """
wired_ip = None wired_ip = None
wifi_ip = None wifi_ip = None
try:
if daemon.GetSuspend():
print "Suspended."
state = misc.SUSPENDED
self.update_state(state)
return True
# Determine what our current state is. if daemon.GetSuspend():
# Are we currently connecting? print "Suspended."
if daemon.CheckIfConnecting(): state = misc.SUSPENDED
state = misc.CONNECTING
self.update_state(state)
return True
daemon.SendConnectResultsIfAvail()
# Check for wired.
wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip)
# Trigger an AutoConnect if we're plugged in, not connected
# to a wired network, and the "autoswitch to wired" option
# is on.
if self.trigger_reconnect:
self.trigger_reconnect = False
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
return True
if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip)
return True
# Check for wireless
wifi_ip = wireless.GetWirelessIP("")
self.signal_changed = False
wireless_found = self.check_for_wireless_connection(wifi_ip)
if wireless_found:
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
return True
state = misc.NOT_CONNECTED
if self.last_state == misc.WIRELESS:
from_wireless = True
else:
from_wireless = False
self.auto_reconnect(from_wireless)
self.update_state(state) self.update_state(state)
except DBusException, e: return True
print 'Ignoring DBus Error: ' + str(e)
# Determine what our current state is.
# Are we currently connecting?
if daemon.CheckIfConnecting():
state = misc.CONNECTING
self.update_state(state)
return True
daemon.SendConnectResultsIfAvail()
# Check for wired.
wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip)
# Trigger an AutoConnect if we're plugged in, not connected
# to a wired network, and the "autoswitch to wired" option
# is on.
if self.trigger_reconnect:
self.trigger_reconnect = False
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
return True
if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip)
return True
# Check for wireless
wifi_ip = wireless.GetWirelessIP("")
self.signal_changed = False
wireless_found = self.check_for_wireless_connection(wifi_ip)
if wireless_found:
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
return True
state = misc.NOT_CONNECTED
if self.last_state == misc.WIRELESS:
from_wireless = True
else:
from_wireless = False
self.auto_reconnect(from_wireless)
self.update_state(state)
return True return True
def _force_update_connection_status(self): def _force_update_connection_status(self):