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 | ||
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; | |
fc6ccf6f FC |
23 | import org.eclipse.linuxtools.tmf.request.TmfDataRequest; |
24 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
d18dd09b ASL |
25 | import org.eclipse.linuxtools.tmf.tests.TmfCoreTestPlugin; |
26 | import org.eclipse.linuxtools.tmf.trace.ITmfContext; | |
fc6ccf6f | 27 | import org.eclipse.linuxtools.tmf.trace.TmfContext; |
d18dd09b ASL |
28 | import org.eclipse.linuxtools.tmf.trace.TmfTraceStub; |
29 | ||
30 | /** | |
31 | * <b><u>TmfEventProviderStub</u></b> | |
32 | * <p> | |
33 | * TODO: Implement me. Please. | |
34 | */ | |
35 | public class TmfEventProviderStub extends TmfEventProvider<TmfEvent> { | |
36 | ||
37 | private static final String DIRECTORY = "testfiles"; | |
85fb0e54 | 38 | private static final String TEST_STREAM = "A-Test-10K"; |
d18dd09b ASL |
39 | |
40 | private TmfTraceStub fTrace; | |
41 | ||
42 | public TmfEventProviderStub(String path) throws IOException { | |
fc6ccf6f FC |
43 | super(TmfEvent.class); |
44 | URL location = FileLocator.find(TmfCoreTestPlugin.getPlugin().getBundle(), new Path(path), null); | |
d18dd09b ASL |
45 | try { |
46 | File test = new File(FileLocator.toFileURL(location).toURI()); | |
47 | fTrace = new TmfTraceStub(test.getPath(), true); | |
48 | } catch (URISyntaxException e) { | |
49 | e.printStackTrace(); | |
50 | } | |
51 | } | |
52 | ||
53 | public TmfEventProviderStub() throws IOException { | |
54 | this(DIRECTORY + File.separator + TEST_STREAM); | |
55 | } | |
951d134a FC |
56 | |
57 | @Override | |
58 | public void deregister() { | |
59 | fTrace.deregister(); | |
60 | super.deregister(); | |
61 | } | |
d18dd09b ASL |
62 | |
63 | // ------------------------------------------------------------------------ | |
64 | // TmfEventProvider | |
65 | // ------------------------------------------------------------------------ | |
66 | ||
67 | @Override | |
fc6ccf6f FC |
68 | public ITmfContext armRequest(TmfDataRequest<TmfEvent> request) { |
69 | if (request instanceof TmfEventRequest<?>) { | |
70 | TmfContext context = fTrace.seekEvent(((TmfEventRequest<?>) request).getRange().getStartTime()); | |
d18dd09b ASL |
71 | return context; |
72 | } | |
73 | return null; | |
74 | } | |
75 | ||
76 | @Override | |
77 | public TmfEvent getNext(ITmfContext context) { | |
78 | return fTrace.getNext(context); | |
79 | } | |
80 | ||
81 | } |