Commit | Line | Data |
---|---|---|
e31e01e8 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.component; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.IOException; | |
17 | import java.net.URISyntaxException; | |
18 | import java.net.URL; | |
19 | ||
20 | import org.eclipse.core.runtime.FileLocator; | |
21 | import org.eclipse.core.runtime.Path; | |
22 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
23 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
24 | import org.eclipse.linuxtools.tmf.request.TmfDataRequest; | |
25 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
26 | import org.eclipse.linuxtools.tmf.tests.TmfCoreTestPlugin; | |
9f584e4c FC |
27 | import org.eclipse.linuxtools.tmf.trace.ITmfContext; |
28 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
e31e01e8 FC |
29 | import org.eclipse.linuxtools.tmf.trace.TmfTraceStub; |
30 | ||
31 | /** | |
32 | * <b><u>TmfProviderStub</u></b> | |
33 | * <p> | |
34 | * TODO: Implement me. Please. | |
35 | */ | |
36 | public class TmfProviderStub extends TmfProvider<TmfEvent> { | |
37 | ||
38 | private TmfTraceStub fTrace; | |
39 | ||
40 | public TmfProviderStub(String path) throws IOException { | |
41 | super(TmfEvent.class); | |
42 | URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null); | |
43 | try { | |
44 | File test = new File(FileLocator.toFileURL(location).toURI()); | |
45 | fTrace = new TmfTraceStub(test.getPath(), true); | |
46 | } catch (URISyntaxException e) { | |
47 | e.printStackTrace(); | |
48 | } | |
49 | } | |
50 | ||
51 | @Override | |
52 | public ITmfContext setContext(TmfDataRequest<TmfEvent> request) { | |
53 | if (request instanceof TmfEventRequest<?>) { | |
9f584e4c | 54 | TmfContext context = fTrace.seekEvent(((TmfEventRequest<?>) request).getRange().getStartTime()); |
e31e01e8 FC |
55 | return context; |
56 | } | |
57 | return null; | |
58 | } | |
59 | ||
60 | @Override | |
61 | public TmfEvent getNext(ITmfContext context) { | |
62 | return fTrace.getNext(context); | |
63 | } | |
64 | ||
65 | @Override | |
66 | public boolean isCompleted(TmfDataRequest<TmfEvent> request, TmfEvent event) { | |
67 | TmfTimestamp endTime = ((TmfEventRequest<?>) request).getRange().getEndTime(); | |
68 | return event.getTimestamp().compareTo(endTime, false) <= 0; | |
69 | } | |
70 | ||
71 | } |