core,plugin: Simplify MediaServer implementation
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sun, 1 Aug 2010 01:26:14 +0000 (04:26 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sun, 1 Aug 2010 01:26:14 +0000 (04:26 +0300)
We no longer require plugins to provide a ContentDirectory service but
instead they need to always subclass Plugin class and implement it's
'get_root_container' method.

16 files changed:
src/plugins/external/Makefile.am
src/plugins/external/rygel-external-content-dir.vala [deleted file]
src/plugins/external/rygel-external-plugin.vala
src/plugins/gst-launch/Makefile.am
src/plugins/gst-launch/rygel-gst-launch-content-dir.vala [deleted file]
src/plugins/gst-launch/rygel-gst-launch-plugin.vala
src/plugins/media-export/rygel-media-export-plugin.vala
src/plugins/mediathek/rygel-mediathek-plugin.vala
src/plugins/test/Makefile.am
src/plugins/test/rygel-test-content-dir.vala [deleted file]
src/plugins/test/rygel-test-plugin.vala
src/plugins/tracker/Makefile.am
src/plugins/tracker/rygel-tracker-content-directory.vala [deleted file]
src/plugins/tracker/rygel-tracker-plugin.vala
src/rygel/rygel-content-directory.vala
src/rygel/rygel-media-server-plugin.vala

index 1307c11..397f888 100644 (file)
@@ -17,8 +17,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
            -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(shareddir)"' \
            -include config.h
 
-librygel_external_la_SOURCES = rygel-external-content-dir.vala \
-                              rygel-external-container.vala \
+librygel_external_la_SOURCES = rygel-external-container.vala \
                               rygel-external-dummy-container.vala \
                               rygel-external-item-factory.vala \
                               rygel-external-thumbnail-factory.vala \
diff --git a/src/plugins/external/rygel-external-content-dir.vala b/src/plugins/external/rygel-external-content-dir.vala
deleted file mode 100644 (file)
index 98b5031..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
- * Copyright (C) 2009,2010 Nokia Corporation.
- *
- * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
- *                               <zeeshan.ali@nokia.com>
- *
- * This file is part of Rygel.
- *
- * Rygel is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Rygel is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using GUPnP;
-using DBus;
-using Gee;
-
-/**
- * Implementation of External ContentDirectory service.
- */
-public class Rygel.External.ContentDir : Rygel.ContentDirectory {
-    // Pubic methods
-    public override MediaContainer? create_root_container () {
-        var plugin = (External.Plugin) this.root_device.resource_factory;
-
-        return new Container ("0",
-                              plugin.title,
-                              plugin.child_count,
-                              plugin.searchable,
-                              plugin.service_name,
-                              plugin.root_object,
-                              this.context.host_ip,
-                              null);
-    }
-}
-
index 6078fb0..c9539cd 100644 (file)
@@ -40,7 +40,6 @@ public class Rygel.External.Plugin : Rygel.MediaServerPlugin {
                    IconInfo? icon) {
         base (service_name,
               title,
-              typeof (ContentDir),
               "Rygel External " + title);
 
         this.service_name = service_name;
@@ -51,4 +50,16 @@ public class Rygel.External.Plugin : Rygel.MediaServerPlugin {
             this.add_icon (icon);
         }
     }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
+        return new Container ("0",
+                              this.title,
+                              this.child_count,
+                              this.searchable,
+                              this.service_name,
+                              this.root_object,
+                              content_dir.context.host_ip,
+                              null);
+    }
 }
index a512eac..575d925 100644 (file)
@@ -14,7 +14,6 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
 
 librygel_gst_launch_la_SOURCES = rygel-gst-launch-plugin.vala \
                                rygel-gst-launch-root-container.vala \
-                               rygel-gst-launch-content-dir.vala \
                                rygel-gst-launch-item.vala
 
 librygel_gst_launch_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \
