[rygel] media-export: Implement a cancel-everything
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Implement a cancel-everything
- Date: Sat, 14 Aug 2010 23:32:51 +0000 (UTC)
commit d14f0543f689969efd370aca6c9193c65d9f5cce
Author: Jens Georg <mail jensge org>
Date: Sat Aug 14 12:31:32 2010 +0300
media-export: Implement a cancel-everything
.../media-export/rygel-media-export-harvester.vala | 14 ++++++++------
.../rygel-media-export-harvesting-task.vala | 8 +++++++-
.../media-export/rygel-media-export-plugin.vala | 10 ++++++++++
.../rygel-media-export-root-container.vala | 10 ++++++++--
4 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 62c540c..243e6b2 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -28,16 +28,17 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
private MetadataExtractor extractor;
private RecursiveFileMonitor monitor;
private Regex file_filter;
+ private Cancellable cancellable;
/**
* Create a new instance of the meta-data extraction manager.
*/
- public Harvester () {
+ public Harvester (Cancellable cancellable) {
+ this.cancellable = cancellable;
this.extractor = new MetadataExtractor ();
- this.monitor = new RecursiveFileMonitor (null);
- if (this.monitor != null) {
- this.monitor.changed.connect (this.on_file_changed);
- }
+
+ this.monitor = new RecursiveFileMonitor (cancellable);
+ this.monitor.changed.connect (this.on_file_changed);
this.tasks = new HashMap<File, HarvestingTask> (file_hash, file_equal);
this.create_file_filter ();
@@ -68,6 +69,7 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
file,
parent,
flag);
+ task.cancellable = this.cancellable;
task.completed.connect (this.on_file_harvested);
this.tasks[file] = task;
task.run ();
@@ -83,7 +85,7 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
var task = this.tasks[file];
task.completed.disconnect (this.on_file_harvested);
this.tasks.unset (file);
- task.cancellable.cancel ();
+ task.cancel ();
}
}
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 c0f1da7..8652643 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -67,11 +67,17 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine, GLib.Object
this.files = new LinkedList<File> ();
this.containers = new GLib.Queue<MediaContainer> ();
this.monitor = monitor;
- this.cancellable = new Cancellable ();
this.flag = flag;
this.file_filter = file_filter;
}
+ public void cancel () {
+ // detach from common cancellable; otherwise everything would be
+ // cancelled like file monitoring, other harvesters etc.
+ this.cancellable = new Cancellable ();
+ this.cancellable.cancel ();
+ }
+
/**
* Extract all metainformation from a given file.
*
diff --git a/src/plugins/media-export/rygel-media-export-plugin.vala b/src/plugins/media-export/rygel-media-export-plugin.vala
index efee996..37ef684 100644
--- a/src/plugins/media-export/rygel-media-export-plugin.vala
+++ b/src/plugins/media-export/rygel-media-export-plugin.vala
@@ -53,6 +53,16 @@ public void on_plugin_available (Plugin plugin, Plugin our_plugin) {
message ("Disabling plugin '%s' in favor of plugin '%s'",
OUR_PLUGIN,
TRACKER_PLUGIN);
+ try {
+ var config = MetaConfig.get_default ();
+ var enabled = config.get_bool ("MediaExport", "enabled");
+ if (enabled) {
+ var root = Rygel.MediaExport.RootContainer.get_instance ()
+ as Rygel.MediaExport.RootContainer;
+
+ root.shutdown ();
+ }
+ } catch (Error error) {};
} else {
message ("Plugin '%s' disabled, enabling '%s' plugin",
TRACKER_PLUGIN,
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 46fb2a7..03eac11 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -42,7 +42,8 @@ const Rygel.MediaExport.FolderDefinition[] virtual_folders_music = {
*/
public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
private DBusService service;
- private Harvester harvester;
+ private Harvester harvester;
+ private Cancellable cancellable;
private static MediaContainer instance = null;
@@ -59,6 +60,10 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
return RootContainer.instance;
}
+ public void shutdown () {
+ this.cancellable.cancel ();
+ }
+
// DBus utility methods
public void add_uri (string uri) {
@@ -278,7 +283,8 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
base (db, "0", "MediaExportRoot");
- this.harvester = new Harvester ();
+ this.cancellable = new Cancellable ();
+ this.harvester = new Harvester (this.cancellable);
try {
this.service = new DBusService (this);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]