[rygel] media-export: Make singleton getters non-throwing.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Make singleton getters non-throwing.
- Date: Mon, 11 Feb 2013 15:39:31 +0000 (UTC)
commit 77e85a0ca4253795a93f99d91d825aadc81a0a0f
Author: Krzesimir Nowak <krnowak openismus com>
Date: Mon Feb 11 15:52:15 2013 +0100
media-export: Make singleton getters non-throwing.
When loading a plugin we are ensuring that media cache could be
opened. If opening a database (or upgrading it) fail then plugin is
not loaded.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=692362
.../rygel-media-export-db-container.vala | 5 +--
.../rygel-media-export-dummy-container.vala | 7 +--
.../media-export/rygel-media-export-harvester.vala | 6 ++-
.../rygel-media-export-harvesting-task.vala | 14 +-----
.../rygel-media-export-media-cache.vala | 10 +++--
.../media-export/rygel-media-export-plugin.vala | 40 ++++++++++++-------
.../rygel-media-export-root-container.vala | 11 +++--
7 files changed, 48 insertions(+), 45 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index 28aec72..58c00e8 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -37,10 +37,7 @@ public class Rygel.MediaExport.DBContainer : MediaContainer,
public override void constructed () {
base.constructed ();
- try {
- this.media_db = MediaCache.get_default ();
- } catch (Error error) { }
-
+ this.media_db = MediaCache.get_default ();
this.search_classes = new ArrayList<string> ();
this.container_updated.connect ( () => {
this.child_count = this.count_children ();
diff --git a/src/plugins/media-export/rygel-media-export-dummy-container.vala b/src/plugins/media-export/rygel-media-export-dummy-container.vala
index 6329e44..ff8ca98 100644
--- a/src/plugins/media-export/rygel-media-export-dummy-container.vala
+++ b/src/plugins/media-export/rygel-media-export-dummy-container.vala
@@ -25,10 +25,7 @@ internal class Rygel.MediaExport.DummyContainer : TrackableDbContainer {
public DummyContainer (File file,
MediaContainer parent) {
- MediaCache cache = null;
- try {
- cache = MediaCache.get_default ();
- } catch (Error error) { }
+ var cache = MediaCache.get_default ();
base (MediaCache.get_id (file), file.get_basename ());
@@ -45,7 +42,7 @@ internal class Rygel.MediaExport.DummyContainer : TrackableDbContainer {
this.file = file;
this.uris.add (file.get_uri ());
try {
- this.children = MediaCache.get_default ().get_child_ids (this.id);
+ this.children = cache.get_child_ids (this.id);
this.child_count = this.children.size;
} catch (Error error) {
this.children = new ArrayList<string> ();
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index c882948..9fa5f0b 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -204,11 +204,13 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
debug ("%s is not eligible for extraction", file.get_uri ());
}
} catch (Error error) {
- warning (_("Failed to access media cache: %s"), error.message);
+ warning (_("Failed to query info of a file %s: %s"),
+ file.get_uri (),
+ error.message);
}
}
- private void on_file_removed (File file) throws Error {
+ private void on_file_removed (File file) {
var cache = MediaCache.get_default ();
if (this.extraction_grace_timers.has_key (file)) {
Source.remove (this.extraction_grace_timers[file]);
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 0044d05..a2e2e8f 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -64,15 +64,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
this.extractor = extractor;
this.origin = file;
this.parent = parent;
-
- try {
- this.cache = MediaCache.get_default ();
- } catch (Error error) {
- // This should not happen. As the harvesting tasks are created
- // long after the first call to get_default which - if fails -
- // will make the whole root-container creation fail
- assert_not_reached ();
- }
+ this.cache = MediaCache.get_default ();
this.extractor.extraction_done.connect (on_extracted_cb);
this.extractor.error.connect (on_extractor_error_cb);
@@ -376,13 +368,13 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
if (this.files.is_empty &&
!this.containers.is_empty ()) {
var container = this.containers.peek_head ();
+ var cache = MediaCache.get_default ();
try {
- var cache = MediaCache.get_default ();
if (cache.get_child_count (container.id) == 0) {
var parent = container.parent as TrackableContainer;
parent.remove_child_tracked.begin (container, () => {
try {
- MediaCache.get_default ().save_container (parent);
+ cache.save_container (parent);
} catch (Error error) { }
});
}
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 5b470eb..bfccc3d 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -71,12 +71,14 @@ public class Rygel.MediaExport.MediaCache : Object {
file.get_uri ());
}
- public static MediaCache get_default () throws Error {
- if (instance == null) {
- instance = new MediaCache ();
+ public static void ensure_exists () throws Error {
+ if (MediaCache.instance == null) {
+ MediaCache.instance = new MediaCache ();
}
+ }
- return instance;
+ public static MediaCache get_default () {
+ return MediaCache.instance;
}
// Public functions
diff --git a/src/plugins/media-export/rygel-media-export-plugin.vala b/src/plugins/media-export/rygel-media-export-plugin.vala
index c0b6972..977bf50 100644
--- a/src/plugins/media-export/rygel-media-export-plugin.vala
+++ b/src/plugins/media-export/rygel-media-export-plugin.vala
@@ -35,24 +35,31 @@ public void module_init (PluginLoader loader) {
return;
}
- // Instantiate the plugin object:
- var plugin = new MediaExport.Plugin ();
+ try {
+ // Instantiate the plugin object (it may fail if loading
+ // database did not succeed):
+ var plugin = new MediaExport.Plugin ();
- // Check what other plugins are loaded,
- // and check when other plugins are loaded later:
- Idle.add (() => {
- foreach (var loaded_plugin in loader.list_plugins ()) {
- on_plugin_available (loaded_plugin, plugin);
- }
+ // Check what other plugins are loaded,
+ // and check when other plugins are loaded later:
+ Idle.add (() => {
+ foreach (var loaded_plugin in loader.list_plugins ()) {
+ on_plugin_available (loaded_plugin, plugin);
+ }
- loader.plugin_available.connect ((new_plugin) => {
- on_plugin_available (new_plugin, plugin);
- });
+ loader.plugin_available.connect ((new_plugin) => {
+ on_plugin_available (new_plugin, plugin);
+ });
- return false;
- });
+ return false;
+ });
- loader.add_plugin (plugin);
+ loader.add_plugin (plugin);
+ } catch (Error error) {
+ warning ("Failed to load %s: %s",
+ MediaExport.Plugin.NAME,
+ error.message);
+ }
}
public void on_plugin_available (Plugin plugin, Plugin our_plugin) {
@@ -108,7 +115,10 @@ public class Rygel.MediaExport.Plugin : Rygel.MediaServerPlugin {
/**
* Instantiate the plugin.
*/
- public Plugin () {
+ public Plugin () throws Error {
+ // Ensure that root container could be created and thus
+ // database could be opened:
+ RootContainer.ensure_exists ();
// Call the base constructor,
// passing the instance of our root container.
base (RootContainer.get_instance (),
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 f54a934..66925e7 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -60,14 +60,17 @@ public class Rygel.MediaExport.RootContainer : TrackableDbContainer {
Rygel.MusicItem.UPNP_CLASS +
",";
+ public static void ensure_exists () throws Error {
+ if (RootContainer.instance == null) {
+ MediaCache.ensure_exists ();
+ RootContainer.instance = new RootContainer ();
+ }
+ }
+
/**
* Get the single instance of the root container.
*/
public static MediaContainer get_instance () {
- if (RootContainer.instance == null) {
- RootContainer.instance = new RootContainer ();
- }
-
return RootContainer.instance;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]