services/presence/psutils, buddy: Track NameOwnerChanged in IP4AddressMonitor

This means Buddy and its subclasses no longer need to care about
NameOwnerChanged at all.

The old code might not have worked anyway, since it was watching for
NameOwnerChanged on the session bus, but invoking NM methods on the system bus.
This commit is contained in:
Simon McVittie 2007-05-25 12:14:39 +01:00
parent fdd8c315cf
commit 56b95264cf
2 changed files with 12 additions and 26 deletions

View File

@ -533,19 +533,12 @@ class GenericOwner(Buddy):
self._owner = True self._owner = True
self._bus = dbus.SessionBus() self._bus = dbus.SessionBus()
self._bus.add_signal_receiver(self._name_owner_changed_cb,
signal_name="NameOwnerChanged",
dbus_interface="org.freedesktop.DBus")
def _ip4_address_changed_cb(self, monitor, address): def _ip4_address_changed_cb(self, monitor, address):
"""Handle IPv4 address change, set property to generate event""" """Handle IPv4 address change, set property to generate event"""
props = {_PROP_IP4_ADDRESS: address} props = {_PROP_IP4_ADDRESS: address}
self.set_properties(props) self.set_properties(props)
def _name_owner_changed_cb(self, name, old, new):
"""Handle D-Bus services we care about appearing and disappearing."""
self._ip4_addr_monitor.handle_name_owner_changed(name, old, new)
def get_registered(self): def get_registered(self):
"""Retrieve whether owner has registered with presence server""" """Retrieve whether owner has registered with presence server"""
return self._registered return self._registered

View File

@ -53,23 +53,13 @@ class IP4AddressMonitor(gobject.GObject):
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self._nm_present = False self._nm_present = False
self._nm_has_been_present = False
self._matches = [] self._matches = []
self._addr = None self._addr = None
self._nm_obj = None self._nm_obj = None
sys_bus = dbus.SystemBus() sys_bus = dbus.SystemBus()
bus_object = sys_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') self._watch = sys_bus.watch_name_owner(NM_SERVICE, self._nm_owner_cb)
try:
if bus_object.GetNameOwner(NM_SERVICE, dbus_interface='org.freedesktop.DBus'):
self._nm_present = True
except dbus.DBusException:
pass
if self._nm_present:
self._connect_to_nm()
else:
addr = self._get_address_fallback()
self._update_address(addr)
def do_get_property(self, pspec): def do_get_property(self, pspec):
if pspec.name == "address": if pspec.name == "address":
@ -163,20 +153,23 @@ class IP4AddressMonitor(gobject.GObject):
if new_state == 4: # NM_STATE_DISCONNECTED if new_state == 4: # NM_STATE_DISCONNECTED
self._update_address(None) self._update_address(None)
def handle_name_owner_changed(self, name, old, new): def _nm_owner_cb(self, unique_name):
"""Clear state when NM goes away""" """Clear state when NM goes away"""
if name != NM_SERVICE: if unique_name == '':
return # NM went away, or isn't there at all
if (old and len(old)) and (not new and not len(new)):
# NM went away
self._nm_present = False self._nm_present = False
for match in self._matches: for match in self._matches:
match.remove() match.remove()
self._matches = [] self._matches = []
self._update_address(None) if self._nm_has_been_present:
elif (not old and not len(old)) and (new and len(new)): self._update_address(None)
else:
addr = self._get_address_fallback()
self._update_address(addr)
elif not self._nm_present:
# NM started up # NM started up
self._nm_present = True self._nm_present = True
self._nm_has_been_present = True
self._connect_to_nm() self._connect_to_nm()
def _get_iface_address(self, iface): def _get_iface_address(self, iface):