X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Fctfadaptor%2FCtfIterator.java;h=8311e7acb8fc351abd3183feab786cb491110e6f;hb=b6220b93a649a550ce808b03d2b5e180d3a83e57;hp=d215d76371f84bf47187d779a949d8797be0d00b;hpb=132a02b0c1e609dc72cb8f06f74aa8ef2809ca7f;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java index d215d76371..8311e7acb8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which @@ -25,7 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; * @author Matthew Khouzam */ public class CtfIterator extends CTFTraceReader implements ITmfContext, - Comparable, Cloneable { + Comparable { private final CtfTmfTrace ctfTmfTrace; @@ -72,13 +72,13 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * @since 2.0 */ public CtfIterator(final CtfTmfTrace trace, - final CtfLocationData ctfLocationData, final long rank) { + final CtfLocationInfo ctfLocationData, final long rank) { super(trace.getCTFTrace()); this.ctfTmfTrace = trace; if (this.hasMoreEvents()) { this.curLocation = new CtfLocation(ctfLocationData); - if (this.getCurrentEvent().getTimestampValue() != ctfLocationData.getTimestamp()) { + if (this.getCurrentEvent().getTimestamp().getValue() != ctfLocationData.getTimestamp()) { this.seek(ctfLocationData); this.curRank = rank; } @@ -101,14 +101,19 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * @return CtfTmfEvent */ public CtfTmfEvent getCurrentEvent() { - final StreamInputReader top = super.prio.peek(); + final StreamInputReader top = super.getPrio().peek(); if (top != null) { - return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), - ctfTmfTrace); + return CtfTmfEventFactory.createEvent(top.getCurrentEvent(), + top.getFilename(), ctfTmfTrace); } return null; } + @Override + public boolean seek(long timestamp) { + return seek(new CtfLocationInfo(timestamp, 0)); + } + /** * Seek this iterator to a given location. * @@ -117,12 +122,12 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * @return boolean * @since 2.0 */ - public boolean seek(final CtfLocationData ctfLocationData) { + public synchronized boolean seek(final CtfLocationInfo ctfLocationData) { boolean ret = false; /* Adjust the timestamp depending on the trace's offset */ long currTimestamp = ctfLocationData.getTimestamp(); - final long offsetTimestamp = currTimestamp - this.getTrace().getOffset(); + final long offsetTimestamp = this.getCtfTmfTrace().getCTFTrace().timestampNanoToCycles(currTimestamp); if (offsetTimestamp < 0) { ret = super.seek(0L); } else { @@ -133,20 +138,25 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * Check if there is already one or more events for that timestamp, and * assign the location index correctly */ - currTimestamp = this.getCurrentEvent().getTimestampValue(); long index = 0; - for (long i = 0; i < ctfLocationData.getIndex(); i++) { - if (currTimestamp == this.getCurrentEvent().getTimestampValue()) { - index++; - } else { - index = 0; + final CtfTmfEvent currentEvent = this.getCurrentEvent(); + if (currentEvent != null) { + currTimestamp = currentEvent.getTimestamp().getValue(); + + for (long i = 0; i < ctfLocationData.getIndex(); i++) { + if (currTimestamp == currentEvent.getTimestamp().getValue()) { + index++; + } else { + index = 0; + } + this.advance(); } - this.advance(); + } else { + ret= false; } - /* Seek the current location accordingly */ if (ret) { - curLocation.setLocation(new CtfLocationData(getCurrentEvent().getTimestampValue(), index)); + curLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index)); } else { curLocation = NULL_LOCATION; } @@ -173,15 +183,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, curRank = rank; } - /* - * (non-Javadoc) - * - * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone() - */ @Override public CtfIterator clone() { CtfIterator clone = null; - clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocation(), curRank); + clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank); return clone; } @@ -191,8 +196,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, */ @Override public void dispose() { - // FIXME add dispose() stuff to CTFTrace and call it here... - + super.dispose(); } /** @@ -200,10 +204,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * @param location ITmfLocation */ @Override - public void setLocation(final ITmfLocation location) { + 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).getLocationInfo()); } /** @@ -243,17 +247,17 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, * @return boolean successful or not */ @Override - public boolean advance() { - long index = curLocation.getLocation().getIndex(); - long timestamp = curLocation.getLocation().getTimestamp(); + public synchronized boolean advance() { + long index = curLocation.getLocationInfo().getIndex(); + long timestamp = curLocation.getLocationInfo().getTimestamp(); boolean ret = super.advance(); if (ret) { - final long timestampValue = getCurrentEvent().getTimestampValue(); + final long timestampValue = getCurrentEvent().getTimestamp().getValue(); if (timestamp == timestampValue) { - curLocation.setLocation(timestampValue, index + 1); + curLocation = new CtfLocation(timestampValue, index + 1); } else { - curLocation.setLocation(timestampValue, 0L); + curLocation = new CtfLocation(timestampValue, 0L); } } else { curLocation = NULL_LOCATION; @@ -276,9 +280,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, return 0; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -291,9 +292,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) {