From 486efb2e13e1bea489a6196734e61d8ade1fc81b Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 11 Dec 2012 17:16:06 -0500 Subject: [PATCH] ctf: Fix API inconsistencies Some API methods would return or take as parameter classes that were not part of the API themselves. This little rework seems to fix the problem, mainly by exporting BitBuffer, Stream and StreamInput. Change-Id: I3bac3619426d51c1a1484a6a0a336ec93e700175 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/9173 IP-Clean: Matthew Khouzam Tested-by: Hudson CI Reviewed-by: Matthew Khouzam Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../core/tests/event/CTFEventFieldTest.java | 2 +- .../ctf/core/tests/headless/ReadTrace.java | 2 +- .../ctf/core/tests/io/BitBufferIntTest.java | 2 +- .../ctf/core/tests/io/BitBufferTest.java | 2 +- .../ctf/core/tests/trace/CTFTraceTest.java | 2 +- .../tests/trace/StreamInputReaderTest.java | 4 +- .../ctf/core/tests/trace/StreamInputTest.java | 14 +- .../ctf/core/tests/trace/StreamTest.java | 4 +- .../core/tests/types/ArrayDefinitionTest.java | 2 +- .../ctf/core/tests/types/DefinitionTest.java | 2 +- .../core/tests/types/EnumDefinitionTest.java | 2 +- .../tests/types/EventDeclarationTest.java | 2 +- .../core/tests/types/FloatDefinitionTest.java | 2 +- .../tests/types/IntegerDefinitionTest.java | 2 +- .../tests/types/SequenceDefinitionTest.java | 2 +- .../tests/types/StringDefinitionTest.java | 2 +- .../tests/types/StructDefinitionTest.java | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../ctf/core/event/EventDeclaration.java | 4 +- .../ctf/core/event/io/BitBuffer.java | 559 ++++++++++++++++++ .../ctf/core/event/types/ArrayDefinition.java | 2 +- .../ctf/core/event/types/Definition.java | 3 +- .../ctf/core/event/types/EnumDefinition.java | 2 +- .../ctf/core/event/types/FloatDefinition.java | 4 +- .../core/event/types/IntegerDefinition.java | 2 +- .../core/event/types/SequenceDefinition.java | 4 +- .../core/event/types/StringDefinition.java | 4 +- .../core/event/types/StructDefinition.java | 4 +- .../core/event/types/VariantDefinition.java | 4 +- .../linuxtools/ctf/core/trace/CTFTrace.java | 9 +- .../ctf/core/trace/CTFTraceReader.java | 2 - .../{internal => }/ctf/core/trace/Stream.java | 4 +- .../ctf/core/trace/StreamInput.java | 11 +- .../core/trace/StreamInputPacketReader.java | 7 +- .../ctf/core/trace/StreamInputReader.java | 1 - .../internal/ctf/core/event/io/BitBuffer.java | 558 ----------------- .../ctf/core/event/metadata/IOStructGen.java | 2 +- .../ctfadaptor/CtfTmfEventFieldTest.java | 2 +- 38 files changed, 616 insertions(+), 624 deletions(-) create mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{internal => }/ctf/core/trace/Stream.java (98%) rename org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/{internal => }/ctf/core/trace/StreamInput.java (98%) delete mode 100644 org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java index 77112c1291..98ba2477c1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; @@ -19,7 +20,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java index 0eb31f4930..9bb6d6478c 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java @@ -22,7 +22,7 @@ import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.Stream; @SuppressWarnings("javadoc") public class ReadTrace { diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java index 22fee78a6b..1844cb9740 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java index 18e6fcecc6..cd77e16a71 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java index fa9c087e1d..72ddeca815 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java @@ -17,8 +17,8 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java index bc4a31ecd8..5e850b77dc 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java @@ -13,9 +13,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java index 935ec03df4..9a1e75ab64 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java @@ -13,9 +13,8 @@ import java.nio.channels.FileChannel; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -97,15 +96,6 @@ public class StreamInputTest { assertNotNull(result); } - /** - * Run the StreamInputPacketIndex getIndex() method test. - */ - @Test - public void testGetIndex() { - StreamInputPacketIndex result = fixture.getIndex(); - assertNotNull(result); - } - /** * Run the String getPath() method test. */ diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java index 5f76ac5988..a289b02df2 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java @@ -12,9 +12,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java index facff32435..b2df5813a5 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; @@ -18,7 +19,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java index f225fcf897..3fab337cde 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/DefinitionTest.java @@ -2,10 +2,10 @@ package org.eclipse.linuxtools.ctf.core.tests.types; import static org.junit.Assert.assertNotNull; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java index a7d76d0fdc..39f8091f3c 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java @@ -7,11 +7,11 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java index 3dcbb9873d..9ad01f217f 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java @@ -13,7 +13,7 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; +import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java index c4041e8902..222841c84b 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java @@ -6,9 +6,9 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java index 08419fa393..f4b1653fc1 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java @@ -5,11 +5,11 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java index 24aabb5af9..74799b86b0 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; @@ -14,7 +15,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java index 3de56f061f..e4fe887da2 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java @@ -2,10 +2,10 @@ package org.eclipse.linuxtools.ctf.core.tests.types; import static org.junit.Assert.assertNotNull; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java index 7bbcf46d78..b2795eb566 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java @@ -7,6 +7,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.HashMap; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; @@ -22,7 +23,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF index 3a14d55d34..43cad48141 100644 --- a/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF @@ -11,10 +11,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.eclipse.core.runtime, org.eclipse.linuxtools.ctf.parser;bundle-version="1.0.0" Export-Package: org.eclipse.linuxtools.ctf.core.event, + org.eclipse.linuxtools.ctf.core.event.io, org.eclipse.linuxtools.ctf.core.event.types, org.eclipse.linuxtools.ctf.core.trace, org.eclipse.linuxtools.internal.ctf.core;x-internal:=true, - org.eclipse.linuxtools.internal.ctf.core.event.io;x-internal:=true, org.eclipse.linuxtools.internal.ctf.core.event.metadata;x-internal:=true, org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;x-internal:=true, org.eclipse.linuxtools.internal.ctf.core.trace;x-internal:=true diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java index 5272c0aa4f..1d0d5ca0c7 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java @@ -13,8 +13,8 @@ package org.eclipse.linuxtools.ctf.core.event; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; /** * Representation of one type of event. A bit like "int" or "long" but for trace @@ -172,6 +172,7 @@ public class EventDeclaration { /** * Sets the stream of am event declaration * @param stream the stream + * @since 2.0 */ public void setStream(Stream stream) { this.stream = stream; @@ -180,6 +181,7 @@ public class EventDeclaration { /** * Gets the stream of am event declaration * @return stream the stream + * @since 2.0 */ public Stream getStream() { return stream; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java new file mode 100644 index 0000000000..7aae945ef4 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java @@ -0,0 +1,559 @@ +/*******************************************************************************. + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial Design and implementation + * Contributors: Francis Giraldeau - Initial API and implementation + * Contributors: Philippe Proulx - Some refinement and optimization + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.event.io; + +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +/** + * BitBuffer + *

+ * A bitwise buffer capable of accessing fields with bit offsets. + * @since 2.0 + */ +public class BitBuffer { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /* default bit width */ + /** 8 bits to a char */ + public static final int BIT_CHAR = 8; + /** 16 bits to a short */ + public static final int BIT_SHORT = 16; + /** 32 bits to an int */ + public static final int BIT_INT = 32; + /** 32 bits to a float */ + public static final int BIT_FLOAT = 32; + /** 64 bits to a long */ + public static final int BIT_LONG = 64; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + private ByteBuffer buf; + private int pos; + private ByteOrder byteOrder; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Default constructor, makes a bigendian buffer + */ + public BitBuffer() { + this(null, ByteOrder.BIG_ENDIAN); + } + + /** + * Constructor, makes a bigendian buffer + * + * @param buf + * the bytebuffer to read + */ + public BitBuffer(ByteBuffer buf) { + this(buf, ByteOrder.BIG_ENDIAN); + } + + /** + * Constructor that is fully parametrisable + * + * @param buf + * the buffer to read + * @param order + * the byte order (big endian, little endian, network?) + */ + public BitBuffer(ByteBuffer buf, ByteOrder order) { + setByteBuffer(buf); + setByteOrder(order); + position(0); + } + + // ------------------------------------------------------------------------ + // 'Get' operations on buffer + // ------------------------------------------------------------------------ + + /** + * Relative get method for reading 32-bit integer. + * + * Reads next four bytes from the current bit position according to current + * byte order. + * + * @return The int value read from the buffer + */ + public int getInt() { + int val = getInt(BIT_INT, true); + return val; + } + + /** + * Relative get method for reading integer of length bits. + * + * Reads length bits starting at the current position. The result is + * signed extended if signed is true. The current position is + * increased of length bits. + * + * @param length + * The length in bits of this integer + * @param signed + * The sign extended flag + * @return The int value read from the buffer + */ + public int getInt(int length, boolean signed) { + int val = 0; + if (!canRead(length)) { + throw new BufferOverflowException(); + } + if (length == 0) { + return 0; + } + boolean gotIt = false; + + // Fall back to fast ByteBuffer reader if we want to read byte-aligned bytes + if (this.pos % BitBuffer.BIT_CHAR == 0) { + switch (length) { + case BitBuffer.BIT_CHAR: + // Byte + if (signed) { + val = this.buf.get(this.pos / 8); + } else { + val = (this.buf.get(this.pos / 8)) & 0xff; + } + gotIt = true; + break; + + case BitBuffer.BIT_SHORT: + // Word + if (signed) { + val = this.buf.getShort(this.pos / 8); + } else { + short a = this.buf.getShort(this.pos / 8); + val = a & 0xffff; + } + gotIt = true; + break; + + case BitBuffer.BIT_INT: + // Double word + val = this.buf.getInt(this.pos / 8); + gotIt = true; + break; + + default: + break; + } + } + if (!gotIt) { + // Nothing read yet: use longer methods + if (this.byteOrder == ByteOrder.LITTLE_ENDIAN) { + val = getIntLE(this.pos, length, signed); + } else { + val = getIntBE(this.pos, length, signed); + } + } + this.pos += length; + + return val; + } + + private int getIntBE(int index, int length, boolean signed) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask, cache; + int value = 0; + + currByte = startByte; + cache = this.buf.get(currByte) & 0xFF; + boolean isNeg = (cache & (1 << (BIT_CHAR - (index % BIT_CHAR) - 1))) != 0; + if (signed && isNeg) { + value = ~0; + } + if (startByte == (endByte - 1)) { + cmask = cache >>> ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR); + if (((length) % BIT_CHAR) > 0) { + mask = ~((~0) << length); + cmask &= mask; + } + value <<= length; + value |= cmask; + return value; + } + cshift = index % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << (BIT_CHAR - cshift)); + cmask = cache & mask; + lshift = BIT_CHAR - cshift; + value <<= lshift; + value |= cmask; + // index += lshift; + currByte++; + } + for (; currByte < (endByte - 1); currByte++) { + value <<= BIT_CHAR; + value |= this.buf.get(currByte) & 0xFF; + } + lshift = end % BIT_CHAR; + if (lshift > 0) { + mask = ~((~0) << lshift); + cmask = this.buf.get(currByte) & 0xFF; + cmask >>>= BIT_CHAR - lshift; + cmask &= mask; + value <<= lshift; + value |= cmask; + } else { + value <<= BIT_CHAR; + value |= this.buf.get(currByte) & 0xFF; + } + return value; + } + + private int getIntLE(int index, int length, boolean signed) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask, cache, mod; + int value = 0; + + currByte = endByte - 1; + cache = buf.get(currByte) & 0xFF; + mod = end % BIT_CHAR; + lshift = (mod > 0) ? mod : BIT_CHAR; + boolean isNeg = (cache & (1 << (lshift - 1))) != 0; + if (signed && isNeg) { + value = ~0; + } + if (startByte == (endByte - 1)) { + cmask = cache >>> (index % BIT_CHAR); + if (((length) % BIT_CHAR) > 0) { + mask = ~((~0) << length); + cmask &= mask; + } + value <<= length; + value |= cmask; + return value; + } + cshift = end % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << cshift); + cmask = cache & mask; + value <<= cshift; + value |= cmask; + // end -= cshift; + currByte--; + } + for (; currByte >= (startByte + 1); currByte--) { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + lshift = index % BIT_CHAR; + if (lshift > 0) { + mask = ~((~0) << (BIT_CHAR - lshift)); + cmask = buf.get(currByte) & 0xFF; + cmask >>>= lshift; + cmask &= mask; + value <<= (BIT_CHAR - lshift); + value |= cmask; + } else { + value <<= BIT_CHAR; + value |= buf.get(currByte) & 0xFF; + } + return value; + } + + // ------------------------------------------------------------------------ + // 'Put' operations on buffer + // ------------------------------------------------------------------------ + + /** + * Relative put method to write signed 32-bit integer. + * + * Write four bytes starting from current bit position in the buffer + * according to the current byte order. The current position is increased of + * length bits. + * + * @param value + * The int value to write + */ + public void putInt(int value) { + putInt(BIT_INT, value); + } + + /** + * Relative put method to write length bits integer. + * + * Writes length lower-order bits from the provided value, + * starting from current bit position in the buffer. Sequential bytes are + * written according to the current byte order. The sign bit is carried to + * the MSB if signed is true. The sign bit is included in length. The + * current position is increased of length. + * + * @param length + * The number of bits to write + * @param value + * The value to write + */ + public void putInt(int length, int value) { + final int curPos = this.pos; + + if (!canRead(length)) { + throw new BufferOverflowException(); + } + if (length == 0) { + return; + } + if (this.byteOrder == ByteOrder.LITTLE_ENDIAN) { + putIntLE(curPos, length, value); + } else { + putIntBE(curPos, length, value); + } + this.pos += length; + } + + private void putIntBE(int index, int length, int value) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask; + int correctedValue = value; + + /* + * mask v high bits. Works for unsigned and two complement signed + * numbers which value do not overflow on length bits. + */ + + if (length < BIT_INT) { + correctedValue &= ~(~0 << length); + } + + /* sub byte */ + if (startByte == (endByte - 1)) { + lshift = (BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR; + mask = ~((~0) << lshift); + if ((index % BIT_CHAR) > 0) { + mask |= (~(0)) << (BIT_CHAR - (index % BIT_CHAR)); + } + cmask = correctedValue << lshift; + /* + * low bits are cleared because of lshift and high bits are already + * cleared + */ + cmask &= ~mask; + int b = this.buf.get(startByte) & 0xFF; + this.buf.put(startByte, (byte) ((b & mask) | cmask)); + return; + } + + /* head byte contains MSB */ + currByte = endByte - 1; + cshift = end % BIT_CHAR; + if (cshift > 0) { + lshift = BIT_CHAR - cshift; + mask = ~((~0) << lshift); + cmask = correctedValue << lshift; + cmask &= ~mask; + int b = this.buf.get(currByte) & 0xFF; + this.buf.put(currByte, (byte) ((b & mask) | cmask)); + correctedValue >>>= cshift; + // end -= cshift; + currByte--; + } + + /* middle byte(s) */ + for (; currByte >= (startByte + 1); currByte--) { + this.buf.put(currByte, (byte) correctedValue); + correctedValue >>>= BIT_CHAR; + } + /* end byte contains LSB */ + if ((index % BIT_CHAR) > 0) { + mask = (~0) << (BIT_CHAR - (index % BIT_CHAR)); + cmask = correctedValue & ~mask; + int b = this.buf.get(currByte) & 0xFF; + this.buf.put(currByte, (byte) ((b & mask) | cmask)); + } else { + this.buf.put(currByte, (byte) correctedValue); + } + } + + private void putIntLE(int index, int length, int value) { + assert ((length > 0) && (length <= BIT_INT)); + int end = index + length; + int startByte = index / BIT_CHAR; + int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; + int currByte, lshift, cshift, mask, cmask; + int correctedValue = value; + + /* + * mask v high bits. Works for unsigned and two complement signed + * numbers which value do not overflow on length bits. + */ + + if (length < BIT_INT) { + correctedValue &= ~(~0 << length); + } + + /* sub byte */ + if (startByte == (endByte - 1)) { + lshift = index % BIT_CHAR; + mask = ~((~0) << lshift); + if ((end % BIT_CHAR) > 0) { + mask |= (~(0)) << (end % BIT_CHAR); + } + cmask = correctedValue << lshift; + /* + * low bits are cleared because of lshift and high bits are already + * cleared + */ + cmask &= ~mask; + int b = this.buf.get(startByte) & 0xFF; + this.buf.put(startByte, (byte) ((b & mask) | cmask)); + return; + } + + /* head byte */ + currByte = startByte; + cshift = index % BIT_CHAR; + if (cshift > 0) { + mask = ~((~0) << cshift); + cmask = correctedValue << cshift; + cmask &= ~mask; + int b = this.buf.get(currByte) & 0xFF; + this.buf.put(currByte, (byte) ((b & mask) | cmask)); + correctedValue >>>= BIT_CHAR - cshift; + // index += BIT_CHAR - cshift; + currByte++; + } + + /* middle byte(s) */ + for (; currByte < (endByte - 1); currByte++) { + this.buf.put(currByte, (byte) correctedValue); + correctedValue >>>= BIT_CHAR; + } + /* end byte */ + if ((end % BIT_CHAR) > 0) { + mask = (~0) << (end % BIT_CHAR); + cmask = correctedValue & ~mask; + int b = this.buf.get(currByte) & 0xFF; + this.buf.put(currByte, (byte) ((b & mask) | cmask)); + } else { + this.buf.put(currByte, (byte) correctedValue); + } + } + + // ------------------------------------------------------------------------ + // Buffer attributes handling + // ------------------------------------------------------------------------ + + /** + * Can this buffer be read for thus amount of bits? + * + * @param length + * the length in bits to read + * @return does the buffer have enough room to read the next "length" + */ + public boolean canRead(int length) { + if (this.buf == null) { + return false; + } + + if ((this.pos + length) > (this.buf.capacity() * BIT_CHAR)) { + return false; + } + return true; + } + + /** + * Sets the order of the buffer. + * + * @param order + * The order of the buffer. + */ + public void setByteOrder(ByteOrder order) { + this.byteOrder = order; + if (this.buf != null) { + this.buf.order(order); + } + } + + /** + * Sets the order of the buffer. + * + * @return The order of the buffer. + */ + public ByteOrder getByteOrder() { + return this.byteOrder; + } + + /** + * Sets the position in the buffer. + * + * @param newPosition + * The new position of the buffer. + */ + public void position(int newPosition) { + this.pos = newPosition; + } + + /** + * + * Sets the position in the buffer. + * + * @return order The position of the buffer. + */ + public int position() { + return this.pos; + } + + /** + * Sets the byte buffer + * + * @param buf + * the byte buffer + */ + public void setByteBuffer(ByteBuffer buf) { + this.buf = buf; + if (buf != null) { + this.buf.order(this.byteOrder); + } + clear(); + } + + /** + * Gets the byte buffer + * + * @return The byte buffer + */ + public ByteBuffer getByteBuffer() { + return this.buf; + } + + /** + * resets the bitbuffer. + */ + public void clear() { + position(0); + + if (this.buf == null) { + return; + } + this.buf.clear(); + } + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java index 33e655aed8..96c6d06f2b 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF array definiton diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java index 2edc2a9e71..729e155328 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF definiton @@ -98,6 +98,7 @@ public abstract class Definition { * * @param input * the bitbuffer containing the data to read. + * @since 2.0 */ public abstract void read(BitBuffer input); diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java index 98ef3f48c9..f04f1d118c 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java @@ -12,7 +12,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF enum definition. diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java index c94027eb20..4b0153d7f8 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java @@ -11,11 +11,11 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF float definition. - * + * * The definition of a floating point basic data type. It will take the data * from a trace and store it (and make it fit) as a double. * diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java index 194959faa4..6bf0cecc63 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java @@ -14,7 +14,7 @@ package org.eclipse.linuxtools.ctf.core.event.types; import java.nio.ByteOrder; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF integer definition. diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java index 6c95948ce7..b7d9d918ca 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java @@ -12,12 +12,12 @@ package org.eclipse.linuxtools.ctf.core.event.types; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; /** * A CTF sequence definition (a fixed-size array). - * + * * An array where the size is fixed but declared in the trace, unlike array * where it is declared with a literal * diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java index 33a26aa90c..5b5d5bc644 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java @@ -12,11 +12,11 @@ package org.eclipse.linuxtools.ctf.core.event.types; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF string definition (similar to a C null-terminated byte array). - * + * * Strings are an array of bytes of variable size and are terminated by a '\0' * "NULL" character. Their encoding is described in the TSDL meta-data. In * absence of encoding attribute information, the default encoding is UTF-8. diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java index 41fcb66c80..7a837a20dc 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java @@ -16,11 +16,11 @@ import java.util.HashMap; import java.util.List; import java.util.ListIterator; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF structure definition (similar to a C structure). - * + * * A structure is similar to a C structure, it is a compound data type that * contains other datatypes in fields. they are stored in an hashmap and indexed * by names which are strings. diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java index a1dfd95e50..7f1144bb58 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java @@ -15,11 +15,11 @@ package org.eclipse.linuxtools.ctf.core.event.types; import java.util.HashMap; import java.util.Map; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; /** * A CTF variant definition (similar to a C union). - * + * * A variant is similar to a C union, only taking the minimum size of the types, * it is a compound data type that contains other datatypes in fields. they are * stored in an hashmap and indexed by names which are strings. diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java index 97973e7bbb..92e9bbf149 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -39,16 +39,14 @@ import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; import org.eclipse.linuxtools.ctf.core.event.CTFClock; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; /** @@ -278,7 +276,7 @@ public class CTFTrace implements IDefinitionScope { * @param id the StreamInput * @return The index */ - public StreamInputPacketIndex getIndex(StreamInput id){ + StreamInputPacketIndex getIndex(StreamInput id){ if(! indexes.containsKey(id)){ indexes.put(id, new StreamInputPacketIndex()); } @@ -649,6 +647,7 @@ public class CTFTrace implements IDefinitionScope { /** * gets the Environment variables from the trace metadata (See CTF spec) * @return the environment variables in a map form (key value) + * @since 2.0 */ public Map getEnvironment() { return environment; @@ -759,6 +758,7 @@ public class CTFTrace implements IDefinitionScope { * @param cycles * clock cycles since boot * @return time in nanoseconds UTC offset + * @since 2.0 */ public long timestampCyclesToNanos(long cycles) { long retVal = cycles + getOffset(); @@ -776,6 +776,7 @@ public class CTFTrace implements IDefinitionScope { * @param nanos * time in nanoseconds UTC offset * @return clock cycles since boot. + * @since 2.0 */ public long timestampNanoToCycles(long nanos) { long retVal; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java index 70626ed8b6..50a9f9a3ce 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java @@ -19,8 +19,6 @@ import java.util.Vector; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.internal.ctf.core.Activator; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator; /** diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java similarity index 98% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java index bd9234159c..8702243fe0 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java @@ -10,7 +10,7 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.internal.ctf.core.trace; +package org.eclipse.linuxtools.ctf.core.trace; import java.util.HashMap; import java.util.HashSet; @@ -18,13 +18,13 @@ import java.util.Set; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** * Stream *

* Represents a stream in a trace. + * @since 2.0 */ public class Stream { diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java similarity index 98% rename from org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java rename to org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java index fd7baefc0f..6e15940ddb 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java @@ -10,7 +10,7 @@ * Contributors: Simon Marchi - Initial API and implementation *******************************************************************************/ -package org.eclipse.linuxtools.internal.ctf.core.trace; +package org.eclipse.linuxtools.ctf.core.trace; import java.io.File; import java.io.IOException; @@ -19,6 +19,7 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import java.util.UUID; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition; @@ -27,14 +28,14 @@ import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; -import org.eclipse.linuxtools.ctf.core.trace.Utils; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; +import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; /** * StreamInput *

* Represents a trace file that belongs to a certain stream. + * @since 2.0 */ public class StreamInput implements IDefinitionScope { @@ -118,7 +119,7 @@ public class StreamInput implements IDefinitionScope { * * @return the stream input Index */ - public StreamInputPacketIndex getIndex() { + StreamInputPacketIndex getIndex() { return index; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java index 9dd65b3ab3..ede6acd343 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -19,6 +19,7 @@ import java.util.HashMap; import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; @@ -26,8 +27,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.SimpleDatatypeDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; /** @@ -156,7 +155,7 @@ public class StreamInputPacketReader implements IDefinitionScope { * * @return the current packet */ - public StreamInputPacketIndexEntry getCurrentPacket() { + StreamInputPacketIndexEntry getCurrentPacket() { return this.currentPacket; } @@ -202,7 +201,7 @@ public class StreamInputPacketReader implements IDefinitionScope { * @param currentPacket * The index entry of the packet to switch to. */ - public void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) { + void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) { this.currentPacket = currentPacket; if (this.currentPacket != null) { diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java index e18e068018..272fb33b22 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java @@ -16,7 +16,6 @@ import java.nio.ByteOrder; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; /** diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java deleted file mode 100644 index 7440b39c68..0000000000 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/io/BitBuffer.java +++ /dev/null @@ -1,558 +0,0 @@ -/*******************************************************************************. - * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others - * - * All rights reserved. This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Matthew Khouzam - Initial Design and implementation - * Contributors: Francis Giraldeau - Initial API and implementation - * Contributors: Philippe Proulx - Some refinement and optimization - *******************************************************************************/ - - package org.eclipse.linuxtools.internal.ctf.core.event.io; - - import java.nio.BufferOverflowException; - import java.nio.ByteBuffer; - import java.nio.ByteOrder; - - /** - * BitBuffer - *

- * A bitwise buffer capable of accessing fields with bit offsets. - */ - public class BitBuffer { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /* default bit width */ - /** 8 bits to a char */ - public static final int BIT_CHAR = 8; - /** 16 bits to a short */ - public static final int BIT_SHORT = 16; - /** 32 bits to an int */ - public static final int BIT_INT = 32; - /** 32 bits to a float */ - public static final int BIT_FLOAT = 32; - /** 64 bits to a long */ - public static final int BIT_LONG = 64; - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ - - private ByteBuffer buf; - private int pos; - private ByteOrder byteOrder; - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - /** - * Default constructor, makes a bigendian buffer - */ - public BitBuffer() { - this(null, ByteOrder.BIG_ENDIAN); - } - - /** - * Constructor, makes a bigendian buffer - * - * @param buf - * the bytebuffer to read - */ - public BitBuffer(ByteBuffer buf) { - this(buf, ByteOrder.BIG_ENDIAN); - } - - /** - * Constructor that is fully parametrisable - * - * @param buf - * the buffer to read - * @param order - * the byte order (big endian, little endian, network?) - */ - public BitBuffer(ByteBuffer buf, ByteOrder order) { - setByteBuffer(buf); - setByteOrder(order); - position(0); - } - - // ------------------------------------------------------------------------ - // 'Get' operations on buffer - // ------------------------------------------------------------------------ - - /** - * Relative get method for reading 32-bit integer. - * - * Reads next four bytes from the current bit position according to current - * byte order. - * - * @return The int value read from the buffer - */ - public int getInt() { - int val = getInt(BIT_INT, true); - return val; - } - - /** - * Relative get method for reading integer of length bits. - * - * Reads length bits starting at the current position. The result is - * signed extended if signed is true. The current position is - * increased of length bits. - * - * @param length - * The length in bits of this integer - * @param signed - * The sign extended flag - * @return The int value read from the buffer - */ - public int getInt(int length, boolean signed) { - int val = 0; - if (!canRead(length)) { - throw new BufferOverflowException(); - } - if (length == 0) { - return 0; - } - boolean gotIt = false; - - // Fall back to fast ByteBuffer reader if we want to read byte-aligned bytes - if (this.pos % BitBuffer.BIT_CHAR == 0) { - switch (length) { - case BitBuffer.BIT_CHAR: - // Byte - if (signed) { - val = this.buf.get(this.pos / 8); - } else { - val = (this.buf.get(this.pos / 8)) & 0xff; - } - gotIt = true; - break; - - case BitBuffer.BIT_SHORT: - // Word - if (signed) { - val = this.buf.getShort(this.pos / 8); - } else { - short a = this.buf.getShort(this.pos / 8); - val = a & 0xffff; - } - gotIt = true; - break; - - case BitBuffer.BIT_INT: - // Double word - val = this.buf.getInt(this.pos / 8); - gotIt = true; - break; - - default: - break; - } - } - if (!gotIt) { - // Nothing read yet: use longer methods - if (this.byteOrder == ByteOrder.LITTLE_ENDIAN) { - val = getIntLE(this.pos, length, signed); - } else { - val = getIntBE(this.pos, length, signed); - } - } - this.pos += length; - - return val; - } - - private int getIntBE(int index, int length, boolean signed) { - assert ((length > 0) && (length <= BIT_INT)); - int end = index + length; - int startByte = index / BIT_CHAR; - int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; - int currByte, lshift, cshift, mask, cmask, cache; - int value = 0; - - currByte = startByte; - cache = this.buf.get(currByte) & 0xFF; - boolean isNeg = (cache & (1 << (BIT_CHAR - (index % BIT_CHAR) - 1))) != 0; - if (signed && isNeg) { - value = ~0; - } - if (startByte == (endByte - 1)) { - cmask = cache >>> ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR); - if (((length) % BIT_CHAR) > 0) { - mask = ~((~0) << length); - cmask &= mask; - } - value <<= length; - value |= cmask; - return value; - } - cshift = index % BIT_CHAR; - if (cshift > 0) { - mask = ~((~0) << (BIT_CHAR - cshift)); - cmask = cache & mask; - lshift = BIT_CHAR - cshift; - value <<= lshift; - value |= cmask; - // index += lshift; - currByte++; - } - for (; currByte < (endByte - 1); currByte++) { - value <<= BIT_CHAR; - value |= this.buf.get(currByte) & 0xFF; - } - lshift = end % BIT_CHAR; - if (lshift > 0) { - mask = ~((~0) << lshift); - cmask = this.buf.get(currByte) & 0xFF; - cmask >>>= BIT_CHAR - lshift; - cmask &= mask; - value <<= lshift; - value |= cmask; - } else { - value <<= BIT_CHAR; - value |= this.buf.get(currByte) & 0xFF; - } - return value; - } - - private int getIntLE(int index, int length, boolean signed) { - assert ((length > 0) && (length <= BIT_INT)); - int end = index + length; - int startByte = index / BIT_CHAR; - int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; - int currByte, lshift, cshift, mask, cmask, cache, mod; - int value = 0; - - currByte = endByte - 1; - cache = buf.get(currByte) & 0xFF; - mod = end % BIT_CHAR; - lshift = (mod > 0) ? mod : BIT_CHAR; - boolean isNeg = (cache & (1 << (lshift - 1))) != 0; - if (signed && isNeg) { - value = ~0; - } - if (startByte == (endByte - 1)) { - cmask = cache >>> (index % BIT_CHAR); - if (((length) % BIT_CHAR) > 0) { - mask = ~((~0) << length); - cmask &= mask; - } - value <<= length; - value |= cmask; - return value; - } - cshift = end % BIT_CHAR; - if (cshift > 0) { - mask = ~((~0) << cshift); - cmask = cache & mask; - value <<= cshift; - value |= cmask; - // end -= cshift; - currByte--; - } - for (; currByte >= (startByte + 1); currByte--) { - value <<= BIT_CHAR; - value |= buf.get(currByte) & 0xFF; - } - lshift = index % BIT_CHAR; - if (lshift > 0) { - mask = ~((~0) << (BIT_CHAR - lshift)); - cmask = buf.get(currByte) & 0xFF; - cmask >>>= lshift; - cmask &= mask; - value <<= (BIT_CHAR - lshift); - value |= cmask; - } else { - value <<= BIT_CHAR; - value |= buf.get(currByte) & 0xFF; - } - return value; - } - - // ------------------------------------------------------------------------ - // 'Put' operations on buffer - // ------------------------------------------------------------------------ - - /** - * Relative put method to write signed 32-bit integer. - * - * Write four bytes starting from current bit position in the buffer - * according to the current byte order. The current position is increased of - * length bits. - * - * @param value - * The int value to write - */ - public void putInt(int value) { - putInt(BIT_INT, value); - } - - /** - * Relative put method to write length bits integer. - * - * Writes length lower-order bits from the provided value, - * starting from current bit position in the buffer. Sequential bytes are - * written according to the current byte order. The sign bit is carried to - * the MSB if signed is true. The sign bit is included in length. The - * current position is increased of length. - * - * @param length - * The number of bits to write - * @param value - * The value to write - */ - public void putInt(int length, int value) { - final int curPos = this.pos; - - if (!canRead(length)) { - throw new BufferOverflowException(); - } - if (length == 0) { - return; - } - if (this.byteOrder == ByteOrder.LITTLE_ENDIAN) { - putIntLE(curPos, length, value); - } else { - putIntBE(curPos, length, value); - } - this.pos += length; - } - - private void putIntBE(int index, int length, int value) { - assert ((length > 0) && (length <= BIT_INT)); - int end = index + length; - int startByte = index / BIT_CHAR; - int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; - int currByte, lshift, cshift, mask, cmask; - int correctedValue = value; - - /* - * mask v high bits. Works for unsigned and two complement signed - * numbers which value do not overflow on length bits. - */ - - if (length < BIT_INT) { - correctedValue &= ~(~0 << length); - } - - /* sub byte */ - if (startByte == (endByte - 1)) { - lshift = (BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR; - mask = ~((~0) << lshift); - if ((index % BIT_CHAR) > 0) { - mask |= (~(0)) << (BIT_CHAR - (index % BIT_CHAR)); - } - cmask = correctedValue << lshift; - /* - * low bits are cleared because of lshift and high bits are already - * cleared - */ - cmask &= ~mask; - int b = this.buf.get(startByte) & 0xFF; - this.buf.put(startByte, (byte) ((b & mask) | cmask)); - return; - } - - /* head byte contains MSB */ - currByte = endByte - 1; - cshift = end % BIT_CHAR; - if (cshift > 0) { - lshift = BIT_CHAR - cshift; - mask = ~((~0) << lshift); - cmask = correctedValue << lshift; - cmask &= ~mask; - int b = this.buf.get(currByte) & 0xFF; - this.buf.put(currByte, (byte) ((b & mask) | cmask)); - correctedValue >>>= cshift; - // end -= cshift; - currByte--; - } - - /* middle byte(s) */ - for (; currByte >= (startByte + 1); currByte--) { - this.buf.put(currByte, (byte) correctedValue); - correctedValue >>>= BIT_CHAR; - } - /* end byte contains LSB */ - if ((index % BIT_CHAR) > 0) { - mask = (~0) << (BIT_CHAR - (index % BIT_CHAR)); - cmask = correctedValue & ~mask; - int b = this.buf.get(currByte) & 0xFF; - this.buf.put(currByte, (byte) ((b & mask) | cmask)); - } else { - this.buf.put(currByte, (byte) correctedValue); - } - } - - private void putIntLE(int index, int length, int value) { - assert ((length > 0) && (length <= BIT_INT)); - int end = index + length; - int startByte = index / BIT_CHAR; - int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR; - int currByte, lshift, cshift, mask, cmask; - int correctedValue = value; - - /* - * mask v high bits. Works for unsigned and two complement signed - * numbers which value do not overflow on length bits. - */ - - if (length < BIT_INT) { - correctedValue &= ~(~0 << length); - } - - /* sub byte */ - if (startByte == (endByte - 1)) { - lshift = index % BIT_CHAR; - mask = ~((~0) << lshift); - if ((end % BIT_CHAR) > 0) { - mask |= (~(0)) << (end % BIT_CHAR); - } - cmask = correctedValue << lshift; - /* - * low bits are cleared because of lshift and high bits are already - * cleared - */ - cmask &= ~mask; - int b = this.buf.get(startByte) & 0xFF; - this.buf.put(startByte, (byte) ((b & mask) | cmask)); - return; - } - - /* head byte */ - currByte = startByte; - cshift = index % BIT_CHAR; - if (cshift > 0) { - mask = ~((~0) << cshift); - cmask = correctedValue << cshift; - cmask &= ~mask; - int b = this.buf.get(currByte) & 0xFF; - this.buf.put(currByte, (byte) ((b & mask) | cmask)); - correctedValue >>>= BIT_CHAR - cshift; - // index += BIT_CHAR - cshift; - currByte++; - } - - /* middle byte(s) */ - for (; currByte < (endByte - 1); currByte++) { - this.buf.put(currByte, (byte) correctedValue); - correctedValue >>>= BIT_CHAR; - } - /* end byte */ - if ((end % BIT_CHAR) > 0) { - mask = (~0) << (end % BIT_CHAR); - cmask = correctedValue & ~mask; - int b = this.buf.get(currByte) & 0xFF; - this.buf.put(currByte, (byte) ((b & mask) | cmask)); - } else { - this.buf.put(currByte, (byte) correctedValue); - } - } - - // ------------------------------------------------------------------------ - // Buffer attributes handling - // ------------------------------------------------------------------------ - - /** - * Can this buffer be read for thus amount of bits? - * - * @param length - * the length in bits to read - * @return does the buffer have enough room to read the next "length" - */ - public boolean canRead(int length) { - if (this.buf == null) { - return false; - } - - if ((this.pos + length) > (this.buf.capacity() * BIT_CHAR)) { - return false; - } - return true; - } - - /** - * Sets the order of the buffer. - * - * @param order - * The order of the buffer. - */ - public void setByteOrder(ByteOrder order) { - this.byteOrder = order; - if (this.buf != null) { - this.buf.order(order); - } - } - - /** - * Sets the order of the buffer. - * - * @return The order of the buffer. - */ - public ByteOrder getByteOrder() { - return this.byteOrder; - } - - /** - * Sets the position in the buffer. - * - * @param newPosition - * The new position of the buffer. - */ - public void position(int newPosition) { - this.pos = newPosition; - } - - /** - * - * Sets the position in the buffer. - * - * @return order The position of the buffer. - */ - public int position() { - return this.pos; - } - - /** - * Sets the byte buffer - * - * @param buf - * the byte buffer - */ - public void setByteBuffer(ByteBuffer buf) { - this.buf = buf; - if (buf != null) { - this.buf.order(this.byteOrder); - } - clear(); - } - - /** - * Gets the byte buffer - * - * @return The byte buffer - */ - public ByteBuffer getByteBuffer() { - return this.buf; - } - - /** - * resets the bitbuffer. - */ - public void clear() { - position(0); - - if (this.buf == null) { - return; - } - this.buf.clear(); - } - - } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java index 84e5bcfc2f..e65573d52f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java @@ -36,9 +36,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.ctf.parser.CTFParser; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; /** * IOStructGen diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java index 300a27c68d..61fac4df61 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertNotNull; import java.nio.ByteOrder; +import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; @@ -28,7 +29,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField; import org.junit.After; import org.junit.Before; -- 2.34.1