Limiting the sizes of logs
[theonering] / src / connection_manager.py
index 64b6bf8..6d074e9 100644 (file)
@@ -9,17 +9,20 @@ import util.misc as misc_utils
 import connection
 
 
-_moduleLogger = logging.getLogger("connection_manager")
+_moduleLogger = logging.getLogger(__name__)
 
 
 class TheOneRingConnectionManager(tp.ConnectionManager):
 
+       IDLE_TIMEOUT = 10
+
        def __init__(self, shutdown_func=None):
                tp.ConnectionManager.__init__(self, constants._telepathy_implementation_name_)
 
                # self._protos is from super
                self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection
                self._on_shutdown = shutdown_func
+               self._quitImmediately = False
                _moduleLogger.info("Connection manager created")
 
        @misc_utils.log_exception(_moduleLogger)
@@ -59,21 +62,24 @@ class TheOneRingConnectionManager(tp.ConnectionManager):
 
                return result
 
-       def disconnected(self, conn):
-               """
-               Overrides tp.ConnectionManager
-               """
-               result = tp.ConnectionManager.disconnected(self, conn)
-               gobject_utils.timeout_add_seconds(5, self._shutdown)
+       def disconnect_completed(self):
+               if self._quitImmediately:
+                       self._shutdown()
+               else:
+                       gobject_utils.timeout_add_seconds(self.IDLE_TIMEOUT, self._shutdown)
 
        def quit(self):
                """
                Terminates all connections. Must be called upon quit
                """
-               for connection in self._connections:
-                       connection.Disconnect()
+               for conn in self._connections:
+                       conn.Disconnect()
                _moduleLogger.info("Connection manager quitting")
 
+       def quit_now(self):
+               self._quitImmediately = True
+               self.quit()
+
        @misc_utils.log_exception(_moduleLogger)
        def _shutdown(self):
                if (