TMF: Add get parent to state system
authorFrancis Giraldeau <francis.giraldeau@gmail.com>
Tue, 25 Mar 2014 16:00:48 +0000 (12:00 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 28 Mar 2014 19:53:43 +0000 (15:53 -0400)
It is possible to get the children of an attribute. This patch add also
required methods to query the parent attributes.

* Add getParent() method to Attribute, AttributeTree and StateSystem
* Add unit test to check the functionality
* Provides the required documentation

Change-Id: I635326068c2a298b32952599e09b2426b2e1fbb0
Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Reviewed-on: https://git.eclipse.org/r/24026
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java

index 2f46cc34e4e0b1be50abf5c1906bd33afda2de32..8a3708a71af24b471be0da33050e65ca4fdfb76f 100644 (file)
@@ -422,4 +422,25 @@ public abstract class StateSystemTest {
             fail();
         }
     }
+
+    @Test
+    public void testParentAttribute() {
+        String[] path = { "CPUs/0/Current_thread",
+                          "CPUs/0",
+                          "CPUs" };
+        try {
+            int q = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+            for (int i = 0; i < path.length; i++) {
+                String name = ssq.getFullAttributePath(q);
+                assertEquals(path[i], name);
+                q = ssq.getParentAttributeQuark(q);
+            }
+            assertEquals(-1, q);
+            q = ssq.getParentAttributeQuark(q);
+            assertEquals(-1, q);
+        } catch (AttributeNotFoundException e) {
+            fail();
+        }
+    }
+
 }
index 4cd830dd5c5b589622b019ba8f3c866ff4d789b8..6f42a3a34bcc0e2e7c02d9dbda162df8f105c91e 100644 (file)
@@ -129,6 +129,24 @@ public abstract class Attribute {
         return targetNode.getQuark();
     }
 
+    /**
+     * Get the parent attribute of this attribute
+     *
+     * @return The parent attribute
+     */
+    public Attribute getParentAttribute() {
+        return this.parent;
+    }
+
+    /**
+     * Get the parent quark of this attribute
+     *
+     * @return The quark of the parent attribute
+     */
+    public int getParentAttributeQuark() {
+        return this.parent.getQuark();
+    }
+
     /* The methods how to access children are left to derived classes */
 
     /**
index 3d897c69e35040a7955b2d0f651681511db8320d..958c867dfc19f4fe6579d3c0b40b4af6e0fd1fe1 100644 (file)
@@ -357,6 +357,22 @@ public final class AttributeTree {
         return listOfChildren;
     }
 
+    /**
+     * Returns the parent quark of the attribute. The root attribute has no
+     * parent and will return <code>-1</code>
+     *
+     * @param quark
+     *            The quark of the attribute
+     * @return Quark of the parent attribute or <code>-1</code> for the root
+     *         attribute
+     */
+    public int getParentAttributeQuark(int quark) {
+        if (quark == -1) {
+            return quark;
+        }
+        return attributeList.get(quark).getParentAttributeQuark();
+    }
+
     private void addSubAttributes(List<Integer> list, Attribute curAttribute,
             boolean recursive) {
         for (Attribute childNode : curAttribute.getSubAttributes()) {
index 981467fe23563d416e58e069930f49d513fe591d..00871e846fca9b2878701169590e969528ab792c 100644 (file)
@@ -277,6 +277,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
         return ret;
     }
 
+    @Override
+    public int getParentAttributeQuark(int quark) {
+        return getAttributeTree().getParentAttributeQuark(quark);
+    }
+
     @Override
     public List<Integer> getQuarks(String... pattern) {
         List<Integer> quarks = new LinkedList<>();
index 4682c15fd4766b4597bc2fcc27143a69dfb61571..05f662b3d9e5f70596bc1568698d6abef93f6eb8 100644 (file)
@@ -248,6 +248,17 @@ public interface ITmfStateSystem {
      */
     String getFullAttributePath(int attributeQuark);
 
+    /**
+     * Returns the parent quark of the attribute.
+     *
+     * @param attributeQuark
+     *            The quark of the attribute
+     * @return Quark of the parent attribute or <code>-1</code> if root quark or
+     *         no parent.
+     * @since 3.0
+     */
+    int getParentAttributeQuark(int attributeQuark);
+
     /**
      * @name Query methods
      */
This page took 0.028921 seconds and 5 git commands to generate.