Commit | Line | Data |
---|---|---|
d18dd09b ASL |
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 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.stubs.component; |
d18dd09b ASL |
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; | |
6c13869b FC |
22 | import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider; |
23 | import org.eclipse.linuxtools.tmf.core.event.TmfData; | |
24 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; | |
25 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; | |
26 | import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; | |
27 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; | |
28 | import org.eclipse.linuxtools.tmf.stubs.trace.TmfTraceStub; | |
d18dd09b ASL |
29 | |
30 | /** | |
31 | * <b><u>TmfDataProviderStub</u></b> | |
32 | * <p> | |
33 | * TODO: Implement me. Please. | |
34 | */ | |
3b38ea61 | 35 | @SuppressWarnings("nls") |
d18dd09b ASL |
36 | public class TmfDataProviderStub extends TmfDataProvider<TmfData> { |
37 | ||
38 | private static final String DIRECTORY = "testfiles"; | |
39 | private static final String TEST_STREAM = "M-Test-10K"; | |
40 | ||
41 | private TmfTraceStub fTrace; | |
42 | ||
43 | public TmfDataProviderStub(String path) throws IOException { | |
44 | super("TmfDataProviderStub", TmfData.class); | |
cbd4ad82 | 45 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); |
d18dd09b ASL |
46 | try { |
47 | File test = new File(FileLocator.toFileURL(location).toURI()); | |
48 | fTrace = new TmfTraceStub(test.getPath(), true); | |
49 | } catch (URISyntaxException e) { | |
50 | e.printStackTrace(); | |
51 | } | |
52 | } | |
53 | ||
54 | public TmfDataProviderStub() throws IOException { | |
55 | this(DIRECTORY + File.separator + TEST_STREAM); | |
56 | } | |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // TmfProvider | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | @Override | |
2fb2eb37 FC |
63 | public ITmfContext armRequest(ITmfDataRequest<TmfData> request) { |
64 | if (request instanceof ITmfEventRequest<?>) { | |
65 | ITmfContext context = fTrace.seekEvent(((ITmfEventRequest<?>) request).getRange().getStartTime()); | |
d18dd09b ASL |
66 | return context; |
67 | } | |
68 | return null; | |
69 | } | |
70 | ||
71 | @Override | |
72 | public TmfData getNext(ITmfContext context) { | |
73 | return fTrace.getNext(context); | |
74 | } | |
75 | ||
76 | @Override | |
2fb2eb37 | 77 | public boolean isCompleted(ITmfDataRequest<TmfData> request, TmfData data, int nbRead) { |
d18dd09b ASL |
78 | return false; |
79 | } | |
80 | ||
81 | } |