Protecting against stopping without starting
[theonering] / src / autogv.py
index a833c61..41467bd 100644 (file)
@@ -39,6 +39,9 @@ class NewGVConversations(object):
                )
 
        def stop(self):
+               if self.__callback is None:
+                       _moduleLogger.info("New conversation monitor stopped without starting")
+                       return
                self._connRef().session.voicemails.updateSignalHandler.unregister_sink(
                        self.__callback
                )
@@ -77,11 +80,16 @@ class RefreshVoicemail(object):
                self._connRef = connRef
                self._newChannelSignaller = telepathy_utils.NewChannelSignaller(self._on_new_channel)
                self._outstandingRequests = []
+               self._isStarted = False
 
        def start(self):
                self._newChannelSignaller.start()
+               self._isStarted = True
 
        def stop(self):
+               if not self._isStarted:
+                       _moduleLogger.info("voicemail monitor stopped without starting")
+                       return
                _moduleLogger.info("Stopping voicemail refresh")
                self._newChannelSignaller.stop()
 
@@ -92,6 +100,8 @@ class RefreshVoicemail(object):
                for request in localRequests:
                        localRequests.cancel()
 
+               self._isStarted = False
+
        @gtk_toolbox.log_exception(_moduleLogger)
        def _on_new_channel(self, bus, serviceName, connObjectPath, channelObjectPath, channelType):
                if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
@@ -174,13 +184,9 @@ class AutoDisconnect(object):
                        _moduleLogger.info("Received connection change event when not logged in")
                        return
                try:
-                       self._connRef().disconnect()
+                       self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR)
                except Exception:
                        _moduleLogger.exception("Error durring disconnect")
-               self._connRef().StatusChanged(
-                       telepathy.CONNECTION_STATUS_DISCONNECTED,
-                       telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
-               )
                self.__delayedDisconnectEventId = None
                return False