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