ctf: Fix lost events in a more elegant way
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfLightweightContext.java
index ef0b7e7060ee9441928a0e4da64960a0878dc410..1b79f303e763e4e674fb72c3233e6200ce0d487f 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
  * a boxed Long, a long and an int.
  *
- * @versionj 1.0
+ * @version 1.0
  * @author Matthew Khouzam
  */
 public class CtfTmfLightweightContext implements ITmfContext {
@@ -49,7 +49,7 @@ public class CtfTmfLightweightContext implements ITmfContext {
     public CtfTmfLightweightContext(ArrayList<CtfIterator> iters,
             ListIterator<CtfIterator> pos) {
         fTrace = iters.get(0).getCtfTmfTrace();
-        curLocation = new CtfLocation((Long) null);
+        curLocation = new CtfLocation(new CtfLocationData(0, 0));
     }
 
     /**
@@ -60,7 +60,7 @@ public class CtfTmfLightweightContext implements ITmfContext {
      */
     public CtfTmfLightweightContext(CtfTmfTrace ctfTmfTrace) {
         fTrace = ctfTmfTrace;
-        curLocation = new CtfLocation((Long) null);
+        curLocation = new CtfLocation(new CtfLocationData(0, 0));
     }
 
     // -------------------------------------------
@@ -79,7 +79,7 @@ public class CtfTmfLightweightContext implements ITmfContext {
 
     @Override
     public boolean hasValidRank() {
-        return curRank != CtfLocation.INVALID_LOCATION;
+        return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
     }
 
     @Override
@@ -120,10 +120,17 @@ public class CtfTmfLightweightContext implements ITmfContext {
      * @return success or not
      */
     public synchronized boolean advance() {
+        final CtfLocationData curLocationData = this.curLocation.getLocation();
         boolean retVal = getIterator().advance();
         CtfTmfEvent currentEvent = getIterator().getCurrentEvent();
+
         if (currentEvent != null) {
-            curLocation.setLocation(currentEvent.getTimestampValue());
+            final long timestampValue = currentEvent.getTimestampValue();
+            if (curLocationData.getTimestamp() == timestampValue) {
+                curLocation.setLocation(timestampValue, curLocationData.getIndex() + 1);
+            } else {
+                curLocation.setLocation(timestampValue, 0L);
+            }
         } else {
             curLocation.setLocation(CtfLocation.INVALID_LOCATION);
         }
@@ -144,10 +151,23 @@ public class CtfTmfLightweightContext implements ITmfContext {
      * @return success or not
      */
     public synchronized boolean seek(final long timestamp) {
-        curLocation.setLocation(timestamp);
+        curLocation.setLocation(timestamp, 0);
         return getIterator().seek(timestamp);
     }
 
+    /**
+     * Seeks to a given location. Wrapper to help CtfTmfTrace
+     * @param location
+     *              unique location to find the event.
+     *
+     * @return success or not
+     * @since 2.0
+     */
+    public synchronized boolean seek(final CtfLocationData location) {
+        curLocation.setLocation(location);
+        return getIterator().seek(location);
+    }
+
     /*
      * (non-Javadoc)
      *
This page took 0.027459 seconds and 5 git commands to generate.