fix empty trace bug
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 1 May 2012 20:35:56 +0000 (16:35 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 1 May 2012 20:36:48 +0000 (16:36 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
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/CtfLocation.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java

index 751bc0a2578eea1e8b497ad3adb08bc30629002e..24352443987b711776898c6c9a13fac5ac85cd94 100644 (file)
@@ -6,10 +6,12 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 
 public class CtfIterator extends CTFTraceReader implements ITmfContext,
-Comparable<CtfIterator> {
+        Comparable<CtfIterator> {
 
     private final CtfTmfTrace ctfTmfTrace;
 
+    final public static CtfLocation nullLocation = new CtfLocation(
+            CtfLocation.INVALID_LOCATION);
     private CtfLocation curLocation;
     private long curRank;
 
@@ -22,21 +24,39 @@ Comparable<CtfIterator> {
     public CtfIterator(final CtfTmfTrace trace) {
         super(trace.getCTFTrace());
         this.ctfTmfTrace = trace;
+        if (this.hasMoreEvents()) {
 
-        // FIXME put the real stuff here...
-        this.curLocation = new CtfLocation(trace.getStartTime());
-        this.curRank = 0;
+            this.curLocation = new CtfLocation(trace.getStartTime());
+            this.curRank = 0;
+        } else {
+            setUnknownLocation();
+        }
     }
 
-    public CtfIterator(final CtfTmfTrace trace, final long timestampValue, final long rank) {
+    /**
+     *
+     */
+    private void setUnknownLocation() {
+        this.curLocation = nullLocation;
+        this.curRank = UNKNOWN_RANK;
+    }
+
+    public CtfIterator(final CtfTmfTrace trace, final long timestampValue,
+            final long rank) {
         super(trace.getCTFTrace());
+
         this.ctfTmfTrace = trace;
-        this.curLocation = (new CtfLocation(this.getCurrentEvent()
-                .getTimestampValue()));
-        if (this.getCurrentEvent().getTimestampValue() != timestampValue)
-            this.seek(timestampValue);
+        if (this.hasMoreEvents()) {
+            this.curLocation = (new CtfLocation(this.getCurrentEvent()
+                    .getTimestampValue()));
+            if (this.getCurrentEvent().getTimestampValue() != timestampValue) {
+                this.seek(timestampValue);
+                this.curRank = rank;
+            }
+        } else {
+            setUnknownLocation();
+        }
 
-        this.curRank = rank;
     }
 
     public CtfTmfTrace getCtfTmfTrace() {
@@ -45,22 +65,27 @@ Comparable<CtfIterator> {
 
     public CtfTmfEvent getCurrentEvent() {
         final StreamInputReader top = super.prio.peek();
-        if (top != null)
-            return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace);
+        if (top != null) {
+            return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(),
+                    ctfTmfTrace);
+        }
         return null;
     }
 
     @Override
     public boolean seek(final long timestamp) {
         boolean ret = false;
-        final long offsetTimestamp = timestamp - this.getCtfTmfTrace().getCTFTrace().getOffset();
-        if( offsetTimestamp < 0 )
+        final long offsetTimestamp = timestamp
+                - this.getCtfTmfTrace().getCTFTrace().getOffset();
+        if (offsetTimestamp < 0) {
             ret = super.seek(timestamp);
-        else
+        } else {
             ret = super.seek(offsetTimestamp);
+        }
 
-        if (ret)
+        if (ret) {
             curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        }
         return ret;
     }
 
@@ -68,8 +93,9 @@ Comparable<CtfIterator> {
         boolean ret = false;
         ret = super.seekIndex(rank);
 
-        if (ret)
+        if (ret) {
             curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        }
         return ret;
     }
 
@@ -80,7 +106,9 @@ Comparable<CtfIterator> {
 
     @Override
     public void setRank(final long rank) {
-        seekRank(rank);
+        if(!this.curLocation.equals(nullLocation)) {
+            seekRank(rank);
+        }
     }
 
     /*
@@ -106,7 +134,7 @@ Comparable<CtfIterator> {
     public void setLocation(final ITmfLocation<?> location) {
         // FIXME alex: isn't there a cleaner way than a cast here?
         this.curLocation = (CtfLocation) location;
-        seek(((CtfLocation)location).getLocation());
+        seek(((CtfLocation) location).getLocation());
     }
 
     @Override
@@ -131,10 +159,11 @@ Comparable<CtfIterator> {
 
     @Override
     public int compareTo(final CtfIterator o) {
-        if (this.getRank() < o.getRank())
+        if (this.getRank() < o.getRank()) {
             return -1;
-        else if (this.getRank() > o.getRank())
+        } else if (this.getRank() > o.getRank()) {
             return 1;
+        }
         return 0;
     }
 
index e935ebdc71a20b2daf661f79f18ce81dd1f62717..4c7ebb1d047b8beea24d0d48f19a23e136c249f5 100644 (file)
@@ -5,6 +5,8 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 
 public class CtfLocation implements ITmfLocation<Long> {
 
+    public static final Long INVALID_LOCATION = -1L;
+
     public CtfLocation(Long location) {
         setLocation(location);
     }
index 9ec3d43e55b338917b57e376ebda8d99e80b9610..b44a0283480ce39f62e5189f552c4df121f668ef 100644 (file)
@@ -75,7 +75,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
             throw new TmfTraceException(e.getMessage());
         }
         this.iterator = new CtfIterator(this, 0, 0);
-        setStartTime(iterator.getCurrentEvent().getTimestamp());
+        setStartTime(TmfTimestamp.BIG_BANG);
+        if( !this.iterator.getLocation().equals(CtfIterator.nullLocation)) {
+            setStartTime(iterator.getCurrentEvent().getTimestamp());
+        }
         TmfSignalManager.register(this);
         // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
         // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
@@ -266,7 +269,9 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
         if (currentLocation == null) {
             currentLocation = new CtfLocation(0L);
         }
-        iterator.setLocation(currentLocation);
+        if( !iterator.getLocation().equals(CtfIterator.nullLocation)) {
+            iterator.setLocation(currentLocation);
+        }
         return iterator;
     }
 
This page took 0.030959 seconds and 5 git commands to generate.