mirror of
https://github.com/gryf/wicd.git
synced 2025-12-23 22:52:33 +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:
113
wicd/monitor.py
113
wicd/monitor.py
@@ -26,6 +26,7 @@ when appropriate.
|
||||
|
||||
import gobject
|
||||
import time
|
||||
import sys
|
||||
|
||||
from dbus import DBusException
|
||||
|
||||
@@ -46,6 +47,23 @@ wireless = dbus_dict["wireless"]
|
||||
|
||||
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 for monitoring the computer's connection status. """
|
||||
def __init__(self):
|
||||
@@ -63,6 +81,7 @@ class ConnectionStatus(object):
|
||||
self.signal_changed = False
|
||||
self.iwconfig = ""
|
||||
self.trigger_reconnect = False
|
||||
self.__lost_dbus_count = 0
|
||||
|
||||
bus = dbusmanager.get_bus()
|
||||
bus.add_signal_receiver(self._force_update_connection_status,
|
||||
@@ -143,6 +162,7 @@ class ConnectionStatus(object):
|
||||
|
||||
return True
|
||||
|
||||
@diewithdbus
|
||||
def update_connection_status(self):
|
||||
""" Updates the tray icon and current connection status.
|
||||
|
||||
@@ -153,56 +173,53 @@ class ConnectionStatus(object):
|
||||
"""
|
||||
wired_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.
|
||||
# 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)
|
||||
if daemon.GetSuspend():
|
||||
print "Suspended."
|
||||
state = misc.SUSPENDED
|
||||
self.update_state(state)
|
||||
except DBusException, e:
|
||||
print 'Ignoring DBus Error: ' + str(e)
|
||||
return True
|
||||
|
||||
# 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
|
||||
|
||||
def _force_update_connection_status(self):
|
||||
|
||||
Reference in New Issue
Block a user