[rygel/wip/cablelabs-integration: 2/18] core: Add +LPE+ feature to proper X_DLNADOC node



commit e4e4f5b9ba6ddaf9d21c24124ffd21466e31c0e6
Author: rygelgit <p balasubramanian cablelabs com>
Date:   Mon May 19 07:50:21 2014 -0700

    core: Add +LPE+ feature to proper X_DLNADOC node
    
    Add capability to enable LPE feature in device xml
    
    Conflicts:
        src/librygel-core/rygel-description-file.vala
        src/librygel-core/rygel-plugin.vala

 src/librygel-core/rygel-description-file.vala |   98 +++++++++++++++++++------
 1 files changed, 74 insertions(+), 24 deletions(-)
---
diff --git a/src/librygel-core/rygel-description-file.vala b/src/librygel-core/rygel-description-file.vala
index d735a8f..c43459e 100644
--- a/src/librygel-core/rygel-description-file.vala
+++ b/src/librygel-core/rygel-description-file.vala
@@ -1,7 +1,9 @@
 /*
  * Copyright (C) 2011 Jens Georg
+ * Copyright (C) 2013 Cable Television Laboratories, Inc.
  *
  * Author: Jens Georg <mail jensge org>
+ *         Parthiban Balasubramanian <P Balasubramanian-contractor cablelabs com>
  *
  * This file is part of Rygel.
  *
@@ -60,9 +62,10 @@ public class Rygel.DescriptionFile : Object {
     private const string X_DLNADOC_NODE = "X_DLNADOC";
 
     // Get the local name of X_DLNADOC that does not contain +DIAGE+
-    private const string X_DLNADOC_NODE_XPATH = "//*[local-name()='X_DLNADOC'"+
-                                                " and not(contains("+
-                                                ".,\"DIAGE\"))]";
+    private const string X_DLNADOC_NON_DEVCAP_XPATH = "//*[local-name()="+
+                                              " 'X_DLNADOC'"+
+                                              " and not(contains(.,\"DIAGE\"))"+
+                                              " and not(contains(.,\"LPE\"))]";
 
     // Get the local name of X_DLNADOC that does contain +DIAGE+
     private const string X_DLNADOC_DIAGE_XPATH = "//*[local-name()='X_DLNADOC'"+
@@ -70,6 +73,12 @@ public class Rygel.DescriptionFile : Object {
 
     private const string DIAGE_DEV_CAP = "+DIAGE+";
 
+    // Get the local name of X_DLNADOC that does contain +LPE+
+    private const string X_DLNADOC_LPE_XPATH = "//*[local-name()='X_DLNADOC'"+
+                                                 " and contains(.,\"LPE\")]";
+
+    private const string LPE_DEV_CAP = "+LPE+";
+
     /**
      * Constructor to load a description file from disk
      *
@@ -249,11 +258,27 @@ public class Rygel.DescriptionFile : Object {
 
             // Add X_DLNADOC element that holds DIAGE capability
             // in the device template
-            add_dlna_doc_diage_element ();
+            add_dlna_doc_element (X_DLNADOC_DIAGE_XPATH,
+                                  X_DLNADOC_NON_DEVCAP_XPATH,
+                                  DIAGE_DEV_CAP);
+        } else {
+            // Remove X_DLNADOC element that holds DIAGE capability
+            // in the device template if it is disabled
+            remove_dlna_doc_element (X_DLNADOC_DIAGE_XPATH);
         }
 
         if (PluginCapabilities.ENERGY_MANAGEMENT in capabilities) {
-            flags += "+LPE+";
+            flags += LPE_DEV_CAP;
+
+            // Add X_DLNADOC element that holds LPE capability
+            // in the device template
+            add_dlna_doc_element (X_DLNADOC_LPE_XPATH,
+                                  X_DLNADOC_NON_DEVCAP_XPATH,
+                                  LPE_DEV_CAP);
+        } else {
+            // Remove X_DLNADOC element that holds LPE capability
+            // in the device template if it is disabled
+            remove_dlna_doc_element (X_DLNADOC_LPE_XPATH);
         }
 
         // Set the flags we found; otherwise remove whatever is in the
@@ -270,35 +295,51 @@ public class Rygel.DescriptionFile : Object {
         this.remove_device_element ("serviceList");
     }
 
-    // Add the X_DLNADOC element with +DIAGE+ if not added already.
-    public void add_dlna_doc_diage_element () {
+    // Add the X_DLNADOC element with dev_cap if not added already.
+    public void add_dlna_doc_element (string dlnadoc_xpath,
+                                      string dlnadoc_non_xpath,
+                                            string dev_cap) {
         Xml.XPath.Object* dlna_doc_object = null;
 
-        // Check if the X_DLNADOC node has already +DIAGE+ dev cap
-        if (is_diag_node_present (X_DLNADOC_DIAGE_XPATH)) {
+        // Check if the X_DLNADOC node has already dev_cap
+        if (is_node_unavailable (dlnadoc_xpath)) {
             // Get all X_DLNADOC node and extract the 'capability host & version'
-            if (get_dlna_doc_nodes (X_DLNADOC_NODE_XPATH, ref dlna_doc_object)) {
+            if (get_dlna_doc_nodes (dlnadoc_non_xpath, ref dlna_doc_object)) {
                 for (int i=0; i < dlna_doc_object->nodesetval->length(); i++) {
                     Xml.Node* node = dlna_doc_object->nodesetval->item (i);
                     string node_content = node->get_content ();
                     int doc_index = node_content.last_index_of ("/");
-                    string diage_content;
+                    string devcap_content;
 
                     // Add X_DLNADOC sibbling element for
                     // each unique capability-host
-                    var diag_element = get_device_element ()
+                    var devcap_element = get_device_element ()
                                         ->new_child (node->ns, X_DLNADOC_NODE);
                     if (doc_index != -1) {
-                        diage_content = (string)node_content
+                        devcap_content = (string)node_content
                                                 [doc_index+1:node_content.length];
                     } else {
-                        diage_content = node_content;
+                        devcap_content = node_content;
                     }
-                    message (diage_content);
-                    diag_element->set_content (DIAGE_DEV_CAP +
-                                               "/" +
-                                               diage_content);
-                    node->add_next_sibling (diag_element);
+                    message (dev_cap + "/" + devcap_content);
+                    devcap_element->set_content (dev_cap +
+                                                 "/" +
+                                                 devcap_content);
+                    node->add_next_sibling (devcap_element);
+                }
+            }
+        }
+    }
+
+    // Remove the X_DLNADOC element with DEV CAP if disabled.
+    public void remove_dlna_doc_element (string dlnadoc_xpath) {
+        Xml.XPath.Object* devcap_object = null;
+        if (get_nodes (dlnadoc_xpath, ref devcap_object)) {
+            for (int i=0; i < devcap_object->nodesetval->length(); i++) {
+                Xml.Node* node = devcap_object->nodesetval->item (i);
+                if (node != null) {
+                    node->unlink ();
+                    delete node;
                 }
             }
         }
@@ -311,12 +352,21 @@ public class Rygel.DescriptionFile : Object {
                                "device");
     }
 
-    private bool is_diag_node_present (string diage_node_xpath) {
+    private bool is_node_unavailable (string devcap_node_xpath) {
+        var context = new XPath.Context (this.doc.doc);
+        var devcap_node = context.eval_expression (devcap_node_xpath);
+        return (devcap_node != null &&
+                devcap_node->type == XPath.ObjectType.NODESET &&
+                devcap_node->nodesetval->is_empty ());
+    }
+
+    private bool get_nodes (string devcap_node_xpath,
+                                 ref Xml.XPath.Object* devcap_object) {
         var context = new XPath.Context (this.doc.doc);
-        var diage_node = context.eval_expression (diage_node_xpath);
-        return (diage_node != null &&
-                diage_node->type == XPath.ObjectType.NODESET &&
-                diage_node->nodesetval->is_empty ());
+        devcap_object = context.eval_expression (devcap_node_xpath);
+        return (devcap_object != null &&
+                devcap_object->type == XPath.ObjectType.NODESET &&
+                !devcap_object->nodesetval->is_empty ());
     }
 
     private bool get_dlna_doc_nodes (string dlna_doc_xpath,


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