de1458b98619780cba8906c7c51880031f99d52b
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfIterator.java
1 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
4 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
5 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
7
8 public class CtfIterator extends CTFTraceReader implements ITmfContext,
9 Comparable<CtfIterator> {
10
11 private final CtfTmfTrace ctfTmfTrace;
12
13 private CtfLocation curLocation;
14 private long curRank;
15
16 /**
17 * Create a new CTF trace iterator, which initially points at the first
18 * event in the trace.
19 *
20 * @param trace
21 */
22 public CtfIterator(final CtfTmfTrace trace) {
23 super(trace.getCTFTrace());
24 this.ctfTmfTrace = trace;
25
26 // FIXME put the real stuff here...
27 this.curLocation = new CtfLocation(trace.getStartTime());
28 this.curRank = 0;
29 }
30
31 public CtfIterator(final CtfTmfTrace trace, final long timestampValue, final long rank) {
32 super(trace.getCTFTrace());
33 this.ctfTmfTrace = trace;
34 this.curLocation = (new CtfLocation(this.getCurrentEvent()
35 .getTimestampValue()));
36 if (this.getCurrentEvent().getTimestampValue() != timestampValue)
37 this.seek(timestampValue);
38
39 this.curRank = rank;
40 }
41
42 public CtfTmfTrace getCtfTmfTrace() {
43 return ctfTmfTrace;
44 }
45
46 public CtfTmfEvent getCurrentEvent() {
47 final StreamInputReader top = super.prio.peek();
48 if (top != null)
49 return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace);
50 return null;
51 }
52
53 @Override
54 public boolean seek(final long timestamp) {
55 boolean ret = false;
56 final long offsetTimestamp = timestamp - this.getCtfTmfTrace().getCTFTrace().getOffset();
57 if( offsetTimestamp < 0 )
58 ret = super.seek(timestamp);
59 else
60 ret = super.seek(offsetTimestamp);
61
62 if (ret)
63 curLocation.setLocation(getCurrentEvent().getTimestampValue());
64 return ret;
65 }
66
67 public boolean seekRank(final long rank) {
68 boolean ret = false;
69 ret = super.seekIndex(rank);
70
71 if (ret)
72 curLocation.setLocation(getCurrentEvent().getTimestampValue());
73 return ret;
74 }
75
76 @Override
77 public long getRank() {
78 return super.getIndex();
79 }
80
81 @Override
82 public void setRank(final long rank) {
83 seekRank(rank);
84 }
85
86 /*
87 * (non-Javadoc)
88 *
89 * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone()
90 */
91 @Override
92 public CtfIterator clone() {
93 CtfIterator clone = null;
94 clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent()
95 .getTimestampValue(), curRank);
96 return clone;
97 }
98
99 @Override
100 public void dispose() {
101 // FIXME add dispose() stuff to CTFTrace and call it here...
102
103 }
104
105 @Override
106 public void setLocation(final ITmfLocation<?> location) {
107 // FIXME alex: isn't there a cleaner way than a cast here?
108 this.curLocation = (CtfLocation) location;
109 seek(((CtfLocation)location).getLocation());
110 }
111
112 @Override
113 public CtfLocation getLocation() {
114 return curLocation;
115 }
116
117 @SuppressWarnings("unused")
118 @Override
119 public void increaseRank() {
120 curRank++;
121 }
122
123 @Override
124 public boolean hasValidRank() {
125 return (getRank() > -1);
126 }
127
128 @Override
129 public boolean advance() {
130 return super.advance();
131 }
132
133 @Override
134 public int compareTo(final CtfIterator o) {
135 if (this.getRank() < o.getRank())
136 return -1;
137 else if (this.getRank() > o.getRank())
138 return 1;
139 return 0;
140 }
141
142 }
This page took 0.032278 seconds and 5 git commands to generate.