[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
index 3ec8f15af0d5f231932e7e9a9fec0981691902a1..f391fea8ddb3162c594fe65462763edde7225f2e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
  * 
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -17,17 +17,18 @@ import java.io.IOException;
 import java.io.RandomAccessFile;
 
 import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
 
 /**
  * <b><u>TmfTraceStub</u></b>
  * <p>
  * Dummy test trace. Use in conjunction with TmfEventParserStub.
  */
-public class TmfTraceStub extends TmfTrace {
+public class TmfTraceStub extends TmfTrace<TmfEvent> {
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Attributes
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     // The actual stream
     private final RandomAccessFile fTrace;
@@ -35,9 +36,9 @@ public class TmfTraceStub extends TmfTrace {
     // The associated event parser
     private final ITmfEventParser fParser;
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Constructors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     /**
      * @param filename
@@ -49,19 +50,19 @@ public class TmfTraceStub extends TmfTrace {
 
     /**
      * @param filename
+     * @param cacheSize
      * @throws FileNotFoundException
      */
-    public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
-        this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
+    public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
+        this(filename, cacheSize, false);
     }
 
     /**
      * @param filename
-     * @param cacheSize
      * @throws FileNotFoundException
      */
-    public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
-        this(filename, cacheSize, false);
+    public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
+        this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
     }
 
     /**
@@ -70,39 +71,40 @@ public class TmfTraceStub extends TmfTrace {
      * @throws FileNotFoundException
      */
     public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
-        super(filename, cacheSize, waitForCompletion);
+        super(TmfEvent.class, filename, cacheSize);
         fTrace = new RandomAccessFile(filename, "r");
         fParser = new TmfEventParserStub();
-        indexStream();
+        indexTrace(waitForCompletion);
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Accessors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     public RandomAccessFile getStream() {
         return fTrace;
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Operators
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     /* (non-Javadoc)
      * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
      */
        public TmfTraceContext seekLocation(Object location) {
-       TmfTraceContext context = null;
         try {
                synchronized(fTrace) {
+                       // Position the trace, read the event (to obtain its timestamp)
+                       // and then re-position the trace (not great...)
                        fTrace.seek((location != null) ? (Long) location : 0);
-                       context = new TmfTraceContext(getCurrentLocation(), null, 0);
+                       TmfTraceContext context = new TmfTraceContext(getCurrentLocation());
+                       return context;
                }
                } catch (IOException e) {
-                       // TODO Auto-generated catch block
                        e.printStackTrace();
                }
-               return context;
+               return null;
     }
 
     /* (non-Javadoc)
@@ -127,9 +129,6 @@ public class TmfTraceStub extends TmfTrace {
                try {
                        // paserNextEvent updates the context
                        TmfEvent event = fParser.parseNextEvent(this, context);
-                       if (event != null) {
-                               context.setTimestamp(event.getTimestamp());
-                       }
                        return event;
                }
                catch (IOException e) {
@@ -138,8 +137,4 @@ public class TmfTraceStub extends TmfTrace {
                return null;
        }
 
-       // ========================================================================
-    // Helper functions
-    // ========================================================================
-
-}
+}
\ No newline at end of file
This page took 0.025372 seconds and 5 git commands to generate.