From 2f018f3606cedb76922ac59db4f37e51597fb015 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 14 Nov 2007 14:17:57 +0000 Subject: Move IP4AddressMonitor object from ServerPlugin to TelepathyPlugin so we can reset the reconnect timer when our IP is changed --- diff --git a/src/server_plugin.py b/src/server_plugin.py index ef79aaa..fa7efdf 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -56,16 +56,9 @@ class ServerPlugin(TelepathyPlugin): def __init__(self, registry, owner): TelepathyPlugin.__init__(self, registry, owner) - # Monitor IPv4 address as an indicator of the network connection - self._ip4am = psutils.IP4AddressMonitor.get_instance() - self._ip4am_sigid = self._ip4am.connect('address-changed', self._ip4_address_changed_cb) - - def cleanup(self): - TelepathyPlugin.cleanup(self) - self._ip4am.disconnect(self._ip4am_sigid) - def _ip4_address_changed_cb(self, ip4am, address): - _logger.debug("::: IP4 address now %s", address) + TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address) + if address: _logger.debug("::: valid IP4 address, conn_status %s" % self._conn_status) diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py index af1a327..c73e7c7 100644 --- a/src/telepathy_plugin.py +++ b/src/telepathy_plugin.py @@ -36,6 +36,8 @@ from telepathy.interfaces import (CONN_INTERFACE, CHANNEL_TYPE_TEXT, CONN_INTERFACE_ALIASING, CHANNEL_TYPE_CONTACT_LIST, CONN_MGR_INTERFACE) +import psutils + CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo' CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' @@ -142,6 +144,11 @@ class TelepathyPlugin(gobject.GObject): self._session_bus = SessionBus() self._watch_conn_name = None + # Monitor IPv4 address as an indicator of the network connection + self._ip4am = psutils.IP4AddressMonitor.get_instance() + self._ip4am_sigid = self._ip4am.connect('address-changed', + self._ip4_address_changed_cb) + @property def status(self): """Return the Telepathy connection status.""" @@ -332,6 +339,8 @@ class TelepathyPlugin(gobject.GObject): gobject.source_remove(self._backoff_id) self._backoff_id = 0 + self._ip4am.disconnect(self._ip4am_sigid) + def _contacts_offline(self, handles): """Handle contacts going offline (send message, update set)""" self._online_contacts -= handles @@ -540,3 +549,8 @@ class TelepathyPlugin(gobject.GObject): self._init_connection() else: _logger.debug('%r: Postponing connection', self) + + def _ip4_address_changed_cb(self, ip4am, address): + _logger.debug("::: IP4 address now %s", address) + + self._reconnect_timeout = self._RECONNECT_INITIAL_TIMEOUT -- cgit v0.9.1