ctf: make SIPIE enums store both key and value
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 2 Dec 2015 20:41:59 +0000 (15:41 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 16 Dec 2015 21:45:50 +0000 (16:45 -0500)
By adding the getStringValue and getIntegerValue,
instead of getValue, we have more information available.
This is useful for enums so we can look up the string
name but also sort it easier.

Change-Id: Icfa095a0a8c2b8924809c389dbfe53055c3b63be
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/61814
Reviewed-by: Hudson CI
Reviewed-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java

index fd33e77c6047e6c571e977c0e345df9cfbdc94ab..f1677c7268b7da6e9b47f03dcf91c39a7e645305 100644 (file)
@@ -84,7 +84,9 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
         sd.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder.nativeOrder(), 8));
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
-        sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
+        final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+        declaration.add(-100, 100, "");
+        sd.addField("Enum", declaration);
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
         bb.getByteBuffer().putInt(200);
@@ -112,7 +114,9 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
-        sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
+        final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+        declaration.add(-100, 100, "");
+        sd.addField("Enum", declaration);
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
         bb.getByteBuffer().putInt(200);
@@ -140,7 +144,9 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
         sd.addField("packet_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
-        sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
+        final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+        declaration.add(-100, 100, "");
+        sd.addField("Enum", declaration);
         sd.addField("intruder", new StructDeclaration(8));
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
@@ -170,7 +176,9 @@ public class CTFStreamInputPacketIndexEntryTest {
         StructDeclaration sd = new StructDeclaration(8);
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
-        sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
+        final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+        declaration.add(-100, 100, "");
+        sd.addField("Enum", declaration);
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(0);
         bb.getByteBuffer().put(("Test").getBytes());
@@ -195,7 +203,9 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII));
-        sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
+        final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+        declaration.add(-100, 100, "");
+        sd.addField("Enum", declaration);
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(-1);
         bb.getByteBuffer().putInt(0);
index ade605afe5d40c1aba494e1113da0cb904375bbe..64bb804615bfe43f0944b577f4602ab12f89b438 100644 (file)
 
 package org.eclipse.tracecompass.internal.ctf.core.trace;
 
+import java.util.AbstractMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.ctf.core.CTFStrings;
 import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.FloatDefinition;
@@ -101,7 +103,7 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor {
      * @param fileSizeBytes
      *            number of bytes in a file
      *
-     * TODO: Remove
+     *            TODO: Remove
      */
 
     public StreamInputPacketIndexEntry(long dataOffsetBits, long fileSizeBytes) {
@@ -129,7 +131,7 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor {
      * @param lostSoFar
      *            number of lost events so far
      *
-     * TODO: Remove
+     *            TODO: Remove
      */
     public StreamInputPacketIndexEntry(long dataOffsetBits, StructDefinition streamPacketContextDef, long fileSizeBytes, long lostSoFar) {
         this(dataOffsetBits, streamPacketContextDef, fileSizeBytes, lostSoFar, dataOffsetBits);
@@ -158,7 +160,10 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor {
             } else if (id instanceof FloatDefinition) {
                 fAttributes.put(field, ((FloatDefinition) id).getValue());
             } else if (id instanceof EnumDefinition) {
-                fAttributes.put(field, ((EnumDefinition) id).getValue());
+                final EnumDefinition enumDec = (EnumDefinition) id;
+                fAttributes.put(field, new AbstractMap.SimpleImmutableEntry<>(
+                        NonNullUtils.checkNotNull(enumDec.getStringValue()),
+                        NonNullUtils.checkNotNull(enumDec.getIntegerValue())));
             } else if (id instanceof StringDefinition) {
                 fAttributes.put(field, ((StringDefinition) id).getValue());
             }
This page took 0.028772 seconds and 5 git commands to generate.