[rygel] media-export: Disable plugin if error while init
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Disable plugin if error while init
- Date: Sun, 28 Nov 2010 19:38:06 +0000 (UTC)
commit de58de51650832802b7c344ca692e7b163898534
Author: Jens Georg <mail jensge org>
Date: Sun Oct 24 00:48:33 2010 +0200
media-export: Disable plugin if error while init
If there's a problem reading the database e.g. disable plugin right
away
.../rygel-media-export-object-factory.vala | 7 ++++++-
.../media-export/rygel-media-export-plugin.vala | 11 ++++++++++-
.../rygel-media-export-root-container.vala | 10 ++++++++--
3 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-object-factory.vala b/src/plugins/media-export/rygel-media-export-object-factory.vala
index a1a62dc..ce34bd4 100644
--- a/src/plugins/media-export/rygel-media-export-object-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-object-factory.vala
@@ -33,7 +33,12 @@ internal class Rygel.MediaExport.ObjectFactory : Object {
string title,
uint child_count) {
if (id == "0") {
- return RootContainer.get_instance () as DBContainer;
+ try {
+ return RootContainer.get_instance () as DBContainer;
+ } catch (Error error) {
+ // Must not fail - plugin is disabled if this fails
+ assert_not_reached ();
+ }
} else if (id.has_prefix (QueryContainer.PREFIX)) {
return new QueryContainer (media_db, id, title);
} else {
diff --git a/src/plugins/media-export/rygel-media-export-plugin.vala b/src/plugins/media-export/rygel-media-export-plugin.vala
index 37ef684..de3087a 100644
--- a/src/plugins/media-export/rygel-media-export-plugin.vala
+++ b/src/plugins/media-export/rygel-media-export-plugin.vala
@@ -79,6 +79,15 @@ public class Rygel.MediaExport.Plugin : Rygel.MediaServerPlugin {
}
public override MediaContainer? get_root_container (GUPnP.Context context) {
- return RootContainer.get_instance ();
+ try {
+ return RootContainer.get_instance ();
+ } catch (Error error) {
+ warning ("Could not create root container: %s. " +
+ "Disabling plugin",
+ error.message);
+ this.available = false;
+ }
+
+ return new NullContainer ();
}
}
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 ffea4cd..deb15d2 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -47,17 +47,23 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
private MediaContainer filesystem_container;
private static MediaContainer instance = null;
+ private static Error creation_error = null;
internal const string FILESYSTEM_FOLDER_NAME = "Files & Folders";
internal const string FILESYSTEM_FOLDER_ID = "Filesystem";
- public static MediaContainer get_instance () {
+ public static MediaContainer get_instance () throws Error {
if (RootContainer.instance == null) {
try {
RootContainer.instance = new RootContainer ();
} catch (Error error) {
- warning (_("Failed to create instance of database"));
+ // cache error for further calls and create Null container
RootContainer.instance = new NullContainer ();
+ RootContainer.creation_error = error;
+ }
+ } else {
+ if (creation_error != null) {
+ throw creation_error;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]