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