Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 c1cd20e486..eee9b8e26f 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 cdee2293c6..3d1ce39ad3 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... */

Back to the top