2010-06-05 fchouinard@gmail.com Contributions for bugs 292965, 292963, 293102,...
[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 this(filename, DEFAULT_CACHE_SIZE, false);
51 }
52
53 /**
54 * @param filename
55 * @param cacheSize
56 * @throws FileNotFoundException
57 */
58 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
59 this(filename, cacheSize, false);
60 }
61
62 /**
63 * @param filename
64 * @param waitForCompletion
65 * @throws FileNotFoundException
66 */
67 public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
68 this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
69 }
70
71 /**
72 * @param filename
73 * @param cacheSize
74 * @param waitForCompletion
75 * @throws FileNotFoundException
76 */
77 public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
78 super(filename, TmfEvent.class, filename, cacheSize);
79 fTrace = new RandomAccessFile(filename, "r");
80 fParser = new TmfEventParserStub();
81 }
82
83 /**
84 */
85 @Override
86 public TmfTraceStub clone() {
87 TmfTraceStub clone = null;
88 try {
89 clone = (TmfTraceStub) super.clone();
90 clone.fTrace = new RandomAccessFile(getPath(), "r");
91 clone.fParser = new TmfEventParserStub();
92 } catch (CloneNotSupportedException e) {
93 } catch (FileNotFoundException e) {
94 }
95 return clone;
96 }
97
98 public ITmfTrace createTraceCopy() {
99 ITmfTrace returnedValue = null;
100 returnedValue = clone();
101 return returnedValue;
102 }
103
104 // ------------------------------------------------------------------------
105 // Accessors
106 // ------------------------------------------------------------------------
107
108 public RandomAccessFile getStream() {
109 return fTrace;
110 }
111
112 // ------------------------------------------------------------------------
113 // Operators
114 // ------------------------------------------------------------------------
115
116 @Override
117 @SuppressWarnings("unchecked")
118 public TmfContext seekLocation(ITmfLocation<?> location) {
119 try {
120 synchronized(fTrace) {
121 // Position the trace at the requested location and
122 // returns the corresponding context
123 long loc = 0;
124 long rank = 0;
125 if (location != null) {
126 loc = ((TmfLocation<Long>) location).getLocation();
127 rank = ITmfContext.UNKNOWN_RANK;
128 }
129 if (loc != fTrace.getFilePointer()) {
130 fTrace.seek(loc);
131 }
132 TmfContext context = new TmfContext(getCurrentLocation(), rank);
133 return context;
134 }
135 } catch (IOException e) {
136 e.printStackTrace();
137 }
138 return null;
139 }
140
141 @Override
142 public TmfLocation<Long> getCurrentLocation() {
143 try {
144 return new TmfLocation<Long>(fTrace.getFilePointer());
145 } catch (IOException e) {
146 e.printStackTrace();
147 }
148 return null;
149 }
150
151 @Override
152 public TmfEvent parseEvent(TmfContext context) {
153 try {
154 // parseNextEvent will update the context
155 TmfEvent event = fParser.parseNextEvent(this, context.clone());
156 return event;
157 }
158 catch (IOException e) {
159 e.printStackTrace();
160 }
161 return null;
162 }
163
164 @Override
165 public void setTimeRange(TmfTimeRange range) {
166 super.setTimeRange(range);
167 }
168
169 @Override
170 public void setStartTime(TmfTimestamp startTime) {
171 super.setStartTime(startTime);
172 }
173
174 @Override
175 public void setEndTime(TmfTimestamp endTime) {
176 super.setEndTime(endTime);
177 }
178
179 }
This page took 0.03603 seconds and 6 git commands to generate.