Fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
CommitLineData
a3fc8213
AM
1package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3import java.io.FileNotFoundException;
a3fc8213
AM
4
5import org.eclipse.core.resources.IProject;
6import org.eclipse.core.resources.IResource;
7import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
8import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
9import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
10import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
11import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
12import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
13import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
14import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
15import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
16import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
17import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
18import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
19import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
a3fc8213
AM
20
21public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements
22 ITmfTrace<CtfTmfEvent> {
23
24 // ------------------------------------------------------------------------
25 // Constants
26 // ------------------------------------------------------------------------
27
a3fc8213
AM
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 // the Ctf Trace
33 private CTFTrace fTrace;
34
a3fc8213
AM
35 // The number of events collected
36 protected long fNbEvents = 0;
37
38 // The time span of the event stream
39 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
40 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
41
42 // The trace resource
43 private IResource fResource;
44
45 /*
46 * Since in TMF, "traces" can read events, this trace here will have its own
47 * iterator. The user can instantiate extra iterator if they want to seek at
48 * many places at the same time.
49 */
50 protected CtfIterator iterator;
51
52 // ------------------------------------------------------------------------
53 // Constructors
54 // ------------------------------------------------------------------------
55
56 public CtfTmfTrace() {
57 super();
58 }
59
cbfd4822 60 @SuppressWarnings("unused")
a3fc8213 61 @Override
3118edf1 62 public void initTrace(String name, String path, Class<CtfTmfEvent> eventType)
a3fc8213
AM
63 throws FileNotFoundException {
64 try {
65 this.fTrace = new CTFTrace(path);
66 } catch (CTFReaderException e) {
67 /*
68 * If it failed at the init(), we can assume it's because the file
69 * was not found or was not recognized as a CTF trace. Throw into
70 * the new type of exception expected by the rest of TMF.
71 */
a3fc8213
AM
72 throw new FileNotFoundException(e.getMessage());
73 }
74 this.iterator = new CtfIterator(this, 0, 0);
75 setStartTime(iterator.getCurrentEvent().getTimestamp());
76 TmfSignalManager.register(this);
77 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
78 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
79 // .getLocation().getStartTime());
80 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
81 // .getLocation().getEndTime());
82 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
83 // this.fEndTime.clone()));
84 }
85
cbfd4822 86 @SuppressWarnings("unused")
a3fc8213 87 @Override
8636b448 88 public void indexTrace(boolean waitForCompletion) {
cbfd4822 89 // do nothing
a3fc8213
AM
90 }
91
92 @Override
93 public void dispose() {
94 TmfSignalManager.deregister(this);
95 }
96
97 @Override
98 public void broadcast(TmfSignal signal) {
99 TmfSignalManager.dispatchSignal(signal);
100 }
101
cbfd4822 102 @SuppressWarnings("unused")
a3fc8213
AM
103 @Override
104 public boolean validate(IProject project, String path) {
105 try {
106 final CTFTrace temp = new CTFTrace(path);
107 return temp.majortIsSet(); // random test
90235d6b
AM
108 } catch (CTFReaderException e) {
109 /* Nope, not a CTF trace we can read */
110 return false;
a3fc8213 111 }
a3fc8213
AM
112 }
113
114 @Override
115 public CtfTmfTrace clone() throws CloneNotSupportedException {
116 CtfTmfTrace clone = null;
117 clone = (CtfTmfTrace) super.clone();
a3fc8213
AM
118 clone.fStartTime = this.fStartTime.clone();
119 clone.fEndTime = this.fEndTime.clone();
120 clone.fTrace = this.fTrace;
121 return clone;
122 }
123
a3fc8213
AM
124 // ------------------------------------------------------------------------
125 // Accessors
126 // ------------------------------------------------------------------------
127
128 /**
129 * @return the trace path
130 */
131 @Override
132 public String getPath() {
133 return this.fTrace.getPath();
134 }
135
136 @Override
137 public String getName() {
138 String temp[] = this.fTrace.getPath().split(
139 System.getProperty("file.separator")); //$NON-NLS-1$
140 if (temp.length > 2) {
141 return temp[temp.length - 1];
142 }
143 return temp[0];
144 }
145
146 @Override
3118edf1 147 public int getIndexPageSize() {
b782a8e7 148 return 50000; //not true, but it works
a3fc8213
AM
149 }
150
151 @Override
152 public long getNbEvents() {
153 return this.fNbEvents;
154 }
155
156 @Override
157 public TmfTimeRange getTimeRange() {
158 return new TmfTimeRange(this.fStartTime, this.fEndTime);
159 }
160
161 @Override
162 public ITmfTimestamp getStartTime() {
163 return this.fStartTime;
164 }
165
166 @Override
167 public ITmfTimestamp getEndTime() {
168 return this.fEndTime;
169 }
170
171 @Override
172 public ITmfLocation<?> getCurrentLocation() {
173 return iterator.getLocation();
174 }
175
176 @Override
177 public long getRank(ITmfTimestamp timestamp) {
178 ITmfContext context = seekEvent(timestamp);
179 return context.getRank();
180 }
181
182 // ------------------------------------------------------------------------
183 // Operators
184 // ------------------------------------------------------------------------
185
186 protected void setTimeRange(TmfTimeRange range) {
187 this.fStartTime = range.getStartTime();
188 this.fEndTime = range.getEndTime();
189 }
190
191 protected void setStartTime(ITmfTimestamp startTime) {
192 this.fStartTime = startTime;
193 }
194
195 protected void setEndTime(ITmfTimestamp endTime) {
196 this.fEndTime = endTime;
197 }
198
199 // ------------------------------------------------------------------------
200 // TmfProvider
201 // ------------------------------------------------------------------------
202
203 @Override
204 public ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent> request) {
205 if ((request instanceof ITmfEventRequest<?>)
4dbe1f0e
MK
206 && !TmfTimestamp.BIG_BANG
207 .equals(((ITmfEventRequest<CtfTmfEvent>) request)
208 .getRange().getStartTime())
a3fc8213 209 && (request.getIndex() == 0)) {
4dbe1f0e
MK
210 ITmfContext context = seekEvent(((ITmfEventRequest<CtfTmfEvent>) request)
211 .getRange().getStartTime());
212 ((ITmfEventRequest<CtfTmfEvent>) request)
213 .setStartIndex((int) context.getRank());
a3fc8213
AM
214 return context;
215 }
216 return seekEvent(request.getIndex());
217 }
218
219 /**
220 * The trace reader keeps its own iterator: the "context" parameter here
221 * will be ignored.
4dbe1f0e 222 *
a3fc8213
AM
223 * If you wish to specify a new context, instantiate a new CtfIterator and
224 * seek() it to where you want, and use that to read events.
4dbe1f0e 225 *
a3fc8213
AM
226 * FIXME merge with getNextEvent below once they both use the same parameter
227 * type.
228 */
cbfd4822 229 @SuppressWarnings("unused")
a3fc8213
AM
230 @Override
231 public CtfTmfEvent getNext(ITmfContext context) {
232 iterator.advance();
233 return iterator.getCurrentEvent();
234 }
235
236 // ------------------------------------------------------------------------
237 // ITmfTrace
238 // ------------------------------------------------------------------------
239
240 @Override
241 public ITmfContext seekLocation(ITmfLocation<?> location) {
cbfd4822
MK
242 CtfLocation currentLocation = (CtfLocation) location;
243 if (currentLocation == null) {
244 currentLocation = new CtfLocation(0L);
1a096cc5 245 }
cbfd4822 246 iterator.setLocation(currentLocation);
a3fc8213
AM
247 return iterator;
248 }
249
250 @Override
251 public double getLocationRatio(ITmfLocation<?> location) {
cbfd4822
MK
252 CtfLocation curLocation = (CtfLocation) location;
253 iterator.seek(curLocation.getLocation());
254 return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator
c62f8976 255 .getStartTime())
cbfd4822 256 / (iterator.getEndTime() - iterator.getStartTime());
a3fc8213
AM
257 }
258
259 @Override
260 public long getStreamingInterval() {
261 return 0;
262 }
263
264 @Override
265 public ITmfContext seekEvent(ITmfTimestamp timestamp) {
266 iterator.seek(timestamp.getValue());
267 return iterator;
268 }
269
270 /**
271 * Seek by rank
272 */
273 @Override
274 public ITmfContext seekEvent(long rank) {
275 iterator.setRank(rank);
276 return iterator;
277 }
278
279 /**
280 * Seek rank ratio
281 */
282 @Override
283 public ITmfContext seekLocation(double ratio) {
284 iterator.seek((long) (this.fNbEvents * ratio));
285 return iterator;
286 }
287
cbfd4822 288 @SuppressWarnings("unused")
a3fc8213 289 @Override
cbfd4822 290 public CtfTmfEvent getNextEvent( ITmfContext context) {
a3fc8213
AM
291 iterator.advance();
292 return iterator.getCurrentEvent();
293 }
294
cbfd4822 295 @SuppressWarnings("unused")
a3fc8213
AM
296 @Override
297 public CtfTmfEvent parseEvent(ITmfContext context) {
298 return iterator.getCurrentEvent();
299 }
300
a3fc8213
AM
301 @Override
302 public IResource getResource() {
303 return this.fResource;
304 }
305
306 @Override
307 public void setResource(IResource fResource) {
308 this.fResource = fResource;
309 }
310
90235d6b 311 CTFTrace getCTFTrace() {
a3fc8213
AM
312 return fTrace;
313 }
8636b448 314
a3fc8213 315}
This page took 0.049806 seconds and 5 git commands to generate.