bbcee8a8a94bdeb0a3d877ec07d02a9db893235b
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / component / TmfEventProviderStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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.tests.stubs.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.core.component.TmfEventProvider;
23 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
24 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
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;
29 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
30
31 /**
32 * <b><u>TmfEventProviderStub</u></b>
33 * <p>
34 * TODO: Implement me. Please.
35 */
36 @SuppressWarnings("javadoc")
37 public class TmfEventProviderStub extends TmfEventProvider {
38
39 private static final String DIRECTORY = "testfiles";
40 private static final String TEST_STREAM = "A-Test-10K";
41
42 private TmfTraceStub fTrace;
43
44 public TmfEventProviderStub(final String path) throws IOException {
45 super(path, ITmfEvent.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());
49 fTrace = new TmfTraceStub(test.getPath(), 0, true);
50 } catch (final TmfTraceException e) {
51 e.printStackTrace();
52 } catch (final URISyntaxException e) {
53 e.printStackTrace();
54 }
55 }
56
57 public TmfEventProviderStub() throws IOException {
58 this(DIRECTORY + File.separator + TEST_STREAM);
59 }
60
61 @Override
62 public void dispose() {
63 fTrace.dispose();
64 super.dispose();
65 }
66
67 // ------------------------------------------------------------------------
68 // TmfEventProvider
69 // ------------------------------------------------------------------------
70
71 @Override
72 public ITmfContext armRequest(final ITmfDataRequest request) {
73 if (request instanceof ITmfEventRequest) {
74 final ITmfContext context = fTrace.seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
75 return context;
76 }
77 return null;
78 }
79
80 @Override
81 public ITmfEvent getNext(final ITmfContext context) {
82 return fTrace.getNext(context);
83 }
84
85 }
This page took 0.03324 seconds and 4 git commands to generate.