[rygel] core: Port Utils.get_xml_element() to Vala



commit 2ed80b315a934a141b3ef6d79c0e31563bf0b9fe
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Jun 21 02:25:51 2010 +0300

    core: Port Utils.get_xml_element() to Vala

 src/rygel/Makefile.am                    |    1 +
 src/rygel/cstuff.c                       |   29 ----------------
 src/rygel/cstuff.h                       |    4 --
 src/rygel/cstuff.vapi                    |    3 --
 src/rygel/rygel-root-device-factory.vala |   34 ++++++++++----------
 src/rygel/rygel-xbox-hacks.vala          |   32 +++++++++---------
 src/rygel/rygel-xml-utils.vala           |   52 ++++++++++++++++++++++++++++++
 7 files changed, 86 insertions(+), 69 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index b1e1c50..902e0ff 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -37,6 +37,7 @@ rygel_SOURCES = $(VAPI_SOURCE_FILES) \
 		rygel-dbus-service.vala \
 		rygel-root-device.vala \
 		rygel-root-device-factory.vala \
+		rygel-xml-utils.vala \
 		rygel-signal-handler.vala \
 		rygel-main.vala
 
diff --git a/src/rygel/cstuff.c b/src/rygel/cstuff.c
index 7b4ab52..8552c93 100644
--- a/src/rygel/cstuff.c
+++ b/src/rygel/cstuff.c
@@ -25,35 +25,6 @@
 #include <cstuff.h>
 #include <string.h>
 
