/*******************************************************************************
- * 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
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
/**
* The CTF trace reader iterator.
* @author Matthew Khouzam
*/
public class CtfIterator extends CTFTraceReader implements ITmfContext,
- Comparable<CtfIterator>, Cloneable {
+ Comparable<CtfIterator> {
private final CtfTmfTrace ctfTmfTrace;
* @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;
* @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.
*
* @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 */
* assign the location index correctly
*/
long index = 0;
- if (this.getCurrentEvent() != null) {
- currTimestamp = this.getCurrentEvent().getTimestamp().getValue();
+ final CtfTmfEvent currentEvent = this.getCurrentEvent();
+ if (currentEvent != null) {
+ currTimestamp = currentEvent.getTimestamp().getValue();
for (long i = 0; i < ctfLocationData.getIndex(); i++) {
- if (currTimestamp == this.getCurrentEvent().getTimestamp().getValue()) {
+ if (currTimestamp == currentEvent.getTimestamp().getValue()) {
index++;
} else {
index = 0;
}
/* Seek the current location accordingly */
if (ret) {
- curLocation.setLocation(new CtfLocationData(getCurrentEvent().getTimestamp().getValue(), index));
+ curLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
} else {
curLocation = NULL_LOCATION;
}
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;
}
*/
@Override
public void dispose() {
- // FIXME add dispose() stuff to CTFTrace and call it here...
-
+ super.dispose();
}
/**
* Method setLocation.
* @param location ITmfLocation<?>
+ * @since 3.0
*/
@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());
}
/**
* @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().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;
return 0;
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
final int prime = 31;
return result;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {