[rygel] server, media-export: Add and use signals emitted after tracking child changes.
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] server, media-export: Add and use signals emitted after tracking child changes.
- Date: Thu, 14 Feb 2013 15:28:06 +0000 (UTC)
commit e99ef02d9318036f27a99a7f5db7977f192dafd7
Author: Krzesimir Nowak <krnowak openismus com>
Date: Wed Feb 13 16:43:18 2013 +0100
server,media-export: Add and use signals emitted after tracking child changes.
child_added and child_removed are emitted when respectively
add_child_tracked and remove_child_tracked are finished. We use those
signals in media-export to store the container and, optionally, its
new child in the database. That simplifies a code a bit in
media-export and makes sure that update IDs are stored in database as
well.
https://bugzilla.gnome.org/show_bug.cgi?id=693577
src/librygel-server/rygel-trackable-container.vala | 4 ++
.../media-export/rygel-media-export-harvester.vala | 6 +---
.../rygel-media-export-harvesting-task.vala | 13 +-------
.../rygel-media-export-trackable-db-container.vala | 32 ++++++++++++++++++++
4 files changed, 39 insertions(+), 16 deletions(-)
---
diff --git a/src/librygel-server/rygel-trackable-container.vala
b/src/librygel-server/rygel-trackable-container.vala
index 5ccc141..5c1283e 100644
--- a/src/librygel-server/rygel-trackable-container.vala
+++ b/src/librygel-server/rygel-trackable-container.vala
@@ -51,6 +51,8 @@ public interface Rygel.TrackableContainer : Rygel.MediaContainer {
* See the remove_child() virtual function.
*/
protected abstract async void add_child (MediaObject object);
+ protected signal void child_added (MediaObject object);
+ protected signal void child_removed (MediaObject object);
/**
* Add a child object, emitting the #RygelContainer::container_updated signal
@@ -70,6 +72,7 @@ public interface Rygel.TrackableContainer : Rygel.MediaContainer {
// Release the events that might have accumulated
trackable.thaw_events ();
}
+ this.child_added (object);
}
/**
@@ -101,6 +104,7 @@ public interface Rygel.TrackableContainer : Rygel.MediaContainer {
// FIXME: Check if modification of child_count should lead to
// LastChange event.
this.updated ();
+ this.child_removed (object);
}
/**
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala
b/src/plugins/media-export/rygel-media-export-harvester.vala
index 557113d..7732dc6 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -230,11 +230,7 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
parent = object.parent;
if (parent is TrackableContainer) {
var container = parent as TrackableContainer;
- container.remove_child_tracked.begin (object, () => {
- try {
- cache.save_container (container);
- } catch (Error error) { }
- });
+ container.remove_child_tracked.begin (object);
}
if (parent == null) {
break;
diff --git a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
index a2e2e8f..f34a6c4 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -326,12 +326,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
(item as UpdatableObject).commit.begin ();
} else {
var container = item.parent as TrackableContainer;
- container.add_child_tracked.begin (item, () => {
- // save again to make sure we persist the update count
- try {
- cache.save_item (item);
- } catch (Error error) { }
- }) ;
+ container.add_child_tracked.begin (item) ;
}
}
@@ -372,11 +367,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
try {
if (cache.get_child_count (container.id) == 0) {
var parent = container.parent as TrackableContainer;
- parent.remove_child_tracked.begin (container, () => {
- try {
- cache.save_container (parent);
- } catch (Error error) { }
- });
+ parent.remove_child_tracked.begin (container);
}
} catch (Error error) { }
this.containers.pop_head ();
diff --git a/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
index aac9a35..7f9dd5a 100644
--- a/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
@@ -33,6 +33,38 @@ public class Rygel.MediaExport.TrackableDbContainer : DBContainer,
child_count : 0);
}
+ public override void constructed () {
+ base.constructed ();
+
+ this.child_added.connect (on_child_added);
+ this.child_removed.connect (on_child_removed);
+ }
+
+ private void on_child_added (MediaObject object) {
+ try {
+ var cache = this.media_db;
+
+ if (object is MediaItem) {
+ cache.save_item (object as MediaItem);
+ } else if (object is MediaContainer) {
+ cache.save_container (object as MediaContainer);
+ } else {
+ assert_not_reached ();
+ }
+ cache.save_container (this);
+ } catch (Error error) {
+ warning ("Failed to save object: %s", error.message);
+ }
+ }
+
+ private void on_child_removed (MediaObject object) {
+ try {
+ this.media_db.save_container (this);
+ } catch (Error error) {
+ warning ("Failed to save object: %s", error.message);
+ }
+ }
+
// TrackableContainer virtual function implementations:
protected async void add_child (MediaObject object) {
try {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]