1
/*******************************************************************************
2
* Copyright (c) 2009 Ericsson
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
10
* Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11
*******************************************************************************/
13
package org.eclipse.linuxtools.internal.lttng.stubs;
15
import java.io.FileNotFoundException;
16
import java.io.IOException;
17
import java.io.RandomAccessFile;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
22
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
23
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
24
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
25
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
26
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
27
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
28
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
29
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
30
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
33
* <b><u>LTTngTraceStub</u></b>
35
* Dummy test trace. Use in conjunction with LTTngEventParserStub.
37
@SuppressWarnings("nls")
38
public class LTTngTraceStub extends TmfTrace<LttngEvent> implements ITmfEventParser<LttngEvent> {
40
// ========================================================================
42
// ========================================================================
45
private final RandomAccessFile fTrace;
47
// The associated event parser
48
private final ITmfEventParser<LttngEvent> fParser;
50
// ========================================================================
52
// ========================================================================
57
* @throws FileNotFoundException
59
public LTTngTraceStub(final IResource resource) throws TmfTraceException {
60
this(resource, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE);
67
* @throws FileNotFoundException
69
public LTTngTraceStub(final IResource resource, final int cacheSize) throws TmfTraceException {
70
// super(resource, LttngEvent.class, resource.getName(), cacheSize, true);
71
super(resource, LttngEvent.class, resource.getName(), cacheSize);
73
fTrace = new RandomAccessFile(resource.getName(), "r");
74
} catch (FileNotFoundException e) {
75
throw new TmfTraceException(e.getMessage());
77
fParser = new LTTngEventParserStub();
80
public void indexTrace() {
81
getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
84
// ========================================================================
86
// ========================================================================
88
public RandomAccessFile getStream() {
92
// ========================================================================
94
// ========================================================================
97
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
100
@SuppressWarnings("unchecked")
101
public TmfContext seekEvent(final ITmfLocation<?> location) {
102
TmfContext context = null;
104
synchronized(fTrace) {
105
fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
106
context = new TmfContext(getCurrentLocation(), 0);
107
// TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
108
// TmfEvent event = parseEvent(context2);
109
// context.setTimestamp(event.getTimestamp());
111
} catch (final IOException e) {
112
// TODO Auto-generated catch block
119
public TmfContext seekEvent(final double ratio) {
120
// TODO Auto-generated method stub
125
public double getLocationRatio(final ITmfLocation<?> location) {
126
// TODO Auto-generated method stub
131
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
134
public ITmfLocation<?> getCurrentLocation() {
136
return new TmfLocation<Long>(fTrace.getFilePointer());
137
} catch (final IOException e) {
138
// TODO Auto-generated catch block
145
* @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
148
public LttngEvent parseEvent(final ITmfContext context) {
150
// paserNextEvent updates the context
151
final LttngEvent event = (LttngEvent) fParser.parseEvent(context);
152
// if (event != null) {
153
// context.setTimestamp(event.getTimestamp());
157
// catch (final IOException e) {
158
// e.printStackTrace();
164
* @see java.lang.Object#toString()
167
public String toString() {
168
return "[LTTngTraceStub]";
172
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
175
public boolean validate(IProject project, String path) {
176
return fileExists(path);
179
// // ========================================================================
180
// // Helper functions
181
// // ========================================================================
184
// * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
186
// public Map<String, Object> getAttributes() {
187
// // TODO Auto-generated method stub
b'\\ No newline at end of file'