Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2007-03-03 08:15:18 (GMT)
committer Dan Williams <dcbw@redhat.com>2007-03-03 08:15:18 (GMT)
commitfc970ccf3dbbaf2cfac85b3e300eba8564b5877a (patch)
tree465072f3c997aba22eaffb6c971eb28faa4e68a0 /services
parent7da177a054fe6902791162349dfeb50bc25fa289 (diff)
Attempt periodic reconnection on connect error, traceback less on server problems
Diffstat (limited to 'services')
-rw-r--r--services/presence2/server_plugin.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/services/presence2/server_plugin.py b/services/presence2/server_plugin.py
index 9990c19..472b024 100644
--- a/services/presence2/server_plugin.py
+++ b/services/presence2/server_plugin.py
@@ -96,6 +96,8 @@ class ServerPlugin(gobject.GObject):
self._conn = self._init_connection()
+ self._reconnect_id = 0
+
def _get_account_info(self):
account_info = {}
@@ -210,7 +212,12 @@ class ServerPlugin(gobject.GObject):
# vcards are changed
#self._conn[CONN_INTERFACE_ALIASING].connect_to_signal('AliasesChanged', self._alias_changed_cb)
- self._set_self_buddy_info()
+ try:
+ self._set_self_buddy_info()
+ except RuntimeError, e:
+ print e
+ self.cleanup()
+ return
# Request presence for everyone on the channel
self._conn[CONN_INTERFACE_PRESENCE].GetPresence(subscribe_handles)
@@ -220,7 +227,11 @@ class ServerPlugin(gobject.GObject):
props = {}
props['color'] = profile.get_color().to_string()
props['key'] = profile.get_pubkey()
- self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props)
+ try:
+ self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props)
+ except dbus.DBusException, e:
+ if str(e).find("Server does not support PEP") >= 0:
+ raise RuntimeError("Server does not support PEP")
name = profile.get_nick_name()
self_handle = self._conn[CONN_INTERFACE].GetSelfHandle()
@@ -255,6 +266,7 @@ class ServerPlugin(gobject.GObject):
return False
def start(self):
+ print "Trying to connect..."
# If the connection is already connected query initial contacts
conn_status = self._conn[CONN_INTERFACE].GetStatus()
if conn_status == CONNECTION_STATUS_CONNECTED:
@@ -265,7 +277,22 @@ class ServerPlugin(gobject.GObject):
elif conn_status == CONNECTION_STATUS_CONNECTING:
pass
else:
- self._conn[CONN_INTERFACE].Connect()
+ self._conn[CONN_INTERFACE].Connect(reply_handler=self._connect_reply_cb,
+ error_handler=self._connect_error_cb)
+
+ def _connect_reply_cb(self):
+ if self._reconnect_id > 0:
+ gobject.source_remove(self._reconnect_id)
+
+ def _reconnect(self):
+ self._reconnect_id = 0
+ self.start()
+ return False
+
+ def _connect_error_cb(self, exception):
+ print "Connect error: %s" % exception
+ if not self._reconnect_id:
+ self._reconnect_id = gobject.timeout_add(10000, self._reconnect)
def cleanup(self):
self._conn[CONN_INTERFACE].Disconnect()
@@ -280,6 +307,10 @@ class ServerPlugin(gobject.GObject):
except dbus.DBusException, e:
if str(e).startswith("org.freedesktop.DBus.Error.NoReply"):
raise InvalidBuddyError("couldn't get properties")
+ except KeyError, e:
+ if str(e) == "'%s'" % CONN_INTERFACE_BUDDY_INFO:
+ raise InvalidBuddyError("server doesn't support BuddyInfo interface")
+
if not props.has_key('color'):
raise InvalidBuddyError("no color")
if not props.has_key('key'):