Fix seek behaviour in CtfAdaptor
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
index 991520b29b837f39298a51799c46cf8e294304fe..389170423e4a2d191d6abce96d6b535d3ad1da95 100644 (file)
@@ -59,13 +59,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     // The trace resource
     private IResource fResource;
 
-    /*
-     * Since in TMF, "traces" can read events, this trace here will have its own
-     * iterator. The user can instantiate extra iterator if they want to seek at
-     * many places at the same time.
-     */
-    protected CtfIterator iterator;
-
     /* Reference to the state system assigned to this trace */
     protected IStateSystemQuerier ss = null;
 
@@ -85,7 +78,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @throws TmfTraceException
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(IResource, String, Class<CtfTmfEvent>)
      */
-    @SuppressWarnings("unused")
     @Override
     public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
             throws TmfTraceException {
@@ -105,9 +97,9 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
              */
             throw new TmfTraceException(e.getMessage());
         }
-        this.iterator = new CtfIterator(this, 0, 0);
+        CtfIterator iterator = new CtfIterator(this, 0, 0);
         setStartTime(TmfTimestamp.BIG_BANG);
-        if( !this.iterator.getLocation().equals(CtfIterator.nullLocation)) {
+        if( !iterator.getLocation().equals(CtfIterator.NULL_LOCATION)) {
             setStartTime(iterator.getCurrentEvent().getTimestamp());
         }
         TmfSignalManager.register(this);
@@ -156,7 +148,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @return boolean
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String)
      */
-    @SuppressWarnings("unused")
     @Override
     public boolean validate(final IProject project, final String path) {
         try {
@@ -287,13 +278,13 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     }
 
     /**
-     * Method getCurrentLocation.
-     * @return ITmfLocation<?>
+     * Method getCurrentLocation. This is not applicable in CTF
+     * @return null, since the trace has no knowledge of the current location
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
      */
     @Override
     public ITmfLocation<?> getCurrentLocation() {
-        return iterator.getLocation();
+        return null;
     }
 
     // ------------------------------------------------------------------------
@@ -383,10 +374,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
         if (currentLocation == null) {
             currentLocation = new CtfLocation(0L);
         }
-        if( !iterator.getLocation().equals(CtfIterator.nullLocation)) {
-            iterator.setLocation(currentLocation);
-        }
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.setLocation(currentLocation);
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -398,6 +389,7 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
     @Override
     public double getLocationRatio(final ITmfLocation<?> location) {
         final CtfLocation curLocation = (CtfLocation) location;
+        CtfIterator iterator = new CtfIterator(this);
         iterator.seek(curLocation.getLocation());
         return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator
                 .getStartTime())
@@ -422,8 +414,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final ITmfTimestamp timestamp) {
-        iterator.seek(timestamp.getValue());
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seek(timestamp.getValue());
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -434,8 +428,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final long rank) {
-        iterator.setRank(rank);
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seekRank(rank);
+        context.setRank(rank);
+        return context;
     }
 
     /**
@@ -446,8 +442,10 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      */
     @Override
     public ITmfContext seekEvent(final double ratio) {
-        iterator.seek((long) (this.fNbEvents * ratio));
-        return iterator;
+        CtfIterator context = new CtfIterator(this);
+        context.seek((long) (this.fNbEvents * ratio));
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
@@ -456,11 +454,14 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * @return CtfTmfEvent
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(ITmfContext)
      */
-    @SuppressWarnings("unused")
     @Override
     public CtfTmfEvent readNextEvent(final ITmfContext context) {
-        CtfTmfEvent event = iterator.getCurrentEvent();
-        iterator.advance();
+        CtfTmfEvent event = null;
+        if (context instanceof CtfIterator) {
+            CtfIterator ctfIterator = (CtfIterator) context;
+            event = ctfIterator.getCurrentEvent();
+            ctfIterator.advance();
+        }
         return event;
     }
 
@@ -496,7 +497,6 @@ public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTr
      * sub-classes.
      * @throws TmfTraceException
      */
-    @SuppressWarnings({ "unused", "static-method" })
     protected void buildStateSystem() throws TmfTraceException {
         /*
          * Nothing is done in the basic implementation, please specify
This page took 0.038907 seconds and 5 git commands to generate.