diff --git a/src/plugins/gst-launch/rygel-gst-launch-content-dir.vala b/src/plugins/gst-launch/rygel-gst-launch-content-dir.vala
deleted file mode 100644 (file)
index 34686c3..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 Thijs Vermeir <thijsvermeir@gmail.com>
- *
- * Author: Thijs Vermeir <thijsvermeir@gmail.com>
- *
- * This file is part of Rygel.
- *
- * Rygel is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Rygel is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using Rygel;
-using GUPnP;
-using Gee;
-
-public class Rygel.GstLaunch.ContentDir : ContentDirectory {
-    /* Pubic methods */
-    public override MediaContainer? create_root_container () {
-        string friendly_name = this.root_device.get_friendly_name ();
-        return new RootContainer (friendly_name);
-    }
-}
-
index 471653a..10a59b3 100644 (file)
@@ -24,9 +24,18 @@ using Rygel;
 using Gee;
 
 public void module_init (PluginLoader loader) {
-    var plugin = new MediaServerPlugin ("GstLaunch",
-                                        "Gst Launch",
-                                        typeof (GstLaunch.ContentDir));
+    var plugin = new GstLaunch.Plugin ();
+
     loader.add_plugin (plugin);
 }
 
+public class Rygel.GstLaunch.Plugin : Rygel.MediaServerPlugin {
+    public Plugin () {
+        base ("GstLaunch", "Gst Launch");
+    }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
+        return new RootContainer (this.title);
+    }
+}
index 26ca5ea..5e93017 100644 (file)
@@ -28,14 +28,18 @@ using GLib;
  *
  */
 public void module_init (PluginLoader loader) {
-    var plugin = new MediaServerPlugin ("MediaExport",
-                                        _("@REALNAME@'s media"),
-                                        typeof (Rygel.MediaExport.ContentDir));
+    var plugin = new MediaExport.Plugin ();
+
     loader.add_plugin (plugin);
 }
 
-public class Rygel.MediaExport.ContentDir : ContentDirectory {
-    public override MediaContainer? create_root_container () {
+public class Rygel.MediaExport.Plugin : Rygel.MediaServerPlugin {
+    public Plugin () {
+        base ("MediaExport", _("@REALNAME@'s media"));
+    }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
         return RootContainer.get_instance ();
     }
 }
index 4b9c22e..86f7da2 100644 (file)
@@ -24,15 +24,18 @@ using Rygel;
 using GUPnP;
 
 public void module_init (PluginLoader loader) {
-    var plugin = new MediaServerPlugin ("ZDFMediathek",
-                                        "ZDF Mediathek",
-                                        typeof (Mediathek.ContentDir));
+    var plugin = new Mediathek.Plugin ();
+
     loader.add_plugin (plugin);
 }
 
-public class Rygel.Mediathek.ContentDir : ContentDirectory {
-    public override MediaContainer? create_root_container () {
+public class Rygel.Mediathek.Plugin : Rygel.MediaServerPlugin {
+    public Plugin () {
+        base ("ZDFMediathek", "ZDF Mediathek");
+    }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
         return RootContainer.get_instance ();
     }
 }
-
index 9c6078b..77e6fae 100644 (file)
@@ -17,8 +17,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
            -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(shareddir)"' \
            -include config.h
 
-librygel_test_la_SOURCES = rygel-test-content-dir.vala \
-                          rygel-test-root-container.vala \
+librygel_test_la_SOURCES = rygel-test-root-container.vala \
                           rygel-test-item.vala \
                           rygel-test-audio-item.vala \
                           rygel-test-video-item.vala \
diff --git a/src/plugins/test/rygel-test-content-dir.vala b/src/plugins/test/rygel-test-content-dir.vala
deleted file mode 100644 (file)
index 2aac724..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
- * Copyright (C) 2008 Nokia Corporation.
- *
- * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
- *                               <zeeshan.ali@nokia.com>
- *
- * This file is part of Rygel.
- *
- * Rygel is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Rygel is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using GUPnP;
-using Gee;
-
-/**
- * Implementation of ContentDirectory service, meant for testing purposes only.
- */
-public class Rygel.Test.ContentDir : Rygel.ContentDirectory {
-    /* Pubic methods */
-    public override MediaContainer? create_root_container () {
-        string friendly_name = this.root_device.get_friendly_name ();
-        return new RootContainer (friendly_name);
-    }
-}
-
index 9a02d07..ad57e66 100644 (file)
@@ -26,9 +26,18 @@ using Rygel;
 using Gee;
 
 public void module_init (PluginLoader loader) {
-    var plugin = new MediaServerPlugin("Test",
-                                       "Test Streams",
-                                       typeof (Rygel.Test.ContentDir));
+    var plugin = new Rygel.Test.Plugin ();
+
     loader.add_plugin (plugin);
 }
 
+public class Rygel.Test.Plugin : Rygel.MediaServerPlugin {
+    public Plugin () {
+        base ("Test", "Test Streams");
+    }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
+        return new RootContainer (this.title);
+    }
+}
index b6adfbc..315e6e4 100644 (file)
@@ -11,9 +11,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
            -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(datadir)"' \
            -include config.h
 
-librygel_media_tracker_la_SOURCES = \
-                                   rygel-tracker-content-directory.vala \
-                                   rygel-tracker-root-container.vala \
+librygel_media_tracker_la_SOURCES = rygel-tracker-root-container.vala \
                                    rygel-tracker-category-container.vala \
                                    rygel-tracker-music.vala \
                                    rygel-tracker-videos.vala \
diff --git a/src/plugins/tracker/rygel-tracker-content-directory.vala b/src/plugins/tracker/rygel-tracker-content-directory.vala
deleted file mode 100644 (file)
index 5520f49..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
- * Copyright (C) 2008,2010 Nokia Corporation.
- *
- * Author: Zeeshan Ali <zeenix@gmail.com>
- *
- * This file is part of Rygel.
- *
- * Rygel is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Rygel is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using GUPnP;
-using DBus;
-using Gee;
-
-/**
- * Implementation of Tracker-based ContentDirectory service.
- */
-public class Rygel.Tracker.ContentDirectory : Rygel.ContentDirectory {
-    /* Pubic methods */
-    public override MediaContainer? create_root_container () {
-        string friendly_name = this.root_device.get_friendly_name ();
-        return new RootContainer (friendly_name);
-    }
-}
-
index d65aa47..b31f4a2 100644 (file)
@@ -31,8 +31,7 @@ public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
         base ("Tracker",
               // @REALNAME@ is substituted for user's real name
               // and it doesn't need translation.
-              _("@REALNAME@'s media"),
-              typeof (Tracker.ContentDirectory));
+              _("@REALNAME@'s media"));
 
         var icon_info = new IconInfo ("image/png");
 
