Define CTF API
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 12 Apr 2012 19:29:13 +0000 (15:29 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Mon, 16 Apr 2012 18:20:39 +0000 (14:20 -0400)
32 files changed:
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/StreamInputPacketIndexTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java [deleted file]
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderComparatorTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTimestampComparatorTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core/META-INF/MANIFEST.MF
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java [deleted file]
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/Metadata.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/StreamInputPacketIndex.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java [deleted file]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java [new file with mode: 0644]
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/event/metadata/exceptions/ParseException.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderComparator.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java

index 58358e6cbc75dadf1aca1dc1b39655ded5474fc0..260b17b569219b92d214d6071065637c264a62d0 100644 (file)
@@ -12,13 +12,13 @@ import java.util.Map;
 import java.util.UUID;
 
 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
index 99fca9d9d8794e6d1d37e3e410fe7706f4bb5e92..0992c7e2f51ea32a480ded9249f127c3aa7ea20e 100644 (file)
@@ -7,7 +7,7 @@ import java.util.Collection;
 import java.util.ListIterator;
 
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 import org.junit.After;
 import org.junit.Before;
diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketReaderTest.java
deleted file mode 100644 (file)
index 49aac9d..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.channels.FileChannel;
-
-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.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
-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.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputPacketReaderTest</code> contains tests for the
- * class <code>{@link StreamInputPacketReader}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class StreamInputPacketReaderTest {
-
-    private StreamInputPacketReader fixture;
-
-    /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(StreamInputPacketReaderTest.class);
-    }
-
-    /**
-     * Perform pre-test initialization.
-     *
-     * @throws CTFReaderException
-     */
-    @Before
-    public void setUp() throws CTFReaderException {
-        // FIXME The test is broken here. "FileChannel" can't be null because we
-        // need it further in. Heck this whole thing shouldn't be public in the
-        // first place, perhaps fixing that is the best way to go.
-        fixture = new StreamInputPacketReader(new StreamInputReader(
-                new StreamInput(new Stream(TestParams.createTrace()),
-                        (FileChannel) null, TestParams.getEmptyFile())));
-    }
-
-    /**
-     * Perform post-test clean-up.
-     */
-    @After
-    public void tearDown() {
-        // Add additional tear down code here
-    }
-
-    /**
-     * Run the StreamInputPacketReader(StreamInputReader) constructor test.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testStreamInputPacketReader() throws CTFReaderException {
-        StreamInputReader streamInputReader;
-        StreamInputPacketReader result;
-
-        streamInputReader = new StreamInputReader(new StreamInput(new Stream(
-                TestParams.createTrace()), (FileChannel) null,
-                TestParams.getEmptyFile()));
-
-        result = new StreamInputPacketReader(streamInputReader);
-
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the int getCPU() method test.
-     */
-    @Test
-    public void testGetCPU() {
-        int result = fixture.getCPU();
-        assertEquals(0, result);
-    }
-
-    /**
-     * Run the StreamInputPacketIndexEntry getCurrentPacket() method test.
-     */
-    @Test
-    public void testGetCurrentPacket() {
-        StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(1L);
-        fixture.setCurrentPacket(sipie);
-        StreamInputPacketIndexEntry result = fixture.getCurrentPacket();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String getPath() method test.
-     */
-    @Test
-    public void testGetPath() {
-        String result = fixture.getPath();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the StructDefinition getStreamPacketContextDef() method test.
-     */
-    @Test
-    public void testGetStreamPacketContextDef() {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        StructDefinition result = fixture.getStreamPacketContextDef();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the boolean hasMoreEvents() method test.
-     */
-    @Test
-    public void testHasMoreEvents() {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        boolean result = fixture.hasMoreEvents();
-        assertTrue(result);
-    }
-
-    /**
-     * Run the Definition lookupDefinition(String) method test.
-     */
-    @Test
-    public void testLookupDefinition() {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        String lookupPath = ""; //$NON-NLS-1$
-        Definition result = fixture.lookupDefinition(lookupPath);
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the EventDefinition readNextEvent() method test.
-     *
-     * @throws CTFReaderException
-     */
-    @Test
-    public void testReadNextEvent() throws CTFReaderException {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        EventDefinition result = fixture.readNextEvent();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
-     */
-    @Test
-    public void testSetCurrentPacket() {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
-                1L);
-        currentPacket.setPacketSizeBits(1);
-        fixture.setCurrentPacket(currentPacket);
-    }
-
-    /**
-     * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
-     */
-    @Test
-    public void testSetCurrentPacket_2() throws Exception {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        StreamInputPacketIndexEntry currentPacket = null;
-        fixture.setCurrentPacket(currentPacket);
-
-    }
-
-    /**
-     * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
-     */
-    @Test
-    public void testSetCurrentPacket_3() {
-        fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
-        StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
-                1L);
-        currentPacket.setTimestampBegin(1L);
-        currentPacket.setPacketSizeBits(1);
-
-        fixture.setCurrentPacket(currentPacket);
-    }
-}
index 280194de105746f762c7125c4b2541ed58c11dcf..2b03b3825f994c4945e52e44d2ea41d62c8e62d3 100644 (file)
@@ -8,9 +8,9 @@ import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 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.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderComparator;
 import org.junit.*;
 
index d9a6573877a0866b81c4b07ec580e33179b43033..f10138f57665c186b7fc59f00a7e11129121271a 100644 (file)
@@ -13,9 +13,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -23,7 +23,7 @@ import org.junit.Test;
 /**
  * The class <code>StreamInputReaderTest</code> contains tests for the class
  * <code>{@link StreamInputReader}</code>.
- * 
+ *
  * @author ematkho
  * @version $Revision: 1.0 $
  */
@@ -33,7 +33,7 @@ public class StreamInputReaderTest {
 
     /**
      * Launch the test.
-     * 
+     *
      * @param args
      *            the command line arguments
      */
@@ -43,8 +43,8 @@ public class StreamInputReaderTest {
 
     /**
      * Perform pre-test initialization.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -92,7 +92,7 @@ public class StreamInputReaderTest {
     /**
      * Run the StreamInputReader(StreamInput) constructor test, with an invalid
      * trace.
-     * 
+     *
      * @throws CTFReaderException
      */
     @Test(expected = CTFReaderException.class)
@@ -140,18 +140,9 @@ public class StreamInputReaderTest {
         assertEquals(1, result);
     }
 
-    /**
-     * Run the StreamInput getStreamInput() method test.
-     */
-    @Test
-    public void testGetStreamInput() {
-        StreamInput result = fixture.getStreamInput();
-        assertNotNull(result);
-    }
-
     /**
      * Run the void goToLastEvent() method test.
-     * 
+     *
      * @throws CTFReaderException
      */
     @Test
@@ -180,8 +171,8 @@ public class StreamInputReaderTest {
     /**
      * Run the seek test. Seek by passing an EventDefinition to which we've
      * given the timestamp we want.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testSeek_eventDefinition() throws CTFReaderException {
index 1d3a3ca73e4fb852d6495e93ce4503faf7dbf2e0..33ab674893304bfcb59c142af3933a20579d1ac2 100644 (file)
@@ -7,10 +7,10 @@ import java.nio.channels.FileChannel;
 
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 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.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderTimestampComparator;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
 import org.junit.*;
 
 /**
index 4a71dc3ac860f4beda325c4d821ceb96ee80a740..40963a9498db0a2856b0146cb1bbbea8236cc813 100644 (file)
@@ -10,9 +10,9 @@ import java.nio.channels.FileChannel;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
index cf660c8f9fbd545b87db965f6504e19d27bd661a..c6b6740613e080b09d7d7ee82888ea384e17f238 100644 (file)
@@ -8,13 +8,13 @@ import java.util.HashMap;
 import java.util.Set;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
index f129c9a9e7c51e20fc11fa3ea83f9af246d73b15..2c796beca2b1655883511e3b4664ce8014e4892f 100644 (file)
@@ -15,9 +15,9 @@ import org.eclipse.linuxtools.ctf.core.tests.TestParams;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
index bc67bb984e6099d31e3a9ea4cffffb1b51ddef51..64b5eb13b54f70ba0b9b97c09724c21d0a70635d 100644 (file)
@@ -12,7 +12,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
  org.antlr.runtime;bundle-version="3.2.0",
  org.eclipse.linuxtools.ctf.parser;bundle-version="0.1.0"
 Export-Package: org.eclipse.linuxtools.ctf.core.event,
- org.eclipse.linuxtools.ctf.core.event.metadata,
- org.eclipse.linuxtools.ctf.core.event.metadata.exceptions,
  org.eclipse.linuxtools.ctf.core.event.types,
  org.eclipse.linuxtools.ctf.core.trace
index c6e06f8d5c3e4c0d0aa3e0bd7ca30aa85425ac7b..1650ed1a08133fbe9889560887c5d0a7a574828e 100644 (file)
@@ -13,8 +13,8 @@
 package org.eclipse.linuxtools.ctf.core.event;
 
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 
 /**
  * <b><u>EventDeclaration</u></b>
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/DeclarationScope.java
deleted file mode 100644 (file)
index 57e887e..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial Design and Grammar
- * Contributors: Simon Marchi    - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.event.metadata;
-
-import java.util.HashMap;
-
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
-import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
-
-/**
- * <b><u>DeclarationScope</u></b>
- * <p>
- * A DeclarationScope keeps track of the various CTF declarations for a given
- * scope.
- */
-public class DeclarationScope {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private DeclarationScope parentScope = null;
-
-    private final HashMap<String, StructDeclaration> structs = new HashMap<String, StructDeclaration>();
-    private final HashMap<String, EnumDeclaration> enums = new HashMap<String, EnumDeclaration>();
-    private final HashMap<String, VariantDeclaration> variants = new HashMap<String, VariantDeclaration>();
-    private final HashMap<String, IDeclaration> types = new HashMap<String, IDeclaration>();
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Creates a declaration scope with no parent.
-     */
-    public DeclarationScope() {
-    }
-
-    /**
-     * Creates a declaration scope with the specified parent.
-     *
-     * @param parentScope
-     *            The parent of the newly created scope.
-     */
-    public DeclarationScope(DeclarationScope parentScope) {
-        this.parentScope = parentScope;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    /**
-     * Returns the parent of the current scope.
-     *
-     * @return The parent scope.
-     */
-    public DeclarationScope getParentScope() {
-        return parentScope;
-    }
-
-    // ------------------------------------------------------------------------
-    // Registration operations
-    // ------------------------------------------------------------------------
-
-    /**
-     * Registers a type declaration.
-     *
-     * @param name
-     *            The name of the type.
-     * @param declaration
-     *            The type declaration.
-     * @throws ParseException
-     *             if a type with the same name has already been defined.
-     */
-    public void registerType(String name, IDeclaration declaration)
-            throws ParseException {
-        /* Check if the type has been defined in the current scope */
-        if (types.containsKey(name)) {
-            throw new ParseException("Type " + name //$NON-NLS-1$
-                    + " has already been defined."); //$NON-NLS-1$
-        }
-
-        /* Add it to the register. */
-        types.put(name, declaration);
-    }
-
-    /**
-     * Registers a struct declaration.
-     *
-     * @param name
-     *            The name of the struct.
-     * @param declaration
-     *            The declaration of the struct.
-     * @throws ParseException
-     *             if a struct with the same name has already been registered.
-     */
-    public void registerStruct(String name, StructDeclaration declaration)
-            throws ParseException {
-        /* Check if the struct has been defined in the current scope. */
-        if (structs.containsKey(name)) {
-            throw new ParseException("struct " + name //$NON-NLS-1$
-                    + " has already been defined."); //$NON-NLS-1$
-        }
-
-        /* Add it to the register. */
-        structs.put(name, declaration);
-
-        /* It also defined a new type, so add it to the type declarations. */
-        String struct_prefix = "struct "; //$NON-NLS-1$
-        registerType(struct_prefix + name, declaration);
-    }
-
-    /**
-     * Registers an enum declaration.
-     *
-     * @param name
-     *            The name of the enum.
-     * @param declaration
-     *            The declaration of the enum.
-     * @throws ParseException
-     *             if an enum with the same name has already been registered.
-     */
-    public void registerEnum(String name, EnumDeclaration declaration)
-            throws ParseException {
-        /* Check if the enum has been defined in the current scope. */
-        if (lookupEnum(name) != null) {
-            throw new ParseException("enum " + name //$NON-NLS-1$
-                    + " has already been defined."); //$NON-NLS-1$
-        }
-
-        /* Add it to the register. */
-        enums.put(name, declaration);
-
-        /* It also defined a new type, so add it to the type declarations. */
-        String enum_prefix = "enum "; //$NON-NLS-1$
-        registerType(enum_prefix + name, declaration);
-    }
-
-    /**
-     * Registers a variant declaration.
-     *
-     * @param name
-     *            The name of the variant.
-     * @param declaration
-     *            The declaration of the variant.
-     * @throws ParseException
-     *             if a variant with the same name has already been registered.
-     */
-    public void registerVariant(String name, VariantDeclaration declaration)
-            throws ParseException {
-        /* Check if the variant has been defined in the current scope. */
-        if (lookupVariant(name) != null) {
-            throw new ParseException("variant " + name //$NON-NLS-1$
-                    + " has already been defined."); //$NON-NLS-1$
-        }
-
-        /* Add it to the register. */
-        variants.put(name, declaration);
-
-        /* It also defined a new type, so add it to the type declarations. */
-        String variant_prefix = "variant "; //$NON-NLS-1$
-        registerType(variant_prefix + name, declaration);
-    }
-
-    // ------------------------------------------------------------------------
-    // Lookup operations
-    // ------------------------------------------------------------------------
-
-    /**
-     * Looks up a type declaration in the current scope.
-     *
-     * @param name
-     *            The name of the type to search for.
-     * @return The type declaration, or null if no type with that name has been
-     *         defined.
-     */
-    public IDeclaration lookupType(String name) {
-        return types.get(name);
-    }
-
-    /**
-     * Looks up a type declaration in the current scope and recursively in the
-     * parent scopes.
-     *
-     * @param name
-     *            The name of the type to search for.
-     * @return The type declaration, or null if no type with that name has been
-     *         defined.
-     */
-    public IDeclaration rlookupType(String name) {
-        IDeclaration declaration = lookupType(name);
-        if (declaration != null) {
-            return declaration;
-        } else if (parentScope != null) {
-            return parentScope.rlookupType(name);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Looks up a struct declaration.
-     *
-     * @param name
-     *            The name of the struct to search for.
-     * @return The struct declaration, or null if no struct with that name has
-     *         been defined.
-     */
-    public StructDeclaration lookupStruct(String name) {
-        return structs.get(name);
-    }
-
-    /**
-     * Looks up a struct declaration in the current scope and recursively in the
-     * parent scopes.
-     *
-     * @param name
-     *            The name of the struct to search for.
-     * @return The struct declaration, or null if no struct with that name has
-     *         been defined.
-     */
-    public StructDeclaration rlookupStruct(String name) {
-        StructDeclaration declaration = lookupStruct(name);
-        if (declaration != null) {
-            return declaration;
-        } else if (parentScope != null) {
-            return parentScope.rlookupStruct(name);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Looks up a enum declaration.
-     *
-     * @param name
-     *            The name of the enum to search for.
-     * @return The enum declaration, or null if no enum with that name has been
-     *         defined.
-     */
-    public EnumDeclaration lookupEnum(String name) {
-        return enums.get(name);
-    }
-
-    /**
-     * Looks up an enum declaration in the current scope and recursively in the
-     * parent scopes.
-     *
-     * @param name
-     *            The name of the enum to search for.
-     * @return The enum declaration, or null if no enum with that name has been
-     *         defined.
-     */
-    public EnumDeclaration rlookupEnum(String name) {
-        EnumDeclaration declaration = lookupEnum(name);
-        if (declaration != null) {
-            return declaration;
-        } else if (parentScope != null) {
-            return parentScope.rlookupEnum(name);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Looks up a variant declaration.
-     *
-     * @param name
-     *            The name of the variant to search for.
-     * @return The variant declaration, or null if no variant with that name has
-     *         been defined.
-     */
-    public VariantDeclaration lookupVariant(String name) {
-        return variants.get(name);
-    }
-
-    /**
-     * Looks up a variant declaration in the current scope and recursively in
-     * the parent scopes.
-     *
-     * @param name
-     *            The name of the variant to search for.
-     * @return The variant declaration, or null if no variant with that name has
-     *         been defined.
-     */
-    public VariantDeclaration rlookupVariant(String name) {
-        VariantDeclaration declaration = lookupVariant(name);
-        if (declaration != null) {
-            return declaration;
-        } else if (parentScope != null) {
-            return parentScope.rlookupVariant(name);
-        } else {
-            return null;
-        }
-    }
-
-}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/metadata/exceptions/ParseException.java
deleted file mode 100644 (file)
index f4eb8a4..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.event.metadata.exceptions;
-
-/**
- * <b><u>ParseException</u></b>
- */
-public class ParseException extends Exception {
-
-    private static final long serialVersionUID = 7901917601459652080L;
-
-    public ParseException() {
-        super();
-    }
-
-    /**
-     * Constructor
-     *
-     * @param message
-     */
-    public ParseException(String message) {
-        super(message);
-    }
-
-}
index 599f3521ce827eeda5b39640e083858d9b9e781f..08732817a720ae973bf67b04751f329916b2fda9 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Set;
 import java.util.UUID;
 
 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
@@ -37,6 +36,9 @@ 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.Activator;
 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 
 /**
  * <b><u>CTFTrace</u></b>
@@ -637,7 +639,7 @@ public class CTFTrace implements IDefinitionScope {
         {
             return 0;
         }
-        return (Long) getClock().getProperty("offset");
+        return (Long) getClock().getProperty("offset"); //$NON-NLS-1$
     }
 
 }
index 0de9104e6c92713235edf4046d6ae6a3e8f5544d..a4fccaa53d0e379b277729f59c66f98f9d1a8fe2 100644 (file)
@@ -19,7 +19,10 @@ import java.util.Vector;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
 
 /**
  * Reads the events of a trace.
@@ -440,8 +443,7 @@ public class CTFTraceReader {
             int len = (width * this.eventCountPerTraceFile[se.getName()])
                     / numEvents;
 
-            StringBuilder sb = new StringBuilder(se.getStreamInput()
-                    .getFilename() + "\t["); //$NON-NLS-1$
+            StringBuilder sb = new StringBuilder(se.getFilename() + "\t["); //$NON-NLS-1$
 
             for (int i = 0; i < len; i++) {
                 sb.append('+');
index f1931a927ddfe83b7d61717c0540ff226b360975..10172d09e04329a31915f87a0b99a04d18c95ac5 100644 (file)
@@ -29,11 +29,11 @@ import org.antlr.runtime.ANTLRReaderStream;
 import org.antlr.runtime.CommonTokenStream;
 import org.antlr.runtime.RecognitionException;
 import org.antlr.runtime.tree.CommonTree;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.linuxtools.ctf.parser.CTFLexer;
 import org.eclipse.linuxtools.ctf.parser.CTFParser;
 import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return;
 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
 
 /**
  * <b><u>Metadata</u></b>
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 473eeaa..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial 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.Set;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-
-/**
- * <b><u>Stream</u></b>
- * <p>
- * Represents a stream in a trace.
- */
-public class Stream {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-
-    /**
-     * The numerical ID of the stream
-     */
-    private Long id = null;
-
-    /**
-     * Declarations of the stream-specific structures
-     */
-    private StructDeclaration packetContextDecl = null;
-    private StructDeclaration eventHeaderDecl = null;
-    private StructDeclaration eventContextDecl = null;
-
-    /**
-     * The trace to which the stream belongs
-     */
-    private CTFTrace trace = null;
-
-    /**
-     * Maps event ids to events
-     */
-    private final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
-
-    /**
-     * The inputs associated to this stream
-     */
-    private final Set<StreamInput> inputs = new HashSet<StreamInput>();
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a Stream that belongs to a Trace
-     *
-     * @param trace
-     *            The trace to which belongs this stream.
-     */
-    public Stream(CTFTrace trace) {
-        this.trace = trace;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    public void setId(long id) {
-        this.id = id;
-    }
-
-    public Long getId() {
-        return id;
-    }
-
-    public boolean idIsSet() {
-        return id != null;
-    }
-
-    public boolean eventHeaderIsSet() {
-        return eventHeaderDecl != null;
-    }
-
-    public boolean eventContextIsSet() {
-        return eventContextDecl != null;
-    }
-
-    public boolean packetContextIsSet() {
-        return packetContextDecl != null;
-    }
-
-    public void setEventHeader(StructDeclaration eventHeader) {
-        this.eventHeaderDecl = eventHeader;
-    }
-
-    public void setEventContext(StructDeclaration eventContext) {
-        this.eventContextDecl = eventContext;
-    }
-
-    public void setPacketContext(StructDeclaration packetContext) {
-        this.packetContextDecl = packetContext;
-    }
-
-    public StructDeclaration getEventHeaderDecl() {
-        return eventHeaderDecl;
-    }
-
-    public StructDeclaration getEventContextDecl() {
-        return eventContextDecl;
-    }
-
-    public StructDeclaration getPacketContextDecl() {
-        return packetContextDecl;
-    }
-
-    public Set<StreamInput> getStreamInputs() {
-        return inputs;
-    }
-
-    public CTFTrace getTrace() {
-        return trace;
-    }
-
-    public HashMap<Long, EventDeclaration> getEvents() {
-        return events;
-    }
-
-    // ------------------------------------------------------------------------
-    // 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
-     */
-    public void addEvent(EventDeclaration event) throws ParseException {
-        /*
-         * If there is an event without id (the null key), it must be the only
-         * one
-         */
-        if (events.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) && (events.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 (events.get(event.getId()) != null) {
-            throw new ParseException("Event id already exists"); //$NON-NLS-1$
-        }
-
-        /* Put the event in the map */
-        events.put(event.getId(), event);
-    }
-
-    /**
-     * Add an input to this Stream
-     *
-     * @param input
-     *            The StreamInput to add.
-     */
-    public void addInput(StreamInput input) {
-        inputs.add(input);
-    }
-
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
-     */
-    @Override
-    public String toString() {
-        return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$
-                + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$
-                + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$
-                + ", events=" + events + ", inputs=" + inputs + "]"; //$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 ca42c1e..0000000
+++ /dev/null
@@ -1,364 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileChannel.MapMode;
-import java.util.UUID;
-
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
-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.
- */
-public class StreamInput implements IDefinitionScope {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /**
-     * The associated Stream
-     */
-    private final Stream stream;
-
-    /**
-     * FileChannel to the trace file
-     */
-    private final FileChannel fileChannel;
-
-    /**
-     * Information on the file (used for debugging)
-     */
-    public final File file;
-
-    /**
-     * The packet index of this input
-     */
-    private final StreamInputPacketIndex index = new StreamInputPacketIndex();
-
-    private long timestampEnd;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Constructs a StreamInput.
-     *
-     * @param stream
-     *            The stream to which this StreamInput belongs to.
-     * @param fileChannel
-     *            The FileChannel to the trace file.
-     * @param file
-     *            Information about the trace file (for debugging purposes).
-     */
-    public StreamInput(Stream stream, FileChannel fileChannel, File file) {
-        this.stream = stream;
-        this.fileChannel = fileChannel;
-        this.file = file;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    public Stream getStream() {
-        return stream;
-    }
-
-    public StreamInputPacketIndex getIndex() {
-        return index;
-    }
-
-    public FileChannel getFileChannel() {
-        return fileChannel;
-    }
-
-    public String getFilename() {
-        return file.getName();
-    }
-
-    public long getTimestampEnd() {
-        return timestampEnd;
-    }
-
-    public void setTimestampEnd(long timestampEnd) {
-        this.timestampEnd = timestampEnd;
-    }
-
-    @Override
-    public String getPath() {
-        return ""; //$NON-NLS-1$
-    }
-
-    // ------------------------------------------------------------------------
-    // 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.
-     *
-     * @throws CTFReaderException
-     */
-    public void createIndex() throws CTFReaderException {
-        /*
-         * The size of the file in bytes
-         */
-        long fileSizeBytes = 0;
-        try {
-            fileSizeBytes = fileChannel.size();
-        } catch (IOException e) {
-            throw new CTFReaderException(e);
-        }
-
-        /*
-         * Offset of the current packet in bytes
-         */
-        long packetOffsetBytes = 0;
-
-        /*
-         * Initial size, it should map at least the packet header + context
-         * size.
-         *
-         * TODO: use a less arbitrary size.
-         */
-        long mapSize = 4096;
-
-        /*
-         * Definition of trace packet header
-         */
-        StructDefinition tracePacketHeaderDef = null;
-
-        /*
-         * Definition of trace stream packet context
-         */
-        StructDefinition streamPacketContextDef = null;
-
-        /*
-         * The BitBuffer to extract data from the StreamInput
-         */
-        BitBuffer bitBuffer = new BitBuffer();
-        bitBuffer.order(this.getStream().getTrace().getByteOrder());
-
-        /*
-         * Create the definitions we need to read the packet headers + contexts
-         */
-        if (getStream().getTrace().getPacketHeader() != null) {
-            tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
-                    .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
-        }
-
-        if (getStream().getPacketContextDecl() != null) {
-            streamPacketContextDef = getStream().getPacketContextDecl()
-                    .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
-        }
-
-        /*
-         * Scan through the packets of the file.
-         */
-        while (packetOffsetBytes < fileSizeBytes) {
-            /*
-             * If there is less data remaining than what we want to map, reduce
-             * the map size.
-             */
-            if ((fileSizeBytes - packetOffsetBytes) < mapSize) {
-                mapSize = fileSizeBytes - packetOffsetBytes;
-            }
-
-            /*
-             * Map the packet.
-             */
-            MappedByteBuffer bb;
-            try {
-                bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes,
-                        mapSize);
-            } catch (IOException e) {
-                throw new CTFReaderException(e);
-            }
-            bitBuffer.setByteBuffer(bb);
-
-            /*
-             * Create the index entry
-             */
-            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
-                    packetOffsetBytes);
-
-            /*
-             * Read the trace packet header if it exists.
-             */
-            if (tracePacketHeaderDef != null) {
-                tracePacketHeaderDef.read(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) {
-                    byte[] uuidArray = new byte[16];
-
-                    for (int i = 0; i < 16; i++) {
-                        IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
-                                .getElem(i);
-                        uuidArray[i] = (byte) uuidByteDef.getValue();
-                    }
-
-                    UUID uuid = Utils.makeUUID(uuidArray);
-
-                    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$
-                    }
-                }
-            }
-
-            /*
-             * Read the stream packet context if it exists.
-             */
-            if (streamPacketContextDef != null) {
-                streamPacketContextDef.read(bitBuffer);
-
-                /*
-                 * Read the content size in bits
-                 */
-                IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("content_size"); //$NON-NLS-1$
-                if (contentSizeDef != null) {
-                    packetIndex.setContentSizeBits((int) contentSizeDef
-                            .getValue());
-                } else {
-                    packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
-                }
-
-                /*
-                 * Read the packet size in bits
-                 */
-                IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("packet_size"); //$NON-NLS-1$
-                if (packetSizeDef != null) {
-                    packetIndex.setPacketSizeBits((int) packetSizeDef
-                            .getValue());
-                } else {
-                    if (packetIndex.getContentSizeBits() != 0) {
-                        packetIndex.setPacketSizeBits(packetIndex
-                                .getContentSizeBits());
-                    } else {
-                        packetIndex
-                                .setPacketSizeBits((int) (fileSizeBytes * 8));
-                    }
-                }
-
-                /*
-                 * Read the begin timestamp
-                 */
-                IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
-                if (timestampBeginDef != null) {
-                    packetIndex.setTimestampBegin( timestampBeginDef.getValue());
-                }
-
-                /*
-                 * Read the end timestamp
-                 */
-                IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
-                        .lookupDefinition("timestamp_end"); //$NON-NLS-1$
-                if (timestampEndDef != null) {
-                    packetIndex.setTimestampEnd(timestampEndDef
-                            .getValue());
-                    setTimestampEnd(packetIndex.getTimestampEnd());
-                }
-            } else {
-                /*
-                 * 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( (int) (fileSizeBytes * 8));
-                packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
-            }
-
-            /* 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());
-
-            /*
-             * Add the packet index entry to the index
-             */
-            index.addEntry(packetIndex);
-
-            /*
-             * Update the counting packet offset
-             */
-            packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
-
-        }
-        index.getEntries().get(0).setIndexBegin(0L);
-    }
-
-}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketIndex.java
deleted file mode 100644 (file)
index cf2252c..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.util.ListIterator;
-import java.util.Vector;
-
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-/**
- * <b><u>StreamInputPacketIndex</u></b>
- * <p>
- * TODO Implement me. Please.
- */
-public class StreamInputPacketIndex {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /**
-     * Entries of the index. They are sorted by increasing begin timestamp.
-     * index builder.
-     */
-    private final Vector<StreamInputPacketIndexEntry> entries = new Vector<StreamInputPacketIndexEntry>();
-
-    // ------------------------------------------------------------------------
-    // Getters/Setters/Predicates
-    // ------------------------------------------------------------------------
-
-    public Vector<StreamInputPacketIndexEntry> getEntries() {
-        return this.entries;
-    }
-
-    public ListIterator<StreamInputPacketIndexEntry> listIterator() {
-        return this.entries.listIterator();
-    }
-
-    public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
-        return this.entries.listIterator(n);
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    /**
-     * Adds an entry to the index.
-     *
-     * @param entry
-     *            The entry to add
-     * @throws CTFReaderException
-     */
-    public void addEntry(StreamInputPacketIndexEntry entry)
-            throws CTFReaderException {
-        assert (entry.getContentSizeBits() != 0);
-        assert (entry.getContentSizeBits() != 0);
-
-        if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
-            throw new CTFReaderException(
-                    "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
-        }
-
-        if (!this.entries.isEmpty()) {
-            if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
-                throw new CTFReaderException(
-                        "Packets begin timestamp decreasing"); //$NON-NLS-1$
-            }
-        }
-
-        this.entries.add(entry);
-    }
-
-    /**
-     * Given a timestamp, this methods returns the first PacketIndexEntry that
-     * could include the timestamp, that is the last packet with a begin
-     * timestamp smaller than the given timestamp.
-     *
-     * @param timestamp
-     *            The timestamp to look for.
-     * @return The StreamInputPacketEntry that corresponds to the packet that
-     *         includes the given timestamp.
-     */
-    public ListIterator<StreamInputPacketIndexEntry> search(final long timestamp) {
-        /*
-         * Start with min and max covering all the elements.
-         */
-        int max = this.entries.size() - 1;
-        int min = 0;
-
-        int guessI;
-        StreamInputPacketIndexEntry guessEntry = null;
-
-        if (timestamp < 0) {
-            throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$
-        }
-
-        for (;;) {
-            /*
-             * Guess in the middle of min and max. The +1 is so that in case
-             * (min + 1 == max), we choose the packet at the subscript "max"
-             * instead of the one at "min". Otherwise, it would give an infinite
-             * loop.
-             */
-            guessI = (max + min + 1) / 2;
-            guessEntry = this.entries.get(guessI);
-
-            /*
-             * If we reached the point where we focus on a single packet, our
-             * search is done.
-             */
-            if (min == max) {
-                break;
-            }
-
-            if (timestamp < guessEntry.getTimestampBegin()) {
-                /*
-                 * If the timestamp if before the begin timestamp, we know that
-                 * the packet to return is before the guess.
-                 */
-                max = guessI - 1;
-            } else if (timestamp >= guessEntry.getTimestampBegin()) {
-                /*
-                 * If the timestamp is after the begin timestamp, we know that
-                 * the packet to return is after the guess or is the guess.
-                 */
-                min = guessI;
-            }
-        }
-
-        return this.entries.listIterator(guessI);
-    }
-    /**
-     * Given a rank, this methods returns the first PacketIndexEntry that
-     * could include the rank, that is the last packet with a begin
-     * rank smaller than the given rank.
-     *
-     * @param index
-     *            The rank to look for.
-     * @return The StreamInputPacketEntry that corresponds to the packet that
-     *         includes the given timestamp.
-     */
-    public ListIterator<StreamInputPacketIndexEntry> searchIndex(final long index) {
-        /*
-         * Start with min and max covering all the elements.
-         */
-        int max = this.entries.size() - 1;
-        int min = 0;
-
-        int guessI;
-        StreamInputPacketIndexEntry guessEntry = null;
-
-        if (index < 0) {
-            throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$
-        }
-
-        for (;;) {
-            /*
-             * Guess in the middle of min and max. The +1 is so that in case
-             * (min + 1 == max), we choose the packet at the subscript "max"
-             * instead of the one at "min". Otherwise, it would give an infinite
-             * loop.
-             */
-            guessI = (max + min + 1) / 2;
-            guessEntry = this.entries.get(guessI);
-
-            /*
-             * If we reached the point where we focus on a single packet, our
-             * search is done.
-             */
-            if (min == max) {
-                break;
-            }
-
-            if (index < guessEntry.getIndexBegin()) {
-                /*
-                 * If the timestamp if before the begin timestamp, we know that
-                 * the packet to return is before the guess.
-                 */
-                max = guessI - 1;
-            } else if (index >= guessEntry.getIndexBegin()) {
-                /*
-                 * If the timestamp is after the begin timestamp, we know that
-                 * the packet to return is after the guess or is the guess.
-                 */
-                min = guessI;
-            }
-        }
-
-        return this.entries.listIterator(guessI);
-    }
-}
index bd6684d1915f0061f47377a7deed301eaddf0a6c..53e410605edd4612557065f833b907a5e417904d 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 
 /**
@@ -34,7 +35,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr
  * <p>
  * Reads the events of a packet of a trace file.
  */
-public class StreamInputPacketReader implements IDefinitionScope {
+class StreamInputPacketReader implements IDefinitionScope {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -109,7 +110,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
         /*
          * Set the BitBuffer's byte order.
          */
-        getBitBuffer().setByteOrder(streamInputReader.getStreamInput().getStream().getTrace().getByteOrder());
+        getBitBuffer().setByteOrder(streamInputReader.getByteOrder());
 
         /*
          * Create definitions needed to read the events.
index 8c421baec19b88a4d64874df5eead8fabdc6bc49..b33dd77e2db68a38b9394e66da449f5658020f10 100644 (file)
 
 package org.eclipse.linuxtools.ctf.core.trace;
 
+import java.nio.ByteOrder;
 import java.util.ListIterator;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
 import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 
 /**
@@ -90,8 +92,8 @@ public class StreamInputReader {
         return this.packetReader.getStreamPacketContextDef();
     }
 
-    public StreamInput getStreamInput() {
-        return this.streamInput;
+    public ByteOrder getByteOrder() {
+        return streamInput.getStream().getTrace().getByteOrder();
     }
 
     public int getName() {
@@ -106,6 +108,17 @@ public class StreamInputReader {
         return this.packetReader.getCPU();
     }
 
+    public String getFilename() {
+        return streamInput.getFilename();
+    }
+
+    /*
+     * for internal use only
+     */
+    StreamInput getStreamInput() {
+        return streamInput;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -242,4 +255,6 @@ public class StreamInputReader {
         return packetReader;
     }
 
+
+
 }
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReaderTimestampComparator.java
deleted file mode 100644 (file)
index 0971758..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * <b><u>StreamInputReaderTimestampComparator</u></b>
- * <p>
- * Compares two StreamInputReader by their timestamp (smaller comes before).
- */
-public class StreamInputReaderTimestampComparator implements
-        Comparator<StreamInputReader>, Serializable {
-
-    // ------------------------------------------------------------------------
-    // Constants
-    // ------------------------------------------------------------------------
-
-    private static final long serialVersionUID = 1066434959451875045L;
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int compare(StreamInputReader a, StreamInputReader b) {
-        // TODO: use unsigned comparison to avoid sign errors if needed
-        if (a.getCurrentEvent() == null) {
-            return 0;
-        }
-        if (b.getCurrentEvent() == null) {
-            return 0;
-        }
-        long ta = a.getCurrentEvent().timestamp;
-        long tb = b.getCurrentEvent().timestamp;
-
-        if (ta < tb) {
-            return -1;
-        } else if (ta > tb) {
-            return 1;
-        } else {
-            return 0;
-        }
-    }
-
-}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java
new file mode 100644 (file)
index 0000000..82ed90b
--- /dev/null
@@ -0,0 +1,311 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial Design and Grammar
+ * Contributors: Simon Marchi    - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.metadata;
+
+import java.util.HashMap;
+
+import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+
+/**
+ * <b><u>DeclarationScope</u></b>
+ * <p>
+ * A DeclarationScope keeps track of the various CTF declarations for a given
+ * scope.
+ */
+public class DeclarationScope {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private DeclarationScope parentScope = null;
+
+    private final HashMap<String, StructDeclaration> structs = new HashMap<String, StructDeclaration>();
+    private final HashMap<String, EnumDeclaration> enums = new HashMap<String, EnumDeclaration>();
+    private final HashMap<String, VariantDeclaration> variants = new HashMap<String, VariantDeclaration>();
+    private final HashMap<String, IDeclaration> types = new HashMap<String, IDeclaration>();
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Creates a declaration scope with no parent.
+     */
+    public DeclarationScope() {
+    }
+
+    /**
+     * Creates a declaration scope with the specified parent.
+     *
+     * @param parentScope
+     *            The parent of the newly created scope.
+     */
+    public DeclarationScope(DeclarationScope parentScope) {
+        this.parentScope = parentScope;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    /**
+     * Returns the parent of the current scope.
+     *
+     * @return The parent scope.
+     */
+    public DeclarationScope getParentScope() {
+        return parentScope;
+    }
+
+    // ------------------------------------------------------------------------
+    // Registration operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Registers a type declaration.
+     *
+     * @param name
+     *            The name of the type.
+     * @param declaration
+     *            The type declaration.
+     * @throws ParseException
+     *             if a type with the same name has already been defined.
+     */
+    public void registerType(String name, IDeclaration declaration)
+            throws ParseException {
+        /* Check if the type has been defined in the current scope */
+        if (types.containsKey(name)) {
+            throw new ParseException("Type " + name //$NON-NLS-1$
+                    + " has already been defined."); //$NON-NLS-1$
+        }
+
+        /* Add it to the register. */
+        types.put(name, declaration);
+    }
+
+    /**
+     * Registers a struct declaration.
+     *
+     * @param name
+     *            The name of the struct.
+     * @param declaration
+     *            The declaration of the struct.
+     * @throws ParseException
+     *             if a struct with the same name has already been registered.
+     */
+    public void registerStruct(String name, StructDeclaration declaration)
+            throws ParseException {
+        /* Check if the struct has been defined in the current scope. */
+        if (structs.containsKey(name)) {
+            throw new ParseException("struct " + name //$NON-NLS-1$
+                    + " has already been defined."); //$NON-NLS-1$
+        }
+
+        /* Add it to the register. */
+        structs.put(name, declaration);
+
+        /* It also defined a new type, so add it to the type declarations. */
+        String struct_prefix = "struct "; //$NON-NLS-1$
+        registerType(struct_prefix + name, declaration);
+    }
+
+    /**
+     * Registers an enum declaration.
+     *
+     * @param name
+     *            The name of the enum.
+     * @param declaration
+     *            The declaration of the enum.
+     * @throws ParseException
+     *             if an enum with the same name has already been registered.
+     */
+    public void registerEnum(String name, EnumDeclaration declaration)
+            throws ParseException {
+        /* Check if the enum has been defined in the current scope. */
+        if (lookupEnum(name) != null) {
+            throw new ParseException("enum " + name //$NON-NLS-1$
+                    + " has already been defined."); //$NON-NLS-1$
+        }
+
+        /* Add it to the register. */
+        enums.put(name, declaration);
+
+        /* It also defined a new type, so add it to the type declarations. */
+        String enum_prefix = "enum "; //$NON-NLS-1$
+        registerType(enum_prefix + name, declaration);
+    }
+
+    /**
+     * Registers a variant declaration.
+     *
+     * @param name
+     *            The name of the variant.
+     * @param declaration
+     *            The declaration of the variant.
+     * @throws ParseException
+     *             if a variant with the same name has already been registered.
+     */
+    public void registerVariant(String name, VariantDeclaration declaration)
+            throws ParseException {
+        /* Check if the variant has been defined in the current scope. */
+        if (lookupVariant(name) != null) {
+            throw new ParseException("variant " + name //$NON-NLS-1$
+                    + " has already been defined."); //$NON-NLS-1$
+        }
+
+        /* Add it to the register. */
+        variants.put(name, declaration);
+
+        /* It also defined a new type, so add it to the type declarations. */
+        String variant_prefix = "variant "; //$NON-NLS-1$
+        registerType(variant_prefix + name, declaration);
+    }
+
+    // ------------------------------------------------------------------------
+    // Lookup operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Looks up a type declaration in the current scope.
+     *
+     * @param name
+     *            The name of the type to search for.
+     * @return The type declaration, or null if no type with that name has been
+     *         defined.
+     */
+    public IDeclaration lookupType(String name) {
+        return types.get(name);
+    }
+
+    /**
+     * Looks up a type declaration in the current scope and recursively in the
+     * parent scopes.
+     *
+     * @param name
+     *            The name of the type to search for.
+     * @return The type declaration, or null if no type with that name has been
+     *         defined.
+     */
+    public IDeclaration rlookupType(String name) {
+        IDeclaration declaration = lookupType(name);
+        if (declaration != null) {
+            return declaration;
+        } else if (parentScope != null) {
+            return parentScope.rlookupType(name);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Looks up a struct declaration.
+     *
+     * @param name
+     *            The name of the struct to search for.
+     * @return The struct declaration, or null if no struct with that name has
+     *         been defined.
+     */
+    public StructDeclaration lookupStruct(String name) {
+        return structs.get(name);
+    }
+
+    /**
+     * Looks up a struct declaration in the current scope and recursively in the
+     * parent scopes.
+     *
+     * @param name
+     *            The name of the struct to search for.
+     * @return The struct declaration, or null if no struct with that name has
+     *         been defined.
+     */
+    public StructDeclaration rlookupStruct(String name) {
+        StructDeclaration declaration = lookupStruct(name);
+        if (declaration != null) {
+            return declaration;
+        } else if (parentScope != null) {
+            return parentScope.rlookupStruct(name);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Looks up a enum declaration.
+     *
+     * @param name
+     *            The name of the enum to search for.
+     * @return The enum declaration, or null if no enum with that name has been
+     *         defined.
+     */
+    public EnumDeclaration lookupEnum(String name) {
+        return enums.get(name);
+    }
+
+    /**
+     * Looks up an enum declaration in the current scope and recursively in the
+     * parent scopes.
+     *
+     * @param name
+     *            The name of the enum to search for.
+     * @return The enum declaration, or null if no enum with that name has been
+     *         defined.
+     */
+    public EnumDeclaration rlookupEnum(String name) {
+        EnumDeclaration declaration = lookupEnum(name);
+        if (declaration != null) {
+            return declaration;
+        } else if (parentScope != null) {
+            return parentScope.rlookupEnum(name);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Looks up a variant declaration.
+     *
+     * @param name
+     *            The name of the variant to search for.
+     * @return The variant declaration, or null if no variant with that name has
+     *         been defined.
+     */
+    public VariantDeclaration lookupVariant(String name) {
+        return variants.get(name);
+    }
+
+    /**
+     * Looks up a variant declaration in the current scope and recursively in
+     * the parent scopes.
+     *
+     * @param name
+     *            The name of the variant to search for.
+     * @return The variant declaration, or null if no variant with that name has
+     *         been defined.
+     */
+    public VariantDeclaration rlookupVariant(String name) {
+        VariantDeclaration declaration = lookupVariant(name);
+        if (declaration != null) {
+            return declaration;
+        } else if (parentScope != null) {
+            return parentScope.rlookupVariant(name);
+        } else {
+            return null;
+        }
+    }
+
+}
index e6e9e47cbf85ec9c2b8fe87035bcefdeeb425004..40588ebf36a22521393962c000b940e27eef0d1d 100644 (file)
@@ -25,8 +25,6 @@ import java.util.UUID;
 import org.antlr.runtime.tree.CommonTree;
 import org.eclipse.linuxtools.ctf.core.event.CTFClock;
 import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.DeclarationScope;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
@@ -37,9 +35,10 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
 import org.eclipse.linuxtools.ctf.parser.CTFParser;
 import org.eclipse.linuxtools.internal.ctf.core.Activator;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
 
 /*
  * Asserts throughout this class denote the assumptions we can make because of
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/ParseException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/ParseException.java
new file mode 100644 (file)
index 0000000..48055d9
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;
+
+/**
+ * <b><u>ParseException</u></b>
+ */
+public class ParseException extends Exception {
+
+    private static final long serialVersionUID = 7901917601459652080L;
+
+    public ParseException() {
+        super();
+    }
+
+    /**
+     * Constructor
+     *
+     * @param message
+     */
+    public ParseException(String message) {
+        super(message);
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/Stream.java
new file mode 100644 (file)
index 0000000..9a83d84
--- /dev/null
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+
+/**
+ * <b><u>Stream</u></b>
+ * <p>
+ * Represents a stream in a trace.
+ */
+public class Stream {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * The numerical ID of the stream
+     */
+    private Long id = null;
+
+    /**
+     * Declarations of the stream-specific structures
+     */
+    private StructDeclaration packetContextDecl = null;
+    private StructDeclaration eventHeaderDecl = null;
+    private StructDeclaration eventContextDecl = null;
+
+    /**
+     * The trace to which the stream belongs
+     */
+    private CTFTrace trace = null;
+
+    /**
+     * Maps event ids to events
+     */
+    private final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
+
+    /**
+     * The inputs associated to this stream
+     */
+    private final Set<StreamInput> inputs = new HashSet<StreamInput>();
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a Stream that belongs to a Trace
+     *
+     * @param trace
+     *            The trace to which belongs this stream.
+     */
+    public Stream(CTFTrace trace) {
+        this.trace = trace;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public boolean idIsSet() {
+        return id != null;
+    }
+
+    public boolean eventHeaderIsSet() {
+        return eventHeaderDecl != null;
+    }
+
+    public boolean eventContextIsSet() {
+        return eventContextDecl != null;
+    }
+
+    public boolean packetContextIsSet() {
+        return packetContextDecl != null;
+    }
+
+    public void setEventHeader(StructDeclaration eventHeader) {
+        this.eventHeaderDecl = eventHeader;
+    }
+
+    public void setEventContext(StructDeclaration eventContext) {
+        this.eventContextDecl = eventContext;
+    }
+
+    public void setPacketContext(StructDeclaration packetContext) {
+        this.packetContextDecl = packetContext;
+    }
+
+    public StructDeclaration getEventHeaderDecl() {
+        return eventHeaderDecl;
+    }
+
+    public StructDeclaration getEventContextDecl() {
+        return eventContextDecl;
+    }
+
+    public StructDeclaration getPacketContextDecl() {
+        return packetContextDecl;
+    }
+
+    public Set<StreamInput> getStreamInputs() {
+        return inputs;
+    }
+
+    public CTFTrace getTrace() {
+        return trace;
+    }
+
+    public HashMap<Long, EventDeclaration> getEvents() {
+        return events;
+    }
+
+    // ------------------------------------------------------------------------
+    // 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
+     */
+    public void addEvent(EventDeclaration event) throws ParseException {
+        /*
+         * If there is an event without id (the null key), it must be the only
+         * one
+         */
+        if (events.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) && (events.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 (events.get(event.getId()) != null) {
+            throw new ParseException("Event id already exists"); //$NON-NLS-1$
+        }
+
+        /* Put the event in the map */
+        events.put(event.getId(), event);
+    }
+
+    /**
+     * Add an input to this Stream
+     *
+     * @param input
+     *            The StreamInput to add.
+     */
+    public void addInput(StreamInput input) {
+        inputs.add(input);
+    }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$
+                + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$
+                + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$
+                + ", events=" + events + ", inputs=" + inputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java
new file mode 100644 (file)
index 0000000..931b5d3
--- /dev/null
@@ -0,0 +1,366 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+import java.util.UUID;
+
+import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.Utils;
+import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+
+/**
+ * <b><u>StreamInput</u></b>
+ * <p>
+ * Represents a trace file that belongs to a certain stream.
+ */
+public class StreamInput implements IDefinitionScope {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The associated Stream
+     */
+    private final Stream stream;
+
+    /**
+     * FileChannel to the trace file
+     */
+    private final FileChannel fileChannel;
+
+    /**
+     * Information on the file (used for debugging)
+     */
+    public final File file;
+
+    /**
+     * The packet index of this input
+     */
+    private final StreamInputPacketIndex index = new StreamInputPacketIndex();
+
+    private long timestampEnd;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructs a StreamInput.
+     *
+     * @param stream
+     *            The stream to which this StreamInput belongs to.
+     * @param fileChannel
+     *            The FileChannel to the trace file.
+     * @param file
+     *            Information about the trace file (for debugging purposes).
+     */
+    public StreamInput(Stream stream, FileChannel fileChannel, File file) {
+        this.stream = stream;
+        this.fileChannel = fileChannel;
+        this.file = file;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    public Stream getStream() {
+        return stream;
+    }
+
+    public StreamInputPacketIndex getIndex() {
+        return index;
+    }
+
+    public FileChannel getFileChannel() {
+        return fileChannel;
+    }
+
+    public String getFilename() {
+        return file.getName();
+    }
+
+    public long getTimestampEnd() {
+        return timestampEnd;
+    }
+
+    public void setTimestampEnd(long timestampEnd) {
+        this.timestampEnd = timestampEnd;
+    }
+
+    @Override
+    public String getPath() {
+        return ""; //$NON-NLS-1$
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @SuppressWarnings("unused")
+    @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.
+     *
+     * @throws CTFReaderException
+     */
+    public void createIndex() throws CTFReaderException {
+        /*
+         * The size of the file in bytes
+         */
+        long fileSizeBytes = 0;
+        try {
+            fileSizeBytes = fileChannel.size();
+        } catch (IOException e) {
+            throw new CTFReaderException(e);
+        }
+
+        /*
+         * Offset of the current packet in bytes
+         */
+        long packetOffsetBytes = 0;
+
+        /*
+         * Initial size, it should map at least the packet header + context
+         * size.
+         *
+         * TODO: use a less arbitrary size.
+         */
+        long mapSize = 4096;
+
+        /*
+         * Definition of trace packet header
+         */
+        StructDefinition tracePacketHeaderDef = null;
+
+        /*
+         * Definition of trace stream packet context
+         */
+        StructDefinition streamPacketContextDef = null;
+
+        /*
+         * The BitBuffer to extract data from the StreamInput
+         */
+        BitBuffer bitBuffer = new BitBuffer();
+        bitBuffer.order(this.getStream().getTrace().getByteOrder());
+
+        /*
+         * Create the definitions we need to read the packet headers + contexts
+         */
+        if (getStream().getTrace().getPacketHeader() != null) {
+            tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
+                    .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
+        }
+
+        if (getStream().getPacketContextDecl() != null) {
+            streamPacketContextDef = getStream().getPacketContextDecl()
+                    .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
+        }
+
+        /*
+         * Scan through the packets of the file.
+         */
+        while (packetOffsetBytes < fileSizeBytes) {
+            /*
+             * If there is less data remaining than what we want to map, reduce
+             * the map size.
+             */
+            if ((fileSizeBytes - packetOffsetBytes) < mapSize) {
+                mapSize = fileSizeBytes - packetOffsetBytes;
+            }
+
+            /*
+             * Map the packet.
+             */
+            MappedByteBuffer bb;
+            try {
+                bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes,
+                        mapSize);
+            } catch (IOException e) {
+                throw new CTFReaderException(e);
+            }
+            bitBuffer.setByteBuffer(bb);
+
+            /*
+             * Create the index entry
+             */
+            StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
+                    packetOffsetBytes);
+
+            /*
+             * Read the trace packet header if it exists.
+             */
+            if (tracePacketHeaderDef != null) {
+                tracePacketHeaderDef.read(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) {
+                    byte[] uuidArray = new byte[16];
+
+                    for (int i = 0; i < 16; i++) {
+                        IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
+                                .getElem(i);
+                        uuidArray[i] = (byte) uuidByteDef.getValue();
+                    }
+
+                    UUID uuid = Utils.makeUUID(uuidArray);
+
+                    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$
+                    }
+                }
+            }
+
+            /*
+             * Read the stream packet context if it exists.
+             */
+            if (streamPacketContextDef != null) {
+                streamPacketContextDef.read(bitBuffer);
+
+                /*
+                 * Read the content size in bits
+                 */
+                IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
+                        .lookupDefinition("content_size"); //$NON-NLS-1$
+                if (contentSizeDef != null) {
+                    packetIndex.setContentSizeBits((int) contentSizeDef
+                            .getValue());
+                } else {
+                    packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
+                }
+
+                /*
+                 * Read the packet size in bits
+                 */
+                IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
+                        .lookupDefinition("packet_size"); //$NON-NLS-1$
+                if (packetSizeDef != null) {
+                    packetIndex.setPacketSizeBits((int) packetSizeDef
+                            .getValue());
+                } else {
+                    if (packetIndex.getContentSizeBits() != 0) {
+                        packetIndex.setPacketSizeBits(packetIndex
+                                .getContentSizeBits());
+                    } else {
+                        packetIndex
+                                .setPacketSizeBits((int) (fileSizeBytes * 8));
+                    }
+                }
+
+                /*
+                 * Read the begin timestamp
+                 */
+                IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
+                        .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
+                if (timestampBeginDef != null) {
+                    packetIndex.setTimestampBegin( timestampBeginDef.getValue());
+                }
+
+                /*
+                 * Read the end timestamp
+                 */
+                IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
+                        .lookupDefinition("timestamp_end"); //$NON-NLS-1$
+                if (timestampEndDef != null) {
+                    packetIndex.setTimestampEnd(timestampEndDef
+                            .getValue());
+                    setTimestampEnd(packetIndex.getTimestampEnd());
+                }
+            } else {
+                /*
+                 * 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( (int) (fileSizeBytes * 8));
+                packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
+            }
+
+            /* 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());
+
+            /*
+             * Add the packet index entry to the index
+             */
+            index.addEntry(packetIndex);
+
+            /*
+             * Update the counting packet offset
+             */
+            packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
+
+        }
+        index.getEntries().get(0).setIndexBegin(0L);
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java
new file mode 100644 (file)
index 0000000..80723ea
--- /dev/null
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.util.ListIterator;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+/**
+ * <b><u>StreamInputPacketIndex</u></b>
+ * <p>
+ * TODO Implement me. Please.
+ */
+public class StreamInputPacketIndex {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * Entries of the index. They are sorted by increasing begin timestamp.
+     * index builder.
+     */
+    private final Vector<StreamInputPacketIndexEntry> entries = new Vector<StreamInputPacketIndexEntry>();
+
+    // ------------------------------------------------------------------------
+    // Getters/Setters/Predicates
+    // ------------------------------------------------------------------------
+
+    public Vector<StreamInputPacketIndexEntry> getEntries() {
+        return this.entries;
+    }
+
+    public ListIterator<StreamInputPacketIndexEntry> listIterator() {
+        return this.entries.listIterator();
+    }
+
+    public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
+        return this.entries.listIterator(n);
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /**
+     * Adds an entry to the index.
+     *
+     * @param entry
+     *            The entry to add
+     * @throws CTFReaderException
+     */
+    public void addEntry(StreamInputPacketIndexEntry entry)
+            throws CTFReaderException {
+        assert (entry.getContentSizeBits() != 0);
+        assert (entry.getContentSizeBits() != 0);
+
+        if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
+            throw new CTFReaderException(
+                    "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
+        }
+
+        if (!this.entries.isEmpty()) {
+            if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
+                throw new CTFReaderException(
+                        "Packets begin timestamp decreasing"); //$NON-NLS-1$
+            }
+        }
+
+        this.entries.add(entry);
+    }
+
+    /**
+     * Given a timestamp, this methods returns the first PacketIndexEntry that
+     * could include the timestamp, that is the last packet with a begin
+     * timestamp smaller than the given timestamp.
+     *
+     * @param timestamp
+     *            The timestamp to look for.
+     * @return The StreamInputPacketEntry that corresponds to the packet that
+     *         includes the given timestamp.
+     */
+    public ListIterator<StreamInputPacketIndexEntry> search(final long timestamp) {
+        /*
+         * Start with min and max covering all the elements.
+         */
+        int max = this.entries.size() - 1;
+        int min = 0;
+
+        int guessI;
+        StreamInputPacketIndexEntry guessEntry = null;
+
+        if (timestamp < 0) {
+            throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$
+        }
+
+        for (;;) {
+            /*
+             * Guess in the middle of min and max. The +1 is so that in case
+             * (min + 1 == max), we choose the packet at the subscript "max"
+             * instead of the one at "min". Otherwise, it would give an infinite
+             * loop.
+             */
+            guessI = (max + min + 1) / 2;
+            guessEntry = this.entries.get(guessI);
+
+            /*
+             * If we reached the point where we focus on a single packet, our
+             * search is done.
+             */
+            if (min == max) {
+                break;
+            }
+
+            if (timestamp < guessEntry.getTimestampBegin()) {
+                /*
+                 * If the timestamp if before the begin timestamp, we know that
+                 * the packet to return is before the guess.
+                 */
+                max = guessI - 1;
+            } else if (timestamp >= guessEntry.getTimestampBegin()) {
+                /*
+                 * If the timestamp is after the begin timestamp, we know that
+                 * the packet to return is after the guess or is the guess.
+                 */
+                min = guessI;
+            }
+        }
+
+        return this.entries.listIterator(guessI);
+    }
+    /**
+     * Given a rank, this methods returns the first PacketIndexEntry that
+     * could include the rank, that is the last packet with a begin
+     * rank smaller than the given rank.
+     *
+     * @param index
+     *            The rank to look for.
+     * @return The StreamInputPacketEntry that corresponds to the packet that
+     *         includes the given timestamp.
+     */
+    public ListIterator<StreamInputPacketIndexEntry> searchIndex(final long index) {
+        /*
+         * Start with min and max covering all the elements.
+         */
+        int max = this.entries.size() - 1;
+        int min = 0;
+
+        int guessI;
+        StreamInputPacketIndexEntry guessEntry = null;
+
+        if (index < 0) {
+            throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$
+        }
+
+        for (;;) {
+            /*
+             * Guess in the middle of min and max. The +1 is so that in case
+             * (min + 1 == max), we choose the packet at the subscript "max"
+             * instead of the one at "min". Otherwise, it would give an infinite
+             * loop.
+             */
+            guessI = (max + min + 1) / 2;
+            guessEntry = this.entries.get(guessI);
+
+            /*
+             * If we reached the point where we focus on a single packet, our
+             * search is done.
+             */
+            if (min == max) {
+                break;
+            }
+
+            if (index < guessEntry.getIndexBegin()) {
+                /*
+                 * If the timestamp if before the begin timestamp, we know that
+                 * the packet to return is before the guess.
+                 */
+                max = guessI - 1;
+            } else if (index >= guessEntry.getIndexBegin()) {
+                /*
+                 * If the timestamp is after the begin timestamp, we know that
+                 * the packet to return is after the guess or is the guess.
+                 */
+                min = guessI;
+            }
+        }
+
+        return this.entries.listIterator(guessI);
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java
new file mode 100644 (file)
index 0000000..7bc12e7
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+
+
+/**
+ * <b><u>StreamInputReaderTimestampComparator</u></b>
+ * <p>
+ * Compares two StreamInputReader by their timestamp (smaller comes before).
+ */
+public class StreamInputReaderTimestampComparator implements
+        Comparator<StreamInputReader>, Serializable {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    private static final long serialVersionUID = 1066434959451875045L;
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int compare(StreamInputReader a, StreamInputReader b) {
+        // TODO: use unsigned comparison to avoid sign errors if needed
+        if (a.getCurrentEvent() == null) {
+            return 0;
+        }
+        if (b.getCurrentEvent() == null) {
+            return 0;
+        }
+        long ta = a.getCurrentEvent().timestamp;
+        long tb = b.getCurrentEvent().timestamp;
+
+        if (ta < tb) {
+            return -1;
+        } else if (ta > tb) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+}
index 67bf70891bb8faa7f823485dd9022623dda54dbe..ad469f780a00470607e50bfbe77fa5284efa6cd5 100644 (file)
@@ -47,7 +47,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     public CtfTmfEvent getCurrentEvent() {
         StreamInputReader top = super.prio.peek();
         if (top != null) {
-            return new CtfTmfEvent(top.getCurrentEvent(), top, ctfTmfTrace);
+            return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace);
         }
         return null;
     }
index 76d337ea0ec0b2b9932c8008145082166580d650..1500c504aed0ecdaacde085060ad13d998d53eb2 100644 (file)
@@ -19,7 +19,6 @@ import java.util.Map.Entry;
 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.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
@@ -65,7 +64,7 @@ public final class CtfTmfEvent implements ITmfEvent {
      * @param eventDef
      * @param top
      */
-    public CtfTmfEvent(EventDefinition eventDef, StreamInputReader top,
+    public CtfTmfEvent(EventDefinition eventDef, String fileName,
             CtfTmfTrace originTrace) {
         this.fTrace = originTrace;
 
@@ -85,7 +84,7 @@ public final class CtfTmfEvent implements ITmfEvent {
         this.sourceCPU = eventDef.getCPU();
         this.typeId = eventDef.getDeclaration().getId();
         this.eventName = eventDef.getDeclaration().getName();
-        this.fileName = top.getStreamInput().getFilename();
+        this.fileName =  fileName;
 
         /* Read the fields */
         this.fContent = new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID,
This page took 0.09434 seconds and 5 git commands to generate.