summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorGeneviève Bastien2013-02-15 15:34:06 (EST)
committer Matthew Khouzam2013-02-19 14:17:47 (EST)
commitca5d1f526e5ead481e88d3e1ac76c4bf433daacc (patch)
tree3cf978cf678398ec866aa3886c1ffa452d696741
parentdb9e82b99f46a252b364fb4df52e2d0c41ecd83e (diff)
downloadorg.eclipse.linuxtools-ca5d1f526e5ead481e88d3e1ac76c4bf433daacc.zip
org.eclipse.linuxtools-ca5d1f526e5ead481e88d3e1ac76c4bf433daacc.tar.gz
org.eclipse.linuxtools-ca5d1f526e5ead481e88d3e1ac76c4bf433daacc.tar.bz2
TMF: Add support for StructDefinition fields to ctfadaptorrefs/changes/01/10401/5
CTF supports recursive field definitions. So does TMF now. * Added the CTFStructField class * Updated the unit tests for this new class Change-Id: I5e476da2a73f172ff946a1fff386e6fb48dff1bc Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/10401 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java19
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java58
2 files changed, 76 insertions, 1 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
index c1cd20e..eee9b8e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
@@ -50,6 +50,7 @@ public class CtfTmfEventFieldTest {
private static final String LEN = "len";
private static final String INT = "int";
private static final String NAME = "test";
+ private static final String STRUCT = "struct";
private StructDefinition fixture;
@@ -66,20 +67,26 @@ public class CtfTmfEventFieldTest {
ByteOrder.BIG_ENDIAN, 8);
ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec);
SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
+ StructDeclaration structDec = new StructDeclaration(32);
sDec.addField(INT, intDec);
sDec.addField(LEN, intDec);
sDec.addField(FLOAT, flDec);
sDec.addField(STR, strDec);
sDec.addField(ARRAY, arrDec);
sDec.addField(SEQ, seqDec);
+ structDec.addField(STR,strDec);
+ structDec.addField(INT, intDec);
+ sDec.addField(STRUCT, structDec);
fixture = sDec.createDefinition(fixture, ROOT);
- int capacity = 1024;
+ int capacity = 2048;
java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocateDirect(capacity);
for (int i = 0; i < capacity; i++) {
bb.put((byte) 2);
}
bb.position(20);
bb.put((byte) 0);
+ bb.position(40);
+ bb.put((byte) 0);
bb.position(0);
fixture.read(new BitBuffer(bb));
}
@@ -143,4 +150,14 @@ public class CtfTmfEventFieldTest {
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=", result.toString());
}
+
+ /**
+ * Run the CtfTmfEventField parseField(Definition,String) method test.
+ */
+ @Test
+ public void testParseField_struct() {
+ Definition fieldDef = fixture.lookupDefinition(STRUCT);
+ CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
+ assertEquals("test=[str=, int=02]", result.toString());
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
index cdee229..3d1ce39 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEventField.java
@@ -10,12 +10,15 @@
* Matthew Khouzam - Initial API and implementation
* Alexendre Montplaisir - Initial API and implementation, extend TmfEventField
* Bernd Hufmann - Add Enum field handling
+ * Geneviève Bastien - Add support for Struct fields
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
@@ -27,6 +30,8 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
/**
@@ -57,6 +62,9 @@ public abstract class CtfTmfEventField extends TmfEventField {
/** @since 2.0 */
protected static final int FIELDTYPE_ENUM = 4;
+ /** @since 2.0 */
+ protected static final int FIELDTYPE_STRUCT = 5;
+
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
@@ -151,6 +159,21 @@ public abstract class CtfTmfEventField extends TmfEventField {
}
/* Add other Sequence types here */
+ } else if (fieldDef instanceof StructDefinition) {
+ StructDefinition strDef = (StructDefinition) fieldDef;
+
+ String curFieldName = null;
+ Definition curFieldDef;
+ CtfTmfEventField curField;
+ List<ITmfEventField> list = new ArrayList<ITmfEventField>();
+ /* Recursively parse the fields */
+ for (Entry<String, Definition> entry : strDef.getDefinitions().entrySet()) {
+ curFieldName = entry.getKey();
+ curFieldDef = entry.getValue();
+ curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
+ list.add(curField);
+ }
+ field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
}
return field;
}
@@ -362,4 +385,39 @@ final class CTFEnumField extends CtfTmfEventField {
}
}
+/**
+ * The CTF field implementation for struct fields with sub-types
+ *
+ * @author gbastien
+ */
+final class CTFStructField extends CtfTmfEventField {
+
+ /**
+ * Constructor for CTFStringField.
+ *
+ * @param strValue
+ * The string value of this field
+ * @param name
+ * The name of this field
+ */
+ CTFStructField(String name, CtfTmfEventField[] fields) {
+ super(name, fields);
+ }
+
+ @Override
+ public int getFieldType() {
+ return FIELDTYPE_STRUCT;
+ }
+
+ @Override
+ public CtfTmfEventField[] getValue() {
+ return (CtfTmfEventField[]) super.getValue();
+ }
+
+ @Override
+ public String toString() {
+ return getName() + '=' + Arrays.toString(getValue());
+ }
+}
+
/* Implement other possible fields types here... */