From 0b007af8959c162ab6254a0c0ab9d0b7c0c4fd58 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 13 Feb 2008 14:04:41 +0000 Subject: add the iface in the address-changed signal --- diff --git a/src/buddy.py b/src/buddy.py index e956b73..430b57b 100644 --- a/src/buddy.py +++ b/src/buddy.py @@ -901,7 +901,7 @@ class GenericOwner(Buddy): if tp.status == CONNECTION_STATUS_CONNECTED: self._set_self_olpc_properties(tp) - def _ip4_address_changed_cb(self, monitor, address): + def _ip4_address_changed_cb(self, monitor, address, iface): """Handle IPv4 address change, set property to generate event""" props = {_PROP_IP4_ADDRESS: address} self.set_properties(props) diff --git a/src/psutils.py b/src/psutils.py index 6b8ec95..f7c6db7 100644 --- a/src/psutils.py +++ b/src/psutils.py @@ -129,7 +129,7 @@ class IP4AddressMonitor(gobject.GObject): __gsignals__ = { 'address-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) + ([gobject.TYPE_PYOBJECT, gobject.TYPE_STRING])) } __gproperties__ = { @@ -155,22 +155,22 @@ class IP4AddressMonitor(gobject.GObject): sys_bus = dbus.SystemBus() self._watch = sys_bus.watch_name_owner(NM_SERVICE, self._nm_owner_cb) if not sys_bus.name_has_owner(NM_SERVICE): - addr = self._get_address_fallback() - self._update_address(addr) + addr, iface = self._get_address_fallback() + self._update_address(addr, iface) def do_get_property(self, pspec): if pspec.name == "address": return self._addr - def _update_address(self, new_addr): + def _update_address(self, new_addr, iface): if new_addr == "0.0.0.0": new_addr = None if new_addr == self._addr: return self._addr = new_addr - _logger.debug("IP4 address now '%s'" % new_addr) - self.emit('address-changed', new_addr) + _logger.debug("IP4 address now '%s' (%s)" % (new_addr, iface)) + self.emit('address-changed', new_addr, iface) def _connect_to_nm(self): """Connect to NM device state signals to tell when the IPv4 address changes""" @@ -215,7 +215,7 @@ class IP4AddressMonitor(gobject.GObject): if act_stage != 8 and act_stage != 7: # not activated return - self._update_address(props[6]) + self._update_address(props[6], props[1]) def _device_properties_error_cb(self, err): _logger.debug("Error querying device properties: %s" % err) @@ -244,11 +244,11 @@ class IP4AddressMonitor(gobject.GObject): self._query_device_properties(device) def _nm_device_no_longer_active_cb(self, device): - self._update_address(None) + self._update_address(None, None) def _nm_state_change_cb(self, new_state): if new_state == 4: # NM_STATE_DISCONNECTED - self._update_address(None) + self._update_address(None, None) def _nm_owner_cb(self, unique_name): """Clear state when NM goes away""" @@ -259,10 +259,10 @@ class IP4AddressMonitor(gobject.GObject): match.remove() self._matches = [] if self._nm_has_been_present: - self._update_address(None) + self._update_address(None, None) else: - addr = self._get_address_fallback() - self._update_address(addr) + addr, iface = self._get_address_fallback() + self._update_address(addr, iface) elif not self._nm_present: # NM started up self._nm_present = True @@ -278,7 +278,7 @@ class IP4AddressMonitor(gobject.GObject): SIOCGIFADDR = 0x8915 addr = fcntl.ioctl(fd, SIOCGIFADDR, struct.pack('256s', iface[:15]))[20:24] s.close() - return socket.inet_ntoa(addr) + return socket.inet_ntoa(addr), iface def _get_address_fallback(self): import commands @@ -290,4 +290,4 @@ class IP4AddressMonitor(gobject.GObject): if fields[0] == "0.0.0.0": iface = fields[len(fields) - 1] return self._get_iface_address(iface) - return None + return None, None diff --git a/src/server_plugin.py b/src/server_plugin.py index 4a32042..8d0a4f0 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -62,8 +62,8 @@ class ServerPlugin(TelepathyPlugin): self._friends_channel = None - def _ip4_address_changed_cb(self, ip4am, address): - TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address) + def _ip4_address_changed_cb(self, ip4am, address, iface): + TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address, iface) if address: _logger.debug("::: valid IP4 address, conn_status %s" % diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py index c486884..5131c9c 100644 --- a/src/telepathy_plugin.py +++ b/src/telepathy_plugin.py @@ -555,7 +555,7 @@ class TelepathyPlugin(gobject.GObject): else: _logger.debug('%r: Postponing connection', self) - def _ip4_address_changed_cb(self, ip4am, address): + def _ip4_address_changed_cb(self, ip4am, address, iface): _logger.debug("::: IP4 address now %s", address) self._reconnect_timeout = self._RECONNECT_INITIAL_TIMEOUT -- cgit v0.9.1