Commit | Line | Data |
---|---|---|
6040f86c ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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 (fchouinard@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2e5e79d5 | 13 | package org.eclipse.linuxtools.internal.lttng.stubs; |
6040f86c ASL |
14 | |
15 | import java.io.FileNotFoundException; | |
16 | import java.io.IOException; | |
17 | import java.io.RandomAccessFile; | |
18 | ||
2352aed9 | 19 | import org.eclipse.core.resources.IProject; |
25e48683 | 20 | import org.eclipse.core.resources.IResource; |
5945cec9 | 21 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent; |
b4f71e4a | 22 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
a1440d1f | 23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
7e6347b0 | 24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; |
6c13869b | 25 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
0316808c | 26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
6c13869b FC |
27 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
28 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; | |
29 | import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; | |
6040f86c ASL |
30 | |
31 | /** | |
32 | * <b><u>LTTngTraceStub</u></b> | |
33 | * <p> | |
34 | * Dummy test trace. Use in conjunction with LTTngEventParserStub. | |
35 | */ | |
3b38ea61 | 36 | @SuppressWarnings("nls") |
7e6347b0 | 37 | public class LTTngTraceStub extends TmfTrace<LttngEvent> implements ITmfEventParser<LttngEvent> { |
6040f86c ASL |
38 | |
39 | // ======================================================================== | |
40 | // Attributes | |
41 | // ======================================================================== | |
42 | ||
43 | // The actual stream | |
44 | private final RandomAccessFile fTrace; | |
45 | ||
46 | // The associated event parser | |
72f1e62a | 47 | private final ITmfEventParser<LttngEvent> fParser; |
6040f86c ASL |
48 | |
49 | // ======================================================================== | |
50 | // Constructors | |
51 | // ======================================================================== | |
52 | ||
53 | /** | |
54 | * @param filename | |
55 | * @param parser | |
56 | * @throws FileNotFoundException | |
57 | */ | |
b4f71e4a | 58 | public LTTngTraceStub(final IResource resource) throws TmfTraceException { |
0316808c | 59 | this(resource, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE); |
6040f86c ASL |
60 | } |
61 | ||
62 | /** | |
63 | * @param filename | |
64 | * @param parser | |
65 | * @param cacheSize | |
66 | * @throws FileNotFoundException | |
67 | */ | |
b4f71e4a | 68 | public LTTngTraceStub(final IResource resource, final int cacheSize) throws TmfTraceException { |
09e86496 FC |
69 | // super(resource, LttngEvent.class, resource.getName(), cacheSize, true); |
70 | super(resource, LttngEvent.class, resource.getName(), cacheSize); | |
b4f71e4a FC |
71 | try { |
72 | fTrace = new RandomAccessFile(resource.getName(), "r"); | |
73 | } catch (FileNotFoundException e) { | |
74 | throw new TmfTraceException(e.getMessage()); | |
75 | } | |
25e48683 | 76 | fParser = new LTTngEventParserStub(); |
20658947 FC |
77 | } |
78 | ||
79 | public void indexTrace() { | |
0316808c | 80 | getIndexer().buildIndex(true); |
6040f86c | 81 | } |
25e48683 | 82 | |
6040f86c ASL |
83 | // ======================================================================== |
84 | // Accessors | |
85 | // ======================================================================== | |
86 | ||
87 | public RandomAccessFile getStream() { | |
88 | return fTrace; | |
89 | } | |
90 | ||
91 | // ======================================================================== | |
92 | // Operators | |
93 | // ======================================================================== | |
94 | ||
95 | /* (non-Javadoc) | |
96 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object) | |
97 | */ | |
25e48683 FC |
98 | @Override |
99 | @SuppressWarnings("unchecked") | |
7e6347b0 | 100 | public TmfContext seekEvent(final ITmfLocation<?> location) { |
9f584e4c | 101 | TmfContext context = null; |
25e48683 FC |
102 | try { |
103 | synchronized(fTrace) { | |
104 | fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0); | |
105 | context = new TmfContext(getCurrentLocation(), 0); | |
106 | // TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0); | |
107 | // TmfEvent event = parseEvent(context2); | |
108 | // context.setTimestamp(event.getTimestamp()); | |
109 | } | |
110 | } catch (final IOException e) { | |
111 | // TODO Auto-generated catch block | |
112 | e.printStackTrace(); | |
6040f86c ASL |
113 | } |
114 | return context; | |
115 | } | |
116 | ||
90e2b925 | 117 | @Override |
7e6347b0 | 118 | public TmfContext seekEvent(final double ratio) { |
90e2b925 FC |
119 | // TODO Auto-generated method stub |
120 | return null; | |
121 | } | |
122 | ||
123 | @Override | |
25e48683 | 124 | public double getLocationRatio(final ITmfLocation<?> location) { |
90e2b925 FC |
125 | // TODO Auto-generated method stub |
126 | return 0; | |
127 | } | |
128 | ||
6040f86c ASL |
129 | /* (non-Javadoc) |
130 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation() | |
131 | */ | |
132 | @Override | |
25e48683 FC |
133 | public ITmfLocation<?> getCurrentLocation() { |
134 | try { | |
135 | return new TmfLocation<Long>(fTrace.getFilePointer()); | |
136 | } catch (final IOException e) { | |
137 | // TODO Auto-generated catch block | |
138 | e.printStackTrace(); | |
139 | } | |
140 | return null; | |
141 | } | |
142 | ||
143 | /* (non-Javadoc) | |
144 | * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent() | |
145 | */ | |
146 | @Override | |
2352aed9 | 147 | public LttngEvent parseEvent(final ITmfContext context) { |
7e6347b0 | 148 | // try { |
25e48683 | 149 | // paserNextEvent updates the context |
7e6347b0 | 150 | final LttngEvent event = (LttngEvent) fParser.parseEvent(context); |
25e48683 FC |
151 | // if (event != null) { |
152 | // context.setTimestamp(event.getTimestamp()); | |
153 | // } | |
154 | return event; | |
7e6347b0 FC |
155 | // } |
156 | // catch (final IOException e) { | |
157 | // e.printStackTrace(); | |
158 | // } | |
159 | // return null; | |
6040f86c ASL |
160 | } |
161 | ||
25e48683 FC |
162 | /* (non-Javadoc) |
163 | * @see java.lang.Object#toString() | |
164 | */ | |
165 | @Override | |
166 | public String toString() { | |
167 | return "[LTTngTraceStub]"; | |
168 | } | |
169 | ||
2352aed9 FC |
170 | /* (non-Javadoc) |
171 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String) | |
172 | */ | |
173 | @Override | |
174 | public boolean validate(IProject project, String path) { | |
175 | return fileExists(path); | |
176 | } | |
177 | ||
25e48683 FC |
178 | // // ======================================================================== |
179 | // // Helper functions | |
180 | // // ======================================================================== | |
181 | // | |
182 | // /* (non-Javadoc) | |
183 | // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes() | |
184 | // */ | |
185 | // public Map<String, Object> getAttributes() { | |
186 | // // TODO Auto-generated method stub | |
187 | // return null; | |
188 | // } | |
6040f86c ASL |
189 | |
190 | } |