[rygel] core,renderer: Extract base class for libraries
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,renderer: Extract base class for libraries
- Date: Fri, 27 Jul 2012 20:34:03 +0000 (UTC)
commit 69d5e24422b5de98b84464450f065b797d4dff2b
Author: Jens Georg <mail jensge org>
Date: Mon Jul 9 20:49:29 2012 +0200
core,renderer: Extract base class for libraries
https://bugzilla.gnome.org/show_bug.cgi?id=679648
examples/standalone-renderer.c | 4 +-
src/librygel-core/filelist.am | 1 +
src/librygel-core/rygel-media-device.vala | 131 +++++++++++++++++++++
src/librygel-renderer/rygel-playbin-renderer.vala | 105 +----------------
4 files changed, 137 insertions(+), 104 deletions(-)
---
diff --git a/examples/standalone-renderer.c b/examples/standalone-renderer.c
index f9f5201..61bb3a7 100644
--- a/examples/standalone-renderer.c
+++ b/examples/standalone-renderer.c
@@ -68,9 +68,9 @@ int main(int argc, char *argv[])
NULL);
if (argc >= 2) {
- rygel_playbin_renderer_add_interface (renderer, argv[1]);
+ rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (renderer), argv[1]);
} else {
- rygel_playbin_renderer_add_interface (renderer, "eth0");
+ rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (renderer), "eth0");
}
loop = g_main_loop_new (NULL, FALSE);
diff --git a/src/librygel-core/filelist.am b/src/librygel-core/filelist.am
index a61c4f3..6eba487 100644
--- a/src/librygel-core/filelist.am
+++ b/src/librygel-core/filelist.am
@@ -24,6 +24,7 @@ LIBRYGEL_CORE_VAPI_SOURCE_FILES = \
rygel-user-config.vala \
rygel-video-item.vala \
rygel-media-container.vala \
+ rygel-media-device.vala \
rygel-media-item.vala \
rygel-media-object.vala \
rygel-media-server-plugin.vala \
diff --git a/src/librygel-core/rygel-media-device.vala b/src/librygel-core/rygel-media-device.vala
new file mode 100644
index 0000000..e0d3b98
--- /dev/null
+++ b/src/librygel-core/rygel-media-device.vala
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH.
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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 Gee;
+using GUPnP;
+
+internal class Rygel.DeviceContext {
+ public RootDevice device;
+ public RootDeviceFactory factory;
+ public Context context;
+
+ public DeviceContext (Context context, Rygel.Plugin plugin) throws Error {
+ this.context = context;
+ this.factory = new RootDeviceFactory (context);
+ this.device = this.factory.create (plugin);
+ this.device.available = true;
+ }
+}
+
+public abstract class Rygel.MediaDevice : Object {
+ private ArrayList<string> interfaces;
+ private HashMap<string, Context> contexts;
+ private HashMap<string, DeviceContext> devices;
+ private ContextManager manager;
+
+ protected Rygel.Plugin plugin { get; protected set; }
+
+ public MediaDevice () {
+ this.manager = ContextManager.create (0);
+ this.manager.context_available.connect (this.on_context_available);
+ this.manager.context_unavailable.connect (this.on_context_unavailable);
+ this.interfaces = new ArrayList<string> ();
+ this.contexts = new HashMap<string, Context> ();
+ this.devices = new HashMap<string, DeviceContext> ();
+ }
+
+ /**
+ * Add a network interface the device should listen on.
+ *
+ * If the network interface is not already up, it will be used as soon as
+ * it's ready, otherwise it's used right away.
+ *
+ * @param iface Name of the network interface, e.g. eth0
+ */
+ public void add_interface (string iface) {
+ if (!(iface in this.interfaces)) {
+ this.interfaces.add (iface);
+
+ // Check if we already have a context for this, then enable the
+ // device right away
+ if (iface in this.contexts.keys) {
+ this.on_context_available (this.contexts[iface]);
+ }
+ }
+ }
+
+ /**
+ * Remove a previously added network interface from the device.
+ *
+ * @param iface Name of the network interface, e.g. eth0
+ */
+ public void remove_interface (string iface) {
+ if (!(iface in this.interfaces)) {
+ return;
+ }
+
+ this.interfaces.remove (iface);
+
+ if (iface in this.devices.keys) {
+ this.contexts[iface] = this.devices[iface].context;
+ this.devices.unset (iface);
+ }
+ }
+
+ /**
+ * Get a list of the network interfaces the device is currently allowed
+ * to use.
+ *
+ * @return list of interface names.
+ */
+ public GLib.List<string> get_interfaces () {
+ GLib.List<string> result = null;
+
+ foreach (var iface in this.interfaces) {
+ result.prepend (iface);
+ }
+
+ result.reverse ();
+
+ return result;
+ }
+
+ private void on_context_available (Context context) {
+ if (context.interface in this.interfaces) {
+ try {
+ var ctx = new DeviceContext (context, this.plugin);
+ this.devices[context.interface] = ctx;
+ } catch (Error error) {
+ warning ("Failed to create device context: %s",
+ error.message);
+ }
+ } else {
+ this.contexts[context.interface] = context;
+ }
+ }
+
+ private void on_context_unavailable (Context context) {
+ if (context.interface in this.devices.keys) {
+ this.devices.unset (context.interface);
+ } else {
+ this.contexts.unset (context.interface);
+ }
+ }
+}
diff --git a/src/librygel-renderer/rygel-playbin-renderer.vala b/src/librygel-renderer/rygel-playbin-renderer.vala
index 3c99705..dd81780 100644
--- a/src/librygel-renderer/rygel-playbin-renderer.vala
+++ b/src/librygel-renderer/rygel-playbin-renderer.vala
@@ -21,19 +21,6 @@
using Gee;
using GUPnP;
-internal class Rygel.Playbin.RendererContext {
- public RootDevice device;
- public RootDeviceFactory factory;
- public Context context;
-
- public RendererContext (Context context, MediaRendererPlugin plugin) throws Error {
- this.context = context;
- this.factory = new RootDeviceFactory (context);
- this.device = this.factory.create (plugin);
- this.device.available = true;
- }
-}
-
internal class Rygel.Playbin.WrappingPlugin : Rygel.MediaRendererPlugin {
private MediaPlayer player;
@@ -56,13 +43,7 @@ internal class Rygel.Playbin.WrappingPlugin : Rygel.MediaRendererPlugin {
*
* Likewise the playbin can be modified externally using UPnP.
*/
-public class Rygel.Playbin.Renderer : Object {
- private ArrayList<string> interfaces;
- private HashMap<string, Context> contexts;
- private HashMap<string, RendererContext> renderer;
- private ContextManager manager;
- private MediaRendererPlugin plugin;
-
+public class Rygel.Playbin.Renderer : Rygel.MediaDevice {
/**
* Create a new instance of Renderer.
*
@@ -72,6 +53,7 @@ public class Rygel.Playbin.Renderer : Object {
* @param title Friendly name of the new UPnP renderer on the network.
*/
public Renderer (string title) {
+ base ();
this.plugin = new Plugin ();
this.prepare_upnp (title);
}
@@ -84,93 +66,12 @@ public class Rygel.Playbin.Renderer : Object {
* @param title Friendly name of the new UPnP renderer on the network.
*/
public Renderer.wrap (Gst.Element pipeline, string title) {
+ base ();
this.plugin = new WrappingPlugin (pipeline);
this.prepare_upnp (title);
}
- /**
- * Add a network interface the renderer should listen on.
- *
- * If the network interface is not already up, it will be used as soon as
- * it's ready, otherwise it's used right away.
- *
- * @param iface Name of the network interface, e.g. eth0
- */
- public void add_interface (string iface) {
- if (!(iface in this.interfaces)) {
- this.interfaces.add (iface);
-
- // Check if we already have a context for this, then enable the
- // device right away
- if (iface in this.contexts.keys) {
- this.on_context_available (this.contexts[iface]);
- }
- }
- }
-
- /**
- * Remove a previously added network interface from the renderer.
- *
- * @param iface Name of the network interface, e.g. eth0
- */
- public void remove_interface (string iface) {
- if (!(iface in this.interfaces)) {
- return;
- }
-
- this.interfaces.remove (iface);
-
- if (iface in this.contexts.keys) {
- // Sleeping context; remove the context and we're done.
- this.contexts.unset (iface);
- } else if (iface in this.renderer.keys) {
- this.renderer.unset (iface);
- }
- }
-
- /**
- * Get a list of the network interfaces the renderer is currently allowed
- * to use.
- *
- * @return list of interface names.
- */
- public GLib.List<string> get_interfaces () {
- GLib.List<string> result = null;
-
- foreach (var iface in this.interfaces) {
- result.prepend (iface);
- }
-
- result.reverse ();
-
- return result;
- }
-
- private void on_context_available (Context context) {
- if (context.interface in this.interfaces) {
- try {
- var ctx = new RendererContext (context, this.plugin);
- this.renderer[context.interface] = ctx;
- } catch (Error error) {
- warning ("Failed to create renderer context: %s",
- error.message);
- }
- } else {
- this.contexts[context.interface] = context;
- }
- }
-
- private void on_context_unavailable (Context context) {
- this.remove_interface (context.interface);
- }
-
private void prepare_upnp (string title) {
- this.manager = ContextManager.create (0);
- this.manager.context_available.connect (this.on_context_available);
- this.manager.context_unavailable.connect (this.on_context_unavailable);
- this.interfaces = new ArrayList<string> ();
- this.contexts = new HashMap<string, Context> ();
- this.renderer = new HashMap<string, RendererContext> ();
this.plugin.title = title;
// Always listen on localhost
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]