From: Jens Georg Date: Mon, 21 Sep 2009 12:28:17 +0000 (+0200) Subject: media-export: Use a custom container for DBus X-Git-Tag: RYGEL_0_4~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f12ca4e024f760da5c504112695ed8dd0775fb4;p=profile%2Fivi%2Frygel.git media-export: Use a custom container for DBus All uris added via DBus are now persisted by making them children of this container. --- diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala index 51888d8..258094b 100644 --- a/src/plugins/media-export/rygel-media-export-root-container.vala +++ b/src/plugins/media-export/rygel-media-export-root-container.vala @@ -20,6 +20,29 @@ using Gee; +const string DYNAMIC_CONTAINER_ID = "DynamicContainerId"; + +internal class Rygel.MediaExportDynamicContainer : Rygel.MediaDBContainer { + public MediaExportDynamicContainer ( MediaDB media_db, + MediaContainer parent) { + base (media_db, DYNAMIC_CONTAINER_ID, "dynamic"); + this.parent = parent; + } + + public Gee.List get_uris () { + var result = new ArrayList (); + + var children = this.media_db.get_children (this.id, -1, -1); + if (children != null) { + foreach (var child in children) { + result.add_all (child.uris); + } + } + + return result; + } +} + /** * Represents the root container. */ @@ -28,6 +51,7 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { private HashMap harvester; private MediaExportRecursiveFileMonitor monitor; private MediaExportDBusService service; + private MediaExportDynamicContainer dynamic_elements; private static MediaContainer instance = null; @@ -58,13 +82,9 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { uris.add (uri); } - // add the uris gotten from DBus interface - try { - var obj = this.media_db.get_object ("0"); - if (obj != null && obj.uris != null) { - uris.add_all (obj.uris); - } - } catch (MediaDBError error) { + var dbus_uris = this.dynamic_elements.get_uris (); + if (dbus_uris != null) { + uris.add_all (dbus_uris); } return uris; @@ -86,14 +106,8 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { } public void add_uri (string uri) { - try { - this.uris.add (uri); - this.media_db.update_object (this); - var file = File.new_for_commandline_arg (uri); - this.harvest (file); - } catch (Error error) { - this.uris.remove (uri); - } + var file = File.new_for_commandline_arg (uri); + this.harvest (file, this.dynamic_elements); } public void remove_uri (string uri) { @@ -102,8 +116,6 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { file.get_uri ()); try { - this.uris.remove (uri); - this.media_db.update_object (this); this.media_db.remove_by_id (id); } catch (Error e) { warning ("Failed to remove uri: %s", e.message); @@ -126,6 +138,7 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { this.monitor.changed.connect (this.on_file_changed); this.service = new MediaExportDBusService (this); + this.dynamic_elements = new MediaExportDynamicContainer (db, this); int64 timestamp; if (!this.media_db.exists ("0", out timestamp)) { @@ -136,6 +149,13 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { } } + if (!this.media_db.exists ("DynamicContainerId", out timestamp)) { + try { + media_db.save_object (this.dynamic_elements); + } catch (Error error) { + } + } + ArrayList ids; try { ids = media_db.get_child_ids ("0"); @@ -155,6 +175,9 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer { } foreach (var id in ids) { + if (id == DYNAMIC_CONTAINER_ID) + continue; + debug ("Id %s no longer in config, deleting...", id); try {