media-export,mediathek: Root-Container-Singleton
authorJens Georg <mail@jensge.org>
Mon, 27 Jul 2009 20:49:48 +0000 (22:49 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 9 Sep 2009 13:46:28 +0000 (16:46 +0300)
Use the same root-container on every interface device

src/plugins/media-export/rygel-media-export-plugin.vala
src/plugins/media-export/rygel-media-export-root-container.vala
src/plugins/mediathek/rygel-mediathek-plugin.vala
src/plugins/mediathek/rygel-mediathek-root-container.vala

index 25f4871..58675ff 100644 (file)
@@ -50,6 +50,6 @@ public void module_init (PluginLoader loader) {
 
 public class Rygel.MediaExportContentDir : ContentDirectory {
     public override MediaContainer? create_root_container () {
-        return new MediaExportRootContainer ();
+        return MediaExportRootContainer.get_instance ();
     }
 }
index a6d089d..c4b34f8 100644 (file)
@@ -28,6 +28,8 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
     private HashMap<File, MediaExportHarvester> harvester;
     private MediaExportRecursiveFileMonitor monitor;
 
+    private static MediaExportRootContainer instance = null;
+
     private ArrayList<string> get_uris () {
         ArrayList<string> uris;
 
@@ -58,10 +60,18 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
         return uris;
     }
 
+    public static MediaExportRootContainer get_instance() {
+        if (MediaExportRootContainer.instance == null) {
+            MediaExportRootContainer.instance = new MediaExportRootContainer ();
+        }
+
+        return MediaExportRootContainer.instance;
+    }
+
     /**
      * Create a new root container.
      */
-    public MediaExportRootContainer () {
+    private MediaExportRootContainer () {
         var db = new MediaDB("media-export");
         base (db, "0", "MediaExportRoot");
 
index 69645ba..3f15a56 100644 (file)
@@ -39,7 +39,7 @@ public void module_init (PluginLoader loader) {
 
 public class Rygel.MediathekContentDir : ContentDirectory {
     public override MediaContainer? create_root_container () {
-        return new MediathekRootContainer ();
+        return MediathekRootContainer.get_instance ();
     }
 }
 
index 428b94e..f84a573 100644 (file)
@@ -27,6 +27,7 @@ using GConf;
 public class Rygel.MediathekRootContainer : Rygel.MediaContainer {
     private ArrayList<MediathekRssContainer> items;
     internal SessionAsync session;
+    private static MediathekRootContainer instance;
 
     public override void get_children (uint offset, 
                                        uint max_count, 
@@ -94,7 +95,15 @@ public class Rygel.MediathekRootContainer : Rygel.MediaContainer {
         return true;
     }
 
-    public MediathekRootContainer () {
+    public static MediathekRootContainer get_instance () {
+        if (MediathekRootContainer.instance == null) {
+            MediathekRootContainer.instance = new MediathekRootContainer ();
+        }
+
+        return instance;
+    }
+
+    private MediathekRootContainer () {
         base.root ("ZDF Mediathek", 0);
         this.session = new Soup.SessionAsync ();
         this.items = new ArrayList<MediathekRssContainer> ();