diff options
author | Jens Georg <mail@jensge.org> | 2012-06-29 08:56:52 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2012-07-03 09:53:49 +0200 |
commit | 404b8b84a2f1314b884354413a5d3aeb120e1b26 (patch) | |
tree | 2caa93cf636319e71666d84bb5696e5572cfd67f /src | |
parent | 4bd3685d1411d8856e62d137c4742f6ea6696dcd (diff) | |
download | rygel-404b8b84a2f1314b884354413a5d3aeb120e1b26.tar.gz |
librenderer: Add simpler API
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/playbin/Makefile.am | 3 | ||||
-rw-r--r-- | src/plugins/playbin/rygel-playbin-renderer.vala | 114 |
2 files changed, 116 insertions, 1 deletions
diff --git a/src/plugins/playbin/Makefile.am b/src/plugins/playbin/Makefile.am index 76573992..5e85ee5b 100644 --- a/src/plugins/playbin/Makefile.am +++ b/src/plugins/playbin/Makefile.am @@ -4,7 +4,8 @@ lib_LTLIBRARIES = librygel-renderer.la librygel_renderer_la_SOURCES = \ rygel-playbin-player.vala \ - rygel-playbin-plugin.vala + rygel-playbin-plugin.vala \ + rygel-playbin-renderer.vala librygel_renderer_la_VALAFLAGS = \ -H rygel-renderer.h --library=rygel-renderer-1.0 \ diff --git a/src/plugins/playbin/rygel-playbin-renderer.vala b/src/plugins/playbin/rygel-playbin-renderer.vala new file mode 100644 index 00000000..44b8f4a1 --- /dev/null +++ b/src/plugins/playbin/rygel-playbin-renderer.vala @@ -0,0 +1,114 @@ +/* + * 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.Playbin.RendererContext { + public RootDevice device; + public RootDeviceFactory factory; + public Context context; + + public RendererContext (Context context, Plugin plugin) throws Error { + this.context = context; + this.factory = new RootDeviceFactory (context); + this.device = this.factory.create (plugin); + this.device.available = true; + } +} + +public class Rygel.Playbin.Renderer : Object { + private ArrayList<string> interfaces; + private HashMap<string, Context> contexts; + private HashMap<string, RendererContext> renderer; + private ContextManager manager; + private Plugin plugin; + + public Renderer (string title) { + manager = ContextManager.create (0); + manager.context_available.connect (this.on_context_available); + 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> (); + plugin = new Plugin (); + plugin.title = title; + + // Always listen on localhost + this.add_interface ("lo"); + } + + 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]); + } + } + } + + 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); + } + } + + 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); + } +} |