Reducing duplicate error reports and making note of why an error may occur
[theonering] / src / util / tp_utils.py
index dbf06ec..712e642 100644 (file)
@@ -2,12 +2,11 @@
 
 import logging
 
-import gobject
 import dbus
 import telepathy
 
 import util.go_utils as gobject_utils
-import gtk_toolbox
+import misc
 
 
 _moduleLogger = logging.getLogger("tp_utils")
@@ -17,15 +16,16 @@ DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
 class WasMissedCall(object):
 
        def __init__(self, bus, conn, chan, on_success, on_error):
-               self._on_success = on_success
-               self._on_error = on_error
+               self.__on_success = on_success
+               self.__on_error = on_error
 
                self._requested = None
                self._didMembersChange = False
                self._didClose = False
                self._didReport = False
 
-               self._timeoutId = gobject_utils.timeout_add_seconds(10, self._on_timeout)
+               self._onTimeout = gobject_utils.Timeout(self._on_timeout)
+               self._onTimeout.start(seconds=10)
 
                chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].connect_to_signal(
                        "MembersChanged",
@@ -40,7 +40,7 @@ class WasMissedCall(object):
                chan[DBUS_PROPERTIES].GetAll(
                        telepathy.interfaces.CHANNEL_INTERFACE,
                        reply_handler = self._on_got_all,
-                       error_handler = self._on_got_all,
+                       error_handler = self._on_error,
                )
 
        def cancel(self):
@@ -63,40 +63,36 @@ class WasMissedCall(object):
        def _report_success(self):
                assert not self._didReport
                self._didReport = True
-               if self._timeoutId:
-                       gobject.source_remove(self._timeoutId)
-                       self._timeoutId = None
-               self._on_success(self)
+               self._onTimeout.cancel()
+               self.__on_success(self)
 
        def _report_error(self, reason):
                assert not self._didReport
                self._didReport = True
-               if self._timeoutId:
-                       gobject.source_remove(self._timeoutId)
-                       self._timeoutId = None
-               self._on_error(self, reason)
+               self._onTimeout.cancel()
+               self.__on_error(self, reason)
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_got_all(self, properties):
                self._requested = properties["Requested"]
                self._report_missed_if_ready()
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_members_changed(self, message, added, removed, lp, rp, actor, reason):
                if added:
                        self._didMembersChange = True
                        self._report_missed_if_ready()
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_closed(self):
                self._didClose = True
                self._report_missed_if_ready()
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_error(self, *args):
                self._report_error(args)
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_timeout(self):
                self._report_error("timeout")
                return False
@@ -126,15 +122,18 @@ class NewChannelSignaller(object):
                        None
                )
 
-       @gtk_toolbox.log_exception(_moduleLogger)
+       @misc.log_exception(_moduleLogger)
        def _on_new_channel(
                self, channelObjectPath, channelType, handleType, handle, supressHandler
        ):
                connObjectPath = channel_path_to_conn_path(channelObjectPath)
                serviceName = path_to_service_name(channelObjectPath)
-               self._on_user_new_channel(
-                       self._sessionBus, serviceName, connObjectPath, channelObjectPath, channelType
-               )
+               try:
+                       self._on_user_new_channel(
+                               self._sessionBus, serviceName, connObjectPath, channelObjectPath, channelType
+                       )
+               except Exception:
+                       _moduleLogger.exception("Blocking exception from being passed up")
 
 
 def channel_path_to_conn_path(channelObjectPath):