@@ -47,5 +46,10 @@ public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
             warning (_("Error creating URI from %s: %s"), ICON, err.message);
         }
     }
+
+    public override MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
+        return new RootContainer (this.title);
+    }
 }
 
index 46c7edf..fc13591 100644 (file)
@@ -66,15 +66,9 @@ public class Rygel.ContentDirectory: Service {
 
     public uint32 system_update_id;
 
-    // Public abstract methods derived classes need to implement
-    public virtual MediaContainer? create_root_container () {
-       return null;
-    }
-
     public override void constructed () {
         this.cancellable = new Cancellable ();
-
-        this.root_container = this.create_root_container ();
+        this.root_container = this.get_root_container ();
 
         try {
             this.http_server = new HTTPServer (this, this.get_type ().name ());
@@ -138,6 +132,12 @@ public class Rygel.ContentDirectory: Service {
         this.http_server.run.begin ();
     }
 
+    private MediaContainer get_root_container () {
+        var plugin = this.root_device.resource_factory as MediaServerPlugin;
+
+        return plugin.get_root_container (this);
+    }
+
     ~ContentDirectory () {
         // Cancel all state machines
         this.cancellable.cancel ();
index 73aa103..9aa10bf 100644 (file)
@@ -27,7 +27,6 @@ public class Rygel.MediaServerPlugin : Rygel.Plugin {
 
     public MediaServerPlugin (string  name,
                               string? title,
-                              Type    content_dir_type,
                               string? description = null) {
         base (MEDIA_SERVER_DESC_PATH, name, title, description);
 
@@ -35,7 +34,7 @@ public class Rygel.MediaServerPlugin : Rygel.Plugin {
         var resource_info = new ResourceInfo (ContentDirectory.UPNP_ID,
                                               ContentDirectory.UPNP_TYPE,
                                               ContentDirectory.DESCRIPTION_PATH,
-                                              content_dir_type);
+                                              typeof (ContentDirectory));
         this.add_resource (resource_info);
 
         // Register Rygel.ConnectionManager
@@ -52,5 +51,10 @@ public class Rygel.MediaServerPlugin : Rygel.Plugin {
                                         typeof (MediaReceiverRegistrar));
         this.add_resource (resource_info);
     }
+
+    public virtual MediaContainer? get_root_container (
+                                        ContentDirectory content_dir) {
+        return null;
+    }
 }