rygel r328 - in trunk/src: plugins/tracker rygel



Author: zeeshanak
Date: Sun Dec 14 20:20:57 2008
New Revision: 328
URL: http://svn.gnome.org/viewvc/rygel?rev=328&view=rev

Log:
Introduce BrowseArgs.

Introduce a new class, whose instances holds the arguments (in and out) to
Browse action and pass these instance to all methods instead of passing
around the arguments themselves everywhere. Simplifies the code and lives
of content directory implementors.

Modified:
   trunk/src/plugins/tracker/rygel-media-tracker.vala
   trunk/src/rygel/rygel-content-directory.vala

Modified: trunk/src/plugins/tracker/rygel-media-tracker.vala
==============================================================================
--- trunk/src/plugins/tracker/rygel-media-tracker.vala	(original)
+++ trunk/src/plugins/tracker/rygel-media-tracker.vala	Sun Dec 14 20:20:57 2008
@@ -77,51 +77,40 @@
         this.context.host_path (home_dir, home_dir);
     }
 
-    public override void add_children_metadata
-                            (DIDLLiteWriter didl_writer,
-                             string         container_id,
-                             string         filter,
-                             uint           starting_index,
-                             uint           requested_count,
-                             string         sort_criteria,
-                             out uint       number_returned,
-                             out uint       total_matches,
-                             out uint       update_id) throws GLib.Error {
+    public override void add_children_metadata (DIDLLiteWriter didl_writer,
+                                                BrowseArgs     args)
+                                                throws GLib.Error {
         TrackerContainer container;
 
-        if (requested_count == 0)
-            requested_count = MAX_REQUESTED_COUNT;
+        if (args.requested_count == 0)
+            args.requested_count = MAX_REQUESTED_COUNT;
 
-        container = this.find_container_by_id (container_id);
+        container = this.find_container_by_id (args.object_id);
         if (container == null)
-            number_returned = 0;
+            args.number_returned = 0;
         else {
-            number_returned =
+            args.number_returned =
                 container.add_children_from_db (didl_writer,
-                        starting_index,
-                        requested_count,
-                        out total_matches);
+                                                args.index,
+                                                args.requested_count,
+                                                out args.total_matches);
         }
 
-        if (number_returned > 0) {
-            update_id = uint32.MAX;
+        if (args.number_returned > 0) {
+            args.update_id = uint32.MAX;
         } else {
             throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         }
     }
 
-    public override void add_metadata
-                            (DIDLLiteWriter didl_writer,
-                             string         object_id,
-                             string         filter,
-                             string         sort_criteria,
-                             out uint       update_id) throws GLib.Error {
+    public override void add_metadata (DIDLLiteWriter didl_writer,
+                                       BrowseArgs     args) throws GLib.Error {
         bool found = false;
 
         TrackerContainer container;
 
         /* First try containers */
-        container = find_container_by_id (object_id);
+        container = find_container_by_id (args.object_id);
 
         if (container != null) {
             container.serialize (didl_writer);
@@ -129,34 +118,28 @@
             found = true;
         } else {
             /* Now try items */
-            container = get_item_parent (object_id);
+            container = get_item_parent (args.object_id);
 
             if (container != null)
-                found = container.add_item_from_db (didl_writer, object_id);
+                found = container.add_item_from_db (didl_writer,
+                                                    args.object_id);
         }
 
         if (!found) {
             throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         }
 
-        update_id = uint32.MAX;
+        args.update_id = uint32.MAX;
     }
 
-    public override void add_root_children_metadata
-                                        (DIDLLiteWriter didl_writer,
-                                         string         filter,
-                                         uint           starting_index,
-                                         uint           requested_count,
-                                         string         sort_criteria,
-                                         out uint       number_returned,
-                                         out uint       total_matches,
-                                         out uint       update_id)
-                                         throws GLib.Error {
+    public override void add_root_children_metadata (DIDLLiteWriter didl_writer,
+                                                     BrowseArgs     args)
+                                                     throws GLib.Error {
         foreach (TrackerContainer container in this.containers)
             container.serialize (didl_writer);
 
-        total_matches = number_returned = this.containers.length ();
-        update_id = uint32.MAX;
+        args.total_matches = args.number_returned = this.containers.length ();
+        args.update_id = uint32.MAX;
     }
 
     /* Private methods */

Modified: trunk/src/rygel/rygel-content-directory.vala
==============================================================================
--- trunk/src/rygel/rygel-content-directory.vala	(original)
+++ trunk/src/rygel/rygel-content-directory.vala	Sun Dec 14 20:20:57 2008
@@ -33,6 +33,21 @@
     NO_SUCH_OBJECT = 701
 }
 
+public class BrowseArgs {
+    // In arguments
+    public string object_id;
+    public string browse_flag;
+    public string filter;
+    public uint   index;           // Starting index
+    public uint   requested_count;
+    public string sort_criteria;
+
+    // Out arguments
+    public uint   number_returned;
+    public uint   total_matches;
+    public uint   update_id;
+}
+
 /**
  * Basic implementation of UPnP ContentDirectory service version 2. Most often
  * plugins will provide a child of this class. The inheriting classes should
@@ -54,37 +69,20 @@
     DIDLLiteWriter didl_writer;
 
     // Public abstract methods derived classes need to implement
-    public virtual void add_children_metadata
-                            (DIDLLiteWriter didl_writer,
-                             string         container_id,
-                             string         filter,
-                             uint           starting_index,
-                             uint           requested_count,
-                             string         sort_criteria,
-                             out uint       number_returned,
-                             out uint       total_matches,
-                             out uint       update_id) throws Error {
+    public virtual void add_children_metadata (DIDLLiteWriter didl_writer,
+                                               BrowseArgs     args)
+                                               throws Error {
         throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n");
     }
 
     public virtual void add_metadata (DIDLLiteWriter didl_writer,
-                                       string         object_id,
-                                       string         filter,
-                                       string         sort_criteria,
-                                       out uint       update_id) throws Error {
+                                      BrowseArgs    args) throws Error {
         throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n");
     }
 
     public virtual void add_root_children_metadata
                                         (DIDLLiteWriter didl_writer,
-                                         string         filter,
-                                         uint           starting_index,
-                                         uint           requested_count,
-                                         string         sort_criteria,
-                                         out uint       number_returned,
-                                         out uint       total_matches,
-                                         out uint       update_id)
-                                         throws Error {
+                                         BrowseArgs     args) throws Error {
         throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n");
     }
 
@@ -130,24 +128,24 @@
     /* Browse action implementation */
     protected virtual void browse_cb (ContentDirectory content_dir,
                                       ServiceAction    action) {
-        string object_id, browse_flag;
         bool browse_metadata;
-        string sort_criteria, filter;
-        uint starting_index, requested_count;
-        uint num_returned, total_matches, update_id;
+
+        BrowseArgs args = new BrowseArgs ();
 
         /* Handle incoming arguments */
-        action.get ("ObjectID", typeof (string), out object_id,
-                    "BrowseFlag", typeof (string), out browse_flag,
-                    "Filter", typeof (string), out filter,
-                    "StartingIndex", typeof (uint), out starting_index,
-                    "RequestedCount", typeof (uint), out requested_count,
-                    "SortCriteria", typeof (string), out sort_criteria);
+        action.get ("ObjectID", typeof (string), out args.object_id,
+                    "BrowseFlag", typeof (string), out args.browse_flag,
+                    "Filter", typeof (string), out args.filter,
+                    "StartingIndex", typeof (uint), out args.index,
+                    "RequestedCount", typeof (uint), out args.requested_count,
+                    "SortCriteria", typeof (string), out args.sort_criteria);
 
         /* BrowseFlag */
-        if (browse_flag != null && browse_flag == "BrowseDirectChildren") {
+        if (args.browse_flag != null &&
+            args.browse_flag == "BrowseDirectChildren") {
             browse_metadata = false;
-        } else if (browse_flag != null && browse_flag == "BrowseMetadata") {
+        } else if (args.browse_flag != null &&
+                   args.browse_flag == "BrowseMetadata") {
             browse_metadata = true;
         } else {
             action.return_error (402, "Invalid Args");
@@ -156,10 +154,10 @@
         }
 
         /* ObjectID */
-        if (object_id == null) {
+        if (args.object_id == null) {
             /* Stupid Xbox */
-            action.get ("ContainerID", typeof (string), out object_id);
-            if (object_id == null) {
+            action.get ("ContainerID", typeof (string), out args.object_id);
+            if (args.object_id == null) {
                 action.return_error (701, "No such object");
 
                 return;
@@ -172,40 +170,21 @@
         try {
             if (browse_metadata) {
                 // BrowseMetadata
-                if (object_id == this.root_container.id) {
+                if (args.object_id == this.root_container.id) {
                     this.root_container.serialize (didl_writer);
-                    update_id = this.system_update_id;
+                    args.update_id = this.system_update_id;
                 } else {
-                    this.add_metadata (this.didl_writer,
-                                       object_id,
-                                       filter,
-                                       sort_criteria,
-                                       out update_id);
+                    this.add_metadata (this.didl_writer, args);
                 }
 
-                num_returned = 1;
-                total_matches = 1;
+                args.number_returned = 1;
+                args.total_matches = 1;
             } else {
                 // BrowseDirectChildren
-                if (object_id == this.root_container.id) {
-                    this.add_root_children_metadata (this.didl_writer,
-                                                     filter,
-                                                     starting_index,
-                                                     requested_count,
-                                                     sort_criteria,
-                                                     out num_returned,
-                                                     out total_matches,
-                                                     out update_id);
+                if (args.object_id == this.root_container.id) {
+                    this.add_root_children_metadata (this.didl_writer, args);
                 } else {
-                    this.add_children_metadata (this.didl_writer,
-                                                object_id,
-                                                filter,
-                                                starting_index,
-                                                requested_count,
-                                                sort_criteria,
-                                                out num_returned,
-                                                out total_matches,
-                                                out update_id);
+                    this.add_children_metadata (this.didl_writer, args);
                 }
             }
 
@@ -215,15 +194,15 @@
             /* Retrieve generated string */
             string didl = this.didl_writer.get_string ();
 
-            if (update_id == uint32.MAX) {
-                update_id = this.system_update_id;
+            if (args.update_id == uint32.MAX) {
+                args.update_id = this.system_update_id;
             }
 
             /* Set action return arguments */
             action.set ("Result", typeof (string), didl,
-                        "NumberReturned", typeof (uint), num_returned,
-                        "TotalMatches", typeof (uint), total_matches,
-                        "UpdateID", typeof (uint), update_id);
+                        "NumberReturned", typeof (uint), args.number_returned,
+                        "TotalMatches", typeof (uint), args.total_matches,
+                        "UpdateID", typeof (uint), args.update_id);
 
             action.return ();
         } catch (Error error) {



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