rygel r509 - trunk/src/plugins/dvb



Author: zeeshanak
Date: Wed Jan 28 12:34:13 2009
New Revision: 509
URL: http://svn.gnome.org/viewvc/rygel?rev=509&view=rev

Log:
Separate class for DVB's root container.

Most implementation is now in this class rather than DVBContentDirectory.

Added:
   trunk/src/plugins/dvb/rygel-dvb-root-container.vala
      - copied, changed from r508, /trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
Modified:
   trunk/src/plugins/dvb/Makefile.am
   trunk/src/plugins/dvb/rygel-dvb-content-dir.vala

Modified: trunk/src/plugins/dvb/Makefile.am
==============================================================================
--- trunk/src/plugins/dvb/Makefile.am	(original)
+++ trunk/src/plugins/dvb/Makefile.am	Wed Jan 28 12:34:13 2009
@@ -12,6 +12,8 @@
 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 @@
 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 \

Modified: trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
==============================================================================
--- trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	(original)
+++ trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	Wed Jan 28 12:34:13 2009
@@ -31,83 +31,10 @@
  * 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<DVBChannelGroup> 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<DVBChannelGroup> ();
-
-        // 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 @@
                                                  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<MediaObject> get_root_children (
@@ -141,19 +69,9 @@
                                                  uint     max_count,
                                                  out uint child_count)
                                                  throws GLib.Error {
-        child_count = this.groups.size;
-
-        Gee.List<MediaObject> 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 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);
     }
 }
 

Copied: trunk/src/plugins/dvb/rygel-dvb-root-container.vala (from r508, /trunk/src/plugins/dvb/rygel-dvb-content-dir.vala)
==============================================================================
--- /trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	(original)
+++ trunk/src/plugins/dvb/rygel-dvb-root-container.vala	Wed Jan 28 12:34:13 2009
@@ -28,9 +28,9 @@
 using Gee;
 
 /**
- * Implementation of DVB ContentDirectory service.
+ * Represents the root container for DVB media content hierarchy.
  */
-public class Rygel.DVBContentDir : ContentDirectory {
+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";
@@ -41,10 +41,9 @@
 
     private ArrayList<DVBChannelGroup> groups;
 
-    // Pubic methods
-    public override void constructed () {
-        // Chain-up to base first
-        base.constructed ();
+    public DVBRootContainer (string     title,
+                             HTTPServer http_server) {
+        base.root (title, 0);
 
         DBus.Connection connection;
         try {
@@ -58,9 +57,9 @@
         this.groups = new ArrayList<DVBChannelGroup> ();
 
         // Get a proxy to DVB Manager object
-        this.manager = connection.get_object (DVBContentDir.DVB_SERVICE,
-                                              DVBContentDir.MANAGER_PATH,
-                                              DVBContentDir.MANAGER_IFACE);
+        this.manager = connection.get_object (DVBRootContainer.DVB_SERVICE,
+                                              DVBRootContainer.MANAGER_PATH,
+                                              DVBRootContainer.MANAGER_IFACE);
         uint[] dev_groups = null;
 
         try {
@@ -86,61 +85,23 @@
 
             // Get a proxy to DVB ChannelList object
             dynamic DBus.Object channel_list = connection.get_object
-                                        (DVBContentDir.DVB_SERVICE,
+                                        (DVBRootContainer.DVB_SERVICE,
                                          channel_list_path,
-                                         DVBContentDir.CHANNEL_LIST_IFACE);
+                                         DVBRootContainer.CHANNEL_LIST_IFACE);
 
             // Create ChannelGroup for each registered device group
             this.groups.add (new DVBChannelGroup (group_id,
                                                   group_name,
-                                                  this.root_container.id,
+                                                  this.id,
                                                   channel_list,
-                                                  this.http_server));
+                                                  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);
-        }
-
-        if (media_object == null) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
-        }
-
-        return media_object;
-    }
-
-    public override Gee.List<MediaObject> get_children (
-                                                 string   container_id,
-                                                 uint     offset,
-                                                 uint     max_count,
-                                                 out uint child_count)
-                                                 throws GLib.Error {
-        var group = this.find_group_by_id (container_id);
-        if (group == null) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
-        }
-
-        var channels = group.get_children (offset,
-                                           max_count,
-                                           out child_count);
-        if (channels == null) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
-        }
-
-        return channels;
-    }
-
-    public override Gee.List<MediaObject> get_root_children (
-                                                 uint     offset,
-                                                 uint     max_count,
-                                                 out uint child_count)
-                                                 throws GLib.Error {
+    public override Gee.List<MediaObject> get_children (uint     offset,
+                                                        uint     max_count,
+                                                        out uint child_count)
+                                                        throws GLib.Error {
         child_count = this.groups.size;
 
         Gee.List<MediaObject> children = null;
@@ -154,16 +115,19 @@
         stop = stop.clamp (0, child_count);
         children = this.groups.slice ((int) offset, (int) stop);
 
-        if (children == null) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
-        }
-
         return children;
     }
 
-    public override MediaContainer? create_root_container () {
-        string friendly_name = this.root_device.get_friendly_name ();
-        return new MediaContainer.root (friendly_name, 0);
+    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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]