From 839d709b1ba4a3312942fd2343ec37b32ea7fd3d Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Tue, 11 Jan 2011 17:11:36 +0200 Subject: [PATCH] core,plugins: MS plugin constructor takes root container Instead of expecting inheriting classes of MediaServerPlugin to implement get_root_container method, require the root container to be passed to the construction method. This also fixes the issue of external plugin accessing uninitialized fields. --- .../external/rygel-external-plugin-factory.vala | 23 +++++++----- src/plugins/external/rygel-external-plugin.vala | 41 ++++++---------------- .../gst-launch/rygel-gst-launch-plugin.vala | 6 ++-- .../media-export/rygel-media-export-plugin.vala | 29 +++++++-------- .../rygel-media-export-root-container.vala | 2 +- src/plugins/mediathek/rygel-mediathek-plugin.vala | 6 +--- src/plugins/test/rygel-test-plugin.vala | 6 ++-- src/plugins/tracker/rygel-tracker-plugin.vala | 17 ++++----- src/rygel/rygel-content-directory.vala | 2 +- src/rygel/rygel-media-server-plugin.vala | 18 ++++++---- 10 files changed, 62 insertions(+), 88 deletions(-) diff --git a/src/plugins/external/rygel-external-plugin-factory.vala b/src/plugins/external/rygel-external-plugin-factory.vala index 4384a2b..fe315c4 100644 --- a/src/plugins/external/rygel-external-plugin-factory.vala +++ b/src/plugins/external/rygel-external-plugin-factory.vala @@ -151,13 +151,20 @@ public class Rygel.External.PluginFactory { var child_count = (uint) container_props.lookup ("ChildCount"); var searchable = (bool) container_props.lookup ("Searchable"); - var plugin = new External.Plugin (service_name, - title, - child_count, - searchable, - root_object, - icon); - - this.loader.add_plugin (plugin); + try { + var plugin = new External.Plugin (service_name, + title, + child_count, + searchable, + root_object, + icon); + + this.loader.add_plugin (plugin); + } catch (IOError err) { + critical ("Failed to create root container for '%s': %s. " + + "Ignoring", + service_name, + err.message); + } } } diff --git a/src/plugins/external/rygel-external-plugin.vala b/src/plugins/external/rygel-external-plugin.vala index 46bd71d..f01224c 100644 --- a/src/plugins/external/rygel-external-plugin.vala +++ b/src/plugins/external/rygel-external-plugin.vala @@ -25,45 +25,24 @@ using FreeDesktop; public class Rygel.External.Plugin : Rygel.MediaServerPlugin { - public string root_object; - - // Root container properties - public uint child_count; - public bool searchable; - public Plugin (string service_name, string title, uint child_count, bool searchable, string root_object, - IconInfo? icon) { - base (service_name, - title, - "Rygel External " + title); + IconInfo? icon) throws IOError { + var root_container = new Container ("0", + title, + child_count, + searchable, + service_name, + root_object, + null); + + base (root_container, service_name, "Rygel External " + title); - this.child_count = child_count; - this.searchable = searchable; - this.root_object = root_object; if (icon != null) { this.add_icon (icon); } } - - public override MediaContainer get_root_container () { - Container root_container = null; - - try { - root_container = new Container ("0", - this.title, - this.child_count, - this.searchable, - this.name, - this.root_object, - null); - } catch (IOError err) { - critical ("Failed to connect to session bus: %s", err.message); - } - - return root_container; - } } diff --git a/src/plugins/gst-launch/rygel-gst-launch-plugin.vala b/src/plugins/gst-launch/rygel-gst-launch-plugin.vala index c20aca6..aa90a25 100644 --- a/src/plugins/gst-launch/rygel-gst-launch-plugin.vala +++ b/src/plugins/gst-launch/rygel-gst-launch-plugin.vala @@ -31,10 +31,8 @@ public void module_init (PluginLoader loader) { public class Rygel.GstLaunch.Plugin : Rygel.MediaServerPlugin { public Plugin () { - base ("GstLaunch", "Gst Launch"); - } + var root_container = new RootContainer ("Gst Launch"); - public override MediaContainer get_root_container () { - return new RootContainer (this.title); + base (root_container, "GstLaunch"); } } diff --git a/src/plugins/media-export/rygel-media-export-plugin.vala b/src/plugins/media-export/rygel-media-export-plugin.vala index 9b0d94c..956c807 100644 --- a/src/plugins/media-export/rygel-media-export-plugin.vala +++ b/src/plugins/media-export/rygel-media-export-plugin.vala @@ -29,7 +29,17 @@ private const string OUR_PLUGIN = "MediaExport"; * */ public void module_init (PluginLoader loader) { - var plugin = new MediaExport.Plugin (); + MediaExport.Plugin plugin; + + try { + plugin = new MediaExport.Plugin (); + } catch (Error error) { + warning ("Failed to initialize plugin '%s': %s. Ignoring..", + OUR_PLUGIN, + error.message); + + return; + } Idle.add (() => { foreach (var loaded_plugin in loader.list_plugins ()) { @@ -74,20 +84,7 @@ public void on_plugin_available (Plugin plugin, Plugin our_plugin) { } public class Rygel.MediaExport.Plugin : Rygel.MediaServerPlugin { - public Plugin () { - base (OUR_PLUGIN, _("@REALNAME@'s media")); - } - - public override MediaContainer get_root_container () { - try { - return RootContainer.get_instance (); - } catch (Error error) { - warning ("Could not create root container: %s. " + - "Disabling plugin", - error.message); - this.active = false; - } - - return new NullContainer (); + public Plugin () throws Error { + base (RootContainer.get_instance (), OUR_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 deb15d2..5e5e053 100644 --- a/src/plugins/media-export/rygel-media-export-root-container.vala +++ b/src/plugins/media-export/rygel-media-export-root-container.vala @@ -318,7 +318,7 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer { private RootContainer () throws Error { var db = MediaCache.get_default (); - base (db, "0", "MediaExportRoot"); + base (db, "0", _("@REALNAME@'s media")); this.cancellable = new Cancellable (); this.harvester = new Harvester (this.cancellable); diff --git a/src/plugins/mediathek/rygel-mediathek-plugin.vala b/src/plugins/mediathek/rygel-mediathek-plugin.vala index 691803d..320d8ce 100644 --- a/src/plugins/mediathek/rygel-mediathek-plugin.vala +++ b/src/plugins/mediathek/rygel-mediathek-plugin.vala @@ -31,10 +31,6 @@ public void module_init (PluginLoader loader) { public class Rygel.Mediathek.Plugin : Rygel.MediaServerPlugin { public Plugin () { - base ("ZDFMediathek", "ZDF Mediathek"); - } - - public override MediaContainer get_root_container () { - return RootContainer.get_instance (); + base (RootContainer.get_instance (), "ZDFMediathek"); } } diff --git a/src/plugins/test/rygel-test-plugin.vala b/src/plugins/test/rygel-test-plugin.vala index bb5a7cd..6239bf7 100644 --- a/src/plugins/test/rygel-test-plugin.vala +++ b/src/plugins/test/rygel-test-plugin.vala @@ -33,10 +33,8 @@ public void module_init (PluginLoader loader) { public class Rygel.Test.Plugin : Rygel.MediaServerPlugin { public Plugin () { - base ("Test", "Test Streams"); - } + var root_container = new RootContainer ("Test Streams"); - public override MediaContainer get_root_container () { - return new RootContainer (this.title); + base (root_container, "Test"); } } diff --git a/src/plugins/tracker/rygel-tracker-plugin.vala b/src/plugins/tracker/rygel-tracker-plugin.vala index 08d2ab3..2d066b8 100644 --- a/src/plugins/tracker/rygel-tracker-plugin.vala +++ b/src/plugins/tracker/rygel-tracker-plugin.vala @@ -23,21 +23,16 @@ using Gee; public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin { - private static RootContainer root_container; + private static RootContainer root; public Plugin () { - base ("Tracker", - // @REALNAME@ is substituted for user's real name - // and it doesn't need translation. - _("@REALNAME@'s media")); - } - - public override MediaContainer get_root_container () { - if (root_container == null) { - root_container = new RootContainer (this.title); + // @REALNAME@ is substituted for user's real name and it + // doesn't need translation. + if (root == null) { + root = new RootContainer (_("@REALNAME@'s media")); } - return root_container; + base (root, "Tracker"); } } diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala index 1466ac1..5076878 100644 --- a/src/rygel/rygel-content-directory.vala +++ b/src/rygel/rygel-content-directory.vala @@ -71,7 +71,7 @@ internal class Rygel.ContentDirectory: Service { var plugin = this.root_device.resource_factory as MediaServerPlugin; - this.root_container = plugin.get_root_container (); + this.root_container = plugin.root_container; this.http_server = new HTTPServer (this, plugin.name); this.updated_containers = new ArrayList (); diff --git a/src/rygel/rygel-media-server-plugin.vala b/src/rygel/rygel-media-server-plugin.vala index 2090f08..0961eb5 100644 --- a/src/rygel/rygel-media-server-plugin.vala +++ b/src/rygel/rygel-media-server-plugin.vala @@ -25,10 +25,17 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin { private static const string MEDIA_SERVER_DESC_PATH = BuildConfig.DATA_DIR + "/xml/MediaServer2.xml"; - public MediaServerPlugin (string name, - string? title, - string? description = null) { - base (MEDIA_SERVER_DESC_PATH, name, title, description); + public MediaContainer root_container; + + public MediaServerPlugin (MediaContainer root_container, + string name, + string? description = null) { + base (MEDIA_SERVER_DESC_PATH, + name, + root_container.title, + description); + + this.root_container = root_container; // MediaServer implementations must implement ContentDirectory service var info = new ResourceInfo (ContentDirectory.UPNP_ID, @@ -50,7 +57,6 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin { typeof (MediaReceiverRegistrar)); this.add_resource (info); - var root_container = this.get_root_container (); if (root_container.child_count == 0) { debug ("Deactivating plugin '%s' until it provides content.", this.name); @@ -62,8 +68,6 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin { } } - public abstract MediaContainer get_root_container (); - private void on_container_updated (MediaContainer root_container, MediaContainer updated) { if (updated != root_container || updated.child_count == 0) { -- 2.7.4