-/* Copy-paste from gupnp. */
-xmlNode *
-get_xml_element (xmlNode *node,
-                 ...)
-{
-        va_list var_args;
-
-        va_start (var_args, node);
-
-        while (TRUE) {
-                const char *arg;
-
-                arg = va_arg (var_args, const char *);
-                if (!arg)
-                        break;
-
-                for (node = node->children; node; node = node->next)
-                        if (!strcmp (arg, (char *) node->name))
-                                break;
-
-                if (!node)
-                        break;
-        }
-
-        va_end (var_args);
-
-        return node;
-}
-
 char *
 generate_random_udn (void)
 {
diff --git a/src/rygel/cstuff.h b/src/rygel/cstuff.h
index 1637a05..8a85d6b 100644
--- a/src/rygel/cstuff.h
+++ b/src/rygel/cstuff.h
@@ -29,10 +29,6 @@
 #include <glib.h>
 #include <uuid/uuid.h>
 
-G_GNUC_INTERNAL xmlNode *
-get_xml_element                         (xmlNode *node,
-                                         ...);
-
 G_GNUC_INTERNAL char *
 generate_random_udn                     (void);
 
diff --git a/src/rygel/cstuff.vapi b/src/rygel/cstuff.vapi
index 9c1487b..837d1b0 100644
--- a/src/rygel/cstuff.vapi
+++ b/src/rygel/cstuff.vapi
@@ -28,9 +28,6 @@ namespace CStuff {
      * Provides utility functions implemented in C.
      */
     public class Utils {
-        [CCode (cname = "get_xml_element", cheader_filename = "cstuff.h")]
-        public static unowned Xml.Node * get_xml_element (Xml.Node node,
-                                                          ...);
         [CCode (cname = "generate_random_udn", cheader_filename = "cstuff.h")]
         public static string generate_random_udn ();
     }
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index 4f928aa..d54d0da 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -94,10 +94,10 @@ internal class Rygel.RootDeviceFactory {
     private void prepare_desc_for_plugin (XMLDoc doc, Plugin plugin) {
         Xml.Node *device_element;
 
-        device_element = Utils.get_xml_element ((Xml.Node *) doc.doc,
-                                                "root",
-                                                "device",
-                                                null);
+        device_element = XMLUtils.get_element ((Xml.Node *) doc.doc,
+                                               "root",
+                                               "device",
+                                               null);
         if (device_element == null) {
             warning (_("XML node '%s' not found."), "/root/device");
 
@@ -128,9 +128,9 @@ internal class Rygel.RootDeviceFactory {
                                             string    plugin_name,
                                             string    plugin_title) {
         /* friendlyName */
-        Xml.Node *element = Utils.get_xml_element (device_element,
-                                                   "friendlyName",
-                                                   null);
+        Xml.Node *element = XMLUtils.get_element (device_element,
+                                                  "friendlyName",
+                                                  null);
         if (element == null) {
             warning (_("XML node '%s' not found."),
                        "/root/device/friendlyName");
@@ -152,7 +152,7 @@ internal class Rygel.RootDeviceFactory {
         element->set_content (title);
 
         /* UDN */
-        element = Utils.get_xml_element (device_element, "UDN");
+        element = XMLUtils.get_element (device_element, "UDN");
         if (element == null) {
             warning (_("XML node '%s' not found."), "/root/device/UDN");
 
@@ -169,9 +169,9 @@ internal class Rygel.RootDeviceFactory {
 
     private void set_description (Xml.Node *device_element,
                                   string    description) {
-        Xml.Node *element = Utils.get_xml_element (device_element,
-                                                   "modelDescription",
-                                                   null);
+        Xml.Node *element = XMLUtils.get_element (device_element,
+                                                  "modelDescription",
+                                                  null);
         if (element == null) {
             warning (_("XML node '%s' not found."),
                        "/root/device/modelDescription");
@@ -184,9 +184,9 @@ internal class Rygel.RootDeviceFactory {
 
     private void add_services_to_desc (Xml.Node *device_element,
                                        Plugin    plugin) {
-        Xml.Node *service_list_node = Utils.get_xml_element (device_element,
-                                                             "serviceList",
-                                                             null);
+        Xml.Node *service_list_node = XMLUtils.get_element (device_element,
+                                                            "serviceList",
+                                                            null);
         if (service_list_node == null) {
             warning (_("XML node '%s' not found."), "/root/device/serviceList");
 
@@ -237,9 +237,9 @@ internal class Rygel.RootDeviceFactory {
             icons = plugin.default_icons;
         }
 
-        Xml.Node *icon_list_node = Utils.get_xml_element (device_element,
-                                                          "iconList",
-                                                          null);
+        Xml.Node *icon_list_node = XMLUtils.get_element (device_element,
+                                                         "iconList",
+                                                         null);
         if (icon_list_node == null) {
             icon_list_node = device_element->new_child (null, "iconList", null);
         } else {
diff --git a/src/rygel/rygel-xbox-hacks.vala b/src/rygel/rygel-xbox-hacks.vala
index 2e20125..0ea4029 100644
--- a/src/rygel/rygel-xbox-hacks.vala
+++ b/src/rygel/rygel-xbox-hacks.vala
@@ -81,24 +81,24 @@ internal class Rygel.XBoxHacks : GLib.Object {
     }
 
     private void modify_dms_desc (Xml.Doc doc) {
-        var element = Utils.get_xml_element ((Xml.Node *) doc,
-                                             "root",
-                                             "device",
-                                             "deviceType");
+        Xml.Node *element = XMLUtils.get_element ((Xml.Node *) doc,
+                                                  "root",
+                                                  "device",
+                                                  "deviceType");
         assert (element != null);
         element->set_content (DMS_V1);
 
-        element = Utils.get_xml_element ((Xml.Node *) doc,
-                                         "root",
-                                         "device",
-                                         "modelName");
+        element = XMLUtils.get_element ((Xml.Node *) doc,
+                                        "root",
+                                        "device",
+                                        "modelName");
         assert (element != null);
         element->set_content (MODEL_NAME);
 
-        element = Utils.get_xml_element ((Xml.Node *) doc,
-                                         "root",
-                                         "device",
-                                         "friendlyName");
+        element = XMLUtils.get_element ((Xml.Node *) doc,
+                                        "root",
+                                        "device",
+                                        "friendlyName");
         assert (element != null);
         element->add_content (FRIENDLY_NAME_POSTFIX);
 
@@ -108,10 +108,10 @@ internal class Rygel.XBoxHacks : GLib.Object {
     }
 
     private Xml.Node * find_cds_type_node (Xml.Node *doc_node) {
-        var element = Utils.get_xml_element (doc_node,
-                                             "root",
-                                             "device",
-                                             "serviceList");
+        Xml.Node *element = XMLUtils.get_element (doc_node,
+                                                  "root",
+                                                  "device",
+                                                  "serviceList");
         assert (element != null && element->children != null);
 
         Xml.Node *cds_type_node = null;
diff --git a/src/rygel/rygel-xml-utils.vala b/src/rygel/rygel-xml-utils.vala
new file mode 100644
index 0000000..da44b3f
--- /dev/null
+++ b/src/rygel/rygel-xml-utils.vala
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008,2010 Nokia Corporation.
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *
+ * 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 Xml;
+
+/**
+ * XML utility API.
+ */
+public class Rygel.XMLUtils {
+    /* Copy-paste from gupnp and ported to Vala. */
+    public static Xml.Node* get_element (Xml.Node *node, ...) {
+        Xml.Node *ret = node;
+
+        var list = va_list ();
+
+        while (true) {
+            string arg = list.arg ();
+            if (arg == null)
+                break;
+
+            for (ret = ret->children; ret != null; ret = ret->next)
+                if (arg == ret->name)
+                    break;
+
+            if (ret == null)
+                break;
+        }
+
+        return ret;
+    }
+}
+



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