ctf: Rename Stream* classes to CTFStream*
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 21 May 2014 21:11:13 +0000 (17:11 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 22 May 2014 13:44:39 +0000 (09:44 -0400)
"Stream" will become very confusing with java.util.stream.Stream when
Java 8 comes. Rename those classes to CTFStream, for better namespacing.

Change-Id: Ifb239af0366553472463c50d8e6ed899e002f880
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/27067
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
33 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTimestampComparatorTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamTest.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/TestAll.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/IEventDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConsumer.java
org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfIterator.java

diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java
new file mode 100644 (file)
index 0000000..9ec59d0
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
+ * class <code>{@link StreamInputPacketIndexEntry}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+public class CTFStreamInputPacketIndexEntryTest {
+
+    private StreamInputPacketIndexEntry fixture;
+
+    /**
+     * Perform pre-test initialization.
+     */
+    @Before
+    public void setUp() {
+        fixture = new StreamInputPacketIndexEntry(1L);
+    }
+
+    /**
+     * Run the StreamInputPacketIndexEntry(long) constructor test.
+     */
+    @Test
+    public void testStreamInputPacketIndexEntry_1() {
+        String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1, " +
+                "timestampBegin=0, timestampEnd=0]";
+
+        assertNotNull(fixture);
+        assertEquals(expectedResult, fixture.toString());
+    }
+
+    /**
+     * Run the String toString() method test.
+     */
+    @Test
+    public void testToString() {
+        String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1,"+
+                " timestampBegin=1, timestampEnd=1]";
+
+
+        fixture.setContentSizeBits(1);
+        fixture.setDataOffsetBits(1);
+        fixture.setTimestampEnd(1L);
+        fixture.setPacketSizeBits(1);
+        fixture.setTimestampBegin(1L);
+
+        assertEquals(expectedResult, fixture.toString());
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputPacketIndexTest.java
new file mode 100644 (file)
index 0000000..a9aef8b
--- /dev/null
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Collection;
+import java.util.ListIterator;
+
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>StreamInputPacketIndexTest</code> contains tests for the
+ * class <code>{@link StreamInputPacketIndex}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class CTFStreamInputPacketIndexTest {
+
+    private StreamInputPacketIndex fixture;
+    private StreamInputPacketIndexEntry entry;
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp() throws CTFReaderException {
+        fixture = new StreamInputPacketIndex();
+        fixture.addEntry(new StreamInputPacketIndexEntry(1L));
+        entry = new StreamInputPacketIndexEntry(1L);
+    }
+
+    /**
+     * Run the StreamInputPacketIndex() constructor test.
+     */
+    @Test
+    public void testStreamInputPacketIndex() {
+        assertNotNull(fixture);
+    }
+
+    /**
+     * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
+     * specifying only 1 parameter to the entry.
+     *
+     * @throws CTFReaderException
+     */
+    @Test
+    public void testAddEntry_1param() throws CTFReaderException {
+        entry.setPacketSizeBits(0);
+        fixture.addEntry(entry);
+    }
+
+    /**
+     * Run the void addEntry(StreamInputPacketIndexEntry) method test by
+     * specifying 2 parameters to the entry.
+     *
+     * @throws CTFReaderException
+     */
+    @Test
+    public void testAddEntry_2params() throws CTFReaderException {
+        entry.setPacketSizeBits(1);
+        entry.setContentSizeBits(0);
+        fixture.addEntry(entry);
+    }
+
+    /**
+     * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
+     * specifying all 4 parameters to the entry.
+     *
+     * @throws CTFReaderException
+     */
+    @Test
+    public void testAddEntry_4params() throws CTFReaderException {
+        entry.setTimestampBegin(1L);
+        entry.setPacketSizeBits(1);
+        entry.setContentSizeBits(1);
+        entry.setTimestampEnd(1L);
+        fixture.addEntry(entry);
+    }
+
+    /**
+     * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
+     */
+    @Test
+    public void testGetEntries() {
+        Collection<StreamInputPacketIndexEntry> result = fixture.getEntries();
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+    }
+
+    /**
+     * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
+     * test, with no parameter to listIterator().
+     */
+    @Test
+    public void testListIterator_noparam() {
+        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator();
+
+        assertNotNull(result);
+        assertEquals(true, result.hasNext());
+        assertEquals(-1, result.previousIndex());
+        assertEquals(false, result.hasPrevious());
+        assertEquals(0, result.nextIndex());
+    }
+
+    /**
+     * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
+     * test, with n = 1.
+     */
+    @Test
+    public void testListIterator_withparam() {
+        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1);
+
+        assertNotNull(result);
+        assertEquals(false, result.hasNext());
+        assertEquals(0, result.previousIndex());
+        assertEquals(true, result.hasPrevious());
+        assertEquals(1, result.nextIndex());
+        assertEquals(false, result.hasNext());
+    }
+
+    /**
+     * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
+     * test with a valid timestamp.
+     */
+    @Test
+    public void testSearch_valid() {
+        ListIterator<StreamInputPacketIndexEntry> result = fixture.search(1L);
+
+        assertNotNull(result);
+        assertEquals(true, result.hasNext());
+        assertEquals(-1, result.previousIndex());
+        assertEquals(false, result.hasPrevious());
+        assertEquals(0, result.nextIndex());
+    }
+
+    /**
+     * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
+     * test with an invalid timestamp.
+     */
+    @Test(expected = java.lang.IllegalArgumentException.class)
+    public void testSearch_invalid() {
+        ListIterator<StreamInputPacketIndexEntry> result = fixture.search(-1L);
+
+        assertNotNull(result);
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTest.java
new file mode 100644 (file)
index 0000000..ab9a89a
--- /dev/null
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.util.Set;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+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.tests.shared.CtfTestTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFResponse;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The class <code>StreamInputReaderTest</code> contains tests for the class
+ * <code>{@link CTFStreamInputReader}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class CTFStreamInputReaderTest {
+
+    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
+
+    private CTFStreamInputReader fixture;
+
+    private static ImmutableList<String> wrap(String s) {
+        return ImmutableList.<String> builder().add(s).build();
+    }
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp() throws CTFReaderException {
+        fixture = getStreamInputReader();
+        fixture.setName(1);
+        fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
+                getStreamInputReader(), 0, null, null,
+                new StructDefinition(
+                        new StructDeclaration(0),
+                        null,
+                        "packet",
+                        wrap( "field" ),
+                        new Definition[] { new StringDefinition(new StringDeclaration(), null, "field", "test") }),
+                null)
+                );
+    }
+
+    private static CTFStreamInputReader getStreamInputReader() throws CTFReaderException {
+        assumeTrue(testTrace.exists());
+        CTFTrace trace = testTrace.getTrace();
+        CTFStream s = trace.getStream((long) 0);
+        Set<CTFStreamInput> streamInput = s.getStreamInputs();
+        CTFStreamInputReader retVal = null;
+        for (CTFStreamInput si : streamInput) {
+            /*
+             * For the tests, we'll use the stream input corresponding to the
+             * CPU 0
+             */
+            if (si.getFilename().endsWith("0_0")) {
+                retVal = new CTFStreamInputReader(si);
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Run the StreamInputReader(StreamInput) constructor test, with a valid
+     * trace.
+     */
+    @Test
+    public void testStreamInputReader_valid() {
+        assertNotNull(fixture);
+    }
+
+    /**
+     * Run the StreamInputReader(StreamInput) constructor test, with an invalid
+     * trace.
+     *
+     * @throws CTFReaderException
+     */
+    @Test(expected = CTFReaderException.class)
+    public void testStreamInputReader_invalid() throws CTFReaderException {
+        CTFStreamInput streamInput = new CTFStreamInput(
+                new CTFStream(new CTFTrace("")), new File(""));
+
+        CTFStreamInputReader result = new CTFStreamInputReader(streamInput);
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the int getCPU() method test.
+     */
+    @Test
+    public void testGetCPU() {
+        int result = fixture.getCPU();
+        assertEquals(0, result);
+    }
+
+    /**
+     * Run the EventDefinition getCurrentEvent() method test.
+     */
+    @Test
+    public void testGetCurrentEvent() {
+        EventDefinition result = fixture.getCurrentEvent();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the StructDefinition getCurrentPacketContext() method test.
+     */
+    @Test
+    public void testGetCurrentPacketContext() {
+        StructDefinition result = fixture.getCurrentEvent().getPacketContext();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the int getName() method test.
+     */
+    @Test
+    public void testGetName() {
+        int result = fixture.getName();
+        assertEquals(1, result);
+    }
+
+    /**
+     * Run the void goToLastEvent() method test.
+     *
+     * @throws CTFReaderException
+     *             error
+     */
+    @Test
+    public void testGoToLastEvent1() throws CTFReaderException {
+        final long endTimestamp = goToEnd();
+        final long endTime = 4287422460315L;
+        assertEquals(endTime, endTimestamp);
+    }
+
+    /**
+     * Run the void goToLastEvent() method test.
+     *
+     * @throws CTFReaderException
+     *             error
+     */
+    @Test
+    public void testGoToLastEvent2() throws CTFReaderException {
+        long timestamp = -1;
+        while (fixture.readNextEvent().equals(CTFResponse.OK)) {
+            timestamp = fixture.getCurrentEvent().getTimestamp();
+        }
+        long endTimestamp = goToEnd();
+        assertEquals(0, timestamp - endTimestamp);
+    }
+
+    private long goToEnd() throws CTFReaderException {
+        fixture.goToLastEvent();
+        return fixture.getCurrentEvent().getTimestamp();
+    }
+
+    /**
+     * Run the boolean readNextEvent() method test.
+     *
+     * @throws CTFReaderException
+     *             error
+     */
+    @Test
+    public void testReadNextEvent() throws CTFReaderException {
+        assertEquals(CTFResponse.OK, fixture.readNextEvent());
+    }
+
+    /**
+     * Run the void seek(long) method test. Seek by direct timestamp
+     *
+     * @throws CTFReaderException
+     *             error
+     */
+    @Test
+    public void testSeek_timestamp() throws CTFReaderException {
+        long timestamp = 1L;
+        fixture.seek(timestamp);
+    }
+
+    /**
+     * Run the seek test. Seek by passing an EventDefinition to which we've
+     * given the timestamp we want.
+     *
+     * @throws CTFReaderException
+     */
+    @Test
+    public void testSeek_eventDefinition() throws CTFReaderException {
+        EventDefinition eventDefinition = new EventDefinition(
+                new EventDeclaration(), getStreamInputReader(), 1L, null, null, null, null);
+        fixture.setCurrentEvent(eventDefinition);
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTimestampComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputReaderTimestampComparatorTest.java
new file mode 100644 (file)
index 0000000..84ecfb4
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>StreamInputReaderTimestampComparatorTest</code> contains
+ * tests for the class <code>{@link StreamInputReaderTimestampComparator}</code>
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+public class CTFStreamInputReaderTimestampComparatorTest {
+
+    private StreamInputReaderTimestampComparator fixture;
+
+    /**
+     * Perform pre-test initialization.
+     */
+    @Before
+    public void setUp() {
+        fixture = new StreamInputReaderTimestampComparator();
+    }
+
+    /**
+     * Run the StreamInputReaderTimestampComparator() constructor test.
+     */
+    @Test
+    public void testStreamInputReaderTimestampComparator_1() {
+        assertNotNull(fixture);
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamInputTest.java
new file mode 100644 (file)
index 0000000..0e1e80d
--- /dev/null
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>StreamInputTest</code> contains tests for the class
+ * <code>{@link CTFStreamInput}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class CTFStreamInputTest {
+
+    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
+
+    private CTFStreamInput fixture;
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp() throws CTFReaderException {
+        assumeTrue(testTrace.exists());
+        fixture = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
+        fixture.setTimestampEnd(1L);
+    }
+
+    private static File createFile() {
+        File path = new File(testTrace.getPath());
+        return path.listFiles(new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                if (name.contains("hann")) {
+                    return true;
+                }
+                return false;
+            }
+        })[0];
+    }
+
+    /**
+     * Run the StreamInput(Stream,FileChannel,File) constructor test.
+     */
+    @Test
+    public void testStreamInput() {
+        assertNotNull(fixture);
+    }
+
+    /**
+     * Run the String getFilename() method test.
+     */
+    @Test
+    public void testGetFilename() {
+        String result = fixture.getFilename();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the String getPath() method test.
+     */
+    @Test
+    public void testGetPath() {
+        String result = fixture.getScopePath().toString();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Stream getStream() method test.
+     */
+    @Test
+    public void testGetStream() {
+        CTFStream result = fixture.getStream();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the long getTimestampEnd() method test.
+     */
+    @Test
+    public void testGetTimestampEnd() {
+        long result = fixture.getTimestampEnd();
+        assertTrue(0L < result);
+    }
+
+    /**
+     * Run the Definition lookupDefinition(String) method test.
+     */
+    @Test
+    public void testLookupDefinition() {
+        Definition result = fixture.lookupDefinition("id");
+        assertNull(result);
+    }
+
+    /**
+     * Run the void setTimestampEnd(long) method test.
+     */
+    @Test
+    public void testSetTimestampEnd() {
+        fixture.setTimestampEnd(1L);
+        assertEquals(fixture.getTimestampEnd(), 1L);
+    }
+
+    CTFStreamInput s1;
+    CTFStreamInput s2;
+
+    @Test
+    public void testEquals1() throws CTFReaderException {
+        s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
+                createFile());
+        assertFalse(s1.equals(null));
+    }
+
+    @Test
+    public void testEquals2() throws CTFReaderException {
+        s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
+                createFile());
+        assertFalse(s1.equals(new Long(23L)));
+
+    }
+
+    @Test
+    public void testEquals3() throws CTFReaderException {
+        s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
+                createFile());
+        assertEquals(s1, s1);
+
+    }
+
+    @Test
+    public void testEquals4() throws CTFReaderException {
+        s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
+                createFile());
+        s2 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
+                createFile());
+        assertEquals(s1, s2);
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFStreamTest.java
new file mode 100644 (file)
index 0000000..5b9abed
--- /dev/null
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * 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 API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.trace;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>StreamTest</code> contains tests for the class
+ * <code>{@link CTFStream}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class CTFStreamTest {
+
+    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
+
+    private CTFStream fixture;
+
+    /**
+     * Perform pre-test initialization.
+     *
+     * @throws CTFReaderException
+     */
+    @Before
+    public void setUp() throws CTFReaderException {
+        assumeTrue(testTrace.exists());
+        fixture = new CTFStream(testTrace.getTrace());
+        fixture.setEventContext(new StructDeclaration(1L));
+        fixture.setPacketContext(new StructDeclaration(1L));
+        fixture.setEventHeader(new StructDeclaration(1L));
+        fixture.setId(1L);
+        fixture.addInput(new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile()));
+    }
+
+    private static File createFile() {
+        File path = new File(testTrace.getPath());
+        return path.listFiles(new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                if (name.contains("hann")) {
+                    return true;
+                }
+                return false;
+            }
+        })[0];
+    }
+
+    /**
+     * Run the Stream(CTFTrace) constructor test.
+     *
+     * @throws CTFReaderException
+     */
+    @Test
+    public void testStream() throws CTFReaderException {
+        CTFTrace trace = testTrace.getTrace();
+        CTFStream result = new CTFStream(trace);
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the void addEvent(EventDeclaration) method test with the basic event.
+     *
+     * @throws ParseException
+     */
+    @Test
+    public void testAddEvent_base() throws ParseException {
+        EventDeclaration event = new EventDeclaration();
+        fixture.addEvent(event);
+    }
+
+    /**
+     * Run the boolean eventContextIsSet() method test.
+     */
+    @Test
+    public void testEventContextIsSet() {
+        assertTrue(fixture.isEventContextSet());
+    }
+
+    /**
+     * Run the boolean eventContextIsSet() method test.
+     */
+    @Test
+    public void testToString() {
+        assertNotNull(fixture.toString());
+    }
+
+    /**
+     * Run the boolean eventHeaderIsSet() method test.
+     */
+    @Test
+    public void testEventHeaderIsSet() {
+        assertTrue(fixture.isEventHeaderSet());
+    }
+
+    /**
+     * Run the StructDeclaration getEventContextDecl() method test.
+     */
+    @Test
+    public void testGetEventContextDecl() {
+        assertNotNull(fixture.getEventContextDecl());
+    }
+
+    /**
+     * Run the StructDeclaration getEventHeaderDecl() method test.
+     */
+    @Test
+    public void testGetEventHeaderDecl() {
+        assertNotNull(fixture.getEventHeaderDecl());
+    }
+
+    /**
+     * Run the HashMap<Long, EventDeclaration> getEvents() method test.
+     */
+    @Test
+    public void testGetEvents() {
+        Map<Long, IEventDeclaration> result = fixture.getEvents();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Long getId() method test.
+     */
+    @Test
+    public void testGetId() {
+        Long result = fixture.getId();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the StructDeclaration getPacketContextDecl() method test.
+     */
+    @Test
+    public void testGetPacketContextDecl() {
+        StructDeclaration result = fixture.getPacketContextDecl();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the Set<StreamInput> getStreamInputs() method test.
+     */
+    @Test
+    public void testGetStreamInputs() {
+        Set<CTFStreamInput> result = fixture.getStreamInputs();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the CTFTrace getTrace() method test.
+     */
+    @Test
+    public void testGetTrace() {
+        CTFTrace result = fixture.getTrace();
+        assertNotNull(result);
+    }
+
+    /**
+     * Run the boolean idIsSet() method test.
+     */
+    @Test
+    public void testIdIsSet() {
+        boolean result = fixture.isIdSet();
+        assertTrue(result);
+    }
+
+    /**
+     * Run the boolean packetContextIsSet() method test.
+     */
+    @Test
+    public void testPacketContextIsSet() {
+        boolean result = fixture.isPacketContextSet();
+        assertTrue(result);
+    }
+
+    /**
+     * Run the void setEventContext(StructDeclaration) method test.
+     */
+    @Test
+    public void testSetEventContext() {
+        StructDeclaration eventContext = new StructDeclaration(1L);
+        fixture.setEventContext(eventContext);
+    }
+
+    /**
+     * Run the void setEventHeader(StructDeclaration) method test.
+     */
+    @Test
+    public void testSetEventHeader() {
+        StructDeclaration eventHeader = new StructDeclaration(1L);
+        fixture.setEventHeader(eventHeader);
+    }
+
+    /**
+     * Run the void setId(long) method test.
+     */
+    @Test
+    public void testSetId() {
+        long id = 1L;
+        fixture.setId(id);
+    }
+
+    /**
+     * Run the void setPacketContext(StructDeclaration) method test.
+     */
+    @Test
+    public void testSetPacketContext() {
+        StructDeclaration packetContext = new StructDeclaration(1L);
+        fixture.setPacketContext(packetContext);
+    }
+}
\ No newline at end of file
index 7d12edf7f0ae14c24414b18d905886697eba08f6..3eb60d2779ec2c126931c6a906a62219d37f128b 100644 (file)
@@ -31,7 +31,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
 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.CTFStream;
 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
 import org.junit.Before;
 import org.junit.Test;
@@ -113,7 +113,7 @@ public class CTFTraceTest {
 
         // Add a stream
         try {
-            Stream stream = new Stream(testTrace.getTrace());
+            CTFStream stream = new CTFStream(testTrace.getTrace());
             stream.setId(1234);
             fixture.addStream(stream);
         } catch (CTFReaderException e) {
@@ -187,7 +187,7 @@ public class CTFTraceTest {
     @Test
     public void testGetStream() {
         Long id = new Long(0L);
-        Stream result = fixture.getStream(id);
+        CTFStream result = fixture.getStream(id);
         assertNotNull(result);
     }
 
index 45a712c92095bc783c3843dc0bc8e66178d07125..105adb7850186c7daa6c8d437acff1149ee12b5a 100644 (file)
@@ -24,7 +24,7 @@ import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.Metadata;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -188,12 +188,12 @@ public class MetadataTest {
     protected CTFTrace testSingleFragment() throws CTFReaderException {
         fixture = new Metadata();
         CTFTrace trace = fixture.getTrace();
-        for (Stream s : trace.getStreams()) {
+        for (CTFStream s : trace.getStreams()) {
             fail("This should be empty, has" + s.toString());
         }
         fixture.parseText(mdStart);
         int count = 0;
-        for (Stream s : trace.getStreams()) {
+        for (CTFStream s : trace.getStreams()) {
             count++;
             assertNotNull(s);
         }
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
deleted file mode 100644 (file)
index 07a1b44..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
- * class <code>{@link StreamInputPacketIndexEntry}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class StreamInputPacketIndexEntryTest {
-
-    private StreamInputPacketIndexEntry fixture;
-
-    /**
-     * Perform pre-test initialization.
-     */
-    @Before
-    public void setUp() {
-        fixture = new StreamInputPacketIndexEntry(1L);
-    }
-
-    /**
-     * Run the StreamInputPacketIndexEntry(long) constructor test.
-     */
-    @Test
-    public void testStreamInputPacketIndexEntry_1() {
-        String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1, " +
-                "timestampBegin=0, timestampEnd=0]";
-
-        assertNotNull(fixture);
-        assertEquals(expectedResult, fixture.toString());
-    }
-
-    /**
-     * Run the String toString() method test.
-     */
-    @Test
-    public void testToString() {
-        String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1,"+
-                " timestampBegin=1, timestampEnd=1]";
-
-
-        fixture.setContentSizeBits(1);
-        fixture.setDataOffsetBits(1);
-        fixture.setTimestampEnd(1L);
-        fixture.setPacketSizeBits(1);
-        fixture.setTimestampBegin(1L);
-
-        assertEquals(expectedResult, fixture.toString());
-    }
-}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexTest.java
deleted file mode 100644 (file)
index c603811..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Collection;
-import java.util.ListIterator;
-
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputPacketIndexTest</code> contains tests for the
- * class <code>{@link StreamInputPacketIndex}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class StreamInputPacketIndexTest {
-
-    private StreamInputPacketIndex fixture;
-    private StreamInputPacketIndexEntry entry;
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        fixture = new StreamInputPacketIndex();
-        fixture.addEntry(new StreamInputPacketIndexEntry(1L));
-        entry = new StreamInputPacketIndexEntry(1L);
-    }
-
-    /**
-     * Run the StreamInputPacketIndex() constructor test.
-     */
-    @Test
-    public void testStreamInputPacketIndex() {
-        assertNotNull(fixture);
-    }
-
-    /**
-     * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
-     * specifying only 1 parameter to the entry.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testAddEntry_1param() throws CTFReaderException {
-        entry.setPacketSizeBits(0);
-        fixture.addEntry(entry);
-    }
-
-    /**
-     * Run the void addEntry(StreamInputPacketIndexEntry) method test by
-     * specifying 2 parameters to the entry.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testAddEntry_2params() throws CTFReaderException {
-        entry.setPacketSizeBits(1);
-        entry.setContentSizeBits(0);
-        fixture.addEntry(entry);
-    }
-
-    /**
-     * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
-     * specifying all 4 parameters to the entry.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testAddEntry_4params() throws CTFReaderException {
-        entry.setTimestampBegin(1L);
-        entry.setPacketSizeBits(1);
-        entry.setContentSizeBits(1);
-        entry.setTimestampEnd(1L);
-        fixture.addEntry(entry);
-    }
-
-    /**
-     * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
-     */
-    @Test
-    public void testGetEntries() {
-        Collection<StreamInputPacketIndexEntry> result = fixture.getEntries();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-    }
-
-    /**
-     * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
-     * test, with no parameter to listIterator().
-     */
-    @Test
-    public void testListIterator_noparam() {
-        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator();
-
-        assertNotNull(result);
-        assertEquals(true, result.hasNext());
-        assertEquals(-1, result.previousIndex());
-        assertEquals(false, result.hasPrevious());
-        assertEquals(0, result.nextIndex());
-    }
-
-    /**
-     * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
-     * test, with n = 1.
-     */
-    @Test
-    public void testListIterator_withparam() {
-        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1);
-
-        assertNotNull(result);
-        assertEquals(false, result.hasNext());
-        assertEquals(0, result.previousIndex());
-        assertEquals(true, result.hasPrevious());
-        assertEquals(1, result.nextIndex());
-        assertEquals(false, result.hasNext());
-    }
-
-    /**
-     * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
-     * test with a valid timestamp.
-     */
-    @Test
-    public void testSearch_valid() {
-        ListIterator<StreamInputPacketIndexEntry> result = fixture.search(1L);
-
-        assertNotNull(result);
-        assertEquals(true, result.hasNext());
-        assertEquals(-1, result.previousIndex());
-        assertEquals(false, result.hasPrevious());
-        assertEquals(0, result.nextIndex());
-    }
-
-    /**
-     * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
-     * test with an invalid timestamp.
-     */
-    @Test(expected = java.lang.IllegalArgumentException.class)
-    public void testSearch_invalid() {
-        ListIterator<StreamInputPacketIndexEntry> result = fixture.search(-1L);
-
-        assertNotNull(result);
-    }
-}
\ No newline at end of file
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
deleted file mode 100644 (file)
index 82e7851..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.File;
-import java.util.Set;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-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.tests.shared.CtfTestTrace;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.CTFResponse;
-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.event.EventDeclaration;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * The class <code>StreamInputReaderTest</code> contains tests for the class
- * <code>{@link StreamInputReader}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class StreamInputReaderTest {
-
-    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
-
-    private StreamInputReader fixture;
-
-    private static ImmutableList<String> wrap(String s) {
-        return ImmutableList.<String> builder().add(s).build();
-    }
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        fixture = getStreamInputReader();
-        fixture.setName(1);
-        fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
-                getStreamInputReader(), 0, null, null,
-                new StructDefinition(
-                        new StructDeclaration(0),
-                        null,
-                        "packet",
-                        wrap( "field" ),
-                        new Definition[] { new StringDefinition(new StringDeclaration(), null, "field", "test") }),
-                null)
-                );
-    }
-
-    private static StreamInputReader getStreamInputReader() throws CTFReaderException {
-        assumeTrue(testTrace.exists());
-        CTFTrace trace = testTrace.getTrace();
-        Stream s = trace.getStream((long) 0);
-        Set<StreamInput> streamInput = s.getStreamInputs();
-        StreamInputReader retVal = null;
-        for (StreamInput si : streamInput) {
-            /*
-             * For the tests, we'll use the stream input corresponding to the
-             * CPU 0
-             */
-            if (si.getFilename().endsWith("0_0")) {
-                retVal = new StreamInputReader(si);
-                break;
-            }
-        }
-        return retVal;
-    }
-
-    /**
-     * Run the StreamInputReader(StreamInput) constructor test, with a valid
-     * trace.
-     */
-    @Test
-    public void testStreamInputReader_valid() {
-        assertNotNull(fixture);
-    }
-
-    /**
-     * Run the StreamInputReader(StreamInput) constructor test, with an invalid
-     * trace.
-     *
-     * @throws CTFReaderException
-     */
-    @Test(expected = CTFReaderException.class)
-    public void testStreamInputReader_invalid() throws CTFReaderException {
-        StreamInput streamInput = new StreamInput(
-                new Stream(new CTFTrace("")), new File(""));
-
-        StreamInputReader result = new StreamInputReader(streamInput);
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the int getCPU() method test.
-     */
-    @Test
-    public void testGetCPU() {
-        int result = fixture.getCPU();
-        assertEquals(0, result);
-    }
-
-    /**
-     * Run the EventDefinition getCurrentEvent() method test.
-     */
-    @Test
-    public void testGetCurrentEvent() {
-        EventDefinition result = fixture.getCurrentEvent();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the StructDefinition getCurrentPacketContext() method test.
-     */
-    @Test
-    public void testGetCurrentPacketContext() {
-        StructDefinition result = fixture.getCurrentEvent().getPacketContext();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the int getName() method test.
-     */
-    @Test
-    public void testGetName() {
-        int result = fixture.getName();
-        assertEquals(1, result);
-    }
-
-    /**
-     * Run the void goToLastEvent() method test.
-     *
-     * @throws CTFReaderException
-     *             error
-     */
-    @Test
-    public void testGoToLastEvent1() throws CTFReaderException {
-        final long endTimestamp = goToEnd();
-        final long endTime = 4287422460315L;
-        assertEquals(endTime, endTimestamp);
-    }
-
-    /**
-     * Run the void goToLastEvent() method test.
-     *
-     * @throws CTFReaderException
-     *             error
-     */
-    @Test
-    public void testGoToLastEvent2() throws CTFReaderException {
-        long timestamp = -1;
-        while (fixture.readNextEvent().equals(CTFResponse.OK)) {
-            timestamp = fixture.getCurrentEvent().getTimestamp();
-        }
-        long endTimestamp = goToEnd();
-        assertEquals(0, timestamp - endTimestamp);
-    }
-
-    private long goToEnd() throws CTFReaderException {
-        fixture.goToLastEvent();
-        return fixture.getCurrentEvent().getTimestamp();
-    }
-
-    /**
-     * Run the boolean readNextEvent() method test.
-     *
-     * @throws CTFReaderException
-     *             error
-     */
-    @Test
-    public void testReadNextEvent() throws CTFReaderException {
-        assertEquals(CTFResponse.OK, fixture.readNextEvent());
-    }
-
-    /**
-     * Run the void seek(long) method test. Seek by direct timestamp
-     *
-     * @throws CTFReaderException
-     *             error
-     */
-    @Test
-    public void testSeek_timestamp() throws CTFReaderException {
-        long timestamp = 1L;
-        fixture.seek(timestamp);
-    }
-
-    /**
-     * Run the seek test. Seek by passing an EventDefinition to which we've
-     * given the timestamp we want.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testSeek_eventDefinition() throws CTFReaderException {
-        EventDefinition eventDefinition = new EventDefinition(
-                new EventDeclaration(), getStreamInputReader(), 1L, null, null, null, null);
-        fixture.setCurrentEvent(eventDefinition);
-    }
-}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java
deleted file mode 100644 (file)
index 04f7ab9..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputReaderTimestampComparatorTest</code> contains
- * tests for the class <code>{@link StreamInputReaderTimestampComparator}</code>
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class StreamInputReaderTimestampComparatorTest {
-
-    private StreamInputReaderTimestampComparator fixture;
-
-    /**
-     * Perform pre-test initialization.
-     */
-    @Before
-    public void setUp() {
-        fixture = new StreamInputReaderTimestampComparator();
-    }
-
-    /**
-     * Run the StreamInputReaderTimestampComparator() constructor test.
-     */
-    @Test
-    public void testStreamInputReaderTimestampComparator_1() {
-        assertNotNull(fixture);
-    }
-
-}
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
deleted file mode 100644 (file)
index 472ef02..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.File;
-import java.io.FilenameFilter;
-
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputTest</code> contains tests for the class
- * <code>{@link StreamInput}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class StreamInputTest {
-
-    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
-
-    private StreamInput fixture;
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        assumeTrue(testTrace.exists());
-        fixture = new StreamInput(new Stream(testTrace.getTrace()), createFile());
-        fixture.setTimestampEnd(1L);
-    }
-
-    private static File createFile() {
-        File path = new File(testTrace.getPath());
-        return path.listFiles(new FilenameFilter() {
-            @Override
-            public boolean accept(File dir, String name) {
-                if (name.contains("hann")) {
-                    return true;
-                }
-                return false;
-            }
-        })[0];
-    }
-
-    /**
-     * Run the StreamInput(Stream,FileChannel,File) constructor test.
-     */
-    @Test
-    public void testStreamInput() {
-        assertNotNull(fixture);
-    }
-
-    /**
-     * Run the String getFilename() method test.
-     */
-    @Test
-    public void testGetFilename() {
-        String result = fixture.getFilename();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String getPath() method test.
-     */
-    @Test
-    public void testGetPath() {
-        String result = fixture.getScopePath().toString();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Stream getStream() method test.
-     */
-    @Test
-    public void testGetStream() {
-        Stream result = fixture.getStream();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the long getTimestampEnd() method test.
-     */
-    @Test
-    public void testGetTimestampEnd() {
-        long result = fixture.getTimestampEnd();
-        assertTrue(0L < result);
-    }
-
-    /**
-     * Run the Definition lookupDefinition(String) method test.
-     */
-    @Test
-    public void testLookupDefinition() {
-        Definition result = fixture.lookupDefinition("id");
-        assertNull(result);
-    }
-
-    /**
-     * Run the void setTimestampEnd(long) method test.
-     */
-    @Test
-    public void testSetTimestampEnd() {
-        fixture.setTimestampEnd(1L);
-        assertEquals(fixture.getTimestampEnd(), 1L);
-    }
-
-    StreamInput s1;
-    StreamInput s2;
-
-    @Test
-    public void testEquals1() throws CTFReaderException {
-        s1 = new StreamInput(new Stream(testTrace.getTrace()),
-                createFile());
-        assertFalse(s1.equals(null));
-    }
-
-    @Test
-    public void testEquals2() throws CTFReaderException {
-        s1 = new StreamInput(new Stream(testTrace.getTrace()),
-                createFile());
-        assertFalse(s1.equals(new Long(23L)));
-
-    }
-
-    @Test
-    public void testEquals3() throws CTFReaderException {
-        s1 = new StreamInput(new Stream(testTrace.getTrace()),
-                createFile());
-        assertEquals(s1, s1);
-
-    }
-
-    @Test
-    public void testEquals4() throws CTFReaderException {
-        s1 = new StreamInput(new Stream(testTrace.getTrace()),
-                createFile());
-        s2 = new StreamInput(new Stream(testTrace.getTrace()),
-                createFile());
-        assertEquals(s1, s2);
-    }
-}
\ No newline at end of file
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
deleted file mode 100644 (file)
index 68fe8a8..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * 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 API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
-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.EventDeclaration;
-import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamTest</code> contains tests for the class
- * <code>{@link Stream}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class StreamTest {
-
-    private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
-
-    private Stream fixture;
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        assumeTrue(testTrace.exists());
-        fixture = new Stream(testTrace.getTrace());
-        fixture.setEventContext(new StructDeclaration(1L));
-        fixture.setPacketContext(new StructDeclaration(1L));
-        fixture.setEventHeader(new StructDeclaration(1L));
-        fixture.setId(1L);
-        fixture.addInput(new StreamInput(new Stream(testTrace.getTrace()), createFile()));
-    }
-
-    private static File createFile() {
-        File path = new File(testTrace.getPath());
-        return path.listFiles(new FilenameFilter() {
-            @Override
-            public boolean accept(File dir, String name) {
-                if (name.contains("hann")) {
-                    return true;
-                }
-                return false;
-            }
-        })[0];
-    }
-
-    /**
-     * Run the Stream(CTFTrace) constructor test.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testStream() throws CTFReaderException {
-        CTFTrace trace = testTrace.getTrace();
-        Stream result = new Stream(trace);
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the void addEvent(EventDeclaration) method test with the basic event.
-     *
-     * @throws ParseException
-     */
-    @Test
-    public void testAddEvent_base() throws ParseException {
-        EventDeclaration event = new EventDeclaration();
-        fixture.addEvent(event);
-    }
-
-    /**
-     * Run the boolean eventContextIsSet() method test.
-     */
-    @Test
-    public void testEventContextIsSet() {
-        assertTrue(fixture.isEventContextSet());
-    }
-
-    /**
-     * Run the boolean eventContextIsSet() method test.
-     */
-    @Test
-    public void testToString() {
-        assertNotNull(fixture.toString());
-    }
-
-    /**
-     * Run the boolean eventHeaderIsSet() method test.
-     */
-    @Test
-    public void testEventHeaderIsSet() {
-        assertTrue(fixture.isEventHeaderSet());
-    }
-
-    /**
-     * Run the StructDeclaration getEventContextDecl() method test.
-     */
-    @Test
-    public void testGetEventContextDecl() {
-        assertNotNull(fixture.getEventContextDecl());
-    }
-
-    /**
-     * Run the StructDeclaration getEventHeaderDecl() method test.
-     */
-    @Test
-    public void testGetEventHeaderDecl() {
-        assertNotNull(fixture.getEventHeaderDecl());
-    }
-
-    /**
-     * Run the HashMap<Long, EventDeclaration> getEvents() method test.
-     */
-    @Test
-    public void testGetEvents() {
-        Map<Long, IEventDeclaration> result = fixture.getEvents();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Long getId() method test.
-     */
-    @Test
-    public void testGetId() {
-        Long result = fixture.getId();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the StructDeclaration getPacketContextDecl() method test.
-     */
-    @Test
-    public void testGetPacketContextDecl() {
-        StructDeclaration result = fixture.getPacketContextDecl();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the Set<StreamInput> getStreamInputs() method test.
-     */
-    @Test
-    public void testGetStreamInputs() {
-        Set<StreamInput> result = fixture.getStreamInputs();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the CTFTrace getTrace() method test.
-     */
-    @Test
-    public void testGetTrace() {
-        CTFTrace result = fixture.getTrace();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the boolean idIsSet() method test.
-     */
-    @Test
-    public void testIdIsSet() {
-        boolean result = fixture.isIdSet();
-        assertTrue(result);
-    }
-
-    /**
-     * Run the boolean packetContextIsSet() method test.
-     */
-    @Test
-    public void testPacketContextIsSet() {
-        boolean result = fixture.isPacketContextSet();
-        assertTrue(result);
-    }
-
-    /**
-     * Run the void setEventContext(StructDeclaration) method test.
-     */
-    @Test
-    public void testSetEventContext() {
-        StructDeclaration eventContext = new StructDeclaration(1L);
-        fixture.setEventContext(eventContext);
-    }
-
-    /**
-     * Run the void setEventHeader(StructDeclaration) method test.
-     */
-    @Test
-    public void testSetEventHeader() {
-        StructDeclaration eventHeader = new StructDeclaration(1L);
-        fixture.setEventHeader(eventHeader);
-    }
-
-    /**
-     * Run the void setId(long) method test.
-     */
-    @Test
-    public void testSetId() {
-        long id = 1L;
-        fixture.setId(id);
-    }
-
-    /**
-     * Run the void setPacketContext(StructDeclaration) method test.
-     */
-    @Test
-    public void testSetPacketContext() {
-        StructDeclaration packetContext = new StructDeclaration(1L);
-        fixture.setPacketContext(packetContext);
-    }
-}
\ No newline at end of file
index 83bc4ca1b71da3d93e6301b539d63ad6ef037674..10098c300c07631862625f81829c7089ced63fb3 100644 (file)
@@ -30,12 +30,12 @@ import org.junit.runners.Suite;
     CTFTraceGrowingTest.class,
     IOstructgenTest.class,
     MetadataTest.class,
-    StreamInputPacketIndexEntryTest.class,
-    StreamInputPacketIndexTest.class,
-    StreamInputReaderTest.class,
-    StreamInputReaderTimestampComparatorTest.class,
-    StreamInputTest.class,
-    StreamTest.class,
+    CTFStreamInputPacketIndexEntryTest.class,
+    CTFStreamInputPacketIndexTest.class,
+    CTFStreamInputReaderTest.class,
+    CTFStreamInputReaderTimestampComparatorTest.class,
+    CTFStreamInputTest.class,
+    CTFStreamTest.class,
     UtilsTest.class
 })
 public class TestAll {
index 66a258e8df737f9a50dd30ae1f3d3c24e807a964..600d3bcb60f833e651c93fdcdf874aa2f9fe7e88 100644 (file)
@@ -24,7 +24,7 @@ import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
 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.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,7 +55,7 @@ public class EventDeclarationTest {
         fixture.setContext(new StructDeclaration(1L));
         fixture.setId(1L);
         fixture.setFields(new StructDeclaration(1L));
-        fixture.setStream(new Stream(testTrace.getTrace()));
+        fixture.setStream(new CTFStream(testTrace.getTrace()));
         fixture.setName("");
     }
 
@@ -99,7 +99,7 @@ public class EventDeclarationTest {
         obj.setContext(new StructDeclaration(1L));
         obj.setId(1L);
         obj.setFields(new StructDeclaration(1L));
-        obj.setStream(new Stream(testTrace.getTrace()));
+        obj.setStream(new CTFStream(testTrace.getTrace()));
         obj.setName("");
 
         assertTrue(fixture.equals(fixture));
@@ -235,7 +235,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testGetStream() {
-        Stream result = fixture.getStream();
+        CTFStream result = fixture.getStream();
         assertNotNull(result);
     }
 
@@ -253,7 +253,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testHashCode_null() {
-        fixture.setStream((Stream) null);
+        fixture.setStream((CTFStream) null);
         fixture.setName((String) null);
 
         int result = fixture.hashCode();
@@ -303,7 +303,7 @@ public class EventDeclarationTest {
      */
     @Test
     public void testStreamIsSet_null() {
-        fixture.setStream((Stream) null);
+        fixture.setStream((CTFStream) null);
 
         boolean result = fixture.streamIsSet();
         assertEquals(false, result);
index 183bfc02216df93648bdfbd28004716eac56fa1f..f2fb8ca885e2dbc46376cec0d50b4a0286f9ff86 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 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.StreamInputReader;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
 
 import com.google.common.collect.ImmutableList;
@@ -71,7 +71,7 @@ public final class EventDefinition implements IDefinitionScope {
     /**
      * The StreamInputReader that reads this event definition.
      */
-    private final StreamInputReader fStreamInputReader;
+    private final CTFStreamInputReader fStreamInputReader;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -97,7 +97,7 @@ public final class EventDefinition implements IDefinitionScope {
      * @since 3.0
      */
     public EventDefinition(IEventDeclaration declaration,
-            StreamInputReader streamInputReader,
+            CTFStreamInputReader streamInputReader,
             long timestamp,
             StructDefinition streamContext,
             StructDefinition eventContext,
@@ -220,8 +220,9 @@ public final class EventDefinition implements IDefinitionScope {
      * Gets the stream input reader that this event was made by
      *
      * @return the parent
+     * @since 3.0
      */
-    public StreamInputReader getStreamInputReader() {
+    public CTFStreamInputReader getStreamInputReader() {
         return fStreamInputReader;
     }
 
index e10470d685f8e0f49d3e6b995be88a045dfcef75..6107114716622aa35a46e0395c3e35a99a30b5b8 100644 (file)
@@ -17,8 +17,8 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
 
 /**
  * Representation of one type of event. A bit like "int" or "long" but for trace
@@ -44,7 +44,7 @@ public interface IEventDeclaration {
      *             IOExceptions.
      * @since 3.0
      */
-    EventDefinition createDefinition(StreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException;
+    EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException;
 
     /**
      * Gets the name of an event declaration
@@ -75,12 +75,12 @@ public interface IEventDeclaration {
     Long getId();
 
     /**
-     * Gets the {@link Stream} of an event declaration
+     * Gets the {@link CTFStream} of an event declaration
      *
      * @return the stream
-     * @since 2.0
+     * @since 3.0
      */
-    Stream getStream();
+    CTFStream getStream();
 
     /**
      * What is the log level of this event?
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStream.java
new file mode 100644 (file)
index 0000000..c8defa3
--- /dev/null
@@ -0,0 +1,271 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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 API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.trace;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+
+/**
+ * <b><u>Stream</u></b>
+ * <p>
+ * Represents a stream in a trace.
+ * @since 3.0
+ */
+public class CTFStream {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * The numerical ID of the stream
+     */
+    private Long fId = null;
+
+    /**
+     * Declarations of the stream-specific structures
+     */
+    private StructDeclaration fPacketContextDecl = null;
+    private StructDeclaration fEventHeaderDecl = null;
+    private StructDeclaration fEventContextDecl = null;
+
+    /**
+     * The trace to which the stream belongs
+     */
+    private CTFTrace fTrace = null;
+
+    /**
+     * Maps event ids to events
+     */
+    private Map<Long, IEventDeclaration> fEvents = new HashMap<>();
+
+    /**
+     * The inputs associated to this stream
+     */
+    private final Set<CTFStreamInput> fInputs = new HashSet<>();
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a Stream that belongs to a Trace
+     *
+     * @param trace
+     *            The trace to which belongs this stream.
+     */
+    public CTFStream(CTFTrace trace) {
+        fTrace = trace;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * Sets the id of a stream
+     * @param id the id of a stream
+     */
+    public void setId(long id) {
+        fId = id;
+    }
+
+    /**
+     * Gets the id of a stream
+     * @return id the id of a stream
+     */
+    public Long getId() {
+        return fId;
+    }
+
+    /**
+     * Is the id of a stream set
+     *
+     * @return If the ID is set or not
+     */
+    public boolean isIdSet() {
+        return fId != null;
+    }
+
+    /**
+     *
+     * @return is the event header set (timestamp and stuff) (see Ctf Spec)
+     */
+    public boolean isEventHeaderSet() {
+        return fEventHeaderDecl != null;
+    }
+
+    /**
+    *
+    * @return is the event context set (pid and stuff) (see Ctf Spec)
+    */
+    public boolean isEventContextSet() {
+        return fEventContextDecl != null;
+    }
+
+    /**
+     *
+     * @return Is the packet context set (see Ctf Spec)
+     */
+    public boolean isPacketContextSet() {
+        return fPacketContextDecl != null;
+    }
+
+    /**
+     *
+     * @param eventHeader the current event header for all events in this stream
+     */
+    public void setEventHeader(StructDeclaration eventHeader) {
+        fEventHeaderDecl = eventHeader;
+    }
+
+    /**
+     *
+     * @param eventContext the context for all events in this stream
+     */
+    public void setEventContext(StructDeclaration eventContext) {
+        fEventContextDecl = eventContext;
+    }
+
+    /**
+     *
+     * @param packetContext the packet context for all packets in this stream
+     */
+    public void setPacketContext(StructDeclaration packetContext) {
+        fPacketContextDecl = packetContext;
+    }
+
+    /**
+     *
+     * @return the event header declaration in structdeclaration form
+     */
+    public StructDeclaration getEventHeaderDecl() {
+        return fEventHeaderDecl;
+    }
+
+    /**
+     *
+     * @return the event context declaration in structdeclaration form
+     */
+    public StructDeclaration getEventContextDecl() {
+        return fEventContextDecl;
+    }
+
+    /**
+     *
+     * @return the packet context declaration in structdeclaration form
+     */
+    public StructDeclaration getPacketContextDecl() {
+        return fPacketContextDecl;
+    }
+
+    /**
+     *
+     * @return the set of all stream inputs for this stream
+     */
+    public Set<CTFStreamInput> getStreamInputs() {
+        return fInputs;
+    }
+
+    /**
+     *
+     * @return the parent trace
+     */
+    public CTFTrace getTrace() {
+        return fTrace;
+    }
+
+    /**
+     *
+     * @return all the event declarations for this stream, using the id as a key for the hashmap.
+     */
+    public Map<Long, IEventDeclaration> getEvents() {
+        return fEvents;
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Adds an event to the event map.
+     *
+     * An event in a stream can omit its id if it is the only event in this
+     * stream. An event for which no id has been specified has a null id. It is
+     * thus not possible to add an event with the null key if the map is not
+     * empty. It is also not possible to add an event to the map if the null key
+     * is present in the map.
+     *
+     * @param event
+     *            The event to add
+     * @throws ParseException
+     *             If there was a problem reading the event or adding it to the
+     *             stream
+     */
+    public void addEvent(IEventDeclaration event) throws ParseException {
+        /*
+         * If there is an event without id (the null key), it must be the only
+         * one
+         */
+        if (fEvents.get(null) != null) {
+            throw new ParseException(
+                    "Event without id with multiple events in a stream"); //$NON-NLS-1$
+        }
+
+        /*
+         * If there is an event without id (the null key), it must be the only
+         * one
+         */
+        if ((event.getId() == null) && (fEvents.size() != 0)) {
+            throw new ParseException(
+                    "Event without id with multiple events in a stream"); //$NON-NLS-1$
+        }
+
+        /* Check if an event with the same ID already exists */
+        if (fEvents.get(event.getId()) != null) {
+            throw new ParseException("Event id already exists"); //$NON-NLS-1$
+        }
+        if (event.getId() == null) {
+            fEvents.put(EventDeclaration.UNSET_EVENT_ID, event);
+        } else {
+            /* Put the event in the map */
+            fEvents.put(event.getId(), event);
+        }
+    }
+
+    /**
+     * Add an input to this Stream
+     *
+     * @param input
+     *            The StreamInput to add.
+     */
+    public void addInput(CTFStreamInput input) {
+        fInputs.add(input);
+    }
+
+    @Override
+    public String toString() {
+        return "Stream [id=" + fId + ", packetContextDecl=" + fPacketContextDecl //$NON-NLS-1$ //$NON-NLS-2$
+                + ", eventHeaderDecl=" + fEventHeaderDecl //$NON-NLS-1$
+                + ", eventContextDecl=" + fEventContextDecl + ", trace=" + fTrace //$NON-NLS-1$ //$NON-NLS-2$
+                + ", events=" + fEvents + ", inputs=" + fInputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java
new file mode 100644 (file)
index 0000000..af7f964
--- /dev/null
@@ -0,0 +1,519 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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 API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.trace;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+import java.util.UUID;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+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;
+import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
+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.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+
+/**
+ * <b><u>StreamInput</u></b>
+ * <p>
+ * Represents a trace file that belongs to a certain stream.
+ *
+ * @since 3.0
+ */
+public class CTFStreamInput implements IDefinitionScope, AutoCloseable {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The associated Stream
+     */
+    private final CTFStream fStream;
+
+    /**
+     * FileChannel to the trace file
+     */
+    private final FileChannel fFileChannel;
+
+    /**
+     * Information on the file (used for debugging)
+     */
+    private final File fFile;
+
+    /**
+     * The packet index of this input
+     */
+    private final StreamInputPacketIndex fIndex;
+
+    private long fTimestampEnd;
+
+    /**
+     * Definition of trace packet header
+     */
+    private StructDeclaration fTracePacketHeaderDecl = null;
+
+    /**
+     * Definition of trace stream packet context
+     */
+    private StructDeclaration fStreamPacketContextDecl = null;
+
+    /**
+     * Total number of lost events in this stream
+     */
+    private long fLostSoFar = 0;
+
+    /**
+     * File input stream, the parent input file
+     */
+    private final FileInputStream fFileInputStream;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a StreamInput.
+     *
+     * @param stream
+     *            The stream to which this StreamInput belongs to.
+     * @param file
+     *            Information about the trace file (for debugging purposes).
+     * @throws CTFReaderException
+     *             The file must exist
+     */
+    public CTFStreamInput(CTFStream stream, File file) throws CTFReaderException {
+        fStream = stream;
+        fFile = file;
+        try {
+            fFileInputStream = new FileInputStream(file);
+        } catch (FileNotFoundException e) {
+            throw new CTFReaderException(e);
+        }
+
+        fFileChannel = fFileInputStream.getChannel();
+        fIndex = new StreamInputPacketIndex();
+    }
+
+    @Override
+    public void close() throws IOException {
+        fFileChannel.close();
+        fFileInputStream.close();
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the stream the streamInput wrapper is wrapping
+     *
+     * @return the stream the streamInput wrapper is wrapping
+     */
+    public CTFStream getStream() {
+        return fStream;
+    }
+
+    /**
+     * The common streamInput Index
+     *
+     * @return the stream input Index
+     */
+    StreamInputPacketIndex getIndex() {
+        return fIndex;
+    }
+
+    /**
+     * Gets the filename of the streamInput file.
+     *
+     * @return the filename of the streaminput file.
+     */
+    public String getFilename() {
+        return fFile.getName();
+    }
+
+    /**
+     * Gets the last read timestamp of a stream. (this is not necessarily the
+     * last time in the stream.)
+     *
+     * @return the last read timestamp
+     */
+    public long getTimestampEnd() {
+        return fTimestampEnd;
+    }
+
+    /**
+     * Sets the last read timestamp of a stream. (this is not necessarily the
+     * last time in the stream.)
+     *
+     * @param timestampEnd
+     *            the last read timestamp
+     */
+    public void setTimestampEnd(long timestampEnd) {
+        fTimestampEnd = timestampEnd;
+    }
+
+    /**
+     * Useless for streaminputs
+     */
+    @Override
+    public LexicalScope getScopePath() {
+        return LexicalScope.STREAM;
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public Definition lookupDefinition(String lookupPath) {
+        /* TODO: lookup in different dynamic scopes is not supported yet. */
+        return null;
+    }
+
+    /**
+     * Create the index for this trace file.
+     */
+    public void setupIndex() {
+
+        /*
+         * The BitBuffer to extract data from the StreamInput
+         */
+        BitBuffer bitBuffer = new BitBuffer();
+        bitBuffer.setByteOrder(getStream().getTrace().getByteOrder());
+
+        /*
+         * Create the definitions we need to read the packet headers + contexts
+         */
+        if (getStream().getTrace().getPacketHeader() != null) {
+            fTracePacketHeaderDecl = getStream().getTrace().getPacketHeader();
+        }
+
+        if (getStream().getPacketContextDecl() != null) {
+            fStreamPacketContextDecl = getStream().getPacketContextDecl();
+        }
+
+    }
+
+    /**
+     * Adds the next packet header index entry to the index of a stream input.
+     *
+     * <strong>This method is slow and can corrupt data if not used properly</strong>
+     * @return true if there are more packets to add
+     * @throws CTFReaderException
+     *             If there was a problem reading the packed header
+     */
+    public boolean addPacketHeaderIndex() throws CTFReaderException {
+        long currentPos = 0L;
+        if (!fIndex.getEntries().isEmpty()) {
+            StreamInputPacketIndexEntry pos = fIndex.getEntries().lastElement();
+            currentPos = computeNextOffset(pos);
+        }
+        long fileSize = getStreamSize();
+        if (currentPos < fileSize) {
+            BitBuffer bitBuffer = new BitBuffer();
+            bitBuffer.setByteOrder(getStream().getTrace().getByteOrder());
+            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
+                    currentPos);
+            createPacketIndexEntry(fileSize, currentPos, packetIndex,
+                    fTracePacketHeaderDecl, fStreamPacketContextDecl, bitBuffer);
+            fIndex.addEntry(packetIndex);
+            return true;
+        }
+        return false;
+    }
+
+    private long getStreamSize() {
+        return fFile.length();
+    }
+
+    private long createPacketIndexEntry(long fileSizeBytes,
+            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
+            StructDeclaration tracePacketHeaderDecl,
+            StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer)
+            throws CTFReaderException {
+
+        /*
+         * Ignoring the return value, but this call is needed to initialize the
+         * input
+         */
+        createPacketBitBuffer(fileSizeBytes, packetOffsetBytes, packetIndex, bitBuffer);
+
+        /*
+         * Read the trace packet header if it exists.
+         */
+        if (tracePacketHeaderDecl != null) {
+            parseTracePacketHeader(tracePacketHeaderDecl, bitBuffer);
+        }
+
+        /*
+         * Read the stream packet context if it exists.
+         */
+        if (streamPacketContextDecl != null) {
+            parsePacketContext(fileSizeBytes, streamPacketContextDecl,
+                    bitBuffer, packetIndex);
+        } else {
+            setPacketContextNull(fileSizeBytes, packetIndex);
+        }
+
+        /* Basic validation */
+        if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
+            throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
+        }
+
+        if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex
+                .getOffsetBytes()) * 8)) {
+            throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+        }
+
+        /*
+         * Offset in the file, in bits
+         */
+        packetIndex.setDataOffsetBits(bitBuffer.position());
+
+        /*
+         * Update the counting packet offset
+         */
+        return computeNextOffset(packetIndex);
+    }
+
+    /**
+     * @param packetIndex
+     * @return
+     */
+    private static long computeNextOffset(
+            StreamInputPacketIndexEntry packetIndex) {
+        return packetIndex.getOffsetBytes()
+                + ((packetIndex.getPacketSizeBits() + 7) / 8);
+    }
+
+    ByteBuffer getByteBufferAt(long position, long size) throws IOException {
+        return fFileChannel.map(MapMode.READ_ONLY, position, size);
+    }
+
+    /**
+     * @param fileSizeBytes
+     * @param packetOffsetBytes
+     * @param packetIndex
+     * @param bitBuffer
+     * @return
+     * @throws CTFReaderException
+     */
+    private ByteBuffer createPacketBitBuffer(long fileSizeBytes,
+            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
+            BitBuffer bitBuffer) throws CTFReaderException {
+        /*
+         * Initial size, it should map at least the packet header + context
+         * size.
+         *
+         * TODO: use a less arbitrary size.
+         */
+        long mapSize = 4096;
+        /*
+         * If there is less data remaining than what we want to map, reduce the
+         * map size.
+         */
+        if ((fileSizeBytes - packetIndex.getOffsetBytes()) < mapSize) {
+            mapSize = fileSizeBytes - packetIndex.getOffsetBytes();
+        }
+
+        /*
+         * Map the packet.
+         */
+        ByteBuffer bb;
+
+        try {
+            bb = getByteBufferAt(packetOffsetBytes, mapSize);
+        } catch (IOException e) {
+            throw new CTFReaderException(e);
+        }
+        bitBuffer.setByteBuffer(bb);
+        return bb;
+    }
+
+    private void parseTracePacketHeader(StructDeclaration tracePacketHeaderDecl,
+            @NonNull BitBuffer bitBuffer) throws CTFReaderException {
+        StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER.getName(), bitBuffer);
+
+        /*
+         * Check the CTF magic number
+         */
+        IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
+                .lookupDefinition("magic"); //$NON-NLS-1$
+        if (magicDef != null) {
+            int magic = (int) magicDef.getValue();
+            if (magic != Utils.CTF_MAGIC) {
+                throw new CTFReaderException(
+                        "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
+            }
+        }
+
+        /*
+         * Check the trace UUID
+         */
+        ArrayDefinition uuidDef =
+                (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
+        if (uuidDef != null) {
+            UUID uuid = Utils.getUUIDfromDefinition(uuidDef);
+
+            if (!getStream().getTrace().getUUID().equals(uuid)) {
+                throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
+            }
+        }
+
+        /*
+         * Check that the stream id did not change
+         */
+        IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
+                .lookupDefinition("stream_id"); //$NON-NLS-1$
+        if (streamIDDef != null) {
+            long streamID = streamIDDef.getValue();
+
+            if (streamID != getStream().getId()) {
+                throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$
+            }
+        }
+    }
+
+    private static void setPacketContextNull(long fileSizeBytes,
+            StreamInputPacketIndexEntry packetIndex) {
+        /*
+         * If there is no packet context, infer the content and packet size from
+         * the file size (assume that there is only one packet and no padding)
+         */
+        packetIndex.setContentSizeBits(fileSizeBytes * 8);
+        packetIndex.setPacketSizeBits(fileSizeBytes * 8);
+    }
+
+    private void parsePacketContext(long fileSizeBytes,
+            StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer,
+            StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
+        StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(null, LexicalScope.STREAM_PACKET_CONTEXT.getName(), bitBuffer);
+
+        for (String field : streamPacketContextDef.getDeclaration()
+                .getFieldsList()) {
+            Definition id = streamPacketContextDef.lookupDefinition(field);
+            if (id instanceof IntegerDefinition) {
+                packetIndex.addAttribute(field,
+                        ((IntegerDefinition) id).getValue());
+            } else if (id instanceof FloatDefinition) {
+                packetIndex.addAttribute(field,
+                        ((FloatDefinition) id).getValue());
+            } else if (id instanceof EnumDefinition) {
+                packetIndex.addAttribute(field,
+                        ((EnumDefinition) id).getValue());
+            } else if (id instanceof StringDefinition) {
+                packetIndex.addAttribute(field,
+                        ((StringDefinition) id).getValue());
+            }
+        }
+
+        Long contentSize = (Long) packetIndex.lookupAttribute("content_size"); //$NON-NLS-1$
+        Long packetSize = (Long) packetIndex.lookupAttribute("packet_size"); //$NON-NLS-1$
+        Long tsBegin = (Long) packetIndex.lookupAttribute("timestamp_begin"); //$NON-NLS-1$
+        Long tsEnd = (Long) packetIndex.lookupAttribute("timestamp_end"); //$NON-NLS-1$
+        String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
+        // LTTng Specific
+        Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
+        Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
+
+        /* Read the content size in bits */
+        if (contentSize != null) {
+            packetIndex.setContentSizeBits(contentSize.intValue());
+        } else if (packetSize != null) {
+            packetIndex.setContentSizeBits(packetSize.longValue());
+        } else {
+            packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
+        }
+
+        /* Read the packet size in bits */
+        if (packetSize != null) {
+            packetIndex.setPacketSizeBits(packetSize.intValue());
+        } else if (packetIndex.getContentSizeBits() != 0) {
+            packetIndex.setPacketSizeBits(packetIndex.getContentSizeBits());
+        } else {
+            packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
+        }
+
+        /* Read the begin timestamp */
+        if (tsBegin != null) {
+            packetIndex.setTimestampBegin(tsBegin.longValue());
+        }
+
+        /* Read the end timestamp */
+        if (tsEnd != null) {
+            if (tsEnd == -1) {
+                tsEnd = Long.MAX_VALUE;
+            }
+            packetIndex.setTimestampEnd(tsEnd.longValue());
+            setTimestampEnd(packetIndex.getTimestampEnd());
+        }
+
+        if (device != null) {
+            packetIndex.setTarget(device);
+        }
+
+        if (cpuId != null) {
+            packetIndex.setTarget("CPU" + cpuId.toString()); //$NON-NLS-1$
+        }
+
+        if (lostEvents != null) {
+            packetIndex.setLostEvents(lostEvents - fLostSoFar);
+            fLostSoFar = lostEvents;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = (prime * result) + ((fFile == null) ? 0 : fFile.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof CTFStreamInput)) {
+            return false;
+        }
+        CTFStreamInput other = (CTFStreamInput) obj;
+        if (fFile == null) {
+            if (other.fFile != null) {
+                return false;
+            }
+        } else if (!fFile.equals(other.fFile)) {
+            return false;
+        }
+        return true;
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java
new file mode 100644 (file)
index 0000000..8530c86
--- /dev/null
@@ -0,0 +1,484 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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 API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.ctf.core.trace;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.CTFStrings;
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+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.EventDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * CTF trace packet reader. Reads the events of a packet of a trace file.
+ *
+ * @author Matthew Khouzam
+ * @author Simon Marchi
+ * @since 3.0
+ */
+public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseable {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /** BitBuffer used to read the trace file. */
+    @NonNull
+    private final BitBuffer fBitBuffer;
+
+    /** StreamInputReader that uses this StreamInputPacketReader. */
+    private final CTFStreamInputReader fStreamInputReader;
+
+    /** Trace packet header. */
+    private final StructDeclaration fTracePacketHeaderDecl;
+
+    /** Stream packet context definition. */
+    private final StructDeclaration fStreamPacketContextDecl;
+
+    /** Stream event header definition. */
+    private final StructDeclaration fStreamEventHeaderDecl;
+
+    /** Stream event context definition. */
+    private final StructDeclaration fStreamEventContextDecl;
+
+    private StructDefinition fCurrentTracePacketHeaderDef;
+    private StructDefinition fCurrentStreamEventHeaderDef;
+    private Definition fCurrentStreamPacketContextDef;
+    /** Reference to the index entry of the current packet. */
+    private StreamInputPacketIndexEntry fCurrentPacket = null;
+
+    /**
+     * Last timestamp recorded.
+     *
+     * Needed to calculate the complete timestamp values for the events with
+     * compact headers.
+     */
+    private long fLastTimestamp = 0;
+
+    /** CPU id of current packet. */
+    private int fCurrentCpu = 0;
+
+    private int fLostEventsInThisPacket;
+
+    private long fLostEventsDuration;
+
+    private boolean fHasLost = false;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a StreamInputPacketReader.
+     *
+     * @param streamInputReader
+     *            The StreamInputReader to which this packet reader belongs to.
+     */
+    public CTFStreamInputPacketReader(CTFStreamInputReader streamInputReader) {
+        fStreamInputReader = streamInputReader;
+
+        /* Set the BitBuffer's byte order. */
+        fBitBuffer = new BitBuffer();
+        fBitBuffer.setByteOrder(streamInputReader.getByteOrder());
+
+        final CTFStream currentStream = streamInputReader.getStreamInput().getStream();
+        fTracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
+        fStreamPacketContextDecl = currentStream.getPacketContextDecl();
+        fStreamEventHeaderDecl = currentStream.getEventHeaderDecl();
+        fStreamEventContextDecl = currentStream.getEventContextDecl();
+    }
+
+    /**
+     * Get the event context defintiion
+     *
+     * @param input
+     *            the bitbuffer to read from
+     * @return an context definition, can be null
+     * @throws CTFReaderException
+     *             out of bounds exception or such
+     */
+    public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+        return fStreamEventContextDecl.createDefinition(this, LexicalScope.STREAM_EVENT_CONTEXT.getName(), input);
+    }
+
+    /**
+     * Get the stream context defintiion
+     *
+     * @param input
+     *            the bitbuffer to read from
+     * @return an context definition, can be null
+     * @throws CTFReaderException
+     *             out of bounds exception or such
+     */
+    public StructDefinition getStreamEventHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+        return fStreamEventHeaderDecl.createDefinition(this, LexicalScope.STREAM_EVENT_HEADER.getName(), input);
+    }
+
+    /**
+     * Get the packet context defintiion
+     *
+     * @param input
+     *            the bitbuffer to read from
+     * @return an context definition, can be null
+     * @throws CTFReaderException
+     *             out of bounds exception or such
+     */
+    public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+        return fStreamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT.getName(), input);
+    }
+
+    /**
+     * Get the event header defintiion
+     *
+     * @param input
+     *            the bitbuffer to read from
+     * @return an header definition, can be null
+     * @throws CTFReaderException
+     *             out of bounds exception or such
+     */
+    public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+        return fTracePacketHeaderDecl.createDefinition(this, LexicalScope.TRACE_PACKET_HEADER.getName(), input);
+    }
+
+    /**
+     * Dispose the StreamInputPacketReader
+     */
+    @Override
+    public void close() {
+        fBitBuffer.setByteBuffer(null);
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the current packet
+     *
+     * @return the current packet
+     */
+    StreamInputPacketIndexEntry getCurrentPacket() {
+        return fCurrentPacket;
+    }
+
+    /**
+     * Gets the CPU (core) number
+     *
+     * @return the CPU (core) number
+     */
+    public int getCPU() {
+        return fCurrentCpu;
+    }
+
+    @Override
+    public LexicalScope getScopePath() {
+        return LexicalScope.PACKET;
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Changes the current packet to the given one.
+     *
+     * @param currentPacket
+     *            The index entry of the packet to switch to.
+     * @throws CTFReaderException
+     *             If we get an error reading the packet
+     */
+    void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) throws CTFReaderException {
+        StreamInputPacketIndexEntry prevPacket = null;
+        fCurrentPacket = currentPacket;
+
+        if (fCurrentPacket != null) {
+            /*
+             * Change the map of the BitBuffer.
+             */
+            ByteBuffer bb = null;
+            try {
+                bb = fStreamInputReader.getStreamInput().getByteBufferAt(
+                        fCurrentPacket.getOffsetBytes(),
+                        (fCurrentPacket.getPacketSizeBits() + 7) / 8);
+            } catch (IOException e) {
+                throw new CTFReaderException(e.getMessage(), e);
+            }
+
+            fBitBuffer.setByteBuffer(bb);
+
+            /*
+             * Read trace packet header.
+             */
+            if (fTracePacketHeaderDecl != null) {
+                fCurrentTracePacketHeaderDef = getTracePacketHeaderDefinition(fBitBuffer);
+            }
+
+            /*
+             * Read stream packet context.
+             */
+            if (fStreamPacketContextDecl != null) {
+                fCurrentStreamPacketContextDef = getStreamPacketContextDefinition(fBitBuffer);
+
+                /* Read CPU ID */
+                if (getCurrentPacket().getTarget() != null) {
+                    fCurrentCpu = (int) getCurrentPacket().getTargetId();
+                }
+
+                /* Read number of lost events */
+                fLostEventsInThisPacket = (int) getCurrentPacket().getLostEvents();
+                if (fLostEventsInThisPacket != 0) {
+                    fHasLost = true;
+                    /*
+                     * Compute the duration of the lost event time range. If the
+                     * current packet is the first packet, duration will be set
+                     * to 1.
+                     */
+                    long lostEventsStartTime;
+                    int index = fStreamInputReader.getStreamInput().getIndex().getEntries().indexOf(currentPacket);
+                    if (index == 0) {
+                        lostEventsStartTime = currentPacket.getTimestampBegin() + 1;
+                    } else {
+                        prevPacket = fStreamInputReader.getStreamInput().getIndex().getEntries().get(index - 1);
+                        lostEventsStartTime = prevPacket.getTimestampEnd();
+                    }
+                    fLostEventsDuration = Math.abs(lostEventsStartTime - currentPacket.getTimestampBegin());
+                }
+            }
+
+            /*
+             * Use the timestamp begin of the packet as the reference for the
+             * timestamp reconstitution.
+             */
+            fLastTimestamp = currentPacket.getTimestampBegin();
+        } else {
+            fBitBuffer.setByteBuffer(null);
+
+            fLastTimestamp = 0;
+        }
+    }
+
+    /**
+     * Returns whether it is possible to read any more events from this packet.
+     *
+     * @return True if it is possible to read any more events from this packet.
+     */
+    public boolean hasMoreEvents() {
+        if (fCurrentPacket != null) {
+            return fHasLost || (fBitBuffer.position() < fCurrentPacket.getContentSizeBits());
+        }
+        return false;
+    }
+
+    /**
+     * Reads the next event of the packet into the right event definition.
+     *
+     * @return The event definition containing the event data that was just
+     *         read.
+     * @throws CTFReaderException
+     *             If there was a problem reading the trace
+     */
+    public EventDefinition readNextEvent() throws CTFReaderException {
+        /* Default values for those fields */
+        long eventID = EventDeclaration.UNSET_EVENT_ID;
+        long timestamp = 0;
+        if (fHasLost) {
+            fHasLost = false;
+            EventDeclaration lostEventDeclaration = EventDeclaration.getLostEventDeclaration();
+            StructDeclaration lostFields = lostEventDeclaration.getFields();
+            // this is a hard coded map, we know it's not null
+            IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_FIELD);
+            if (lostFieldsDecl == null)
+            {
+                throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$
+            }
+            IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_DURATION);
+            if (lostEventsDurationDecl == null) {
+                throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$
+            }
+            IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, fLostEventsDuration);
+            IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket);
+            IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
+            /* this is weird notation, but it's the java notation */
+            final ImmutableList<String> fieldNameList = ImmutableList.<String> builder().add(CTFStrings.LOST_EVENTS_FIELD).add(CTFStrings.LOST_EVENTS_DURATION).build();
+            return new EventDefinition(
+                    lostEventDeclaration,
+                    fStreamInputReader,
+                    fLastTimestamp,
+                    null,
+                    null,
+                    null,
+                    new StructDefinition(
+                            lostFields,
+                            this, "fields", //$NON-NLS-1$
+                            fieldNameList,
+                            fields
+                    ));
+
+        }
+
+        final BitBuffer currentBitBuffer = fBitBuffer;
+        final long posStart = currentBitBuffer.position();
+        /* Read the stream event header. */
+        if (fStreamEventHeaderDecl != null) {
+            fCurrentStreamEventHeaderDef = getStreamEventHeaderDefinition(currentBitBuffer);
+
+            /* Check for the event id. */
+            Definition idDef = fCurrentStreamEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$
+            if (idDef instanceof SimpleDatatypeDefinition) {
+                eventID = ((SimpleDatatypeDefinition) idDef).getIntegerValue();
+            } else if (idDef != null) {
+                throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
+            }
+
+            /*
+             * Get the timestamp from the event header (may be overridden later
+             * on)
+             */
+            IntegerDefinition timestampDef = fCurrentStreamEventHeaderDef.lookupInteger("timestamp"); //$NON-NLS-1$
+            if (timestampDef != null) {
+                timestamp = calculateTimestamp(timestampDef);
+            } // else timestamp remains 0
+
+            /* Check for the variant v. */
+            Definition variantDef = fCurrentStreamEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$
+            if (variantDef instanceof VariantDefinition) {
+
+                /* Get the variant current field */
+                StructDefinition variantCurrentField = (StructDefinition) ((VariantDefinition) variantDef).getCurrentField();
+
+                /*
+                 * Try to get the id field in the current field of the variant.
+                 * If it is present, it overrides the previously read event id.
+                 */
+                Definition idIntegerDef = variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
+                if (idIntegerDef instanceof IntegerDefinition) {
+                    eventID = ((IntegerDefinition) idIntegerDef).getValue();
+                }
+
+                /*
+                 * Get the timestamp. This would overwrite any previous
+                 * timestamp definition
+                 */
+                Definition def = variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$
+                if (def instanceof IntegerDefinition) {
+                    timestamp = calculateTimestamp((IntegerDefinition) def);
+                }
+            }
+        }
+
+        /* Get the right event definition using the event id. */
+        IEventDeclaration eventDeclaration = fStreamInputReader.getStreamInput().getStream().getEvents().get(eventID);
+        if (eventDeclaration == null) {
+            throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
+        }
+        EventDefinition eventDef = eventDeclaration.createDefinition(fStreamInputReader, fBitBuffer, timestamp);
+
+        /*
+         * Set the event timestamp using the timestamp calculated by
+         * updateTimestamp.
+         */
+
+        if (posStart == currentBitBuffer.position()) {
+            throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
+        }
+
+        return eventDef;
+    }
+
+    /**
+     * Calculates the timestamp value of the event, possibly using the timestamp
+     * from the last event.
+     *
+     * @param timestampDef
+     *            Integer definition of the timestamp.
+     * @return The calculated timestamp value.
+     */
+    private long calculateTimestamp(IntegerDefinition timestampDef) {
+        long newval;
+        long majorasbitmask;
+        int len = timestampDef.getDeclaration().getLength();
+
+        /*
+         * If the timestamp length is 64 bits, it is a full timestamp.
+         */
+        if (timestampDef.getDeclaration().getLength() == 64) {
+            fLastTimestamp = timestampDef.getValue();
+            return fLastTimestamp;
+        }
+
+        /*
+         * Bit mask to keep / remove all old / new bits.
+         */
+        majorasbitmask = (1L << len) - 1;
+
+        /*
+         * If the new value is smaller than the corresponding bits of the last
+         * timestamp, we assume an overflow of the compact representation.
+         */
+        newval = timestampDef.getValue();
+        if (newval < (fLastTimestamp & majorasbitmask)) {
+            newval = newval + (1L << len);
+        }
+
+        /* Keep only the high bits of the old value */
+        fLastTimestamp = fLastTimestamp & ~majorasbitmask;
+
+        /* Then add the low bits of the new value */
+        fLastTimestamp = fLastTimestamp + newval;
+
+        return fLastTimestamp;
+    }
+
+    @Override
+    public Definition lookupDefinition(String lookupPath) {
+        if (lookupPath.equals(LexicalScope.STREAM_PACKET_CONTEXT)) {
+            return fCurrentStreamPacketContextDef;
+        }
+        if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER)) {
+            return fCurrentTracePacketHeaderDef;
+        }
+        return null;
+    }
+
+    /**
+     * Get stream event header
+     *
+     * @return the stream event header
+     */
+    public StructDefinition getCurrentStreamEventHeader() {
+        return fCurrentStreamEventHeaderDef;
+    }
+
+    /**
+     * Get the current packet event header
+     *
+     * @return the current packet event header
+     */
+    public StructDefinition getCurrentPacketEventHeader() {
+        return fCurrentTracePacketHeaderDef;
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java
new file mode 100644 (file)
index 0000000..df44575
--- /dev/null
@@ -0,0 +1,468 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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 API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.trace;
+
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * A CTF trace event reader. Reads the events of a trace file.
+ *
+ * @author Matthew Khouzam
+ * @author Simon Marchi
+ * @since 3.0
+ */
+public class CTFStreamInputReader implements AutoCloseable {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The StreamInput we are reading.
+     */
+    private final CTFStreamInput fStreamInput;
+
+    /**
+     * The packet reader used to read packets from this trace file.
+     */
+    private final CTFStreamInputPacketReader fPacketReader;
+
+    /**
+     * Iterator on the packet index
+     */
+    private int fPacketIndex;
+
+    /**
+     * Reference to the current event of this trace file (iow, the last on that
+     * was read, the next one to be returned)
+     */
+    private EventDefinition fCurrentEvent = null;
+
+    private int fId;
+
+    private CTFTraceReader fParent;
+
+    /**
+     * Live trace reading
+     */
+    private boolean fLive = false;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a StreamInputReader that reads a StreamInput.
+     *
+     * @param streamInput
+     *            The StreamInput to read.
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    public CTFStreamInputReader(CTFStreamInput streamInput) throws CTFReaderException {
+        fStreamInput = streamInput;
+        fPacketReader = new CTFStreamInputPacketReader(this);
+        /*
+         * Get the iterator on the packet index.
+         */
+        fPacketIndex = 0;
+        /*
+         * Make first packet the current one.
+         */
+        goToNextPacket();
+    }
+
+    /**
+     * Dispose the StreamInputReader
+     */
+    @Override
+    public void close() {
+        fPacketReader.close();
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * Gets the current event in this stream
+     *
+     * @return the current event in the stream, null if the stream is
+     *         finished/empty/malformed
+     */
+    public EventDefinition getCurrentEvent() {
+        return fCurrentEvent;
+    }
+
+    /**
+     * Gets the byte order for a trace
+     *
+     * @return the trace byte order
+     */
+    public ByteOrder getByteOrder() {
+        return fStreamInput.getStream().getTrace().getByteOrder();
+    }
+
+    /**
+     * Gets the name of the stream (it's an id and a number)
+     *
+     * @return gets the stream name (it's a number)
+     */
+    public int getName() {
+        return fId;
+    }
+
+    /**
+     * Sets the name of the stream
+     *
+     * @param name
+     *            the name of the stream, (it's a number)
+     */
+    public void setName(int name) {
+        fId = name;
+    }
+
+    /**
+     * Gets the CPU of a stream. It's the same as the one in /proc or running
+     * the asm CPUID instruction
+     *
+     * @return The CPU id (a number)
+     */
+    public int getCPU() {
+        return fPacketReader.getCPU();
+    }
+
+    /**
+     * Gets the filename of the stream being read
+     *
+     * @return The filename of the stream being read
+     */
+    public String getFilename() {
+        return fStreamInput.getFilename();
+    }
+
+    /*
+     * for internal use only
+     */
+    CTFStreamInput getStreamInput() {
+        return fStreamInput;
+    }
+
+    /**
+     * Gets the event definition set for this StreamInput
+     *
+     * @return Unmodifiable set with the event definitions
+     */
+    public Iterable<IEventDeclaration> getEventDeclarations() {
+        return ImmutableSet.copyOf(fStreamInput.getStream().getEvents().values());
+    }
+
+    /**
+     * Set the trace to live mode
+     *
+     * @param live
+     *            whether the trace is read live or not
+     */
+    public void setLive(boolean live) {
+        fLive = live;
+    }
+
+    /**
+     * Get if the trace is to read live or not
+     *
+     * @return whether the trace is live or not
+     */
+    public boolean isLive() {
+        return fLive;
+    }
+
+    /**
+     * Get the event context of the stream
+     *
+     * @return the event context declaration of the stream
+     */
+    public StructDeclaration getStreamEventContextDecl() {
+        return getStreamInput().getStream().getEventContextDecl();
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /**
+     * Reads the next event in the current event variable.
+     *
+     * @return If an event has been successfully read.
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    public CTFResponse readNextEvent() throws CTFReaderException {
+
+        /*
+         * Change packet if needed
+         */
+        if (!fPacketReader.hasMoreEvents()) {
+            final StreamInputPacketIndexEntry prevPacket = fPacketReader
+                    .getCurrentPacket();
+            if (prevPacket != null || fLive) {
+                goToNextPacket();
+            }
+
+        }
+
+        /*
+         * If an event is available, read it.
+         */
+        if (fPacketReader.hasMoreEvents()) {
+            setCurrentEvent(fPacketReader.readNextEvent());
+            return CTFResponse.OK;
+        }
+        this.setCurrentEvent(null);
+        return fLive ? CTFResponse.WAIT : CTFResponse.FINISH;
+    }
+
+    /**
+     * Change the current packet of the packet reader to the next one.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    private void goToNextPacket() throws CTFReaderException {
+        fPacketIndex++;
+        // did we already index the packet?
+        if (getPacketSize() >= (fPacketIndex + 1)) {
+            fPacketReader.setCurrentPacket(getPacket());
+        } else {
+            // go to the next packet if there is one, index it at the same time
+            if (fStreamInput.addPacketHeaderIndex()) {
+                fPacketIndex = getPacketSize() - 1;
+                fPacketReader.setCurrentPacket(getPacket());
+            } else {
+                // out of packets
+                fPacketReader.setCurrentPacket(null);
+            }
+        }
+    }
+
+    /**
+     * @return
+     */
+    private int getPacketSize() {
+        return fStreamInput.getIndex().getEntries().size();
+    }
+
+    /**
+     * Changes the location of the trace file reader so that the current event
+     * is the first event with a timestamp greater or equal the given timestamp.
+     *
+     * @param timestamp
+     *            The timestamp to seek to.
+     * @return The offset compared to the current position
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    public long seek(long timestamp) throws CTFReaderException {
+        long offset = 0;
+
+        gotoPacket(timestamp);
+
+        /*
+         * index up to the desired timestamp.
+         */
+        while ((fPacketReader.getCurrentPacket() != null)
+                && (fPacketReader.getCurrentPacket().getTimestampEnd() < timestamp)) {
+            try {
+                fStreamInput.addPacketHeaderIndex();
+                goToNextPacket();
+            } catch (CTFReaderException e) {
+                // do nothing here
+            }
+        }
+        if (fPacketReader.getCurrentPacket() == null) {
+            gotoPacket(timestamp);
+        }
+
+        /*
+         * Advance until either of these conditions are met:
+         *
+         * - reached the end of the trace file (the given timestamp is after the
+         * last event)
+         *
+         * - found the first event with a timestamp greater or equal the given
+         * timestamp.
+         */
+        readNextEvent();
+        boolean done = (this.getCurrentEvent() == null);
+        while (!done && (this.getCurrentEvent().getTimestamp() < timestamp)) {
+            readNextEvent();
+            done = (this.getCurrentEvent() == null);
+            offset++;
+        }
+        return offset;
+    }
+
+    /**
+     * @param timestamp
+     *            the time to seek
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    private void gotoPacket(long timestamp) throws CTFReaderException {
+        fPacketIndex = fStreamInput.getIndex().search(timestamp)
+                .previousIndex();
+        /*
+         * Switch to this packet.
+         */
+        goToNextPacket();
+    }
+
+    /**
+     * Seeks the last event of a stream and returns it.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
+     */
+    public void goToLastEvent() throws CTFReaderException {
+        /*
+         * Search in the index for the packet to search in.
+         */
+        final int len = fStreamInput.getIndex().getEntries().size();
+
+        /*
+         * Go to beginning of trace.
+         */
+        seek(0);
+        /*
+         * if the trace is empty.
+         */
+        if ((len == 0) || (fPacketReader.hasMoreEvents() == false)) {
+            /*
+             * This means the trace is empty. abort.
+             */
+            return;
+        }
+        /*
+         * Go to the last packet that contains events.
+         */
+        for (int pos = len - 1; pos > 0; pos--) {
+            fPacketIndex = pos;
+            fPacketReader.setCurrentPacket(getPacket());
+            if (fPacketReader.hasMoreEvents()) {
+                break;
+            }
+        }
+
+        /*
+         * Go until the end of that packet
+         */
+        EventDefinition prevEvent = null;
+        while (fCurrentEvent != null) {
+            prevEvent = fCurrentEvent;
+            this.readNextEvent();
+        }
+        /*
+         * Go back to the previous event
+         */
+        this.setCurrentEvent(prevEvent);
+    }
+
+    /**
+     * @return the parent
+     */
+    public CTFTraceReader getParent() {
+        return fParent;
+    }
+
+    /**
+     * @param parent
+     *            the parent to set
+     */
+    public void setParent(CTFTraceReader parent) {
+        fParent = parent;
+    }
+
+    /**
+     * Sets the current event in a stream input reader
+     *
+     * @param currentEvent
+     *            the event to set
+     */
+    public void setCurrentEvent(EventDefinition currentEvent) {
+        fCurrentEvent = currentEvent;
+    }
+
+    /**
+     * @return the packetIndexIt
+     */
+    private int getPacketIndex() {
+        return fPacketIndex;
+    }
+
+    private StreamInputPacketIndexEntry getPacket() {
+        return fStreamInput.getIndex().getEntries().get(getPacketIndex());
+    }
+
+    /**
+     * @return the packetReader
+     */
+    public CTFStreamInputPacketReader getPacketReader() {
+        return fPacketReader;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = (prime * result) + fId;
+        result = (prime * result)
+                + ((fStreamInput == null) ? 0 : fStreamInput.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof CTFStreamInputReader)) {
+            return false;
+        }
+        CTFStreamInputReader other = (CTFStreamInputReader) obj;
+        if (fId != other.fId) {
+            return false;
+        }
+        if (fStreamInput == null) {
+            if (other.fStreamInput != null) {
+                return false;
+            }
+        } else if (!fStreamInput.equals(other.fStreamInput)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        // this helps debugging
+        return fId + ' ' + fCurrentEvent.toString();
+    }
+}
index b945cf12d67ec8883b571f0a4b3b33cdd261bbb8..563d8215ccc8a5d1a3565cb3db58c08f6c80e381 100644 (file)
@@ -116,7 +116,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
     /**
      * Collection of streams contained in the trace.
      */
-    private final Map<Long, Stream> fStreams = new HashMap<>();
+    private final Map<Long, CTFStream> fStreams = new HashMap<>();
 
     /**
      * Collection of environment variables set by the tracer
@@ -210,9 +210,9 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
         }
 
         /* Create their index */
-        for (Stream stream : getStreams()) {
-            Set<StreamInput> inputs = stream.getStreamInputs();
-            for (StreamInput s : inputs) {
+        for (CTFStream stream : getStreams()) {
+            Set<CTFStreamInput> inputs = stream.getStreamInputs();
+            for (CTFStreamInput s : inputs) {
                 addStream(s);
             }
         }
@@ -272,9 +272,9 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
      * @param id
      *            Long the id of the stream
      * @return Stream the stream that we need
-     * @since 2.0
+     * @since 3.0
      */
-    public Stream getStream(Long id) {
+    public CTFStream getStream(Long id) {
         return fStreams.get(id);
     }
 
@@ -444,7 +444,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
      * @return Iterable&lt;Stream&gt; an iterable over streams.
      * @since 3.0
      */
-    public Iterable<Stream> getStreams() {
+    public Iterable<CTFStream> getStreams() {
         return fStreams.values();
     }
 
@@ -470,7 +470,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
     // Operations
     // ------------------------------------------------------------------------
 
-    private void addStream(StreamInput s) {
+    private void addStream(CTFStreamInput s) {
 
         /*
          * Copy the events
@@ -502,10 +502,10 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
      * @throws CTFReaderException
      *             if there is a file error
      */
-    private Stream openStreamInput(File streamFile) throws CTFReaderException {
+    private CTFStream openStreamInput(File streamFile) throws CTFReaderException {
         MappedByteBuffer byteBuffer;
         BitBuffer streamBitBuffer;
-        Stream stream;
+        CTFStream stream;
         FileChannel fc;
 
         if (!streamFile.canRead()) {
@@ -580,7 +580,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
          * Create the stream input and add a reference to the streamInput in the
          * stream
          */
-        stream.addInput(new StreamInput(stream, streamFile));
+        stream.addInput(new CTFStreamInput(stream, streamFile));
 
         return stream;
     }
@@ -622,9 +622,9 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
      *            A stream object.
      * @throws ParseException
      *             If there was some problem reading the metadata
-     * @since 2.0
+     * @since 3.0
      */
-    public void addStream(Stream stream) throws ParseException {
+    public void addStream(CTFStream stream) throws ParseException {
         /*
          * If there is already a stream without id (the null key), it must be
          * the only one
@@ -644,7 +644,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
         /*
          * If a stream with the same ID already exists, it is not valid.
          */
-        Stream existingStream = fStreams.get(stream.getId());
+        CTFStream existingStream = fStreams.get(stream.getId());
         if (existingStream != null) {
             throw new ParseException("Stream id already exists"); //$NON-NLS-1$
         }
@@ -905,14 +905,14 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
      * @since 3.0
      */
     public void addStream(long id, File streamFile) throws CTFReaderException {
-        Stream stream = null;
+        CTFStream stream = null;
         if (fStreams.containsKey(id)) {
             stream = fStreams.get(id);
         } else {
-            stream = new Stream(this);
+            stream = new CTFStream(this);
             fStreams.put(id, stream);
         }
-        stream.addInput(new StreamInput(stream, streamFile));
+        stream.addInput(new CTFStreamInput(stream, streamFile));
     }
 }
 
index e640bc32c7ef0dc640e3773c08e8cede9aebc7be..5ae504315d9f04869a18cd0154aae1af3a7b66a8 100644 (file)
@@ -50,12 +50,12 @@ public class CTFTraceReader implements AutoCloseable {
     /**
      * Vector of all the trace file readers.
      */
-    private final List<StreamInputReader> fStreamInputReaders = new ArrayList<>();
+    private final List<CTFStreamInputReader> fStreamInputReaders = new ArrayList<>();
 
     /**
      * Priority queue to order the trace file readers by timestamp.
      */
-    private PriorityQueue<StreamInputReader> fPrio;
+    private PriorityQueue<CTFStreamInputReader> fPrio;
 
     /**
      * Array to count the number of event per trace file.
@@ -132,7 +132,7 @@ public class CTFTraceReader implements AutoCloseable {
      */
     @Override
     public void close() {
-        for (StreamInputReader reader : fStreamInputReaders) {
+        for (CTFStreamInputReader reader : fStreamInputReaders) {
             if (reader != null) {
                 reader.close();
             }
@@ -169,7 +169,7 @@ public class CTFTraceReader implements AutoCloseable {
      * @return The priority queue of input readers
      * @since 2.0
      */
-    protected PriorityQueue<StreamInputReader> getPrio() {
+    protected PriorityQueue<CTFStreamInputReader> getPrio() {
         return fPrio;
     }
 
@@ -187,17 +187,17 @@ public class CTFTraceReader implements AutoCloseable {
         /*
          * For each stream.
          */
-        for (Stream stream : fTrace.getStreams()) {
-            Set<StreamInput> streamInputs = stream.getStreamInputs();
+        for (CTFStream stream : fTrace.getStreams()) {
+            Set<CTFStreamInput> streamInputs = stream.getStreamInputs();
 
             /*
              * For each trace file of the stream.
              */
-            for (StreamInput streamInput : streamInputs) {
+            for (CTFStreamInput streamInput : streamInputs) {
                 /*
                  * Create a reader.
                  */
-                StreamInputReader streamInputReader = new StreamInputReader(
+                CTFStreamInputReader streamInputReader = new CTFStreamInputReader(
                         streamInput);
 
                 /*
@@ -222,14 +222,14 @@ public class CTFTraceReader implements AutoCloseable {
      * @since 3.0
      */
     public void update() throws CTFReaderException {
-        Set<StreamInputReader> readers = new HashSet<>();
-        for (Stream stream : fTrace.getStreams()) {
-            Set<StreamInput> streamInputs = stream.getStreamInputs();
-            for (StreamInput streamInput : streamInputs) {
+        Set<CTFStreamInputReader> readers = new HashSet<>();
+        for (CTFStream stream : fTrace.getStreams()) {
+            Set<CTFStreamInput> streamInputs = stream.getStreamInputs();
+            for (CTFStreamInput streamInput : streamInputs) {
                 /*
                  * Create a reader.
                  */
-                StreamInputReader streamInputReader = new StreamInputReader(
+                CTFStreamInputReader streamInputReader = new CTFStreamInputReader(
                         streamInput);
 
                 /*
@@ -244,7 +244,7 @@ public class CTFTraceReader implements AutoCloseable {
         }
         long[] temp = fEventCountPerTraceFile;
         fEventCountPerTraceFile = new long[readers.size() + temp.length];
-        for (StreamInputReader reader : readers) {
+        for (CTFStreamInputReader reader : readers) {
             fPrio.add(reader);
         }
         for (int i = 0; i < temp.length; i++) {
@@ -260,7 +260,7 @@ public class CTFTraceReader implements AutoCloseable {
      */
     public Iterable<IEventDeclaration> getEventDeclarations() {
         ImmutableSet.Builder<IEventDeclaration> builder = new Builder<>();
-        for (StreamInputReader sir : fStreamInputReaders) {
+        for (CTFStreamInputReader sir : fStreamInputReaders) {
             builder.addAll(sir.getEventDeclarations());
         }
         return builder.build();
@@ -290,7 +290,7 @@ public class CTFTraceReader implements AutoCloseable {
 
         int pos = 0;
 
-        for (StreamInputReader reader : fStreamInputReaders) {
+        for (CTFStreamInputReader reader : fStreamInputReaders) {
             /*
              * Add each trace file reader in the priority queue, if we are able
              * to read an event from it.
@@ -316,7 +316,7 @@ public class CTFTraceReader implements AutoCloseable {
      *         of the trace.
      */
     public EventDefinition getCurrentEventDef() {
-        StreamInputReader top = getTopStream();
+        CTFStreamInputReader top = getTopStream();
 
         return (top != null) ? top.getCurrentEvent() : null;
     }
@@ -332,7 +332,7 @@ public class CTFTraceReader implements AutoCloseable {
         /*
          * Remove the reader from the top of the priority queue.
          */
-        StreamInputReader top = fPrio.poll();
+        CTFStreamInputReader top = fPrio.poll();
 
         /*
          * If the queue was empty.
@@ -408,7 +408,7 @@ public class CTFTraceReader implements AutoCloseable {
          * Remove all the trace readers from the priority queue
          */
         fPrio.clear();
-        for (StreamInputReader streamInputReader : fStreamInputReaders) {
+        for (CTFStreamInputReader streamInputReader : fStreamInputReaders) {
             /*
              * Seek the trace reader.
              */
@@ -428,8 +428,9 @@ public class CTFTraceReader implements AutoCloseable {
      * Gets the stream with the oldest event
      *
      * @return the stream with the oldest event
+     * @since 3.0
      */
-    public StreamInputReader getTopStream() {
+    public CTFStreamInputReader getTopStream() {
         return fPrio.peek();
     }
 
@@ -466,7 +467,7 @@ public class CTFTraceReader implements AutoCloseable {
         }
 
         for (int j = 0; j < fEventCountPerTraceFile.length; j++) {
-            StreamInputReader se = fStreamInputReaders.get(j);
+            CTFStreamInputReader se = fStreamInputReaders.get(j);
 
             long len = (width * fEventCountPerTraceFile[se.getName()])
                     / numEvents;
@@ -505,7 +506,7 @@ public class CTFTraceReader implements AutoCloseable {
      * @since 3.0
      */
     public void setLive(boolean live) {
-        for (StreamInputReader s : fPrio) {
+        for (CTFStreamInputReader s : fPrio) {
             s.setLive(live);
         }
     }
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java
deleted file mode 100644 (file)
index e87888f..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 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 API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
-
-/**
- * <b><u>Stream</u></b>
- * <p>
- * Represents a stream in a trace.
- * @since 2.0
- */
-public class Stream {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-
-    /**
-     * The numerical ID of the stream
-     */
-    private Long fId = null;
-
-    /**
-     * Declarations of the stream-specific structures
-     */
-    private StructDeclaration fPacketContextDecl = null;
-    private StructDeclaration fEventHeaderDecl = null;
-    private StructDeclaration fEventContextDecl = null;
-
-    /**
-     * The trace to which the stream belongs
-     */
-    private CTFTrace fTrace = null;
-
-    /**
-     * Maps event ids to events
-     */
-    private Map<Long, IEventDeclaration> fEvents = new HashMap<>();
-
-    /**
-     * The inputs associated to this stream
-     */
-    private final Set<StreamInput> fInputs = new HashSet<>();
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a Stream that belongs to a Trace
-     *
-     * @param trace
-     *            The trace to which belongs this stream.
-     */
-    public Stream(CTFTrace trace) {
-        fTrace = trace;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    /**
-     * Sets the id of a stream
-     * @param id the id of a stream
-     */
-    public void setId(long id) {
-        fId = id;
-    }
-
-    /**
-     * Gets the id of a stream
-     * @return id the id of a stream
-     */
-    public Long getId() {
-        return fId;
-    }
-
-    /**
-     * Is the id of a stream set
-     *
-     * @return If the ID is set or not
-     */
-    public boolean isIdSet() {
-        return fId != null;
-    }
-
-    /**
-     *
-     * @return is the event header set (timestamp and stuff) (see Ctf Spec)
-     */
-    public boolean isEventHeaderSet() {
-        return fEventHeaderDecl != null;
-    }
-
-    /**
-    *
-    * @return is the event context set (pid and stuff) (see Ctf Spec)
-    */
-    public boolean isEventContextSet() {
-        return fEventContextDecl != null;
-    }
-
-    /**
-     *
-     * @return Is the packet context set (see Ctf Spec)
-     */
-    public boolean isPacketContextSet() {
-        return fPacketContextDecl != null;
-    }
-
-    /**
-     *
-     * @param eventHeader the current event header for all events in this stream
-     */
-    public void setEventHeader(StructDeclaration eventHeader) {
-        fEventHeaderDecl = eventHeader;
-    }
-
-    /**
-     *
-     * @param eventContext the context for all events in this stream
-     */
-    public void setEventContext(StructDeclaration eventContext) {
-        fEventContextDecl = eventContext;
-    }
-
-    /**
-     *
-     * @param packetContext the packet context for all packets in this stream
-     */
-    public void setPacketContext(StructDeclaration packetContext) {
-        fPacketContextDecl = packetContext;
-    }
-
-    /**
-     *
-     * @return the event header declaration in structdeclaration form
-     */
-    public StructDeclaration getEventHeaderDecl() {
-        return fEventHeaderDecl;
-    }
-
-    /**
-     *
-     * @return the event context declaration in structdeclaration form
-     */
-    public StructDeclaration getEventContextDecl() {
-        return fEventContextDecl;
-    }
-
-    /**
-     *
-     * @return the packet context declaration in structdeclaration form
-     */
-    public StructDeclaration getPacketContextDecl() {
-        return fPacketContextDecl;
-    }
-
-    /**
-     *
-     * @return the set of all stream inputs for this stream
-     */
-    public Set<StreamInput> getStreamInputs() {
-        return fInputs;
-    }
-
-    /**
-     *
-     * @return the parent trace
-     */
-    public CTFTrace getTrace() {
-        return fTrace;
-    }
-
-    /**
-     *
-     * @return all the event declarations for this stream, using the id as a key for the hashmap.
-     */
-    public Map<Long, IEventDeclaration> getEvents() {
-        return fEvents;
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    /**
-     * Adds an event to the event map.
-     *
-     * An event in a stream can omit its id if it is the only event in this
-     * stream. An event for which no id has been specified has a null id. It is
-     * thus not possible to add an event with the null key if the map is not
-     * empty. It is also not possible to add an event to the map if the null key
-     * is present in the map.
-     *
-     * @param event
-     *            The event to add
-     * @throws ParseException
-     *             If there was a problem reading the event or adding it to the
-     *             stream
-     */
-    public void addEvent(IEventDeclaration event) throws ParseException {
-        /*
-         * If there is an event without id (the null key), it must be the only
-         * one
-         */
-        if (fEvents.get(null) != null) {
-            throw new ParseException(
-                    "Event without id with multiple events in a stream"); //$NON-NLS-1$
-        }
-
-        /*
-         * If there is an event without id (the null key), it must be the only
-         * one
-         */
-        if ((event.getId() == null) && (fEvents.size() != 0)) {
-            throw new ParseException(
-                    "Event without id with multiple events in a stream"); //$NON-NLS-1$
-        }
-
-        /* Check if an event with the same ID already exists */
-        if (fEvents.get(event.getId()) != null) {
-            throw new ParseException("Event id already exists"); //$NON-NLS-1$
-        }
-        if (event.getId() == null) {
-            fEvents.put(EventDeclaration.UNSET_EVENT_ID, event);
-        } else {
-            /* Put the event in the map */
-            fEvents.put(event.getId(), event);
-        }
-    }
-
-    /**
-     * Add an input to this Stream
-     *
-     * @param input
-     *            The StreamInput to add.
-     */
-    public void addInput(StreamInput input) {
-        fInputs.add(input);
-    }
-
-    @Override
-    public String toString() {
-        return "Stream [id=" + fId + ", packetContextDecl=" + fPacketContextDecl //$NON-NLS-1$ //$NON-NLS-2$
-                + ", eventHeaderDecl=" + fEventHeaderDecl //$NON-NLS-1$
-                + ", eventContextDecl=" + fEventContextDecl + ", trace=" + fTrace //$NON-NLS-1$ //$NON-NLS-2$
-                + ", events=" + fEvents + ", inputs=" + fInputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    }
-}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
deleted file mode 100644 (file)
index 03db342..0000000
+++ /dev/null
@@ -1,525 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 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 API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileChannel.MapMode;
-import java.util.UUID;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-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;
-import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
-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.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-/**
- * <b><u>StreamInput</u></b>
- * <p>
- * Represents a trace file that belongs to a certain stream.
- *
- * @since 2.0
- */
-public class StreamInput implements IDefinitionScope, AutoCloseable {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /**
-     * The associated Stream
-     */
-    private final Stream fStream;
-
-    /**
-     * FileChannel to the trace file
-     */
-    private final FileChannel fFileChannel;
-
-    /**
-     * Information on the file (used for debugging)
-     */
-    private final File fFile;
-
-    /**
-     * The packet index of this input
-     */
-    private final StreamInputPacketIndex fIndex;
-
-    private long fTimestampEnd;
-
-    /**
-     * Definition of trace packet header
-     */
-    private StructDeclaration fTracePacketHeaderDecl = null;
-
-    /**
-     * Definition of trace stream packet context
-     */
-    private StructDeclaration fStreamPacketContextDecl = null;
-
-    /**
-     * Total number of lost events in this stream
-     */
-    private long fLostSoFar = 0;
-
-    /**
-     * File input stream, the parent input file
-     */
-    private final FileInputStream fFileInputStream;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a StreamInput.
-     *
-     * @param stream
-     *            The stream to which this StreamInput belongs to.
-     * @param file
-     *            Information about the trace file (for debugging purposes).
-     * @throws CTFReaderException
-     *             The file must exist
-     * @since 3.0
-     */
-    public StreamInput(Stream stream, File file) throws CTFReaderException {
-        fStream = stream;
-        fFile = file;
-        try {
-            fFileInputStream = new FileInputStream(file);
-        } catch (FileNotFoundException e) {
-            throw new CTFReaderException(e);
-        }
-
-        fFileChannel = fFileInputStream.getChannel();
-        fIndex = new StreamInputPacketIndex();
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public void close() throws IOException {
-        fFileChannel.close();
-        fFileInputStream.close();
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    /**
-     * Gets the stream the streamInput wrapper is wrapping
-     *
-     * @return the stream the streamInput wrapper is wrapping
-     */
-    public Stream getStream() {
-        return fStream;
-    }
-
-    /**
-     * The common streamInput Index
-     *
-     * @return the stream input Index
-     */
-    StreamInputPacketIndex getIndex() {
-        return fIndex;
-    }
-
-    /**
-     * Gets the filename of the streamInput file.
-     *
-     * @return the filename of the streaminput file.
-     */
-    public String getFilename() {
-        return fFile.getName();
-    }
-
-    /**
-     * Gets the last read timestamp of a stream. (this is not necessarily the
-     * last time in the stream.)
-     *
-     * @return the last read timestamp
-     */
-    public long getTimestampEnd() {
-        return fTimestampEnd;
-    }
-
-    /**
-     * Sets the last read timestamp of a stream. (this is not necessarily the
-     * last time in the stream.)
-     *
-     * @param timestampEnd
-     *            the last read timestamp
-     */
-    public void setTimestampEnd(long timestampEnd) {
-        fTimestampEnd = timestampEnd;
-    }
-
-    /**
-     * Useless for streaminputs
-     *
-     * @since 3.0
-     */
-    @Override
-    public LexicalScope getScopePath() {
-        return LexicalScope.STREAM;
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    @Override
-    public Definition lookupDefinition(String lookupPath) {
-        /* TODO: lookup in different dynamic scopes is not supported yet. */
-        return null;
-    }
-
-    /**
-     * Create the index for this trace file.
-     */
-    public void setupIndex() {
-
-        /*
-         * The BitBuffer to extract data from the StreamInput
-         */
-        BitBuffer bitBuffer = new BitBuffer();
-        bitBuffer.setByteOrder(getStream().getTrace().getByteOrder());
-
-        /*
-         * Create the definitions we need to read the packet headers + contexts
-         */
-        if (getStream().getTrace().getPacketHeader() != null) {
-            fTracePacketHeaderDecl = getStream().getTrace().getPacketHeader();
-        }
-
-        if (getStream().getPacketContextDecl() != null) {
-            fStreamPacketContextDecl = getStream().getPacketContextDecl();
-        }
-
-    }
-
-    /**
-     * Adds the next packet header index entry to the index of a stream input.
-     *
-     * <strong>This method is slow and can corrupt data if not used properly</strong>
-     * @return true if there are more packets to add
-     * @throws CTFReaderException
-     *             If there was a problem reading the packed header
-     */
-    public boolean addPacketHeaderIndex() throws CTFReaderException {
-        long currentPos = 0L;
-        if (!fIndex.getEntries().isEmpty()) {
-            StreamInputPacketIndexEntry pos = fIndex.getEntries().lastElement();
-            currentPos = computeNextOffset(pos);
-        }
-        long fileSize = getStreamSize();
-        if (currentPos < fileSize) {
-            BitBuffer bitBuffer = new BitBuffer();
-            bitBuffer.setByteOrder(getStream().getTrace().getByteOrder());
-            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
-                    currentPos);
-            createPacketIndexEntry(fileSize, currentPos, packetIndex,
-                    fTracePacketHeaderDecl, fStreamPacketContextDecl, bitBuffer);
-            fIndex.addEntry(packetIndex);
-            return true;
-        }
-        return false;
-    }
-
-    private long getStreamSize() {
-        return fFile.length();
-    }
-
-    private long createPacketIndexEntry(long fileSizeBytes,
-            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
-            StructDeclaration tracePacketHeaderDecl,
-            StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer)
-            throws CTFReaderException {
-
-        /*
-         * Ignoring the return value, but this call is needed to initialize the
-         * input
-         */
-        createPacketBitBuffer(fileSizeBytes, packetOffsetBytes, packetIndex, bitBuffer);
-
-        /*
-         * Read the trace packet header if it exists.
-         */
-        if (tracePacketHeaderDecl != null) {
-            parseTracePacketHeader(tracePacketHeaderDecl, bitBuffer);
-        }
-
-        /*
-         * Read the stream packet context if it exists.
-         */
-        if (streamPacketContextDecl != null) {
-            parsePacketContext(fileSizeBytes, streamPacketContextDecl,
-                    bitBuffer, packetIndex);
-        } else {
-            setPacketContextNull(fileSizeBytes, packetIndex);
-        }
-
-        /* Basic validation */
-        if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
-            throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
-        }
-
-        if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex
-                .getOffsetBytes()) * 8)) {
-            throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
-        }
-
-        /*
-         * Offset in the file, in bits
-         */
-        packetIndex.setDataOffsetBits(bitBuffer.position());
-
-        /*
-         * Update the counting packet offset
-         */
-        return computeNextOffset(packetIndex);
-    }
-
-    /**
-     * @param packetIndex
-     * @return
-     */
-    private static long computeNextOffset(
-            StreamInputPacketIndexEntry packetIndex) {
-        return packetIndex.getOffsetBytes()
-                + ((packetIndex.getPacketSizeBits() + 7) / 8);
-    }
-
-    ByteBuffer getByteBufferAt(long position, long size) throws IOException {
-        return fFileChannel.map(MapMode.READ_ONLY, position, size);
-    }
-
-    /**
-     * @param fileSizeBytes
-     * @param packetOffsetBytes
-     * @param packetIndex
-     * @param bitBuffer
-     * @return
-     * @throws CTFReaderException
-     */
-    private ByteBuffer createPacketBitBuffer(long fileSizeBytes,
-            long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
-            BitBuffer bitBuffer) throws CTFReaderException {
-        /*
-         * Initial size, it should map at least the packet header + context
-         * size.
-         *
-         * TODO: use a less arbitrary size.
-         */
-        long mapSize = 4096;
-        /*
-         * If there is less data remaining than what we want to map, reduce the
-         * map size.
-         */
-        if ((fileSizeBytes - packetIndex.getOffsetBytes()) < mapSize) {
-            mapSize = fileSizeBytes - packetIndex.getOffsetBytes();
-        }
-
-        /*
-         * Map the packet.
-         */
-        ByteBuffer bb;
-
-        try {
-            bb = getByteBufferAt(packetOffsetBytes, mapSize);
-        } catch (IOException e) {
-            throw new CTFReaderException(e);
-        }
-        bitBuffer.setByteBuffer(bb);
-        return bb;
-    }
-
-    private void parseTracePacketHeader(StructDeclaration tracePacketHeaderDecl,
-            @NonNull BitBuffer bitBuffer) throws CTFReaderException {
-        StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER.getName(), bitBuffer);
-
-        /*
-         * Check the CTF magic number
-         */
-        IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
-                .lookupDefinition("magic"); //$NON-NLS-1$
-        if (magicDef != null) {
-            int magic = (int) magicDef.getValue();
-            if (magic != Utils.CTF_MAGIC) {
-                throw new CTFReaderException(
-                        "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
-            }
-        }
-
-        /*
-         * Check the trace UUID
-         */
-        ArrayDefinition uuidDef =
-                (ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
-        if (uuidDef != null) {
-            UUID uuid = Utils.getUUIDfromDefinition(uuidDef);
-
-            if (!getStream().getTrace().getUUID().equals(uuid)) {
-                throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
-            }
-        }
-
-        /*
-         * Check that the stream id did not change
-         */
-        IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
-                .lookupDefinition("stream_id"); //$NON-NLS-1$
-        if (streamIDDef != null) {
-            long streamID = streamIDDef.getValue();
-
-            if (streamID != getStream().getId()) {
-                throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$
-            }
-        }
-    }
-
-    private static void setPacketContextNull(long fileSizeBytes,
-            StreamInputPacketIndexEntry packetIndex) {
-        /*
-         * If there is no packet context, infer the content and packet size from
-         * the file size (assume that there is only one packet and no padding)
-         */
-        packetIndex.setContentSizeBits(fileSizeBytes * 8);
-        packetIndex.setPacketSizeBits(fileSizeBytes * 8);
-    }
-
-    private void parsePacketContext(long fileSizeBytes,
-            StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer,
-            StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
-        StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(null, LexicalScope.STREAM_PACKET_CONTEXT.getName(), bitBuffer);
-
-        for (String field : streamPacketContextDef.getDeclaration()
-                .getFieldsList()) {
-            Definition id = streamPacketContextDef.lookupDefinition(field);
-            if (id instanceof IntegerDefinition) {
-                packetIndex.addAttribute(field,
-                        ((IntegerDefinition) id).getValue());
-            } else if (id instanceof FloatDefinition) {
-                packetIndex.addAttribute(field,
-                        ((FloatDefinition) id).getValue());
-            } else if (id instanceof EnumDefinition) {
-                packetIndex.addAttribute(field,
-                        ((EnumDefinition) id).getValue());
-            } else if (id instanceof StringDefinition) {
-                packetIndex.addAttribute(field,
-                        ((StringDefinition) id).getValue());
-            }
-        }
-
-        Long contentSize = (Long) packetIndex.lookupAttribute("content_size"); //$NON-NLS-1$
-        Long packetSize = (Long) packetIndex.lookupAttribute("packet_size"); //$NON-NLS-1$
-        Long tsBegin = (Long) packetIndex.lookupAttribute("timestamp_begin"); //$NON-NLS-1$
-        Long tsEnd = (Long) packetIndex.lookupAttribute("timestamp_end"); //$NON-NLS-1$
-        String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
-        // LTTng Specific
-        Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
-        Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
-
-        /* Read the content size in bits */
-        if (contentSize != null) {
-            packetIndex.setContentSizeBits(contentSize.intValue());
-        } else if (packetSize != null) {
-            packetIndex.setContentSizeBits(packetSize.longValue());
-        } else {
-            packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
-        }
-
-        /* Read the packet size in bits */
-        if (packetSize != null) {
-            packetIndex.setPacketSizeBits(packetSize.intValue());
-        } else if (packetIndex.getContentSizeBits() != 0) {
-            packetIndex.setPacketSizeBits(packetIndex.getContentSizeBits());
-        } else {
-            packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
-        }
-
-        /* Read the begin timestamp */
-        if (tsBegin != null) {
-            packetIndex.setTimestampBegin(tsBegin.longValue());
-        }
-
-        /* Read the end timestamp */
-        if (tsEnd != null) {
-            if (tsEnd == -1) {
-                tsEnd = Long.MAX_VALUE;
-            }
-            packetIndex.setTimestampEnd(tsEnd.longValue());
-            setTimestampEnd(packetIndex.getTimestampEnd());
-        }
-
-        if (device != null) {
-            packetIndex.setTarget(device);
-        }
-
-        if (cpuId != null) {
-            packetIndex.setTarget("CPU" + cpuId.toString()); //$NON-NLS-1$
-        }
-
-        if (lostEvents != null) {
-            packetIndex.setLostEvents(lostEvents - fLostSoFar);
-            fLostSoFar = lostEvents;
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = (prime * result) + ((fFile == null) ? 0 : fFile.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof StreamInput)) {
-            return false;
-        }
-        StreamInput other = (StreamInput) obj;
-        if (fFile == null) {
-            if (other.fFile != null) {
-                return false;
-            }
-        } else if (!fFile.equals(other.fFile)) {
-            return false;
-        }
-        return true;
-    }
-
-}
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
deleted file mode 100644 (file)
index 6ad4ebc..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 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 API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.CTFStrings;
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-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.EventDeclaration;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * CTF trace packet reader. Reads the events of a packet of a trace file.
- *
- * @version 1.0
- * @author Matthew Khouzam
- * @author Simon Marchi
- */
-public class StreamInputPacketReader implements IDefinitionScope, AutoCloseable {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /** BitBuffer used to read the trace file. */
-    @NonNull
-    private final BitBuffer fBitBuffer;
-
-    /** StreamInputReader that uses this StreamInputPacketReader. */
-    private final StreamInputReader fStreamInputReader;
-
-    /** Trace packet header. */
-    private final StructDeclaration fTracePacketHeaderDecl;
-
-    /** Stream packet context definition. */
-    private final StructDeclaration fStreamPacketContextDecl;
-
-    /** Stream event header definition. */
-    private final StructDeclaration fStreamEventHeaderDecl;
-
-    /** Stream event context definition. */
-    private final StructDeclaration fStreamEventContextDecl;
-
-    private StructDefinition fCurrentTracePacketHeaderDef;
-    private StructDefinition fCurrentStreamEventHeaderDef;
-    private Definition fCurrentStreamPacketContextDef;
-    /** Reference to the index entry of the current packet. */
-    private StreamInputPacketIndexEntry fCurrentPacket = null;
-
-    /**
-     * Last timestamp recorded.
-     *
-     * Needed to calculate the complete timestamp values for the events with
-     * compact headers.
-     */
-    private long fLastTimestamp = 0;
-
-    /** CPU id of current packet. */
-    private int fCurrentCpu = 0;
-
-    private int fLostEventsInThisPacket;
-
-    private long fLostEventsDuration;
-
-    private boolean fHasLost = false;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a StreamInputPacketReader.
-     *
-     * @param streamInputReader
-     *            The StreamInputReader to which this packet reader belongs to.
-     */
-    public StreamInputPacketReader(StreamInputReader streamInputReader) {
-        fStreamInputReader = streamInputReader;
-
-        /* Set the BitBuffer's byte order. */
-        fBitBuffer = new BitBuffer();
-        fBitBuffer.setByteOrder(streamInputReader.getByteOrder());
-
-        final Stream currentStream = streamInputReader.getStreamInput().getStream();
-        fTracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
-        fStreamPacketContextDecl = currentStream.getPacketContextDecl();
-        fStreamEventHeaderDecl = currentStream.getEventHeaderDecl();
-        fStreamEventContextDecl = currentStream.getEventContextDecl();
-    }
-
-    /**
-     * Get the event context defintiion
-     *
-     * @param input
-     *            the bitbuffer to read from
-     * @return an context definition, can be null
-     * @throws CTFReaderException
-     *             out of bounds exception or such
-     * @since 3.0
-     */
-    public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamEventContextDecl.createDefinition(this, LexicalScope.STREAM_EVENT_CONTEXT.getName(), input);
-    }
-
-    /**
-     * Get the stream context defintiion
-     *
-     * @param input
-     *            the bitbuffer to read from
-     * @return an context definition, can be null
-     * @throws CTFReaderException
-     *             out of bounds exception or such
-     * @since 3.0
-     */
-    public StructDefinition getStreamEventHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamEventHeaderDecl.createDefinition(this, LexicalScope.STREAM_EVENT_HEADER.getName(), input);
-    }
-
-    /**
-     * Get the packet context defintiion
-     *
-     * @param input
-     *            the bitbuffer to read from
-     * @return an context definition, can be null
-     * @throws CTFReaderException
-     *             out of bounds exception or such
-     * @since 3.0
-     */
-    public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT.getName(), input);
-    }
-
-    /**
-     * Get the event header defintiion
-     *
-     * @param input
-     *            the bitbuffer to read from
-     * @return an header definition, can be null
-     * @throws CTFReaderException
-     *             out of bounds exception or such
-     * @since 3.0
-     */
-    public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fTracePacketHeaderDecl.createDefinition(this, LexicalScope.TRACE_PACKET_HEADER.getName(), input);
-    }
-
-    /**
-     * Dispose the StreamInputPacketReader
-     *
-     * @since 3.0
-     */
-    @Override
-    public void close() {
-        fBitBuffer.setByteBuffer(null);
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    /**
-     * Gets the current packet
-     *
-     * @return the current packet
-     */
-    StreamInputPacketIndexEntry getCurrentPacket() {
-        return fCurrentPacket;
-    }
-
-    /**
-     * Gets the CPU (core) number
-     *
-     * @return the CPU (core) number
-     */
-    public int getCPU() {
-        return fCurrentCpu;
-    }
-
-    /**
-     * @since 3.0
-     */
-    @Override
-    public LexicalScope getScopePath() {
-        return LexicalScope.PACKET;
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    /**
-     * Changes the current packet to the given one.
-     *
-     * @param currentPacket
-     *            The index entry of the packet to switch to.
-     * @throws CTFReaderException
-     *             If we get an error reading the packet
-     */
-    void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) throws CTFReaderException {
-        StreamInputPacketIndexEntry prevPacket = null;
-        fCurrentPacket = currentPacket;
-
-        if (fCurrentPacket != null) {
-            /*
-             * Change the map of the BitBuffer.
-             */
-            ByteBuffer bb = null;
-            try {
-                bb = fStreamInputReader.getStreamInput().getByteBufferAt(
-                        fCurrentPacket.getOffsetBytes(),
-                        (fCurrentPacket.getPacketSizeBits() + 7) / 8);
-            } catch (IOException e) {
-                throw new CTFReaderException(e.getMessage(), e);
-            }
-
-            fBitBuffer.setByteBuffer(bb);
-
-            /*
-             * Read trace packet header.
-             */
-            if (fTracePacketHeaderDecl != null) {
-                fCurrentTracePacketHeaderDef = getTracePacketHeaderDefinition(fBitBuffer);
-            }
-
-            /*
-             * Read stream packet context.
-             */
-            if (fStreamPacketContextDecl != null) {
-                fCurrentStreamPacketContextDef = getStreamPacketContextDefinition(fBitBuffer);
-
-                /* Read CPU ID */
-                if (getCurrentPacket().getTarget() != null) {
-                    fCurrentCpu = (int) getCurrentPacket().getTargetId();
-                }
-
-                /* Read number of lost events */
-                fLostEventsInThisPacket = (int) getCurrentPacket().getLostEvents();
-                if (fLostEventsInThisPacket != 0) {
-                    fHasLost = true;
-                    /*
-                     * Compute the duration of the lost event time range. If the
-                     * current packet is the first packet, duration will be set
-                     * to 1.
-                     */
-                    long lostEventsStartTime;
-                    int index = fStreamInputReader.getStreamInput().getIndex().getEntries().indexOf(currentPacket);
-                    if (index == 0) {
-                        lostEventsStartTime = currentPacket.getTimestampBegin() + 1;
-                    } else {
-                        prevPacket = fStreamInputReader.getStreamInput().getIndex().getEntries().get(index - 1);
-                        lostEventsStartTime = prevPacket.getTimestampEnd();
-                    }
-                    fLostEventsDuration = Math.abs(lostEventsStartTime - currentPacket.getTimestampBegin());
-                }
-            }
-
-            /*
-             * Use the timestamp begin of the packet as the reference for the
-             * timestamp reconstitution.
-             */
-            fLastTimestamp = currentPacket.getTimestampBegin();
-        } else {
-            fBitBuffer.setByteBuffer(null);
-
-            fLastTimestamp = 0;
-        }
-    }
-
-    /**
-     * Returns whether it is possible to read any more events from this packet.
-     *
-     * @return True if it is possible to read any more events from this packet.
-     */
-    public boolean hasMoreEvents() {
-        if (fCurrentPacket != null) {
-            return fHasLost || (fBitBuffer.position() < fCurrentPacket.getContentSizeBits());
-        }
-        return false;
-    }
-
-    /**
-     * Reads the next event of the packet into the right event definition.
-     *
-     * @return The event definition containing the event data that was just
-     *         read.
-     * @throws CTFReaderException
-     *             If there was a problem reading the trace
-     */
-    public EventDefinition readNextEvent() throws CTFReaderException {
-        /* Default values for those fields */
-        long eventID = EventDeclaration.UNSET_EVENT_ID;
-        long timestamp = 0;
-        if (fHasLost) {
-            fHasLost = false;
-            EventDeclaration lostEventDeclaration = EventDeclaration.getLostEventDeclaration();
-            StructDeclaration lostFields = lostEventDeclaration.getFields();
-            // this is a hard coded map, we know it's not null
-            IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_FIELD);
-            if (lostFieldsDecl == null)
-            {
-                throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$
-            }
-            IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_DURATION);
-            if (lostEventsDurationDecl == null) {
-                throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$
-            }
-            IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, fLostEventsDuration);
-            IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket);
-            IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
-            /* this is weird notation, but it's the java notation */
-            final ImmutableList<String> fieldNameList = ImmutableList.<String> builder().add(CTFStrings.LOST_EVENTS_FIELD).add(CTFStrings.LOST_EVENTS_DURATION).build();
-            return new EventDefinition(
-                    lostEventDeclaration,
-                    fStreamInputReader,
-                    fLastTimestamp,
-                    null,
-                    null,
-                    null,
-                    new StructDefinition(
-                            lostFields,
-                            this, "fields", //$NON-NLS-1$
-                            fieldNameList,
-                            fields
-                    ));
-
-        }
-
-        final BitBuffer currentBitBuffer = fBitBuffer;
-        final long posStart = currentBitBuffer.position();
-        /* Read the stream event header. */
-        if (fStreamEventHeaderDecl != null) {
-            fCurrentStreamEventHeaderDef = getStreamEventHeaderDefinition(currentBitBuffer);
-
-            /* Check for the event id. */
-            Definition idDef = fCurrentStreamEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$
-            if (idDef instanceof SimpleDatatypeDefinition) {
-                eventID = ((SimpleDatatypeDefinition) idDef).getIntegerValue();
-            } else if (idDef != null) {
-                throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
-            }
-
-            /*
-             * Get the timestamp from the event header (may be overridden later
-             * on)
-             */
-            IntegerDefinition timestampDef = fCurrentStreamEventHeaderDef.lookupInteger("timestamp"); //$NON-NLS-1$
-            if (timestampDef != null) {
-                timestamp = calculateTimestamp(timestampDef);
-            } // else timestamp remains 0
-
-            /* Check for the variant v. */
-            Definition variantDef = fCurrentStreamEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$
-            if (variantDef instanceof VariantDefinition) {
-
-                /* Get the variant current field */
-                StructDefinition variantCurrentField = (StructDefinition) ((VariantDefinition) variantDef).getCurrentField();
-
-                /*
-                 * Try to get the id field in the current field of the variant.
-                 * If it is present, it overrides the previously read event id.
-                 */
-                Definition idIntegerDef = variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
-                if (idIntegerDef instanceof IntegerDefinition) {
-                    eventID = ((IntegerDefinition) idIntegerDef).getValue();
-                }
-
-                /*
-                 * Get the timestamp. This would overwrite any previous
-                 * timestamp definition
-                 */
-                Definition def = variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$
-                if (def instanceof IntegerDefinition) {
-                    timestamp = calculateTimestamp((IntegerDefinition) def);
-                }
-            }
-        }
-
-        /* Get the right event definition using the event id. */
-        IEventDeclaration eventDeclaration = fStreamInputReader.getStreamInput().getStream().getEvents().get(eventID);
-        if (eventDeclaration == null) {
-            throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
-        }
-        EventDefinition eventDef = eventDeclaration.createDefinition(fStreamInputReader, fBitBuffer, timestamp);
-
-        /*
-         * Set the event timestamp using the timestamp calculated by
-         * updateTimestamp.
-         */
-
-        if (posStart == currentBitBuffer.position()) {
-            throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
-        }
-
-        return eventDef;
-    }
-
-    /**
-     * Calculates the timestamp value of the event, possibly using the timestamp
-     * from the last event.
-     *
-     * @param timestampDef
-     *            Integer definition of the timestamp.
-     * @return The calculated timestamp value.
-     */
-    private long calculateTimestamp(IntegerDefinition timestampDef) {
-        long newval;
-        long majorasbitmask;
-        int len = timestampDef.getDeclaration().getLength();
-
-        /*
-         * If the timestamp length is 64 bits, it is a full timestamp.
-         */
-        if (timestampDef.getDeclaration().getLength() == 64) {
-            fLastTimestamp = timestampDef.getValue();
-            return fLastTimestamp;
-        }
-
-        /*
-         * Bit mask to keep / remove all old / new bits.
-         */
-        majorasbitmask = (1L << len) - 1;
-
-        /*
-         * If the new value is smaller than the corresponding bits of the last
-         * timestamp, we assume an overflow of the compact representation.
-         */
-        newval = timestampDef.getValue();
-        if (newval < (fLastTimestamp & majorasbitmask)) {
-            newval = newval + (1L << len);
-        }
-
-        /* Keep only the high bits of the old value */
-        fLastTimestamp = fLastTimestamp & ~majorasbitmask;
-
-        /* Then add the low bits of the new value */
-        fLastTimestamp = fLastTimestamp + newval;
-
-        return fLastTimestamp;
-    }
-
-    @Override
-    public Definition lookupDefinition(String lookupPath) {
-        if (lookupPath.equals(LexicalScope.STREAM_PACKET_CONTEXT)) {
-            return fCurrentStreamPacketContextDef;
-        }
-        if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER)) {
-            return fCurrentTracePacketHeaderDef;
-        }
-        return null;
-    }
-
-    /**
-     * Get stream event header
-     *
-     * @return the stream event header
-     * @since 3.0
-     */
-    public StructDefinition getCurrentStreamEventHeader() {
-        return fCurrentStreamEventHeaderDef;
-    }
-
-    /**
-     * Get the current packet event header
-     *
-     * @return the current packet event header
-     * @since 3.0
-     */
-    public StructDefinition getCurrentPacketEventHeader() {
-        return fCurrentTracePacketHeaderDef;
-    }
-}
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
deleted file mode 100644 (file)
index e0f7c16..0000000
+++ /dev/null
@@ -1,476 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2014 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 API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.nio.ByteOrder;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * A CTF trace event reader. Reads the events of a trace file.
- *
- * @version 1.0
- * @author Matthew Khouzam
- * @author Simon Marchi
- */
-public class StreamInputReader implements AutoCloseable {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /**
-     * The StreamInput we are reading.
-     */
-    private final StreamInput fStreamInput;
-
-    /**
-     * The packet reader used to read packets from this trace file.
-     */
-    private final StreamInputPacketReader fPacketReader;
-
-    /**
-     * Iterator on the packet index
-     */
-    private int fPacketIndex;
-
-    /**
-     * Reference to the current event of this trace file (iow, the last on that
-     * was read, the next one to be returned)
-     */
-    private EventDefinition fCurrentEvent = null;
-
-    private int fId;
-
-    private CTFTraceReader fParent;
-
-    /**
-     * Live trace reading
-     */
-    private boolean fLive = false;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a StreamInputReader that reads a StreamInput.
-     *
-     * @param streamInput
-     *            The StreamInput to read.
-     * @throws CTFReaderException
-     *             if an error occurs
-     * @since 2.0
-     */
-    public StreamInputReader(StreamInput streamInput) throws CTFReaderException {
-        fStreamInput = streamInput;
-        fPacketReader = new StreamInputPacketReader(this);
-        /*
-         * Get the iterator on the packet index.
-         */
-        fPacketIndex = 0;
-        /*
-         * Make first packet the current one.
-         */
-        goToNextPacket();
-    }
-
-    /**
-     * Dispose the StreamInputReader
-     *
-     * @since 3.0
-     */
-    @Override
-    public void close() {
-        fPacketReader.close();
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    /**
-     * Gets the current event in this stream
-     *
-     * @return the current event in the stream, null if the stream is
-     *         finished/empty/malformed
-     */
-    public EventDefinition getCurrentEvent() {
-        return fCurrentEvent;
-    }
-
-    /**
-     * Gets the byte order for a trace
-     *
-     * @return the trace byte order
-     */
-    public ByteOrder getByteOrder() {
-        return fStreamInput.getStream().getTrace().getByteOrder();
-    }
-
-    /**
-     * Gets the name of the stream (it's an id and a number)
-     *
-     * @return gets the stream name (it's a number)
-     */
-    public int getName() {
-        return fId;
-    }
-
-    /**
-     * Sets the name of the stream
-     *
-     * @param name
-     *            the name of the stream, (it's a number)
-     */
-    public void setName(int name) {
-        fId = name;
-    }
-
-    /**
-     * Gets the CPU of a stream. It's the same as the one in /proc or running
-     * the asm CPUID instruction
-     *
-     * @return The CPU id (a number)
-     */
-    public int getCPU() {
-        return fPacketReader.getCPU();
-    }
-
-    /**
-     * Gets the filename of the stream being read
-     *
-     * @return The filename of the stream being read
-     */
-    public String getFilename() {
-        return fStreamInput.getFilename();
-    }
-
-    /*
-     * for internal use only
-     */
-    StreamInput getStreamInput() {
-        return fStreamInput;
-    }
-
-    /**
-     * Gets the event definition set for this StreamInput
-     *
-     * @return Unmodifiable set with the event definitions
-     * @since 3.0
-     */
-    public Iterable<IEventDeclaration> getEventDeclarations() {
-        return ImmutableSet.copyOf(fStreamInput.getStream().getEvents().values());
-    }
-
-    /**
-     * Set the trace to live mode
-     *
-     * @param live
-     *            whether the trace is read live or not
-     * @since 3.0
-     */
-    public void setLive(boolean live) {
-        fLive = live;
-    }
-
-    /**
-     * Get if the trace is to read live or not
-     *
-     * @return whether the trace is live or not
-     * @since 3.0
-     */
-    public boolean isLive() {
-        return fLive;
-    }
-
-    /**
-     * Get the event context of the stream
-     *
-     * @return the event context declaration of the stream
-     * @since 3.0
-     */
-    public StructDeclaration getStreamEventContextDecl() {
-        return getStreamInput().getStream().getEventContextDecl();
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-    /**
-     * Reads the next event in the current event variable.
-     *
-     * @return If an event has been successfully read.
-     * @throws CTFReaderException
-     *             if an error occurs
-     * @since 3.0
-     */
-    public CTFResponse readNextEvent() throws CTFReaderException {
-
-        /*
-         * Change packet if needed
-         */
-        if (!fPacketReader.hasMoreEvents()) {
-            final StreamInputPacketIndexEntry prevPacket = fPacketReader
-                    .getCurrentPacket();
-            if (prevPacket != null || fLive) {
-                goToNextPacket();
-            }
-
-        }
-
-        /*
-         * If an event is available, read it.
-         */
-        if (fPacketReader.hasMoreEvents()) {
-            setCurrentEvent(fPacketReader.readNextEvent());
-            return CTFResponse.OK;
-        }
-        this.setCurrentEvent(null);
-        return fLive ? CTFResponse.WAIT : CTFResponse.FINISH;
-    }
-
-    /**
-     * Change the current packet of the packet reader to the next one.
-     *
-     * @throws CTFReaderException
-     *             if an error occurs
-     */
-    private void goToNextPacket() throws CTFReaderException {
-        fPacketIndex++;
-        // did we already index the packet?
-        if (getPacketSize() >= (fPacketIndex + 1)) {
-            fPacketReader.setCurrentPacket(getPacket());
-        } else {
-            // go to the next packet if there is one, index it at the same time
-            if (fStreamInput.addPacketHeaderIndex()) {
-                fPacketIndex = getPacketSize() - 1;
-                fPacketReader.setCurrentPacket(getPacket());
-            } else {
-                // out of packets
-                fPacketReader.setCurrentPacket(null);
-            }
-        }
-    }
-
-    /**
-     * @return
-     */
-    private int getPacketSize() {
-        return fStreamInput.getIndex().getEntries().size();
-    }
-
-    /**
-     * Changes the location of the trace file reader so that the current event
-     * is the first event with a timestamp greater or equal the given timestamp.
-     *
-     * @param timestamp
-     *            The timestamp to seek to.
-     * @return The offset compared to the current position
-     * @throws CTFReaderException
-     *             if an error occurs
-     */
-    public long seek(long timestamp) throws CTFReaderException {
-        long offset = 0;
-
-        gotoPacket(timestamp);
-
-        /*
-         * index up to the desired timestamp.
-         */
-        while ((fPacketReader.getCurrentPacket() != null)
-                && (fPacketReader.getCurrentPacket().getTimestampEnd() < timestamp)) {
-            try {
-                fStreamInput.addPacketHeaderIndex();
-                goToNextPacket();
-            } catch (CTFReaderException e) {
-                // do nothing here
-            }
-        }
-        if (fPacketReader.getCurrentPacket() == null) {
-            gotoPacket(timestamp);
-        }
-
-        /*
-         * Advance until either of these conditions are met:
-         *
-         * - reached the end of the trace file (the given timestamp is after the
-         * last event)
-         *
-         * - found the first event with a timestamp greater or equal the given
-         * timestamp.
-         */
-        readNextEvent();
-        boolean done = (this.getCurrentEvent() == null);
-        while (!done && (this.getCurrentEvent().getTimestamp() < timestamp)) {
-            readNextEvent();
-            done = (this.getCurrentEvent() == null);
-            offset++;
-        }
-        return offset;
-    }
-
-    /**
-     * @param timestamp
-     *            the time to seek
-     * @throws CTFReaderException
-     *             if an error occurs
-     */
-    private void gotoPacket(long timestamp) throws CTFReaderException {
-        fPacketIndex = fStreamInput.getIndex().search(timestamp)
-                .previousIndex();
-        /*
-         * Switch to this packet.
-         */
-        goToNextPacket();
-    }
-
-    /**
-     * Seeks the last event of a stream and returns it.
-     *
-     * @throws CTFReaderException
-     *             if an error occurs
-     */
-    public void goToLastEvent() throws CTFReaderException {
-        /*
-         * Search in the index for the packet to search in.
-         */
-        final int len = fStreamInput.getIndex().getEntries().size();
-
-        /*
-         * Go to beginning of trace.
-         */
-        seek(0);
-        /*
-         * if the trace is empty.
-         */
-        if ((len == 0) || (fPacketReader.hasMoreEvents() == false)) {
-            /*
-             * This means the trace is empty. abort.
-             */
-            return;
-        }
-        /*
-         * Go to the last packet that contains events.
-         */
-        for (int pos = len - 1; pos > 0; pos--) {
-            fPacketIndex = pos;
-            fPacketReader.setCurrentPacket(getPacket());
-            if (fPacketReader.hasMoreEvents()) {
-                break;
-            }
-        }
-
-        /*
-         * Go until the end of that packet
-         */
-        EventDefinition prevEvent = null;
-        while (fCurrentEvent != null) {
-            prevEvent = fCurrentEvent;
-            this.readNextEvent();
-        }
-        /*
-         * Go back to the previous event
-         */
-        this.setCurrentEvent(prevEvent);
-    }
-
-    /**
-     * @return the parent
-     */
-    public CTFTraceReader getParent() {
-        return fParent;
-    }
-
-    /**
-     * @param parent
-     *            the parent to set
-     */
-    public void setParent(CTFTraceReader parent) {
-        fParent = parent;
-    }
-
-    /**
-     * Sets the current event in a stream input reader
-     *
-     * @param currentEvent
-     *            the event to set
-     */
-    public void setCurrentEvent(EventDefinition currentEvent) {
-        fCurrentEvent = currentEvent;
-    }
-
-    /**
-     * @return the packetIndexIt
-     */
-    private int getPacketIndex() {
-        return fPacketIndex;
-    }
-
-    private StreamInputPacketIndexEntry getPacket() {
-        return fStreamInput.getIndex().getEntries().get(getPacketIndex());
-    }
-
-    /**
-     * @return the packetReader
-     */
-    public StreamInputPacketReader getPacketReader() {
-        return fPacketReader;
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = (prime * result) + fId;
-        result = (prime * result)
-                + ((fStreamInput == null) ? 0 : fStreamInput.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof StreamInputReader)) {
-            return false;
-        }
-        StreamInputReader other = (StreamInputReader) obj;
-        if (fId != other.fId) {
-            return false;
-        }
-        if (fStreamInput == null) {
-            if (other.fStreamInput != null) {
-                return false;
-            }
-        } else if (!fStreamInput.equals(other.fStreamInput)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        // this helps debugging
-        return fId + ' ' + fCurrentEvent.toString();
-    }
-}
index abd15b671e334f095aa74f0dc6b55fec15386c6b..f76330fbb68b8b030da38ed966eebc8386f92534 100644 (file)
@@ -27,8 +27,8 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 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.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
 
 /**
  * Representation of one type of event. A bit like "int" or "long" but for trace
@@ -73,7 +73,7 @@ public class EventDeclaration implements IEventDeclaration {
     /**
      * Stream to which belongs this event.
      */
-    private Stream fStream = null;
+    private CTFStream fStream = null;
 
     /**
      * Loglevel of an event
@@ -95,7 +95,7 @@ public class EventDeclaration implements IEventDeclaration {
     }
 
     @Override
-    public EventDefinition createDefinition(StreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException {
+    public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException {
         StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
         StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(null, LexicalScope.STREAM_EVENT_CONTEXT.toString(), input) : null;
         StructDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
@@ -202,12 +202,12 @@ public class EventDeclaration implements IEventDeclaration {
      *            the stream
      * @since 2.0
      */
-    public void setStream(Stream stream) {
+    public void setStream(CTFStream stream) {
         fStream = stream;
     }
 
     @Override
-    public Stream getStream() {
+    public CTFStream getStream() {
         return fStream;
     }
 
index 3f43802442c54623b5b3b86b2b94a4060daf9629..202997e9b61f6ba184ceac6acfd0ce5a21dd754f 100644 (file)
@@ -42,7 +42,7 @@ 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.core.trace.CTFStream;
 import org.eclipse.linuxtools.ctf.parser.CTFParser;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
 import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
@@ -252,7 +252,7 @@ public class IOStructGen {
                 }
             } else {
                 /* Add an empty stream that will have a null id */
-                fTrace.addStream(new Stream(fTrace));
+                fTrace.addStream(new CTFStream(fTrace));
             }
 
             if (DEBUG) {
@@ -621,7 +621,7 @@ public class IOStructGen {
 
     private void parseStream(CommonTree streamNode) throws ParseException {
 
-        Stream stream = new Stream(fTrace);
+        CTFStream stream = new CTFStream(fTrace);
 
         List<CommonTree> children = streamNode.getChildren();
         if (children == null) {
@@ -660,7 +660,7 @@ public class IOStructGen {
         popScope();
     }
 
-    private void parseStreamDeclaration(CommonTree streamDecl, Stream stream)
+    private void parseStreamDeclaration(CommonTree streamDecl, CTFStream stream)
             throws ParseException {
 
         /* There should be a left and right */
@@ -794,7 +794,7 @@ public class IOStructGen {
              * could be possible to just get the only existing stream, whatever
              * is its id.
              */
-            Stream stream = fTrace.getStream(null);
+            CTFStream stream = fTrace.getStream(null);
 
             if (stream != null) {
                 event.setStream(stream);
@@ -850,7 +850,7 @@ public class IOStructGen {
 
             long streamId = getStreamID(rightNode);
 
-            Stream stream = fTrace.getStream(streamId);
+            CTFStream stream = fTrace.getStream(streamId);
 
             if (stream == null) {
                 throw new ParseException("Stream " + streamId + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
index 39768fb443a2c93a76607010b1964225c5428463..01582c254b976c28fdf04d69a2088711b46cd072 100644 (file)
@@ -16,7 +16,7 @@ import java.io.Serializable;
 import java.util.Comparator;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
 import org.eclipse.linuxtools.ctf.core.trace.Utils;
 
 /**
@@ -25,7 +25,7 @@ import org.eclipse.linuxtools.ctf.core.trace.Utils;
  * Compares two StreamInputReader by their timestamp (smaller comes before).
  */
 public class StreamInputReaderTimestampComparator implements
-        Comparator<StreamInputReader>, Serializable {
+        Comparator<CTFStreamInputReader>, Serializable {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -39,11 +39,11 @@ public class StreamInputReaderTimestampComparator implements
 
     /**
      * @throws NullPointerException
-     *             If any {@link StreamInputReader} parameter is null, of if any
+     *             If any {@link CTFStreamInputReader} parameter is null, of if any
      *             of them does not contain a current event.
      */
     @Override
-    public int compare(StreamInputReader a, StreamInputReader b) {
+    public int compare(CTFStreamInputReader a, CTFStreamInputReader b) {
         EventDefinition event_a = a.getCurrentEvent();
         EventDefinition event_b = b.getCurrentEvent();
 
index ad669de7477a69eeba5a0847727021782554f892..0df2041d049fbf6c3b92dee9c3cbcf6e2d6c51f7 100644 (file)
@@ -25,8 +25,8 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.Metadata;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput;
 import org.eclipse.linuxtools.internal.lttng2.control.core.Activator;
 import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
 import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.LttngViewerCommands;
@@ -72,8 +72,8 @@ public class LttngRelaydConsumer {
         fPort = port;
         fSession = session;
         fCtfTrace = ctfTrace;
-        for (Stream s : fCtfTrace.getCTFTrace().getStreams()) {
-            for (StreamInput si : s.getStreamInputs()) {
+        for (CTFStream s : fCtfTrace.getCTFTrace().getStreams()) {
+            for (CTFStreamInput si : s.getStreamInputs()) {
                 fStreams.put(si.getStream().getId(), new File(si.getStream().getTrace().getPath() + si.getFilename()));
             }
         }
index 3f542b710f22b2a4161c2878699fd6160aabc28b..a08b29c3d594f70bb4f71026dcf2688192cb53b0 100644 (file)
@@ -15,7 +15,7 @@ package org.eclipse.linuxtools.tmf.ctf.core;
 
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
 import org.eclipse.linuxtools.internal.tmf.ctf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
@@ -127,7 +127,7 @@ public class CtfIterator extends CTFTraceReader
      * @return CtfTmfEvent The current event
      */
     public synchronized CtfTmfEvent getCurrentEvent() {
-        final StreamInputReader top = super.getPrio().peek();
+        final CTFStreamInputReader top = super.getPrio().peek();
         if (top != null) {
             if (!fCurLocation.equals(fPreviousLocation)) {
                 fPreviousLocation = fCurLocation;
This page took 0.087835 seconds and 5 git commands to generate.