(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
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.trace;
14
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18
19 import org.eclipse.linuxtools.tmf.event.TmfEvent;
20 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
21 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
22 import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
23
24 /**
25 * <b><u>TmfTraceStub</u></b>
26 * <p>
27 * Dummy test trace. Use in conjunction with TmfEventParserStub.
28 */
29 public class TmfTraceStub extends TmfTrace<TmfEvent> {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 // The actual stream
36 private RandomAccessFile fTrace;
37
38 // The associated event parser
39 private ITmfEventParser fParser;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * @param filename
47 * @throws FileNotFoundException
48 */
49 public TmfTraceStub(String filename) throws FileNotFoundException {
50 super("TmfTraceStub", TmfEvent.class, filename);
51 fTrace = new RandomAccessFile(filename, "r");
52 fParser = new TmfEventParserStub();
53 }
54
55 /**
56 * @param filename
57 * @param cacheSize
58 * @throws FileNotFoundException
59 */
60 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
61 this(filename, cacheSize, false);
62 }
63
64 /**
65 * @param filename
66 * @param waitForCompletion
67 * @throws FileNotFoundException
68 */
69 public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
70 this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
71 }
72
73 /**
74 * @param filename
75 * @param cacheSize
76 * @param waitForCompletion
77 * @throws FileNotFoundException
78 */
79 public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
80 super(filename, TmfEvent.class, filename, cacheSize);
81 fTrace = new RandomAccessFile(filename, "r");
82 fParser = new TmfEventParserStub();
83 }
84
85 // /**
86 // * @param other
87 // */
88 // public TmfTraceStub(TmfTraceStub other) {
89 // this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
90 // }
91
92 /**
93 */
94 @Override
95 public TmfTraceStub clone() {
96 TmfTraceStub clone = null;
97 try {
98 clone = (TmfTraceStub) super.clone();
99 clone.fTrace = new RandomAccessFile(getName(), "r");
100 clone.fParser = new TmfEventParserStub();
101 } catch (CloneNotSupportedException e) {
102 } catch (FileNotFoundException e) {
103 }
104 return clone;
105 }
106
107 public ITmfTrace createTraceCopy() {
108 ITmfTrace returnedValue = null;
109 try {
110 returnedValue = new TmfTraceStub(this.getName());
111 }
112 catch (FileNotFoundException e) {
113 // e.printStackTrace();
114 }
115 return returnedValue;
116 }
117
118 // ------------------------------------------------------------------------
119 // Accessors
120 // ------------------------------------------------------------------------
121
122 public RandomAccessFile getStream() {
123 return fTrace;
124 }
125
126 // ------------------------------------------------------------------------
127 // Operators
128 // ------------------------------------------------------------------------
129
130 @Override
131 @SuppressWarnings("unchecked")
132 public TmfContext seekLocation(ITmfLocation<?> location) {
133 try {
134 synchronized(fTrace) {
135 // Position the trace at the requested location and
136 // returns the corresponding context
137 long loc = 0;
138 long rank = 0;
139 if (location != null) {
140 loc = ((TmfLocation<Long>) location).getLocation();
141 rank = ITmfContext.UNKNOWN_RANK;
142 }
143 if (loc != fTrace.getFilePointer()) {
144 fTrace.seek(loc);
145 }
146 TmfContext context = new TmfContext(getCurrentLocation(), rank);
147 return context;
148 }
149 } catch (IOException e) {
150 e.printStackTrace();
151 }
152 return null;
153 }
154
155 @Override
156 public TmfLocation<Long> getCurrentLocation() {
157 try {
158 return new TmfLocation<Long>(fTrace.getFilePointer());
159 } catch (IOException e) {
160 e.printStackTrace();
161 }
162 return null;
163 }
164
165 @Override
166 public TmfEvent parseEvent(TmfContext context) {
167 try {
168 // paserNextEvent updates the context
169 TmfEvent event = fParser.parseNextEvent(this, context);
170 return event;
171 }
172 catch (IOException e) {
173 e.printStackTrace();
174 }
175 return null;
176 }
177
178 @Override
179 public void setTimeRange(TmfTimeRange range) {
180 super.setTimeRange(range);
181 }
182
183 @Override
184 public void setStartTime(TmfTimestamp startTime) {
185 super.setStartTime(startTime);
186 }
187
188 @Override
189 public void setEndTime(TmfTimestamp endTime) {
190 super.setEndTime(endTime);
191 }
192
193 }
This page took 0.034761 seconds and 5 git commands to generate.