[conduit] Centralise syncset handling



commit cd78fa8c5a81f4d8fccb33197c87c6e17dc43f4d
Author: John Stowers <john stowers gmail com>
Date:   Thu Sep 23 12:54:17 2010 +1200

    Centralise syncset handling

 conduit/DBus.py            |    5 +++++
 conduit/Globals.py         |    8 ++++++++
 conduit/Main.py            |   30 +++++++++++++++++++-----------
 conduit/Synchronization.py |    4 ++--
 4 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/conduit/DBus.py b/conduit/DBus.py
index 5bbceb3..6bbf456 100644
--- a/conduit/DBus.py
+++ b/conduit/DBus.py
@@ -532,6 +532,11 @@ class DBusInterface(DBusItem):
     def get_syncset(self):
         return self.sync_set
 
+    def get_all_syncsets(self):
+        return [EXPORTED_OBJECTS[path].syncSet
+                    for path in EXPORTED_OBJECTS if path.startswith("/syncset/")
+        ]
+
     @dbus.service.signal(APPLICATION_DBUS_IFACE, signature='s')
     def DataproviderAvailable(self, key):
         self._print("Emmiting DBus signal DataproviderAvailable %s" % key)
diff --git a/conduit/Globals.py b/conduit/Globals.py
index 8a26162..3e15b7a 100644
--- a/conduit/Globals.py
+++ b/conduit/Globals.py
@@ -15,6 +15,8 @@ class Globals:
 
         #the main application
         self.app = None
+        #the dbus interface
+        self.dbus = None
 
         #Global cancellation flag
         self.cancelled = False
@@ -22,3 +24,9 @@ class Globals:
         #the application main loop
         self.mainloop = None
 
+    def get_all_syncsets(self):
+        ss = []
+        for s in [self.app.get_syncset()] + [self.dbus.get_syncset()] + self.dbus.get_all_syncsets():
+            if s not in ss:
+                ss.append(s)
+        return ss
diff --git a/conduit/Main.py b/conduit/Main.py
index aa9f45a..940bb5d 100644
--- a/conduit/Main.py
+++ b/conduit/Main.py
@@ -40,7 +40,6 @@ class Application(dbus.service.Object):
         self.splash = None
         self.gui = None
         self.statusIcon = None
-        self.dbus = None
         self.guiSyncSet = None
         self.uiLib = None
 
@@ -185,23 +184,23 @@ class Application(dbus.service.Object):
                         xmlSettingFilePath=self.settingsFile
                         )
 
-        #Set the view models
-        if options.build_gui:
-            self.BuildGUI()
-            if not options.iconify:
-                self.ShowGUI()
-        
         #Dbus view...
-        self.dbus = DBusInterface(
+        conduit.GLOBALS.dbus = DBusInterface(
                         conduitApplication=self,
                         moduleManager=conduit.GLOBALS.moduleManager,
                         typeConverter=conduit.GLOBALS.typeConverter,
                         syncManager=conduit.GLOBALS.syncManager,
                         guiSyncSet=self.guiSyncSet
                         )
+
+        #Set the view models
+        if options.build_gui:
+            self.BuildGUI()
+            if not options.iconify:
+                self.ShowGUI()
         
         if self.statusIcon:
-            dbusSyncSet = self.dbus.get_syncset()
+            dbusSyncSet = conduit.GLOBALS.dbus.get_syncset()
             dbusSyncSet.connect("conduit-added", self.statusIcon.on_conduit_added)
             dbusSyncSet.connect("conduit-removed", self.statusIcon.on_conduit_removed)
 
@@ -212,6 +211,9 @@ class Application(dbus.service.Object):
         except KeyboardInterrupt:
             self.Quit()
 
+    def get_syncset(self):
+        return self.guiSyncSet
+
     @dbus.service.method(APPLICATION_DBUS_IFACE, in_signature='', out_signature='b')
     def HasGUI(self):
         return self.gui != None
@@ -281,10 +283,16 @@ class Application(dbus.service.Object):
         
         #unitialize all dataproviders
         log.info("Unitializing dataproviders")
-        self.guiSyncSet.quit()
-
+        for ss in conduit.GLOBALS.get_all_syncsets():
+            ss.quit()
+
+        #Close any open DBus resources. Typically calling syncset.quit() will be 
+        #sufficient, except if a nasty DBus user has been creating Conduits
+        #that are not included in any syncset. In that case they
+        #will not be freed when syncset.quit() is called. dbus.quit()
+        #calls quit() on all such conduits
         log.info("Closing DBus interface")
-        self.dbus.quit()
+        conduit.GLOBALS.dbus.quit()
 
         #Save the mapping DB
         conduit.GLOBALS.mappingDB.save()
diff --git a/conduit/Synchronization.py b/conduit/Synchronization.py
index aa19e15..c05bf88 100644
--- a/conduit/Synchronization.py
+++ b/conduit/Synchronization.py
@@ -141,8 +141,8 @@ class SyncManager:
         #need to get the conduit assocated with this dataprovider because the sync-completed
         #signal is emmited from the conduit object
         conds = []
-        conds.extend(conduit.GLOBALS.app.guiSyncSet.get_all_conduits())
-        conds.extend(conduit.GLOBALS.app.dbusSyncSet.get_all_conduits())
+        for ss in conduit.GLOBALS.get_all_syncsets():
+            conds.extend(ss.get_all_conduits())
         for c in conds:
             for dpw in c.get_all_dataproviders():
                 if dataprovider == dpw.module:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]