From: Zeeshan Ali (Khattak) Date: Wed, 28 Jan 2009 12:34:13 +0000 (+0000) Subject: Separate class for DVB's root container. X-Git-Tag: RYGEL_0_2_2~134 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=787ffec95f581a1e4a1ffa4fa14b9e901ee3627a;p=profile%2Fivi%2Frygel.git Separate class for DVB's root container. Most implementation is now in this class rather than DVBContentDirectory. svn path=/trunk/; revision=509 --- diff --git a/src/plugins/dvb/Makefile.am b/src/plugins/dvb/Makefile.am index f614c0f..d6395fa 100644 --- a/src/plugins/dvb/Makefile.am +++ b/src/plugins/dvb/Makefile.am @@ -12,6 +12,8 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ BUILT_SOURCES = rygel-dvb.stamp \ rygel-dvb-content-dir.h \ rygel-dvb-content-dir.c \ + rygel-dvb-root-container.h \ + rygel-dvb-root-container.c \ rygel-dvb-channel-group.h \ rygel-dvb-channel-group.c \ rygel-dvb-channel.h \ @@ -22,6 +24,9 @@ BUILT_SOURCES = rygel-dvb.stamp \ librygel_dvb_la_SOURCES = rygel-dvb-content-dir.h \ rygel-dvb-content-dir.c \ rygel-dvb-content-dir.vala \ + rygel-dvb-root-container.h \ + rygel-dvb-root-container.c \ + rygel-dvb-root-container.vala \ rygel-dvb-channel-group.h \ rygel-dvb-channel-group.c \ rygel-dvb-channel-group.vala \ diff --git a/src/plugins/dvb/rygel-dvb-content-dir.vala b/src/plugins/dvb/rygel-dvb-content-dir.vala index 1b6cadd..d54b6c2 100644 --- a/src/plugins/dvb/rygel-dvb-content-dir.vala +++ b/src/plugins/dvb/rygel-dvb-content-dir.vala @@ -31,83 +31,10 @@ using Gee; * Implementation of DVB ContentDirectory service. */ public class Rygel.DVBContentDir : ContentDirectory { - // class-wide constants - private const string DVB_SERVICE = "org.gnome.DVB"; - private const string MANAGER_PATH = "/org/gnome/DVB/Manager"; - private const string MANAGER_IFACE = "org.gnome.DVB.Manager"; - private const string CHANNEL_LIST_IFACE = "org.gnome.DVB.ChannelList"; - - public dynamic DBus.Object manager; - - private ArrayList groups; - // Pubic methods - public override void constructed () { - // Chain-up to base first - base.constructed (); - - DBus.Connection connection; - try { - connection = DBus.Bus.get (DBus.BusType.SESSION); - } catch (DBus.Error error) { - critical ("Failed to connect to Session bus: %s\n", - error.message); - return; - } - - this.groups = new ArrayList (); - - // Get a proxy to DVB Manager object - this.manager = connection.get_object (DVBContentDir.DVB_SERVICE, - DVBContentDir.MANAGER_PATH, - DVBContentDir.MANAGER_IFACE); - uint[] dev_groups = null; - - try { - dev_groups = this.manager.GetRegisteredDeviceGroups (); - } catch (GLib.Error error) { - critical ("error: %s", error.message); - return; - } - - foreach (uint group_id in dev_groups) { - string channel_list_path = null; - string group_name = null; - - try { - channel_list_path = manager.GetChannelList (group_id); - - // Get the name of the group - group_name = manager.GetDeviceGroupName (group_id); - } catch (GLib.Error error) { - critical ("error: %s", error.message); - return; - } - - // Get a proxy to DVB ChannelList object - dynamic DBus.Object channel_list = connection.get_object - (DVBContentDir.DVB_SERVICE, - channel_list_path, - DVBContentDir.CHANNEL_LIST_IFACE); - - // Create ChannelGroup for each registered device group - this.groups.add (new DVBChannelGroup (group_id, - group_name, - this.root_container.id, - channel_list, - this.http_server)); - } - } - public override MediaObject find_object_by_id (string object_id) throws GLib.Error { - // First try groups - MediaObject media_object = find_group_by_id (object_id); - - if (media_object == null) { - media_object = find_channel_by_id (object_id); - } - + var media_object = this.root_container.find_object_by_id (object_id); if (media_object == null) { throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } @@ -121,19 +48,20 @@ public class Rygel.DVBContentDir : ContentDirectory { uint max_count, out uint child_count) throws GLib.Error { - var group = this.find_group_by_id (container_id); - if (group == null) { + var media_object = this.find_object_by_id (container_id); + if (media_object == null || !(media_object is MediaContainer)) { throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } - var channels = group.get_children (offset, - max_count, - out child_count); - if (channels == null) { + var container = (MediaContainer) media_object; + var children = container.get_children (offset, + max_count, + out child_count); + if (children == null) { throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } - return channels; + return children; } public override Gee.List get_root_children ( @@ -141,19 +69,9 @@ public class Rygel.DVBContentDir : ContentDirectory { uint max_count, out uint child_count) throws GLib.Error { - child_count = this.groups.size; - - Gee.List children = null; - - if (max_count == 0) { - max_count = child_count; - } - - uint stop = offset + max_count; - - stop = stop.clamp (0, child_count); - children = this.groups.slice ((int) offset, (int) stop); - + var children = this.root_container.get_children (offset, + max_count, + out child_count); if (children == null) { throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } @@ -163,35 +81,7 @@ public class Rygel.DVBContentDir : ContentDirectory { public override MediaContainer? create_root_container () { string friendly_name = this.root_device.get_friendly_name (); - return new MediaContainer.root (friendly_name, 0); - } - - // Private methods - private DVBChannelGroup? find_group_by_id (string id) { - DVBChannelGroup group = null; - - foreach (DVBChannelGroup tmp in this.groups) { - if (id == tmp.id) { - group = tmp; - - break; - } - } - - return group; - } - - private MediaObject find_channel_by_id (string id) throws GLib.Error { - MediaObject channel = null; - - foreach (DVBChannelGroup group in this.groups) { - channel = group.find_object_by_id (id); - if (channel != null) { - break; - } - } - - return channel; + return new DVBRootContainer (friendly_name, this.http_server); } } diff --git a/src/plugins/dvb/rygel-dvb-root-container.vala b/src/plugins/dvb/rygel-dvb-root-container.vala new file mode 100644 index 0000000..8098c3e --- /dev/null +++ b/src/plugins/dvb/rygel-dvb-root-container.vala @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2008 Zeeshan Ali (Khattak) . + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * Author: Zeeshan Ali (Khattak) + * + * + * 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 DBus; +using Gee; + +/** + * Represents the root container for DVB media content hierarchy. + */ +public class Rygel.DVBRootContainer : MediaContainer { + // class-wide constants + private const string DVB_SERVICE = "org.gnome.DVB"; + private const string MANAGER_PATH = "/org/gnome/DVB/Manager"; + private const string MANAGER_IFACE = "org.gnome.DVB.Manager"; + private const string CHANNEL_LIST_IFACE = "org.gnome.DVB.ChannelList"; + + public dynamic DBus.Object manager; + + private ArrayList groups; + + public DVBRootContainer (string title, + HTTPServer http_server) { + base.root (title, 0); + + DBus.Connection connection; + try { + connection = DBus.Bus.get (DBus.BusType.SESSION); + } catch (DBus.Error error) { + critical ("Failed to connect to Session bus: %s\n", + error.message); + return; + } + + this.groups = new ArrayList (); + + // Get a proxy to DVB Manager object + this.manager = connection.get_object (DVBRootContainer.DVB_SERVICE, + DVBRootContainer.MANAGER_PATH, + DVBRootContainer.MANAGER_IFACE); + uint[] dev_groups = null; + + try { + dev_groups = this.manager.GetRegisteredDeviceGroups (); + } catch (GLib.Error error) { + critical ("error: %s", error.message); + return; + } + + foreach (uint group_id in dev_groups) { + string channel_list_path = null; + string group_name = null; + + try { + channel_list_path = manager.GetChannelList (group_id); + + // Get the name of the group + group_name = manager.GetDeviceGroupName (group_id); + } catch (GLib.Error error) { + critical ("error: %s", error.message); + return; + } + + // Get a proxy to DVB ChannelList object + dynamic DBus.Object channel_list = connection.get_object + (DVBRootContainer.DVB_SERVICE, + channel_list_path, + DVBRootContainer.CHANNEL_LIST_IFACE); + + // Create ChannelGroup for each registered device group + this.groups.add (new DVBChannelGroup (group_id, + group_name, + this.id, + channel_list, + http_server)); + } + } + + public override Gee.List get_children (uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { + child_count = this.groups.size; + + Gee.List children = null; + + if (max_count == 0) { + max_count = child_count; + } + + uint stop = offset + max_count; + + stop = stop.clamp (0, child_count); + children = this.groups.slice ((int) offset, (int) stop); + + return children; + } + + public override MediaObject find_object_by_id (string id) + throws GLib.Error { + // First try groups + MediaObject media_object = find_group_by_id (id); + + if (media_object == null) { + media_object = find_channel_by_id (id); + } + + return media_object; + } + + // Private methods + private DVBChannelGroup? find_group_by_id (string id) { + DVBChannelGroup group = null; + + foreach (DVBChannelGroup tmp in this.groups) { + if (id == tmp.id) { + group = tmp; + + break; + } + } + + return group; + } + + private MediaObject find_channel_by_id (string id) throws GLib.Error { + MediaObject channel = null; + + foreach (DVBChannelGroup group in this.groups) { + channel = group.find_object_by_id (id); + if (channel != null) { + break; + } + } + + return channel; + } +} +